[gradsusr] txt to gridded binary file?

Reto Stauffer Reto.Stauffer at student.uibk.ac.at
Fri Aug 19 03:43:35 EDT 2011


Servus Meg

It is quite simple but i invested some hours to sail around some  
problems :). Therefore i will give you some hints. Maybe it could help  
you.

My project was to visualize my MOS-forecasts in GrADS. Therefore the  
stationdata option in GrADS can be used. What you have to do is to  
create a binary file with the stationdata in a special format, the  
controlfile and some small other things. I made it in fortran for my  
project.

There is a tutorial to do that on the wishingwork webpage  
(http://www.wishingwork.com/grads/gridded-station-data.html) but the  
fortran code you can get there is .... öh ... do not use it.

While writing the binary file it is VERRY important to use the correct  
format. Some values have to be 4-bit, others 8-bit.

This i wrote into my fortran-header
------------------------------------
! IMPORTANT:     The GrADS visualisation software requires a special
!                data-set. Therefore a controlscript (.ctl) and the
!                data-file (.bin) is written on the fly in this script.
!                This binary file needs some special value-definitions!
!                Please do not change them - else GrADS cannot read
!                the data.
!                - stnr has to be integer*8
!                - all other integer values have to be *4 (single precision)
!                - all real values have to be *4 (single precision)
------------------------------------

! Now open the new GrADS stationdata file (binary, stream)
   open(11, file=trim(pathout)//'/'//trim(gradsBIN), form='unformatted', &
            status='replace', access='stream',iostat=ios)

Again some commens out of my code. GrADS reads
alwasys "time dependent" so the first block is
only containing data for the first time, afterwards
you have to "close" this time-block with a
terminate line (please have a look to
http://www.wishingwork.com/grads/control-file/write-station-data.html
where the terminate line is explained mor detailed; it is
nothing else like one of the "station" lines but has some
special flags). Afterwards you can bein with the
next time-block.
------------------------------------
! The expected "format" for the GrADS file is like the following example
! station1  lat1  lon1  time1  nlev  nflag    \
!   sutable forecast values                    |
! station2  lat2  lon2  time1  nlev  nflag     |  time1
!   sutable forecast values                    |  all stations, one leadime!
! station3  lat3  lon3  time1  nlev  nflag     |
!   sutable forecast values                   /
! terminate line
! station1  lat1  lon1  time2  nlev  nflag    \
!   sutable forecast values                    |
! station2  lat2  lon2  time2  nlev  nflag     | time 2
!   sutable forecast values                    | all stations, one leadtime!
! station3  lat3  lon3  time2  nlev  nflag     |
!   sutable forecast values                   /
! terminate line
------------------------------------

And within some loops to create the format
you can se above you can write your data into
the binary file.
------------------------------------
write(11)  stnr,lat,lon,zero,nlev,nflag
------------------------------------

As you can see there is no format definition for the binary file. This  
is the reason wha the variables have to be in the correct form (single  
our double precission) to avoid problems.


Depending on the number of variables you wrote into the datalines of  
the binary file you have co create the correct controlfile for grads  
also. It is a
normal controlfile with "stationdata" options. One of mine is ...


------------------------------------
dset ^AUMOS_GrADS_2011081100_GRADSeu.bin
dtype station
stnmap grads.map
undef -999.
tdef 37 linear 00z11aug2011 3hr
vars 35
spot       0 99 spot
tmax       0 99 tmax
....
....
aktww4     0 99 aktww4
aktww5     0 99 aktww5
aktww6     0 99 aktww6
endvars
------------------------------------


If all this is correct you have to create the stationmap for GrADS.  
stnmp is an executable delivered with GrADS. -q option means quite, -i  
is for the inputfile. After that stnmap creates a new file.
------------------------------------
stnmap -q -i AUMOS_GrADS_2011081100_GRADSeu.ctl
------------------------------------

Now you can plot the data in GrADS. I havnt done any  
cressmann-interpolation until now, only plotted the values i get from  
the MOS.

Probably this hints can help you or anyone else who googles in the future :).

Have a nice day out there

Best wishes
Reto, Switzerland




Zitat von "Huddleston, John" <Huddleston at cira.colostate.edu>:

> Hi Meg
>
> See  
> http://cookbooks.opengrads.org/index.php?title=Recipe-013:_Gridding_and_Plotting_Station_Data
>
> and http://cookbooks.opengrads.org/index.php?title=Table_of_Contents  
> for more goodies.
>
> John Huddleston
>
> ________________________________________
> From: gradsusr-bounces at gradsusr.org [gradsusr-bounces at gradsusr.org]  
> On Behalf Of Meg Sutton [mcs2214 at columbia.edu]
> Sent: Thursday, August 18, 2011 8:35 AM
> To: gradsusr at gradsusr.org
> Subject: [gradsusr] txt to gridded binary file?
>
> I'm using a program that outputs only formatted data, (separated by  
> tabs) does anyone know how I can convert this data to the correct  
> format to use in GrADS?
> Thanks for your help,
> Meg
>
>
>
>
> _______________________________________________
> 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
>






More information about the gradsusr mailing list