#!/usr/bin/perl # $Id: sis.pl, v 1.0 2007/09/27 WS Harpole, modified from tacg script written by Harry Mangalam # usage: this is a cgi that is supposed to respond to input provided by the form.html page. # the following vars are set automagically from the installation script # or can be manually edited if you continue to have problems. ############################################################################## $server = "sis.bio.uci.edu"; # What YOUR server is $tmppath = "/home/sis/public_html/tmp"; # Where you want to store your temp stuff $sisapp = "/home/sis/public_html/cgi-bin/sis"; # The app name of the exe $Rapp = "/home/sis/public_html/cgi-bin/plot.r"; # the R script $Rbin = "/home/sis/bin"; # the R command path ############################################################################## #use strict; use vars qw( @fl_ary $PATTERN $fl $card $cardmem $cardports $systemram $status $readahead $disks $lc $N @L %idline $dataline $NData @Data $fc @ID $Nid $Tvar $filesystem %timvars $key $raidtype $date $keymash ); use CGI qw/:standard :html3/ ; use Time::localtime; $tm = localtime; $| =1; # set autoflush to true. print STDERR "INC = @INC\\nn"; print header, start_html('SIS Results'); # Basically have to parse the input via param() calls, build the commandline # submit it, perhaps grab the results and munge it into a form to be sent back # to the user. # get the PID of this process, make the directory, based on an identifiable root and the PID $suffix = $$ . time; # cat time to PID to make it more fine-grained $dirname = $tmppath . "/sis" . $suffix; mkdir $dirname, 666; chmod 0777, $dirname; #Open the sis error log file #$logname = $dirname . "/sis.errlog." . $suffix; # the output of this is the input to sis #open(LOG, ">$logname") or die "Can't open the damn error log file: $logname!\n"; # What should be done here is that if the ERROR LOG button is clicked, it should write something # to the errror log at every logic step to show how far it gets when it dies #print LOG "this was an error because the wrong value was input\n"; #print "this was an error because the wrong value was input\n"; # ================ And process the input - get params ========================= #print "

Input Parameter Values


" ; # species 1=exotic, species 2=native $SP1DIS = param('SP1DIS'); # species dispersal: 0=local, 1=global if (!defined $SP1DIS) { $SP1DIS = 1; } #print "

SP1DIS = $SP1DIS

" ; $SP2DIS = param('SP2DIS'); # species dispersal: 0=local, 1=global if (!defined $SP2DIS) { $SP2DIS = 0; } #print "

SP2DIS = $SP2DIS

" ; $SP1FB = param('SP1FB'); # species positive feedback strength: 0=none, 100=overwhelmingly strong if (!defined $SP1FB) { $SP1FB = 30; } if ( $SP1FB <0 || $SP1FB >100 ) { die "species 1 feedback must be bewteen 0 and 100"; } #else { print "

SP1FB = $SP1FB

" ; } $SP2FB = param('SP2FB'); # species positive feedback strength: 0=none, 100=overwhelmingly strong if (!defined $SP2FB) { $SP2FB = 30; } if ( $SP2FB <0 || $SP2FB >100 ) { die "species 2 feedback must be bewteen 0 and 100"; } #else { print "

SP2FB = $SP2FB

" ; } $SP1MORT = param('SP1MORT'); # species percent mortality: 0=immortal, <100=perennial, 100=annual if (!defined $SP1MORT) { $SP1MORT = 5; } if ( $SP1MORT <0 || $SP1MORT >100 ) { die "species 1 mortality must be bewteen 0 and 100"; } #else { print "

SP1MORT = $SP1MORT

" ; } $SP2MORT = param('SP2MORT'); # species percent mortality: 0=immortal, <100=perennial, 100=annual if (!defined $SP2MORT) { $SP2MORT = 5; } if ( $SP2MORT <0 || $SP2MORT >100 ) { die "species 2 mortality must be bewteen 0 and 100"; } #else { print "

SP2MORT = $SP2MORT

" ; } $SCENARIO = param('SCENARIO'); # initial soil feedback state: 0=neutral, 1=exotic (spp1), 2=native (spp2) if (!defined $SCENARIO) { $SCENARIO = 1; } #print "

SCENARIO = $SCENARIO

" ; $INITABUND = param('INITABUND'); # initial percent natives if (!defined $INITABUND) { $INITABUND = 80; } if ( $INITABUND <1 || $INITABUND >100 ) { die "initial native abundance must be bewteen 1% and 99%"; } #else { print "

INITABUND = $INITABUND

" ; } # check below for 100 percent case and no external exotic seed source $SEEDRATIO = param('SEEDRATIO'); # ratio of exotic to native seed production: 1= default (values: 1000, 100, 10, 1, 0.1, 0.01, 0.001) if (!defined $SEEDRATIO) { $SEEDRATIO = 1; } #print "

SEEDRATIO = $SEEDRATIO

" ; $EDGE = param('EDGE'); # 0=absorbing boundaries, 1=one edge all exotics (spp1) if (!defined $EDGE) { $EDGE = 0; } if ($EDGE eq "on") {$EDGE1=1; } else {$EDGE1=0; } #print "

EDGE = $EDGE

" ; # only allow 100 percent native if there is external source of exotics if ( $INITABUND ==100 && $edge==0 ) { $INITABUND = 99; } $DIM = param('DIM'); # dimension of matrix (not counting the edges) if (!defined $DIM) { $DIM = 50; } #print "

DIM = $DIM

" ; $TMAX = param('TMAX'); # time steps if (!defined $TMAX) { $TMAX = 100; } #print "

TMAX = $TMAX


" ; # ============================ End getting params ============================== # So now we have all the stuff needed to run the model # Build the results header 1st # start off the commmandline with the full path of the app (set above) and the HTML flag #set up an error file to accept the errors from sis, $sisErrFile = $dirname . "/sisErr"; # for the sisi error log, can simply start a log output from here to be chatty as we want # What do we need to have in the Results section (compare with V2) # Author, version number of sisi, sis, URL of home page, server URL, ################# Build the sis command line with all the options needed #################### # So now we build the commmand line with the full path of the app (set above) $siscmdline = $sisapp; # /home/public_html/sis (or whatever - where the app lives) $siscmdline .= " $SP1DIS $SP2DIS $SP1FB $SP2FB $SP1MORT $SP2MORT $SCENARIO $INITABUND $SEEDRATIO $EDGE1 $DIM $TMAX $suffix"; #print "

Commandline is: $siscmdline


"; # so at this point. the commandline is finished and merely has to be executed, print "

Files written to: $dirname


" ; # and this is how I punt that file back to the user just using backtics to execute it.... for ($r=0; $r < $FONT; $r++) { print ""; } print "
", `$siscmdline`, "
\n\n"; #if (defined $ERRFile){ # print "

Errors from sis

", `cat $sisErrFile;`, "
"; #} for ($r=0; $r < $FONT; $r++) { print "
"; } # Run the R script to make the PDF figure from the C output files system "cd $dirname; $Rbin/R --no-save --quiet --slave < $Rapp";# > $sisErrFile"; print "
» View output pdf here: sisout.pdf
"; #printf "

%02d-%02d-%04d (DD-MM-YYYY).

", $tm->mday, ($tm->mon)+1, ($tm->year)+1900; #and delete all the files that are no longer needed unlink "$sisErrFile"; print "\n\n"; #end of form, body, html