/* determines new minimum and new maximum * DetMinMax* (* = all cell representation) analyzes * an array of cells and adjust the min and max argument * if necessary. If min and max are not yet set then they * must be MV both. The function * assumes that both min and max are MV if min is MV. */ static void DetMinMaxREAL8( REAL8 *min, /* read-write. adjusted minimum */ REAL8 *max, /* read-write. adjusted maximum */ size_t nrCells,/* number of cells in buf */ const REAL8 *buf) /* cell values to be examined */ { size_t i = 0; if ( IS_MV_REAL8(min)) { while ( IS_MV_REAL8(min) && (i != nrCells)) { ((UINT4 *)min)[0] = ((const UINT4 *)buf)[2*i]; ((UINT4 *)min)[1] = ((const UINT4 *)buf)[(2*i++)+1]; } *max = *min; } while (i != nrCells) { if (! IS_MV_REAL8(buf+i)) { if (buf[i] < *min ) *min = buf[i]; if (buf[i] > *max) *max = buf[i]; } i++; } }
static int SetAndCloseMap( MAP *m, const ATTRIBUTES *a) { double angle; if (! (IS_MV_REAL8(&(a->angle)))) { if (a->angle < 0) angle = -Deg2Rad(-a->angle); else angle = Deg2Rad(a->angle); } if (RuseAs(m, CR_REAL8)) goto error2; if (a->projection != PT_UNDEFINED) MputProjection(m,a->projection); if (! (IS_MV_REAL8(&(a->xUL)))) RputXUL(m, a->xUL); if (! (IS_MV_REAL8(&(a->yUL)))) RputYUL(m, a->yUL); if (! (IS_MV_REAL8(&(a->angle)))) RputAngle(m, angle); if (! (IS_MV_REAL8(&(a->cellSize)))) RputCellSize(m, a->cellSize); if(a->gisFileId != MV_UINT4) MputGisFileId(m,a->gisFileId); if (Merrno) goto error2; return 0; error2: return RetError(1,"Can not write to '%s': %s",MgetFileName(m),MstrError()); }
int is_mv_double(const double *d) { #ifdef HAVE_LIBCSF return IS_MV_REAL8(d); #else const unsigned char u[sizeof(double)] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; /* will choke if sizeof(double) != 8 */ return (memcmp(d, &u, sizeof(double)) == 0); #endif }
static void MergeOptAttr( ATTRIBUTES *a, const ATTRIBUTES *opt) { if (opt->projection != PT_UNDEFINED) a->projection = opt->projection; if (opt->valueScale != VS_UNDEFINED) a->valueScale = opt->valueScale; if (opt->cellRepr != CR_UNDEFINED) a->cellRepr = opt->cellRepr; if (opt->nrRows != MV_UINT4) a->nrRows = opt->nrRows; if (opt->nrCols != MV_UINT4) a->nrCols = opt->nrCols; if (!(IS_MV_REAL8(&(opt->xUL)))) a->xUL = opt->xUL; if (!(IS_MV_REAL8(&(opt->yUL)))) a->yUL = opt->yUL; if (!(IS_MV_REAL8(&(opt->cellSize)))) a->cellSize = opt->cellSize; if (!(IS_MV_REAL8(&(opt->angle)))) a->angle = opt->angle; if (opt->gisFileId != MV_UINT4) a->gisFileId = opt->gisFileId; if (!(IS_MV_REAL8(&(opt->minVal)))) a->minVal = opt->minVal; if (!(IS_MV_REAL8(&(opt->maxVal)))) a->maxVal = opt->maxVal; }
static int PrintOption( const char **names, int nrNames) { ATTRIBUTES *a = (ATTRIBUTES *)ChkMalloc(sizeof(ATTRIBUTES) * nrNames); int *colLen = (int *)ChkMalloc(sizeof(int) * nrNames); int i; if (a == NULL || colLen == NULL) return 1; for(i = 0 ; i < nrNames; i++) { MAP *m= Mopen(names[i],M_READ); if (m == NULL) { Free(a); return RetError(1,"while reading map '%s': %s",names[i],MstrError()); } ReadAttr(a+i,m,TRUE); colLen[i] = MAX(11, strlen(names[i])); Mclose(m); } if (printDataType) { for(i = 0 ; i < nrNames; i++) { int c; switch(a[i].valueScale) { case VS_LDD : c = 'L'; break; case VS_SCALAR : c = 'S'; break; case VS_BOOLEAN : c = 'B'; break; case VS_NOMINAL : c = 'N'; break; case VS_ORDINAL : c = 'O'; break; case VS_DIRECTION : c = 'D'; break; default : c = ' '; break; } printf("%c",c); } return 1; } printf("%s",HEAD); for(i = 0 ; i < nrNames; i++) printf(" %-*s", colLen[i], names[i]); printf("\n"); printf("%s",printLabels[ATTR_nrRows]); for(i = 0 ; i < nrNames; i++) printf(" %-*u", colLen[i], a[i].nrRows); printf("\n"); printf("%s",printLabels[ATTR_nrCols]); for(i = 0 ; i < nrNames; i++) printf(" %-*u", colLen[i], a[i].nrCols); printf("\n"); printf("%s",printLabels[ATTR_cellSize]); for(i = 0 ; i < nrNames; i++) printf(" %-*g", colLen[i], a[i].cellSize); printf("\n"); printf("%s",printLabels[ATTR_valueScale]); for(i = 0 ; i < nrNames; i++) printf(" %-*s", colLen[i], RstrValueScale(a[i].valueScale)); printf("\n"); printf("%s",printLabels[ATTR_cellRepr]); for(i = 0 ; i < nrNames; i++) { const char *cStr; switch(a[i].cellRepr) { case CR_UINT1 : cStr = "small"; break; case CR_INT4 : cStr = "large"; break; case CR_REAL4 : cStr = "single"; break; case CR_REAL8 : cStr = "double"; break; default : cStr = RstrCellRepr(a[i].cellRepr); } printf(" %-*s", colLen[i], cStr); } printf("\n"); printf("%s",printLabels[ATTR_projection]); for(i = 0 ; i < nrNames; i++) printf(" %-*s", colLen[i], a[i].projection ? "yb2t" : "yt2b" ); printf("\n"); printf("%s",printLabels[ATTR_angle]); for(i = 0 ; i < nrNames; i++) printf(" %-*g", colLen[i], a[i].angle); printf("\n"); printf("%s",printLabels[ATTR_xUL]); for(i = 0 ; i < nrNames; i++) printf(" %-*g", colLen[i], a[i].xUL); printf("\n"); printf("%s",printLabels[ATTR_yUL]); for(i = 0 ; i < nrNames; i++) printf(" %-*g", colLen[i], a[i].yUL); printf("\n"); printf("%s",printLabels[ATTR_minVal]); for(i = 0 ; i < nrNames; i++) if (IS_MV_REAL8(&(a[i].minVal))) printf(" %-*s", colLen[i], "mv"); else { if ((a[i].cellRepr) & CSF_FLOAT_MASK) printf(" %-*g", colLen[i], a[i].minVal); else printf(" %-*d", colLen[i], (int)a[i].minVal); } printf("\n"); printf("%s",printLabels[ATTR_maxVal]); for(i = 0 ; i < nrNames; i++) if (IS_MV_REAL8(&(a[i].maxVal))) printf(" %-*s", colLen[i], "mv"); else { if ((a[i].cellRepr) & CSF_FLOAT_MASK) printf(" %-*g", colLen[i], a[i].maxVal); else printf(" %-*d", colLen[i], (int)a[i].maxVal); } printf("\n"); printf("%s",printLabels[ATTR_version]); for(i = 0 ; i < nrNames; i++) printf(" %-*u", colLen[i], a[i].version); printf("\n"); printf("%s",printLabels[ATTR_gisFileId]); for(i = 0 ; i < nrNames; i++) printf(" %-*u", colLen[i], a[i].gisFileId); printf("\n"); printf("%s",printLabels[ATTR_byteOrder]); for(i = 0 ; i < nrNames; i++) printf(" %-*s", colLen[i], a[i].byteOrder == 1 ? "y" : "n"); printf("\n"); printf("%s",printLabels[ATTR_attrTable]); for(i = 0 ; i < nrNames; i++) printf(" %-*s", colLen[i], a[i].attrTable == 0 ? "n" : "y"); printf("\n"); return 0; }