Beispiel #1
0
static CDFstatus ValidateAEDR (struct CDFstruct *CDF, vFILE *fp, OFF_T offset,
                               Int32 num, Int32 maxEntry, Logical zEntry,
                               Logical debug)
{
    struct AEDRstruct64 AEDR;
    size_t nBytes;
    CDFstatus status;

    if (debug)
#if defined(win32) || defined(__MINGW32__)
        printf("  Checking AEDR...@%I64d\n", offset);
#else
        printf("  Checking AEDR...@%lld\n", offset);
#endif
    status = ReadAEDR64 (fp, offset,
                         AEDR_RECORD, &AEDR, NULL,
                         AEDR_NULL);
    if (status != CDF_OK) return status;
    if ((!zEntry && AEDR.RecordType != AgrEDR_) ||
            (zEntry && AEDR.RecordType != AzEDR_))
        return QuitCDF ("CDF(AEDR): record type is invalid ", offset,
                        4, 1, &(AEDR.RecordType), 0, debug);
    if (AEDR.RecordSize < AEDR_BASE_SIZE64)
        return QuitCDF ("CDF(AEDR): record size is invalid ", offset,
                        8, 1, &(AEDR.RecordSize), 0, debug);
    if (AEDR.AEDRnext < 0)
        return QuitCDF ("CDF(AEDR): offset to next AEDR is invalid ", offset,
                        8, 1, &(AEDR.AEDRnext), 0, debug);
    /*  Check for "AEDR.AttrNum != num" is not included as some CDFs fail this
        check. Don't know why.... */
    /*
      if (AEDR.AttrNum < 0 || AEDR.AttrNum > GDR.NumAttr)
        return QuitCDF ("CDF(AEDR): attribute number is invalid ", offset,
                        4, 2, &(AEDR.AttrNum), &(GDR.NumAttr), debug);
    */
    if (!ValidDataType(AEDR.DataType))
        return QuitCDF ("CDF(AEDR): data type is invalid ", offset,
                        4, 1, &(AEDR.DataType), 0, debug);
    if (AEDR.Num < 0 || AEDR.Num > maxEntry)
        return QuitCDF ("CDF(AEDR): entry number is invalid ", offset,
                        4, 2, &(AEDR.Num), &(maxEntry), debug);
    if (AEDR.AEDRnext < 0)
        return QuitCDF ("CDF(AEDR): next AEDR offset is invalid : ", offset,
                        8, 1, &(AEDR.AEDRnext), 0, debug);
    if (AEDR.NumElems < 1 ||
            (STRINGdataType(AEDR.DataType) &&
             AEDR.NumElems > (AEDR.RecordSize - AEDR_VALUE_OFFSET64)))
        return QuitCDF ("CDF(AEDR): number of elements is invalid ", offset,
                        4, 1, &(AEDR.NumElems), 0, debug);
    nBytes = (size_t) (CDFelemSize(AEDR.DataType) * AEDR.NumElems);
    if (nBytes < 1 ||
            nBytes > (AEDR.RecordSize - AEDR_VALUE_OFFSET64))
        return QuitCDF ("CDF(AEDR): entry value size is invalid ", offset,
                        4, 1, &nBytes, 0, debug);
    if (AEDR.RecordSize > (AEDR_MAX_SIZE64 + nBytes))
        return QuitCDF ("CDF(AEDR): record size is invalid ", offset,
                        8, 1, &(AEDR.RecordSize), 0, debug);
    return CDF_OK;
}
Beispiel #2
0
static CDFstatus ValidateVDR (struct CDFstruct *CDF, vFILE *fp, OFF_T offset,
                              Logical zVar, Logical debug)
{
    struct VDRstruct64 VDR;
    void *padValue;
    Int32 nDims, numVars;
    int ix;
    CDFstatus status;
    size_t nBytes;

    if (debug)
#if defined(win32) || defined(__MINGW32__)
        printf("  Checking VDR...@%I64d\n", offset);
#else
        printf("  Checking VDR...@%lld\n", offset);
#endif
    status = ReadVDR64 (CDF, fp, offset, zVar,
                        VDR_RECORD, &VDR, NULL,
                        VDR_NULL);
    if (status != CDF_OK) return status;
    if ((zVar && VDR.RecordType != zVDR_) || (!zVar && VDR.RecordType != rVDR_))
        return QuitCDF ("CDF(VDR): record type is invalid ", offset,
                        4, 1, &(VDR.RecordType), 0, debug);
    if (VDR.RecordSize < (zVar ? zVDR_BASE_SIZE64 : rVDR_BASE_SIZE64))
        return QuitCDF ("CDF(VDR): record size is invalid ", offset,
                        8, 1, &(VDR.RecordSize), 0, debug);
    if (!ValidDataType(VDR.DataType))
        return QuitCDF ("CDF(VDR): data type is invalid ", offset,
                        4, 1, &(VDR.DataType), 0, debug);
    if (VDR.MaxRec < -1)
        return QuitCDF ("CDF(VDR): max record is invalid ", offset,
                        4, 1, &(VDR.MaxRec), 0, debug);
    if (VDR.NumElems < 1 || (!STRINGdataType(VDR.DataType) && VDR.NumElems != 1))
        return QuitCDF ("CDF(VDR): number of elements is invalid ", offset,
                        4, 1, &(VDR.NumElems), 0, debug);
    if (zVar) numVars = CDF->NzVars;
    else numVars = CDF->NrVars;
    if (VDR.Num < 0 || VDR.Num > numVars)
        return QuitCDF ("CDF(VDR): variable number is invalid ", offset,
                        4, 2, &(VDR.Num), &numVars, debug);
    if ((VDR.Num < (numVars-1)) && (VDR.VDRnext < 1))
        return QuitCDF ("CDF(VDR): offset to next VDR is invalid ", offset,
                        8, 1, &(VDR.VDRnext), 0, debug);
    if (VARcompressionBITset(VDR.Flags) && VDR.CPRorSPRoffset <= NO_OFFSET64)
        return QuitCDF ("CDF(VDR): offset to CPRorSPR is invalid ", offset,
                        8, 1, &(VDR.CPRorSPRoffset), 0, debug);
    if (VDR.blockingFactor < 0)
        return QuitCDF ("CDF(VDR): blocking factor is invalid ", offset,
                        4, 1, &(VDR.blockingFactor), 0, debug);
    if (!ValidVarName(VDR.Name))
        return QuitCDF ("CDF(VDR): variable name is invalid ",  offset,
                        0, 1, VDR.Name, 0, debug);
    if (zVar) {
        if (VDR.zNumDims < 0 || VDR.zNumDims > CDF_MAX_DIMS)
            return QuitCDF ("CDF(VDR): number of dimensions is invalid ", offset,
                            4, 1, &(VDR.zNumDims), 0, debug);
        for (ix = 0; ix < (int)VDR.zNumDims; ++ix)
            if (VDR.zDimSizes[ix] < 1)
                return QuitCDF ("CDF(VDR): dimensional size is invalid ", offset,
                                4, 1, &(VDR.zDimSizes[ix]), 0, debug);
    }
    nBytes = (size_t) (CDFelemSize(VDR.DataType)*VDR.NumElems);
    if (nBytes < 1)
        return QuitCDF ("CDF(VDR): pad value size is invalid ", offset,
                        4, 1, &nBytes, 0, debug);
    if (VDR.RecordSize > ((zVar ? zVDR_MAX_SIZE64 : rVDR_MAX_SIZE64) + nBytes))
        return QuitCDF ("CDF(VDR): record size is invalid ", offset,
                        8, 1, &(VDR.RecordSize), 0, debug);
    return CDF_OK;
}
Beispiel #3
0
CDFstatus ValidateVDR (struct CDFstruct *CDF, vFILE *fp, Int32 offset, 
		       Logical zVar, Logical debug)
{
  struct VDRstruct VDR;
  void *padValue;
  Int32 nDims, numVars;
  int ix;
  CDFstatus status;
  size_t nBytes;
  
  if (debug)
    printf("  Checking VDR...@%d\n", (int) offset);
  status = ReadVDR (CDF, fp, offset, zVar, 
                    VDR_RECORD, &VDR, NULL,
                    VDR_NULL);
  if (status != CDF_OK) return status;
  if ((!zVar && VDR.RecordType != rVDR_) || (zVar && VDR.RecordType != zVDR_))
    return QuitCDF ("CDF: record type is invalid ",
                    4, 1, &(VDR.RecordType), 0, debug);
  if (VDR.RecordSize < (zVar ? zVDR_BASE_SIZE : rVDR_BASE_SIZE)) 
    return QuitCDF ("CDF: record size is invalid ",
                    4, 1, &(VDR.RecordSize), 0, debug);
  if (!ValidDataType(VDR.DataType) || InValidDataType(VDR.DataType))
    return QuitCDF ("CDF: data type is invalid ",
                    4, 1, &(VDR.DataType), 0, debug);
  if (VDR.MaxRec < -1) 
    return QuitCDF ("CDF: max record is invalid ",
                    4, 1, &(VDR.MaxRec), 0, debug);
  if (VDR.NumElems < 1 || (!STRINGdataType(VDR.DataType) && VDR.NumElems != 1))
    return QuitCDF ("CDF: number of elements is invalid ",
                    4, 1, &(VDR.NumElems), 0, debug);
  if (zVar) numVars = CDF->NzVars;
  else numVars = CDF->NrVars;
  if (VDR.Num < 0 || VDR.Num > numVars)
    return QuitCDF ("CDF: variable number is invalid ",
                    4, 2, &(VDR.Num), &numVars, debug);
  if ((VDR.Num < (numVars-1)) && VDR.VDRnext < 1) 
    return QuitCDF ("CDF: offset to next VDR is invalid ",
                    4, 1, &(VDR.VDRnext), 0, debug);
  if (VARcompressionBITset(VDR.Flags) && VDR.CPRorSPRoffset <= (int) NO_OFFSET) 
    return QuitCDF ("CDF: offset to CPRorSPR is invalid ",
                    4, 1, &(VDR.CPRorSPRoffset), 0, debug);
  if (VDR.blockingFactor < 0) 
    return QuitCDF ("CDF: blocking factor is invalid ",
                    4, 1, &(VDR.blockingFactor), 0, debug);
  if (!ValidVarName(VDR.Name)) 
    return QuitCDF ("CDF: variable name is invalid ", 
                    0, 1, VDR.Name, 0, debug);
  if (zVar) {
    if (VDR.zNumDims < 0 || VDR.zNumDims > CDF_MAX_DIMS) 
    return QuitCDF ("CDF: number of dimensions is invalid ",
                    4, 1, &(VDR.zNumDims), 0, debug);
    for (ix = 0; ix < (int)VDR.zNumDims; ++ix)
      if (VDR.zDimSizes[ix] < 1) 
    return QuitCDF ("CDF: dimensional size is invalid ",
                    4, 1, &(VDR.zDimSizes[ix]), 0, debug);
  }
  nBytes = (size_t) (CDFelemSize(VDR.DataType)*VDR.NumElems);
  if (nBytes < 1)
    return QuitCDF ("CDF: pad value size is invalid ",
                    4, 1, &nBytes, 0, debug);
  if (VDR.RecordSize > ((zVar ? zVDR_MAX_SIZE : rVDR_MAX_SIZE) + nBytes +
                         (CDF->wastedSpace ? VDR_WASTED_SIZE : 0)))
    return QuitCDF ("CDF: record size is invalid ",
                    4, 1, &(VDR.RecordSize), 0, debug);
  return CDF_OK;
}
Beispiel #4
0
CDFstatus ValidateAEDR (struct CDFstruct *CDF, vFILE *fp, Int32 offset,
                        Int32 num, Int32 maxEntry, Logical zEntry, 
                        Logical debug)
{
  struct AEDRstruct AEDR;
  size_t nBytes;
  CDFstatus status;

  if (debug)
    printf("  Checking AEDR...@%d\n", (int) offset);
  status = ReadAEDR (fp, offset, 
                     AEDR_RECORD, &AEDR, NULL,
                     AEDR_NULL);
  if (status != CDF_OK) return status;
  if ((!zEntry && AEDR.RecordType != AgrEDR_) ||
      (zEntry && AEDR.RecordType != AzEDR_))
    return QuitCDF ("CDF: record type is invalid ",
                    4, 1, &(AEDR.RecordType), 0, debug);
  if (AEDR.RecordSize < AEDR_BASE_SIZE) 
    return QuitCDF ("CDF: record size is invalid ",
                    4, 1, &(AEDR.RecordSize), 0, debug);
  if (AEDR.AEDRnext < 0) 
    return QuitCDF ("CDF: offset to next AEDR is invalid ",
                    4, 1, &(AEDR.AEDRnext), 0, debug);
/*  Check for "AEDR.AttrNum != num" is not included as some CDFs fail this
    check. Don't know why.... */ 
/*  if (AEDR.AttrNum < 0 || AEDR.AttrNum > GDR.NumAttr || AEDR.AttrNum != num)  */
/*
  if (AEDR.AttrNum < 0 || AEDR.AttrNum > GDR.NumAttr) 
    return QuitCDF ("CDF: attribute number is invalid ",
                    4, 2, &(AEDR.AttrNum), &(GDR.NumAttr), debug);
*/
  if (!ValidDataType(AEDR.DataType) || InValidDataType(AEDR.DataType))
    return QuitCDF ("CDF: data type is invalid ",
                    4, 1, &(AEDR.DataType), 0, debug);
  if (AEDR.Num < 0 || AEDR.Num > maxEntry)
    return QuitCDF ("CDF: entry number is invalid ",
                    4, 2, &(AEDR.Num), &maxEntry, debug);
  if (AEDR.AEDRnext < 0)
    return QuitCDF ("CDF: next AEDR offset is invalid : ",
                    4, 1, &(AEDR.AEDRnext), 0, debug);
/*  
  if (zEntry && AEDR.EntryNum > GDR->NzVars)
    return QuitCDF ("CDF: entry number is invalid ",
                    4, 2, &(AEDR.Num), &(GDR->NzVars), debug);
*/
  if (AEDR.NumElems < 1 || 
      (STRINGdataType(AEDR.DataType) && 
       AEDR.NumElems > (AEDR.RecordSize - AEDR_VALUE_OFFSET))) 
    return QuitCDF ("CDF: number of elements is invalid ",
                    4, 1, &(AEDR.NumElems), 0, debug);
  nBytes = (size_t) (CDFelemSize(AEDR.DataType) * AEDR.NumElems);
  if (nBytes < 1 || 
      nBytes > (AEDR.RecordSize - AEDR_VALUE_OFFSET)) 
    return QuitCDF ("CDF: entry value size is invalid ",
                    4, 1, &nBytes, 0, debug);	
  if (AEDR.RecordSize > (AEDR_MAX_SIZE + nBytes))
    return QuitCDF ("CDF: record size is invalid ",
                    4, 1, &(AEDR.RecordSize), 0, debug);
  return CDF_OK;
}