how obtain the date from a NetCdf file

Matthias Fripp matthias.fripp at ECI.OX.AC.UK
Wed Nov 4 12:08:52 EST 2009


you could use something like this:

'q time'
datetime = subwrd(result, 3)

That will give you the date and time in grads format, e.g.,  
"00Z01JAN1979". If you want, you could go further, with something like  
this:

formatted_time = substr(datetime, 9, 4) '/' substr(datetime, 6, 3) '/'  
substr(datetime, 4, 2) ' ' substr(datetime, 1, 2) ':00'
say "formatted time: " formatted_time

Unfortunately, I don't know any way to convert "JAN" to "01" within  
grads. So you may need to use awk (or similar) to convert the dates  
after-the-fact, in which case you might as well just write the  
datetime directly to the file, and then convert that later.

Matthias

On Nov 4, 2009, at 4:26 PM, Javier Peña wrote:

> Hello everyone,
>
> I have a netcdf file from which I can obtain any of the variables  
> with the following script (for example to get u wind component):
>
> * takes the values of the component or in a column
> 'reinit'
> 'sdfopen prueba.nc'
> 'set lat 41'
> 'set lon 359'
> 'set lev 1'
> to = 1
> * Write the variable to a file
> * 'set gxout vector'
> * 'set fwrite z: \ dummy.dat'
> while (to <5)
> 'set t' to
> tmp =''
> tmp = subwrd (rerult, 4)
> 'd u', tmp = tmp%''subwrd (result, 4)
> rrc = write ( 'c: \ prueba_c \ pruebas_archivo_ecmwf \ new_u.txt',  
> tmp)
> to = to + 1
> endwhile
>
> but my question is, can I get the date which belongs each variable  
> value? That is, if I have values for the velocity component u: 2.3,  
> 3.4, 5.6, 3.9, can I get a. txt what next?
>
> Date                         U (m / s)
> 2009/12/06 00:00          2.3
> 2009/12/06 06:00          3.4
> 2009/12/06 18:00          5.6
> 2009/12/07 00:00          3.9
>
> Thank you very much. Best regards.
>
> Javier Peña

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20091104/4233bd61/attachment.html 


More information about the gradsusr mailing list