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

Marston Johnston shejo284 at gmail.com
Thu Oct 19 11:42:47 MDT 2017


It would help if you did a printVarSummary() on the problem array.

 

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Marston S. Ward, PhD

Department of Earth Sciences

University of Gothenburg, Sweden

Email: marston.johnston at gu.se

SkypeID: marston.johnston 

Phone: +46-31-7864901 

Only the fruitful thing is true!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

 

From: ncl-talk <ncl-talk-bounces at ucar.edu> on behalf of Prashanth Bhalachandran <prashanth.bhalachandran at gmail.com>
Date: Thursday, 19 October 2017 at 19:31
To: <ncl-talk at ucar.edu>
Subject: [ncl-talk] Question regarding the transfer of integer values from shell to NCL

 

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”








_______________________________________________ ncl-talk mailing list ncl-talk at ucar.edu List instructions, subscriber options, unsubscribe: http://mailman.ucar.edu/mailman/listinfo/ncl-talk 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171019/7c362a3f/attachment.html>


More information about the ncl-talk mailing list