[gradsusr] Day of week showing ???

Perry, Aaron axp09171 at alumni.northernvermont.edu
Tue Jan 5 15:07:11 EST 2021


Thanks for passing along your quick fix Howard.

I am running GrADS on a Linux system and have found that the following method works for correcting the ??? Day of Week issue by passing the forecast date/time to the Shell and then to a text file. I then read the contents of the (short) text file back into the GrADS script and define it as a usable variable.

***************************************
function dayofweek(fdow)
* Created by Aaron Perry

fdate=subwrd(fdow,1)

rc = gsfallow("on")

'!date -d "'fdate'" +"%a" > fdayofweek.tmp'

istat = 0

while (istat != 2)

data = read("fdayofweek.tmp")
istat = sublin(data,1)

if (istat = 2)
break
endif

linez = sublin(data,2)

fday = subwrd(linez,1)

endwhile

rc = close("fdayofweek.tmp")

return (fday)


Usage in a GrADS Script:

fday = dayofweek(fdate)

say fday *For proof of valid Day of Week Abbreviation


Best,

Aaron Perry
Meteorologist
Class of '16
Northern Vermont University-Lyndon
(formerly Lyndon State College)
Boston, Mass.
Twitter: @AaronPerryWx<https://twitter.com/AaronPerryWx><https://twitter.com/arnpry><https://twitter.com/AaronPerryWx>
Email: Aaron.Perry at lyndonstate.edu<http://Aaron.Perry@lyndonstate.edu/>

________________________________
From: gradsusr <gradsusr-bounces at gradsusr.org> on behalf of Howard Staines <rossby at rossby.co.nz>
Sent: Saturday, January 2, 2021 6:19 PM
To: 'GrADS Users Forum' <gradsusr at gradsusr.org>
Subject: Re: [gradsusr] Day of week showing ???

This message is from an external sender. Please be careful when clicking on links and attachments.



Re Day of the week showing ???



I have a workaround that will work for 2021



When creating strings for labels for graphics



‘q time’

….

At the end of the string creation for Month, Year etc my string for year is ‘yearnum’



* code work around for 2021 correcting daystr error

if yearnum = "2021"

daystr = daystring( monstr, datenum)

endif



daystring() is a function at the bottom of the script it takes two arguments monstr (a string for the month)

and datenum (the current day of the month as a number.

The function finds the day of the week name for the current date and returns this.

Does this by finding the month, if statement gets the 1st day of every month as a position in an array. MON is position 1 etc. The loop is used to move from the 1st day of the month till you reach the date in question. Then using the array you are able to return the day of the weeks name. Works well.

Trust this helps.



The function

***********************************************

function daystring( monstr, datenum)

monname = subwrd (monstr,1)

daynum = subwrd (datenum,1)

if (monname = JAN)

cposition = 5

endif

if (monname = FEB)

cposition = 1

endif

if (monname = MAR)

cposition = 1

endif

if (monname = APR)

cposition = 4

endif

if (monname = MAY)

cposition = 6

endif

if (monname = JUN)

cposition = 2

endif

if (monname = JUL)

cposition = 4

endif

if (monname = AUG)

cposition = 7

endif

if (monname = SEP)

cposition = 3

endif

if (monname = OCT)

cposition = 5

endif

if (monname = NOV)

cposition = 1

endif

if (monname = DEC)

cposition = 3

endif

while (daynum > 1)

cposition = cposition + 1

** end array correction

if cposition > 7

cposition = 1

endif

daynum = daynum - 1

endwhile

* Calculate the day name

dayarray = 'MON TUE WED THU FRI SAT SUN ????'

dayname = subwrd(dayarray,cposition)

return dayname



regards Howard Staines

Metris forecaster New Zealand.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gradsusr.org/pipermail/gradsusr/attachments/20210105/5f7fd0a0/attachment-0001.html>


More information about the gradsusr mailing list