Commit 905a0f6a authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

add support for GRID type SINUSOIDAL

parent b9751ad8
2008-12-?? Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* add support for GRID type SINUSOIDAL
* add support of GRIB level type MEANSEA
* cdf_inq_contents: check zaxis type "depth_blow_sea/land" (bug fix)
......
......@@ -246,6 +246,7 @@ static void printGridInfo(int vlistID)
int ngrids, index;
int gridID, gridtype, trunc, gridsize, xsize, ysize;
int nbyte0;
char xname[128], yname[128], xunits[128], yunits[128];
ngrids = vlistNgrids(vlistID);
for ( index = 0; index < ngrids; index++ )
......@@ -256,22 +257,27 @@ static void printGridInfo(int vlistID)
gridsize = gridInqSize(gridID);
xsize = gridInqXsize(gridID);
ysize = gridInqYsize(gridID);
gridInqXname(gridID, xname);
gridInqYname(gridID, yname);
gridInqXunits(gridID, xunits);
gridInqYunits(gridID, yunits);
/* nbyte0 = fprintf(stdout, " %4d : %-23s : ",*/
nbyte0 = fprintf(stdout, " %4d : %-12s > ",
gridID+1, gridNamePtr(gridtype));
if ( gridtype == GRID_LONLAT ||
gridtype == GRID_SINUSOIDAL ||
gridtype == GRID_GAUSSIAN ||
gridtype == GRID_GAUSSIAN_REDUCED )
{
double lonfirst = 0.0, lonlast = 0.0;
double latfirst = 0.0, latlast = 0.0;
double loninc = 0.0, latinc = 0.0;
double xfirst = 0.0, xlast = 0.0;
double yfirst = 0.0, ylast = 0.0;
double xinc = 0.0, yinc = 0.0;
latfirst = gridInqYval(gridID, 0);
latlast = gridInqYval(gridID, ysize-1);
latinc = gridInqYinc(gridID);
yfirst = gridInqYval(gridID, 0);
ylast = gridInqYval(gridID, ysize-1);
yinc = gridInqYinc(gridID);
if ( gridtype == GRID_GAUSSIAN_REDUCED )
{
fprintf(stdout, "size : dim = %d nlat = %d\n", gridsize, ysize);
......@@ -280,22 +286,24 @@ static void printGridInfo(int vlistID)
}
else
{
lonfirst = gridInqXval(gridID, 0);
lonlast = gridInqXval(gridID, xsize-1);
loninc = gridInqXinc(gridID);
xfirst = gridInqXval(gridID, 0);
xlast = gridInqXval(gridID, xsize-1);
xinc = gridInqXinc(gridID);
fprintf(stdout, "size : dim = %d nlon = %d nlat = %d\n", gridsize, xsize, ysize);
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "longitude : first = %.9g last = %.9g", lonfirst, lonlast);
if ( !DBL_IS_EQUAL(loninc, 0) )
fprintf(stdout, " inc = %.9g", loninc);
fprintf(stdout, "%-9s : first = %.9g last = %.9g", xname, xfirst, xlast);
if ( !DBL_IS_EQUAL(xinc, 0) )
fprintf(stdout, " inc = %.9g", xinc);
fprintf(stdout, " %s", xunits);
if ( gridIsCircular(gridID) )
fprintf(stdout, " circular");
fprintf(stdout, "\n");
}
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "latitude : first = %.9g last = %.9g", latfirst, latlast);
if ( !DBL_IS_EQUAL(latinc, 0) && gridtype == GRID_LONLAT )
fprintf(stdout, " inc = %.9g", latinc);
fprintf(stdout, "%-9s : first = %.9g last = %.9g", yname, yfirst, ylast);
if ( !DBL_IS_EQUAL(yinc, 0) && (gridtype == GRID_LONLAT || gridtype == GRID_SINUSOIDAL) )
fprintf(stdout, " inc = %.9g", yinc);
fprintf(stdout, " %s", yunits);
fprintf(stdout, "\n");
if ( gridIsRotated(gridID) )
......@@ -338,8 +346,6 @@ static void printGridInfo(int vlistID)
if ( gridInqXvals(gridID, NULL) && gridInqYvals(gridID, NULL) )
{
int i;
char xunits[256];
char yunits[256];
double *xvals, *yvals;
double xfirst, xlast, yfirst, ylast;
xvals = (double *) malloc(gridsize*sizeof(double));
......@@ -347,8 +353,6 @@ static void printGridInfo(int vlistID)
gridInqXvals(gridID, xvals);
gridInqYvals(gridID, yvals);
gridInqXunits(gridID, xunits);
gridInqYunits(gridID, yunits);
xfirst = xvals[0];
xlast = xvals[0];
......@@ -363,12 +367,12 @@ static void printGridInfo(int vlistID)
}
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "longitude : min = %.9g max = %.9g %s", xfirst, xlast, xunits);
fprintf(stdout, "%-9s : min = %.9g max = %.9g %s", xname, xfirst, xlast, xunits);
if ( gridIsCircular(gridID) )
fprintf(stdout, " circular");
fprintf(stdout, "\n");
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "latitude : min = %.9g max = %.9g %s\n", yfirst, ylast, yunits);
fprintf(stdout, "%-9s : min = %.9g max = %.9g %s\n", yname, yfirst, ylast, yunits);
free(xvals);
free(yvals);
......
......@@ -109,6 +109,7 @@ extern "C" {
#define GRID_CURVILINEAR 10
#define GRID_LCC 11 /* Lambert Conformal Conic */
#define GRID_LAEA 12 /* Lambert Azimuthal Equal Area */
#define GRID_SINUSOIDAL 13 /* Sinusoidal */
/* ZAXIS types */
......
This diff is collapsed.
......@@ -48,7 +48,7 @@ typedef struct {
char xunits[256];
char yunits[256];
}
GRID;
grid_t;
const double *gridInqXvalsPtr(int gridID);
......@@ -58,8 +58,8 @@ double *gridInqXboundsPtr(int gridID);
double *gridInqYboundsPtr(int gridID);
const double *gridInqAreaPtr(int gridID);
int gridCompare(int gridID, GRID grid);
int gridGenerate(GRID grid);
int gridCompare(int gridID, grid_t grid);
int gridGenerate(grid_t grid);
/* GME grid */
void gme_grid(int gridsize, double *rlon, double *rlat,
......
......@@ -2227,6 +2227,38 @@ void cdfDefPole(int streamID, int gridID)
}
void cdfDefMapping(int streamID, int gridID)
{
#if defined (HAVE_LIBNETCDF)
int fileID;
int ncvarid = UNDEFID;
int ncerr;
if ( gridInqType(gridID) == GRID_SINUSOIDAL )
{
char varname[] = "sinusoidal";
char mapname[] = "sinusoidal";
fileID = streamInqFileID(streamID);
cdf_redef(fileID);
ncerr = nc_def_var(fileID, varname, (nc_type) NC_CHAR, 0, NULL, &ncvarid);
if ( ncerr == NC_NOERR )
{
cdf_put_att_text(fileID, ncvarid, "grid_mapping_name", strlen(mapname), mapname);
/*
cdf_put_att_double(fileID, ncvarid, "grid_north_pole_latitude", NC_DOUBLE, 1L, &ypole);
cdf_put_att_double(fileID, ncvarid, "grid_north_pole_longitude", NC_DOUBLE, 1L, &xpole);
*/
}
cdf_enddef(fileID);
}
#endif
}
void cdfDefGrid(int streamID, int gridID)
{
#if defined (HAVE_LIBNETCDF)
......@@ -2286,6 +2318,13 @@ void cdfDefGrid(int streamID, int gridID)
{
cdfDefCell(streamID, gridID);
}
else if ( gridtype == GRID_SINUSOIDAL )
{
cdfDefXaxis(streamID, gridID);
cdfDefYaxis(streamID, gridID);
cdfDefMapping(streamID, gridID);
}
/*
else if ( gridtype == GRID_LCC )
{
......@@ -2485,6 +2524,12 @@ int cdfDefVar(int streamID, int varID)
cdf_put_att_text(fileID, ncvarid, "grid_mapping", strlen(mapping), mapping);
}
if ( gridInqType(gridID) == GRID_SINUSOIDAL )
{
char mapping[] = "sinusoidal";
cdf_put_att_text(fileID, ncvarid, "grid_mapping", strlen(mapping), mapping);
}
if ( gridInqType(gridID) == GRID_TRAJECTORY )
{
cdf_put_att_text(fileID, ncvarid, "coordinates", 9, "tlon tlat" );
......@@ -3518,7 +3563,7 @@ int cdfInqContents(int streamID)
size_t len;
int nc_nvars;
int nvcth_id = UNDEFID, vcta_id = UNDEFID, vctb_id = UNDEFID;
GRID grid;
grid_t grid;
int gridindex;
int zaxisindex;
size_t vctsize = 0;
......@@ -3817,6 +3862,8 @@ int cdfInqContents(int streamID)
ncvars[ncvarid].gridtype = GRID_CELL;
else if ( strncmp(attstring, "curvilinear", attlen) == 0 )
ncvars[ncvarid].gridtype = GRID_CURVILINEAR;
else if ( strncmp(attstring, "sinusoidal", attlen) == 0 )
/* ncvars[ncvarid].gridtype = GRID_CURVILINEAR */;
else
{
static int warn = TRUE;
......@@ -4596,7 +4643,7 @@ int cdfInqContents(int streamID)
if ( ncvars[ncvarid].gridtype == UNDEFID || ncvars[ncvarid].gridtype == GRID_GENERIC )
if ( ydimid == xdimid ) ncvars[ncvarid].gridtype = GRID_CELL;
memset(&grid, 0, sizeof(GRID));
memset(&grid, 0, sizeof(grid_t));
grid.prec = DATATYPE_FLT64;
grid.trunc = ncvars[ncvarid].truncation;
......@@ -4872,6 +4919,8 @@ int cdfInqContents(int streamID)
if ( strcmp(attstring, "rotated_latitude_longitude") == 0 )
grid.isRotated = TRUE;
else if ( strcmp(attstring, "sinusoidal") == 0 )
grid.type = GRID_SINUSOIDAL;
}
else if ( strcmp(attname, "grid_north_pole_latitude") == 0 )
{
......
......@@ -260,7 +260,7 @@ void extAddRecord(int streamID, int code, int level, int xysize,
int tsID, recID, varID;
int datatype;
RECORD *record;
GRID grid;
grid_t grid;
int vlistID;
STREAM *streamptr;
......@@ -276,7 +276,7 @@ void extAddRecord(int streamID, int code, int level, int xysize,
(*record).code = code;
(*record).ilevel = level;
memset(&grid, 0, sizeof(GRID));
memset(&grid, 0, sizeof(grid_t));
grid.type = GRID_GENERIC;
grid.size = xysize;
grid.xsize = xysize;
......
......@@ -715,7 +715,7 @@ void grbAddRecord(int streamID, int code, int *isec1, int *isec2, double *fsec2,
int numavg;
int lbounds = 0;
RECORD *record;
GRID grid;
grid_t grid;
int vlistID;
STREAM *streamptr;
......@@ -750,7 +750,7 @@ void grbAddRecord(int streamID, int code, int *isec1, int *isec2, double *fsec2,
ISEC4_NumValues = ISEC2_NumLon*ISEC2_NumLat;
}
memset(&grid, 0, sizeof(GRID));
memset(&grid, 0, sizeof(grid_t));
switch (gridtype)
{
case GRID_LONLAT:
......
......@@ -610,7 +610,7 @@ void iegAddRecord(int streamID, int code, int *pdb, int *gdb, double *vct,
int gridtype;
int lbounds = 0;
RECORD *record;
GRID grid;
grid_t grid;
int vlistID;
STREAM *streamptr;
......@@ -648,7 +648,7 @@ void iegAddRecord(int streamID, int code, int *pdb, int *gdb, double *vct,
else
gridtype = GRID_GENERIC;
memset(&grid, 0, sizeof(GRID));
memset(&grid, 0, sizeof(grid_t));
grid.type = gridtype;
grid.size = IEG_G_NumLon(gdb)*IEG_G_NumLat(gdb);
grid.xsize = IEG_G_NumLon(gdb);
......
......@@ -278,7 +278,7 @@ void srvAddRecord(int streamID, int code, int level, int xsize, int ysize,
int tsID, recID, varID;
int datatype;
RECORD *record;
GRID grid;
grid_t grid;
int vlistID;
STREAM *streamptr;
......@@ -294,7 +294,7 @@ void srvAddRecord(int streamID, int code, int level, int xsize, int ysize,
(*record).code = code;
(*record).ilevel = level;
memset(&grid, 0, sizeof(GRID));
memset(&grid, 0, sizeof(grid_t));
grid.type = GRID_GENERIC;
grid.size = xsize*ysize;
grid.xsize = xsize;
......
......@@ -513,7 +513,7 @@ void varDefVCT(size_t vctsize, double *vctptr)
}
int varDefGrid(int vlistID, GRID grid, int mode)
int varDefGrid(int vlistID, grid_t grid, int mode)
{
/*
mode: 0 search in vlist and grid table
......
......@@ -12,7 +12,7 @@ void varAddRecord(int recID, int code, int gridID, int zaxistype, int lbounds,
void varDefVCT(size_t vctsize, double *vctptr);
int varDefGrid(int vlistID, GRID grid, int mode);
int varDefGrid(int vlistID, grid_t grid, int mode);
int varDefZaxis(int vlistID, int zaxistype, int nlevels, double *levels, int lbounds,
double *levels1, double *levels2, int vctsize, double *vct, char *name,
char *longname, char *units, int prec, int mode, int ltype);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment