Commit 4370c5a2 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

netCDF: scan uuid of horizontal grid

parent 63593b22
#define DATE_FORMAT "%5.4d-%2.2d-%2.2d" #define DATE_FORMAT "%5.4d-%2.2d-%2.2d"
#define TIME_FORMAT "%2.2d:%2.2d:%2.2d" #define TIME_FORMAT "%2.2d:%2.2d:%2.2d"
void uuid2str(const char *uuid, char *uuidstr);
void date2str(int date, char *datestr, int maxlen) void date2str(int date, char *datestr, int maxlen)
{ {
int year, month, day; int year, month, day;
...@@ -66,6 +68,7 @@ void printFiletype(int streamID, int vlistID) ...@@ -66,6 +68,7 @@ void printFiletype(int streamID, int vlistID)
break; break;
default: default:
printf(" File format: unsupported filetype %d" , filetype); printf(" File format: unsupported filetype %d" , filetype);
break;
} }
if ( filetype == FILETYPE_SRV || filetype == FILETYPE_EXT || filetype == FILETYPE_IEG ) if ( filetype == FILETYPE_SRV || filetype == FILETYPE_EXT || filetype == FILETYPE_IEG )
...@@ -133,6 +136,7 @@ void printGridInfo(int vlistID) ...@@ -133,6 +136,7 @@ void printGridInfo(int vlistID)
int gridID, gridtype, trunc, gridsize, xsize, ysize; int gridID, gridtype, trunc, gridsize, xsize, ysize;
int nbyte0; int nbyte0;
char xname[CDI_MAX_NAME], yname[CDI_MAX_NAME], xunits[CDI_MAX_NAME], yunits[CDI_MAX_NAME]; char xname[CDI_MAX_NAME], yname[CDI_MAX_NAME], xunits[CDI_MAX_NAME], yunits[CDI_MAX_NAME];
char uuidOfHGrid[17];
ngrids = vlistNgrids(vlistID); ngrids = vlistNgrids(vlistID);
for ( index = 0; index < ngrids; index++ ) for ( index = 0; index < ngrids; index++ )
...@@ -356,10 +360,8 @@ void printGridInfo(int vlistID) ...@@ -356,10 +360,8 @@ void printGridInfo(int vlistID)
if ( ysize == 0 ) if ( ysize == 0 )
fprintf(stdout, "size : dim = %d\n", gridsize); fprintf(stdout, "size : dim = %d\n", gridsize);
else else
{
fprintf(stdout, "size : dim = %d nx = %d ny = %d\n", gridsize, xsize, ysize); fprintf(stdout, "size : dim = %d nx = %d ny = %d\n", gridsize, xsize, ysize);
} }
}
if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED || gridtype == GRID_LCC ) if ( gridtype == GRID_CURVILINEAR || gridtype == GRID_UNSTRUCTURED || gridtype == GRID_LCC )
{ {
...@@ -377,6 +379,18 @@ void printGridInfo(int vlistID) ...@@ -377,6 +379,18 @@ void printGridInfo(int vlistID)
fprintf(stdout, "\n"); fprintf(stdout, "\n");
} }
} }
gridInqUUID(gridID, uuidOfHGrid);
if ( uuidOfHGrid[0] != 0 )
{
char uuidOfHGridStr[37];
uuid2str(uuidOfHGrid, uuidOfHGridStr);
if ( uuidOfHGridStr[0] != 0 && strlen(uuidOfHGridStr) == 36 )
{
fprintf(stdout, "%*s", nbyte0, "");
fprintf(stdout, "uuid : %s\n", uuidOfHGridStr);
}
}
} }
} }
/* /*
......
...@@ -1864,6 +1864,7 @@ void cdfDefGdim(stream_t *streamptr, int gridID) ...@@ -1864,6 +1864,7 @@ void cdfDefGdim(stream_t *streamptr, int gridID)
if ( streamptr->ncmode == 2 ) cdf_redef(fileID); if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
//printf("axisname, dimlen %s %d\n", axisname, dimlen);
cdf_def_dim(fileID, axisname, dimlen, &dimID); cdf_def_dim(fileID, axisname, dimlen, &dimID);
cdf_enddef(fileID); cdf_enddef(fileID);
...@@ -2510,6 +2511,23 @@ void cdfDefMapping(stream_t *streamptr, int gridID) ...@@ -2510,6 +2511,23 @@ void cdfDefMapping(stream_t *streamptr, int gridID)
#endif #endif
#if defined (HAVE_LIBNETCDF) #if defined (HAVE_LIBNETCDF)
static
void cdfDefGridUUID(stream_t *streamptr, int gridID)
{
char uuidOfHGrid[17];
gridInqUUID(gridID, uuidOfHGrid);
if ( uuidOfHGrid[0] != 0 )
{
char uuidOfHGridStr[37];
uuid2str(uuidOfHGrid, uuidOfHGridStr);
if ( uuidOfHGridStr[0] != 0 && strlen(uuidOfHGridStr) == 36 )
{
// cdf_put_att_text(fileID, ncvarid, "uuid", 36, uuidOfHGridStr);
}
}
}
static static
void cdfDefGrid(stream_t *streamptr, int gridID) void cdfDefGrid(stream_t *streamptr, int gridID)
{ {
...@@ -2607,6 +2625,8 @@ void cdfDefGrid(stream_t *streamptr, int gridID) ...@@ -2607,6 +2625,8 @@ void cdfDefGrid(stream_t *streamptr, int gridID)
{ {
Error("Unsupported grid type: %s", gridNamePtr(gridtype)); Error("Unsupported grid type: %s", gridNamePtr(gridtype));
} }
cdfDefGridUUID(streamptr, gridID);
} }
#endif #endif
...@@ -5157,7 +5177,7 @@ void copy_numeric_projatts(int gridID, int ncvarID, int ncfileID) ...@@ -5157,7 +5177,7 @@ void copy_numeric_projatts(int gridID, int ncvarID, int ncfileID)
/* define all input grids */ /* define all input grids */
static static
void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nvars, ncvar_t *ncvars, int timedimid) void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nvars, ncvar_t *ncvars, int timedimid, char *uuidOfHGrid)
{ {
int ncvarid, ncvarid2; int ncvarid, ncvarid2;
int ndims; int ndims;
...@@ -5704,6 +5724,9 @@ void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva ...@@ -5704,6 +5724,9 @@ void define_all_grids(stream_t *streamptr, int vlistID, ncdim_t *ncdims, int nva
#endif #endif
ncvars[ncvarid].gridID = varDefGrid(vlistID, grid, 1); ncvars[ncvarid].gridID = varDefGrid(vlistID, grid, 1);
if ( uuidOfHGrid[0] != 0 && grid.type == GRID_UNSTRUCTURED )
gridDefUUID(ncvars[ncvarid].gridID, uuidOfHGrid);
if ( ncvars[ncvarid].chunked ) if ( ncvars[ncvarid].chunked )
{ {
ndims = ncvars[ncvarid].ndims; ndims = ncvars[ncvarid].ndims;
...@@ -6218,8 +6241,8 @@ void define_all_vars(stream_t *streamptr, int vlistID, int instID, int modelID, ...@@ -6218,8 +6241,8 @@ void define_all_vars(stream_t *streamptr, int vlistID, int instID, int modelID,
} }
static static
void read_global_attributtes(int fileID, int vlistID, stream_t *streamptr, int ngatts, void scan_global_attributtes(int fileID, int vlistID, stream_t *streamptr, int ngatts,
int *instID, int *modelID, int *ucla_les) int *instID, int *modelID, int *ucla_les, char *uuidOfHGrid)
{ {
nc_type xtype; nc_type xtype;
size_t attlen; size_t attlen;
...@@ -6271,6 +6294,12 @@ void read_global_attributtes(int fileID, int vlistID, stream_t *streamptr, int n ...@@ -6271,6 +6294,12 @@ void read_global_attributtes(int fileID, int vlistID, stream_t *streamptr, int n
else if ( strcmp(attname, "CDO") == 0 ) else if ( strcmp(attname, "CDO") == 0 )
{ {
} }
else if ( strcmp(attname, "uuid") == 0 && attlen == 36 )
{
attstring[36] = 0;
str2uuid(attstring, uuidOfHGrid);
// printf("uuid: %d %s\n", attlen, attstring);
}
else else
{ {
vlistDefAttTxt(vlistID, CDI_GLOBAL, attname, (int)attlen, attstring); vlistDefAttTxt(vlistID, CDI_GLOBAL, attname, (int)attlen, attstring);
...@@ -6333,6 +6362,9 @@ int cdfInqContents(stream_t *streamptr) ...@@ -6333,6 +6362,9 @@ int cdfInqContents(stream_t *streamptr)
int vlistID; int vlistID;
int format = 0; int format = 0;
int ucla_les = FALSE; int ucla_les = FALSE;
char uuidOfHGrid[17];
uuidOfHGrid[0] = 0;
vlistID = streamptr->vlistID; vlistID = streamptr->vlistID;
fileID = streamptr->fileID; fileID = streamptr->fileID;
...@@ -6401,8 +6433,8 @@ int cdfInqContents(stream_t *streamptr) ...@@ -6401,8 +6433,8 @@ int cdfInqContents(stream_t *streamptr)
return (CDI_EUFSTRUCT); return (CDI_EUFSTRUCT);
} }
/* read global attributtes */ /* scan global attributtes */
read_global_attributtes(fileID, vlistID, streamptr, ngatts, &instID, &modelID, &ucla_les); scan_global_attributtes(fileID, vlistID, streamptr, ngatts, &instID, &modelID, &ucla_les, uuidOfHGrid);
/* find time dim */ /* find time dim */
if ( unlimdimid >= 0 ) if ( unlimdimid >= 0 )
...@@ -6695,7 +6727,7 @@ int cdfInqContents(stream_t *streamptr) ...@@ -6695,7 +6727,7 @@ int cdfInqContents(stream_t *streamptr)
/* define all grids */ /* define all grids */
define_all_grids(streamptr, vlistID, ncdims, nvars, ncvars, timedimid); define_all_grids(streamptr, vlistID, ncdims, nvars, ncvars, timedimid, uuidOfHGrid);
/* read VCT */ /* read VCT */
......
...@@ -93,6 +93,8 @@ void str2uuid(const char *uuidstr, char *uuid) ...@@ -93,6 +93,8 @@ void str2uuid(const char *uuidstr, char *uuid)
if ( iret != 16 ) return; if ( iret != 16 ) return;
for ( int i = 0; i < 16; ++i ) uuid[i] = ui[i]; for ( int i = 0; i < 16; ++i ) uuid[i] = ui[i];
uuid[16] = 0;
} }
/* /*
......
Supports Markdown
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