Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

Re: Converting GMT files to the netCDF format



Mark A Ohrenschall wrote:

Hey, I've got a really similar (identical?) problem:

I have a netCDF file that was generated by GMT, and this is what it looks like:

ncdump -v x_range,y_range,z_range,spacing,dimension gulf.nc
netcdf gulf {
dimensions:
       side = 2 ;
       xysize = 171388801 ;
variables:
       double x_range(side) ;
               x_range:units = "" ;
       double y_range(side) ;
               y_range:units = "" ;
       double z_range(side) ;
               z_range:units = "" ;
       double spacing(side) ;
       int dimension(side) ;
       float z(xysize) ;
               z:scale_factor = 1. ;
               z:add_offset = 0. ;
               z:node_offset = 0 ;

// global attributes:
               :title = "" ;
               :source = "" ;
data:
x_range = -98, -81 ;
y_range = 24, 31 ;
z_range = -3706.10009765625, 383 ;
spacing = 0.000833333333333333, 0.000833333333333333 ;
dimension = 20401, 8401 ;
}

It's implicitly a 2-D grid that I'd like to be COARDS-compliant. A colleague on the GMT maillist asked the same basic question on my behalf, and forwarded this response to me:

> From: Norman Vine <nhv@xxxxxxxx>
> Date: Wed May 7, 2003  8:09:26 AM US/Mountain
> To: gmt-help@xxxxxxxxxx
> Subject: [GMT-HELP:10777] RE: GMT to COARDS-compliant netCDF?
> Reply-To: nhv@xxxxxxxx
>
>> Is anyone aware of a utility or procedure to export data from GMT
>> into a
>> COARDS-compliant netCDF file?
>
> If you use Python this is easy enough todo
>
> Several modules build apon the Scientific Python NetCDF
> http://starship.python.net/~hinsen/ScientificPython/ <http://starship.python.net/%7Ehinsen/ScientificPython/>
>
> COARDS specific
> http://www.pyclimate.org/
>
> GMT specific
> http://starship.python.net/crew/jhauser/NCfns.py.html

I've looked a little at www.pyclimate.org, and it doesn't look like a push-button process. It may be more expedient in my case to write a hasty Java program against the Java netCDF API to do this conversion.

I'd be interested in what anyone else has done or can suggest.

Cheers,

Mark

1. COARDS requires lat/lon coordinates, so you need to make sure thats the case.

2. Its pretty easy to use the NcML writer to do this kind of transformation, once you know what metadata you need. Its like using a declarative language instead of a procedural one. Give me the CDL of what you want (or better, run it through thncgen to get a netcdf file) and ill give you the NcML to transform it.

3. I might add an "automatic" converter to particularly important Conventions like COARDS. The rub is that the original file has to have equivilent metadata, and a Convention parser needs to be written for it. Is GMT in that category? Are its conventions published?



 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690