From cc9a2335e668b9cf229e906bbcb32dd9f3915701 Mon Sep 17 00:00:00 2001 From: Uwe Schulzweida <uwe.schulzweida@mpimet.mpg.de> Date: Tue, 10 Jan 2017 11:11:16 +0100 Subject: [PATCH] gridPrintKernel: changed 1st parameter from gridptr to gridID. --- src/cdi_int.h | 1 - src/grid.c | 136 +++++++++++++++++++++++++++++--------------------- 2 files changed, 78 insertions(+), 59 deletions(-) diff --git a/src/cdi_int.h b/src/cdi_int.h index d2f9c3625..8e02463b3 100644 --- a/src/cdi_int.h +++ b/src/cdi_int.h @@ -351,7 +351,6 @@ int streamInqFileID(int streamID); void gridDefHasDims(int gridID, int hasdims); int gridInqHasDims(int gridID); -const char *gridNamePtr(int gridtype); const char *zaxisNamePtr(int leveltype); int zaxisInqLevelID(int zaxisID, double level); diff --git a/src/grid.c b/src/grid.c index ed560acc5..70f7fdfef 100644 --- a/src/grid.c +++ b/src/grid.c @@ -3150,7 +3150,7 @@ printBounds(FILE *fp, int dig, const char prefix[], size_t nbyte0, static void printMask(FILE *fp, const char prefix[], size_t nbyte0, - size_t n, const mask_t mask[]) + size_t n, const int mask[]) { fputs(prefix, fp); size_t nbyte = nbyte0; @@ -3161,7 +3161,7 @@ printMask(FILE *fp, const char prefix[], size_t nbyte0, fprintf(fp, "\n%*s", (int)nbyte0, ""); nbyte = nbyte0; } - nbyte += (size_t)fprintf(fp, "%d ", (int)mask[i]); + nbyte += (size_t)fprintf(fp, "%d ", mask[i]); } fputs("\n", fp); } @@ -3237,19 +3237,18 @@ void gridPrintAttributes(FILE *fp, int gridID) } static -void gridPrintKernel(grid_t *gridptr, int opt, FILE *fp) +void gridPrintKernel(int gridID, int opt, FILE *fp) { int xdim, ydim; + char attstr[CDI_MAX_NAME]; + char attstr2[CDI_MAX_NAME]; unsigned char uuidOfHGrid[CDI_UUID_SIZE]; - int gridID = gridptr->self; - const double *area = gridInqAreaPtr(gridID); - const double *xvals = gridInqXvalsPtr(gridID); - const double *yvals = gridInqYvalsPtr(gridID); - const double *xbounds = gridInqXboundsPtr(gridID); - const double *ybounds = gridInqYboundsPtr(gridID); + size_t nxvals = (size_t) gridInqXvals(gridID, NULL); + size_t nyvals = (size_t) gridInqYvals(gridID, NULL); + size_t nxbounds = (size_t) gridInqXbounds(gridID, NULL); + size_t nybounds = (size_t) gridInqYbounds(gridID, NULL); int type = gridInqType(gridID); - int trunc = gridInqTrunc(gridID); int gridsize = gridInqSize(gridID); int xsize = gridInqXsize(gridID); int ysize = gridInqYsize(gridID); @@ -3258,9 +3257,6 @@ void gridPrintKernel(grid_t *gridptr, int opt, FILE *fp) int dig = (prec == CDI_DATATYPE_FLT64) ? 15 : 7; - struct gridaxis_t *xaxis = &gridptr->x; - struct gridaxis_t *yaxis = &gridptr->y; - fprintf(fp, "gridtype = %s\n" "gridsize = %d\n", gridNamePtr(type), gridsize); if ( type != GRID_GME ) @@ -3271,25 +3267,35 @@ void gridPrintKernel(grid_t *gridptr, int opt, FILE *fp) if ( ysize > 0 ) fprintf(fp, "ysize = %d\n", ysize); } - if ( xvals ) + if ( nxvals > 0 ) { - if ( xaxis->name[0] ) fprintf(fp, "xname = %s\n", xaxis->name); - if ( xaxis->longname[0] ) fprintf(fp, "xlongname = %s\n", xaxis->longname); - if ( xaxis->units[0] ) fprintf(fp, "xunits = %s\n", xaxis->units); - if ( xaxis->dimname[0] && strcmp(xaxis->name, xaxis->dimname) ) - fprintf(fp, "xdimname = %s\n", xaxis->dimname); + attstr[0] = 0; cdiGridInqKeyStr(gridID, CDI_KEY_XNAME, CDI_MAX_NAME, attstr); + if ( attstr[0] ) fprintf(fp, "xname = %s\n", attstr); + attstr2[0] = 0; cdiGridInqKeyStr(gridID, CDI_KEY_XDIMNAME, CDI_MAX_NAME, attstr2); + if ( attstr2[0] && strcmp(attstr, attstr2) ) fprintf(fp, "xdimname = %s\n", attstr2); + attstr[0] = 0; cdiGridInqKeyStr(gridID, CDI_KEY_XLONGNAME, CDI_MAX_NAME, attstr); + if ( attstr[0] ) fprintf(fp, "xlongname = %s\n", attstr); + attstr[0] = 0; cdiGridInqKeyStr(gridID, CDI_KEY_XUNITS, CDI_MAX_NAME, attstr); + if ( attstr[0] ) fprintf(fp, "xunits = %s\n", attstr); } - if ( yvals ) + + if ( nyvals > 0 ) { - if ( yaxis->name[0] ) fprintf(fp, "yname = %s\n", yaxis->name); - if ( yaxis->longname[0] ) fprintf(fp, "ylongname = %s\n", yaxis->longname); - if ( yaxis->units[0] ) fprintf(fp, "yunits = %s\n", yaxis->units); - if ( yaxis->dimname[0] && strcmp(yaxis->name, yaxis->dimname) ) - fprintf(fp, "ydimname = %s\n", yaxis->dimname); + attstr[0] = 0; cdiGridInqKeyStr(gridID, CDI_KEY_YNAME, CDI_MAX_NAME, attstr); + if ( attstr[0] ) fprintf(fp, "yname = %s\n", attstr); + attstr2[0] = 0; cdiGridInqKeyStr(gridID, CDI_KEY_YDIMNAME, CDI_MAX_NAME, attstr2); + if ( attstr2[0] && strcmp(attstr, attstr2) ) fprintf(fp, "ydimname = %s\n", attstr2); + attstr[0] = 0; cdiGridInqKeyStr(gridID, CDI_KEY_YLONGNAME, CDI_MAX_NAME, attstr); + if ( attstr[0] ) fprintf(fp, "ylongname = %s\n", attstr); + attstr[0] = 0; cdiGridInqKeyStr(gridID, CDI_KEY_YUNITS, CDI_MAX_NAME, attstr); + if ( attstr[0] ) fprintf(fp, "yunits = %s\n", attstr); } if ( type == GRID_UNSTRUCTURED || type == GRID_CURVILINEAR ) - if ( gridptr->vdimname[0] ) fprintf(fp, "vdimname = %s\n", gridptr->vdimname); + { + attstr[0] = 0; cdiGridInqKeyStr(gridID, CDI_KEY_VDIMNAME, CDI_MAX_NAME, attstr); + if ( attstr[0] ) fprintf(fp, "vdimname = %s\n", attstr); + } if ( type == GRID_UNSTRUCTURED && nvertex > 0 ) fprintf(fp, "nvertex = %d\n", nvertex); } @@ -3303,7 +3309,7 @@ void gridPrintKernel(grid_t *gridptr, int opt, FILE *fp) case GRID_CURVILINEAR: case GRID_UNSTRUCTURED: { - if ( type == GRID_GAUSSIAN || type == GRID_GAUSSIAN_REDUCED ) fprintf(fp, "np = %d\n", gridptr->np); + if ( type == GRID_GAUSSIAN || type == GRID_GAUSSIAN_REDUCED ) fprintf(fp, "np = %d\n", gridInqNP(gridID)); if ( type == GRID_CURVILINEAR || type == GRID_UNSTRUCTURED ) { @@ -3346,7 +3352,7 @@ void gridPrintKernel(grid_t *gridptr, int opt, FILE *fp) } } - if ( xvals ) + if ( nxvals > 0 ) { double xfirst = 0.0, xinc = 0.0; @@ -3364,21 +3370,24 @@ void gridPrintKernel(grid_t *gridptr, int opt, FILE *fp) } else { + double *xvals = (double*) Malloc(nyvals*sizeof(double)); + gridInqXvals(gridID, xvals); static const char prefix[] = "xvals = "; - printDblsPrefixAutoBrk(fp, dig, prefix, sizeof(prefix)-1, - (size_t)(xdim > 0 ? xdim : 0), xvals); + printDblsPrefixAutoBrk(fp, dig, prefix, sizeof(prefix)-1, nxvals, xvals); + Free(xvals); } } - if ( xbounds ) + if ( nxbounds ) { + double *xbounds = (double*) Malloc(nxbounds*sizeof(double)); + gridInqXbounds(gridID, xbounds); static const char prefix[] = "xbounds = "; - printBounds(fp, dig, prefix, sizeof(prefix)-1, - (size_t)(xdim > 0 ? xdim : 0), - (size_t)(nvertex > 0 ? nvertex : 0), xbounds); + printBounds(fp, dig, prefix, sizeof(prefix)-1, xdim, nvertex, xbounds); + Free(xbounds); } - if ( yvals ) + if ( nyvals > 0 ) { double yfirst = 0.0, yinc = 0.0; @@ -3396,25 +3405,30 @@ void gridPrintKernel(grid_t *gridptr, int opt, FILE *fp) } else { + double *yvals = (double*) Malloc(nyvals*sizeof(double)); + gridInqYvals(gridID, yvals); static const char prefix[] = "yvals = "; - printDblsPrefixAutoBrk(fp, dig, prefix, sizeof(prefix)-1, - (size_t)(ydim > 0 ? ydim : 0), yvals); + printDblsPrefixAutoBrk(fp, dig, prefix, sizeof(prefix)-1, nyvals, yvals); + Free(yvals); } } - if ( ybounds ) + if ( nybounds ) { + double *ybounds = (double*) Malloc(nybounds*sizeof(double)); + gridInqYbounds(gridID, ybounds); static const char prefix[] = "ybounds = "; - printBounds(fp, dig, prefix, sizeof(prefix)-1, - (size_t)(ydim > 0 ? ydim : 0), - (size_t)(nvertex > 0 ? nvertex : 0), ybounds); + printBounds(fp, dig, prefix, sizeof(prefix)-1, ydim, nvertex, ybounds); + Free(ybounds); } - if ( area ) + if ( gridHasArea(gridID) ) { + double *area = (double*) Malloc(gridsize*sizeof(double)); + gridInqArea(gridID, area); static const char prefix[] = "area = "; - printDblsPrefixAutoBrk(fp, dig, prefix, sizeof(prefix)-1, - (size_t)(gridsize > 0 ? gridsize : 0), area); + printDblsPrefixAutoBrk(fp, dig, prefix, sizeof(prefix)-1, gridsize, area); + Free(area); } if ( type == GRID_GAUSSIAN_REDUCED ) @@ -3436,7 +3450,7 @@ void gridPrintKernel(grid_t *gridptr, int opt, FILE *fp) double originLon = 0, originLat = 0, lonParY = 0, lat1 = 0, lat2 = 0, xincm = 0, yincm = 0; int projflag = 0, scanflag = 0; gridInqParamLCC(gridID, &originLon, &originLat, &lonParY, &lat1, &lat2, &xincm, &yincm, - &projflag, &scanflag); + &projflag, &scanflag); fprintf(fp, "originLon = %.*g\n" @@ -3455,17 +3469,19 @@ void gridPrintKernel(grid_t *gridptr, int opt, FILE *fp) case GRID_SPECTRAL: { fprintf(fp, "truncation = %d\n" - "complexpacking = %d\n", trunc, gridptr->lcomplex ); + "complexpacking = %d\n", gridInqTrunc(gridID), gridInqComplexPacking(gridID) ); break; } case GRID_FOURIER: { - fprintf(fp, "truncation = %d\n", trunc); + fprintf(fp, "truncation = %d\n", gridInqTrunc(gridID)); break; } case GRID_GME: { - fprintf(fp, "ni = %d\n", gridptr->gme.ni ); + int nd, ni, ni2, ni3; + gridInqParamGME(gridID, &nd, &ni, &ni2, &ni3); + fprintf(fp, "ni = %d\n", ni ); break; } default: @@ -3484,31 +3500,32 @@ void gridPrintKernel(grid_t *gridptr, int opt, FILE *fp) fprintf(fp, "uuid = %s\n", uuidOfHGridStr); } - if ( gridptr->mask ) + if ( gridInqMask(gridID, NULL) ) { + int *mask = (gridsize>0) ? (int*) Malloc((size_t)gridsize*sizeof(int)) : NULL; + gridInqMask(gridID, mask); static const char prefix[] = "mask = "; printMask(fp, prefix, sizeof(prefix)-1, - (size_t)(gridsize > 0 ? gridsize : 0), gridptr->mask); + (size_t)(gridsize > 0 ? gridsize : 0), mask); + if ( mask ) Free(mask); } } void gridPrint(int gridID, int opt) { - grid_t *gridptr = grid_to_pointer(gridID); - - gridPrintKernel(gridptr, opt, stdout); + gridPrintKernel(gridID, opt, stdout); } - void gridPrintP(void *voidptr, FILE *fp) { grid_t *gridptr = (grid_t *) voidptr; + int gridID = gridptr->self; xassert( gridptr ); - gridPrintKernel(gridptr, 0, fp); + gridPrintKernel(gridID, 0, fp); fprintf(fp, "precision = %d\n" @@ -3533,12 +3550,15 @@ void gridPrintP(void *voidptr, FILE *fp) ? gridptr->nrowlon : 0), gridptr->rowlon); } - if ( gridptr->mask_gme ) + if ( gridInqMaskGME(gridID, NULL) ) { + int gridsize = gridptr->size; + int *mask = (gridsize>0) ? (int*) Malloc((size_t)gridsize*sizeof(int)) : NULL; + gridInqMaskGME(gridID, mask); static const char prefix[] = "mask_gme = "; printMask(fp, prefix, sizeof(prefix)-1, - (size_t)(gridptr->size > 0 ? gridptr->size : 0), - gridptr->mask_gme); + (size_t)(gridptr->size > 0 ? gridptr->size : 0), mask); + if ( mask ) Free(mask); } } -- GitLab