[Marxan] (R) Scripts to run Marxan in batch mode

Venter, Oscar oscar.venter at jcu.edu.au
Thu Jun 20 16:10:00 EST 2013


Hi Richard,

Can't help you with R, but I usually batch process marxan from Excel using VBA. There's surely a far more elegant way to do what you want (and I look forward to other posts on this), but what works for me is to:


1)      Use whatever code to create the input files. I'll usually line up a number of Marxan runs in parallel, depending on how many processors I have and whether I want some free to do other work.


2)      Get Marxan running using:

        'run marxan
        x = "C:\MarZoneRuns\" + y 'path for launching marxan
        ChDir x 'sets the directory in excel
        Set WshShell = VBA.CreateObject("WScript.Shell")
        WshShell.run "Marxan.exe < input.dat", 1, False


3)      Use a wait loop to let Marxan complete the runs, which requires pretesting to see how long it takes.


4)      Terminate Marxan using



Sub TerminateMarxan()

     '---------------------------------------------------------------------------------------

     ' Terminates the exe process specified.

     ' Uses WMI (Windows Management Instrumentation) to query all running processes

     ' then terminates ALL instances of the exe process held in the variable strTerminateThis.

     '---------------------------------------------------------------------------------------

Dim lExplhwnd As Long 'used for closing window

Dim strTerminateThis As String 'The variable to hold the process to terminate

Dim objWMIcimv2 As Object, objProcess As Object, objList As Object

Dim intError As Integer



'Process to terminate - you could specify and .exe program name here

strTerminateThis = "Marxan.exe"



'Connect to CIMV2 Namespace and then find the .exe process

Set objWMIcimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

Set objList = objWMIcimv2.ExecQuery("select * from win32_process where name='" & strTerminateThis & "'")

For Each objProcess In objList

            intError = objProcess.Terminate 'Terminates a process and all of its threads.

             'Return value is 0 for success. Any other number is an error.

            If intError <> 0 Then Exit For

Next



'ALL instances of exe (strTerminateThis) have been terminated

Set objWMIcimv2 = Nothing

Set objList = Nothing

Set objProcess = Nothing



End Sub



5)      Use whatever code to read in a summarize results

Cheers,

Oscar


From: marxan-bounces at lists.sps.uq.edu.au [mailto:marxan-bounces at lists.sps.uq.edu.au] On Behalf Of Richard Schuster
Sent: Thursday, 20 June 2013 12:54 PM
To: marxan at lists.science.uq.edu.au
Subject: [Marxan] (R) Scripts to run Marxan in batch mode

Hello all,

As I am fairly new to Marxan and was wondering the following:

I usually do most of my data analysis in/from R and was wondering if there were by any chance R scripts available to run Marxan in batch mode/loops? I was thinking of putting something together myself but wanted to check with the list first as I figured with that many people using Marxan there ought to be someone who has already done this before.

If anyone uses a different scripting language instead I would be very grateful if you could share example code as well so I can get an idea of how you approach this.

Thanks very much,
Richard




--

Richard Schuster

PhD Candidate

Centre for Applied Conservation Research

Faculty of Forestry

University of British Columbia



+1 604 822 1256

mail at richard-schuster.com<mailto:ubc at richard-schuster.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.science.uq.edu.au/pipermail/marxan/attachments/20130620/d9efebce/attachment-0001.html 


More information about the Marxan mailing list