[gradsusr] [SOLVED] RE: Using A While Loop To Sequentially Loop Through Many Hours/Control Files

Perry, Aaron @ LSC Aaron.Perry at lsc.vsc.edu
Fri Dec 27 16:19:53 EST 2013


I actually solved this issue on my own...

Just needed to relocate 'reinit' to directly above the open ctl line.

Thank you everyone for your patience and help!


Onward and Upward,

Aaron D. Perry
Boston, MA
Lyndon State College '15
Twitter: @AaronPerryLSC<https://twitter.com/AaronPerryLSC>
Mobile: 617-780-4312
________________________________
From: gradsusr-bounces at gradsusr.org [gradsusr-bounces at gradsusr.org] on behalf of Perry, Aaron @ LSC [Aaron.Perry at lsc.vsc.edu]
Sent: Friday, December 27, 2013 4:06 PM
To: GrADS Users Forum
Subject: Re: [gradsusr] Using A While Loop To Sequentially Loop Through Many Hours/Control Files

Hi James,

Thanks for your reply!

I feel like this step is exactly what I need, except you're right, I don't need the "incr = 3" in that script at all.

To clear the air, I have a bunch of control files that are called 000.ctl, 003.ctl, 006.ctl, 012.ctl...240.ctl and I'm trying to set some sort of loop that will automate the process of opening each control file without having to create 80 different scripts for each individual control file. I've successfully gotten the loop to work but, a new issues has now come up..

When I try to create the graphic using gxprint, it creates the first graphic for hour 000 and then uses that for each graphic/hour afterwards.

I've attached the updated script to this email.

I feel like I'm so close!



Onward and Upward,

Aaron D. Perry
Boston, MA
Lyndon State College '15
Twitter: @AaronPerryLSC<https://twitter.com/AaronPerryLSC>
Mobile: 617-780-4312
________________________________
From: gradsusr-bounces at gradsusr.org [gradsusr-bounces at gradsusr.org] on behalf of James T. Potemra [jimp at hawaii.edu]
Sent: Friday, December 27, 2013 3:03 PM
To: GrADS Users Forum
Subject: Re: [gradsusr] Using A While Loop To Sequentially Loop Through Many Hours/Control Files

Aaron:

I'm not quite sure what you want fcsthr1 to look like.  "incr" is a constant value of 3, and "i" runs from 0 to 80 incremented by 3.  Do you want fcsthr1 to be 3000, 3003, 3006, 3009, 3012, ..., 3080?  If so, you can do this via if/then, e.g., (echoing Jeff's reply about the unnecessary quotes, below all quotes are single):

incr=3
START=0
END=80
i=START

while(i <= END)
  fcsthr1 = incr''i
  if ( i < 100 )
     fcsthr1 = incr'0'i
  endif
  if ( i < 10 )
     fcsthr1 = incr'00'i
  endif
  i = i + 3
  say fcsthr1
endwhile



On 12/27/13 7:02 AM, Jeff Duda wrote:
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<mailto: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<mailto: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



_______________________________________________
gradsusr mailing list
gradsusr at gradsusr.org<mailto:gradsusr at gradsusr.org>
http://gradsusr.org/mailman/listinfo/gradsusr


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20131227/8b13b9f3/attachment.html 


More information about the gradsusr mailing list