Running ORGANON in R Peter Gould and David Marshall Growth Model User Group December 9, 2011.

Slides:



Advertisements
Similar presentations
Professional Toolkit V2.0 C:\Presentations - SmartCafe_Prof_V2.0 - bsc page 1 Professional Toolkit 2.0.
Advertisements

SOFTWARE PRESENTATION ODMS (OPEN SOURCE DOCUMENT MANAGEMENT SYSTEM)
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files.
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
1 Introduction to Programming Environment Using MetroWerks CodeWarrior and Palm Emulator.
CHAPTER 1: INTORDUCTION TO C LANGUAGE
OCLC Online Computer Library Center Distributing ILLiad Reports Created Using Microsoft Access David Larsen Head of Access Services University of Chicago.
The Basic Java Tools A text editor to write Java program source code. A compiler to translate source code into bytecode. An interpreter to translate.
Simple Web SQLite Manager/Form/Report
MBAC 611.  We have been using MS Access to query and modify our databases.  MS Access provides a GUI (Graphical User Interface) that hides much of the.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Module 2: Using Transact-SQL Querying Tools. Overview SQL Query Analyzer Using the Object Browser Tool in SQL Query Analyzer Using Templates in SQL Query.
IS 426: Information Systems Construction in Modern Society Downloading and exploring oracle development environments.
BizTalk Adapter Pack (SAP) Installation
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Lesson 4 Computer Software
1 ENG236: ENG236: C++ Programming Environment (2) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY.
1 Programming Concepts Module Code : CMV6107 Class Contact Hours: 45 hours (Lecture 15 hours) (Laboratory/Tutorial 30 hours) Module Value: 1 Textbook:
Introduction to M ATLAB EE 100 – EE Dept. - JUST.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
Software Engineering in Robotics Packaging and Deployment of Systems Henrik I. Christensen –
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.
Shell Scripting Introduction. Agenda What is Shell Scripting? Why use Shell Scripting? Writing and Running a Shell Script Basic Commands -ECHO - REM.
Makefiles CISC/QCSE 810. BeamApp and Tests in C++ 5 source code files After any modification, changed source needs to be recompiled all object files need.
Credit Union National Association Installing and Uploading Project Zip Code.
C31102 IT 2 Computer Center Pluakdaengpittayakom
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Installation and Testing.
COP 3330 Notes 1/12. Today's topics Downloading Java and Eclipse Hello World Basic control structures Basic I/O Strings.
Active-HDL Interfaces Debugging C Code Course 10.
CERN - IT Department CH-1211 Genève 23 Switzerland t DB Development Tools Benthic SQL Developer Application Express WLCG Service Reliability.
Running in Peter Gould, Pacific Northwest Research Station Growth-Model User Group Meeting, June 2, 2010.
Outline Comparison of Excel and R R Coding Example – RStudio Environment – Getting Help – Enter Data – Calculate Mean – Basic Plots – Save a Coding Script.
1 Data Manipulation (with SQL) HRP223 – 2010 October 13, 2010 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
The Metadata Tool Custom Metadata Tool Who this tool is for: This tool designed to be used a data management system. This tool is geared more for the.
When I want to work with SQL, I start off as if I am doing a regular query.
Introduction to R Introductions What is R? RStudio Layout Summary Statistics Your First R Graph 17 September 2014 Sherubtse Training.
] COREY PEARSON [ ASUG INSTALLATION MEMBER MEMBER SINCE: 2008 CHAVONE JACOBS [ ASUG INSTALLATION MEMBER MEMBER SINCE: 2003 ALLAN FISHER [ ASUG INSTALLATION.
AE6382 MinGW l The MinGW (Minimalist GNU for Windows) GNU compilers u C/C++ u Fortran 77 u Fortran 95 l Generate native Windows code l User Windows libraries.
All sections to appear here Welcome to my pptPlex Slide Show, this can be executed in either two ways: 1.As a normal PowerPoint slide show: Example hit.
1 How to Install OpenGL u Software running under Microsoft Windows makes extensive use of "dynamic link libraries." A dynamic link library (DLL) is a set.
ASP. ASP is a powerful tool for making dynamic and interactive Web pages An ASP file can contain text, HTML tags and scripts. Scripts in an ASP file are.
Win32 Programming Lesson 19: Introduction to DLLs.
1 Introduction to SQL *Plus Oracle SQL Interface MIS309 Database Systems.
Program Libraries 1. What is a program library? A library is a collection of implementations of behavior, written in terms of a language, that has a well-defined.
1 Data Manipulation (with SQL) HRP223 – 2009 October 12, 2009 Copyright © Leland Stanford Junior University. All rights reserved. Warning: This.
Perl Subroutines User Input Perl on linux Forks and Pipes.
E Copyright © 2006, Oracle. All rights reserved. Using SQL Developer.
 CSC 215 : Procedural Programming with C C Compilers.
Computer Software 1.
C Copyright © 2009, Oracle. All rights reserved. Using SQL Developer.
Required Tools Copyright © 2005 Liferay, LLC All Rights Reserved. No material may be reproduced electronically or in print without written permission from.
CSC 215 : Procedural Programming with C
A step-by-Step Guide For labels or merges
Ashima Wadhwa Assistant Professor(giBS)
Refworks Part I.
Easily retrieve data from the Baan database
CO6025 Advanced Programming
Automating reports with Python
Code is on the Website Outline Comparison of Excel and R
CSCI N207 Data Analysis Using Spreadsheet
Microsoft PowerPoint 2007 – Unit 2
Tutorial 6 PHP & MySQL Li Xu
Using SQL*Plus.
SOFTWARE TECHNOLOGIES
Input and Output Python3 Beginner #3.
ENERGY 211 / CME 211 Lecture 29 December 3, 2008.
Web Application Development Using PHP
Presentation transcript:

Running ORGANON in R Peter Gould and David Marshall Growth Model User Group December 9, 2011

Why run ORGANON in R? R is an excellent environment for analysis. You can do just about any computing task in R. Connects with different data formats (text files, Access databases, SQL databases). Produced excellent graphics, also tables and other types of text output. Many tasks can be automated. If you can do it in R, why do it any other way?

What do we need to get started? Computer with Windows OS R (free download from website). ORGANON source code (download from website). Freeware FORTRAN compiler (gfortran, installed as part of MinGW). A little patience…

Everything’s installed, what do we do now? Make a few changes to the ORGANON source code. Recompile the dlls* using gfortran. Write R scripts to access the dlls. *Dynamic link library: a library of subroutines that can be called by a Windows application.

Changes to the Source Code Compiling with gfortran will make “R- compatible” dlls but a few things need to be changed: Remove or comment out all lines that contain “DLL EXPORT” in these files: PREPARE.FOR EXECUTE2.FOR ORGVOL.FOR WOODQUAL.FOR Change the functions JIFIX and INT4 to LONG in: ORGVOL.FOR VOLEQNS.FOR

You can also make other changes. C RECORD CHANGES WHEN THE DLL IS RECOMPILED SUBROUTINE REVISION(HISTORY) CHARACTER*500 HISTORY HISTORY='Recompiled by Peter Gould Nov 13,2011. Minor changes' 1 //'were made for compatibility with gfortran. No substantive' 2 //' changes were made. Contact: END Example: add a subroutine to identify the new dll:

Compile the dlls using gfortran Compiler is called from the command prompt. gfortran -shared -static-libgcc -o ORGEDIT.dll DIAMCAL.FOR COMFILES.FOR START2.FOR PREPARE.FOR Edit the PATH variable to make the call to the compiler easier.

We can also do all these things with R … ###Download and compile ORGANON dlls ##Peter Gould Dec 6, 2011 ###set a working directory setwd("C:/AdataFolder/ORGANON/R_EXAMPLE") ###download ORGANON download.file(" "ORGSOURCE.ZIP",mode="wb") ##unzip file unzip("ORGSOURCE.ZIP") unzip("EDITDLL SOURCE CODE.ZIP") unzip("RUNDLL SOURCE CODE.ZIP") unzip("VOLDLL SOURCE CODE.ZIP") unzip("WQDLL SOURCE CODE.ZIP") ###edit files allfiles = dir(pattern=".FOR",recursive = T,full.name=T) for(getfile in allfiles){ read1 = read.table(getfile,sep="~",as.is=T,quote="") read1 = read1$V1 ##remove DLL statements read1 = read1[!grepl("DLL_EXPORT",read1)] ##replace JIFIX statements read1 =sub("JIFIX","LONG",read1) ##replace INT4 statements read1 =sub("INT4","LONG",read1) ##re-write the file write(read1,getfile,ncolumns=1) } ##write a batch file to run the compiler send = rep("",5) send[1] = getwd() send[1] = gsub("/","\\\\",send[1]) send[1] = paste("cd",send[1]) send[2] = "gfortran -shared -static-libgcc -o ORGEDIT.dll DIAMCAL.FOR COMFILES.FOR START2.FOR PREPARE.FOR" send[3] = "gfortran -shared -static-libgcc -static-libgfortran -o ORGRUN.dll CRNGROW.FOR DIAGRO.FOR EXECUTE2.FOR GROW.FOR GROWTH_MODS.FOR HTGROWTH.FOR MORTALITY.FOR STATS.FOR SUBMAX.FOR TRIPLE.FOR WHPHG.FOR" send[4] = "gfortran -shared -static-libgcc -o ORGVOL.dll ORGVOL.FOR VOLEQNS.FOR" send[5] = "gfortran -shared -static-libgcc -o ORGWQ.dll COMFILES2.FOR WOODQ2.FOR WOODQUAL.FOR" write.table(send,"COMPILE.BAT",row.names=F,col.names=F,quote=F) system("COMPILE.BAT") Download Unzip files Make needed changes Compile

Making a model run 1.Load data into R. 2.Format data to get it ready to run. 3. Load the dlls. 4.Call the subroutine “prepare” to fill-in heights and crown ratios. 5.Project the stand 1 cycle (5 yrs) by calling “execute”. 6.Load the projected values into the initial values. 7.Repeat steps 4 and 5 until the projection is completed.

Loading the dlls dyn.load() ###load dll ##DEFINE THE DIRECTORY WHERE THE DLLS WERE PLACED setwd("C:/AdataFolder/ORGANON/COMPILE") dyn.load("ORGEDIT.dll", type="Fortran") dyn.load("ORGRUN.dll", type="Fortran") dyn.load("ORGVOL.dll", type="Fortran")

Calling a dll from R: grow =.Fortran("execute", as.integer(CYCLEG), as.integer(VERSION), as.integer(NPTS), as.integer(NTREES1), as.integer(STAGE), as.integer(BHAGE), as.integer(TREENO), as.integer(PTNO), as.integer(SPECIES), as.integer(USER), as.integer(INDS), as.single(DBH1), as.single(HT1), as.single(CR1), as.single(SCR1), as.single(EXPAN1), as.single(MGEXP), All variables must be initialized first: Variables must be “cast” within a call: ## initialize variables VERSION = 1 NPTS = 2 NTREES = 10 STAGE = 40 BHAGE = 37

Example Script Double-click icon to open. Doesn’t work in “slide show” mode.

Speed Test 100 stands 200 trees/stand 20 periods 56.5 seconds

What can we do now? Create an R package for ORGANON. Can also make individual functions available such as “volcal” and “prepare” to impute heights and crown ratios. Create functions to “seamlessly” hand off projections from CONIFERS to ORGANON. Create a working custom version of the main ORGANON growth model. Do simple or elaborate projections/analyses within R.