[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #SHR-240384]: txt to cdl



> I'm trying to convert a TXT FILE INTO A CDL FILE inn fortran, and then
> use ncgen to convert to netcdf
> 
> I need to see how to
> 
> 
> Here is the metadata of the files
> 
> !!$ Map metadata
> !!$
> !!$ Map Projection: Polar Stereographic Ellipsoid
> !!$ Map Reference Latitude: 90.0
> !!$ Map Reference Longitude: -39.0
> !!$ Map Second Reference Latitude: 71.0
> !!$ Map Eccentricity: 0.081819190843 ;wgs84
> !!$ Map Equatorial Radius: 6378137.0 ;wgs84 meters
> !!$
> 
> !!$ Grid metadata
> !!$
> !!$ Grid Map Origin Column: 160
> !!$ Grid Map Origin Row: -120
> !!$ Grid Map Units per Cell: 5000 ( 5 km)
> !!$ Grid Width: 301 ( Number of units)
> !!$ Grid Height: 561 ( number of Units)x

I would first just create a skeleton CDL file with a text editor, but
without the actual data, just the metadata.  Then you could have the
Fortran program print the data as text to a file, making sure you
separate the data values with commas, and use ";" after the last data
value (or just do that in a text editor manually).  Finally you could
just combine these two files into a larger CDL file and use ncgen.

Here's a little more detail about these steps.

1.  Create a skeleton CDL file with all the metadata and schema for
    the data (dimensions, variable names and types, attributes).  You
    should follow some conventions for how to do this, preferably the
    CF Conventions at 

       http://www.cfconventions.org/

    So, your skeleton CDL file might look something like this example.
    Note, I have stuck in a few of your values, but you will have to
    verify these and find out what to use for things like
    false_easting and false_northing, which I know nothing about:

netcdf mygrids {
dimensions:
   xc = 301;
   yc = 561;
 variables:
   char polar_stereographic;
     polar_stereographic:grid_mapping_name = "polar_stereographic";
     polar_stereographic:straight_vertical_longitude_from_pole = -39.0f;
     polar_stereographic:standard_parallel = 71.0f;
     polar_stereographic:false_easting = -2264501.0f;
     polar_stereographic:false_northing = 4844997.5f;
     polar_stereographic:latitude_of_projection_origin = 90.0f;
     polar_stereographic:resolution_at_standard_parallel = 2500.0f;
     polar_stereographic:_CoordinateTransformType = "Projection";
     polar_stereographic:_CoordinateAxisTypes = "GeoX GeoY";
   float xc(xc);
     xc:units = "m";
     xc:long_name = "x-coordinate of polar-stereographic projection";
     xc:standard_name = "projection_x_coordinate";
     xc:axis = "X";
     xc:coordinate_defines = "point";
     xc:actual_range = 0.0d, 390000.0d;
     xc:_CoordinateAxisType = "GeoX";
   float yc(yc);
     yc:units = "m";
     yc:long_name = "y-coordinate of polar-stereographic projection";
     yc:standard_name = "projection_y_coordinate";
     yc:axis = "Y";
     yc:coordinate_defines = "point";
     yc:actual_range = 0.0d, 525000.0d;
     yc:_CoordinateAxisType = "GeoY";
   double lon(yc, xc);
     lon:units = "degrees_east";
     lon:long_name = "longitude";
     lon:standard_name = "longitude";
     lon:actual_range = 275.0508346557617, 281.5693588256836; // double
     lon:_CoordinateAxisType = "Lon";
   double lat(yc, xc);
     lat:units = "degrees_north";
     lat:long_name = "latitude";
     lat:standard_name = "latitude";
     lat:actual_range = 40.151729583740234, 45.38578414916992; // double
     lat:_CoordinateAxisType = "Lat";
   float mygrid(yc, xc) ;
     mygrid:long_name = "sea surface temperature" ;
     mygrid:units = "kelvin" ;
     mygrid:coordinates = "lon lat" ;
     mygrid:grid_mapping = "polar_stereographic" ;
     mygrid:source = "EUMETSAT SAF O&SI" ;
 // Global attributes
 :Conventions = "CF 1.4";
data:
}

edited to match your own metadata, but with no data.

2.  Write a Fortran program to print the data but remember that the
    CDL has the last dimension varying fastest, unlike Fortran, so be
    sure the data for mygrid, lon, and lat, if you follow the example
    above, has the xc dimension varying fastest in the data output.
    Separate values with ", ".

    Note that to follow the CF Conventions, you need to provide the
    lat and lon of each grid point, even though this is redundant from
    providing the projection information.  You can calculate these
    lat/lon values using formulas referenced in the CF Conventions
    document.

3.  Manually edit the data values you have printed into the above
    file, preceded by variable names and ending with ";", e.g.:

    mygrid = 
      297.5, 298, 298.5, 299, 298, 297, 300.0, 
      ...
      301.5, 302;
    lon = 
      ...
    lat = 
      ...
    xc = 
      ...
    yc = 
      ...

4.  Use ncgen to generate a netCDF file.

5.  Use some netCDF visualization tool (r.g. ncview, NCL, IDL, MATLAB,
    IDV, ...) to verify that the data looks right
     
Obviously if you will have to do this hundreds of times for different
data sets, you will want to automate the manual steps, probably by
including them in the Fortran program.  But it would be easier to get
things right first for one set of data before automating things, in my
opinion.

Hope this helps ...

--Russ

Russ Rew                                         UCAR Unidata Program
address@hidden                     http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: SHR-240384
Department: Support netCDF
Priority: Normal
Status: Closed