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

Kishore Ragi kishoreragi at gmail.com
Mon Mar 9 02:44:24 EDT 2020


Dear Uma S. Bhatt,

Why don't you create your wind.gs file automatically in the Shell script
and then run grads subsequently in the same script?
See the following script of mine. I hope it helps you to write your own.

#!/bin/bash

MODEL=/home/kishore/Desktop/WRFV3.8.1

dm=02
yr=2018
mn=01
sdy=01
edy=02
sh=00
eh=18


STATION=( GNDKT HRTHI ROYAL )
for stn in "${STATION[@]}"
do

if [ "$stn" = "GNDKT" ]
then
hgt=0.540,0.560,0.580

elif [ "$stn" = "HRTHI" ]
then
hgt=0.783,0.803,0.823

else
hgt=0.560,0.580,0.600

fi

cat << Eof > ${yr}-${mn}-${sdy}   #You can change your wind.gs file name
according to your inputs inside.
\$RP_INPUT

&datetime
 start_date = '${yr}-${mn}-${sdy}_${sh}:00:00',
 end_date   = '${yr}-${mn}-${edy}_${eh}:00:00',
 interval_seconds = 3600,
 tacc = 0,
 debug_level = 1,
/

&io
 input_root_name =
'${MODEL}/WRFV3/test/em_real/wrfout_d${dm}_${yr}-${mn}-${sdy}*'  #you can
bring in automatically to your wind.gs grads code.
 output_root_name =
'${MODEL}/SITES/${stn}_${mn}-${sdy}'
#you can bring in automatically to your wind.gs grads code.
plot = 'list'
fields = 'wdir,wspd'
mercator_defs = .true.
/
split_output = .true.
frames_per_outfile = 2


&interp
!interp_method = -1, ! 0 is model levels, -1 is nice height levels, 1 is
user specified pressure/height

interp_method = 1,
interp_levels = ${hgt},    #This one you can bring in automatically to your
wind.gs grads code.

/

\$END
Eof

done

Then you can run the following
grads -bpcx "run new_created_name.gs <http://wind.gs>"

Hope this helps!

Regards,
Kishore

*Department of Chemistry,*

*National Institute of Technology, Rourkela,*

*India- 769008*





*Phone: +91-8908671881http://www.researchgate.net/profile/Kishore_Ragi
<http://www.researchgate.net/profile/Kishore_Ragi>https://in.linkedin.com/in/kishoreragi
<https://in.linkedin.com/in/kishoreragi>*


On Mon, Mar 9, 2020 at 8:33 AM Uma Bhatt <usbhatt at alaska.edu> 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 <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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gradsusr.org/pipermail/gradsusr/attachments/20200309/eda945c7/attachment-0001.html>


More information about the gradsusr mailing list