[ncl-talk] Question regarding the transfer of integer values from shell to NCL
Marston Johnston
shejo284 at gmail.com
Thu Oct 19 12:37:03 MDT 2017
Oh forgot the reply to all,
If time is a single value then is it actually easier to call it via the environment:
export time=$time; ncl ….my_script.ncl
Then in the ncl script: time = toint(getenv(time))
I use this method all the time.
/M
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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: Prashanth Bhalachandran <prashanth.bhalachandran at gmail.com>
Date: Thursday, 19 October 2017 at 20:32
To: Marston Johnston <shejo284 at gmail.com>
Cc: ncl-talk <ncl-talk at ucar.edu>, Barry Lynn <barry.h.lynn at gmail.com>
Subject: Re: [ncl-talk] Question regarding the transfer of integer values from shell to NCL
Marston,
It is being passed from Bash, yes. But it is not an array. The bash script reads one line from the text file containing the file name and the time, passes this to NCL, writes the output to a NETCDF file for that particular file and time and moves to the next file and list. So, as far as NCL is concerned, the time is a single value. When I tested the NCL script, I simply gave it
Filename = “20141009.nc”
Time = 40
And the script works perfectly fine.
Barry : This is not an array of time values where some of them are missing. The missing value is because of the string passed. In this case, every value will be missing. The output of printMinMax(time,False) is as follows :
Variable: time
Type: integer
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
Number Of Attributes: 1
_FillValue : -2147483647
min=-2147483647 max=-2147483647
On Oct 19, 2017, at 11:27 AM, Barry Lynn <barry.h.lynn at gmail.com> wrote:
Hi:
printMinMax(time,False) shows no min/max?
You can handle missing values by checking for them with "ismissing." If it is true, then you can't use the time variable.
Barry
On Thu, Oct 19, 2017 at 9:20 PM, Prashanth Bhalachandran <prashanth.bhalachandran at gmail.com> wrote:
Marston,
I did this previously too. The problem is as follows. It is being assigned a missing value.
time := stringtointeger(time)
printVarSummary(time)
print(time)
Variable: time
Type: integer
Total Size: 4 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
Number Of Attributes: 1
_FillValue : -2147483647
-2147483647
On Oct 19, 2017, at 11:16 AM, Marston Johnston <shejo284 at gmail.com> wrote:
Correction:
Why not convert time once at the beginning?
time := stringtointeger(time)
/M
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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: Prashanth Bhalachandran <prashanth.bhalachandran at gmail.com>
Date: Thursday, 19 October 2017 at 20:08
To: Marston Johnston <shejo284 at gmail.com>
Cc: <ncl-talk at ucar.edu>
Subject: Re: [ncl-talk] Question regarding the transfer of integer values from shell to NCL
Marston,
The problem is I have several arrays where time is one of the variables as you will see in the attached code.
For example,
u10 = a->u10 is [76 times] x [801 lats] x [810 lon]
u = a->u. Is [76 times] x [11 levels] [801 lats] x [810 lon]
Using the input argument from the shell script, I am reading these variables at particular times. That is, the text file contains the name of the file and the particular time.
Therefore, when I use it like this :
speed(:,:) = wind_speed(u10(time,0,:,:),v10(time,0,:,:)) * toknots
Or any such line, there will be an error primarily because the time input from the shell script is a string. As you can see from the printVarSummary of the received time from the shell script.
Variable: time
Type: string
Total Size: 8 bytes
1 values
Number of Dimensions: 1
Dimensions and sizes: [1]
Coordinates:
Number Of Attributes: 1
_FillValue : -2147483647
-2147483647
On Oct 19, 2017, at 10:42 AM, Marston Johnston <shejo284 at gmail.com> wrote:
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
_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
--
Barry H. Lynn, Ph.D
Senior Lecturer,
The Institute of the Earth Science,
The Hebrew University of Jerusalem,
Givat Ram, Jerusalem 91904, Israel
Tel: 972 547 231 170
Fax: (972)-25662581
C.E.O, Weather It Is, LTD
Weather and Climate Focus
http://weather-it-is.com
Jerusalem, Israel
Local: 02 930 9525
Cell: 054 7 231 170
Int-IS: x972 2 930 9525
US 914 432 3108
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171019/1c9dd1a7/attachment.html>
More information about the ncl-talk
mailing list