[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

20000427: Perl and mcenv (cont.)



>From: Bryan Rockwood <address@hidden>
>Organization: Creighton
>Keywords: 200004271734.e3RHYfG05347 McIDAS Perl CGI BIN

Bryan,

This is a follow-up message that demonstrates one way of writing a Perl
script that will execute multiple McIDAS-X commands in a single environment.

>Greetings.  Quick question that I wanted to run by you folks.  Currently,
>I am writing a CGI script to allow a user to create dynamic Skew-Ts.  I
>would like to write this in Perl, but with my intermediate knowledge of
>the scripting language, have hit a snag.  Setting the environment is
>simple enough, and I can run the individual commands from inside the
>script. My problem is trying to get the mcenv to work.  From what I have
>seen so far, when running a command from inside a Perl script using the
>system call, it will run with the set environment (MCPATH, etc), but only
>last for the length of time it takes to run the executable.  So, if I do
>the following:
>
>print "Creating the McIDAS environment.<br>";
>system "mcenv";
>print "Environment created.<br>Creating Skew-T plot for station:
>72558.<br>";
>system "uaplot.k 72558";
>print "Plot created, now creating gif.<br>";
>system "svgif.k 1 /some/directory/for/webstuff/$skewt_gif_name";
>print "Gif created, exiting the McIDAS environment and displaying
>gif.<hr>";
>system "exit";
>
>it appears that when the system call is made, the mcenv is lost as soon as
>the script moves on.

What is happening is that each 'system' execution is starting up its own
McIDAS environment (defined by a shared memory segment and a set of
McIDAS environment variables) in which the argument of the call is run.

>Any idea here?  Thanks for any input.

We took mcscour.sh, a Bourne shell script distributed with Undiata McIDAS-X,
and transformed it almost line-for-line into a Perl script.  Here is the
result:

#!/usr/local/bin/perl

# Define macros needed for McIDAS-7.X environment
#
# Set MCHOME to be the home directory of your 'mcidas' installation.

# Set MCDATA to be the working directory of your 'mcidas' installation.
# For this example, I will assume that this is /home/mcidas/workdata
#
# Set MCPATH to include MCDATA as its first directory.  I assume
# in this example that McIDAS-X was installed in /home/mcidas.

$MCHOME = "/home/mcidas" ;
$MCDATA = "$MCHOME/workdata" ;
$MCLOG = "$MCDATA/perltest.log" ;
$MCPATH = "$MCDATA:$MCHOME/data:$MCHOME/help" ;

# Setup PATH so that the McIDAS-X executables can be found

$PATH = "$MCHOME/bin:" . $ENV{ 'PATH' } ;

# Set LD_LIBRARY_PATH to include all directories (other than those searched
# by default) that are needed to be searched to find shared libraries.
# For this example, I assume that the shared Fortran library is located
# in /opt/SUNWspro/lib

$LD_LIBRARY_PATH = 
        "/usr/openwin/lib:/opt/SUNWspro/lib:$MCHOME/lib:/usr/lib:/usr/ucblib" ;

# redirect STDOUT and STDERR
open( STDOUT, ">$MCLOG" ) || die "could not open $MCLOG: $!\n" ;
open( STDERR, ">&STDOUT" ) || die "could not dup stdout: $!\n" ;
select( STDERR ) ; $| = 1 ;
select( STDOUT ) ; $| = 1 ;

# cd to the MCDATA directory
chdir( "$MCDATA" ) ;

# Now run 'mcenv' to create a McIDAS-X environment in which all of the
# scouring routines will run.
# NOTES:
#  o you need to modify the parameters in the commands to be run to
#    match your system setup.
#  o if you did not build the XCD component of the Unidata McIDAS-X
#    distribution, you should:
#      o comment out the 'qrtmdg.k GRID' entry below
#      o comment out the 'delwxt.k' entry

$ENV{ 'MCPATH' } = $MCPATH ;
$ENV{ 'PATH' } = $PATH ;
$ENV{ 'LD_LIBRARY_PATH' } = $LD_LIBRARY_PATH;

print <<`EOC`; # execute commands

  mcenv << EOF
    uaplot.k 72558
    frmsave.k 1 /some/directory/for/webstuff/$skewt_gif_name
    exit
  EOF

EOC

# Done
exit( 0 ) ;

The 'print <<`EOC`' syntax says to execute everything down to the EOC.
The 'mcenv << EOF' syntax tells mcenv to run everyting down to the EOF
as a script.  mcenv creates the needed McIDAS-X environment in which
uaplot.k and frmsave.k are run.  It is assumed, of course, that
$skewt_gif_name has been defined previous to its use.

As an aside, you should switch to use of FRMSAVE (frmsave.k) since
SVGIF (svgif.k) will be going away.  FRMSAVE is much more robust than
SVGIF, and its functionality will be increased to be able to save
McIDAS frames in a variety of ways.

I hope that this helps...

Tom Yoksas