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

20021018: writing cgi scripts that run McIDAS for web pages (cont.)



>From: Sridharareddy Duggireddy <address@hidden>
>Organization: USF
>Keywords: 200210162107.g9GL7S107707 McIDAS FRMSAVE

Sridharareddy,

Hi Sridharareddy,

>   Thank you very much. I got one more doubt. I am able to save the images
>in the directory where mcidas is installed using frmsave within the script.
>I am not able to save them in other directories where mcidas is not installed.

I modified the example script I sent you previously to include a specific
directory in which to save the GIF file and had no problems.  Again,
you must specify the fully qualified pathname of the output image, AND
you have to have write permission in the directory where you are trying
to do the save.  Here is my frmsave.k line from mymcrun.sh script:

# Save the display
frmsave.k 1 /home/www/staff/tom/gifs/20022941815.gif

The results of this invocation can be found at:

http://www.unidata.ucar.edu/staff/tom/gifs/20022941815.gif

>What should i do?

Make sure that you give frmsave.k the fully qualified pathname for the 
output file, and that you have write permission in the output directory.

>please help me to solve this problem also along with that problem.

I assume that you got Jim Koermer's email this morning regarding the
technique he uses to run McIDAS applications from a web page.  As you
can see in Jim's email (included at the bottom of this message so
that the information will get into our inquiry tracking system), he
is using a C shell script, not Perl.

>From address@hidden Sun Oct 20 21:16:14 2002
>To: Sridharareddy Duggireddy <address@hidden>
>CC: address@hidden, address@hidden
>Subject: Re: How to display Mcidas images in website

Sridharareddy Duggireddy wrote:
> 
> Hi ,
> 
>    I am Sridhara. I am a graduate assistant in the department of geography
> in the university of south florida.I am trying to design a website to
> display mcidas images. I need to take type of image ,date ,time as input
> from the webpage and display the corresponding image in the web.I have
> seen your website. can you how help me how to do this?
> 
> Regards,
> Sridhara,
> University of South Florida.

Sridhara,

I can provide you with the details on how our page and underlying
scripts are designed. The input is from a standard HTML
(mcidas_sat.html) that passes the information selected to and calls a
short sh CGI. The data passed looks like the information after the "?"
mark in a browser's location bar. The CGI script (gen_mcidas_sat.cgi) in
turn passes the data to and calls a csh script (gen_mcidas_sat) that
strips out the options and then calls another csh script (mk_mcsat) that
executes the McIDAS instructions. You have to set up a user directory
for user "nobody" that has all of the files and data directories needed
by McIDAS and another directory owned by "nobody" to store the images
created. I've appended the scripts below.

