<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Huw:<br>
<br>
The lines in your descriptor file for XDEF and YDEF should reflect
the dimensions<br>
in your netcdf file. A sample output from ncdump might help, but I
presume you<br>
don't have dimensions "dimension1" and "dimension2", but rather
"rows" and "length"<br>
so these two lines:<br>
<br>
XDEF dimension1 180 LINEAR -104.0 2.0<br>
YDEF dimension2 80 LINEAR -80.0 2.0<br>
<br>
need to be changed to reflect what your two dimensions are, e.g., <br>
<br>
XDEF length 180 LINEAR -104.0 2.0<br>
YDEF rows 80 LINEAR -80.0 2.0<br>
<br>
<br>
Jim<br>
<br>
<br>
<div class="moz-cite-prefix">On 7/26/13 1:08 PM, Huw Davies wrote:<br>
</div>
<blockquote cite="mid:03a301ce89f8$c8b3e2d0$5a1ba870$@gmail.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<meta name="Generator" content="Microsoft Word 14 (filtered
medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal">Hello.<o:p></o:p></p>
<p class="MsoNormal">I am trying to open a NetCDF file in GRADS
that I have generated in matlab (filename swh.nc). <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">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. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">My matlab code is:<o:p></o:p></p>
<p class="MsoNormal">% Create a variable in the MATLAB workspace<o:p></o:p></p>
<p class="MsoNormal">swh_12 = flipud(swh_12(1:80, 1:180));<o:p></o:p></p>
<p class="MsoNormal">numrow = 80;<o:p></o:p></p>
<p class="MsoNormal">numcol = 180;<o:p></o:p></p>
<p class="MsoNormal">my_data=swh_12;<o:p></o:p></p>
<p class="MsoNormal">% Create a netCDF file<o:p></o:p></p>
<p class="MsoNormal">ncid = netcdf.create('swh.nc','NC_WRITE');<o:p></o:p></p>
<p class="MsoNormal">% Define a dimension in the file (must give
it a name and length or use NC_UNLIMITED)<o:p></o:p></p>
<p class="MsoNormal">dimidrow =
netcdf.defDim(ncid,'rows',numrow);<o:p></o:p></p>
<p class="MsoNormal">dimidcol =
netcdf.defDim(ncid,'length',numcol);<o:p></o:p></p>
<p class="MsoNormal">% Define a variable on the dimension (must
give it a name,data type,and a dimension ID).<o:p></o:p></p>
<p class="MsoNormal">varid =
netcdf.defVar(ncid,'swh','NC_DOUBLE',[dimidrow dimidcol]);<o:p></o:p></p>
<p class="MsoNormal">% Take the netCDF file out of define mode.
To write data to a file, you must be in data mode.<o:p></o:p></p>
<p class="MsoNormal">netcdf.endDef(ncid);<o:p></o:p></p>
<p class="MsoNormal">netcdf.putVar(ncid,varid,my_data);<o:p></o:p></p>
<p class="MsoNormal">netcdf.close(ncid);<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">----------------------------------------------<o:p></o:p></p>
<p class="MsoNormal">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) <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">My descriptor file is:<o:p></o:p></p>
<p class="MsoNormal">DSET ^swh.nc<o:p></o:p></p>
<p class="MsoNormal">TITLE Significant Wave Height<o:p></o:p></p>
<p class="MsoNormal">UNDEF -9.99<o:p></o:p></p>
<p class="MsoNormal">XDEF dimension1 180 LINEAR -104.0 2.0<o:p></o:p></p>
<p class="MsoNormal">YDEF dimension2 80 LINEAR -80.0 2.0<o:p></o:p></p>
<p class="MsoNormal">VARS 1<o:p></o:p></p>
<p class="MsoNormal">swh=>swh 1 99 swh<o:p></o:p></p>
<p class="MsoNormal">ENDVARS<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">When I execute 'xdfopen12_swh.dat' I
receive the following error:<o:p></o:p></p>
<p class="MsoNormal">---> The invalid description file record
is:<o:p></o:p></p>
<p class="MsoNormal">---> xdef 180 linear -104.0 2.0<o:p></o:p></p>
<p class="MsoNormal">-----------------------------------------------------<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Do I need to include x and y vectors in the
NetCDF - if so how do I add them to the NetCDF in matlab? <o:p></o:p></p>
<p class="MsoNormal">Is there something simple that I have
missed in the GRADS descriptor file?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Out of ideas here and would greatly
appreciate your help.<o:p></o:p></p>
<p class="MsoNormal">Huw<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
gradsusr mailing list
<a class="moz-txt-link-abbreviated" href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</a>
<a class="moz-txt-link-freetext" href="http://gradsusr.org/mailman/listinfo/gradsusr">http://gradsusr.org/mailman/listinfo/gradsusr</a>
</pre>
</blockquote>
<br>
</body>
</html>