[gradsusr] Time series at point

Goodson,Ron [Edm] Ron.Goodson at EC.gc.ca
Mon May 3 14:33:33 EDT 2010


This topic about writing text comes up a lot!

Anywhoo .. short form is to 

- set gxout print 
- d <whatever>	- which will write something but also send it to the grads pre-defined "result"
- write "result" to file

Here is a script I use to write out some results to a file. It has a bunch of hardcoded variable names and paths - but you can probably modify it to suit your needs.  There may be other, better ways to accomplish this task .. but this works for me.



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

* Script in testing to write data values at lat/lon (not using gr2stn - just
* nearest grid point) to a file.
*
*
* Set the list of Variables, and some name-mapping that I'll remember.
* Should be in a read-config file, but we shall throw it in here for now.

var.1.1 = 'TMPl11910000 - 273.16'
var.1.2 = 'Surface Temperature'

var.2.1 = 'TCDCsfc'
var.2.2 = 'Cloud Cover'

var.3.1 = 'TMPPRS(lev=850)'
var.3.2 = 'Temperature 850mb'

NumVars = 3

* For now - pretend the grib file is open
*

* Read in the list of stations and the lat/lon and put into a some
* global variables

site = 1
while (1)
  result = read("/home/ron/GEMLAM/Meteograms/stn.cfg")
  EOF = sublin(result,1)
  if (EOF = 2)
    break
  endif
  line2 = sublin(result,2)
  _name.site = subwrd(line2, 1)
  _lat.site = subwrd(line2,2) 
  _lon.site = subwrd(line2,3)
** say "name is " _name.site ' ' _lat.site ' ' _lon.site
   site = site + 1
   
endwhile

_NumSites = site - 1

* Set the time to 1 and do an inquiry on the
* time.  We can use this to get the date/time
* of our data. Will be used in the name of
* the output file

'set t 1'
MyDTStamp = DateTimeStamp()
say "Date Time Stamp is " MyDTStamp


* Now get the time range of our data, as
* we want to loop through all time periods
* For now, user will just have to know what
* the time increment is

'q file'
MyLine    = sublin(result, 5)
TimeSteps = subwrd(MyLine, 12)
'set t 1 ' TimeSteps


* Loop through the sites and print out some values to
* a file.  For now, just one big file but it could
* just as easily be a seperate file for each station.
*
* For now, just hardcode the name of the variable that is
* desired.  I might make some more obvious names later as
* I'll want to use them in the GribViewer program

MyFile = MyDTStamp".txt"
rc = write (MyFile, 'Model Run ' MyDTStamp )

'set gxout print'
'set prnopts %6.1f 17'

MySite = 1
while (MySite <= _NumSites)
  say 'working on  '_name.MySite
  'set lat ' _lat.MySite
  'set lon ' _lon.MySite 
  rc = write(MyFile,'')
  rc = write (MyFile, 'Station '_name.MySite' ' _lat.MySite ' ' _lon.MySite)
  MyVar = 1
  while (MyVar <= NumVars)
    'd ' var.MyVar.1 
    rc = write(MyFile, var.MyVar.2) 
    MyResult = sublin(result, 3)
    
    say MyResult
    
    rc = write (MyFile, MyResult)
    MyVar = MyVar + 1
  endwhile
  MySite = MySite + 1
endwhile







*-------------------------------------------------------------- 

function DateTimeStamp()

month.JAN = "01"
month.FEB = "02"
month.MAR = "03"
month.APR = "04"
month.MAY = "05"
month.JUN = "06"
month.JUL = "07"
month.AUG = "08"
month.SEP = "09"
month.OCT = "10"
month.NOV = "11"
month.DEC = "12"

  
'q dim'
rec = sublin(result,5)
time = subwrd(rec,6)

MyHour     = substr(time,1,2)
MyDay      = substr(time,4,2)
MyMonth    = substr(time,6,3)
MyYear     = substr(time,9,4)

NumMonth = month.MyMonth

return MyYear''NumMonth''MyDay'_'MyHour

*------------------------------------------------------------------








Ron Goodson		
Prairie and Northern Meteorological Service of Canada Science Section	Unité des Sciences, Région des Prairies et du Nord, Service Météorologique du Canada	
Environment Canada
Room 200 ; 4999 - 98 Avenue
Edmonton Alberta T6B 2X3	Environnement Canada
Pièce 200 ; 4999 - 98 Avenue
Edmonton Alberta T6B 2X3	
Telephone | Téléphone	780 951 8791	
Email | Courriel	ron.goodson at ec.gc.ca	



-----Original Message-----
From: gradsusr-bounces at gradsusr.org [mailto:gradsusr-bounces at gradsusr.org] On Behalf Of Austin Conaty
Sent: May 3, 2010 12:11 PM
To: GrADS Users Forum
Subject: Re: [gradsusr] Time series at point

Teddy,
'set gxout fwrite' gives you a flat binary data file.
why would Mogesh want to write it to a file called variable.txt?
it won't be text output but binary.
-Austin

Teddy Allen wrote:
> Mogesh,
> Try the following:
>
> 'set gxout fwrite'
> 'set fwrite [INSERT YOUR FILE PATH AND FILE NAME HERE]'   (example: 'set fwrite c:\mogesh\variable.txt')
> 'd VARIABLE'
> 'disable fwrite'
>
>
>  (VARIABLE is whatever you are writing out.....) Also, all of your calculations and geographic settings should be done prior to the 'set gxout fwrite' line.
>
>
> This should write out your variable to a .txt file in the path name that was supplied.
> good luck,
> teddy
>
>
> http://www.teddyallen.com<http://www.teddyallen.com/>
>
> "To move quickly, go alone. To move far, go together."
>
> African Proverb
>
>
> ________________________________
> From: Mogesh Naidoo <mnaidoo4 at csir.co.za>
> To: gradsusr at gradsusr.org
> Sent: Mon, May 3, 2010 10:01:56 AM
> Subject: [gradsusr] Time series at point
>
> Hi users,
>
> New to grads (using for 3 months now).
>
> I was wondering what the best way to extract a time series of values at a point on a grid.
> I'd like the values to be output to a text file.
> The grid is of netcdf format.
>
> So far I constrain the grid to one point and use set gxout value to give me a plot on the grads display. How can I get this into a text file?
>
> regards,
>
>
> Mogesh Naidoo
> Atmospheric Modelling Group
> Natural Resources and the Environment
> CSIR
> P.O. Box 17001,
> Congella 4013
> Durban
> South Africa
>
> Telephone: [int+27] (0)31 242 2318
> Email: mnaidoo4 at csir.co.za
>
> --
> This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard.
> The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.
>
> This message has been scanned for viruses and dangerous content by 
> MailScanner<http://www.mailscanner.info/>,
> and is believed to be clean. MailScanner thanks Transtec Computers<http://www.transtec.co.uk/> for their support.
>
>
>   
> ----------------------------------------------------------------------
> --
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>   


-- 
Austin Conaty, SAIC        Global Modeling & Assimilation Office
301-614-6149 (ph)          NASA Goddard Space Flight Center
301-614-6297 (fax)         Code 610.1 Greenbelt, MD 20771

Austin.L.Conaty at .nasa.gov
  
http://gmao.gsfc.nasa.gov


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




More information about the gradsusr mailing list