Here is "mcidas_sat.html" (see
http://pscwx.plymouth.edu/mcidas_sat.html):

<title>PSC Weather Center McIDAS Satellite Imagery Generator</title>
<body bgcolor=FFFFCE text=000000 link=0000FF vlink=0000FF>
<center><h2><a href="http://vortex.plymouth.edu"; TARGET="_top">PSC
Weather Center</a><br><br><hr></center>
Make Your Own...<br><br><center>
McIDAS GINI Satellite Images</h2></center>
<h3>Enter the type of GINI satellite input, the 4-digit WMO Station ID
(e.g. KCON)or 5-digit WMO Number (e.g. "72518" for Albany, NY) or
Lat,Lon (e.g. 43.77,-71.68, for Plymouth, NH) for the central point of
the image, the zoom factor, the desired image size, and current (leave
blank or enter "0") or the previous number of images to go back (e.g. a
"-12" entry will go back 12 images from the current image in the
database).</h3>
<form method="GET" action="/cgi-bin/gen_mcidas_sat.cgi">
<TABLE BORDER=0 WIDTH=100%>
<TD><b>
<SELECT NAME="type">
<OPTION VALUE="GAN8KVIS">8 km VIS Alaska National
<OPTION VALUE="GAN8KIR">8 km 10.7 um IR Alaska National
<OPTION VALUE="GAR16KWV">16 km WV Alaska National
<OPTION VALUE="GAR2KVIS">2 km VIS Alaska Regional
<OPTION VALUE="GAR8K39">8 km 3.9 um IR Alaska Regional
<OPTION VALUE="GAR8KIR">8 km 10.7 um IR Alaska Regional
<OPTION VALUE="GAR8K12">8 km 12.0 um IR Alaska Regional
<OPTION VALUE="GAN8KWV">8 km WV Alaska Regional
<OPTION VALUE="GE1KVIS">1 km VIS East CONUS
<OPTION VALUE="GE2KVIS">2 km VIS East CONUS
<OPTION VALUE="GE4KVIS">4 km VIS East CONUS
<OPTION VALUE="GE4K39">4 km 3.9 um IR East CONUS
<OPTION SELECTED VALUE="GE4KIR">4 km 10.7 um IR East CONUS
<OPTION VALUE="GE4K12">4 km 12.0 um IR East CONUS
<OPTION VALUE="GE8KWV">8 km WV East CONUS
<OPTION VALUE="GHN14KIR">14 km 10.7 um IR Hawaii National
<OPTION VALUE="GHN14KVIS">14 km VIS Hawaii National
<OPTION VALUE="GHN14KWV">14 km WV Hawaii National
<OPTION VALUE="GHR1KVIS">1 km VIS Hawaii Regional
<OPTION VALUE="GHR4K39">4 km 3.9 um IR Hawaii Regional
<OPTION VALUE="GHR4KIR">4 km 10.7 um IR Hawaii Regional
<OPTION VALUE="GHR4K12">4 km 12.0 um IR Hawaii Regional
<OPTION VALUE="GHR8KWV">8 km WV Hawaii Regional
<OPTION VALUE="GNC24KVIS">24 km VIS Nhem Composite
<OPTION VALUE="GNC24K39">24 km 3.9 um IR Nhem Composite
<OPTION VALUE="GNC24KIR">24 km 10.7 um IR Nhem Composite
<OPTION VALUE="GNC24K12">24 km 12.0 um IR Nhem Composite
<OPTION VALUE="GNC24KWV">24 km WV Nhem-Composite
<OPTION VALUE="GPN8KVIS">8 km VIS Puerto Rico National
<OPTION VALUE="GPN8KIR">8 km 10.7 um IR Puerto Rico National
<OPTION VALUE="GPN8KWV">8 km WV Puerto Rico National
<OPTION VALUE="GPR1KVIS">1 km VIS Puerto Rico Regional
<OPTION VALUE="GPR4K39">4 km 3.9 um IR Puerto Rico Regional
<OPTION VALUE="GPR4KIR">4 km 10.7 um IR Puerto Rico Regional
<OPTION VALUE="GPR4K12">4 km 12.0 um IR Puerto Rico Regional
<OPTION VALUE="GPR8KWV">8 km WV Puerto Rico Regional
<OPTION VALUE="GSN8KVIS">8 km VIS US National Composite
<OPTION VALUE="GSN8K39">8 km 3.9 um IR US National Composite
<OPTION VALUE="GSN8KIR">8 km 10.7 um IR US National Composite
<OPTION VALUE="GSN8K12">8 km 12.0 um IR US National Composite
<OPTION VALUE="GSN8KWV">8 km WV US National Composite
<OPTION VALUE="GW1KVIS">1 km VIS West CONUS
<OPTION VALUE="GW2KVIS">2 km VIS West CONUS
<OPTION VALUE="GW4KVIS">4 km VIS West CONUS
<OPTION VALUE="GW4K39">4 km 3.9 um IR West CONUS
<OPTION VALUE="GW4KIR">4 km 10.7 um IR West CONUS
<OPTION VALUE="GW4K12">4 km 12.0 um IR West CONUS
<OPTION VALUE="GW8KWV">8 km WV West CONUS
</SELECT>
Station ID, WMO#, or Lat,Lon:</b> <INPUT NAME=id SIZE=13 MAXLENGTH=13>
<SELECT NAME="mag">
<OPTION VALUE="4">Zoom in x 4
<OPTION VALUE="3">Zoom in x 3
<OPTION VALUE="2">Zoom in x 2
<OPTION SELECTED VALUE="1">No Zoom
<OPTION VALUE="-2">Zoom out x 2
<OPTION VALUE="-3">Zoom out x 3
<OPTION VALUE="-4">Zoom out x 4
<OPTION VALUE="-5">Zoom out x 5
<OPTION VALUE="-6">Zoom out x 6
<OPTION VALUE="-7">Zoom out x 7
</SELECT>
<SELECT NAME="size">
<OPTION SELECTED VALUE="480x640">640x480
<OPTION VALUE="600x800">800x600
<OPTION VALUE="768x1024">1024x768
</SELECT>
<b>Current/Previous:</b> <INPUT NAME=imgnum SIZE=3 MAXLENGTH=3>
</TABLE>
<p><center><input value="Click Here to View Diagram/Data" type="submit">
<input type="reset" value="Reset"></center>
</form>
<hr>
<h3>Notes:<ul>
<li>If no identification information is specified, the NW portion of the
image will be displayed by default.
<li>Check a <a href="stations_sat.html">map</a> or this <a
href="sao_all.cty">list</a> for possible station identifiers.
<li>If you get vertical banding, the information is in the process of
being updated. Try loading again in a few minutes or select the previous
image with a "-1" in the "Current/Previous" box.
<li>Most data are updated at approximately 15 minute intervals and we
currently keep data back through 24 hours (at most -95 images, although
often somewhat less).</ul>
<hr>
</body>
  
################################# END mcidas_sat.html
###################################

The above HTML call /cgi-bin/gen_mcidas_sat.cgi. This is the
gen_mcidas_sat.cgi sh script:

#!/bin/sh

# disable filename globbing
set -f

cd /usr/local/lib/httpd/cgi-bin
CAT=/bin/cat

echo "Content-type: text/html"
echo "Pragma: no-cache"
echo ""

PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/local/lib/httpd/cgi-bin:.;
export PATH
if [ -x $CAT ]; then

                cat << EOM
<TITLE>McIDAS GINI Satellite Image from PSC</TITLE>
<body bgcolor=FFFFCE text=000000 link=0000FF vlink=0000FF>
<center><h2>McIDAS GINI Satellite Image from PSC</h2>
EOM
  echo \<PRE\>
  /usr/local/lib/httpd/cgi-bin/gen_mcidas_sat $QUERY_STRING

else
        echo Cannot find cat on this system.
fi

################################ END gen_mcidas_sat.cgi
##############################

The above cgi call gen_mcidas_sat:

#!/bin/csh -f
#
# gen_mcidas_sat  This script generates satellite images of GINI
satellite data
#                 using McIDAS
#
# usage:  gen_mcidas_sat
#
######################################################################################
#
setenv PATH
/usr/bin:/etc:/usr/sbin:/usr/ucb:/bin:/usr/X11R6/bin:/sbin:/usr/local/bin:/home/mcidas/bin:.
setenv MCPATH /home/nobody/mcidas/data:/home/mcidas/data:/data/mcidas
#
limit cputime 30
#
#echo $1 was passed to gen_mcidas_sat
set type=`echo $1 | cut -f1 -d"&" | cut -f2 -d"="`
set test=`echo $type | grep WV`
#echo test is $test
if ( "$test" == "" ) then
        set enh="EU=IMAGE"
else
        set enh="EU=H2O"
endif
set test=`echo $1 | cut -f2 -d"&"`
if ("$test" == "id=") then
#       echo "You forgot to enter a station identifier or location--go
back and try again!"
#       Use default
        set ident=""
        goto here2
endif
set test=`echo $1 | cut -f2 -d"&" | cut -f2 -d"="`
#echo test is $test
set lat=`echo $test | cut -f1 -d"%"`
#echo lat is $lat
if ( "$test" == "$lat" ) then
        goto here1
else
        set lon=`echo $test | cut -f2 -d"%" | cut -f2 -d"C" | cut -f2
-d"-"`
#       echo lon is $lon
        set ident="LATLON=$lat $lon"
endif
goto here2
here1:
if ( "$test" == "kply" | "$test" == "KPLY" ) then
        set ident="LATLON=43.77  71.68"
else
        set ident="STA=$test"
endif
here2:
#echo ident is $ident
set zoom="MAG="`echo $1 | cut -f3 -d"&" | cut -f2 -d"="`
#echo zoom is $zoom
set geom=`echo $1 | cut -f4 -d"&" | cut -f2 -d"="`
#echo geom is $geom
set dx=`echo $geom | cut -f2 -d"x"`
#echo $dx
#
set imgnum=`echo $1 | cut -f5 -d"&" | cut -f2 -d"="`
if ( "$imgnum" == "" || "$imgnum" == "0" ) then
        set imgnum=0
        goto SKIP
endif
set check=`echo $imgnum | cut -c1`
#echo check is $check
if ( "$check" == "-" ) then
        goto SKIP
else
        echo "The Current-Previous box entry must be blank or 0 (zero)
or a negative number, try again!"
        exit
endif
SKIP:
#
# Now set up default file paths
#
set homedir=/home/nobody # This directory must be owned by user "nobody"
set labdir=/home/wxp/gifs
set outdir=/usr/local/lib/httpd/htdocs/gifs  # This directory must be
owned by user "nobody"
#
# Create GIF
#
set gifname=`date +%y%m%d%H%M%S`".gif"
#echo $gifname
set outfile1=tmp_$gifname
set outfile2=$gifname
#
cd $homedir
#echo "$type.$imgnum" "$ident" "$zoom" "$enh"
mcenv -g 32 -i 128 -f "$geom" mk_mcsat "$type.$imgnum" "$ident" "$zoom"
"$enh" "$outdir
/$outfile1" > $outdir/out.tmp
cd $outdir
rm out.tmp
#
# Add PSC logo
#
set label=$labdir/psc"$dx".pnm
giftopnm $outfile1 > $outfile1.pnm
pnmcat -tb $label $outfile1.pnm | ppmtogif > $outfile2
#
rm $outfile1 $outfile1.pnm
set num=`cat num_maps`
@ num += 1
echo $num > num_maps
echo "<img src="../gifs/$gifname">"
#
exit

################################## END gen_mcidas_sat
#################################

The above script through the McIDAS "mcenv" command call sthe script,
"mk_mcsat" in the /home/nobody directory (owned by user, "nobody"). Here
is mk_mcsat:

#! /bin/csh -f
#
# mk_mcsat    Takes input and build a McIDAS satellite image
#
#
# Run with "mcenv -f 480x640 mk_mcsat "GE4KIR" "LATLON=43.77 71.68"
"MAG=1" "EU=IMAGE" # "/home/jim/test.gif" command (all on one line)
#
##########################################################################################
#
# echo got to mk_mcsat
# echo this was passed $1 $2 $3 $4 $5
#
# set McIDAS environment
#
if ( ! ${?MCPATH} ) then
  setenv MCDATA $HOME/mcidas/data
  setenv MCPATH
$HOME/mcidas/data:/home/mcidas/data:/data/mcidas-c:/home/mcidas/help
  setenv MCGUI /home/mcidas/bin
  setenv MCTABLE_READ "$MCDATA/MCTABLE.TXT;$MCHOME/data/ADDESITE.TXT"
  setenv MCTABLE_WRITE "$MCHOME/data/ADDESITE.TXT"
endif
#
/home/mcidas/bin/dataloc.k ADD RTGINI 158.136.73.192
#/home/mcidas/bin/dataloc.k ADD RTGINI ADDE.UNIDATA.UCAR.EDU # Backup
site
/home/mcidas/bin/imgdisp.k RTGINI/"$1" 1 "$3" "$4" $2
/home/mcidas/bin/map.k H
/home/mcidas/bin/bar.k
/home/mcidas/bin/frmsave.k 1 "$5"
#
exit
#
#################################### END mk_mcsat
###################################

Hopefully, you know something about unix programming scripts. If so, you
should be able to follow the above scripts. They contain man commented
out echo commands. I uncommented and used these for debugging purposes.
I hope this helps.

Jim
--
James P. Koermer             E-Mail: address@hidden
Professor of Meteorology     Office Phone: (603)535-2574
Natural Science Department   Office Fax: (603)535-2723
Plymouth State College       WWW: http://vortex.plymouth.edu/
Plymouth, NH 03264

Tom


>From address@hidden Mon Oct 21 13:33:20 2002
>Subject: 20021020: How to display Mcidas images in website (cont.)

Hi Jim,

I just wanted to send my thanks for the help you provided to Sridhara
of the University of South Florida.  This is the kind of interaction
that I think makes Unidata a true community enterprise!

Cheers,

Tom

>From address@hidden Mon Oct 21 13:34:41 2002
>To: Unidata Support <address@hidden>
>Subject: Re: 20021018: writing cgi scripts that run McIDAS for web pages 
>(cont.)

Hi ,

  I am looking at the scripts sent by Jim.I will mail you if i have any
doubts.Thank you for your cooperation.

Thank You,
Sridhara.


NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.