[gradsusr] GRADS USER FORUM QUESTION

James T. Potemra jimp at hawaii.edu
Fri Jul 26 09:03:59 EDT 2013


Huw:

The lines in your descriptor file for XDEF and YDEF should reflect the 
dimensions
in your netcdf file.  A sample output from ncdump might help, but I 
presume you
don't have dimensions "dimension1" and "dimension2", but rather "rows" 
and "length"
so these two lines:

XDEF dimension1 180 LINEAR -104.0 2.0
YDEF dimension2 80 LINEAR -80.0 2.0

need to be changed to reflect what your two dimensions are, e.g.,

XDEF length 180 LINEAR -104.0 2.0
YDEF rows 80 LINEAR -80.0 2.0


Jim


On 7/26/13 1:08 PM, Huw Davies wrote:
>
> Hello.
>
> I am trying to open a NetCDF file in GRADS that I have generated in 
> matlab (filename swh.nc).
>
> The file is an 80x180 matrix of global wave height data on a regular 2 
> deg grid with bottom right corner at -80 -104 (80S 140W). The file 
> does not contain any Latitude, Longitude, X or Y information.
>
> My matlab code is:
>
> % Create a variable in the MATLAB workspace
>
> swh_12 = flipud(swh_12(1:80, 1:180));
>
> numrow = 80;
>
> numcol = 180;
>
> my_data=swh_12;
>
> % Create a netCDF file
>
> ncid = netcdf.create('swh.nc','NC_WRITE');
>
> % Define a dimension in the file (must give it a name and length or 
> use NC_UNLIMITED)
>
> dimidrow = netcdf.defDim(ncid,'rows',numrow);
>
> dimidcol = netcdf.defDim(ncid,'length',numcol);
>
> % Define a variable on the dimension (must give it a name,data 
> type,and a dimension ID).
>
> varid = netcdf.defVar(ncid,'swh','NC_DOUBLE',[dimidrow dimidcol]);
>
> % Take the netCDF file out of define mode. To write data to a file, 
> you must be in data mode.
>
> netcdf.endDef(ncid);
>
> netcdf.putVar(ncid,varid,my_data);
>
> netcdf.close(ncid);
>
> ----------------------------------------------
>
> To open this in GRADS I need to create a descriptor file as 'sdfopen' 
> cannot find the xdef and ydef (as they aren't in the NetCDF)
>
> My descriptor file is:
>
> DSET ^swh.nc
>
> TITLE Significant Wave Height
>
> UNDEF -9.99
>
> XDEF dimension1 180 LINEAR -104.0 2.0
>
> YDEF dimension2 80 LINEAR -80.0 2.0
>
> VARS 1
>
> swh=>swh 1 99 swh
>
> ENDVARS
>
> When I execute 'xdfopen12_swh.dat' I receive the following error:
>
> ---> The invalid description file record is:
>
> ---> xdef 180 linear -104.0 2.0
>
> -----------------------------------------------------
>
> Do I need to include x and y vectors in the NetCDF - if so how do I 
> add them to the NetCDF in matlab?
>
> Is there something simple that I have missed in the GRADS descriptor file?
>
> Out of ideas here and would greatly appreciate your help.
>
> Huw
>
>
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20130726/3b24a065/attachment-0003.html 


More information about the gradsusr mailing list