[gradsusr] Mask/Scripting error
Jennifer M Adams
jadams21 at gmu.edu
Thu Jan 5 17:45:25 EST 2017
Hi, Justin —
I have a couple of suggestions for you.
0. Please use indents to make your code readable for yourself and others helping you.
1. Rather than duplicate the code block over and over again, I would try adding a wrapper around it to loop over the mask names.
2. You are missing a statement to close your text output file:
rc=close(“gldas_mask_data.txt”)
And it looks like your ‘append’ option is never set for your write statements. Be careful that you don’t overwrite this output file with every write call. I would set the name up front, delete the file with a call to the shell, then proceed with all the mask results appending to the file every time, then close it when you are done. If you are creating a separate output text file for each mask, put this code inside the wrapper loop and create a uniqe outfile name that uses the mask name.
3. You should add a check after every ‘open’ and ‘sdfopen’ call to make sure they worked (test if rc!=0), and if not, exit the script with an informative message. Then you will be able to see more clearly where things are going wrong.
Here’s an untested draft of a re-organization of your script:
‘reinit’
* set the output file name, delete it if it already exists
outfile=‘GLDAS_MASK_DATA.txt’
‘!/bin/rm -f ‘outfile
* create a list the different mask names for constructing filenames
masks=’00_WLD 01_ART 02_ABC 03_XYZ’
nmasks=4
* loop over all the masks
m=1
while (m<=nmasks)
maskname=subwrd(masks,m)
infile=‘/data2/control/Region’maskname’_mask_GLDAS.nc'
‘open ‘infile
* make sure the file open worked without any errors
if (rc)
say ‘open failed for mask file ‘m’: ‘infile’, rc=‘rc
return
endif
* add your code here
‘sdfopen GLDASfile.nc’
if (rc)
say ‘sdfopen failed for GLDAS file with mask number ‘m
return
endif
* add more of your code here
string=blah’ ‘blah
rc=write(outfile,string,append)
* no need to keep calling reinit, just clean up properly, reset if necessary
‘close 2’
‘close 1’
mask=mask+1
endwhile
* close the text file with all the mask data
rc=close(“text_output_for_this_mask”)
—Jennifer
On Jan 5, 2017, at 12:46 PM, Justin Hicks <jhicks2014 at gmail.com<mailto:jhicks2014 at gmail.com>> wrote:
Jeff,
The seventh file exists; this is an issue that pertains to any combination of seven masks. Also, I begin each new block of commands with 'reinit', which should close any previously open mask files. If I run all 56 masks (one at a time, each closing before the next mask is opened), some of the masks still output data, and others just output that error statement. That's why I don't believe it is a memory issue. Each mask file runs perfectly fine when run in its own gradscript; I just get this error when grouping them all into one script.
-Justin
On Thu, Jan 5, 2017 at 12:32 PM, Jeff Duda <jeffduda319 at gmail.com<mailto:jeffduda319 at gmail.com>> wrote:
-Does the seventh file exist on your system?
-Are you opening too many files? I don't see any 'close' statements in your script, so you may want to consider the ramifications of never closing files if you're opening a large number of them.
-Are you running out of memory? Usually Grads just crashes entirely when there's a memory error, but perhaps it's not in this instance.
Usually when it comes to debugging, the most comprehensive thing you can do is a line-by-line print statement to see what's going on in the script after each and every line. You can simplify by printing out only specific lines that you think are critical, then subdivide sections of code down to the source of the problem so that you don't have to literally issue a print statement after every line.
Jeff Duda
On Thu, Jan 5, 2017 at 10:19 AM, Justin Hicks <jhicks2014 at gmail.com<mailto:jhicks2014 at gmail.com>> wrote:
GrADS users,
I have come across a strange problem while running a gradscript. I am using this script to output average monthly data of different regions to a text file. Each block of commands contains a different mask, but uses the same datafile. The first block of commands is shown below:
'reinit'
'open /data2/control/Region00_WLD_mask_GLDAS.nc'
'set t 1 756'
'set dfile 1'
'set lon -179.5 179.5'
'set lat -89.5 89.5'
'sdfopen /data2/control/GLDAS_NOAH10_M.020.ctl_1Deg_RainfallRateSfc.nc'
'set dfile 2'
'set lon -179.5 179.5'
'set lat -89.5 89.5'
'set time 00Z01JAN1948'
'set dfile 1'
nmonths=756
i=1
while (i<=nmonths)
'set t 'i
'q file 1'
region = sublin(result,2)
region = subwrd(region,2)
'q file 2'
dataset = sublin(result,2)
dataset = subwrd(dataset,2)
'q dims'
rectime = sublin(result,5)
recdate = subwrd(rectime,6)
'd aave(maskout(rainfsfc.2*86400,lterp(mask.1(time=00Z01JAN1948),rainfsfc.2)),lon=-179.5,lon=179.5,lat=-89.5,lat=89.5)'
say 't='i
say result
rainfsfc = sublin(result,1)
rainfsfc = subwrd(rainfsfc,4)
string = dataset' 'region' 'rectime' 'rainfsfc
rc=write('GLDAS_MASK_DATA.txt' , string ,'append')
i = i + 1
endwhile
I repeat these commands in the same script over and over, only changing the second line (ex. the next one would read 'open /data2/control/Region01_ART_mask_GLDAS.nc'). The data is output perfectly when I have six masks in the script, but when I include the seventh, the data output from the third mask / block of commands is altered, and I get the following error:
QUERY FILE Error: file 2 not open
Data Request Error: File number out of range
Variable = rainfsfc.2
Operation Error: Error from maskout function
Operation Error: Error from aave function
Error ocurred at column 1
DISPLAY error: Invalid expression
Expression = aave(maskout(rainfsfc.2*86400,lterp(mask.1(time=00z01jan1948),rainfsfc.2)),lon=-179.5,lon=179.5,lat=-89.5,lat=89.5)
t=703
Data Request Error: File number out of range
Variable = rainfsfc.2
Operation Error: Error from maskout function
Operation Error: Error from aave function
Error ocurred at column 1
DISPLAY error: Invalid expression
Expression = aave(maskout(rainfsfc.2*86400,lterp(mask.1(time=00z01jan1948),rainfsfc.2)),lon=-179.5,lon=179.5,lat=-89.5,lat=89.5)
I don't believe the error lies within the third mask file itself because it plots fine when it is run independently from the other masks. I also get the same output issue when I run, for example, masks 50-56 (one or two of these will come up with the error, but running masks 50-55 will yield no problems).
Any help would be appreciated to me solve this issue, as I'm baffled.
-Justin
--
Justin Hicks
Undergraduate
Atmospheric Sciences Major
GIS Minor
University of Maryland-College Park
_______________________________________________
gradsusr mailing list
gradsusr at gradsusr.org<mailto:gradsusr at gradsusr.org>
http://gradsusr.org/mailman/listinfo/gradsusr
--
Jeff Duda
Post-doctoral research fellow
University of Oklahoma School of Meteorology
_______________________________________________
gradsusr mailing list
gradsusr at gradsusr.org<mailto:gradsusr at gradsusr.org>
http://gradsusr.org/mailman/listinfo/gradsusr
--
Justin Hicks
Undergraduate
Atmospheric Sciences Major
GIS Minor
University of Maryland-College Park
_______________________________________________
gradsusr mailing list
gradsusr at gradsusr.org<mailto:gradsusr at gradsusr.org>
http://gradsusr.org/mailman/listinfo/gradsusr
--
Jennifer Miletta Adams
Center for Ocean-Land-Atmosphere Studies (COLA)
George Mason University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20170105/4350a55a/attachment.html
More information about the gradsusr
mailing list