If/else statements dependent upon time

Jack Ordille MrSpock29 at COMCAST.NET
Thu Dec 6 16:36:25 EST 2007


Chuck,

Thank you so much, I will try this tonight!
It looks like it is what I am looking for.

Jack
----- Original Message -----
From: "Charles Seman" <Charles.Seman at NOAA.GOV>
To: <GRADSUSR at LIST.CINECA.IT>
Sent: Thursday, December 06, 2007 4:25 PM
Subject: Re: If/else statements dependent upon time


> Jack,
>
> Please find attached script "month.gs" and script function
> "get_month.gsf" (called by "month.gs", enabled by "month.gs" statement:
> rc = gsfallow("on"); see http://grads.iges.org/grads/gadoc/gsf.html
> Running "month.gs" gives following output (some error checks were also
> run, not shown here):
> ga-> month
> Time values set: 2005:1:1:0 2005:1:1:0
> 2005:1:1:0
> month is Jan
>
> "get_month.gsf" returns a character month name, given a "date" which has
> been assigned after doing a 'set t ...' (in above example, 'set t 1')
> You could modify function "get_month.gsf" to return the numerical month
> value if desired; to do this, remove statements that assign character
> string names to "month" in "get_month.gsf" (in this case, you could also
> consolidate the "if" checks like: if( month = 1 | month = 2 | ... |
> month = 12 )...)
>
> I hope this helps,
> Chuck
>
> Jack wrote:
>> Hi all,
>>
>> I am new to GrADS, so maybe that's why I haven't found this on my own
>> yet,
>> but here's what I'm trying to do:
>>
>> I want to do a calculation based on an 850 temp map, to forecast surface
>> temps, that is dependent on the month of the year. Each month has a
>> slightly
>> different formula than the prior month. Instead of changing the formula
>> in
>> the script every month, I wanted to use "if/else" statements, where the
>> "if"
>> is dependent on the month.
>>
>> I guess my biggest issue now, is getting time identified and used so that
>> it
>> can be executed by the proper formula (of which there should be 12 in
>> there).
>>
>> Any help would be greatly appreciated.
>>
>> Thanks!
>>
>> Jack
>>
>
> --
>
> Please note that Charles.Seman at noaa.gov should be considered my NOAA
> email address, not cjs at gfdl.noaa.gov.
>
> ********************************************************************
> Charles Seman                                Charles.Seman at noaa.gov
> U.S. Department of Commerce / NOAA / OAR
> Geophysical Fluid Dynamics Laboratory         voice: (609) 452-6547
> 201 Forrestal Road                              fax: (609) 987-5063
> Princeton, NJ  08540-6649            http://www.gfdl.noaa.gov/~cjs/
> ********************************************************************
>
> "The contents of this message are mine personally and do not reflect
> any position of the Government or NOAA."
>
>


--------------------------------------------------------------------------------


> rc = gsfallow("on")
> 'open tseries.ctl'
> 'set t 1'
> date_rec = sublin(result,1)
> say date_rec
> date = subwrd(result,4)
> *
> *  error check...
> *
> **date = '2005:0:1:0'
> *
> *  error check...
> *
> **'q time'
> **time_rec = sublin(result,1)
> **date = subwrd(result,3)
> *
> *  assign three character month name to numerical month number...
> *
> month = get_month(date)
> if( month != 'error' )
>  say 'month is 'month
> else
>  exit
> endif
>


--------------------------------------------------------------------------------


> ************************************************************************
> *
> function get_month(date)
> *
> *  Finds "month", given a GrADS "date" string...
> *
> *  Note, it is assumed "date" is defined using the GrADS command
> *    'set t '...
> *  and "date" is of the form "year:month:day:hour"
> *
> say date
> ns = strlen(date)
> *
> *  verify date format...
> *
> n = 1 ; nc = 0
> while ( n <= ns )
>  ch = substr(date,n,1)
>  if( ch = ':' )
>    nc = nc + 1
>  endif
>  n=n+1
> endwhile
> if( nc != 3 )
>  say 'error, invalid date format...'
>  return error
> endif
> *
> *  skip over the "year" portion of the date...
> *
> n=1
> while ( n <= ns )
>  ch = substr(date,n,1)
>  if( ch = ':' )
>    nms = n + 1
>    break
>  endif
>  n=n+1
> endwhile
> *
> *  find the "month" portion of the date...
> *
> n=nms
> while ( n <= ns )
>  ch = substr(date,n,1)
>  if( ch = ':' )
>    nml = n - nms
>    break
>  endif
>  n=n+1
> endwhile
> month = substr(date,nms,nml)
> *
> *  convert the numerical "month" to a character abbreviation...
> *
> if( month = 1 )
>  month = Jan
>  return month
> endif
> if( month = 2 )
>  month = Feb
>  return month
> endif
> if( month = 3 )
>  month = Mar
>  return month
> endif
> if( month = 4 )
>  month = Apr
>  return month
> endif
> if( month = 5 )
>  month = May
>  return month
> endif
> if( month = 6 )
>  month = Jun
>  return month
> endif
> if( month = 7 )
>  month = Jul
>  return month
> endif
> if( month = 8 )
>  month = Aug
>  return month
> endif
> if( month = 9 )
>  month = Sep
>  return month
> endif
> if( month = 10 )
>  month = Oct
>  return month
> endif
> if( month = 11 )
>  month = Nov
>  return month
> endif
> if( month = 12 )
>  month = Dec
>  return month
> endif
> say 'error, no match found...'
> return error
> *
> ************************************************************************
>



More information about the gradsusr mailing list