[gradsusr] Input bash shell set of variables into grads script?

Davide Sacchetti davide.sacchetti at arpal.gov.it
Mon Mar 9 05:43:49 EDT 2020


it should work, it doesn't matter if you export or not pref tw te, it
would matter if grads was started by a subprocess, but is not the case.

You should just transform your main script in a function

Your grads script should start in this way:
function main(args)
pref=subwrd(args,1)
tw=subwrd(args,2)
te=subwrd(args,3)
...
return


On Sun, 2020-03-08 at 18:31 -0800, Uma Bhatt wrote:
> Hi Grads Users,
>  
>  I am trying to automate the processing, calculations, and plotting
> of CFSv2 seasonal forecast products. 
> 
>  I have to loop through different time values and file names of CFSv2
> files and it would be easier to loop through these in a bash shell. I
> am sure you can do it all in grads but I am less clear on how to do
> that. 
> 
>  I am using this version of grads:
> Config: v2.1.0 little-endian readline grib2 netcdf hdf4-sds hdf5
> opendap-grids,stn geotiff shapefile cairo
> Issue 'q config' command for more detailed configuration information
> 
> 
> In my script I loop through 8 ensemble members. The parameter name
> provides the name of when the particular ensemble starts. The tstart
> is the first time that I want to average over and tend is the last
> time I want to average over. I want to use these three variables in
> my grads script wind.gs (not included here for simplicity. 
> I am stuck on the syntax of this line where I run the grads script. I
> want to provide these three variables to wind.gs. I also call these
> variables in this script using $pref, $tw, and $te (something that
> works in fortran, but not here). 
> 
>   grads -bpcx "run wind.gs $pref $tw $te”
> 
> I added an export statement in the upper part of the bash shell but
> that did not work. I am sure I am doing something stupid. 
> Thanks,
> Regards,
> Uma Bhatt
> 
> 
>  My script looks like this:
> 
> #!/bin/bash
> #name=("0100" "0106" "0112" "0118" "0200" "0206" "0212" "0218")
> #tstart=(28 27 26 25 24 23 22 21 )
> #tend=(55 54 53 52 51 50 49 48)
> 
> limit=1
> for ((nvar=0;nvar <= limit; nvar++))
> do
> echo  "$nvar"
> 
> pref=${name["$nvar"]}
> echo  "$pref"
> tw=${tstart["$nvar"]}
> echo  "$tw"
> te=${tend["$nvar"]}
> echo  "$te"
> 
> #export $pref
> #export $tw
> #export $te
> 
> cat << EOR > wind.gs
> 
> …….text snipped…...
> 
> EOR
> 
>   echo "$pref"
>   grads -bpcx "run wind.gs $pref $tw $te"
> 
> # nvar=$(($nvar+1))
> 
> done
> 
> 
> echo "Fin del script"
> 
> ——————
> A brand is what a business does, reputation is what people remember.
> - Ted Rubin
> 
> Uma S. Bhatt
> Professor of Atmospheric Sciences & Geophysical Institute, 
> Director Cooperative Institute for Alaska Research
> physical location: Akasofu (IARC) Building (2158 Koyukuk Drive),
> office location: Room 315 Akasofu
> 
> mailing address:
> University of Alaska Fairbanks
> Geophysical Institute
> 2156 Koyukuk Drive                          
> Fairbanks, Alaska  99775-7320
> 
> tel: (907) 474-2662  fax: (907) 474-2643
> 
> email: usbhatt at alaska.edu
> web: http://ffden-2.phys.uaf.edu/usbhatt/
> 
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr



Attenzione ARPAL ha cambiato indirizzi digitali, i nuovi indirizzi di e-mail sono composti dall'attuale nome.cognome seguito da @arpal.liguria.it, quindi nome.cognome at arpal.liguria.it
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gradsusr.org/pipermail/gradsusr/attachments/20200309/ee6e5c51/attachment.html>


More information about the gradsusr mailing list