[ncl-talk] Question regarding the transfer of integer values from shell to NCL

Prashanth Bhalachandran prashanth.bhalachandran at gmail.com
Thu Oct 19 11:31:41 MDT 2017


Dear NCL team, 
Greetings. 

I have a shell script that does the following : Read from a text file which has a list of dates (yyyyddmm) format and times. For example, the first column in the text represents the date and the second the time. 
20121030        13     73.34     51.77    -21.57

My shell script reads in the first and second column and stores those values and passes off as arguments to my NCL script. My NCL script reads the first argument as the filename and the second as time. I use this time as an index in several of my arrays in my NCL script since my variable dimensions are time x lev x lat x lon. 
The problem here is that shell reads these values as strings and I am unable to get it as an integer, which is compulsory if I want to use it as an array index. Please see the below error. 
Can one of you please guide me as to how I pass this value as an integer? 

Many thanks, 
Prashanth 

Error: 
fatal:Illegal subscript. Subscripts must be integer when not using coordinate indexing

My code (I’m attaching the entire code in case you want to have a look, but I am pasting the necessary portions here) : 

#!bin/bash
file="/scratch/conte/s/sbhalach/DATA/RI_compute/CatRW2030.txt"
while read f1 f2 f3 f4;
do

  export dirname=$(echo $f1)00post
  echo $dirname
  cd $dirname
  export filename=${f1}.nc
  export time=$f2

#*************************************************************************
  cat > varcalc.ncl << EOF 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  

 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
 load "/scratch/lustreD/s/sbhalach/DATA/func_center.ncl"
 load "/scratch/lustreD/s/sbhalach/DATA/func_rtheta.ncl"

 a    = addfile(filename,"r")
 u10  = a->u10
 v10  = a->v10
 slp  = a->slp
 u    = a->u
 v    = a->v
allvars   = new((/40/),float)

slpsub       = slp(time,0,:,:) 
; Note that the time here is taken as string and hence the error. I obviously tried the toint() and strongpoint() functions but then the function only returns missing values. 
.
.
. 
;;;;;;;;;;;;;;;;;;;;;; Write to a netcdf file ;;;;;;;;;;;;;;;;;;

  system("rm -f $f1_$f2_allvars.nc")
  ncdf = addfile("$f1_$f2_allvars.nc","c")
  ncdf->allvars = allvars
 
EOF

#*************************************************************************

 ncl -n 'filename = "$filename"' 'time = "$time"' varcalc.ncl
 mv $f1_$f2_allvars.nc ../
 cd ../
 done <"$file”




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171019/add9428b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wrapper_variables.sh
Type: application/octet-stream
Size: 9988 bytes
Desc: not available
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171019/add9428b/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171019/add9428b/attachment-0001.html>


More information about the ncl-talk mailing list