Leap Year

Diane Stokes Diane.Stokes at NOAA.GOV
Mon Jan 8 16:03:49 EST 2007


Hi, Katherin.

Try including some "say"s in your script to see what's going on inside
your if-block and else-block.  See which block you enter if you
include/exclude the word "then" when it runs on a leap year, say 1952.

Try "say result" after your 'set dfile's and 'set t's.

Also, it looks like you've opened 40 or so descriptor files before you
run the script you included.  If so, and if the files have the year
integrated in the name, you could use only 4 descriptor files (one for
each variable) with the template option to process the data.  Then you
can let grads take care of knowing when to change from year to year.

If the last day of your time series is 31 December 1959, then include:
'set time 31dec1959'
'q dims'
and extract the value of the last time step from the result, using
"sublin" and "subwrd".  Then you can use that value as the ending point
of your loop.

I don't have time to provide more detail right now.  I hope the above is
clear enough to help.

    Cheers!
      Diane Stokes

Katherin Kullgren wrote:
> MJ,
> What I think is happening, is that it is trying to say each year has 366
> days, because my binary file is 160 bytes too large, (160/4 = 40) and
> for 5 variables (40/5 = 8) which means it is writing 366 days for 10
> years instead of 365 for 8 years and 366 for 2 years (from 1950 - 1959).
> Do you have any suggestions on how I can change/improve this script so
> it reads the proper number of days?
> Should I include a
> else (rc not equal 0)   ??
>
> How would I do that?
> Thanks for your help!
> Katherin
>
>
>
>
>
> On Jan 8, 2007, at 2:26 PM, Mary Jo Nath wrote:
>
>> Katherin,
>>
>> Your syntax is off a little. There is no "then" on an "if" statement in
>> GrADS scripting language. Instead of:
>>
>>        if (rc = 0) then
>>
>> use
>>
>>        if (rc = 0)
>>
>>
>> MJ
>>
>>
>>
>> Katherin Kullgren wrote:
>>> Good Afternoon,
>>> I am having some trouble with my program. I want to write daily data from
>>> year files of 4 different variables, into one file.  It looks like in my
>>> loop, when it moves onto the next file, it still tries to read say
>>> line 366
>>> of the previous file instead of line 1 of the next file.  I am sure it is
>>> some order of commands error, but I cannot figure it out. Could someone
>>> please take a look?
>>> Thanks in advance,
>>> Katherin
>>>
>>> lat = 168
>>> lon = 173
>>> starttime = 1
>>> year = 1950
>>> endday = 365
>>> leap = 366
>>> pfile = 1
>>> rfile = 11
>>> wfile = 21
>>> tfile = 31
>>> num_2 = 4
>>>
>>> * write the new data into a file
>>> 'set gxout fwrite'
>>> 'set fwrite 10110204.data'
>>>
>>> *********
>>> while (pfile <= 10)
>>> num_1 = year
>>> rc = math_mod(num_1,num_2)
>>> tt=starttime
>>> imap = 1
>>> jmap = 8
>>> 'set x 'lat
>>> 'set y 'lon
>>>
>>> if (rc = 0) then
>>>
>>> while (tt<=leap)
>>> 'set dfile 'tfile
>>> 'd max(tair2,t='imap',t='jmap')-273.16'
>>> 'd min(tair2,t='imap',t='jmap')-273.16'
>>> 'set dfile 'pfile
>>> 'set t 'tt
>>> 'd prate*86400'
>>> 'set dfile 'rfile
>>> 'set t 'tt
>>> 'd rh/100'
>>> 'set dfile 'wfile
>>> 'set t 'tt
>>> 'd wind*1.3'
>>> imap = imap + 8
>>> jmap = jmap + 8
>>> tt = tt + 1
>>> endwhile
>>>
>>> else
>>>
>>> tt=starttime
>>> imap = 1
>>> jmap = 8
>>>
>>> while (tt<=endday)
>>> 'set dfile 'tfile
>>> 'd max(tair2,t='imap',t='jmap')-273.16'
>>> 'd min(tair2,t='imap',t='jmap')-273.16'
>>> 'set dfile 'pfile
>>> 'set t 'tt
>>> 'd prate*86400'
>>> 'set dfile 'rfile
>>> 'set t 'tt
>>> 'd rh/100'
>>> 'set dfile 'wfile
>>> 'set t 'tt
>>> 'd wind*1.3'
>>> imap = imap + 8
>>> jmap = jmap + 8
>>> tt = tt + 1
>>> endwhile
>>>
>>> endif
>>>
>>> year = year + 1
>>> pfile = pfile + 1
>>> rfile = rfile + 1
>>> wfile = wfile + 1
>>> tfile = tfile + 1
>>> endwhile
>>>
>>>
>>> 'disable fwrite'
>>>
>>> <Mary-Jo.Nath.vcf>
>

--
Diane Stokes
Environmental Modeling Center
National Weather Service/NOAA



More information about the gradsusr mailing list