[gradsusr] Converting Daily Average to Monthly Average

Jeff Duda jeffduda319 at gmail.com
Wed Jun 15 10:18:40 EDT 2016


To avoid ambiguity in your code structure, I would suggest removing lines
with semicolons to separate commands and move them to separate lines. I'm
wondering if the semicolon after the endif partway through the code is the
cause of the error.

Jeff Duda

On Wed, Jun 15, 2016 at 8:30 AM, Justin Hicks <jhicks2014 at gmail.com> wrote:

> Itesh,
>
> I am still getting the same error even after including a space. I'll paste
> my code below:
>
> reinit
> mday = '31 28 31 30 31 30 31 31 30 31 30 31'
> month = 'jan feb mar apr may jun jul aug sep oct nov dec'
>
>  'open /data2/control/GPCC_FirstGuessDaily'
>
>  'set gxout fwrite'
>  'set fwrite /data2/control/GPCC_FirstGuessDailyScriptTest'
>
>  yr1 = 2009
>  yr2 = 2013
>
>  yr = yr1
>  while (yr<=yr2)
>  leap = 0
>   if (math_mod(yr,400) = 0 | math_mod(yr,4) = 0 & math_mod(yr,100) != 0)
>    leap = 1
>    say yr' is a leap year.'
>   endif
>   imon = 1
>   while (imon <= 12)
>    md = subwrd(mday,imon)
>    mc = subwrd(month,imon)
>    if (imon = 2); md = md + leap; endif;
>   time1 = '01'mc''yr
>    time2 = md''mc''yr
>    say time1' 'time2
>    'd ave(p,time='time1',time='time2')'
>    imon = imon + 1
>   endwhile
>   yr = yr + 1
>   endwhile
>
> -Justin
>
> On Tue, Jun 14, 2016 at 4:36 PM, itesh dash <itesh at rimes.int> wrote:
>
>> Just provide a space at beginning of () in the while statement.
>>
>> While (yr<=yr2)
>>
>> It should work.
>>
>>
>> On Wednesday, 15 June 2016, Justin Hicks <jhicks2014 at gmail.com> wrote:
>>
>>> Now, with the same exact script, it is giving me the error
>>>
>>>  "Unable to locate ENDWHILE statement for the WHILE statement at line 14
>>>   In file DailytoMonthlyTest.gs"
>>>
>>> This is the error I was previously dealing with, yet it resolved itself
>>> with no changes. I'm not too sure what's going on, both endwhile statements
>>> are there.
>>>
>>> -Justin
>>>
>>>
>>> On Thu, Jun 9, 2016 at 12:32 PM, Jeff Duda <jeffduda319 at gmail.com>
>>> wrote:
>>>
>>>> The code looks fine to me other than the following line:
>>>>
>>>>  'open file /data2/control/GPCC_FirstGuessDaily'
>>>>
>>>> Remove 'file' from this command.
>>>>
>>>> Jeff Duda
>>>>
>>>>
>>>> On Thu, Jun 9, 2016 at 10:10 AM, Justin Hicks <jhicks2014 at gmail.com>
>>>> wrote:
>>>>
>>>>> To whom it may concern,
>>>>>
>>>>> I'm working on converting a plethora of datasets, many of them with
>>>>> daily and hourly temporal resolutions, into a monthly temporal resolution.
>>>>>
>>>>> I am unsure how to write a script that I can run that changes, in this
>>>>> case, average daily data into average monthly data, with respect to leap
>>>>> years and such. I have tried to follow scripts from other users who have
>>>>> previously posted here, but they did not seem to work.
>>>>>
>>>>> There is an example of the script I tried to run on this page:
>>>>> http://gradsusr.org/pipermail/gradsusr/2006-June/003290.html
>>>>>
>>>>> This is the script I am currently running:
>>>>>
>>>>> reinit
>>>>> mday = '31 28 31 30 31 30 31 31 30 31 30 31'
>>>>> month = 'jan feb mar apr may jun jul aug sep oct nov dec'
>>>>>
>>>>>  'open file /data2/control/GPCC_FirstGuessDaily'
>>>>>
>>>>>  'set gxout fwrite'
>>>>>  'set fwrite /data2/control/GPCC_FirstGuessDailyScriptTest'
>>>>>
>>>>>  yr1 = 2009
>>>>>  yr2 = 2013
>>>>>
>>>>>  yr = yr1
>>>>>  while(yr<=yr2)
>>>>>  leap = 0
>>>>>   if(math_mod(yr,400) = 0 | math_mod(yr,4) = 0 & math_mod(yr,100) != 0)
>>>>>    leap = 1
>>>>>    say yr' is a leap year.'
>>>>>   endif
>>>>>   imon = 1
>>>>>   while(imon <= 12)
>>>>>    md = subwrd(mday,imon)
>>>>>    mc = subwrd(month,imon)
>>>>>    if(imon = 2); md = md + leap; endif;
>>>>>   time1 = '01'mc''yr
>>>>>    time2 = md''mc''yr
>>>>> *   say time1' 'time2
>>>>>    'd ave(p,time='time1',time='time2')'
>>>>>    imon = imon + 1
>>>>>   endwhile
>>>>>   yr = yr + 1
>>>>>  endwhile
>>>>>
>>>>>
>>>>> Running this code gives me an error saying that it cannot open the
>>>>> file, yet it is pointed to the correct directory. However, it does output
>>>>> saying that '2012 is a leap year' which is correct.
>>>>>
>>>>> Any help would be appreciated, as I'm a terrible coder.
>>>>>
>>>>> -Justin
>>>>>
>>>>> _______________________________________________
>>>>> gradsusr mailing list
>>>>> gradsusr at gradsusr.org
>>>>> http://gradsusr.org/mailman/listinfo/gradsusr
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Jeff Duda
>>>> Post-doctoral research associate
>>>> University of Oklahoma School of Meteorology
>>>>
>>>> _______________________________________________
>>>> gradsusr mailing list
>>>> gradsusr at gradsusr.org
>>>> http://gradsusr.org/mailman/listinfo/gradsusr
>>>>
>>>>
>>>
>> _______________________________________________
>> gradsusr mailing list
>> gradsusr at gradsusr.org
>> http://gradsusr.org/mailman/listinfo/gradsusr
>>
>>
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>
>


-- 
Jeff Duda
Post-doctoral research associate
University of Oklahoma School of Meteorology
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20160615/653a991b/attachment-0001.html 


More information about the gradsusr mailing list