Commit 7c1dc9a5 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added function cdf_def_mapping().

parent faf298b7
......@@ -164,8 +164,8 @@ void *resizeBuf(void **buf, size_t *bufSize, size_t reqSize)
return *buf;
}
static
void cdfDefineAttributes(int vlistID, int varID, int fileID, int ncvarID)
void cdfDefineAttributes(int cdiID, int varID, int fileID, int ncvarID)
{
int atttype, attlen;
size_t len;
......@@ -174,11 +174,11 @@ void cdfDefineAttributes(int vlistID, int varID, int fileID, int ncvarID)
size_t attBufSize = 0;
int natts;
vlistInqNatts(vlistID, varID, &natts);
vlistInqNatts(cdiID, varID, &natts);
for ( int iatt = 0; iatt < natts; iatt++ )
{
vlistInqAtt(vlistID, varID, iatt, attname, &atttype, &attlen);
vlistInqAtt(cdiID, varID, iatt, attname, &atttype, &attlen);
if ( attlen == 0 ) continue;
......@@ -186,7 +186,7 @@ void cdfDefineAttributes(int vlistID, int varID, int fileID, int ncvarID)
{
size_t attSize = (size_t)attlen*sizeof(char);
char *atttxt = (char *)resizeBuf(&attBuf, &attBufSize, attSize);
vlistInqAttTxt(vlistID, varID, attname, attlen, atttxt);
vlistInqAttTxt(cdiID, varID, attname, attlen, atttxt);
len = (size_t)attlen;
cdf_put_att_text(fileID, ncvarID, attname, len, atttxt);
}
......@@ -196,7 +196,7 @@ void cdfDefineAttributes(int vlistID, int varID, int fileID, int ncvarID)
{
size_t attSize = (size_t)attlen*sizeof(int);
int *attint = (int *)resizeBuf(&attBuf, &attBufSize, attSize);
vlistInqAttInt(vlistID, varID, attname, attlen, &attint[0]);
vlistInqAttInt(cdiID, varID, attname, attlen, &attint[0]);
len = (size_t)attlen;
nc_type xtype = (atttype == DATATYPE_INT8) ? NC_BYTE :
(atttype == DATATYPE_INT16) ? NC_SHORT :
......@@ -212,7 +212,7 @@ void cdfDefineAttributes(int vlistID, int varID, int fileID, int ncvarID)
{
size_t attSize = (size_t)attlen * sizeof(double);
double *attflt = (double *)resizeBuf(&attBuf, &attBufSize, attSize);
vlistInqAttFlt(vlistID, varID, attname, attlen, attflt);
vlistInqAttFlt(cdiID, varID, attname, attlen, attflt);
len = (size_t)attlen;
if ( atttype == DATATYPE_FLT32 )
{
......@@ -581,7 +581,8 @@ int cdfDefVar(stream_t *streamptr, int varID)
}
}
if ( gridtype != GRID_GENERIC && gridtype != GRID_LONLAT && gridtype != GRID_CURVILINEAR )
if ( gridtype != GRID_GENERIC && gridtype != GRID_LONLAT &&
gridtype != GRID_PROJECTION && gridtype != GRID_CURVILINEAR )
{
size_t len = strlen(gridNamePtr(gridtype));
if ( len > 0 )
......@@ -594,7 +595,12 @@ int cdfDefVar(stream_t *streamptr, int varID)
cdf_put_att_text(fileID, ncvarid, "grid_mapping", strlen(mapping), mapping);
}
if ( gridtype == GRID_SINUSOIDAL )
if ( gridtype == GRID_PROJECTION )
{
char mapping[] = "dummy";
cdf_put_att_text(fileID, ncvarid, "grid_mapping", strlen(mapping), mapping);
}
else if ( gridtype == GRID_SINUSOIDAL )
{
char mapping[] = "sinusoidal";
cdf_put_att_text(fileID, ncvarid, "grid_mapping", strlen(mapping), mapping);
......
......@@ -170,7 +170,7 @@ void grid_init(grid_t *gridptr)
memset(gridptr->uuid, 0, CDI_UUID_SIZE);
gridptr->name = NULL;
gridptr->vtable = &cdiGridVtable;
gridptr->atts.nalloc = 0;
gridptr->atts.nalloc = MAX_ATTRIBUTES;
gridptr->atts.nelems = 0;
}
......
......@@ -16,6 +16,8 @@ void cdfDefRecord(stream_t * streamptr);
void cdfCopyRecord(stream_t *streamptr2, stream_t *streamptr1);
void cdfDefineAttributes(int vlistID, int varID, int fileID, int ncvarID);
void cdf_read_record(stream_t *streamptr, int memtype, void *data, int *nmiss);
void cdf_write_record(stream_t *streamptr, int memtype, const void *data, int nmiss);
......
......@@ -943,7 +943,7 @@ void cdf_set_cdi_attr(int ncid, int ncvarid, int attnum, int cdiID, int varID)
int attint[attlen];
cdfGetAttInt(ncid, ncvarid, attname, (int)attlen, attint);
int datatype = (atttype == NC_SHORT) ? DATATYPE_INT16 :
(atttype == NC_BYTE) ? DATATYPE_INT8 :
(atttype == NC_BYTE) ? DATATYPE_INT8 :
#if defined (HAVE_NETCDF4)
(atttype == NC_UBYTE) ? DATATYPE_UINT8 :
(atttype == NC_USHORT) ? DATATYPE_UINT16 :
......
......@@ -1966,6 +1966,23 @@ void cdfDefPole(stream_t *streamptr, int gridID)
cdf_enddef(fileID);
}
static
void cdf_def_mapping(stream_t *streamptr, int gridID)
{
int fileID = streamptr->fileID;
static const char varname[] = "dummy";
cdf_redef(fileID);
int ncvarid;
int ncerrcode = nc_def_var(fileID, varname, (nc_type) NC_CHAR, 0, NULL, &ncvarid);
if ( ncerrcode == NC_NOERR )
cdfDefineAttributes(gridID, CDI_GLOBAL, fileID, ncvarid);
cdf_enddef(fileID);
}
static
void cdfDefMapping(stream_t *streamptr, int gridID)
{
......@@ -2061,8 +2078,9 @@ void cdfDefGrid(stream_t *streamptr, int gridID)
if ( CDI_Debug )
Message("gridtype = %d size = %d", gridtype, size);
if ( gridtype == GRID_GAUSSIAN ||
gridtype == GRID_LONLAT ||
if ( gridtype == GRID_GAUSSIAN ||
gridtype == GRID_LONLAT ||
gridtype == GRID_PROJECTION ||
gridtype == GRID_GENERIC )
{
if ( gridtype == GRID_GENERIC )
......@@ -2097,6 +2115,8 @@ void cdfDefGrid(stream_t *streamptr, int gridID)
if ( gridInqXsize(gridID) > 0 ) cdfDefXaxis(streamptr, gridID, ndims);
if ( gridInqYsize(gridID) > 0 ) cdfDefYaxis(streamptr, gridID, ndims);
if ( gridtype == GRID_PROJECTION ) cdf_def_mapping(streamptr, gridID);
}
if ( gridIsRotated(gridID) ) cdfDefPole(streamptr, gridID);
......
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