Running in

14
Running in Peter Gould, Pacific Northwest Research Station Growth-Model User Group Meeting, June 2, 2010

description

Running in. Peter Gould, Pacific Northwest Research Station Growth-Model User Group Meeting, June 2, 2010. Acknowledgements. I “borrowed” previous work on the implementation of the ORGANON dlls in Excel from Mark Hanus and Sean Garber . - PowerPoint PPT Presentation

Transcript of Running in

Page 1: Running                                    in

Running

in

Peter Gould, Pacific Northwest Research StationGrowth-Model User Group Meeting, June 2, 2010

Page 2: Running                                    in

Acknowledgements• I “borrowed” previous work on the implementation of the ORGANON dlls in Excel from Mark Hanus and Sean Garber.

• Mark Hanus helped troubleshoot problems with ORGANON8.4.

• David Hann and other ORGANON developers for providing DLLs.

Page 3: Running                                    in

Why run ORGANON in R?

• R users don’t need to switch environments or interfaces to run different programs (on cutting and pasting).

• Can combine projections and summaries.

• Can automate processing (1 or 100,000 stands).

Page 4: Running                                    in

How to connect to ORGANON

DLL (Dynamic-Link Library): a program that can be called by another program. Often used to create, manipulate, and update variables.

ORGANON has three dlls:ORGVOL.dllORGEDIT.dllORGRUN.dll

Page 5: Running                                    in

Can we call the dlls directly from R?(Yes, in theory)

Should I be worried?

R sees the dll!

R sees the functions in the dll!!

R CRASHES!!!

Page 6: Running                                    in

Alternative Approach• ORGANON can be run in MS EXCEL using the dlls.

•Mark Hanus did the original coding in VB.• Sean Garber added more features• I updated it for Version 8.4 (with help from Mark Hanus) and added features for input/output.

• R can control EXCEL using the rcom package (Thomas Baier (2008). rcom: R COM Client Interface and internal COM Server. R package version 2.0-4.)

• runOrg8.4 runs ORGANON via EXCEL.

Page 7: Running                                    in

What do you need?• ORGANON DLLs and RUN_ORGANON8.4.xls need to be installed in: C:\Program Files\ORGANON\DLL

•R needs to be installed (I’m using version 2.9.1) AND the rcom package.

• Excel need to be installed and macros enabled (I’m using Excel2007).

• The runOrg8.4 function needs to be loaded.

Page 8: Running                                    in

Input Formats

•Optional: HT, CR

•Tree list (use the exact variable names)

Page 9: Running                                    in

Input Formats

•Header info (use the exact variable names)

Optional: USEGEN, DBHGAIN, HTGAIN, USESNC, RETAINYRS.

Page 10: Running                                    in

Process for runOrg8.41.Opens the Excel workbook (set to be

invisible). 2.Loops through the stands

1.Updates header information2.Pastes the input treelist into the worksheet3.Runs ORGEDIT (adds heights, crown ratios, etc.)4.Runs ORGRUN (the actual projections)5.Copies output back to R

3.Closes Excel and returns to R

Page 11: Running                                    in

Run the function and output

Page 12: Running                                    in

Example: Two stands, 30 plots / stand , 10 trees / plot, projected for 10 cycles (50 yrs). Elapse time: 5.5 seconds

Page 13: Running                                    in

The Excel Workbook

Microsoft Office Excel 97-2003 Worksheet

Double-click above to open and then save with this name and path:

C:\Program Files\ORGANON\DLL\RUN_ORGANON8.4.xls

Use Excel1997-2003 format.

Page 14: Running                                    in

The R Code (double-click below to open)

RunOrg8.4 with example.txt