[gradsusr] Using A While Loop To Sequentially Loop Through Many Hours/Control Files
Jeff Duda
jeffduda319 at gmail.com
Fri Dec 27 12:02:30 EST 2013
Aaron,
I had a look through your script. Here are my observations and suggestions.
-Grads does not have an intrinsic fprintf function. There are user-defined
scripts that use that function, but what you should use for string
formatting in a grads script is math_format. See this page on grads script
math functions <http://www.iges.org/grads/gadoc/mathfunctions.html> for a
list of more and how to use them.
-You have some seemingly superfluous single quotes running around in your
code. Perhaps this is related to different versions of Grads (for example,
if you are running OpenGrads instead of the regular version), but you might
want to check that. For example (including a snippet of your code)
(line 1) init = ''runhr''Z26DEC2013
fhr = 0
path = 'graphix/gem/25km/'
sysdate2 = 20131226
'reinit'
incr=3
START=0
END=80
(line 2) i=''START''
(line 3) while('i' <= 'END')
In (what I've marked as) line 1, I'm not sure why you have quotes
surrounding runhr. All that seems to be doing is surrounding the string
runhr with empty strings. Also, I think you need to include the Z26DEC2013
part in quotes to define it as a string. I'm not sure how Grads will
interpret it if you attempt to set init as a number of some kind. As a
check, you can include the line "say init" after you define init to have
grads spit out the value of the variable to the window. In line 2, it
seems you're setting the variable i as the string "START". Since you have
previously set START to the number 0, I think you will want to remove those
quotes so that i is properly set. In line 3, you have placed quotes around
i and END in your while statement. Remove those. You would only use
quotes to set off lines that you would input to the command prompt. If it
belongs internally to the Grads script code (like the while loop is) you
don't need to set it off with quotes.
As far as setting your forecast hour goes, I would imagine the range of
possible forecast hours follows a regular pattern that you could either set
in an array or set using math. For example, if your model output is every
three hours, then you could just do
while (i < END)
fcsthr = (i-1)*3
....
i = i + 1
endwhile
Jeff Duda
On Thu, Dec 26, 2013 at 10:57 PM, Perry, Aaron @ LSC <
Aaron.Perry at lsc.vsc.edu> wrote:
> Good Evening All,
>
> I am trying to implement a while loop that will automatically insert each
> forecast hour (ex. 000, 003, 006, etc) of many control files for a weather
> model directly into the 'open .ctl' line.
>
> The reason for this is because I have 10+ control files that I'd like to
> run sequentially without having to create 10 different GrADS scripts to
> process each individual control file.
>
> What I have in place now does not return any errors within GrADS but, it
> doesn't process anything and the screen stays black. Clearly, I'm doing
> something wrong...
>
> In UNIX, you can simply use printf "%0*d\n" to accomplish three leading
> zeros. I've tried modifying this process by putting a "!" in front of
> printf to run the process outside of GrADS but, this doesn't seem to be
> working...
>
> I've attached the "working" script to this email in hopes that someone who
> is more GrADS-savy than me can take a look at the coding and potentially
> figure out this issue for me.
>
>
> Onward and Upward,
>
> Aaron Perry
> Boston, MA
> Mobile: 617-780-4312
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>
>
--
Jeff Duda
Graduate research assistant
University of Oklahoma School of Meteorology
Center for Analysis and Prediction of Storms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20131227/ebea7dbd/attachment.html
More information about the gradsusr
mailing list