[gradsusr] Writing a text output from Grads with header information

Arlindo da Silva dasilva at alum.mit.edu
Thu Mar 3 20:44:05 EST 2011


On Tue, Mar 1, 2011 at 7:09 PM, Muhammad Rahiz <muhammad.rahiz at ouce.ox.ac.uk
> wrote:

> Dear Felix,
>
> The attached script may do what you want. What it does is to draw the
> values of lon-lat from a text file, and for each lon-lat value, it extracts
> value of variable at each time step and appends to an output txt file.
>
> The output file would contain the following (without headers);
>
> timestep        lat     lon     var
> x.1.x           30.0    70      2.3
> ...
> x.120.x         30.0    70      2.1
> x.1.x           35.0    69.1    1.2
> ...
> x.120.x         35.0    69.1    1.3
>
> If you want to extract the timesteps, grep it;
>
>  grep "x.1.x" output.txt > timestep.1.txt
>> grep "x.120.x" output.txt > timestep.120.txt
>>
>
> or in a shell script;
>
> #!/bin/bash
>
> for i in `seq 1 120`; do # where 120 = no. of timesteps
>  grep "x.'$i'.x" output.txt > timestep.$i.txt
> done
>
> I've yet to test the script with multiple files according to your file
> specifications as I did not manage to download the files from the link you
> gave. Nonethless, this wouldn't be a problem as you can make the same
> "while-endwhile" loop to read in the files as I did for coordinates.txt. Or
> easier, concantenate the files.
>
> Do tell us how it goes...
>
>
> Muhammad Rahiz
> Researcher & DPhil Candidate (Climate Systems & Policy)
> School of Geography & the Environment
> University of Oxford
>
> On Tue, 1 Mar 2011, Felix Mutua wrote:
>
>  Hi Muhammad,
>> I'm using TRMM 3B42 Rainfall data sample on this link.. The data is Netcdf
>> with each 3hrs as a different file..I.e 3*8*365 files(=timesteps)in a
>> year...
>>
>> I was thinking of doing a shell script to open and run the grads script
>> for
>> all the time steps producing the text output for
>> some modelling application.. I'm running Opengrads in Windows and also I
>> have access to a Unix server-based one..
>>
>> Thanks and Regards
>>
>> On Tue, Mar 1, 2011 at 6:32 PM, Muhammad Rahiz
>> <muhammad.rahiz at ouce.ox.ac.uk> wrote:
>>      Hi Felix,
>>
>>      At each lon & lat, you want to extract rainfall at every time
>>      step i.e. 3 hours? Is that what you want to do? If yes, then
>>      1. how many time steps are you dealing with?
>>      2. what is the format of your file i.e. ctl or netcdf? If ctl,
>>      then I need two samples of the filename.
>>      3. are you using GrADS in windows or linux?
>>
>>      Off the top of my head, what you need is a double loop. If you
>>      could give me the details above, then I could modify a similar
>>      script that I have.
>>
>>      --
>>      Muhammad Rahiz
>>      Researcher & DPhil Candidate (Climate Systems & Policy)
>>      School of Geography & the Environment
>>      University of Oxford
>>
>>      On Tue, 1 Mar 2011, Felix Mutua wrote:
>>
>>      Thanks Muhammad,
>>      I've looked at it before...But my challenge is that I have
>>      to do this for
>>      many files  (TRMM 3 hrly precipitation data) for one
>>      year..Is there a way I
>>      can automate or just get the formatted output in Grads?
>>
>>      Thanks
>>
>>      Regards
>>
>>      On Tue, Mar 1, 2011 at 5:28 PM, Muhammad Rahiz
>>      <muhammad.rahiz at ouce.ox.ac.uk> wrote:
>>      You need the fprintf.gs script, availableathttp://
>> cookbooks.opengrads.org/index.php?title=Recipe-002:_Saving_GrADS_v
>>
>> ar
>>      iable_data_to_a_text_file.
>>
>>
>>      Muhammad Rahiz
>>      Researcher & DPhil Candidate (Climate Systems & Policy)
>>      School of Geography & the Environment
>>      University of Oxford
>>
>>
>> On Tue, 1 Mar 2011, Felix Mutua wrote:
>>
>>      Hi All, Could someone kindly assist..I'm trying to export
>>      a variable into an
>>      text output in this format ( with header)
>>
>>      Lat                            Lon               Pre
>>      ...........................................................
>>      1.5                           34.5             4.56
>>      2.0                           34.0             3.46
>>      ..                              ....               ......
>>      ..                              ....               ......
>>
>>      For a specified period...
>>
>>      Any help greatly appreciated
>>
>>
>>      Regards
>>
>>      Felix
>>
>>
>>
>>
>> _______________________________________________
>> gradsusr mailing list
>> gradsusr at gradsusr.org
>> http://gradsusr.org/mailman/listinfo/gradsusr
>>
>>
>>
>>
>>
>>
>> --
>> _________________________________________________________
>> Felix Mutua
>> School of Engineering, The University of Tokyo
>> River Engineering and Environment Laboratory
>> 7-3-1 Hongo Bunkyo-ku, Tokyo 113-8656, Japan
>> Phone +81-80-3553-0339,E-mail: Felix.mutua at gmail.com,
>> f-mutua at hydra.t.u-tokyo.ac.jp
>> Skype: Felix.mutua
>>
>>
>>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>
>
If you are a python programmer, take a look at this pygrads recipe:

http://cookbooks.opengrads.org/index.php?title=Recipe-003:_Using_PyGrADS_to_save_variable_data_to_a_text_file

I think it does exactly what you want.

    Arlindo



-- 
Arlindo da Silva
dasilva at alum.mit.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20110303/0efd8274/attachment-0003.html 


More information about the gradsusr mailing list