[gradsusr] using fwrite

Charles Seman Charles.Seman at noaa.gov
Thu Jun 17 12:02:42 EDT 2010


Chris,

Some comments regarding your questions 1) and 2)...

1) try removing the "OPTIONS yrev" in your "out4.dat" ctl file... it 
appears that GrADS is flipping the data in the N/S direction when you 
issue "open test.ctl" since it has "OPTIONS yrev"... then the data that 
is written out into out4.dat is "flipped" data so there is no need to 
have an "OPTIONS yrev" in the "out4.ctl"...

2) for more than one variable, please study 
http://grads.iges.org/grads/gadoc/aboutgriddeddata.html#structure
from the above web site:
---

The structure of a 3-D, 4-D, or 5-D data set is determined by the order 
in which the horizonal grids are written to file. The building blocks 
are stacked in a sequence according to dimension. The sequence goes in 
the following order starting from the fastest varying dimension to the 
slowest varying dimension: longitude (X), latitude (Y), vertical level 
(Z), variable (VAR), time (T), and ensemble (E).

For example, suppose you want to create a 4-D binary data set containing 
four variables. The horizonal grids would be written to the data set in 
the following order:

      Time 1, Variable 1, Each vertical level from bottom to top
      Time 1, Variable 2, Each vertical level from bottom to top
      Time 1, Variable 3, Each vertical level from bottom to top
      Time 1, Variable 4, Each vertical level from bottom to top

      Time 2, Variable 1, Each vertical level from bottom to top
      Time 2, Variable 2, Each vertical level from bottom to top
      Time 2, Variable 3, Each vertical level from bottom to top
      Time 2, Variable 4, Each vertical level from bottom to top

      etc.
        

---
condensing the above information from the above web site into example 
pseudo-code, try something like the following (caution: code not tested)...
note, "var1", "var2" should be defined to be 2D (x,y) variables 
appropriate for each level "zz"...

'set fwrite out4.dat'
'set gxout fwrite'
tt=1
while ( tt <= tlast )
  zz=1
  while ( zz <= ztop )
    'define var1 = ...'
    'd var1'
    'undefine var1'
    zz=zz+1
  endwhile
  zz=1
  while ( zz <= ztop )
    'define var2 = ...'
    'd var2'
    'undefine var2'
    zz=zz+1
  endwhile
  tt=tt+1
endwhile
'disable fwrite'

Hope this helps,
Chuck

Alauda arvensis wrote:
>
> Dear GrADS users,
>
>  
> I wish to open a GrADS file (test.ctl) and save one variable to a 
> different file (out4.ctl).  For this purpose I type the following:
>  
>
> open test.ctl
>
> set fwrite out4.dat
>
> set gxout fwrite
>
> d var130
>  
> I now have a binary file called "out4.dat" which contains my variable 
> "var130". To open it in GrADS I need to create the respective 
> .ctl-file. I copy it from test.ctl and make a few changes (see both 
> test.ctl and out4.ctl below). I can open "out4" in GrADS and display 
> "var130". Unfortunately the data does not display correctly: all 
> longitude values are displayed correctly but all latitude values are 
> upside down, comparible to the effect of a mirrow.
>  
> My questions:
>  
>
> (1) Why is my data not displaying correctly and what do I need to do 
> to fix this?
>
> (2) Is it possible to save more than 1 variable in a binary file? I 
> tried this by applying the steps above and typing after "d var130" 
> also "d var157". I then apply the respective changes in the .ctl-file 
> (i.e. VARS 2 and var157 14 157,100 var157). However, I can only 
> display "var130" and not "var157".
>
> (3) Is this methodology (fwrite) the best way to save changes after 
> the manipulation of a GrADS file?
>  
>
> Thank you very much in advance.
>
>  
>
> With kind regards,
>
> Chris
>
>  
> ###################################
> test.ctl
>  
>
> * Generated by CDO version 1.4.0
>
> *
>
> DSET ^test.grb
>
> DTYPE GRIB
>
> INDEX ^test.gmp
>
> XDEF 55 LINEAR 270.000000 1.125000
>
> YDEF 47 LEVELS -40.934 -39.813 -38.691 -37.570 -36.448 -35.327
>
> -34.205 -33.084 -31.962 -30.841 -29.719 -28.598
>
> -27.476 -26.355 -25.234 -24.112 -22.991 -21.869
>
> -20.748 -19.626 -18.505 -17.383 -16.262 -15.140
>
> -14.019 -12.897 -11.776 -10.654 -9.533 -8.411
>
> -7.290 -6.168 -5.047 -3.925 -2.804 -1.682
>
> -0.561 0.561 1.682 2.804 3.925 5.047
>
> 6.168 7.290 8.411 9.533 10.654
>
> ZDEF 14 LEVELS 1000 925 850 700 500 400 300 250 200 150
>
> 100 70 50 30
>
> TDEF 4 LINEAR 00:00Z01jan1960 1dy
>
> TITLE test.grb T31 grid
>
> OPTIONS yrev
>
> UNDEF -9e+33
>
> VARS 5
>
> var130 14 130,100 var130
>
> var157 14 157,100 var157
>
> var129 14 129,100 var129
>
> var131 14 131,100 var131
>
> var132 14 132,100 var132
>
> ENDVARS
>  
> ###################################
>  
> out4.ctl
>  
>
> * Generated by CDO version 1.4.0
>
> *
>
> DSET ^out4.dat
>
> XDEF 55 LINEAR 270.000000 1.125000
>
> YDEF 47 LEVELS -40.934 -39.813 -38.691 -37.570 -36.448 -35.327
>
> -34.205 -33.084 -31.962 -30.841 -29.719 -28.598
>
> -27.476 -26.355 -25.234 -24.112 -22.991 -21.869
>
> -20.748 -19.626 -18.505 -17.383 -16.262 -15.140
>
> -14.019 -12.897 -11.776 -10.654 -9.533 -8.411
>
> -7.290 -6.168 -5.047 -3.925 -2.804 -1.682
>
> -0.561 0.561 1.682 2.804 3.925 5.047
>
> 6.168 7.290 8.411 9.533 10.654
>
> ZDEF 14 LEVELS 1000 925 850 700 500 400 300 250 200 150
>
> 100 70 50 30
>
> TDEF 4 LINEAR 00:00Z01jan1960 1dy
>
> TITLE out4.dat
>
> OPTIONS yrev
>
> UNDEF -9e+33
>
> VARS 1
>
> var130 14 130,100 var130
>
> ENDVARS
>
>  
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>   

-- 

Please note that Charles.Seman at noaa.gov should be considered my NOAA
email address, not cjs at gfdl.noaa.gov.

********************************************************************
 Charles Seman                                Charles.Seman at noaa.gov
 U.S. Department of Commerce / NOAA / OAR
 Geophysical Fluid Dynamics Laboratory         voice: (609) 452-6547
 201 Forrestal Road                              fax: (609) 987-5063
 Princeton, NJ  08540-6649            http://www.gfdl.noaa.gov/~cjs/
********************************************************************

"The contents of this message are mine personally and do not reflect any
official or unofficial position of the United States Federal Government,
the United States Department of Commerce, or NOAA."




More information about the gradsusr mailing list