[gradsusr] problem in looping with sdfwrite to generate multiple netcdf files

Jennifer Adams jma at cola.iges.org
Thu Feb 13 15:11:15 EST 2014


On Feb 13, 2014, at 6:12 AM, pankaj kumar wrote:

> Hi,
> 
> It's my deepest request to whosoever working to write 4-dimensional netcdf data using grads since sdfwrite is unable to generate 4-D netcdf data. My global netcdf data is in 4-D format with each yearly file has 12 time and 15 vertical points. I am trying to save errenous data from these files into netcdf format in 4-dimensions. I have tried many methods of looping in z and t scales. Although loops in z and t scales are running properly as grads displays sorted data for each time and each layer, the output file only saves data in netcdf format for final time and final layer which is 2-dimensional data. It is clear that the sdfwrite command does not allow one to write out more than one variable to a file (source: grads documentation on sdfwrite) so the sdfwrite generates output for one time and one layer only.
> 
> However, can someone tell me how to write a loop in grads to generate multiple netcdf files using sdfwrite command for each single time and each layer from my 4-D netcdf data? Once number of netcdf files are generated with data for different time and layers, I hope sdfwrite allows to concatenate all files for multiple layers first and then for long time series.
> 
> Here, I have tried a looping to produce multiple files for each layer and each time but it hasn't worked.
> _____________________________________________________________________________________
> 'set lon 0 360'
> 'set lat -90 90'
'set z 1 15'
'set t 1 12'
'var = var'
> 
> 'set sdfwrite -4d -flt -nc4 data.nc'
> 'sdfwrite var'
> 

You must define your variable with X,Y,Z, and T varying BEFORE you invoke sdfwrite. The code above will write out a 4D file for all levels and all time steps in one file. However, you will likely have an extra column so it would be better to remove 'set lon 0 360' and set the x dimension to vary by the grid size -- 'set x 1 'xsize -- where xsize is the size of your X axis. 

If you want one time step per file:
'set x 1 'xsize
'set lat -90 90'
'set z 1 15'
t=1
while (t<=12)
  'set t 't
  'var = var'
  'set sdfwrite -4d -flt -nc4 data't'.nc'
  'sdfwrite var'
  t=t+1
endwhile

In this case, your variable has 3 dimensions (X, Y, and Z) but since you use the -4d flag the variable in the netcdf file will have 4 dimensions, with the 4th being time having a size of 1. But it will provide correct metadata for the time associated with that grid. If you want your netcdf variable to have only the 3 varyding dimensions , remove the -4d from the 'set sdfwrite' statement. 
--Jennifer






> t=1
>  while(t<=12)
>   'set t 't
> 
>    z=1
>     while(z<=15)
>      'set z 'z
> 
> #  rec=read(filename.nc)
> # IO = sublin(rec,1)
> # if (IO = 0) 
> # a = subwrd(rec,2) 
> # endif 
> # 'sdfopen 'a'' 
> # say '' 
> # say ' Filename: 'a'' 
> # say ' File no: 'z'_'t''
> 
> 
>             'define var = var'
>             'd var'
>          #'set sdfwrite -4d flt -nc4 data-sort_'z'_'t'.nc'
>          #'sdfwrite var'
> 
>     z=z+1
>    endwhile
>  t=t+1
> endwhile
> 
> Thank you for your help and support here.
> Regards
> Pankaj
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr

--
Jennifer M. Adams
Center for Ocean-Land-Atmosphere Studies (COLA)
111 Research Hall, Mail Stop 2B3
George Mason University
4400 University Drive
Fairfax, VA 22030 





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20140213/767a7dac/attachment.html 


More information about the gradsusr mailing list