<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
Hi, Justin —
<div>I have a couple of suggestions for you. </div>
<div><br>
</div>
<div>0. Please use indents to make your code readable for yourself and others helping you. </div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>2. You are missing a statement to close your text output file: </div>
<div> rc=close(“gldas_mask_data.txt”)</div>
<div>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. </div>
<div><br>
</div>
<div>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. </div>
<div><br>
</div>
<div>Here’s an untested draft of a re-organization of your script: </div>
<div><br>
</div>
<div><font face="Courier" style="font-size: 14px;">‘reinit’</font></div>
<div><font face="Courier" style="font-size: 14px;"><br>
</font></div>
<div><font face="Courier" style="font-size: 14px;">* set the output file name, delete it if it already exists</font></div>
<div><font face="Courier" style="font-size: 14px;">outfile=‘GLDAS_MASK_DATA.txt’</font></div>
<div><font face="Courier" style="font-size: 14px;">‘!/bin/rm -f ‘outfile</font></div>
<div><font face="Courier" style="font-size: 14px;"><br>
</font></div>
<div><font face="Courier" style="font-size: 14px;">* create a list the different mask names for constructing filenames</font></div>
<div><font face="Courier" style="font-size: 14px;">masks=’00_WLD 01_ART 02_ABC 03_XYZ’</font></div>
<div><font face="Courier" style="font-size: 14px;">nmasks=4</font></div>
<div><font face="Courier" style="font-size: 14px;"><br>
</font></div>
<div><font face="Courier" style="font-size: 14px;">* loop over all the masks</font></div>
<div><font face="Courier" style="font-size: 14px;">m=1</font></div>
<div><font face="Courier" style="font-size: 14px;">while (m<=nmasks)</font></div>
<div><font face="Courier" style="font-size: 14px;"> maskname=subwrd(masks,m)</font></div>
<div><font face="Courier" style="font-size: 14px;"> infile=‘/data2/control/Region’maskname’_mask_GLDAS.nc'</font></div>
<div><font face="Courier" style="font-size: 14px;"> ‘open ‘infile</font></div>
<div><font face="Courier" style="font-size: 14px;">* make sure the file open worked without any errors</font></div>
<div><font face="Courier" style="font-size: 14px;"> if (rc)</font></div>
<div><font face="Courier"><span style="font-size: 14px;"> say ‘open failed for mask file ‘m’: ‘infile’, rc=‘rc</span></font></div>
<div><font face="Courier" style="font-size: 14px;"> return</font></div>
<div><font face="Courier" style="font-size: 14px;"> endif</font></div>
<div><font face="Courier" style="font-size: 14px;"><br>
</font></div>
<div><font face="Courier" style="font-size: 14px;">* add your code here </font></div>
<div><font face="Courier" style="font-size: 14px;"><br>
</font></div>
<div><font face="Courier" style="font-size: 14px;"> ‘sdfopen GLDASfile.nc’</font></div>
<div>
<div><font face="Courier" style="font-size: 14px;"> if (rc)</font></div>
<div><font face="Courier" style="font-size: 14px;"> say ‘sdfopen failed for GLDAS file with mask number ‘m</font></div>
<div><font face="Courier" style="font-size: 14px;"> return</font></div>
<div><font face="Courier" style="font-size: 14px;"> endif</font></div>
</div>
<div><font face="Courier" style="font-size: 14px;"><br>
</font></div>
<div><font face="Courier" style="font-size: 14px;">* add more of your code here</font></div>
<div><font face="Courier" style="font-size: 14px;"> string=blah’ ‘blah</font></div>
<div><font face="Courier" style="font-size: 14px;"> rc=write(outfile,string,append)</font></div>
<div><font face="Courier" style="font-size: 14px;"><br>
</font></div>
<div><font face="Courier" style="font-size: 14px;">* no need to keep calling reinit, just clean up properly, reset if necessary</font></div>
<div><font face="Courier" style="font-size: 14px;"> ‘close 2’</font></div>
<div><font face="Courier" style="font-size: 14px;"> ‘close 1’</font></div>
<div><font face="Courier" style="font-size: 14px;"> </font></div>
<div><font face="Courier" style="font-size: 14px;"> mask=mask+1</font></div>
<div><font face="Courier" style="font-size: 14px;">endwhile</font></div>
<div><font face="Courier" style="font-size: 14px;"><br>
</font></div>
<div><font face="Courier" style="font-size: 14px;">* close the text file with all the mask data</font></div>
<div><font face="Courier" style="font-size: 14px;">rc=close(“text_output_for_this_mask”)</font></div>
<div><br>
</div>
<div>—Jennifer</div>
<div><br>
</div>
<div><br>
<div>
<div>On Jan 5, 2017, at 12:46 PM, Justin Hicks <<a href="mailto:jhicks2014@gmail.com">jhicks2014@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<div dir="ltr">Jeff,
<div><br>
</div>
<div>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. </div>
<div><br>
</div>
<div>-Justin</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, Jan 5, 2017 at 12:32 PM, Jeff Duda <span dir="ltr">
<<a href="mailto:jeffduda319@gmail.com" target="_blank">jeffduda319@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div>
<div>
<div>
<div>-Does the seventh file exist on your system?<br>
</div>
-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.
<br>
</div>
-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.<br>
<br>
</div>
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.<br>
<br>
</div>
Jeff Duda<br>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">
<div>
<div class="h5">On Thu, Jan 5, 2017 at 10:19 AM, Justin Hicks <span dir="ltr"><<a href="mailto:jhicks2014@gmail.com" target="_blank">jhicks2014@gmail.com</a>></span> wrote:<br>
</div>
</div>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto;">
<div>
<div class="h5">
<div dir="ltr"><span style="font-size:12.8px">GrADS users,</span>
<div style="font-size:12.8px"><br>
</div>
<div style="font-size:12.8px">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:</div>
<div style="font-size:12.8px"><br>
</div>
<div style="font-size:12.8px"> 'reinit'
<div>'open /data2/control/Region00_WLD_ma<wbr>sk_GLDAS.nc'</div>
<div>'set t 1 756'</div>
<div>'set dfile 1'</div>
<div>'set lon -179.5 179.5'</div>
<div>'set lat -89.5 89.5'</div>
<div>'sdfopen /data2/control/GLDAS_NOAH10_M.<wbr>020.ctl_1Deg_RainfallRateSfc.n<wbr>c'</div>
<div>'set dfile 2'</div>
<div>'set lon -179.5 179.5'</div>
<div>'set lat -89.5 89.5'</div>
<div>'set time 00Z01JAN1948'</div>
<div>'set dfile 1'</div>
<div> nmonths=756</div>
<div> i=1</div>
<div> while (i<=nmonths)</div>
<div> 'set t 'i</div>
<div>'q file 1'</div>
<div>region = sublin(result,2)</div>
<div>region = subwrd(region,2)</div>
<div>'q file 2'</div>
<div>dataset = sublin(result,2)</div>
<div>dataset = subwrd(dataset,2)</div>
<div> 'q dims'</div>
<div> rectime = sublin(result,5)</div>
<div> recdate = subwrd(rectime,6) </div>
<div>'d aave(maskout(rainfsfc.2*86400,<wbr>lterp(mask.1(time=00Z01JAN1948<wbr>),rainfsfc.2)),lon=-179.5,lon=<wbr>179.5,lat=-89.5,lat=89.5)' </div>
<div> say 't='i </div>
<div> say result</div>
<div> rainfsfc = sublin(result,1)</div>
<div> rainfsfc = subwrd(rainfsfc,4)</div>
<div> string = dataset' 'region' 'rectime' 'rainfsfc</div>
<div> rc=write('GLDAS_MASK_DATA.txt<wbr>' , string ,'append')</div>
<div> i = i + 1</div>
<div> endwhile</div>
<div><br>
</div>
<div>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_ma<wbr>sk_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:</div>
<div><br>
</div>
<div>
<div>QUERY FILE Error: file 2 not open</div>
<div>Data Request Error: File number out of range </div>
<div> Variable = rainfsfc.2 </div>
<div>Operation Error: Error from maskout function</div>
<div>Operation Error: Error from aave function</div>
<div> Error ocurred at column 1</div>
<div>DISPLAY error: Invalid expression </div>
<div> Expression = aave(maskout(rainfsfc.2*86400,<wbr>lterp(mask.1(time=00z01jan1948<wbr>),rainfsfc.2)),lon=-179.5,lon=<wbr>179.5,lat=-89.5,lat=89.5)</div>
<div>t=703</div>
<div>Data Request Error: File number out of range </div>
<div> Variable = rainfsfc.2 </div>
<div>Operation Error: Error from maskout function</div>
<div>Operation Error: Error from aave function</div>
<div> Error ocurred at column 1</div>
<div>DISPLAY error: Invalid expression </div>
<div> Expression = aave(maskout(rainfsfc.2*86400,<wbr>lterp(mask.1(time=00z01jan1948<wbr>),rainfsfc.2)),lon=-179.5,lon=<wbr>179.5,lat=-89.5,lat=89.5)</div>
<div><br>
</div>
<div><br>
</div>
<div>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). </div>
<div><br>
</div>
<div>Any help would be appreciated to me solve this issue, as I'm baffled.</div>
</div>
<span class="m_735202519539341002HOEnZb"><font color="#888888">
<div><br>
</div>
<div>-Justin</div>
</font></span></div>
<span class="m_735202519539341002HOEnZb"><font color="#888888">
<div><br>
</div>
-- <br>
<div class="m_735202519539341002m_1561338336932819900gmail_signature">
<div dir="ltr">
<div dir="ltr">
<div><span style="font-size:12.8px"><span style="font-size:10pt;font-family:"times new roman",serif;background-image:initial;background-repeat:initial"><font><b>Justin Hicks</b></font></span></span><br>
</div>
<div><i style="font-size:12.8px"><span style="font-size:10pt;font-family:"times new roman",serif;background-image:initial;background-repeat:initial"><font>Undergraduate<br>
Atmospheric Sciences Major</font></span></i></div>
<div><i style="font-size:12.8px"><span style="font-size:10pt;font-family:"times new roman",serif;background-image:initial;background-repeat:initial"><font>GIS Minor<br>
University of Maryland-College Park</font></span></i><font size="2" face="arial, helvetica, sans-serif"><b><br>
</b></font></div>
</div>
</div>
</div>
</font></span></div>
<br>
</div>
</div>
<span class="">______________________________<wbr>_________________<br>
gradsusr mailing list<br>
<a href="mailto:gradsusr@gradsusr.org" target="_blank">gradsusr@gradsusr.org</a><br>
<a href="http://gradsusr.org/mailman/listinfo/gradsusr" rel="noreferrer" target="_blank">http://gradsusr.org/mailman/li<wbr>stinfo/gradsusr</a><br>
<br>
</span></blockquote>
</div>
<span class="HOEnZb"><font color="#888888"><br>
<br clear="all">
<br>
-- <br>
<div class="m_735202519539341002gmail_signature" data-smartmail="gmail_signature">
<div dir="ltr">
<div dir="ltr">Jeff Duda<br>
Post-doctoral research fellow<br>
University of Oklahoma School of Meteorology<br>
</div>
</div>
</div>
</font></span></div>
<br>
______________________________<wbr>_________________<br>
gradsusr mailing list<br>
<a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a><br>
<a href="http://gradsusr.org/mailman/listinfo/gradsusr" rel="noreferrer" target="_blank">http://gradsusr.org/mailman/<wbr>listinfo/gradsusr</a><br>
<br>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div class="gmail_signature" data-smartmail="gmail_signature">
<div dir="ltr">
<div dir="ltr">
<div><span style="font-size:12.8px"><span style="font-size:10pt;font-family:"Times New Roman",serif;background-image:initial;background-repeat:initial"><font><b>Justin Hicks</b></font></span></span><br>
</div>
<div><i style="font-size:12.8px"><span style="font-size:10pt;font-family:"Times New Roman",serif;background-image:initial;background-repeat:initial">Undergraduate<br>
Atmospheric Sciences Major</span></i></div>
<div><i style="font-size:12.8px"><span style="font-size:10pt;font-family:"Times New Roman",serif;background-image:initial;background-repeat:initial">GIS Minor<br>
University of Maryland-College Park</span></i><font face="arial, helvetica, sans-serif" size="2"><b><br>
</b></font></div>
</div>
</div>
</div>
</div>
_______________________________________________<br>
gradsusr mailing list<br>
<a href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a><br>
http://gradsusr.org/mailman/listinfo/gradsusr<br>
</blockquote>
</div>
<br>
<div apple-content-edited="true">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div style="font-size: 12px; orphans: 2; widows: 2;">--</div>
<div style="font-size: 12px; orphans: 2; widows: 2;">Jennifer Miletta Adams<br>
Center for Ocean-Land-Atmosphere Studies (COLA)<br>
George Mason University<br>
<br>
<br>
</div>
</div>
</div>
</div>
<br>
</div>
</body>
</html>