From cb2f02fa1c51f41ffd91d9411a2c835421a858f1 Mon Sep 17 00:00:00 2001 From: Uwe Schulzweida <uwe.schulzweida@mpimet.mpg.de> Date: Thu, 4 May 2006 09:12:11 +0000 Subject: [PATCH] Version 0.9.7 released --- ChangeLog | 3 +- src/stream_cdf.c | 76 ++++++++++++++++++++++++++++++------------------ src/vlist.c | 53 +++++++++++++++++++++++++++++++-- src/vlist.h | 5 ++++ 4 files changed, 106 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7072f278f..5815d8be3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,11 @@ -2006-05-?? Uwe Schulzweida <schulzweida@dkrz.de> +2006-05-04 Uwe Schulzweida <schulzweida@dkrz.de> * using GRIB library version 0.6.6 * cdfInqContents: check attlen for attname "axis" * cdfInqContents: use coord vars from attr coordinates (bug report: Alberto Maurizi) * gridPrint: print xfirst and xinc if xinc is constant * gridGenYvals: try to calculate non global gaussian latitides + * add global int attr support * add function tableInqParCode * Version 0.9.7 released diff --git a/src/stream_cdf.c b/src/stream_cdf.c index d5df5286b..e837a0319 100644 --- a/src/stream_cdf.c +++ b/src/stream_cdf.c @@ -3012,6 +3012,7 @@ int cdfInqContents(int streamID) size_t attlen; int ilev; char name[256]; + int attint; char attname[256]; const int attstringlen = 1024; char attstring[1024]; char *pname, *plongname, *punits; @@ -3127,37 +3128,43 @@ int cdfInqContents(int streamID) cdf_inq_attname(fileID, NC_GLOBAL, iatt, attname); cdf_inq_atttype(fileID, NC_GLOBAL, attname, &xtype); - if ( xtype != NC_CHAR ) continue; - - if ( strcmp(attname, "history") == 0 ) - { - streams[streamID].historyID = iatt; - } - else if ( strcmp(attname, "institution") == 0 ) - { - cdfGetAttText(fileID, NC_GLOBAL, attname, attstring, attstringlen); - instID = institutInq(0, 0, NULL, attstring); - if ( instID == UNDEFID ) - instID = institutDef(0, 0, NULL, attstring); - } - else if ( strcmp(attname, "source") == 0 ) - { - cdfGetAttText(fileID, NC_GLOBAL, attname, attstring, attstringlen); - modelID = modelInq(-1, 0, attstring); - } - else if ( strcmp(attname, "Conventions") == 0 ) - { - } - else if ( strcmp(attname, "CDI") == 0 ) - { - } - else if ( strcmp(attname, "CDO") == 0 ) + if ( xtype == NC_CHAR ) { + if ( strcmp(attname, "history") == 0 ) + { + streams[streamID].historyID = iatt; + } + else if ( strcmp(attname, "institution") == 0 ) + { + cdfGetAttText(fileID, NC_GLOBAL, attname, attstring, attstringlen); + instID = institutInq(0, 0, NULL, attstring); + if ( instID == UNDEFID ) + instID = institutDef(0, 0, NULL, attstring); + } + else if ( strcmp(attname, "source") == 0 ) + { + cdfGetAttText(fileID, NC_GLOBAL, attname, attstring, attstringlen); + modelID = modelInq(-1, 0, attstring); + } + else if ( strcmp(attname, "Conventions") == 0 ) + { + } + else if ( strcmp(attname, "CDI") == 0 ) + { + } + else if ( strcmp(attname, "CDO") == 0 ) + { + } + else + { + cdfGetAttText(fileID, NC_GLOBAL, attname, attstring, attstringlen); + vlistDefAttribute(vlistID, attname, attstring); + } } - else + else if ( xtype == NC_INT ) { - cdfGetAttText(fileID, NC_GLOBAL, attname, attstring, attstringlen); - vlistDefAttribute(vlistID, attname, attstring); + cdfGetAttInt(fileID, NC_GLOBAL, attname, &attint); + vlistDefIntAttribute(vlistID, attname, attint); } } @@ -4633,6 +4640,7 @@ int cdfInqTimestep(int streamID, int tsID) return ((int) nrecs); } + void cdfEndDef(int streamID) { int varID, ncvarid; @@ -4652,6 +4660,7 @@ void cdfEndDef(int streamID) } } + void cdfDefInstitut(int streamID) { #if defined (HAVE_LIBNETCDF) @@ -4704,6 +4713,7 @@ void cdfDefSource(int streamID) #endif } + void cdfDefGlobalAtts(int streamID) { #if defined (HAVE_LIBNETCDF) @@ -4737,6 +4747,16 @@ void cdfDefGlobalAtts(int streamID) cdfDefSource(streamID); cdfDefInstitut(streamID); + if ( vlistptr->niatts > 0 ) + { + if ( streams[streamID].ncmode == 2 ) cdf_redef(fileID); + for ( iatt = 0; iatt < vlistptr->niatts; iatt++ ) + { + cdf_put_att_int(fileID, NC_GLOBAL, vlistptr->iattnames[iatt], NC_INT, 1L, &vlistptr->iatts[iatt]); + } + if ( streams[streamID].ncmode == 2 ) cdf_enddef(fileID); + } + streams[streamID].globalatts = 1; #endif } diff --git a/src/vlist.c b/src/vlist.c index dc59c9de1..845ee6d4d 100644 --- a/src/vlist.c +++ b/src/vlist.c @@ -153,6 +153,7 @@ static void vlist_init_entry(VLIST *vlistptr) vlistptr->tableID = cdiDefaultTableID; vlistptr->varsAllocated = 0; vlistptr->natts = 0; + vlistptr->niatts = 0; vlistptr->ntsteps = CDI_UNDEFID; } @@ -381,6 +382,12 @@ void vlistCopy(int vlistID2, int vlistID1) vlistptr2->attstrings[attID] = NULL; } + for ( attID = 0; attID < vlistptr1->niatts; attID++ ) + { + vlistptr2->iattnames[attID] = strdupx(vlistptr1->iattnames[attID]); + vlistptr2->iatts[attID] = vlistptr1->iatts[attID]; + } + if ( vlistptr1->vars ) { int nvars = vlistptr1->nvars; @@ -574,6 +581,12 @@ void vlistCopyFlag(int vlistID2, int vlistID1) vlistptr2->attstrings[attID] = NULL; } + for ( attID = 0; attID < vlistptr1->niatts; attID++ ) + { + vlistptr2->iattnames[attID] = strdupx(vlistptr1->iattnames[attID]); + vlistptr2->iatts[attID] = vlistptr1->iatts[attID]; + } + if ( vlistptr1->vars ) { int nvars = vlistptr1->nvars; @@ -1507,7 +1520,7 @@ void vlistDefAttribute(int vlistID, const char *attname, const char *attstring) else { for ( attID = 0; attID < vlistptr->natts; attID++ ) - if ( strcmp(vlistptr->attnames[attID], attname ) == 0 ) + if ( strcmp(vlistptr->attnames[attID], attname) == 0 ) { if ( vlistptr->attstrings[attID] ) free(vlistptr->attstrings[attID]); @@ -1517,7 +1530,7 @@ void vlistDefAttribute(int vlistID, const char *attname, const char *attstring) if ( attID == vlistptr->natts ) { - attID = vlistptr->natts++; + vlistptr->natts++; vlistptr->attnames[attID] = strdupx(attname); } @@ -1527,3 +1540,39 @@ void vlistDefAttribute(int vlistID, const char *attname, const char *attstring) vlistptr->attstrings[attID] = NULL; } } + + +void vlistDefIntAttribute(int vlistID, const char *attname, int attint) +{ + static char func[] = "vlistDefIntAttribute"; + int attID; + VLIST *vlistptr; + + vlistptr = vlist_to_pointer(vlistID); + + vlist_check_ptr(func, vlistptr); + + if ( attname == NULL ) return; + + if ( (vlistptr->niatts + 1) == MAX_ATTRIBUTES ) + { + Warning(func, "vlistID %d, maximum of %d int attributes reached!", + vlistID, MAX_ATTRIBUTES); + } + else + { + for ( attID = 0; attID < vlistptr->niatts; attID++ ) + if ( strcmp(vlistptr->iattnames[attID], attname) == 0 ) + { + break; + } + + if ( attID == vlistptr->niatts ) + { + vlistptr->niatts++; + vlistptr->iattnames[attID] = strdupx(attname); + } + + vlistptr->iatts[attID] = attint; + } +} diff --git a/src/vlist.h b/src/vlist.h index e3646e94c..e6496161e 100644 --- a/src/vlist.h +++ b/src/vlist.h @@ -66,6 +66,9 @@ typedef struct int natts; char *attnames[MAX_ATTRIBUTES]; char *attstrings[MAX_ATTRIBUTES]; + int niatts; + char *iattnames[MAX_ATTRIBUTES]; + int iatts[MAX_ATTRIBUTES]; } VLIST; @@ -85,4 +88,6 @@ void vlistDefVarTime(int vlistID, int varID, int timeID); int vlistInqVarMissvalUsed(int vlistID, int varID); int vlistHasTime(int vlistID); +void vlistDefIntAttribute(int vlistID, const char *attname, int attint); + #endif /* _VLIST_H */ -- GitLab