diff --git a/cdf36_3-dist/Note.linux b/cdf36_3-dist/Note.linux deleted file mode 100644 index 79b796d..0000000 --- a/cdf36_3-dist/Note.linux +++ /dev/null @@ -1,6 +0,0 @@ -Recommended/tested gcc: - Version 4.4.2 or later - -Recommended/tested gfortran: - Version 4.4.2 or later - diff --git a/cdf36_3-dist/Note.macosx b/cdf36_3-dist/Note.macosx deleted file mode 100644 index e5a0ab2..0000000 --- a/cdf36_3-dist/Note.macosx +++ /dev/null @@ -1,4 +0,0 @@ -# To compile and link on Mac OS X 10.6, make the following changes to Makefile: -# 1) Replace MacOSX10.5.sdk with MacOSX10.6.sdk -# 2) Replace /usr/lib/gcc/powerpc-apple-darwin9 with -# /usr/lib/gcc/powerpc-apple-darwin10 diff --git a/cdf36_3-dist/cdfjava/cdfml/cdfml.jar b/cdf36_3-dist/cdfjava/cdfml/cdfml.jar deleted file mode 100644 index 38906de..0000000 Binary files a/cdf36_3-dist/cdfjava/cdfml/cdfml.jar and /dev/null differ diff --git a/cdf36_3-dist/cdfjava/cdftools/CDFToolsDriver.jar b/cdf36_3-dist/cdfjava/cdftools/CDFToolsDriver.jar deleted file mode 100644 index 1de4571..0000000 Binary files a/cdf36_3-dist/cdfjava/cdftools/CDFToolsDriver.jar and /dev/null differ diff --git a/cdf36_3-dist/cdfjava/classes/cdfjava.jar b/cdf36_3-dist/cdfjava/classes/cdfjava.jar deleted file mode 100644 index 0eb26c5..0000000 Binary files a/cdf36_3-dist/cdfjava/classes/cdfjava.jar and /dev/null differ diff --git a/cdf36_3-dist/cdfjava/examples/CreateCDF.class b/cdf36_3-dist/cdfjava/examples/CreateCDF.class deleted file mode 100644 index 8285da0..0000000 Binary files a/cdf36_3-dist/cdfjava/examples/CreateCDF.class and /dev/null differ diff --git a/cdf36_3-dist/cdfjava/examples/ReadCDF.class b/cdf36_3-dist/cdfjava/examples/ReadCDF.class deleted file mode 100644 index 94bac85..0000000 Binary files a/cdf36_3-dist/cdfjava/examples/ReadCDF.class and /dev/null differ diff --git a/cdf36_3-dist/cdfjava/examples/test1.cdf b/cdf36_3-dist/cdfjava/examples/test1.cdf deleted file mode 100644 index 494b538..0000000 Binary files a/cdf36_3-dist/cdfjava/examples/test1.cdf and /dev/null differ diff --git a/cdf36_3-dist/cdfjava/lib/.empty b/cdf36_3-dist/cdfjava/lib/.empty deleted file mode 100644 index e69de29..0000000 diff --git a/cdf36_3-dist/modify_definition_files.sh b/cdf36_3-dist/modify_definition_files.sh deleted file mode 100755 index 9009f38..0000000 --- a/cdf36_3-dist/modify_definition_files.sh +++ /dev/null @@ -1,51 +0,0 @@ -#! /bin/bash -search="" -replace=$1 # Current working directory -whichos=`uname` -case "$whichos" in - CYGWIN*) topath=1;; - MINGW*) topath=1;; - Darwin*) topath=2;; - * ) topath=0;; -esac -for file in `ls $replace/bin/definitions.*` -do -# extension=`echo $file | cut -f2 -d"."` - extension="${file:${#file}-1}" - if [ $topath -eq 1 ]; then - if [ $extension == "B" ] || [ $extension == "K" ]; then - echo "export PATH=\"$search/lib:$PATH\"" >> $file - else - echo "setenv PATH \"$search/lib:$PATH\"" >> $file - fi - elif [ $topath -eq 2 ]; then - if [ $extension == "B" ] || [ $extension == "K" ]; then - echo "export DYLD_LIBRARY_PATH=$search/lib" >> $file - else - echo "setenv DYLD_LIBRARY_PATH $search/lib" >> $file - fi - else - if [ $extension == "B" ] || [ $extension == "K" ]; then - echo "export LD_LIBRARY_PATH=$search/lib" >> $file - else - echo "setenv LD_LIBRARY_PATH $search/lib" >> $file - fi - fi - echo "Modifying the definition file $file .." - if `type ed > /dev/null 2>&1` - then - ed - $file << editend - 1,\$s:$search:$replace:g - w - q -editend - elif `type sed > /dev/null 2>&1` - then - sed -e "s,$search,$replace,g" < $file > $file.new - mv $file.new $file - else - echo Not modified... as both "ed" and "sed" line editor not installed. - echo Use any available text editor to manually modify "$search" to "$replace". - fi -done - diff --git a/cdf36_3-dist/samples/example1.cdf b/cdf36_3-dist/samples/example1.cdf deleted file mode 100644 index b1c4c52..0000000 Binary files a/cdf36_3-dist/samples/example1.cdf and /dev/null differ diff --git a/cdf36_3-dist/src/lib/Makefile b/cdf36_3-dist/src/lib/Makefile deleted file mode 100644 index cd05ab0..0000000 --- a/cdf36_3-dist/src/lib/Makefile +++ /dev/null @@ -1,231 +0,0 @@ -#------------------------------------------------------------------------------ -# Copyright 1996-2016 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# All Rights Reserved. -#------------------------------------------------------------------------------ -# -# NSSDC/CDF CDF library makefile. -# -# Version 1.5b, 3-Apr-97, Hughes STX. -# -# Modification history: -# -# V1.0 15-Dec-93, J Love Original version. -# V1.0a 23-Feb-94, J Love Added `CC='. -# V1.0b 6-Apr-94, J Love Finished `CC='. -# V1.1 14-Nov-94, J Love CDF V2.5. -# V1.2 30-Dec-94, J Love Corrected dependencies. -# V1.2a 19-Jan-95, J Love IRIX 6.x. -# V1.3 16-Mar-95, J Love Multi-compiler support, etc. -# V1.4 3-Apr-95, J Love POSIX. -# V1.4a 4-May-95, J Love Added `cdfmem.c'. -# V1.5 13-Jun-96, J Love CDF V2.6. -# V1.5a 21-Feb-97, J Love Removed RICE. -# V1.5b 3-Apr-97, J Love Removed mysterious `-M' option. -# V2.0 20-Feb-16, M Liu Mac OS to build both 32 and 64-bit boundle and -# copy libraries into $HOME/lib for Mac. -# -#------------------------------------------------------------------------------ -# -# Notes: -# -# `make' on DECstations complains (prints an error message) if an if-then-else -# construct evaluates to FALSE but there is no `false' part. To prevent this, -# the `NULL' command is executed as the `false' part. -# -#------------------------------------------------------------------------------ - -.SILENT: - -SHELL=/bin/sh -NULL=true - -SHARED= -PIC= -CCx= -LDx= -COPTIONS= -SYSLIBS= -SHAREDEXT= -LDOPTIONS= -AROPTIONS= -RANLIB= -VERSION= -MAKE=make - -INCLUDEcdf=../include -ZlibDIR=. - -CC=$(CCx) -LD=$(LDx) -AR=ar -RANLIBcmd=ranlib -MACos=Darwin - -CFLAGS=$(COPTIONS) $(PIC) -I$(INCLUDEcdf) -I$(ZlibDIR) -CFLAGS2=-DZ_PREFIX -LDFLAGS=$(LDOPTIONS) -ARFLAGS=$(AROPTIONS) -ZLIB=zlib - -OBJs= \ -cdflib.o cdfcre.o cdfope.o cdfclo.o cdfdel.o cdfsel.o cdfcon.o \ -cdfget.o cdfmisc2.o cdfread.o cdfwrite.o cdfhyper.o epochuf.o dirutils.o \ -cdfput1.o cdfput2.o cdfcsi.o cdffsi.o cdffii.o cdftext.o cdfed.o \ -cdfstr.o cdfvalid.o cdfmem.o vstream.o epochu.o cdfmisc3.o cdfhuff.o \ -cdfrle.o cdfmisc1.o cdfalloc.o cdfgzip.o cdfalloc64.o cdfdel64.o cdfmisc2_64.o \ -cdfread64.o cdfclo64.o cdfget64.o cdfmisc3_64.o cdfsel64.o cdfcon64.o \ -cdfput1_64.o cdfwrite64.o cdfcre64.o cdfmisc1_64.o cdfput2_64.o vstream64.o \ -cdfhyper64.o cdfrle64.o cdfhuff64.o cdfgzip64.o cdffsi2.o cdffsi3.o cdfcks.o \ -cdfmd5.o cdfsav.o cdfvalidator.o cdfvalidator64.o cdftt2000.o cdftt2000f.o \ -$(ZLIB)/adler32.o $(ZLIB)/crc32.o $(ZLIB)/deflate.o $(ZLIB)/inffast.o \ -$(ZLIB)/inflate.o $(ZLIB)/infback.o $(ZLIB)/inftrees.o $(ZLIB)/trees.o \ -$(ZLIB)/zutil.o - -CDFh= $(INCLUDEcdf)/cdf.h -CDFREVh= $(INCLUDEcdf)/cdfrev.h -CONFIGh= $(INCLUDEcdf)/cdfconfig.h -CDFDISTh= $(INCLUDEcdf)/cdfdist.h $(CDFh) $(CONFIGh) -CDFLIBh= $(INCLUDEcdf)/cdflib.h $(INCLUDEcdf)/cdflib64.h $(CDFDISTh) -CDFGZIPh=$(ZLIB)/zconf.h $(ZLIB)/zlib.h -CDFMD5h= $(CDFLIBh) $(INCLUDEcdf)/cdfmd5.h - -WHICHOS=$(shell uname) -MACVERSION=0 -MACLIB= -ifeq ("$(WHICHOS)","Darwin") - MACVERSION=$(shell uname -r | cut -f1 -d.) - MACLIB=$(shell echo $$HOME)/lib -endif - -#------------------------------------------------------------------------------ -# Compile/link. -#------------------------------------------------------------------------------ - -all: libcdf.a shared.$(SHARED) - -libcdf.a: $(OBJs) - @if [ -f $@ ] ; then rm $@ ; else $(NULL) ; fi - @echo $(AR) $(ARFLAGS) $@ $(OBJs) - $(AR) $(ARFLAGS) $@ $(OBJs) - @$(MAKE) MAKE=$(MAKE) ranlib.$(RANLIB) - @if [ $(MACVERSION) -gt 0 ]; then \ - cp -f $@ $(MACLIB); \ - fi - -ranlib.yes: - @echo $(RANLIBcmd) libcdf.a - $(RANLIBcmd) libcdf.a -# @cp .ranlib .ranlib.yes - -shared.yes: libcdf.$(SHAREDEXT) - -libcdf.so \ -libcdf.dylib \ -libcdf.dll \ -libcdf.sl: $(OBJs) - @if [ -f $@ ] ; then rm $@ ; else $(NULL) ; fi - @echo $(LD) $(LDFLAGS) -o $@ $(OBJs) $(SYSLIBS) - $(LD) $(LDFLAGS) -o $@ $(OBJs) $(SYSLIBS) - @if [ $(MACVERSION) -gt 0 ]; then \ - rm -f $(MACLIB)/$@; \ - cp $@ $(MACLIB)/libcdf.$(VERSION).dylib; \ - cd $(MACLIB) && ln -s libcdf.$(VERSION).dylib $@; \ - fi - - -libcdf.o: $(OBJs) - @echo $(CC) $(LDFLAGS) -o $@ $(OBJs) $(SYSLIBS) - $(CC) $(LDFLAGS) -o $@ $(OBJs) $(SYSLIBS) - -.c.o: - @if [ "$<" = "cdfgzip.c" ] || [ "$<" = "cdfgzip64.c" ] ; then \ - echo $(CC) $(CFLAGS) $(CFLAGS2) -c $< ; \ - $(CC) $(CFLAGS) $(CFLAGS2) -c $< ; \ - else \ - echo $(CC) $(CFLAGS) -c $< ; \ - $(CC) $(CFLAGS) -c $< ; \ - fi - -cdflib.o: cdflib.c $(CDFLIBh) -cdfcre.o: cdfcre.c $(CDFLIBh) $(CDFREVh) -cdfope.o: cdfope.c $(CDFLIBh) $(CDFREVh) -cdfdel.o: cdfdel.c $(CDFLIBh) -cdfclo.o: cdfclo.c $(CDFLIBh) -cdfget.o: cdfget.c $(CDFLIBh) $(CDFREVh) -cdfput1.o: cdfput1.c $(CDFLIBh) -cdfput2.o: cdfput2.c $(CDFLIBh) -cdfsel.o: cdfsel.c $(CDFLIBh) -cdfcon.o: cdfcon.c $(CDFLIBh) -cdfwrite.o: cdfwrite.c $(CDFLIBh) -cdfread.o: cdfread.c $(CDFLIBh) -cdfmisc1.o: cdfmisc1.c $(CDFLIBh) $(CDFREVh) -cdfmisc2.o: cdfmisc2.c $(CDFLIBh) -cdfmisc3.o: cdfmisc3.c $(CDFLIBh) -cdfalloc.o: cdfalloc.c $(CDFLIBh) $(CDFREVh) -cdftext.o: cdftext.c $(CDFLIBh) -cdfcsi.o: cdfcsi.c $(CDFLIBh) -cdffsi.o: cdffsi.c $(CDFLIBh) -cdffsi2.o: cdffsi2.c $(CDFLIBh) -cdffsi3.o: cdffsi3.c $(CDFLIBh) -cdffii.o: cdffii.c $(CDFLIBh) -cdfstr.o: cdfstr.c $(CDFLIBh) -cdfed.o: cdfed.c $(CDFLIBh) -cdfvalid.o: cdfvalid.c $(CDFLIBh) -cdfhyper.o: cdfhyper.c $(CDFLIBh) -cdfhyper64.o: cdfhyper64.c $(CDFLIBh) -cdfmem.o: cdfmem.c $(CDFLIBh) -cdfhuff.o: cdfhuff.c $(CDFLIBh) -cdfrle.o: cdfrle.c $(CDFLIBh) -cdfgzip.o: cdfgzip.c $(CDFLIBh) $(CDFGZIPh) -epochu.o: epochu.c $(CDFLIBh) -epochuf.o: epochuf.c $(CDFLIBh) -dirutils.o: dirutils.c $(CDFLIBh) -vstream.o: vstream.c $(CDFLIBh) -cdfalloc64.o: cdfalloc64.c $(CDFLIBh) $(CDFREVh) -cdfclo64.o: cdfclo64.c $(CDFLIBh) -cdfcon64.o: cdfcon64.c $(CDFLIBh) -cdfcre64.o: cdfcre64.c $(CDFLIBh) $(CDFREVh) -cdfdel64.o: cdfdel64.c $(CDFLIBh) -cdfget64.o: cdfget64.c $(CDFLIBh) $(CDFREVh) -cdfput1_64.o: cdfput1_64.c $(CDFLIBh) -cdfput2_64.o: cdfput2_64.c $(CDFLIBh) -cdfmisc1_64.o: cdfmisc1_64.c $(CDFLIBh) $(CDFREVh) -cdfmisc2_64.o: cdfmisc2_64.c $(CDFLIBh) -cdfmisc3_64.o: cdfmisc3_64.c $(CDFLIBh) -cdfread64.o: cdfread64.c $(CDFLIBh) -cdfsel64.o: cdfsel64.c $(CDFLIBh) -cdfwrite64.o: cdfwrite64.c $(CDFLIBh) -vstream64.o: vstream64.c $(CDFLIBh) -cdfhuff64.o: cdfhuff64.c $(CDFLIBh) -cdfrle64.o: cdfrle64.c $(CDFLIBh) -cdfgzip64.o: cdfgzip64.c $(CDFLIBh) $(CDFGZIPh) -cdfcks.o: cdfcks.c $(CDFLIBh) $(CDFMD5h) -cdfmd5.o: cdfmd5.c $(CDFLIBh) $(CDFMD5h) -cdfsav.o: cdfsav.c $(CDFLIBh) -cdfvalidator.o: cdfvalidator.c $(CDFLIBh) -cdfvalidator64.o: cdfvalidator64.c $(CDFLIBh) -cdftt2000.o: cdftt2000.c $(CDFLIBh) -cdftt2000f.o: cdftt2000f.c $(CDFLIBh) - -ranlib.no: -shared.no: - -#------------------------------------------------------------------------------ -# Clean/purge. -#------------------------------------------------------------------------------ - -clean: - @-rm -f *.o - @-rm -f zlib/*.o - @-rm -f core - @-rm -f libcdf.a - @-rm -f libcdf.so - @-rm -f libcdf.sl - @-rm -f libcdf.dylib - @-rm -f libcdf.dll - -purge: - @-rm -f *~ - @-rm -f *# - diff --git a/cdf36_3-dist/src/lib/cdfalloc.c b/cdf36_3-dist/src/lib/cdfalloc.c deleted file mode 100644 index 22443e2..0000000 --- a/cdf36_3-dist/src/lib/cdfalloc.c +++ /dev/null @@ -1,939 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF library allocation functions. -* -* Version 1.0, 22-Jul-96, Hughes STX. -* -* Modification history: -* -* V1.0 22-Jul-96, J Love Original version. -* V2.0 7-May-10, M Liu Modified to update file's length when a -* VVR/CVVR is allocated, if needed. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdfrev.h" - -/****************************************************************************** -* Local function prototypes. -******************************************************************************/ - -static CDFstatus InsertRecords PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, struct AllocStruct alloc, - Int32 vxrStart, int *count, Int32 *toRec -)); -static CDFstatus AppendRecords PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, struct AllocStruct *alloc, - Int32 vxrStart, int *count -)); -static CDFstatus InsertEntry PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, struct AllocStruct *alloc, - Int32 vxrOffset, int atEntryN, int *count -)); -static void InsertAtEntry PROTOARGs(( - Int32 first, Int32 last, Int32 offset, struct VXRstruct *VXR, int atEntryN, - Logical *push, Int32 *pushFirst, Int32 *pushLast, Int32 *pushOffset -)); -static CDFstatus AppendEntry PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, struct AllocStruct *alloc, - Int32 vxrOffset, int *count -)); -static CDFstatus PadSparseRecords PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 offset, Int32 nRecords -)); -static CDFstatus CountVXRs PROTOARGs(( - struct CDFstruct *CDF, Int32 vxrStart, int *count -)); -static void InitNewVXRx PROTOARGs((struct VXRstruct *VXRx)); -static CDFstatus FirstRecords PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, struct AllocStruct *alloc -)); -static CDFstatus ExtendLevel PROTOARGs(( - struct CDFstruct *CDF, Int32 vxrOffset, int count, Int32 *vxrOffsetHead, - Int32 *lastNew, int *countNew -)); -static CDFstatus CreateLevel PROTOARGs(( - struct CDFstruct *CDF, Int32 vxrOffset, int count, Int32 *vxrOffsetHead, - int *newCount -)); -static CDFstatus AllocateVR PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, struct AllocStruct *alloc, - Int32 *offset -)); -static CDFstatus AllocateVVR PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 nRecords, - Int32 *vvrOffset -)); -static CDFstatus AllocateCVVR PROTOARGs(( - struct CDFstruct *CDF, Int32 cSize, Int32 xSize, Int32 *cvvrOffset -)); - -/****************************************************************************** -* AllocateRecords. -******************************************************************************/ - -STATICforIDL CDFstatus AllocateRecords (CDF, Var, alloc) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct AllocStruct alloc; -{ - CDFstatus pStatus = CDF_OK; - Int32 vxrHead, toRec, vxrHeadNew; int count, newCount; - /**************************************************************************** - * Read the head of the VXR tree/list. - ****************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_VXRHEAD,&vxrHead, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * If no records allocated yet... - ****************************************************************************/ - if (vxrHead == ZERO_OFFSET) { - if (!sX(FirstRecords(CDF,Var,&alloc),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * Allocate records starting at the VXRhead until done. - ****************************************************************************/ - while (alloc.first <= alloc.last) { - /************************************************************************** - * Try to insert all of the records. - **************************************************************************/ - if (!sX(InsertRecords(CDF,Var, - alloc,vxrHead, - &count,&toRec),&pStatus)) return pStatus; - /************************************************************************** - * Check to see if another level of indexing needs to be added. Multiple - * levels may be created here because prior to CDF V2.6 a hierarchical - * indexing scheme was not used. - **************************************************************************/ - while (count > NUM_VXRx_ENTRIES - 1) { - if (!sX(CreateLevel(CDF,vxrHead,count, - &vxrHeadNew,&newCount),&pStatus)) return pStatus; - vxrHead = vxrHeadNew; - if (!sX(WriteVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_VXRHEAD,&vxrHead, - VDR_NULL),&pStatus)) return pStatus; - count = newCount; - } - /************************************************************************** - * Adjust the allocation request based on the record actually allocated to. - **************************************************************************/ - alloc.first = toRec + 1; - } - /**************************************************************************** - * Update the VXR tail in case it changed. This assumes that the VXR tail - * field in the VDR is not used by any of the record allocation routines. - ****************************************************************************/ - if (!sX(UpdateVXRtailInVDR(CDF,Var),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* InsertRecords. -******************************************************************************/ - -static CDFstatus InsertRecords (CDF, Var, alloc, vxrStart, count, toRec) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct AllocStruct alloc; -Int32 vxrStart; -int *count; -Int32 *toRec; -{ - CDFstatus pStatus = CDF_OK; struct VXRstruct VXR; - Int32 vxrOffset = vxrStart, irType, vxrOffsetNew, lastNew; - int entryN, belowCount, belowCountNew, toEndCount, countNew; - /**************************************************************************** - * Scan linked list of VXRs... - ****************************************************************************/ - *count = 0; - while (vxrOffset != ZERO_OFFSET) { - /************************************************************************** - * Read VXR. - **************************************************************************/ - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - (*count)++; - /************************************************************************** - * Scan VXR entries... - **************************************************************************/ - for (entryN = 0; entryN < VXR.NusedEntries; entryN++) { - if (alloc.first < VXR.First[entryN]) { - if (!sX(ReadIrType(CDF->fp, - VXR.Offset[entryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: { - Int32 prevRecN = VXR.First[entryN] - 1; - alloc.last = MINIMUM(alloc.last,prevRecN); - if (!sX(InsertRecords(CDF,Var,alloc, - VXR.Offset[entryN], - &belowCount, - toRec),&pStatus)) return pStatus; - VXR.First[entryN] = alloc.first; - while (belowCount > NUM_VXRx_ENTRIES - 1) { - if (!sX(CreateLevel(CDF,VXR.Offset[entryN], - belowCount,&VXR.Offset[entryN], - &belowCountNew),&pStatus)) return pStatus; - belowCount = belowCountNew; - } - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - if (!sX(CountVXRs(CDF,VXR.VXRnext, - &toEndCount),&pStatus)) return pStatus; - *count += toEndCount; - return pStatus; - } - case VVR_: - case CVVR_: - if (alloc.last > VXR.First[entryN] - 1) { - if (EXISTSisBAD(&alloc)) return CDF_INTERNAL_ERROR; - alloc.last = VXR.First[entryN] - 1; - sX (SOME_ALREADY_ALLOCATED, &pStatus); - } - if (!sX(InsertEntry(CDF,Var, - &alloc,vxrOffset, - entryN,&toEndCount),&pStatus)) return pStatus; - *count += (toEndCount - 1); - *toRec = alloc.last; - return pStatus; - default: - return CORRUPTED_V2_CDF; - } - } - else { - if (alloc.first <= VXR.Last[entryN]) { - if (!sX(ReadIrType(CDF->fp, - VXR.Offset[entryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - alloc.last = MINIMUM(alloc.last,VXR.Last[entryN]); - if (!sX(InsertRecords(CDF,Var,alloc, - VXR.Offset[entryN], - &belowCount, - toRec),&pStatus)) return pStatus; - while (belowCount > NUM_VXRx_ENTRIES - 1) { - if (!sX(CreateLevel(CDF,VXR.Offset[entryN], - belowCount,&VXR.Offset[entryN], - &belowCountNew),&pStatus)) return pStatus; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - belowCount = belowCountNew; - } - if (!sX(CountVXRs(CDF,VXR.VXRnext, - &toEndCount),&pStatus)) return pStatus; - *count += toEndCount; - return pStatus; - case VVR_: - case CVVR_: - if (EXISTSisBAD(&alloc)) return CDF_INTERNAL_ERROR; - sX (SOME_ALREADY_ALLOCATED, &pStatus); - *toRec = MINIMUM(VXR.Last[entryN],alloc.last); - if (!sX(CountVXRs(CDF, - VXR.VXRnext, - &toEndCount),&pStatus)) return pStatus; - *count += toEndCount; - return pStatus; - default: - return CORRUPTED_V2_CDF; - } - } - } - } - /************************************************************************** - * No more entries for this VXR. If there are no more VXRs... - **************************************************************************/ - if (VXR.VXRnext == ZERO_OFFSET) { - int lastEntryN = entryN - 1; - if (!sX(ReadIrType(CDF->fp, - VXR.Offset[lastEntryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - if (!sX(AppendRecords(CDF,Var,&alloc, - VXR.Offset[lastEntryN], - &belowCount),&pStatus)) return pStatus; - VXR.Last[lastEntryN] = alloc.last; - if (belowCount > NUM_VXRx_ENTRIES) { - if (!sX(ExtendLevel(CDF,VXR.Offset[lastEntryN], - belowCount,&vxrOffsetNew, - &lastNew,&countNew),&pStatus)) return pStatus; - VXR.Last[lastEntryN] = lastNew; - VXR.VXRnext = vxrOffsetNew; - *count += countNew; - } - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - *toRec = alloc.last; - break; - case VVR_: - case CVVR_: - if (!sX(AppendEntry(CDF,Var,&alloc, - vxrOffset,&toEndCount),&pStatus)) return pStatus; - *count += (toEndCount - 1); - *toRec = alloc.last; - break; - default: - return CORRUPTED_V2_CDF; - } - return pStatus; - } - /************************************************************************** - * Go on to the next VXR. - **************************************************************************/ - vxrOffset = VXR.VXRnext; - } - return pStatus; -} - -/****************************************************************************** -* AppendRecords. -******************************************************************************/ - -static CDFstatus AppendRecords (CDF, Var, alloc, vxrStart, count) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct AllocStruct *alloc; -Int32 vxrStart; -int *count; -{ - CDFstatus pStatus = CDF_OK; struct VXRstruct VXR; - Int32 vxrOffset = vxrStart, irType, vxrOffsetNew, lastNew; - int lastEntryN, belowCount, toEndCount, countNew; - /**************************************************************************** - * Locate last VXR on linked list. We had better be appending at the last - * VXR. - ****************************************************************************/ - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - *count = 1; - while (VXR.VXRnext != ZERO_OFFSET) { - vxrOffset = VXR.VXRnext; - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - (*count)++; - } - /**************************************************************************** - * If the last entry points to another VXR, recursively call this routine - * with the offset of that VXR. Otherwise, append the entry. - ****************************************************************************/ - lastEntryN = (int) (VXR.NusedEntries - 1); - if (!sX(ReadIrType(CDF->fp, - VXR.Offset[lastEntryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - if (!sX(AppendRecords(CDF,Var,alloc, - VXR.Offset[lastEntryN], - &belowCount),&pStatus)) return pStatus; - VXR.Last[lastEntryN] = alloc->last; - if (belowCount > NUM_VXRx_ENTRIES) { - if (!sX(ExtendLevel(CDF,VXR.Offset[lastEntryN], - belowCount,&vxrOffsetNew, - &lastNew,&countNew),&pStatus)) return pStatus; - VXR.Last[lastEntryN] = lastNew; - VXR.VXRnext = vxrOffsetNew; - *count += countNew; - } - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - break; - case VVR_: - case CVVR_: - if (!sX(AppendEntry(CDF,Var,alloc, - vxrOffset,&toEndCount),&pStatus)) return pStatus; - *count += (toEndCount - 1); - break; - default: - return CORRUPTED_V2_CDF; - } - return pStatus; -} - -/****************************************************************************** -* InsertEntry. -******************************************************************************/ - -static CDFstatus InsertEntry (CDF, Var, alloc, vxrOffset, atEntryN, count) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct AllocStruct *alloc; -Int32 vxrOffset; -int atEntryN; -int *count; -{ - CDFstatus pStatus = CDF_OK; - Int32 vxrOffsetNew, vrOffset, pushFirst, pushLast, pushOffset; - struct VXRstruct VXR; Logical push; - /**************************************************************************** - * Read the VXR, insert the entry while determining if an entry was pushed - * out of the VXR, and rewrite the VXR. - ****************************************************************************/ - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - if (!sX(AllocateVR(CDF,Var,alloc,&vrOffset),&pStatus)) return pStatus; - InsertAtEntry (alloc->first, alloc->last, vrOffset, &VXR, atEntryN, - &push, &pushFirst, &pushLast, &pushOffset); - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - *count = 1; - /**************************************************************************** - * While an entry was pushed out... - ****************************************************************************/ - while (push) { - if (VXR.VXRnext != ZERO_OFFSET) { - vxrOffset = VXR.VXRnext; - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - InsertAtEntry (pushFirst, pushLast, pushOffset, &VXR, 0, &push, - &pushFirst, &pushLast, &pushOffset); - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - } - else { - if (!sX(AllocateIR(CDF,((Int32)VXR_BASE_SIZE), - &vxrOffsetNew),&pStatus)) return pStatus; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_VXRNEXT,&vxrOffsetNew, - VXR_NULL),&pStatus)) return pStatus; - InitNewVXR (&VXR, pushFirst, pushLast, pushOffset); - if (!sX(WriteVXR(CDF->fp,vxrOffsetNew, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - push = FALSE; - } - (*count)++; - } - return pStatus; -} - -/****************************************************************************** -* InsertAtEntry. -******************************************************************************/ - -static void InsertAtEntry (first, last, offset, VXR, atEntryN, push, - pushFirst, pushLast, pushOffset) -Int32 first; -Int32 last; -Int32 offset; -struct VXRstruct *VXR; -int atEntryN; -Logical *push; -Int32 *pushFirst; -Int32 *pushLast; -Int32 *pushOffset; -{ - int startEntryN, entryN; - if (VXR->NusedEntries < VXR->Nentries) { - *push = FALSE; - startEntryN = (int) VXR->NusedEntries; - VXR->NusedEntries++; - } - else { - startEntryN = (int) (VXR->Nentries - 1); - *pushFirst = VXR->First[startEntryN]; - *pushLast = VXR->Last[startEntryN]; - *pushOffset = VXR->Offset[startEntryN]; - *push = TRUE; - } - for (entryN = startEntryN; entryN > atEntryN; entryN--) { - VXR->First[entryN] = VXR->First[entryN-1]; - VXR->Last[entryN] = VXR->Last[entryN-1]; - VXR->Offset[entryN] = VXR->Offset[entryN-1]; - } - VXR->First[atEntryN] = first; - VXR->Last[atEntryN] = last; - VXR->Offset[atEntryN] = offset; - return; -} - -/****************************************************************************** -* AppendEntry. -* It is assumed that the offset is for a VXR at the end of a linked list. -******************************************************************************/ - -static CDFstatus AppendEntry (CDF, Var, alloc, vxrOffset, count) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct AllocStruct *alloc; -Int32 vxrOffset; -int *count; -{ - CDFstatus pStatus = CDF_OK; Logical resized; - struct VXRstruct VXR, newVXR; Int32 offset, vxrOffsetNew; - /**************************************************************************** - * Read the VXR. - ****************************************************************************/ - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * First check if a VVR_ can be extended. - ****************************************************************************/ - if (alloc->type == VVR_) { - if (!alloc->vvr.newX) { - int lastEntryN = (int) (VXR.NusedEntries - 1); - if (alloc->first == VXR.Last[lastEntryN] + 1) { - Int32 newCount = alloc->last - VXR.First[lastEntryN] + 1; - Int32 newSize = VVR_BASE_SIZE + (newCount * Var->NphyRecBytes); - if (!sX(ResizeIR(CDF,VXR.Offset[lastEntryN], - newSize,NULL, - FALSE,&resized),&pStatus)) return pStatus; - if (resized) { - VXR.Last[lastEntryN] = alloc->last; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - if (!sX(WriteVVR(CDF->fp,VXR.Offset[lastEntryN], - VVR_RECORDSIZE,&newSize, - VVR_NULL),&pStatus)) return pStatus; - switch (Var->vType) { - case SPARSE_RECORDS_: - if (alloc->last < Var->maxWritten) { - Int32 nRecords = alloc->first - VXR.First[lastEntryN]; - offset = VXR.Offset[lastEntryN] + - VVR_BASE_SIZE + - (nRecords * Var->NphyRecBytes); - if (!sX(PadSparseRecords(CDF,Var, - offset, - nRecords),&pStatus)) return pStatus; - } - break; - } - *count = 1; - return pStatus; - } - } - } - } - /**************************************************************************** - * If there is an unused entry... - ****************************************************************************/ - if (VXR.NusedEntries < VXR.Nentries) { - int entryN = (int) VXR.NusedEntries; - VXR.First[entryN] = alloc->first; - VXR.Last[entryN] = alloc->last; - if (!sX(AllocateVR(CDF,Var,alloc, - &VXR.Offset[entryN]),&pStatus)) return pStatus; - VXR.NusedEntries++; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - *count = 1; - return pStatus; - } - /**************************************************************************** - * No unused entries - create a new VXR. - ****************************************************************************/ - if (!sX(AllocateIR(CDF,((Int32)VXR_BASE_SIZE), - &vxrOffsetNew),&pStatus)) return pStatus; - if (!sX(AllocateVR(CDF,Var,alloc,&offset),&pStatus)) return pStatus; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_VXRNEXT,&vxrOffsetNew, - VXR_NULL),&pStatus)) return pStatus; - InitNewVXR (&newVXR, alloc->first, alloc->last, offset); - if (!sX(WriteVXR(CDF->fp,vxrOffsetNew, - VXR_RECORD,&newVXR, - VXR_NULL),&pStatus)) return pStatus; - *count = 2; - return pStatus; -} - -/****************************************************************************** -* PadSparseRecords. -******************************************************************************/ - -static CDFstatus PadSparseRecords (CDF, Var, offset, nRecords) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 offset; -Int32 nRecords; -{ - CDFstatus pStatus = CDF_OK; int how; void *buffer; - if (!sX(BuildPadBuffer(CDF,Var,nRecords, - &how,&buffer,TRUE),&pStatus)) return pStatus; - if (!sX(WritePadValues(Var,CDF->fp,offset, - nRecords,how,buffer),&pStatus)) { - cdf_FreeMemory (buffer, NULL); - return pStatus; - } - cdf_FreeMemory (buffer, NULL); - return pStatus; -} - -/****************************************************************************** -* CountVXRs. -******************************************************************************/ - -static CDFstatus CountVXRs (CDF, vxrStart, count) -struct CDFstruct *CDF; -Int32 vxrStart; -int *count; -{ - CDFstatus pStatus = CDF_OK; Int32 vxrOffset = vxrStart; - *count = 0; - while (vxrOffset != ZERO_OFFSET) { - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_VXRNEXT,&vxrOffset, - VXR_NULL),&pStatus)) return pStatus; - (*count)++; - } - return pStatus; -} - -/****************************************************************************** -* InitNewVXR. -******************************************************************************/ - -STATICforIDL void InitNewVXR (VXR, firstRec, lastRec, offset) -struct VXRstruct *VXR; -Int32 firstRec; -Int32 lastRec; -Int32 offset; -{ - int entryN; - VXR->RecordSize = VXR_BASE_SIZE; - VXR->RecordType = VXR_; - VXR->VXRnext = ZERO_OFFSET; - VXR->Nentries = NUM_VXR_ENTRIES; - VXR->NusedEntries = 1; - VXR->First[0] = firstRec; - VXR->Last[0] = lastRec; - VXR->Offset[0] = offset; - for (entryN = 1; entryN < NUM_VXR_ENTRIES; entryN++) { - VXR->First[entryN] = NO_RECORD; - VXR->Last[entryN] = NO_RECORD; - VXR->Offset[entryN] = NO_OFFSET; - } - return; -} - -/****************************************************************************** -* InitNewVXRx. -******************************************************************************/ - -static void InitNewVXRx (VXRx) -struct VXRstruct *VXRx; -{ - int entryN; - VXRx->RecordSize = VXRx_BASE_SIZE; - VXRx->RecordType = VXR_; - VXRx->VXRnext = 0; - VXRx->Nentries = NUM_VXRx_ENTRIES; - VXRx->NusedEntries = 0; - for (entryN = 0; entryN < NUM_VXRx_ENTRIES; entryN++) { - VXRx->First[entryN] = NO_RECORD; - VXRx->Last[entryN] = NO_RECORD; - VXRx->Offset[entryN] = NO_OFFSET; - } - return; -} - -/****************************************************************************** -* FirstRecords. -******************************************************************************/ - -static CDFstatus FirstRecords (CDF, Var, alloc) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct AllocStruct *alloc; -{ - CDFstatus pStatus = CDF_OK; - struct VXRstruct VXR; Int32 offset, vxrOffset; - if (!sX(AllocateIR(CDF,VXR_BASE_SIZE,&vxrOffset),&pStatus)) return pStatus; - if (!sX(AllocateVR(CDF,Var,alloc,&offset),&pStatus)) return pStatus; - InitNewVXR (&VXR, alloc->first, alloc->last, offset); - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - if (!sX(WriteVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_VXRHEAD,&vxrOffset, - VDR_VXRTAIL,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* ExtendLevel. -******************************************************************************/ - -static CDFstatus ExtendLevel (CDF, vxrOffset, count, vxrOffsetHead, lastNew, - countNew) -struct CDFstruct *CDF; -Int32 vxrOffset; -int count; -Int32 *vxrOffsetHead; -Int32 *lastNew; -int *countNew; -{ - CDFstatus pStatus = CDF_OK; struct VXRstruct VXR; - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - *lastNew = VXR.Last[(int)(VXR.NusedEntries-1)]; - if (!sX(CreateLevel(CDF,VXR.VXRnext,count-1, - vxrOffsetHead,countNew),&pStatus)) return pStatus; - VXR.VXRnext = ZERO_OFFSET; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CreateLevel. -******************************************************************************/ - -static CDFstatus CreateLevel (CDF, vxrOffset, count, vxrOffsetHead, newCount) -struct CDFstruct *CDF; -Int32 vxrOffset; -int count; -Int32 *vxrOffsetHead; -int *newCount; -{ - CDFstatus pStatus = CDF_OK; - Int32 sizeOfVXRx = VXRx_BASE_SIZE; - Int32 vxrOffsetNext, vxrOffsetNew; - int remaining = count, entryN; - struct VXRstruct VXR, newVXR; - /**************************************************************************** - * Create/initialize first VXRx_. - ****************************************************************************/ - if (!sX(AllocateIR(CDF,sizeOfVXRx,vxrOffsetHead),&pStatus)) return pStatus; - InitNewVXRx (&newVXR); - *newCount = 1; - vxrOffsetNew = *vxrOffsetHead; - /**************************************************************************** - * Until no more VXRs... - ****************************************************************************/ - while (vxrOffset != ZERO_OFFSET) { - /************************************************************************** - * Read VXR. - **************************************************************************/ - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************** - * If the current VXRx_ is full... - **************************************************************************/ - if (newVXR.NusedEntries == newVXR.Nentries) { - if (!sX(AllocateIR(CDF,sizeOfVXRx, - &(newVXR.VXRnext)),&pStatus)) return pStatus; - if (!sX(WriteVXR(CDF->fp,vxrOffsetNew, - VXR_RECORD,&newVXR, - VXR_NULL),&pStatus)) return pStatus; - vxrOffsetNew = newVXR.VXRnext; - InitNewVXRx (&newVXR); - (*newCount)++; - } - /************************************************************************** - * Determine entry to be used and increment number of used entries. - **************************************************************************/ - entryN = (int) newVXR.NusedEntries; - newVXR.NusedEntries++; - /************************************************************************** - * If this is the last entry in the VXRx_ and there aren't enough VXRs for - * another full VXRx_... - **************************************************************************/ - if (entryN == newVXR.Nentries - 1) { - if (remaining < NUM_VXRx_ENTRIES + 1) { - newVXR.First[entryN] = VXR.First[0]; - while (VXR.VXRnext != ZERO_OFFSET) { - if (!sX(ReadVXR(CDF->fp,VXR.VXRnext, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - } - newVXR.Last[entryN] = VXR.Last[(int)(VXR.NusedEntries-1)]; - newVXR.Offset[entryN] = vxrOffset; - break; - } - } - /************************************************************************** - * Add this VXR's indexing to the current VXRx_. - **************************************************************************/ - newVXR.First[entryN] = VXR.First[0]; - newVXR.Last[entryN] = VXR.Last[(int)(VXR.NusedEntries-1)]; - newVXR.Offset[entryN] = vxrOffset; - /************************************************************************** - * Break the VXR's link to the next VXR. - **************************************************************************/ - vxrOffsetNext = VXR.VXRnext; - VXR.VXRnext = ZERO_OFFSET; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - vxrOffset = vxrOffsetNext; - /************************************************************************** - * Decrement the number of remaining VXRs. - **************************************************************************/ - remaining--; - } - /**************************************************************************** - * Write the VXRx_ before returning. - ****************************************************************************/ - if (!sX(WriteVXR(CDF->fp,vxrOffsetNew, - VXR_RECORD,&newVXR, - VXR_NULL),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* AllocateVR. -******************************************************************************/ - -static CDFstatus AllocateVR (CDF, Var, alloc, offset) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct AllocStruct *alloc; -Int32 *offset; -{ - CDFstatus pStatus = CDF_OK; - switch (alloc->type) { - case VVR_: { - Int32 nRecords = alloc->last - alloc->first + 1; - if (!sX(AllocateVVR(CDF,Var, - nRecords, - offset),&pStatus)) return pStatus; - switch (Var->vType) { - case SPARSE_RECORDS_: - if (alloc->last < Var->maxWritten) { - Int32 tOffset = *offset + VVR_BASE_SIZE; - if (!sX(PadSparseRecords(CDF,Var, - tOffset, - nRecords),&pStatus)) return pStatus; - } - break; - } - break; - } - case CVVR_: - if (!sX(AllocateCVVR(CDF,alloc->cvvr.cSize, - alloc->cvvr.xSize, - offset),&pStatus)) return pStatus; - break; - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* AllocateVVR. -******************************************************************************/ - -static CDFstatus AllocateVVR (CDF, Var, nRecords, vvrOffset) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 nRecords; -Int32 *vvrOffset; -{ - CDFstatus pStatus = CDF_OK; struct VVRstruct VVR; - VVR.RecordSize = (Int32) (VVR_BASE_SIZE + (nRecords * Var->NphyRecBytes)); - VVR.RecordType = VVR_; - if (!sX(AllocateIR(CDF,VVR.RecordSize,vvrOffset),&pStatus)) return pStatus; - if (!sX(WriteVVR(CDF->fp,*vvrOffset, - VVR_RECORDx,&VVR, - VVR_NULL),&pStatus)) return pStatus; - CDF->fp->length = MaxLong (CDF->fp->length, (long) - *vvrOffset + VVR.RecordSize); - return pStatus; -} - -/****************************************************************************** -* AllocateCVVR. -******************************************************************************/ - -static CDFstatus AllocateCVVR (CDF, cSize, xSize, cvvrOffset) -struct CDFstruct *CDF; -Int32 cSize; -Int32 xSize; -Int32 *cvvrOffset; -{ - CDFstatus pStatus = CDF_OK; struct CVVRstruct CVVR; - CVVR.RecordSize = (Int32) (CVVR_BASE_SIZE + cSize + xSize); - CVVR.RecordType = CVVR_; - CVVR.rfuA = (Int32) 0; - CVVR.cSize = cSize; - if (!sX(AllocateIR(CDF,CVVR.RecordSize,cvvrOffset),&pStatus)) return pStatus; - if (!sX(WriteCVVR(CDF->fp,*cvvrOffset, - CVVR_RECORDx,&CVVR, - CVVR_NULL),&pStatus)) return pStatus; - CDF->fp->length = MaxLong (CDF->fp->length, (long) - *cvvrOffset + CVVR.RecordSize); - return pStatus; -} - -/****************************************************************************** -* UpdateVXRtailInVDR. -******************************************************************************/ - -STATICforIDL CDFstatus UpdateVXRtailInVDR (CDF, Var) -struct CDFstruct *CDF; -struct VarStruct *Var; -{ - CDFstatus pStatus = CDF_OK; struct VXRstruct VXR; - Int32 vxrOffset, irType; int lastEntryN; - /**************************************************************************** - * Read the VXR head. If zero, set the VXR tail to zero. - ****************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_VXRHEAD,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - if (vxrOffset == ZERO_OFFSET) { - if (!sX(WriteVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_VXRTAIL,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * Otherwise, read to the VXR tail... - ****************************************************************************/ - for (;;) { - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - while (VXR.VXRnext != ZERO_OFFSET) { - vxrOffset = VXR.VXRnext; - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - } - lastEntryN = (int) (VXR.NusedEntries - 1); - if (!sX(ReadIrType(CDF->fp, - VXR.Offset[lastEntryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - vxrOffset = VXR.Offset[lastEntryN]; - break; - case VVR_: - case CVVR_: - if (!sX(WriteVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_VXRTAIL,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - return pStatus; - default: - return CORRUPTED_V2_CDF; - } - } -} - diff --git a/cdf36_3-dist/src/lib/cdfalloc64.c b/cdf36_3-dist/src/lib/cdfalloc64.c deleted file mode 100644 index f02ca99..0000000 --- a/cdf36_3-dist/src/lib/cdfalloc64.c +++ /dev/null @@ -1,947 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF library allocation functions. -* -* Version 1.0, 22-Jul-96, Hughes STX. -* -* Modification history: -* -* V1.0 22-Jul-96, J Love Original version. -* V2.0 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* V3.0 7-May-10, M Liu Modified to update file's length64 when a -* VVR/CVVR is allocated, if needed. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" -#include "cdfrev.h" - -/****************************************************************************** -* Local function prototypes. -******************************************************************************/ - -static CDFstatus InsertRecords PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, struct AllocStruct alloc, - OFF_T vxrStart, int *count, Int32 *toRec -)); -static CDFstatus AppendRecords PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, struct AllocStruct *alloc, - OFF_T vxrStart, int *count -)); -static CDFstatus InsertEntry PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, struct AllocStruct *alloc, - OFF_T vxrOffset, int atEntryN, int *count -)); -static void InsertAtEntry PROTOARGs(( - Int32 first, Int32 last, OFF_T offset, struct VXRstruct64 *VXR, int atEntryN, - Logical *push, Int32 *pushFirst, Int32 *pushLast, OFF_T *pushOffset -)); -static CDFstatus AppendEntry PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, struct AllocStruct *alloc, - OFF_T vxrOffset, int *count -)); -static CDFstatus PadSparseRecords PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, OFF_T offset, Int32 nRecords -)); -static CDFstatus CountVXRs PROTOARGs(( - struct CDFstruct *CDF, OFF_T vxrStart, int *count -)); -static void InitNewVXRx PROTOARGs((struct VXRstruct64 *VXRx)); -static CDFstatus FirstRecords PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, struct AllocStruct *alloc -)); -static CDFstatus ExtendLevel PROTOARGs(( - struct CDFstruct *CDF, OFF_T vxrOffset, int count, OFF_T *vxrOffsetHead, - Int32 *lastNew, int *countNew -)); -static CDFstatus CreateLevel PROTOARGs(( - struct CDFstruct *CDF, OFF_T vxrOffset, int count, OFF_T *vxrOffsetHead, - int *newCount -)); -static CDFstatus AllocateVR PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, struct AllocStruct *alloc, - OFF_T *offset -)); -static CDFstatus AllocateVVR PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 nRecords, - OFF_T *vvrOffset -)); -static CDFstatus AllocateCVVR PROTOARGs(( - struct CDFstruct *CDF, OFF_T cSize, OFF_T xSize, OFF_T *cvvrOffset -)); - -/****************************************************************************** -* AllocateRecords64. -******************************************************************************/ - -STATICforIDL CDFstatus AllocateRecords64 (CDF, Var, alloc) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct AllocStruct alloc; -{ - CDFstatus pStatus = CDF_OK; - Int32 toRec; int count, newCount; - OFF_T vxrHead, vxrHeadNew; - /**************************************************************************** - * Read the head of the VXR tree/list. - ****************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_VXRHEAD,&vxrHead, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * If no records allocated yet... - ****************************************************************************/ - if (vxrHead == (OFF_T) ZERO_OFFSET64) { - if (!sX(FirstRecords(CDF,Var,&alloc),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * Allocate records starting at the VXRhead until done. - ****************************************************************************/ - while (alloc.first <= alloc.last) { - /************************************************************************** - * Try to insert all of the records. - **************************************************************************/ - if (!sX(InsertRecords(CDF,Var, - alloc,vxrHead, - &count,&toRec),&pStatus)) return pStatus; - /************************************************************************** - * Check to see if another level of indexing needs to be added. Multiple - * levels may be created here because prior to CDF V2.6 a hierarchical - * indexing scheme was not used. - **************************************************************************/ - while (count > NUM_VXRx_ENTRIES - 1) { - if (!sX(CreateLevel(CDF,vxrHead,count, - &vxrHeadNew,&newCount),&pStatus)) return pStatus; - vxrHead = vxrHeadNew; - if (!sX(WriteVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_VXRHEAD,&vxrHead, - VDR_NULL),&pStatus)) return pStatus; - count = newCount; - } - /************************************************************************** - * Adjust the allocation request based on the record actually allocated to. - **************************************************************************/ - alloc.first = toRec + 1; - } - /**************************************************************************** - * Update the VXR tail in case it changed. This assumes that the VXR tail - * field in the VDR is not used by any of the record allocation routines. - ****************************************************************************/ - if (!sX(UpdateVXRtailInVDR64(CDF,Var),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* InsertRecords. -******************************************************************************/ - -static CDFstatus InsertRecords (CDF, Var, alloc, vxrStart, count, toRec) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct AllocStruct alloc; -OFF_T vxrStart; -int *count; -Int32 *toRec; -{ - CDFstatus pStatus = CDF_OK; struct VXRstruct64 VXR; - OFF_T vxrOffset = vxrStart, vxrOffsetNew; - Int32 irType, lastNew; - int entryN, belowCount, belowCountNew, toEndCount, countNew; - /**************************************************************************** - * Scan linked list of VXRs... - ****************************************************************************/ - *count = 0; - while (vxrOffset != (OFF_T) ZERO_OFFSET64) { - /************************************************************************** - * Read VXR. - **************************************************************************/ - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - (*count)++; - /************************************************************************** - * Scan VXR entries... - **************************************************************************/ - for (entryN = 0; entryN < VXR.NusedEntries; entryN++) { - if (alloc.first < VXR.First[entryN]) { - if (!sX(ReadIrType64(CDF->fp, - VXR.Offset[entryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: { - Int32 prevRecN = VXR.First[entryN] - 1; - alloc.last = MINIMUM(alloc.last,prevRecN); - if (!sX(InsertRecords(CDF,Var,alloc, - VXR.Offset[entryN], - &belowCount, - toRec),&pStatus)) return pStatus; - VXR.First[entryN] = alloc.first; - while (belowCount > NUM_VXRx_ENTRIES - 1) { - if (!sX(CreateLevel(CDF,VXR.Offset[entryN], - belowCount,&VXR.Offset[entryN], - &belowCountNew),&pStatus)) return pStatus; - belowCount = belowCountNew; - } - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - if (!sX(CountVXRs(CDF,VXR.VXRnext, - &toEndCount),&pStatus)) return pStatus; - *count += toEndCount; - return pStatus; - } - case VVR_: - case CVVR_: - if (alloc.last > VXR.First[entryN] - 1) { - if (EXISTSisBAD(&alloc)) return CDF_INTERNAL_ERROR; - alloc.last = VXR.First[entryN] - 1; - sX (SOME_ALREADY_ALLOCATED, &pStatus); - } - if (!sX(InsertEntry(CDF,Var, - &alloc,vxrOffset, - entryN,&toEndCount),&pStatus)) return pStatus; - *count += (toEndCount - 1); - *toRec = alloc.last; - return pStatus; - default: - return CORRUPTED_V3_CDF; - } - } - else { - if (alloc.first <= VXR.Last[entryN]) { - if (!sX(ReadIrType64(CDF->fp, - VXR.Offset[entryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - alloc.last = MINIMUM(alloc.last,VXR.Last[entryN]); - if (!sX(InsertRecords(CDF,Var,alloc, - VXR.Offset[entryN], - &belowCount, - toRec),&pStatus)) return pStatus; - while (belowCount > NUM_VXRx_ENTRIES - 1) { - if (!sX(CreateLevel(CDF,VXR.Offset[entryN], - belowCount,&VXR.Offset[entryN], - &belowCountNew),&pStatus)) return pStatus; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - belowCount = belowCountNew; - } - if (!sX(CountVXRs(CDF,VXR.VXRnext, - &toEndCount),&pStatus)) return pStatus; - *count += toEndCount; - return pStatus; - case VVR_: - case CVVR_: - if (EXISTSisBAD(&alloc)) return CDF_INTERNAL_ERROR; - sX (SOME_ALREADY_ALLOCATED, &pStatus); - *toRec = MINIMUM(VXR.Last[entryN],alloc.last); - if (!sX(CountVXRs(CDF, - VXR.VXRnext, - &toEndCount),&pStatus)) return pStatus; - *count += toEndCount; - return pStatus; - default: - return CORRUPTED_V3_CDF; - } - } - } - } - /************************************************************************** - * No more entries for this VXR. If there are no more VXRs... - **************************************************************************/ - if (VXR.VXRnext == (OFF_T) ZERO_OFFSET64) { - int lastEntryN = entryN - 1; - if (!sX(ReadIrType64(CDF->fp, - VXR.Offset[lastEntryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - if (!sX(AppendRecords(CDF,Var,&alloc, - VXR.Offset[lastEntryN], - &belowCount),&pStatus)) return pStatus; - VXR.Last[lastEntryN] = alloc.last; - if (belowCount > NUM_VXRx_ENTRIES) { - if (!sX(ExtendLevel(CDF,VXR.Offset[lastEntryN], - belowCount,&vxrOffsetNew, - &lastNew,&countNew),&pStatus)) return pStatus; - VXR.Last[lastEntryN] = lastNew; - VXR.VXRnext = vxrOffsetNew; - *count += countNew; - } - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - *toRec = alloc.last; - break; - case VVR_: - case CVVR_: - if (!sX(AppendEntry(CDF,Var,&alloc, - vxrOffset,&toEndCount),&pStatus)) return pStatus; - *count += (toEndCount - 1); - *toRec = alloc.last; - break; - default: - return CORRUPTED_V3_CDF; - } - return pStatus; - } - /************************************************************************** - * Go on to the next VXR. - **************************************************************************/ - vxrOffset = VXR.VXRnext; - } - return pStatus; -} - -/****************************************************************************** -* AppendRecords. -******************************************************************************/ - -static CDFstatus AppendRecords (CDF, Var, alloc, vxrStart, count) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct AllocStruct *alloc; -OFF_T vxrStart; -int *count; -{ - CDFstatus pStatus = CDF_OK; struct VXRstruct64 VXR; - OFF_T vxrOffset = vxrStart, vxrOffsetNew; - Int32 irType, lastNew; - int lastEntryN, belowCount, toEndCount, countNew; - /**************************************************************************** - * Locate last VXR on linked list. We had better be appending at the last - * VXR. - ****************************************************************************/ - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - *count = 1; - while (VXR.VXRnext != (OFF_T) ZERO_OFFSET64) { - vxrOffset = VXR.VXRnext; - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - (*count)++; - } - /**************************************************************************** - * If the last entry points to another VXR, recursively call this routine - * with the offset of that VXR. Otherwise, append the entry. - ****************************************************************************/ - lastEntryN = (int) (VXR.NusedEntries - 1); - if (!sX(ReadIrType64(CDF->fp, - VXR.Offset[lastEntryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - if (!sX(AppendRecords(CDF,Var,alloc, - VXR.Offset[lastEntryN], - &belowCount),&pStatus)) return pStatus; - VXR.Last[lastEntryN] = alloc->last; - if (belowCount > NUM_VXRx_ENTRIES) { - if (!sX(ExtendLevel(CDF,VXR.Offset[lastEntryN], - belowCount,&vxrOffsetNew, - &lastNew,&countNew),&pStatus)) return pStatus; - VXR.Last[lastEntryN] = lastNew; - VXR.VXRnext = vxrOffsetNew; - *count += countNew; - } - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - break; - case VVR_: - case CVVR_: - if (!sX(AppendEntry(CDF,Var,alloc, - vxrOffset,&toEndCount),&pStatus)) return pStatus; - *count += (toEndCount - 1); - break; - default: - return CORRUPTED_V3_CDF; - } - return pStatus; -} - -/****************************************************************************** -* InsertEntry. -******************************************************************************/ - -static CDFstatus InsertEntry (CDF, Var, alloc, vxrOffset, atEntryN, count) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct AllocStruct *alloc; -OFF_T vxrOffset; -int atEntryN; -int *count; -{ - CDFstatus pStatus = CDF_OK; - OFF_T vxrOffsetNew, vrOffset, pushOffset; Int32 pushFirst, pushLast; - struct VXRstruct64 VXR; Logical push; - /**************************************************************************** - * Read the VXR, insert the entry while determining if an entry was pushed - * out of the VXR, and rewrite the VXR. - ****************************************************************************/ - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - if (!sX(AllocateVR(CDF,Var,alloc,&vrOffset),&pStatus)) return pStatus; - InsertAtEntry (alloc->first, alloc->last, vrOffset, &VXR, atEntryN, - &push, &pushFirst, &pushLast, &pushOffset); - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - *count = 1; - /**************************************************************************** - * While an entry was pushed out... - ****************************************************************************/ - while (push) { - if (VXR.VXRnext != (OFF_T) ZERO_OFFSET64) { - vxrOffset = VXR.VXRnext; - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - InsertAtEntry (pushFirst, pushLast, pushOffset, &VXR, 0, &push, - &pushFirst, &pushLast, &pushOffset); - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - } - else { - if (!sX(AllocateIR64(CDF,((Int32)VXR_BASE_SIZE64), - &vxrOffsetNew),&pStatus)) return pStatus; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_VXRNEXT,&vxrOffsetNew, - VXR_NULL),&pStatus)) return pStatus; - InitNewVXR64 (&VXR, pushFirst, pushLast, pushOffset); - if (!sX(WriteVXR64(CDF->fp,vxrOffsetNew, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - push = FALSE; - } - (*count)++; - } - return pStatus; -} - -/****************************************************************************** -* InsertAtEntry. -******************************************************************************/ - -static void InsertAtEntry (first, last, offset, VXR, atEntryN, push, - pushFirst, pushLast, pushOffset) -Int32 first; -Int32 last; -OFF_T offset; -struct VXRstruct64 *VXR; -int atEntryN; -Logical *push; -Int32 *pushFirst; -Int32 *pushLast; -OFF_T *pushOffset; -{ - int startEntryN, entryN; - if (VXR->NusedEntries < VXR->Nentries) { - *push = FALSE; - startEntryN = (int) VXR->NusedEntries; - VXR->NusedEntries++; - } - else { - startEntryN = (int) (VXR->Nentries - 1); - *pushFirst = VXR->First[startEntryN]; - *pushLast = VXR->Last[startEntryN]; - *pushOffset = VXR->Offset[startEntryN]; - *push = TRUE; - } - for (entryN = startEntryN; entryN > atEntryN; entryN--) { - VXR->First[entryN] = VXR->First[entryN-1]; - VXR->Last[entryN] = VXR->Last[entryN-1]; - VXR->Offset[entryN] = VXR->Offset[entryN-1]; - } - VXR->First[atEntryN] = first; - VXR->Last[atEntryN] = last; - VXR->Offset[atEntryN] = offset; - return; -} - -/****************************************************************************** -* AppendEntry. -* It is assumed that the offset is for a VXR at the end of a linked list. -******************************************************************************/ - -static CDFstatus AppendEntry (CDF, Var, alloc, vxrOffset, count) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct AllocStruct *alloc; -OFF_T vxrOffset; -int *count; -{ - CDFstatus pStatus = CDF_OK; Logical resized; - struct VXRstruct64 VXR, newVXR; OFF_T offset, vxrOffsetNew; - /**************************************************************************** - * Read the VXR. - ****************************************************************************/ - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * First check if a VVR_ can be extended. - ****************************************************************************/ - if (alloc->type == VVR_) { - if (!alloc->vvr.newX) { - int lastEntryN = (int) (VXR.NusedEntries - 1); - if (alloc->first == VXR.Last[lastEntryN] + 1) { - Int32 newCount = alloc->last - VXR.First[lastEntryN] + 1; - OFF_T newSize = (OFF_T) (VVR_BASE_SIZE64 + - ((OFF_T)newCount) * Var->NphyRecBytes); - if (!sX(ResizeIR64(CDF,VXR.Offset[lastEntryN], - newSize,NULL, - FALSE,&resized),&pStatus)) return pStatus; - if (resized) { - VXR.Last[lastEntryN] = alloc->last; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - if (!sX(WriteVVR64(CDF->fp,VXR.Offset[lastEntryN], - VVR_RECORDSIZE,&newSize, - VVR_NULL),&pStatus)) return pStatus; - switch (Var->vType) { - case SPARSE_RECORDS_: - if (alloc->last < Var->maxWritten) { - Int32 nRecords = alloc->first - VXR.First[lastEntryN]; - offset = VXR.Offset[lastEntryN] + - VVR_BASE_SIZE64 + - (nRecords * Var->NphyRecBytes); - if (!sX(PadSparseRecords(CDF,Var, - offset, - nRecords),&pStatus)) return pStatus; - } - break; - } - *count = 1; - return pStatus; - } - } - } - } - /**************************************************************************** - * If there is an unused entry... - ****************************************************************************/ - if (VXR.NusedEntries < VXR.Nentries) { - int entryN = (int) VXR.NusedEntries; - VXR.First[entryN] = alloc->first; - VXR.Last[entryN] = alloc->last; - if (!sX(AllocateVR(CDF,Var,alloc, - &VXR.Offset[entryN]),&pStatus)) return pStatus; - VXR.NusedEntries++; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - *count = 1; - return pStatus; - } - /**************************************************************************** - * No unused entries - create a new VXR. - ****************************************************************************/ - if (!sX(AllocateIR64(CDF,((Int32)VXR_BASE_SIZE64), - &vxrOffsetNew),&pStatus)) return pStatus; - if (!sX(AllocateVR(CDF,Var,alloc,&offset),&pStatus)) return pStatus; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_VXRNEXT,&vxrOffsetNew, - VXR_NULL),&pStatus)) return pStatus; - InitNewVXR64 (&newVXR, alloc->first, alloc->last, offset); - if (!sX(WriteVXR64(CDF->fp,vxrOffsetNew, - VXR_RECORD,&newVXR, - VXR_NULL),&pStatus)) return pStatus; - *count = 2; - return pStatus; -} - -/****************************************************************************** -* PadSparseRecords. -******************************************************************************/ - -static CDFstatus PadSparseRecords (CDF, Var, offset, nRecords) -struct CDFstruct *CDF; -struct VarStruct *Var; -OFF_T offset; -Int32 nRecords; -{ - CDFstatus pStatus = CDF_OK; int how; void *buffer; - if (!sX(BuildPadBuffer64(CDF,Var,nRecords, - &how,&buffer,TRUE),&pStatus)) return pStatus; - if (!sX(WritePadValues64(Var,CDF->fp,offset, - nRecords,how,buffer),&pStatus)) { - cdf_FreeMemory (buffer, NULL); - return pStatus; - } - cdf_FreeMemory (buffer, NULL); - return pStatus; -} - -/****************************************************************************** -* CountVXRs. -******************************************************************************/ - -static CDFstatus CountVXRs (CDF, vxrStart, count) -struct CDFstruct *CDF; -OFF_T vxrStart; -int *count; -{ - CDFstatus pStatus = CDF_OK; OFF_T vxrOffset = vxrStart; - *count = 0; - while (vxrOffset != (OFF_T) ZERO_OFFSET64) { - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_VXRNEXT,&vxrOffset, - VXR_NULL),&pStatus)) return pStatus; - (*count)++; - } - return pStatus; -} - -/****************************************************************************** -* InitNewVXR64. -******************************************************************************/ - -STATICforIDL void InitNewVXR64 (VXR, firstRec, lastRec, offset) -struct VXRstruct64 *VXR; -Int32 firstRec; -Int32 lastRec; -OFF_T offset; -{ - int entryN; - VXR->RecordSize = VXR_BASE_SIZE64; - VXR->RecordType = VXR_; - VXR->VXRnext = (OFF_T) ZERO_OFFSET64; - VXR->Nentries = NUM_VXR_ENTRIES; - VXR->NusedEntries = 1; - VXR->First[0] = firstRec; - VXR->Last[0] = lastRec; - VXR->Offset[0] = offset; - for (entryN = 1; entryN < NUM_VXR_ENTRIES; entryN++) { - VXR->First[entryN] = NO_RECORD; - VXR->Last[entryN] = NO_RECORD; - VXR->Offset[entryN] = (OFF_T) NO_OFFSET64; - } - return; -} - -/****************************************************************************** -* InitNewVXRx. -******************************************************************************/ - -static void InitNewVXRx (VXRx) -struct VXRstruct64 *VXRx; -{ - int entryN; - VXRx->RecordSize = VXRx_BASE_SIZE64; - VXRx->RecordType = VXR_; - VXRx->VXRnext = (OFF_T) 0; - VXRx->Nentries = NUM_VXRx_ENTRIES; - VXRx->NusedEntries = 0; - for (entryN = 0; entryN < NUM_VXRx_ENTRIES; entryN++) { - VXRx->First[entryN] = NO_RECORD; - VXRx->Last[entryN] = NO_RECORD; - VXRx->Offset[entryN] = (OFF_T) NO_OFFSET64; - } - return; -} - -/****************************************************************************** -* FirstRecords. -******************************************************************************/ - -static CDFstatus FirstRecords (CDF, Var, alloc) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct AllocStruct *alloc; -{ - CDFstatus pStatus = CDF_OK; - struct VXRstruct64 VXR; OFF_T offset, vxrOffset; - if (!sX(AllocateIR64(CDF,VXR_BASE_SIZE64,&vxrOffset),&pStatus)) - return pStatus; - if (!sX(AllocateVR(CDF,Var,alloc,&offset),&pStatus)) return pStatus; - InitNewVXR64 (&VXR, alloc->first, alloc->last, offset); - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - if (!sX(WriteVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_VXRHEAD,&vxrOffset, - VDR_VXRTAIL,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* ExtendLevel. -******************************************************************************/ - -static CDFstatus ExtendLevel (CDF, vxrOffset, count, vxrOffsetHead, lastNew, - countNew) -struct CDFstruct *CDF; -OFF_T vxrOffset; -int count; -OFF_T *vxrOffsetHead; -Int32 *lastNew; -int *countNew; -{ - CDFstatus pStatus = CDF_OK; struct VXRstruct64 VXR; - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - *lastNew = VXR.Last[(int)(VXR.NusedEntries-1)]; - if (!sX(CreateLevel(CDF,VXR.VXRnext,count-1, - vxrOffsetHead,countNew),&pStatus)) return pStatus; - VXR.VXRnext = (OFF_T) ZERO_OFFSET64; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CreateLevel. -******************************************************************************/ - -static CDFstatus CreateLevel (CDF, vxrOffset, count, vxrOffsetHead, newCount) -struct CDFstruct *CDF; -OFF_T vxrOffset; -int count; -OFF_T *vxrOffsetHead; -int *newCount; -{ - CDFstatus pStatus = CDF_OK; - Int32 sizeOfVXRx = VXRx_BASE_SIZE64; - OFF_T vxrOffsetNext, vxrOffsetNew; - int remaining = count, entryN; - struct VXRstruct64 VXR, newVXR; - /**************************************************************************** - * Create/initialize first VXRx_. - ****************************************************************************/ - if (!sX(AllocateIR64(CDF,sizeOfVXRx,vxrOffsetHead),&pStatus)) return pStatus; - InitNewVXRx (&newVXR); - *newCount = 1; - vxrOffsetNew = *vxrOffsetHead; - /**************************************************************************** - * Until no more VXRs... - ****************************************************************************/ - while (vxrOffset != (OFF_T) ZERO_OFFSET64) { - /************************************************************************** - * Read VXR. - **************************************************************************/ - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************** - * If the current VXRx_ is full... - **************************************************************************/ - if (newVXR.NusedEntries == newVXR.Nentries) { - if (!sX(AllocateIR64(CDF,sizeOfVXRx, - &(newVXR.VXRnext)),&pStatus)) return pStatus; - if (!sX(WriteVXR64(CDF->fp,vxrOffsetNew, - VXR_RECORD,&newVXR, - VXR_NULL),&pStatus)) return pStatus; - vxrOffsetNew = newVXR.VXRnext; - InitNewVXRx (&newVXR); - (*newCount)++; - } - /************************************************************************** - * Determine entry to be used and increment number of used entries. - **************************************************************************/ - entryN = (int) newVXR.NusedEntries; - newVXR.NusedEntries++; - /************************************************************************** - * If this is the last entry in the VXRx_ and there aren't enough VXRs for - * another full VXRx_... - **************************************************************************/ - if (entryN == newVXR.Nentries - 1) { - if (remaining < NUM_VXRx_ENTRIES + 1) { - newVXR.First[entryN] = VXR.First[0]; - while (VXR.VXRnext != (OFF_T) ZERO_OFFSET64) { - if (!sX(ReadVXR64(CDF->fp,VXR.VXRnext, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - } - newVXR.Last[entryN] = VXR.Last[(int)(VXR.NusedEntries-1)]; - newVXR.Offset[entryN] = vxrOffset; - break; - } - } - /************************************************************************** - * Add this VXR's indexing to the current VXRx_. - **************************************************************************/ - newVXR.First[entryN] = VXR.First[0]; - newVXR.Last[entryN] = VXR.Last[(int)(VXR.NusedEntries-1)]; - newVXR.Offset[entryN] = vxrOffset; - /************************************************************************** - * Break the VXR's link to the next VXR. - **************************************************************************/ - vxrOffsetNext = VXR.VXRnext; - VXR.VXRnext = (OFF_T) ZERO_OFFSET64; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - vxrOffset = vxrOffsetNext; - /************************************************************************** - * Decrement the number of remaining VXRs. - **************************************************************************/ - remaining--; - } - /**************************************************************************** - * Write the VXRx_ before returning. - ****************************************************************************/ - if (!sX(WriteVXR64(CDF->fp,vxrOffsetNew, - VXR_RECORD,&newVXR, - VXR_NULL),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* AllocateVR. -******************************************************************************/ - -static CDFstatus AllocateVR (CDF, Var, alloc, offset) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct AllocStruct *alloc; -OFF_T *offset; -{ - CDFstatus pStatus = CDF_OK; - switch (alloc->type) { - case VVR_: { - Int32 nRecords = alloc->last - alloc->first + 1; - if (!sX(AllocateVVR(CDF,Var, - nRecords, - offset),&pStatus)) return pStatus; - switch (Var->vType) { - case SPARSE_RECORDS_: - if (alloc->last < Var->maxWritten) { - OFF_T tOffset = *offset + VVR_BASE_SIZE64; - if (!sX(PadSparseRecords(CDF,Var, - tOffset, - nRecords),&pStatus)) return pStatus; - } - break; - } - break; - } - case CVVR_: - if (!sX(AllocateCVVR(CDF,alloc->cvvr64.cSize, - alloc->cvvr64.xSize, - offset),&pStatus)) return pStatus; - break; - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* AllocateVVR. -******************************************************************************/ - -static CDFstatus AllocateVVR (CDF, Var, nRecords, vvrOffset) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 nRecords; -OFF_T *vvrOffset; -{ - CDFstatus pStatus = CDF_OK; struct VVRstruct64 VVR; - VVR.RecordSize = (OFF_T) (VVR_BASE_SIZE64 + - ((OFF_T)nRecords) * Var->NphyRecBytes); - VVR.RecordType = VVR_; - if (!sX(AllocateIR64(CDF,VVR.RecordSize,vvrOffset),&pStatus)) return pStatus; - if (!sX(WriteVVR64(CDF->fp,*vvrOffset, - VVR_RECORDx,&VVR, - VVR_NULL),&pStatus)) return pStatus; - CDF->fp->length64 = MaxLongLong (CDF->fp->length64, *vvrOffset + - VVR.RecordSize); - return pStatus; -} - -/****************************************************************************** -* AllocateCVVR. -******************************************************************************/ - -static CDFstatus AllocateCVVR (CDF, cSize, xSize, cvvrOffset) -struct CDFstruct *CDF; -OFF_T cSize; -OFF_T xSize; -OFF_T *cvvrOffset; -{ - CDFstatus pStatus = CDF_OK; struct CVVRstruct64 CVVR; - CVVR.RecordSize = (OFF_T) (CVVR_BASE_SIZE64 + cSize + xSize); - CVVR.RecordType = CVVR_; - CVVR.rfuA = (Int32) 0; - CVVR.cSize = cSize; - if (!sX(AllocateIR64(CDF,CVVR.RecordSize,cvvrOffset),&pStatus)) return pStatus; - if (!sX(WriteCVVR64(CDF->fp,*cvvrOffset, - CVVR_RECORDx,&CVVR, - CVVR_NULL),&pStatus)) return pStatus; - CDF->fp->length64 = MaxLongLong (CDF->fp->length64, *cvvrOffset + - CVVR.RecordSize); - return pStatus; -} - -/****************************************************************************** -* UpdateVXRtailInVDR64. -******************************************************************************/ - -STATICforIDL CDFstatus UpdateVXRtailInVDR64 (CDF, Var) -struct CDFstruct *CDF; -struct VarStruct *Var; -{ - CDFstatus pStatus = CDF_OK; struct VXRstruct64 VXR; - OFF_T vxrOffset; Int32 irType; int lastEntryN; - /**************************************************************************** - * Read the VXR head. If zero, set the VXR tail to zero. - ****************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_VXRHEAD,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - if (vxrOffset == (OFF_T) ZERO_OFFSET64) { - if (!sX(WriteVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_VXRTAIL,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * Otherwise, read to the VXR tail... - ****************************************************************************/ - for (;;) { - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - while (VXR.VXRnext != (OFF_T) ZERO_OFFSET64) { - vxrOffset = VXR.VXRnext; - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - } - lastEntryN = (int) (VXR.NusedEntries - 1); - if (!sX(ReadIrType64(CDF->fp, - VXR.Offset[lastEntryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - vxrOffset = VXR.Offset[lastEntryN]; - break; - case VVR_: - case CVVR_: - if (!sX(WriteVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_VXRTAIL,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - return pStatus; - default: - return CORRUPTED_V3_CDF; - } - } -} - diff --git a/cdf36_3-dist/src/lib/cdfcks.c b/cdf36_3-dist/src/lib/cdfcks.c deleted file mode 100644 index 06d3b63..0000000 --- a/cdf36_3-dist/src/lib/cdfcks.c +++ /dev/null @@ -1,573 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `check sum' operations. -* -* Version 1.0, 21-Mar-06, Hughes STX. -* -* Modification history: -* -* V1.0 21-Mar-06, M Liu Original version. -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" -#include "cdfmd5.h" - -#define BUFFSIZE 16384 - -/****************************************************************************** -* Local function prototypes. -******************************************************************************/ -CDFstatus AddChecksumMD5 PROTOARGs((vFILE *vFp, long size, - uChar *signature)); -CDFstatus AddChecksumMD5_64 PROTOARGs((vFILE *vFp, OFF_T size, - uChar *signature)); -CDFstatus ComputeChecksumMD5 PROTOARGs((vFILE *vFp, long size, - uChar *signature)); -CDFstatus ComputeChecksumMD5_64 PROTOARGs((vFILE *vFp, OFF_T size, - uChar *signature)); -CDFstatus GetChecksumMD5 PROTOARGs((vFILE *vFp, long size, - uChar *signature)); -CDFstatus GetChecksumMD5_64 PROTOARGs((vFILE *vFp, OFF_T size, - uChar *signature)); -CDFstatus AddChecksum PROTOARGs((struct CDFstruct *CDF)); -CDFstatus AddChecksum64 PROTOARGs((struct CDFstruct *CDF)); -CDFstatus VerifyChecksum PROTOARGs((struct CDFstruct *CDF)); -CDFstatus VerifyChecksum64 PROTOARGs((struct CDFstruct *CDF)); - -/****************************************************************************** -* AddChecksumMD5. -******************************************************************************/ - -CDFstatus AddChecksumMD5 (vFp, size, signature) -vFILE *vFp; -long size; -uChar signature[16]; -{ - -#if defined(vms) - size_t lastBlk; - uChar buffer[512]; - int i, j, inBlk, cross= 0; - inBlk = size % 512; - lastBlk = (size_t) 512 * (size / 512); - if (inBlk != 0) { - if (fseek(vFp->fp,lastBlk,SEEK_SET) == EOF) { - return FALSE; - } - /* for (i = 0; i < 512; i++) buffer[i] = 0; */ - memset (buffer, 0, (size_t) 512); - if (fread(buffer,512,1,vFp->fp) != 1) { - return FALSE; - } - for (i = 0; i < 16; i++) { - j = inBlk + i; - if (j > 511) { - cross = i; - break; - } - buffer[j] = signature[i]; - } - if (fseek(vFp->fp,lastBlk,SEEK_SET) == EOF) { - return FALSE; - } - if (fwrite(buffer,512,1,vFp->fp) != 1) { - return FALSE; - } - - if (cross > 0) { - /* for (i = 0; i < 512; i++) buffer[i] = 0; */ - memset (buffer, 0, (size_t) 512); - j = 0; - for (i = cross; i < 16; i++) { - buffer[j] = signature[i]; - j++; - } - if (fwrite(buffer,512,1,vFp->fp) != 1) { - return FALSE; - } - } - } else { - /* for (i = 16; i < 512; i++) buffer[i] = 0; */ - /* for (i = 0; i < 16; i++) buffer[i] = signature[i]; */ - memcpy (buffer, signature, (size_t) 16); - memset (buffer+16, 0, (size_t) 512-16); - if (fseek(vFp->fp,size,SEEK_SET) == EOF) { - return FALSE; - } - if (fwrite(buffer,512,1,vFp->fp) != 1) { - return FALSE; - } - } -#else - if (fseek(vFp->fp,size,vSEEK_SET) == EOF) return FALSE; - if (fwrite(signature,1,16,vFp->fp) != 16) return FALSE; -#endif - if (fflush(vFp->fp) == EOF) { - vFp->error = TRUE; - return FALSE; - } - return TRUE; -} - -/****************************************************************************** -* AddChecksumMD5_64. -******************************************************************************/ - -CDFstatus AddChecksumMD5_64 (vFp, size, signature) -vFILE *vFp; -OFF_T size; -uChar signature[16]; -{ - -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (vFp->fh == 0) return FALSE; - if (FSEEK64(vFp->fh,(OFF_T) size,vSEEK_SET) == EOF) return FALSE; - if (FWRITE64(vFp->fh,signature,16) != 16) return FALSE; - if (FLUSH64(vFp->fh) == EOF) { - vFp->error = TRUE; - return FALSE; - } -#else - if (vFp->fp == NULL) return FALSE; - else { -# if defined(vms) - OFF_T lastBlk; - uChar buffer[512]; - int i, j, inBlk, cross= 0; - inBlk = size % 512; - lastBlk = (OFF_T) 512 * (size / 512); - if (inBlk != 0) { - if (FSEEK64(vFp->fp,lastBlk,SEEK_SET) == EOF) { - vFp->error = TRUE; - return FALSE; - } - /* for (i = 0; i < 512; i++) buffer[i] = 0; */ - memset (buffer, 0, (size_t) 512); - if (FREAD64(buffer,512,1,vFp->fp) != 1) { - vFp->error = TRUE; - return FALSE; - } - for (i = 0; i < 16; i++) { - j = inBlk + i; - if (j > 511) { - cross = i; - break; - } - buffer[j] = signature[i]; - } - if (FSEEK64(vFp->fp,lastBlk,SEEK_SET) == EOF) { - vFp->error = TRUE; - return FALSE; - } - if (FWRITE64(buffer,512,1,vFp->fp) != 1) { - vFp->error = TRUE; - return FALSE; - } - - if (cross > 0) { - /* for (i = 0; i < 512; i++) buffer[i] = 0; */ - memset (buffer, 0, (size_t) 512); - j = 0; - for (i = cross; i < 16; i++) { - buffer[j] = signature[i]; - j++; - } - if (FWRITE64(buffer,512,1,vFp->fp) != 1) { - vFp->error = TRUE; - return FALSE; - } - } - } else { - /* for (i = 16; i < 512; i++) buffer[i] = 0; */ - /* for (i = 0; i < 16; i++) buffer[i] = signature[i]; */ - memcpy (buffer, signature, (size_t) 16); - memset (buffer+16, 0, (size_t) 512-16); - if (FSEEK64(vFp->fp,size,SEEK_SET) == EOF) { - vFp->error = TRUE; - return FALSE; - } - if (FWRITE64(buffer,512,1,vFp->fp) != 1) { - vFp->error = TRUE; - return FALSE; - } - } -# else - if (FSEEK64(vFp->fp,(OFF_T) size,vSEEK_SET) == EOF) return FALSE; - if (FWRITE64(signature,1,16,vFp->fp) != 16) return FALSE; -# endif - } - if (FLUSH64(vFp->fp) == EOF) { - vFp->error = TRUE; - return FALSE; - } -#endif - return TRUE; -} - -/****************************************************************************** -* ComputeChecksumMD5. -******************************************************************************/ - -CDFstatus ComputeChecksumMD5 (vFp, size, signature) -vFILE *vFp; -long size; -uChar signature[16]; -{ - uChar buffer[BUFFSIZE]; - struct MD5Context md5c; - int jj = 0, readBytes; - - MD5Init(&md5c); - if (fseek(vFp->fp, 0, vSEEK_SET) == EOF) return FALSE; - while (jj < size) { - if (jj+BUFFSIZE < size) readBytes = BUFFSIZE; - else readBytes = size - jj; - if (fread(buffer,1,readBytes,vFp->fp) != (size_t) readBytes) return FALSE; - MD5Update(&md5c, buffer, (unsigned) readBytes); - jj = jj + readBytes; - } - MD5FinalZ(signature, &md5c); - return TRUE; - -} - -/****************************************************************************** -* ComputeChecksumMD5_64. -******************************************************************************/ - -CDFstatus ComputeChecksumMD5_64 (vFp, size, signature) -vFILE *vFp; -OFF_T size; -uChar signature[16]; -{ - uChar buffer[BUFFSIZE]; - struct MD5Context md5c; - OFF_T jj = 0; - int readBytes; - - MD5Init(&md5c); -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (FSEEK64(vFp->fh,(OFF_T) 0,vSEEK_SET) == EOF) return FALSE; -#else - if (FSEEK64(vFp->fp,(OFF_T) 0,vSEEK_SET) == EOF) return FALSE; -#endif - while (jj < size) { - if (jj+BUFFSIZE < size) readBytes = BUFFSIZE; - else readBytes = (int) (size - jj); -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (FREAD64(vFp->fh,buffer,(unsigned int) readBytes) != (int) readBytes) - return FALSE; -#else - if (FREAD64(buffer,1,readBytes,vFp->fp) != readBytes) return FALSE; -#endif - MD5Update(&md5c, buffer, (unsigned) readBytes); - jj = jj + readBytes; - } - MD5FinalZ(signature, &md5c); - return TRUE; -} - -/****************************************************************************** -* GetChecksumMD5. -******************************************************************************/ - -CDFstatus GetChecksumMD5 (vFp, size, signature) -vFILE *vFp; -long size; -uChar signature[16]; -{ - - if (fseek(vFp->fp,size,vSEEK_SET) == EOF) return FALSE; - if (fread(signature,1,16,vFp->fp) != 16) return FALSE; - return TRUE; -} - -/****************************************************************************** -* GetChecksumMD5_64. -******************************************************************************/ - -CDFstatus GetChecksumMD5_64 (vFp, size, signature) -vFILE *vFp; -OFF_T size; -uChar *signature; -{ - -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (FSEEK64(vFp->fh,(OFF_T) size,vSEEK_SET) == EOF) return FALSE; - if (FREAD64(vFp->fh,signature,16) != 16) return FALSE; -#else - if (FSEEK64(vFp->fp,(OFF_T) size,vSEEK_SET) == EOF) return FALSE; - if (FREAD64(signature,1,16,vFp->fp) != 16) return FALSE; -#endif - return TRUE; -} - -/****************************************************************************** -* CDFVerifyChecksum. -******************************************************************************/ - -CDFstatus CDFVerifyChecksum (CDF) -struct CDFstruct *CDF; -{ - - if (!CDF->largeFile) - return VerifyChecksum (CDF); - else - return VerifyChecksum64 (CDF); - -} - -/****************************************************************************** -* VerifyChecksum. -******************************************************************************/ - -CDFstatus VerifyChecksum (CDF) -struct CDFstruct *CDF; -{ - long GDRoffset, CPRoffset; - Int32 CDRflags; - long CCRsize, CPRsize, usedSize; - CDFstatus pStatus = CDF_OK; - uChar signature[16], csig[16]; - - if (!sX(ReadCDR(CDF->fp,V2_CDR_OFFSET, - CDR_FLAGS,&CDRflags, - CDR_GDROFFSET, &GDRoffset, - CDR_NULL),&pStatus)) { - return pStatus; - } - - if (!BITSET(CDRflags,CDR_CHECKSUM_BIT)) return pStatus; - - if (CDF->uDotFp == NULL) { - /************************************************************************** - * A uncompressed CDF. - **************************************************************************/ - if (!sX(ReadGDR(CDF->dotFp,GDRoffset, - GDR_EOF,&usedSize, - GDR_NULL),&pStatus)) { - return pStatus; - } - } else { - /************************************************************************** - * A compressed CDF. - **************************************************************************/ - if (!sX(ReadCCR(CDF->dotFp,V2_CCR_OFFSET, - CCR_RECORDSIZE,&CCRsize, - CCR_CPROFFSET, &CPRoffset, - CCR_NULL),&pStatus)) { - return pStatus; - } - if (!sX(ReadCPR(CDF->dotFp,CPRoffset, - CPR_RECORDSIZE,&CPRsize, - CPR_NULL),&pStatus)) { - return pStatus; - } - usedSize = 8 + CCRsize + CPRsize; - } - - if (BITSET(CDRflags,CDR_CHECKSUM_MD5_BIT)) { - if (!sX(GetChecksumMD5(CDF->dotFp, usedSize, signature), - &pStatus)) return pStatus; - if (!sX(ComputeChecksumMD5(CDF->dotFp, usedSize, csig), - &pStatus)) return pStatus; - if (memcmp(signature, csig, 16) == 0) return CDF_OK; - else return CHECKSUM_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* VerifyChecksum64. -******************************************************************************/ - -CDFstatus VerifyChecksum64 (CDF) -struct CDFstruct *CDF; -{ - OFF_T GDRoffset, CPRoffset; - Int32 CDRflags; - OFF_T CCRsize, CPRsize, usedSize; - CDFstatus pStatus = CDF_OK; - uChar signature[16], csig[16]; - - if (!sX(ReadCDR64(CDF->fp,V3_CDR_OFFSET64, - CDR_FLAGS,&CDRflags, - CDR_GDROFFSET, &GDRoffset, - CDR_NULL),&pStatus)) { - return pStatus; - } - if (!BITSET(CDRflags,CDR_CHECKSUM_BIT)) return pStatus; - if (CDF->uDotFp == NULL) { - /************************************************************************** - * A uncompressed CDF. - **************************************************************************/ - if (!sX(ReadGDR64(CDF->dotFp,GDRoffset, - GDR_EOF,&usedSize, - GDR_NULL),&pStatus)) { - return pStatus; - } - } else { - /************************************************************************** - * A compressed CDF. - **************************************************************************/ - if (!sX(ReadCCR64(CDF->dotFp,V3_CCR_OFFSET64, - CCR_RECORDSIZE,&CCRsize, - CCR_CPROFFSET, &CPRoffset, - CCR_NULL),&pStatus)) { - return pStatus; - } - if (!sX(ReadCPR64(CDF->dotFp,CPRoffset, - CPR_RECORDSIZE,&CPRsize, - CPR_NULL),&pStatus)) { - return pStatus; - } - usedSize = 8 + CCRsize + CPRsize; - } - - if (BITSET(CDRflags,CDR_CHECKSUM_MD5_BIT)) { - if (!sX(GetChecksumMD5_64(CDF->dotFp, usedSize, signature), - &pStatus)) return pStatus; - if (!sX(ComputeChecksumMD5_64(CDF->dotFp, usedSize, csig), - &pStatus)) return pStatus; - if (memcmp(signature, csig, 16) == 0) return CDF_OK; - else return CHECKSUM_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* CDFAddChecksum. -******************************************************************************/ - -CDFstatus CDFAddChecksum (CDF) -struct CDFstruct *CDF; -{ - if (!CDF->largeFile) - return AddChecksum (CDF); - else - return AddChecksum64 (CDF); -} - -/****************************************************************************** -* AddChecksum. -******************************************************************************/ - -CDFstatus AddChecksum (CDF) -struct CDFstruct *CDF; -{ - long GDRoffset, CPRoffset; - Int32 CDRflags; - long CCRsize, CPRsize, usedSize; - CDFstatus pStatus = CDF_OK; - uChar signature[16]; - - if (!sX(ReadCDR(CDF->fp,V2_CDR_OFFSET, - CDR_FLAGS,&CDRflags, - CDR_GDROFFSET, &GDRoffset, - CDR_NULL),&pStatus)) { - return pStatus; - } - - if (!BITSET(CDRflags,CDR_CHECKSUM_BIT)) return pStatus; - - if (CDF->uDotFp == NULL) { - /************************************************************************** - * A uncompressed CDF. - **************************************************************************/ - if (!sX(ReadGDR(CDF->dotFp,GDRoffset, - GDR_EOF,&usedSize, - GDR_NULL),&pStatus)) { - return pStatus; - } - } else { - /************************************************************************** - * A compressed CDF. - **************************************************************************/ - if (!sX(ReadCCR(CDF->dotFp,V2_CCR_OFFSET, - CCR_RECORDSIZE,&CCRsize, - CCR_CPROFFSET, &CPRoffset, - CCR_NULL),&pStatus)) { - return pStatus; - } - if (!sX(ReadCPR(CDF->dotFp,CPRoffset, - CPR_RECORDSIZE,&CPRsize, - CPR_NULL),&pStatus)) { - return pStatus; - } - usedSize = 8 + CCRsize + CPRsize; - } - - if (BITSET(CDRflags,CDR_CHECKSUM_MD5_BIT)) { - if (!sX(ComputeChecksumMD5(CDF->dotFp, usedSize, signature), - &pStatus)) return pStatus; - if (!sX(AddChecksumMD5(CDF->dotFp, usedSize, signature), - &pStatus)) return pStatus; - } - return pStatus; -} - - -/****************************************************************************** -* AddChecksum64. -******************************************************************************/ - -CDFstatus AddChecksum64 (CDF) -struct CDFstruct *CDF; -{ - OFF_T GDRoffset, CPRoffset; - Int32 CDRflags; - OFF_T CCRsize, CPRsize, usedSize; - CDFstatus pStatus = CDF_OK; - uChar signature[16]; - - if (!sX(ReadCDR64(CDF->fp,V3_CDR_OFFSET64, - CDR_FLAGS,&CDRflags, - CDR_GDROFFSET, &GDRoffset, - CDR_NULL),&pStatus)) { - return pStatus; - } - - if (!BITSET(CDRflags,CDR_CHECKSUM_BIT)) return pStatus; - - if (CDF->uDotFp == NULL) { - /************************************************************************** - * A uncompressed CDF. - **************************************************************************/ - if (!sX(ReadGDR64(CDF->dotFp,GDRoffset, - GDR_EOF,&usedSize, - GDR_NULL),&pStatus)) { - return pStatus; - } - } else { - /************************************************************************** - * A compressed CDF. - **************************************************************************/ - if (!sX(ReadCCR64(CDF->dotFp,V3_CCR_OFFSET64, - CCR_RECORDSIZE,&CCRsize, - CCR_CPROFFSET, &CPRoffset, - CCR_NULL),&pStatus)) { - return pStatus; - } - if (!sX(ReadCPR64(CDF->dotFp,CPRoffset, - CPR_RECORDSIZE,&CPRsize, - CPR_NULL),&pStatus)) { - return pStatus; - } - usedSize = 8 + CCRsize + CPRsize; - } - - if (BITSET(CDRflags,CDR_CHECKSUM_MD5_BIT)) { - if (!sX(ComputeChecksumMD5_64(CDF->dotFp, usedSize, signature), - &pStatus)) return pStatus; - if (!sX(AddChecksumMD5_64(CDF->dotFp, usedSize, signature), - &pStatus)) return pStatus; - } - return pStatus; -} - diff --git a/cdf36_3-dist/src/lib/cdfclo.c b/cdf36_3-dist/src/lib/cdfclo.c deleted file mode 100644 index 07a181b..0000000 --- a/cdf36_3-dist/src/lib/cdfclo.c +++ /dev/null @@ -1,337 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `close' operations. -* -* Version 1.5a, 21-Feb-97, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 21-Aug-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 7-Dec-93, J Love CDF V2.4. Added zMode. -* V1.3 15-Nov-94, J Love CDF V2.5. -* V1.3a 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.4 20-Jul-95, J Love CDFexport-related changes. -* V1.5 8-Aug-96, J Love CDF V2.6. -* V1.4a 21-Feb-97, J Love Removed RICE. -* V2.0 08-Apr-04, M Liu Replaced VSTREAM.STATS with VSTREAM_STATS. -* Removed call to LocateCurrentVar when r/zVAR_ -* is closed as it does more than needed. -* -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* CDFclo. -******************************************************************************/ - -STATICforIDL CDFstatus CDFclo (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ - CDFstatus pStatus = CDF_OK; - switch (Va->item) { - /************************************************************************** - * CDF_ - * Close a CDF with or without statistics for the dotCDF file. - **************************************************************************/ - case CDF_: - case CDFwithSTATS_: { - struct CDFstruct *CDF; vSTATS vStats; - Logical statistics = (Va->item == CDFwithSTATS_); - vSTATS *vStatsDotP = BOO(statistics,va_arg(Va->ap,vSTATS *),NULL); - vSTATS *vStatsStageP = BOO(statistics,va_arg(Va->ap,vSTATS *),NULL); - vSTATS *vStatsCompressP = BOO(statistics,va_arg(Va->ap,vSTATS *),NULL); - /************************************************************************ - * Initialize the Vstream statistics. - ************************************************************************/ - AddTOvStats (vStatsDotP, NULL); - AddTOvStats (vStatsStageP, NULL); - AddTOvStats (vStatsCompressP, NULL); - /************************************************************************ - * Validate the current CDF. Don't use `SelectCDF' here because we don't - * want to return NO_MORE_ACCESS if that is the case. - ************************************************************************/ - if (Cur->cdf == NULL) - return NO_CDF_SELECTED; - else - CDF = Cur->cdf; - /************************************************************************ - * If this is a CDF for which access was aborted, simply free the CDF's - * memory. - ************************************************************************/ - if (CDF->magic == ABORTEDid_MAGIC_NUMBER) { - KillAbortedCDF (CDF, Cur); - break; - } - /************************************************************************ - * Get the Vstream statistics for the dotCDF file(s) so far. - ************************************************************************/ - AddTOvStats (vStatsDotP, &CDF->dotCDFvStats); - AddTOvStats (vStatsDotP, &CDF->uDotCDFvStats); - /************************************************************************ - * If the CDF is open read/write, update the dotCDF file. - ************************************************************************/ - if (CDF->status == READ_WRITE) { - if (!sX(UpdateDotCDF(CDF),&pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - } - /************************************************************************ - * If the CDF is compressed... - ************************************************************************/ - if (CDF->uDotFp != NULL) { - /********************************************************************** - * If the CDF is open read/write... The uncompressed dotCDF file will - * be flushed and the compressed dotCDF will be deleted and recreated - * from the uncompressed dotCDF file. - **********************************************************************/ - if (CDF->status == READ_WRITE) { - char pathName[DU_MAX_PATH_LEN+1]; - Int32 CPRoffset; struct CPRstruct CPR; - /******************************************************************** - * First flush the uncompressed dotCDF file. - ********************************************************************/ - if (!FLUSHv(CDF->uDotFp)) { - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_WRITE_ERROR; - } - /******************************************************************** - * Read the compression parameters from the compressed dotCDF file. - ********************************************************************/ - if (!sX(ReadCCR(CDF->dotFp,V2_CCR_OFFSET, - CCR_CPROFFSET,&CPRoffset, - CCR_NULL),&pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - if (!sX(ReadCPR(CDF->dotFp,CPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - /******************************************************************** - * Delete the compressed dotCDF file. - ********************************************************************/ - if (!DELETEv(CDF->dotFp,&vStats)) { - CDF->dotFp = NULL; - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CLOSE_ERROR; - } - CDF->dotFp = NULL; - AddTOvStats (vStatsDotP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "DotCDF..", &vStats); -#endif - /******************************************************************** - * Recreate the compressed dotCDF file. - ********************************************************************/ - BuildFilePath (CDFt, CDF->CDFname, CDF->no_append, - CDF->upper_case_ext, CDF->version_numbers, - INT32_ZERO, pathName); - CDF->dotFp = V_open (pathName, WRITE_PLUS_a_mode); - if (CDF->dotFp == NULL) { - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CREATE_ERROR; - } - /******************************************************************** - * Write the compressed dotCDF file. - ********************************************************************/ - if (!sX(WriteCompressedCDF(CDF,&CPR,notEMPTY),&pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - /******************************************************************** - * Close the compressed dotCDF file. - ********************************************************************/ - if (!CLOSEv(CDF->dotFp,CDF,&vStats)) { - CDF->dotFp = NULL; - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CLOSE_ERROR; - } - CDF->dotFp = NULL; - AddTOvStats (vStatsDotP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "DotCDF..", &vStats); -#endif - /******************************************************************** - * Delete the uncompressed dotCDF file. - ********************************************************************/ - if (!DELETEv(CDF->uDotFp,&vStats)) { - CDF->uDotFp = NULL; - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CLOSE_ERROR; - } - CDF->uDotFp = NULL; - AddTOvStats (vStatsDotP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "uDotCDF.", &vStats); -#endif - } - else { - /******************************************************************** - * The CDF is open read/only. First close the compressed dotCDF file - * (which has not been changed). - ********************************************************************/ - if (CDF->readOnly) ResetReadOnlyState(CDF); - if (!CLOSEv(CDF->dotFp,CDF,&vStats)) { - CDF->dotFp = NULL; - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CLOSE_ERROR; - } - CDF->dotFp = NULL; - AddTOvStats (vStatsDotP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "DotCDF..", &vStats); -#endif - /******************************************************************** - * Delete the uncompressed dotCDF file. - ********************************************************************/ - if (!DELETEv(CDF->uDotFp,&vStats)) { - CDF->uDotFp = NULL; - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CLOSE_ERROR; - } - CDF->uDotFp = NULL; - AddTOvStats (vStatsDotP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "uDotCDF.", &vStats); -#endif - } - } - else { - /********************************************************************** - * Not compressed - first close the dotCDF file. - **********************************************************************/ - if (CDF->readOnly) ResetReadOnlyState(CDF); - if (!CLOSEv(CDF->dotFp,CDF,&vStats)) { - CDF->dotFp = NULL; - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CLOSE_ERROR; - } - CDF->dotFp = NULL; - AddTOvStats (vStatsDotP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "DotCDF..", &vStats); -#endif - /********************************************************************** - * Close the variable files (if a multi-file CDF). - **********************************************************************/ - if (!sX(CloseVarFiles(CDF),&pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - } - /************************************************************************ - * Delete staging scratch file. - ************************************************************************/ - if (CDF->stage.fp != NULL) { - if (!DELETEv(CDF->stage.fp,&vStats)) { - CDF->stage.fp = NULL; - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return SCRATCH_DELETE_ERROR; - } - CDF->stage.fp = NULL; - AddTOvStats (vStatsStageP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "Stage...", &vStats); -#endif - } - /************************************************************************ - * Delete compression scratch file. - ************************************************************************/ - if (CDF->compressFp != NULL) { - if (!DELETEv(CDF->compressFp,&vStats)) { - CDF->compressFp = NULL; - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return SCRATCH_DELETE_ERROR; - } - CDF->compressFp = NULL; - AddTOvStats (vStatsCompressP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "Compress", &vStats); -#endif - } - /************************************************************************ - * Free memory used and clear current CDF. - ************************************************************************/ - FreeCDFid (CDF, FALSE); - Cur->cdf = NULL; - break; - } - /************************************************************************** - * rVAR_/zVAR_ - * Close the current r/zVariable file. - **************************************************************************/ - case rVAR_: - case zVAR_: { - Logical zOp = (Va->item == zVAR_); - struct CDFstruct *CDF; struct VarStruct *Var; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - if (zModeON(CDF)) { - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - } else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - - if (CDF->singleFile) { - sX (SINGLE_FILE_FORMAT, &pStatus); - break; - } - if (Var != NULL) { - if (Var->fp != NULL) { - if (!CLOSEv(Var->fp,NULL,NULL)) { - Var->fp = NULL; - AbortAccess (CDF, UPDATE, noDELETE); - return VAR_CLOSE_ERROR; - } - Var->fp = NULL; - } - else { - if (!sX(VAR_ALREADY_CLOSED,&pStatus)) return pStatus; - } - } - else { - if (!sX(VAR_ALREADY_CLOSED,&pStatus)) return pStatus; - } - break; - } - /************************************************************************** - * Unknown item, must be the next function. - **************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } - } - return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfclo64.c b/cdf36_3-dist/src/lib/cdfclo64.c deleted file mode 100644 index 854b577..0000000 --- a/cdf36_3-dist/src/lib/cdfclo64.c +++ /dev/null @@ -1,339 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `close' operations. -* -* Version 1.5a, 21-Feb-97, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 21-Aug-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 7-Dec-93, J Love CDF V2.4. Added zMode. -* V1.3 15-Nov-94, J Love CDF V2.5. -* V1.3a 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.4 20-Jul-95, J Love CDFexport-related changes. -* V1.5 8-Aug-96, J Love CDF V2.6. -* V1.4a 21-Feb-97, J Love Removed RICE. -* V2.0 08-Apr-04, M Liu Replaced VSTREAM.STATS with VSTREAM_STATS. -* Removed call to LocateCurrentVar when r/zVAR_ -* is closed as it does more than needed. -* V2.1 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* CDFclo64. -******************************************************************************/ - -STATICforIDL CDFstatus CDFclo64 (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ - CDFstatus pStatus = CDF_OK; - switch (Va->item) { - /************************************************************************** - * CDF_ - * Close a CDF with or without statistics for the dotCDF file. - **************************************************************************/ - case CDF_: - case CDFwithSTATS_: { - struct CDFstruct *CDF; vSTATS vStats; - Logical statistics = (Va->item == CDFwithSTATS_); - vSTATS *vStatsDotP = BOO(statistics,va_arg(Va->ap,vSTATS *),NULL); - vSTATS *vStatsStageP = BOO(statistics,va_arg(Va->ap,vSTATS *),NULL); - vSTATS *vStatsCompressP = BOO(statistics,va_arg(Va->ap,vSTATS *),NULL); - /************************************************************************ - * Initialize the Vstream statistics. - ************************************************************************/ - AddTOvStats (vStatsDotP, NULL); - AddTOvStats (vStatsStageP, NULL); - AddTOvStats (vStatsCompressP, NULL); - /************************************************************************ - * Validate the current CDF. Don't use `SelectCDF' here because we don't - * want to return NO_MORE_ACCESS if that is the case. - ************************************************************************/ - if (Cur->cdf == NULL) - return NO_CDF_SELECTED; - else - CDF = Cur->cdf; - /************************************************************************ - * If this is a CDF for which access was aborted, simply free the CDF's - * memory. - ************************************************************************/ - if (CDF->magic == ABORTEDid_MAGIC_NUMBER) { - KillAbortedCDF (CDF, Cur); - break; - } - /************************************************************************ - * Get the Vstream statistics for the dotCDF file(s) so far. - ************************************************************************/ - AddTOvStats (vStatsDotP, &CDF->dotCDFvStats); - AddTOvStats (vStatsDotP, &CDF->uDotCDFvStats); - /************************************************************************ - * If the CDF is open read/write, update the dotCDF file to flush out - * the (compressed) data in the staging area.. - ************************************************************************/ - if (CDF->status == READ_WRITE) { - if (!sX(UpdateDotCDF64(CDF),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - } - /************************************************************************ - * If the CDF is compressed... - ************************************************************************/ - if (CDF->uDotFp != NULL) { - /********************************************************************** - * If the CDF is open read/write... - **********************************************************************/ - if (CDF->status == READ_WRITE) { - char pathName[DU_MAX_PATH_LEN+1]; - OFF_T CPRoffset; struct CPRstruct64 CPR; - /******************************************************************** - * First flush the uncompressed dotCDF file. - ********************************************************************/ - if (!FLUSHv64(CDF->uDotFp)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_WRITE_ERROR; - } - /******************************************************************** - * Read the compression parameters from the compressed dotCDF file. - ********************************************************************/ - if (!sX(ReadCCR64(CDF->dotFp,V3_CCR_OFFSET64, - CCR_CPROFFSET,&CPRoffset, - CCR_NULL),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - if (!sX(ReadCPR64(CDF->dotFp,CPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - /******************************************************************** - * Delete the compressed dotCDF file. - ********************************************************************/ - if (!DELETEv64(CDF->dotFp,&vStats)) { - CDF->dotFp = NULL; - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CLOSE_ERROR; - } - CDF->dotFp = NULL; - AddTOvStats (vStatsDotP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "DotCDF..", &vStats); -#endif - /******************************************************************** - * Recreate the compressed dotCDF file. - ********************************************************************/ - BuildFilePath (CDFt, CDF->CDFname, CDF->no_append, - CDF->upper_case_ext, CDF->version_numbers, - INT32_ZERO, pathName); - CDF->dotFp = V_open64 (pathName, WRITE_PLUS_a_mode); - if (CDF->dotFp == NULL) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CREATE_ERROR; - } - /******************************************************************** - * Write the compressed dotCDF file. - ********************************************************************/ - if (!sX(WriteCompressedCDF64(CDF,&CPR,notEMPTY),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - /******************************************************************** - * Close the compressed dotCDF file. - ********************************************************************/ - if (!CLOSEv64(CDF->dotFp,CDF,&vStats)) { - CDF->dotFp = NULL; - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CLOSE_ERROR; - } - CDF->dotFp = NULL; - AddTOvStats (vStatsDotP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "DotCDF..", &vStats); -#endif - /******************************************************************** - * Delete the uncompressed dotCDF file. - ********************************************************************/ - if (!DELETEv64(CDF->uDotFp,&vStats)) { - CDF->uDotFp = NULL; - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CLOSE_ERROR; - } - CDF->uDotFp = NULL; - AddTOvStats (vStatsDotP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "uDotCDF.", &vStats); -#endif - } - else { - /******************************************************************** - * The CDF is open read/only. First close the compressed dotCDF file - * (which has not been changed). - ********************************************************************/ - if (CDF->readOnly) ResetReadOnlyState64(CDF); - if (!CLOSEv64(CDF->dotFp,CDF,&vStats)) { - CDF->dotFp = NULL; - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CLOSE_ERROR; - } - CDF->dotFp = NULL; - AddTOvStats (vStatsDotP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "DotCDF..", &vStats); -#endif - /******************************************************************** - * Delete the uncompressed dotCDF file. - ********************************************************************/ - if (!DELETEv64(CDF->uDotFp,&vStats)) { - CDF->uDotFp = NULL; - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CLOSE_ERROR; - } - CDF->uDotFp = NULL; - AddTOvStats (vStatsDotP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "uDotCDF.", &vStats); -#endif - } - } - else { - /********************************************************************** - * Not compressed - first close the dotCDF file. - **********************************************************************/ - if (CDF->readOnly) ResetReadOnlyState64(CDF); - if (!CLOSEv64(CDF->dotFp,CDF,&vStats)) { - CDF->dotFp = NULL; - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CLOSE_ERROR; - } - CDF->dotFp = NULL; - AddTOvStats (vStatsDotP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "DotCDF..", &vStats); -#endif - /********************************************************************** - * Close the variable files (if a multi-file CDF). - **********************************************************************/ - if (!sX(CloseVarFiles64(CDF),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - } - /************************************************************************ - * Delete staging scratch file. - ************************************************************************/ - if (CDF->stage.fp != NULL) { - if (!DELETEv64(CDF->stage.fp,&vStats)) { - CDF->stage.fp = NULL; - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return SCRATCH_DELETE_ERROR; - } - CDF->stage.fp = NULL; - AddTOvStats (vStatsStageP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "Stage...", &vStats); -#endif - } - /************************************************************************ - * Delete compression scratch file. - ************************************************************************/ - if (CDF->compressFp != NULL) { - if (!DELETEv64(CDF->compressFp,&vStats)) { - CDF->compressFp = NULL; - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return SCRATCH_DELETE_ERROR; - } - CDF->compressFp = NULL; - AddTOvStats (vStatsCompressP, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "Compress", &vStats); -#endif - } - /************************************************************************ - * Free memory used and clear current CDF. - ************************************************************************/ - FreeCDFid (CDF, FALSE); - Cur->cdf = NULL; - ReduceOpenCDFsCount(); - break; - } - /************************************************************************** - * rVAR_/zVAR_ - * Close the current r/zVariable file. - **************************************************************************/ - case rVAR_: - case zVAR_: { - Logical zOp = (Va->item == zVAR_); - struct CDFstruct *CDF; struct VarStruct *Var; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - if (zModeON(CDF)) { - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - } else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - - if (CDF->singleFile) { - sX (SINGLE_FILE_FORMAT, &pStatus); - break; - } - if (Var != NULL) { - if (Var->fp != NULL) { - if (!CLOSEv64(Var->fp,NULL,NULL)) { - Var->fp = NULL; - AbortAccess64 (CDF, UPDATE, noDELETE); - return VAR_CLOSE_ERROR; - } - Var->fp = NULL; - } - else { - if (!sX(VAR_ALREADY_CLOSED,&pStatus)) return pStatus; - } - } - else { - if (!sX(VAR_ALREADY_CLOSED,&pStatus)) return pStatus; - } - break; - } - /************************************************************************** - * Unknown item, must be the next function. - **************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } - } - return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfcon.c b/cdf36_3-dist/src/lib/cdfcon.c deleted file mode 100644 index caff6b9..0000000 --- a/cdf36_3-dist/src/lib/cdfcon.c +++ /dev/null @@ -1,551 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `confirm' operations. -* -* Version 1.5a, 21-Feb-97, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 21-Aug-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 21-Dec-93, J Love CDF V2.4. -* V1.2a 22-Feb-94, J Love Spelling lesson. -* V1.3 19-Dec-94, J Love CDF V2.5. -* V1.3a 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.4 15-May-95, J Love Added . -* V1.4a 8-Jun-95, J Love Added . -* V1.4b 4-Aug-95, J Love CDFexport-related changes. -* V1.5 5-Sep-96, J Love CDF V2.6. -* V1.5a 21-Feb-97, J Love Removed RICE. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* CDFcon. -******************************************************************************/ - -STATICforIDL CDFstatus CDFcon (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ -CDFstatus tStatus, pStatus = CDF_OK; - -switch (Va->item) { - /**************************************************************************** - * CDF_ - ****************************************************************************/ - case CDF_: { - CDFid *id = va_arg (Va->ap, CDFid *); - *id = (CDFid) Cur->cdf; - break; - } - /**************************************************************************** - * CDF_STATUS_ - ****************************************************************************/ - case CDF_STATUS_: { - CDFstatus *status = va_arg (Va->ap, CDFstatus *); - *status = Cur->status; - break; - } - /**************************************************************************** - * CDF_NAME_ - ****************************************************************************/ - case CDF_NAME_: { - struct CDFstruct *CDF; - char *CDFname = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - strcpyX (CDFname, CDF->CDFname, CDF_PATHNAME_LEN); - break; - } - /**************************************************************************** - * CDF_ACCESS_ - * The `SelectCDF' macro returns NO_MORE_ACCESS if that is the case. - ****************************************************************************/ - case CDF_ACCESS_: { - if (Cur->cdf == NULL) return NO_CDF_SELECTED; - if (Cur->cdf->magic == ABORTEDid_MAGIC_NUMBER) return NO_MORE_ACCESS; - break; - } - /**************************************************************************** - * CDF_READONLY_MODE_ - ****************************************************************************/ - case CDF_READONLY_MODE_: { - struct CDFstruct *CDF; - long *mode = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *mode = BOO(CDF->readOnly,READONLYon,READONLYoff); - break; - } - /**************************************************************************** - * CDF_zMODE_ - ****************************************************************************/ - case CDF_zMODE_: { - struct CDFstruct *CDF; - long *mode = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *mode = CDF->zMode; - break; - } - /**************************************************************************** - * CDF_NEGtoPOSfp0_MODE_ - ****************************************************************************/ - case CDF_NEGtoPOSfp0_MODE_: { - struct CDFstruct *CDF; - long *mode = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *mode = BOO(CDF->negToPosFp0,NEGtoPOSfp0on,NEGtoPOSfp0off); - break; - } - /**************************************************************************** - * CDF_DECODING_ - ****************************************************************************/ - case CDF_DECODING_: { - struct CDFstruct *CDF; - long *decoding = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *decoding = CDF->decoding; - break; - } - /**************************************************************************** - * CDF_CACHESIZE_ - ****************************************************************************/ - case CDF_CACHESIZE_: { - struct CDFstruct *CDF; - long *nBuffers = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *nBuffers = (long) CDF->workingCacheSize; - break; - } - /**************************************************************************** - * STAGE_CACHESIZE_ - ****************************************************************************/ - case STAGE_CACHESIZE_: { - struct CDFstruct *CDF; - long *nBuffers = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *nBuffers = (long) CDF->stage.cacheSize; - break; - } - /**************************************************************************** - * COMPRESS_CACHESIZE_ - ****************************************************************************/ - case COMPRESS_CACHESIZE_: { - struct CDFstruct *CDF; - long *nBuffers = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *nBuffers = (long) CDF->compressCacheSize; - break; - } - /**************************************************************************** - * rVAR_CACHESIZE_/zVAR_CACHESIZE_ - ****************************************************************************/ - case rVAR_CACHESIZE_: - case zVAR_CACHESIZE_: { - Logical zOp = (Va->item == zVAR_CACHESIZE_); - struct CDFstruct *CDF; - struct VarStruct *Var; - long *nBuffers = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!CDF->singleFile) { - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *nBuffers = (long) Var->varCacheSize; - } - else - sX (SINGLE_FILE_FORMAT, &pStatus); - break; - } - /**************************************************************************** - * rVAR_/zVAR_ - ****************************************************************************/ - case rVAR_: - case zVAR_: { - Logical zOp = (Va->item == zVAR_); - struct CDFstruct *CDF; - long *varNum = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - *varNum = BOO(zOp,CDF->CURzVarNum,CDF->CURrVarNum); - break; - } - /**************************************************************************** - * rVAR_PADVALUE_/zVAR_PADVALUE_ - ****************************************************************************/ - case rVAR_PADVALUE_: - case zVAR_PADVALUE_: { - Logical zOp = (Va->item == zVAR_PADVALUE_), zVar; - struct CDFstruct *CDF; - Int32 offset, flags; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; -/* - if (!sX(LocateCurrentVar(CDF,zOp,&offset,&zVar,NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } -*/ - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_FLAGS,&flags, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!PADvalueBITset(flags)) sX (NO_PADVALUE_SPECIFIED, &pStatus); - break; - } - /**************************************************************************** - * rVAR_EXISTENCE_/zVAR_EXISTENCE_, confirm the existence of a named variable. - ****************************************************************************/ - case rVAR_EXISTENCE_: - case zVAR_EXISTENCE_: { - Logical zOp = (Va->item == zVAR_EXISTENCE_), zVar; - struct CDFstruct *CDF; - char *varName = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - tStatus = FindVarByName (CDF, varName, NULL, &zVar, NULL); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_VAR: - return tStatus; - default: - AbortAccess (CDF, UPDATE, noDELETE); - return tStatus; - } - if (!zModeON(CDF)) { - if ((zVar && !zOp) || (!zVar && zOp)) return NO_SUCH_VAR; /*Wrong type*/ - } - break; - } - /**************************************************************************** - * rVARs_RECNUMBER_/rVARs_RECCOUNT_/rVARs_RECINTERVAL_ - ****************************************************************************/ - case rVARs_RECNUMBER_: - case rVARs_RECCOUNT_: - case rVARs_RECINTERVAL_: { - struct CDFstruct *CDF; - long *value = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,TRUE)) return ILLEGAL_IN_zMODE; - if (CDF->NrVars == 0) { - if (!sX(NO_VARS_IN_CDF,&pStatus)) return pStatus; - } - switch (Va->item) { - case rVARs_RECNUMBER_: - *value = CDF->rRD.recNumber; - break; - case rVARs_RECCOUNT_: - *value = CDF->rRD.recCount; - break; - case rVARs_RECINTERVAL_: - *value = CDF->rRD.recInterval; - break; - } - break; - } - /**************************************************************************** - * zVAR_RECNUMBER_/zVAR_RECCOUNT_/zVAR_RECINTERVAL_ - ****************************************************************************/ - case zVAR_RECNUMBER_: - case zVAR_RECCOUNT_: - case zVAR_RECINTERVAL_: { - struct CDFstruct *CDF; - struct VarStruct *Var; - long *value = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTvarSELECTED(CDF,TRUE)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar(CDF,TRUE,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (Va->item) { - case zVAR_RECNUMBER_: - *value = Var->zRD.recNumber; - break; - case zVAR_RECCOUNT_: - *value = Var->zRD.recCount; - break; - case zVAR_RECINTERVAL_: - *value = Var->zRD.recInterval; - break; - } - break; - } - /**************************************************************************** - * rVARs_DIMINDICES_/rVARs_DIMCOUNTS_/rVARs_DIMINTERVALS_ - ****************************************************************************/ - case rVARs_DIMINDICES_: - case rVARs_DIMCOUNTS_: - case rVARs_DIMINTERVALS_: { - struct CDFstruct *CDF; int dimN; - long *values = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,TRUE)) return ILLEGAL_IN_zMODE; - if (CDF->NrVars == 0) { - if (!sX(NO_VARS_IN_CDF,&pStatus)) return pStatus; - } - switch (Va->item) { - case rVARs_DIMINDICES_: - for (dimN = 0; dimN < CDF->rNumDims; dimN++) - values[dimN] = CDF->rRD.dimIndices[dimN]; - break; - case rVARs_DIMCOUNTS_: - for (dimN = 0; dimN < CDF->rNumDims; dimN++) - values[dimN] = CDF->rRD.dimCounts[dimN]; - break; - case rVARs_DIMINTERVALS_: - for (dimN = 0; dimN < CDF->rNumDims; dimN++) - values[dimN] = CDF->rRD.dimIntervals[dimN]; - break; - } - break; - } - /**************************************************************************** - * zVAR_DIMINDICES_/zVAR_DIMCOUNTS_/zVAR_DIMINTERVALS_ - ****************************************************************************/ - case zVAR_DIMINDICES_: - case zVAR_DIMCOUNTS_: - case zVAR_DIMINTERVALS_: { - struct CDFstruct *CDF; - struct VarStruct *Var; - int dimN; - long *values = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTvarSELECTED(CDF,TRUE)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar(CDF,TRUE,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (Va->item) { - case zVAR_DIMINDICES_: - for (dimN = 0; dimN < Var->numDims; dimN++) - values[dimN] = Var->zRD.dimIndices[dimN]; - break; - case zVAR_DIMCOUNTS_: - for (dimN = 0; dimN < Var->numDims; dimN++) - values[dimN] = Var->zRD.dimCounts[dimN]; - break; - case zVAR_DIMINTERVALS_: - for (dimN = 0; dimN < Var->numDims; dimN++) - values[dimN] = Var->zRD.dimIntervals[dimN]; - break; - } - break; - } - /**************************************************************************** - * rVAR_SEQPOS_/zVAR_SEQPOS_ - ****************************************************************************/ - case rVAR_SEQPOS_: - case zVAR_SEQPOS_: { - Logical zOp = (Va->item == zVAR_SEQPOS_); - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 indices[CDF_MAX_DIMS]; int dimN; - long *recNumber = va_arg (Va->ap, long *); - long *dimIndices = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *recNumber = (long) (Var->seqValueOffset / Var->NphyRecValues); - ValueOffsetIndices (Var->seqValueOffset % Var->NphyRecValues, - CDF->rowMajor, Var->numDims, Var->dimVarys, - Var->nPhyDimValues, indices); - for (dimN = 0; dimN < Var->numDims; dimN++) { - dimIndices[dimN] = (long) indices[dimN]; - } - break; - } - /**************************************************************************** - * rVAR_RESERVEPERCENT_/zVAR_RESERVEPERCENT_ - ****************************************************************************/ - case rVAR_RESERVEPERCENT_: - case zVAR_RESERVEPERCENT_: { - Logical zOp = (Va->item == zVAR_RESERVEPERCENT_); - struct CDFstruct *CDF; struct VarStruct *Var; - long *pct = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (Var->vType) { - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - *pct = (long) Var->reservePct; - break; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return CDF_INTERNAL_ERROR; - case STANDARD_: - case SPARSE_RECORDS_: - *pct = 0; - sX (NA_FOR_VARIABLE, &pStatus); - break; - case IN_MULTI_: - *pct = 0; - sX (MULTI_FILE_FORMAT, &pStatus); - break; - } - break; - } - /**************************************************************************** - * ATTR_ - ****************************************************************************/ - case ATTR_: { - struct CDFstruct *CDF; Int32 tAttrNum; - long *attrNum = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED(CDF)) return NO_ATTR_SELECTED; - if (!sX(ReadADR(CDF->fp,CDF->CURattrOffset, - ADR_NUM,&tAttrNum, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *attrNum = (long) tAttrNum; - break; - } - /**************************************************************************** - * ATTR_EXISTENCE_, confirms the existence of a named attribute. - ****************************************************************************/ - case ATTR_EXISTENCE_: { - struct CDFstruct *CDF; - char *attrName = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - tStatus = FindAttrByName (CDF, attrName, NULL); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_ATTR: - return tStatus;; - default: - AbortAccess (CDF, UPDATE, noDELETE); - return tStatus; - } - break; - } - /**************************************************************************** - * gENTRY_/rENTRY_/zENTRY_ - ****************************************************************************/ - case rENTRY_: - case gENTRY_: - case zENTRY_: { - Logical zOp = (Va->item == zENTRY_); - struct CDFstruct *CDF; - long *entryNum = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,Va->item==rENTRY_)) return ILLEGAL_IN_zMODE; - if (BOO(zOp,CDF->CURzEntryNum,CDF->CURgrEntryNum) == RESERVED_ENTRYNUM) - return NO_ENTRY_SELECTED; - *entryNum = BOO(zOp,CDF->CURzEntryNum,CDF->CURgrEntryNum); - break; - } - /**************************************************************************** - * gENTRY_EXISTENCE_/rENTRY_EXISTENCE_/zENTRY_EXISTENCE_, confirms the - * existence of a numbered entry for the current attribute. - ****************************************************************************/ - case gENTRY_EXISTENCE_: - case rENTRY_EXISTENCE_: - case zENTRY_EXISTENCE_: { - int entryType = E3p(Va->item,gENTRY_EXISTENCE_, - rENTRY_EXISTENCE_, - zENTRY_EXISTENCE_); - struct CDFstruct *CDF; Logical zEntry; - long entryNum = va_arg (Va->ap, long), entryN; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED(CDF)) return NO_ATTR_SELECTED; - if (!sX(CheckEntryOp(CDF,entryType),&pStatus)) return pStatus; - if (entryNum < 0) return BAD_ENTRY_NUM; - switch (entryType) { - case gENTRYt: - case rENTRYt: - zEntry = FALSE; - entryN = entryNum; - break; - case zENTRYt: - zEntry = BOO(zModeON(CDF),BOO(entryNum < CDF->NrVars,FALSE,TRUE),TRUE); - entryN = BOO(zModeON(CDF),BOO(entryNum < CDF->NrVars,entryNum, - entryNum - CDF->NrVars),entryNum); - break; - } - tStatus = FindEntryByNumber(CDF,CDF->CURattrOffset, - zEntry,(Int32)entryN,NULL); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_ENTRY: - return tStatus; - default: - AbortAccess (CDF, UPDATE, noDELETE); - return tStatus; - } - break; - } - /**************************************************************************** - * CURgENTRY_EXISTENCE_/CURrENTRY_EXISTENCE_/CURzENTRY_EXISTENCE_, confirms - * the existence of the current entry number for the current attribute. - ****************************************************************************/ - case CURgENTRY_EXISTENCE_: - case CURrENTRY_EXISTENCE_: - case CURzENTRY_EXISTENCE_: { - int entryType = E3p(Va->item,CURgENTRY_EXISTENCE_, - CURrENTRY_EXISTENCE_, - CURzENTRY_EXISTENCE_); - struct CDFstruct *CDF; Int32 offset; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED(CDF)) return NO_ATTR_SELECTED; - if (E3(entryType, - CDF->CURgrEntryNum, - CDF->CURgrEntryNum, - CDF->CURzEntryNum) == RESERVED_ENTRYNUM) return NO_ENTRY_SELECTED; - if (!sX(CheckEntryOp(CDF,entryType),&pStatus)) return pStatus; - offset = E3(entryType,CDF->CURgrEntryOffset, - CDF->CURgrEntryOffset, - CDF->CURzEntryOffset); - if (offset == RESERVED_ENTRYOFFSET) return NO_SUCH_ENTRY; - break; - } - /**************************************************************************** - * CDF_CHECKSUM_ - ****************************************************************************/ - case CDF_CHECKSUM_: { - struct CDFstruct *CDF; - SelectCDF (Cur->cdf, CDF) - if (!sX(CDFVerifyChecksum(CDF),&pStatus)) return pStatus; - break; - } - /**************************************************************************** - * Unknown item, must be the next function. - ****************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } -} -return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfcon64.c b/cdf36_3-dist/src/lib/cdfcon64.c deleted file mode 100644 index ceb228b..0000000 --- a/cdf36_3-dist/src/lib/cdfcon64.c +++ /dev/null @@ -1,554 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `confirm' operations. -* -* Version 1.5a, 21-Feb-97, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 21-Aug-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 21-Dec-93, J Love CDF V2.4. -* V1.2a 22-Feb-94, J Love Spelling lesson. -* V1.3 19-Dec-94, J Love CDF V2.5. -* V1.3a 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.4 15-May-95, J Love Added . -* V1.4a 8-Jun-95, J Love Added . -* V1.4b 4-Aug-95, J Love CDFexport-related changes. -* V1.5 5-Sep-96, J Love CDF V2.6. -* V1.5a 21-Feb-97, J Love Removed RICE. -* V2.0 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* CDFcon64. -******************************************************************************/ - -STATICforIDL CDFstatus CDFcon64 (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ -CDFstatus tStatus, pStatus = CDF_OK; - -switch (Va->item) { - /**************************************************************************** - * CDF_ - ****************************************************************************/ - case CDF_: { - CDFid *id = va_arg (Va->ap, CDFid *); - *id = (CDFid) Cur->cdf; - break; - } - /**************************************************************************** - * CDF_STATUS_ - ****************************************************************************/ - case CDF_STATUS_: { - CDFstatus *status = va_arg (Va->ap, CDFstatus *); - *status = Cur->status; - break; - } - /**************************************************************************** - * CDF_NAME_ - ****************************************************************************/ - case CDF_NAME_: { - struct CDFstruct *CDF; - char *CDFname = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - strcpyX (CDFname, CDF->CDFname, CDF_PATHNAME_LEN); - break; - } - /**************************************************************************** - * CDF_ACCESS_ - * The `SelectCDF' macro returns NO_MORE_ACCESS if that is the case. - ****************************************************************************/ - case CDF_ACCESS_: { - if (Cur->cdf == NULL) return NO_CDF_SELECTED; - if (Cur->cdf->magic == ABORTEDid_MAGIC_NUMBER) return NO_MORE_ACCESS; - break; - } - /**************************************************************************** - * CDF_READONLY_MODE_ - ****************************************************************************/ - case CDF_READONLY_MODE_: { - struct CDFstruct *CDF; - long *mode = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *mode = BOO(CDF->readOnly,READONLYon,READONLYoff); - break; - } - /**************************************************************************** - * CDF_zMODE_ - ****************************************************************************/ - case CDF_zMODE_: { - struct CDFstruct *CDF; - long *mode = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *mode = CDF->zMode; - break; - } - /**************************************************************************** - * CDF_NEGtoPOSfp0_MODE_ - ****************************************************************************/ - case CDF_NEGtoPOSfp0_MODE_: { - struct CDFstruct *CDF; - long *mode = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *mode = BOO(CDF->negToPosFp0,NEGtoPOSfp0on,NEGtoPOSfp0off); - break; - } - /**************************************************************************** - * CDF_DECODING_ - ****************************************************************************/ - case CDF_DECODING_: { - struct CDFstruct *CDF; - long *decoding = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *decoding = CDF->decoding; - break; - } - /**************************************************************************** - * CDF_CACHESIZE_ - ****************************************************************************/ - case CDF_CACHESIZE_: { - struct CDFstruct *CDF; - long *nBuffers = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *nBuffers = (long) CDF->workingCacheSize; - break; - } - /**************************************************************************** - * STAGE_CACHESIZE_ - ****************************************************************************/ - case STAGE_CACHESIZE_: { - struct CDFstruct *CDF; - long *nBuffers = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *nBuffers = (long) CDF->stage.cacheSize; - break; - } - /**************************************************************************** - * COMPRESS_CACHESIZE_ - ****************************************************************************/ - case COMPRESS_CACHESIZE_: { - struct CDFstruct *CDF; - long *nBuffers = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *nBuffers = (long) CDF->compressCacheSize; - break; - } - /**************************************************************************** - * rVAR_CACHESIZE_/zVAR_CACHESIZE_ - ****************************************************************************/ - case rVAR_CACHESIZE_: - case zVAR_CACHESIZE_: { - Logical zOp = (Va->item == zVAR_CACHESIZE_); - struct CDFstruct *CDF; - struct VarStruct *Var; - long *nBuffers = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!CDF->singleFile) { - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *nBuffers = (long) Var->varCacheSize; - } - else - sX (SINGLE_FILE_FORMAT, &pStatus); - break; - } - /**************************************************************************** - * rVAR_/zVAR_ - ****************************************************************************/ - case rVAR_: - case zVAR_: { - Logical zOp = (Va->item == zVAR_); - struct CDFstruct *CDF; - long *varNum = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - *varNum = BOO(zOp,CDF->CURzVarNum,CDF->CURrVarNum); - break; - } - /**************************************************************************** - * rVAR_PADVALUE_/zVAR_PADVALUE_ - ****************************************************************************/ - case rVAR_PADVALUE_: - case zVAR_PADVALUE_: { - Logical zOp = (Va->item == zVAR_PADVALUE_), zVar; - struct CDFstruct *CDF; - Int32 flags; - OFF_T offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; -/* - if (!sX(LocateCurrentVar64(CDF,zOp,&offset,&zVar,NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } -*/ - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_FLAGS,&flags, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!PADvalueBITset(flags)) sX (NO_PADVALUE_SPECIFIED, &pStatus); - break; - } - /**************************************************************************** - * rVAR_EXISTENCE_/zVAR_EXISTENCE_, confirm the existence of a named variable. - ****************************************************************************/ - case rVAR_EXISTENCE_: - case zVAR_EXISTENCE_: { - Logical zOp = (Va->item == zVAR_EXISTENCE_), zVar; - struct CDFstruct *CDF; - char *varName = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - tStatus = FindVarByName64 (CDF, varName, NULL, &zVar, NULL); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_VAR: - return tStatus; - default: - AbortAccess64 (CDF, UPDATE, noDELETE); - return tStatus; - } - if (!zModeON(CDF)) { - if ((zVar && !zOp) || (!zVar && zOp)) return NO_SUCH_VAR; /*Wrong type*/ - } - break; - } - /**************************************************************************** - * rVARs_RECNUMBER_/rVARs_RECCOUNT_/rVARs_RECINTERVAL_ - ****************************************************************************/ - case rVARs_RECNUMBER_: - case rVARs_RECCOUNT_: - case rVARs_RECINTERVAL_: { - struct CDFstruct *CDF; - long *value = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,TRUE)) return ILLEGAL_IN_zMODE; - if (CDF->NrVars == 0) { - if (!sX(NO_VARS_IN_CDF,&pStatus)) return pStatus; - } - switch (Va->item) { - case rVARs_RECNUMBER_: - *value = (long) CDF->rRD.recNumber; - break; - case rVARs_RECCOUNT_: - *value = (long) CDF->rRD.recCount; - break; - case rVARs_RECINTERVAL_: - *value = (long) CDF->rRD.recInterval; - break; - } - break; - } - /**************************************************************************** - * zVAR_RECNUMBER_/zVAR_RECCOUNT_/zVAR_RECINTERVAL_ - ****************************************************************************/ - case zVAR_RECNUMBER_: - case zVAR_RECCOUNT_: - case zVAR_RECINTERVAL_: { - struct CDFstruct *CDF; - struct VarStruct *Var; - long *value = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTvarSELECTED(CDF,TRUE)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar64(CDF,TRUE,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (Va->item) { - case zVAR_RECNUMBER_: - *value = Var->zRD.recNumber; - break; - case zVAR_RECCOUNT_: - *value = Var->zRD.recCount; - break; - case zVAR_RECINTERVAL_: - *value = Var->zRD.recInterval; - break; - } - break; - } - /**************************************************************************** - * rVARs_DIMINDICES_/rVARs_DIMCOUNTS_/rVARs_DIMINTERVALS_ - ****************************************************************************/ - case rVARs_DIMINDICES_: - case rVARs_DIMCOUNTS_: - case rVARs_DIMINTERVALS_: { - struct CDFstruct *CDF; int dimN; - long *values = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,TRUE)) return ILLEGAL_IN_zMODE; - if (CDF->NrVars == 0) { - if (!sX(NO_VARS_IN_CDF,&pStatus)) return pStatus; - } - switch (Va->item) { - case rVARs_DIMINDICES_: - for (dimN = 0; dimN < CDF->rNumDims; dimN++) - values[dimN] = (long) CDF->rRD.dimIndices[dimN]; - break; - case rVARs_DIMCOUNTS_: - for (dimN = 0; dimN < CDF->rNumDims; dimN++) - values[dimN] = (long) CDF->rRD.dimCounts[dimN]; - break; - case rVARs_DIMINTERVALS_: - for (dimN = 0; dimN < CDF->rNumDims; dimN++) - values[dimN] = (long) CDF->rRD.dimIntervals[dimN]; - break; - } - break; - } - /**************************************************************************** - * zVAR_DIMINDICES_/zVAR_DIMCOUNTS_/zVAR_DIMINTERVALS_ - ****************************************************************************/ - case zVAR_DIMINDICES_: - case zVAR_DIMCOUNTS_: - case zVAR_DIMINTERVALS_: { - struct CDFstruct *CDF; - struct VarStruct *Var; - int dimN; - long *values = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTvarSELECTED(CDF,TRUE)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar64(CDF,TRUE,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (Va->item) { - case zVAR_DIMINDICES_: - for (dimN = 0; dimN < Var->numDims; dimN++) - values[dimN] = Var->zRD.dimIndices[dimN]; - break; - case zVAR_DIMCOUNTS_: - for (dimN = 0; dimN < Var->numDims; dimN++) - values[dimN] = Var->zRD.dimCounts[dimN]; - break; - case zVAR_DIMINTERVALS_: - for (dimN = 0; dimN < Var->numDims; dimN++) - values[dimN] = Var->zRD.dimIntervals[dimN]; - break; - } - break; - } - /**************************************************************************** - * rVAR_SEQPOS_/zVAR_SEQPOS_ - ****************************************************************************/ - case rVAR_SEQPOS_: - case zVAR_SEQPOS_: { - Logical zOp = (Va->item == zVAR_SEQPOS_); - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 indices[CDF_MAX_DIMS]; int dimN; - long *recNumber = va_arg (Va->ap, long *); - long *dimIndices = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *recNumber = (long) (Var->seqValueOffset64 / (OFF_T) Var->NphyRecValues); - ValueOffsetIndices ((Int32) (Var->seqValueOffset64 % - (OFF_T) Var->NphyRecValues), - CDF->rowMajor, Var->numDims, Var->dimVarys, - Var->nPhyDimValues, indices); - for (dimN = 0; dimN < Var->numDims; dimN++) { - dimIndices[dimN] = (long) indices[dimN]; - } - break; - } - /**************************************************************************** - * rVAR_RESERVEPERCENT_/zVAR_RESERVEPERCENT_ - ****************************************************************************/ - case rVAR_RESERVEPERCENT_: - case zVAR_RESERVEPERCENT_: { - Logical zOp = (Va->item == zVAR_RESERVEPERCENT_); - struct CDFstruct *CDF; struct VarStruct *Var; - long *pct = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (Var->vType) { - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - *pct = (long) Var->reservePct; - break; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return CDF_INTERNAL_ERROR; - case STANDARD_: - case SPARSE_RECORDS_: - *pct = 0; - sX (NA_FOR_VARIABLE, &pStatus); - break; - case IN_MULTI_: - *pct = 0; - sX (MULTI_FILE_FORMAT, &pStatus); - break; - } - break; - } - /**************************************************************************** - * ATTR_ - ****************************************************************************/ - case ATTR_: { - struct CDFstruct *CDF; Int32 tAttrNum; - long *attrNum = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED64(CDF)) return NO_ATTR_SELECTED; - if (!sX(ReadADR64(CDF->fp,CDF->CURattrOffset64, - ADR_NUM,&tAttrNum, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *attrNum = (long) tAttrNum; - break; - } - /**************************************************************************** - * ATTR_EXISTENCE_, confirms the existence of a named attribute. - ****************************************************************************/ - case ATTR_EXISTENCE_: { - struct CDFstruct *CDF; - char *attrName = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - tStatus = FindAttrByName64 (CDF, attrName, NULL); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_ATTR: - return tStatus;; - default: - AbortAccess64 (CDF, UPDATE, noDELETE); - return tStatus; - } - break; - } - /**************************************************************************** - * gENTRY_/rENTRY_/zENTRY_ - ****************************************************************************/ - case rENTRY_: - case gENTRY_: - case zENTRY_: { - Logical zOp = (Va->item == zENTRY_); - struct CDFstruct *CDF; - long *entryNum = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,Va->item==rENTRY_)) return ILLEGAL_IN_zMODE; - if (BOO(zOp,CDF->CURzEntryNum,CDF->CURgrEntryNum) == RESERVED_ENTRYNUM) - return NO_ENTRY_SELECTED; - *entryNum = BOO(zOp,CDF->CURzEntryNum,CDF->CURgrEntryNum); - break; - } - /**************************************************************************** - * gENTRY_EXISTENCE_/rENTRY_EXISTENCE_/zENTRY_EXISTENCE_, confirms the - * existence of a numbered entry for the current attribute. - ****************************************************************************/ - case gENTRY_EXISTENCE_: - case rENTRY_EXISTENCE_: - case zENTRY_EXISTENCE_: { - int entryType = E3p(Va->item,gENTRY_EXISTENCE_, - rENTRY_EXISTENCE_, - zENTRY_EXISTENCE_); - struct CDFstruct *CDF; Logical zEntry; - long entryNum = va_arg (Va->ap, long), entryN; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED64(CDF)) return NO_ATTR_SELECTED; - if (!sX(CheckEntryOp64(CDF,entryType),&pStatus)) return pStatus; - if (entryNum < 0) return BAD_ENTRY_NUM; - switch (entryType) { - case gENTRYt: - case rENTRYt: - zEntry = FALSE; - entryN = entryNum; - break; - case zENTRYt: - zEntry = BOO(zModeON(CDF),BOO(entryNum < CDF->NrVars,FALSE,TRUE),TRUE); - entryN = BOO(zModeON(CDF),BOO(entryNum < CDF->NrVars,entryNum, - entryNum - CDF->NrVars),entryNum); - break; - } - tStatus = FindEntryByNumber64(CDF,CDF->CURattrOffset64, - zEntry,(Int32)entryN,NULL); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_ENTRY: - return tStatus; - default: - AbortAccess64 (CDF, UPDATE, noDELETE); - return tStatus; - } - break; - } - /**************************************************************************** - * CURgENTRY_EXISTENCE_/CURrENTRY_EXISTENCE_/CURzENTRY_EXISTENCE_, confirms - * the existence of the current entry number for the current attribute. - ****************************************************************************/ - case CURgENTRY_EXISTENCE_: - case CURrENTRY_EXISTENCE_: - case CURzENTRY_EXISTENCE_: { - int entryType = E3p(Va->item,CURgENTRY_EXISTENCE_, - CURrENTRY_EXISTENCE_, - CURzENTRY_EXISTENCE_); - struct CDFstruct *CDF; OFF_T offset; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED64(CDF)) return NO_ATTR_SELECTED; - if (E3(entryType, - CDF->CURgrEntryNum, - CDF->CURgrEntryNum, - CDF->CURzEntryNum) == RESERVED_ENTRYNUM) return NO_ENTRY_SELECTED; - if (!sX(CheckEntryOp64(CDF,entryType),&pStatus)) return pStatus; - offset = E3(entryType,CDF->CURgrEntryOffset64, - CDF->CURgrEntryOffset64, - CDF->CURzEntryOffset64); - if (offset == (OFF_T) RESERVED_ENTRYOFFSET64) return NO_SUCH_ENTRY; - break; - } - /**************************************************************************** - * CDF_CHECKSUM_ - ****************************************************************************/ - case CDF_CHECKSUM_: { - struct CDFstruct *CDF; - SelectCDF (Cur->cdf, CDF) - if (!sX(CDFVerifyChecksum(CDF),&pStatus)) return pStatus; - break; - } - /**************************************************************************** - * Unknown item, must be the next function. - ****************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } -} -return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfcre.c b/cdf36_3-dist/src/lib/cdfcre.c deleted file mode 100644 index a15599b..0000000 --- a/cdf36_3-dist/src/lib/cdfcre.c +++ /dev/null @@ -1,642 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `create' operations. -* -* Version 1.5b, 20-Oct-97, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 29-Sep-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 24-Jan-94, J Love CDF V2.4. Added readonly mode. -* V1.3 15-Dec-94, J Love CDF V2.5. -* V1.3a 9-Jan-95, J Love Encode/decode changes. More cache-residency. -* V1.3b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.4 21-Mar-95, J Love POSIX. -* V1.4a 7-Sep-95, J Love CDFexport-related changes. Fixed cleanup when -* a CDF is aborted. -* V1.5 15-Aug-96, J Love CDF V2.6. -* V1.5a 21-Feb-97, J Love Removed RICE. -* V1.5b 11-Sep-97, J Love Magic numbers are now uInt32. -* V1.5c 20-Oct-97, J Love Properly cast the uInt32 magic numbers. -* V1.6 8-Apr-04, M Liu Save the currently created variable's offset. -* V1.7 13-Oct-06, M Liu Changed to allow upper and lower case CDF -* name to be used on win32. -* V3.5 23-Jul-13, M Liu Changed the alternative encoding to IBMPC. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" -#include "cdfrev.h" - -/****************************************************************************** -* CDFcre. -******************************************************************************/ - -STATICforIDL CDFstatus CDFcre (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ -CDFstatus tStatus, pStatus = CDF_OK; - -switch (Va->item) { - /**************************************************************************** - * CDF_, create a new CDF. - ****************************************************************************/ - case CDF_: { - long numDims, *dimSizes; - char CDFnameT[CDF_PATHNAME_LEN+1], CDFnameX[DU_MAX_PATH_LEN+1], *CDFnameP; - char CDFnameTx[CDF_PATHNAME_LEN+1]; - char copyRight[CDF_COPYRIGHT_LEN+1]; - CDFid *id; - struct CDFstruct *CDF; - struct CDRstruct CDR; - struct GDRstruct GDR; - vFILE *dotFp; - int dimN; -#if defined(vms) || defined(dos) - Logical upper_case_ext = TRUE; -#else /* Unix, POSIX, & Macintosh */ - Logical upper_case_ext = FALSE; -#endif - Logical version_numbers = FALSE; - Logical no_append = FALSE; - uInt32 magicNumber1 = V2magicNUMBER_1; - uInt32 magicNumber2u = V2magicNUMBER_2u; - char *del = NULL; - /************************************************************************** - * Get arguments for this operation/item. - **************************************************************************/ - CDFnameP = va_arg (Va->ap, char *); - numDims = va_arg (Va->ap, long); - dimSizes = va_arg (Va->ap, long *); - id = va_arg (Va->ap, CDFid *); - *id = (CDFid) NULL; - /************************************************************************** - * Validate arguments. - **************************************************************************/ -#if BUILD_READ_ONLY_DISTRIBUTION - if (!sX(READ_ONLY_DISTRIBUTION,&pStatus)) return pStatus; -#endif - if (numDims < 0 || numDims > CDF_MAX_DIMS) return BAD_NUM_DIMS; - for (dimN = 0; dimN < numDims; dimN++) { - if (dimSizes[dimN] < 1) return BAD_DIM_SIZE; - } - if (strlen(CDFnameP) > (size_t) CDF_PATHNAME_LEN) { - if (!sX(CDF_NAME_TRUNC,&pStatus)) return pStatus; - } - strcpyX (CDFnameT, CDFnameP, CDF_PATHNAME_LEN); -#if STRIP_TRAILING_BLANKS_FROM_CDFPATH - StripTrailingBlanks (CDFnameT); -#endif -#if defined(vms) || defined(dos) - MakeUpperString (CDFnameT); -#endif - RemoveCDFFileExtension(CDFnameT, CDFnameTx); -#if defined(unix) || defined(win32) || defined(dos) -# if defined(unix) - del = strrchr(CDFnameTx, '/'); -# else - del = strrchr(CDFnameTx, '\\'); - if (del == NULL) { -# if defined(win32) - del = strrchr(CDFnameTx, '/'); -# endif - } -# endif - if (del == NULL) { - if (!ValidCDFname(CDFnameTx)) return BAD_CDF_NAME; - } else { - if (!ValidCDFname(del+1)) return BAD_CDF_NAME; - } -#else - if (!ValidCDFname(CDFnameTx)) return BAD_CDF_NAME; -#endif - BuildFilePath (CDFt, CDFnameTx, no_append, upper_case_ext, version_numbers, - INT32_ZERO, CDFnameX); - if (IsReg(CDFnameX)) return CDF_EXISTS; - /************************************************************************** - * Create CDF file. - **************************************************************************/ - dotFp = V_open (CDFnameX, WRITE_PLUS_a_mode); - if (dotFp == NULL) return CDF_CREATE_ERROR; - /************************************************************************** - * Allocate/initialize CDF structure. - **************************************************************************/ - CDF = (struct CDFstruct *) cdf_AllocateMemory ((size_t)sizeof(struct CDFstruct), NULL); - if (CDF == NULL) { - V_close (dotFp, NULL, NULL); - CDFdeleteFile (CDFnameX); - return BAD_MALLOC; - } - CDF->CDFname = (char *) cdf_AllocateMemory ((size_t)strlen(CDFnameTx) + 1, NULL); - if (CDF->CDFname == NULL) { - V_close (dotFp, NULL, NULL); - CDFdeleteFile (CDFnameX); - cdf_FreeMemory (CDF, NULL); - return BAD_MALLOC; - } - else - strcpyX (CDF->CDFname, CDFnameTx, 0); - CDF->magic = VALIDid_MAGIC_NUMBER; - CDF->largeFile = FALSE; - CDF->CDRoffset = V2_CDR_OFFSET; - CDF->GDRoffset = NO_OFFSET; /* Reset below when GDR is written. */ - CDF->readOnly = FALSE; - CDF->zMode = zMODEoff; - CDF->decoding = HOST_DECODING; - CDF->negToPosFp0 = FALSE; - CDF->status = READ_WRITE; - CDF->dotFp = dotFp; - CDF->uDotFp = NULL; - CDF->fp = dotFp; - CDF->pseudo_clock = 0; - CDF->upper_case_ext = upper_case_ext; - CDF->version_numbers = version_numbers; - CDF->no_append = no_append; - CDF->fakeEPOCH = FALSE; - CDF->wastedSpace = FALSE; - CDF->badEOF = FALSE; - CDF->badTerminatingOffsets = FALSE; - CDF->assumedScopes = FALSE; - CDF->NrVars = 0; - CDF->NzVars = 0; - CDF->MAXrVars = 0; - CDF->MAXzVars = 0; - CDF->rVars = NULL; - CDF->zVars = NULL; - CDF->encoding = BOO(DEFAULT_TO_HOST_ENCODING, - HostEncoding(),IBMPC_ENCODING); - CDF->rowMajor = DEFAULT_TO_ROW_MAJOR; - CDF->singleFile = DEFAULT_TO_SINGLE_FILE; - CDF->rMaxRec = NO_RECORD; - CDF->rNumDims = numDims; - for (dimN = 0; dimN < numDims; dimN++) { - CDF->rDimSizes[dimN] = dimSizes[dimN]; - } - CDF->stage.fp = NULL; - CDF->stage.mark = ZERO_OFFSET; - CDF->stage.cacheSize = NUMcacheSTAGE; - CDF->compressFp = NULL; - CDF->scratchDir = NULL; - CDF->workingCacheSize = BOO(CDF->singleFile,NUMcacheSINGLE,NUMcacheMULTI); - CDF->compressCacheSize = NUMcacheCOMPRESS; - CDF->checksum = BOO(CDFgetChecksumEnvVar()<=0,NONE_CHECKSUM,MD5_CHECKSUM); - InitCURobjectsStates (CDF); - AddTOvStats (&CDF->dotCDFvStats, NULL); - AddTOvStats (&CDF->uDotCDFvStats, NULL); - /************************************************************************** - * Set number of cache buffers based on the CDF's format. - **************************************************************************/ - if (!CACHEv(CDF->fp,CDF->workingCacheSize)) { - AbortAccess (CDF, noUPDATE, CDFDELETE); - cdf_FreeMemory (CDF, NULL); - return BAD_CACHE_SIZE; - } - /************************************************************************** - * Write magic numbers. - **************************************************************************/ - if (!Write32(CDF->fp,(Int32 *)&magicNumber1)) { - AbortAccess (CDF, noUPDATE, CDFDELETE); - cdf_FreeMemory (CDF, NULL); - return CDF_WRITE_ERROR; - } - if (!Write32(CDF->fp,(Int32 *)&magicNumber2u)) { - AbortAccess (CDF, noUPDATE, CDFDELETE); - cdf_FreeMemory (CDF, NULL); - return CDF_WRITE_ERROR; - } - /************************************************************************** - * Write CDR. - **************************************************************************/ - CDR.RecordSize = CDR_BASE_SIZE + CDF_COPYRIGHT_LEN; - CDR.RecordType = CDR_; - CDR.GDRoffset = CDF->CDRoffset + CDR.RecordSize; - if (CDFgetFileBackward()) { - CDR.Version = 2; - CDR.Release = 7; - CDR.Increment = 2; - } else { - CDR.Version = CDF_LIBRARY_VERSION; - CDR.Release = CDF_LIBRARY_RELEASE; - CDR.Increment = CDF_LIBRARY_INCREMENT; - } - CDR.Encoding = CDF->encoding; - CDR.Flags = 0; - if (CDF->rowMajor) SetBit32 (&(CDR.Flags), CDR_MAJORITY_BIT); - if (CDF->singleFile) SetBit32 (&(CDR.Flags), CDR_FORMAT_BIT); - CDR.rfuA = 0; - CDR.rfuB = 0; - CDR.rfuD = -1; - CDR.rfuE = -1; - CDFcopyRight (copyRight); - NulPad (copyRight, CDF_COPYRIGHT_LEN); - if (!sX(WriteCDR(CDF->fp,V2_CDR_OFFSET, - CDR_RECORD,&CDR,copyRight, - CDR_NULL),&pStatus)) { - AbortAccess (CDF, noUPDATE, CDFDELETE); - cdf_FreeMemory (CDF, NULL); - return pStatus; - } - /************************************************************************** - * Write GDR. - **************************************************************************/ - CDF->GDRoffset = CDR.GDRoffset; - GDR.RecordSize = GDR_BASE_SIZE + (numDims * sizeof(Int32)); - GDR.RecordType = GDR_; - GDR.rVDRhead = 0; - GDR.zVDRhead = 0; - GDR.ADRhead = 0; - GDR.eof = CDR.GDRoffset + GDR.RecordSize; - GDR.NrVars = CDF->NrVars; - GDR.NumAttr = 0; - GDR.rMaxRec = CDF->rMaxRec; - GDR.rNumDims = CDF->rNumDims; - GDR.NzVars = CDF->NzVars; - GDR.UIRhead = 0; - GDR.rfuC = 0; - GDR.rfuD = -1; - GDR.rfuE = -1; - for (dimN = 0; dimN < CDF->rNumDims; dimN++) { - GDR.rDimSizes[dimN] = CDF->rDimSizes[dimN]; - } - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - GDR_RECORD,&GDR, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, noUPDATE, CDFDELETE); - cdf_FreeMemory (CDF, NULL); - return pStatus; - } - /************************************************************************** - * Select current CDF and pass back CDFid. - **************************************************************************/ - Cur->cdf = CDF; - *id = (CDFid) CDF; - if (CDF->checksum > 0) { - if (!sX(CDFsetChecksum(*id, CDF->checksum),&pStatus)) return pStatus; - } - break; - } - - /**************************************************************************** - * rVAR_/zVAR_, create a new variable. - ****************************************************************************/ - - case rVAR_: - case zVAR_: { - Logical zOp = (Va->item == zVAR_); - long *numOut, zNumDims, *zDimSizes, recVariance, - *dimVariances, newVarNum, numDims; - char *name, Tname[CDF_VAR_NAME_LEN+1], pathnameX[DU_MAX_PATH_LEN+1]; - struct CDFstruct *CDF; - struct VDRstruct VDR; - struct VarStruct ***vars; - vFILE *varFp; - Int32 offset, ntlOffset, VDRhead, nVars; - Int32 dataType, numElements; - int dimN, *max; - Int32 padSize, toPad; - void *pad; - name = va_arg (Va->ap, char *); - dataType = (Int32) va_arg (Va->ap, long); - numElements = (Int32) va_arg (Va->ap, long); - if (zOp) { - zNumDims = va_arg (Va->ap, long); - zDimSizes = va_arg (Va->ap, long *); - } - recVariance = va_arg (Va->ap, long); - dimVariances = va_arg (Va->ap, long *); - numOut = va_arg (Va->ap, long *); - /************************************************************************** - * Get current CDF. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - /************************************************************************** - * Read GDR fields. - **************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - BOO(zOp,GDR_zVDRHEAD,GDR_rVDRHEAD),&VDRhead, - BOO(zOp,GDR_NzVARS,GDR_NrVARS),&nVars, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Validate arguments. - **************************************************************************/ - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!ValidDataType(dataType) || InValidDataType(dataType)) - return BAD_DATA_TYPE; - if (numElements < 1) return BAD_NUM_ELEMS; - if (!STRINGdataType(dataType) && numElements != 1) return BAD_NUM_ELEMS; - if (zOp) { - if (zNumDims < 0 || zNumDims > CDF_MAX_DIMS) return BAD_NUM_DIMS; - for (dimN = 0; dimN < zNumDims; dimN++) - if (zDimSizes[dimN] < 1) return BAD_DIM_SIZE; - } - if (strlen(name) > (size_t) CDF_VAR_NAME_LEN) { - if (!sX(VAR_NAME_TRUNC,&pStatus)) return pStatus; - } - strcpyX (Tname, name, CDF_VAR_NAME_LEN); -#if LIMITof64K - if (TOObigIBMpc(CDFelemSize(dataType)*numElements)) return IBM_PC_OVERFLOW; -#endif - if (!ValidVarName(Tname)) return BAD_VAR_NAME; - tStatus = FindVarByName (CDF, Tname, NULL, NULL, NULL); - switch (tStatus) { - case NO_SUCH_VAR: - break; - case CDF_OK: - return VAR_EXISTS; - default: - AbortAccess (CDF, UPDATE, noDELETE); - return tStatus; - } - newVarNum = nVars; - nVars++; -#if defined(dos) - if (!CDF->singleFile && newVarNum > 99) return TOO_MANY_VARS; -#endif - /************************************************************************** - * Switch to read-write access if necessary. - **************************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Allocate initial/additional pointers to variable data structures. - **************************************************************************/ - max = BOO(zOp,&(CDF->MAXzVars),&(CDF->MAXrVars)); - vars = BOO(zOp,&(CDF->zVars),&(CDF->rVars)); - if (newVarNum >= *max) { - int newMaxVars = (int) (VARs_INCREMENT * ((newVarNum/VARs_INCREMENT)+1)); - int varN; - size_t nBytes = newMaxVars * sizeof(struct VarStruct *); - void *ptr; - if (*max > 0) - ptr = (struct VarStruct **) cdf_ReallocateMemory (*vars, nBytes, NULL); - else - ptr = (struct VarStruct **) cdf_AllocateMemory ((size_t)nBytes, NULL); - if (ptr == NULL) return BAD_MALLOC; - *vars = ptr; - for (varN = *max; varN < newMaxVars; varN++) (*vars)[varN] = NULL; - *max = newMaxVars; - } - /************************************************************************** - * Create variable file (if multi-file CDF). - **************************************************************************/ - if (!CDF->singleFile) { - BuildFilePath (BOO(zOp,Zt,Vt), CDF->CDFname, CDF->no_append, - CDF->upper_case_ext, CDF->version_numbers, - (Int32) newVarNum, pathnameX); - varFp = V_open (pathnameX, WRITE_PLUS_a_mode); - if (varFp == NULL) { - if (!sX(CloseLRUvar(CDF),&pStatus)) return pStatus; - varFp = V_open (pathnameX, WRITE_PLUS_a_mode); - if (varFp == NULL) return VAR_CREATE_ERROR; - } - if (!CLOSEv(varFp,NULL, NULL)) { - CDFdeleteFile (pathnameX); - return VAR_CREATE_ERROR; - } - } - /************************************************************************** - * Write rVDR/zVDR. - **************************************************************************/ - VDR.RecordSize = BOO(zOp,zVDR_BASE_SIZE,rVDR_BASE_SIZE) + - BOO(zOp,zNumDims,0)*sizeof(Int32) + /*DimSizes.*/ - BOO(zOp,zNumDims, - CDF->rNumDims)*sizeof(Int32); /*DimVarys.*/ - VDR.RecordType = BOO(zOp,zVDR_,rVDR_); - VDR.VDRnext = 0; - VDR.DataType = dataType; - VDR.MaxRec = NO_RECORD; - VDR.VXRhead = 0; - VDR.VXRtail = 0; - VDR.Flags = 0; - if (recVariance) SetBit32 (&(VDR.Flags), VDR_RECVARY_BIT); - VDR.sRecords = NO_SPARSERECORDS; - VDR.rfuB = 0; - VDR.rfuC = -1; - VDR.rfuF = -1; - VDR.NumElems = numElements; - VDR.Num = newVarNum; - VDR.CPRorSPRoffset = NO_OFFSET; - VDR.blockingFactor = 0; - strcpyX (VDR.Name, Tname, CDF_VAR_NAME_LEN); - NulPad (VDR.Name, CDF_VAR_NAME_LEN); - if (zOp) { - VDR.zNumDims = zNumDims; - for (dimN = 0; dimN < zNumDims; dimN++) - VDR.zDimSizes[dimN] = zDimSizes[dimN]; - } - for (dimN = 0, numDims = BOO(zOp,zNumDims,CDF->rNumDims); - dimN < numDims; dimN++) { - VDR.DimVarys[dimN] = BOO(dimVariances[dimN],VARY,NOVARY); - } - padSize = (int) (CDFelemSize(dataType) * numElements); - pad = (void *) cdf_AllocateMemory((size_t)padSize, NULL); - if (!sX(AllocateIR(CDF,VDR.RecordSize+padSize,&offset),&pStatus)) { - CDFdeleteFile (pathnameX); - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - toPad = VDR.RecordSize; - DefaultPadValuePre350(dataType, numElements, pad); - VDR.RecordSize += padSize; - SetBit32 (&VDR.Flags,VDR_PADVALUE_BIT); - if (!sX(WriteVDR(CDF,CDF->fp,offset,zOp, - VDR_RECORD,&VDR,pad, - VDR_NULL),&pStatus)) { - CDFdeleteFile (pathnameX); - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - cdf_FreeMemory (pad, NULL); - /************************************************************************** - * Point next-to-last rVDR/zVDR (or GDR) to this rVDR/zVDR. - **************************************************************************/ - if (newVarNum != 0) { - if (!sX(FindVarByNumber(CDF,(Int32)(newVarNum-1), - zOp,&ntlOffset),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteVDR(CDF,CDF->fp,ntlOffset,zOp, - VDR_VDRNEXT,&offset, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - else - VDRhead = offset; - /************************************************************************** - * Update GDR fields that may have been modified. - **************************************************************************/ - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - BOO(zOp,GDR_zVDRHEAD,GDR_rVDRHEAD),&VDRhead, - BOO(zOp,GDR_NzVARS,GDR_NrVARS),&nVars, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Update the appropriate variable count held in memory for efficiency. - **************************************************************************/ - if (zOp) - CDF->NzVars = nVars; - else - CDF->NrVars = nVars; - /************************************************************************** - * Select current variable and determine variable number to be passed back - * (based on zMode). - **************************************************************************/ - if (zModeON(CDF)) { - long varN = CDF->NrVars + newVarNum; - CDF->CURzVarNum = varN; - CDF->CURzVarOffset = offset; - *numOut = varN; - } - else { - if (zOp) { - CDF->CURzVarNum = newVarNum; - CDF->CURzVarOffset = offset; - } else { - CDF->CURrVarNum = newVarNum; - CDF->CURrVarOffset = offset; - } - *numOut = newVarNum; - } - break; - } - /**************************************************************************** - * ATTR_, - ****************************************************************************/ - case ATTR_: { - long *attrNumOut, scope; - char *attrName, truncName[CDF_ATTR_NAME_LEN+1]; - struct CDFstruct *CDF; - struct ADRstruct ADR; - Int32 offset, numAttr, ADRhead; - /************************************************************************** - * Get arguments for this operation/item. - **************************************************************************/ - attrName = va_arg (Va->ap, char *); - scope = va_arg (Va->ap, long); - attrNumOut = va_arg (Va->ap, long *); - /************************************************************************** - * Select current CDF. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - /************************************************************************** - * Validate arguments. - **************************************************************************/ - if (!ValidAttrScope((Int32)scope)) return BAD_SCOPE; - if (strlen(attrName) > (size_t) CDF_ATTR_NAME_LEN) { - if (!sX(ATTR_NAME_TRUNC,&pStatus)) return pStatus; - } - strcpyX (truncName, attrName, CDF_ATTR_NAME_LEN); - if (!ValidAttrName(truncName)) return BAD_ATTR_NAME; - tStatus = FindAttrByName (CDF, truncName, NULL); - switch (tStatus) { - case NO_SUCH_ATTR: - break; - case CDF_OK: - return ATTR_EXISTS; - default: - AbortAccess (CDF, UPDATE, noDELETE); - return tStatus; - } - /************************************************************************** - * Switch to read-write access if necessary. - **************************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Read GDR fields. - **************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_NUMATTR,&numAttr, - GDR_ADRHEAD,&ADRhead, - GDR_NULL),&pStatus)) return pStatus; - /************************************************************************** - * Write ADR. - **************************************************************************/ - ADR.RecordSize = ADR_BASE_SIZE; - ADR.RecordType = ADR_; - ADR.ADRnext = 0; - ADR.AgrEDRhead = 0; - ADR.Scope = scope; - ADR.Num = numAttr; - ADR.NgrEntries = 0; - ADR.MAXgrEntry = NO_ENTRY; - ADR.rfuA = 0; - ADR.AzEDRhead = 0; - ADR.NzEntries = 0; - ADR.MAXzEntry = NO_ENTRY; - ADR.rfuE = -1; - strcpyX (ADR.Name, truncName, CDF_ATTR_NAME_LEN); - NulPad (ADR.Name, CDF_ATTR_NAME_LEN); - if (!sX(AllocateIR(CDF,ADR.RecordSize,&offset),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteADR(CDF->fp,offset, - ADR_RECORD,&ADR, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Point last ADR (or GDR) to this ADR. - **************************************************************************/ - if (numAttr == 0) - ADRhead = offset; - else { - Int32 lastOffset; - if (!sX(FindLastAttr(CDF,&lastOffset),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteADR(CDF->fp,lastOffset, - ADR_ADRNEXT,&offset, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Update GDR fields. - **************************************************************************/ - numAttr++; - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - GDR_NUMATTR,&numAttr, - GDR_ADRHEAD,&ADRhead, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Select current attribute and entry offsets and pass back attribute - * number. - **************************************************************************/ - CDF->CURattrOffset = offset; - CDF->CURgrEntryOffset = RESERVED_ENTRYOFFSET; - CDF->CURzEntryOffset = RESERVED_ENTRYOFFSET; - *attrNumOut = ADR.Num; - break; - } - /**************************************************************************** - * Unknown item, must be the next function. - ****************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } -} -return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfcre64.c b/cdf36_3-dist/src/lib/cdfcre64.c deleted file mode 100644 index 46702aa..0000000 --- a/cdf36_3-dist/src/lib/cdfcre64.c +++ /dev/null @@ -1,652 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `create' operations. -* -* Version 1.5b, 20-Oct-97, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 29-Sep-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 24-Jan-94, J Love CDF V2.4. Added readonly mode. -* V1.3 15-Dec-94, J Love CDF V2.5. -* V1.3a 9-Jan-95, J Love Encode/decode changes. More cache-residency. -* V1.3b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.4 21-Mar-95, J Love POSIX. -* V1.4a 7-Sep-95, J Love CDFexport-related changes. Fixed cleanup when -* a CDF is aborted. -* V1.5 15-Aug-96, J Love CDF V2.6. -* V1.5a 21-Feb-97, J Love Removed RICE. -* V1.5b 11-Sep-97, J Love Magic numbers are now uInt32. -* V1.5c 20-Oct-97, J Love Properly cast the uInt32 magic numbers. -* V1.6 8-Apr-04, M Liu Save the currently created variable's offset. -* V2.0 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* V2.1 13-Oct-06, M Liu Changed to allow upper and lower case CDF -* name to be used on win32. -* V3.5 23-Jul-13, M Liu Changed to alternative encoding to IBMPC. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" -#include "cdfrev.h" - -/****************************************************************************** -* CDFcre64. -******************************************************************************/ - -STATICforIDL CDFstatus CDFcre64 (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ -CDFstatus tStatus, pStatus = CDF_OK; - -switch (Va->item) { - /**************************************************************************** - * CDF_, create a new CDF. - ****************************************************************************/ - case CDF_: { - long numDims, *dimSizes; - char CDFnameT[CDF_PATHNAME_LEN+1], CDFnameX[DU_MAX_PATH_LEN+1], - *CDFnameP; - char copyRight[CDF_COPYRIGHT_LEN+1]; - CDFid *id; - struct CDFstruct *CDF; - struct CDRstruct64 CDR; - struct GDRstruct64 GDR; - vFILE *dotFp; - int dimN; -#if defined(vms) || defined(dos) - Logical upper_case_ext = TRUE; -#else /* Unix, POSIX, win32 & Macintosh */ - Logical upper_case_ext = FALSE; -#endif - Logical version_numbers = FALSE; - Logical no_append = FALSE; - uInt32 magicNumber1 = V3magicNUMBER_1; - uInt32 magicNumber2u = V3magicNUMBER_2u; - char CDFnamePx[CDF_PATHNAME_LEN+1]; - char *del = NULL; - long year, month, day; - /************************************************************************** - * Get arguments for this operation/item. - **************************************************************************/ - CDFnameP = va_arg (Va->ap, char *); - numDims = va_arg (Va->ap, long); - dimSizes = va_arg (Va->ap, long *); - id = va_arg (Va->ap, CDFid *); - *id = (CDFid) NULL; - /************************************************************************** - * Validate arguments. - **************************************************************************/ -#if BUILD_READ_ONLY_DISTRIBUTION - if (!sX(READ_ONLY_DISTRIBUTION,&pStatus)) return pStatus; -#endif - if (numDims < 0 || numDims > CDF_MAX_DIMS) return BAD_NUM_DIMS; - for (dimN = 0; dimN < numDims; dimN++) { - if (dimSizes[dimN] < 1) return BAD_DIM_SIZE; - } - if (strlen(CDFnameP) > (size_t) CDF_PATHNAME_LEN) { - if (!sX(CDF_NAME_TRUNC,&pStatus)) return pStatus; - } - RemoveCDFFileExtension(CDFnameP, CDFnamePx); - strcpyX (CDFnameT, CDFnamePx, CDF_PATHNAME_LEN); -#if STRIP_TRAILING_BLANKS_FROM_CDFPATH - StripTrailingBlanks (CDFnameT); -#endif -#if defined(vms) || defined(dos) - MakeUpperString (CDFnameT); -#endif -#if defined(unix) || defined(win32) || defined(dos) -# if defined(unix) - del = strrchr(CDFnameT, '/'); -# else - del = strrchr(CDFnameT, '\\'); - if (del == NULL) { -# if defined(win32) - del = strrchr(CDFnameT, '/'); -# endif - } -# endif - if (del == NULL) { - if (!ValidCDFname(CDFnameT)) return BAD_CDF_NAME; - } else { - if (!ValidCDFname(del+1)) return BAD_CDF_NAME; - } -#else - if (!ValidCDFname(CDFnameT)) return BAD_CDF_NAME; -#endif - BuildFilePath (CDFt, CDFnameT, no_append, upper_case_ext, version_numbers, - INT32_ZERO, CDFnameX); - if (IsReg(CDFnameX)) return CDF_EXISTS; - /************************************************************************** - * Create CDF file. - **************************************************************************/ - dotFp = V_open64 (CDFnameX, WRITE_PLUS_a_mode); - if (dotFp == NULL) return CDF_CREATE_ERROR; - /************************************************************************** - * Allocate/initialize CDF structure. - **************************************************************************/ - CDF = (struct CDFstruct *) cdf_AllocateMemory ((size_t)sizeof(struct CDFstruct), NULL); - if (CDF == NULL) { - V_close64 (dotFp, NULL, NULL); - CDFdeleteFile (CDFnameX); - return BAD_MALLOC; - } - CDF->CDFname = (char *) cdf_AllocateMemory ((size_t)strlen(CDFnameT) + 1, NULL); - if (CDF->CDFname == NULL) { - V_close64 (dotFp, NULL, NULL); - CDFdeleteFile (CDFnameX); - cdf_FreeMemory (CDF, NULL); - return BAD_MALLOC; - } - else - strcpyX (CDF->CDFname, CDFnameT, 0); - CDF->magic = VALIDid_MAGIC_NUMBER; - CDF->largeFile = TRUE; - CDF->CDRoffset64 = (OFF_T) V3_CDR_OFFSET64; - CDF->GDRoffset64 = (OFF_T) NO_OFFSET64; /* Reset below when GDR is written. */ - CDF->readOnly = FALSE; - CDF->zMode = zMODEoff; - CDF->decoding = HOST_DECODING; - CDF->negToPosFp0 = FALSE; - CDF->status = READ_WRITE; - CDF->dotFp = dotFp; - CDF->uDotFp = NULL; - CDF->fp = dotFp; - CDF->pseudo_clock = 0; - CDF->upper_case_ext = upper_case_ext; - CDF->version_numbers = version_numbers; - CDF->no_append = no_append; - CDF->fakeEPOCH = FALSE; - CDF->wastedSpace = FALSE; - CDF->badEOF = FALSE; - CDF->badTerminatingOffsets = FALSE; - CDF->assumedScopes = FALSE; - CDF->NrVars = 0; - CDF->NzVars = 0; - CDF->MAXrVars = 0; - CDF->MAXzVars = 0; - CDF->rVars = NULL; - CDF->zVars = NULL; - CDF->encoding = BOO(DEFAULT_TO_HOST_ENCODING,HostEncoding(), - IBMPC_ENCODING); - CDF->rowMajor = DEFAULT_TO_ROW_MAJOR; - CDF->singleFile = DEFAULT_TO_SINGLE_FILE; - CDF->rMaxRec = NO_RECORD; - CDF->rNumDims = numDims; - for (dimN = 0; dimN < numDims; dimN++) { - CDF->rDimSizes[dimN] = dimSizes[dimN]; - } - CDF->stage.fp = NULL; - CDF->stage.mark64 = (OFF_T) ZERO_OFFSET64; - CDF->stage.cacheSize = NUMcacheSTAGE; - CDF->compressFp = NULL; - CDF->scratchDir = NULL; - CDF->workingCacheSize = BOO(CDF->singleFile,NUMcacheSINGLE,NUMcacheMULTI); - CDF->compressCacheSize = NUMcacheCOMPRESS; - CDF->checksum = BOO(CDFgetChecksumEnvVar()<=0,NONE_CHECKSUM,MD5_CHECKSUM); - CDF->leapSecondUpdated = 1; - InitCURobjectsStates (CDF); - AddTOvStats (&CDF->dotCDFvStats, NULL); - AddTOvStats (&CDF->uDotCDFvStats, NULL); - /************************************************************************** - * Set number of cache buffers based on the CDF's format. - **************************************************************************/ - if (!CACHEv64(CDF->fp,CDF->workingCacheSize)) { - AbortAccess64 (CDF, noUPDATE, CDFDELETE); - cdf_FreeMemory (CDF, NULL); - return BAD_CACHE_SIZE; - } - /************************************************************************** - * Write magic numbers. - **************************************************************************/ - if (!Write32_64(CDF->fp,(Int32 *)&magicNumber1)) { - AbortAccess64 (CDF, noUPDATE, CDFDELETE); - cdf_FreeMemory (CDF, NULL); - return CDF_WRITE_ERROR; - } - if (!Write32_64(CDF->fp,(Int32 *)&magicNumber2u)) { - AbortAccess64 (CDF, noUPDATE, CDFDELETE); - cdf_FreeMemory (CDF, NULL); - return CDF_WRITE_ERROR; - } - /************************************************************************** - * Write CDR. - **************************************************************************/ - CDR.RecordSize = (OFF_T) (CDR_BASE_SIZE64 + CDF_COPYRIGHT_LEN); - CDR.RecordType = CDR_; - CDR.GDRoffset = CDF->CDRoffset64 + CDR.RecordSize; - CDR.Version = CDF_LIBRARY_VERSION; - CDR.Release = CDF_LIBRARY_RELEASE; - CDR.Encoding = CDF->encoding; - CDR.Flags = 0; - if (CDF->rowMajor) SetBit32 (&(CDR.Flags), CDR_MAJORITY_BIT); - if (CDF->singleFile) SetBit32 (&(CDR.Flags), CDR_FORMAT_BIT); - CDR.rfuA = 0; - CDR.rfuB = 0; - CDR.Increment = CDF_LIBRARY_INCREMENT; - CDR.rfuD = -1; - CDR.rfuE = -1; - CDFcopyRight (copyRight); - NulPad (copyRight, CDF_COPYRIGHT_LEN); - if (!sX(WriteCDR64(CDF->fp,V3_CDR_OFFSET64, - CDR_RECORD,&CDR,copyRight, - CDR_NULL),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, CDFDELETE); - cdf_FreeMemory (CDF, NULL); - return pStatus; - } - /************************************************************************** - * Write GDR. - **************************************************************************/ - CDF->GDRoffset64 = CDR.GDRoffset; - GDR.RecordSize = GDR_BASE_SIZE64 + (OFF_T) ((numDims * sizeof(Int32))); - GDR.RecordType = GDR_; - GDR.rVDRhead = (OFF_T) 0; - GDR.zVDRhead = (OFF_T) 0; - GDR.ADRhead = (OFF_T) 0; - GDR.eof = (OFF_T) (CDR.GDRoffset + GDR.RecordSize); - GDR.NrVars = CDF->NrVars; - GDR.NumAttr = 0; - GDR.rMaxRec = CDF->rMaxRec; - GDR.rNumDims = CDF->rNumDims; - GDR.NzVars = CDF->NzVars; - GDR.UIRhead = (OFF_T) 0; - GDR.rfuC = 0; -#if defined(vms) - CDFgetLastDateinLeapSecondsTBL (&year, &month, &day); -#else - CDFgetLastDateinLeapSecondsTable (&year, &month, &day); -#endif - GDR.LeapSecondLastUpdated = (Int32) (10000*year + 100*month + day); - GDR.rfuE = -1; - for (dimN = 0; dimN < CDF->rNumDims; dimN++) { - GDR.rDimSizes[dimN] = CDF->rDimSizes[dimN]; - } - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_RECORD,&GDR, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, CDFDELETE); - cdf_FreeMemory (CDF, NULL); - return pStatus; - } - /************************************************************************** - * Select current CDF and pass back CDFid. - **************************************************************************/ - Cur->cdf = CDF; - *id = (CDFid) CDF; - if (CDF->checksum > 0) { - if (!sX(CDFsetChecksum(*id, CDF->checksum),&pStatus)) return pStatus; - } - AddOpenCDFsCount(); - break; - } - - /**************************************************************************** - * rVAR_/zVAR_, create a new variable. - ****************************************************************************/ - case rVAR_: - case zVAR_: { - Logical zOp = (Va->item == zVAR_); - long *numOut, zNumDims, *zDimSizes, recVariance, - *dimVariances, newVarNum, numDims; - char *name, Tname[CDF_VAR_NAME_LEN256+1], pathnameX[DU_MAX_PATH_LEN+1]; - struct CDFstruct *CDF; - struct VDRstruct64 VDR; - struct VarStruct ***vars; - vFILE *varFp; - Int32 nVars; - Int32 dataType, numElements; - int dimN, *max; - OFF_T offset, ntlOffset, VDRhead; - int ttmmpp; - Int32 padSize, toPad; - void *pad; - name = va_arg (Va->ap, char *); - dataType = (Int32) va_arg (Va->ap, long); - numElements = (Int32) va_arg (Va->ap, long); - if (zOp) { - zNumDims = va_arg (Va->ap, long); - zDimSizes = va_arg (Va->ap, long *); - } - recVariance = va_arg (Va->ap, long); - dimVariances = va_arg (Va->ap, long *); - numOut = va_arg (Va->ap, long *); - /************************************************************************** - * Get current CDF. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - /************************************************************************** - * Read GDR fields. - **************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - BOO(zOp,GDR_zVDRHEAD,GDR_rVDRHEAD),&VDRhead, - BOO(zOp,GDR_NzVARS,GDR_NrVARS),&nVars, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Validate arguments. - **************************************************************************/ - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!ValidDataType(dataType)) return BAD_DATA_TYPE; - if (numElements < 1) return BAD_NUM_ELEMS; - if (!STRINGdataType(dataType) && numElements != 1) return BAD_NUM_ELEMS; - if (zOp) { - if (zNumDims < 0 || zNumDims > CDF_MAX_DIMS) return BAD_NUM_DIMS; - for (dimN = 0; dimN < zNumDims; dimN++) - if (zDimSizes[dimN] < 1) return BAD_DIM_SIZE; - } - if (strlen(name) > (size_t) CDF_VAR_NAME_LEN256) { - if (!sX(VAR_NAME_TRUNC,&pStatus)) return pStatus; - } - strcpyX (Tname, name, CDF_VAR_NAME_LEN256); -#if LIMITof64K - if (TOObigIBMpc(CDFelemSize(dataType)*numElements)) return IBM_PC_OVERFLOW; -#endif - if (!ValidVarName(Tname)) return BAD_VAR_NAME; - tStatus = FindVarByName64 (CDF, Tname, NULL, NULL, NULL); - switch (tStatus) { - case NO_SUCH_VAR: - break; - case CDF_OK: - return VAR_EXISTS; - default: - AbortAccess64 (CDF, UPDATE, noDELETE); - return tStatus; - } - newVarNum = nVars; - nVars++; -#if defined(dos) - if (!CDF->singleFile && newVarNum > 99) return TOO_MANY_VARS; -#endif - /************************************************************************** - * Switch to read-write access if necessary. - **************************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - if (dataType == CDF_TIME_TT2000) { - if (!UpdateTT2000header(CDF,&pStatus)) return pStatus; - } - /************************************************************************** - * Allocate initial/additional pointers to variable data structures. - **************************************************************************/ - max = BOO(zOp,&(CDF->MAXzVars),&(CDF->MAXrVars)); - vars = BOO(zOp,&(CDF->zVars),&(CDF->rVars)); - if (newVarNum >= *max) { - int newMaxVars = (int) (VARs_INCREMENT * ((newVarNum/VARs_INCREMENT)+1)); - int varN; - size_t nBytes = newMaxVars * sizeof(struct VarStruct *); - void *ptr; - if (*max > 0) - ptr = (struct VarStruct **) cdf_ReallocateMemory (*vars, nBytes, NULL); - else - ptr = (struct VarStruct **) cdf_AllocateMemory ((size_t)nBytes, NULL); - if (ptr == NULL) return BAD_MALLOC; - *vars = ptr; - for (varN = *max; varN < newMaxVars; varN++) (*vars)[varN] = NULL; - *max = newMaxVars; - } - /************************************************************************** - * Create variable file (if multi-file CDF). - **************************************************************************/ - if (!CDF->singleFile) { - BuildFilePath (BOO(zOp,Zt,Vt), CDF->CDFname, CDF->no_append, - CDF->upper_case_ext, CDF->version_numbers, - (Int32) newVarNum, pathnameX); - varFp = V_open64 (pathnameX, WRITE_PLUS_a_mode); - if (varFp == NULL) { - if (!sX(CloseLRUvar(CDF),&pStatus)) return pStatus; - varFp = V_open64 (pathnameX, WRITE_PLUS_a_mode); - if (varFp == NULL) return VAR_CREATE_ERROR; - } - if (!CLOSEv64(varFp,NULL,NULL)) { - CDFdeleteFile (pathnameX); - return VAR_CREATE_ERROR; - } - } - /************************************************************************** - * Write rVDR/zVDR. - **************************************************************************/ - if (zOp) ttmmpp = zNumDims * sizeof(Int32); - else ttmmpp = 0; - VDR.RecordSize = BOO(zOp,zVDR_BASE_SIZE64,rVDR_BASE_SIZE64) + - ttmmpp + /*DimSizes.*/ - BOO(zOp,zNumDims, - CDF->rNumDims)*sizeof(Int32); /*DimVarys.*/ - VDR.RecordType = BOO(zOp,zVDR_,rVDR_); - VDR.VDRnext = (OFF_T) 0; - VDR.DataType = dataType; - VDR.MaxRec = NO_RECORD; - VDR.VXRhead = (OFF_T) 0; - VDR.VXRtail = (OFF_T) 0; - VDR.Flags = 0; - if (recVariance) SetBit32 (&(VDR.Flags), VDR_RECVARY_BIT); - VDR.sRecords = NO_SPARSERECORDS; - VDR.rfuB = 0; - VDR.rfuC = -1; - VDR.rfuF = -1; - VDR.NumElems = numElements; - VDR.Num = newVarNum; - VDR.CPRorSPRoffset = (OFF_T) NO_OFFSET64; - VDR.blockingFactor = 0; - strcpyX (VDR.Name, Tname, CDF_VAR_NAME_LEN256); - NulPad (VDR.Name, CDF_VAR_NAME_LEN256); - if (zOp) { - VDR.zNumDims = zNumDims; - for (dimN = 0; dimN < zNumDims; dimN++) - VDR.zDimSizes[dimN] = zDimSizes[dimN]; - } - for (dimN = 0, numDims = BOO(zOp,zNumDims,CDF->rNumDims); - dimN < numDims; dimN++) { - VDR.DimVarys[dimN] = BOO(dimVariances[dimN],VARY,NOVARY); - } - padSize = (int) (CDFelemSize(dataType) * numElements); - pad = (void *) cdf_AllocateMemory((size_t)padSize, NULL); - if (!sX(AllocateIR64(CDF,VDR.RecordSize+padSize,&offset),&pStatus)) { - CDFdeleteFile (pathnameX); - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - toPad = VDR.RecordSize; - DefaultPadValue(dataType, numElements, pad); - VDR.RecordSize += padSize; - SetBit32 (&VDR.Flags,VDR_PADVALUE_BIT); - if (!sX(WriteVDR64(CDF,CDF->fp,offset,zOp, - VDR_RECORD,&VDR,pad, - VDR_NULL),&pStatus)) { - CDFdeleteFile (pathnameX); - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - cdf_FreeMemory (pad, NULL); - /************************************************************************** - * Point next-to-last rVDR/zVDR (or GDR) to this rVDR/zVDR. - **************************************************************************/ - if (newVarNum != 0) { - if (!sX(FindVarByNumber64(CDF,(Int32)(newVarNum-1), - zOp,&ntlOffset),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteVDR64(CDF,CDF->fp,ntlOffset,zOp, - VDR_VDRNEXT,&offset, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - else - VDRhead = offset; - /************************************************************************** - * Update GDR fields that may have been modified. - **************************************************************************/ - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - BOO(zOp,GDR_zVDRHEAD,GDR_rVDRHEAD),&VDRhead, - BOO(zOp,GDR_NzVARS,GDR_NrVARS),&nVars, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Update the appropriate variable count held in memory for efficiency. - **************************************************************************/ - if (zOp) - CDF->NzVars = nVars; - else - CDF->NrVars = nVars; - /************************************************************************** - * Select current variable and determine variable number to be passed back - * (based on zMode). - **************************************************************************/ - if (zModeON(CDF)) { - long varN = CDF->NrVars + newVarNum; - CDF->CURzVarNum = varN; - CDF->CURzVarOffset64 = offset; - *numOut = varN; - } - else { - if (zOp) { - CDF->CURzVarNum = newVarNum; - CDF->CURzVarOffset64 = offset; - } else { - CDF->CURrVarNum = newVarNum; - CDF->CURrVarOffset64 = offset; - } - *numOut = newVarNum; - } - break; - } - /**************************************************************************** - * ATTR_, - ****************************************************************************/ - case ATTR_: { - long *attrNumOut, scope; - char *attrName, truncName[CDF_ATTR_NAME_LEN256+1]; - struct CDFstruct *CDF; - struct ADRstruct64 ADR; - Int32 numAttr; - OFF_T offset, ADRhead; - /************************************************************************** - * Get arguments for this operation/item. - **************************************************************************/ - attrName = va_arg (Va->ap, char *); - scope = va_arg (Va->ap, long); - attrNumOut = va_arg (Va->ap, long *); - /************************************************************************** - * Select current CDF. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - /************************************************************************** - * Validate arguments. - **************************************************************************/ - if (!ValidAttrScope((Int32)scope)) return BAD_SCOPE; - if (strlen(attrName) > (size_t) CDF_ATTR_NAME_LEN256) { - if (!sX(ATTR_NAME_TRUNC,&pStatus)) return pStatus; - } - strcpyX (truncName, attrName, CDF_ATTR_NAME_LEN256); - if (!ValidAttrName(truncName)) return BAD_ATTR_NAME; - tStatus = FindAttrByName64 (CDF, truncName, NULL); - switch (tStatus) { - case NO_SUCH_ATTR: - break; - case CDF_OK: - return ATTR_EXISTS; - default: - AbortAccess64 (CDF, UPDATE, noDELETE); - return tStatus; - } - /************************************************************************** - * Switch to read-write access if necessary. - **************************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Read GDR fields. - **************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_NUMATTR,&numAttr, - GDR_ADRHEAD,&ADRhead, - GDR_NULL),&pStatus)) return pStatus; - /************************************************************************** - * Write ADR. - **************************************************************************/ - ADR.RecordSize = ADR_BASE_SIZE64; - ADR.RecordType = ADR_; - ADR.ADRnext = (OFF_T) 0; - ADR.AgrEDRhead = (OFF_T) 0; - ADR.Scope = scope; - ADR.Num = numAttr; - ADR.NgrEntries = 0; - ADR.MAXgrEntry = NO_ENTRY; - ADR.rfuA = 0; - ADR.AzEDRhead = (OFF_T) 0; - ADR.NzEntries = 0; - ADR.MAXzEntry = NO_ENTRY; - ADR.rfuE = -1; - strcpyX (ADR.Name, truncName, CDF_ATTR_NAME_LEN256); - NulPad (ADR.Name, CDF_ATTR_NAME_LEN256); - if (!sX(AllocateIR64(CDF,ADR.RecordSize,&offset),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteADR64(CDF->fp,offset, - ADR_RECORD,&ADR, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Point last ADR (or GDR) to this ADR. - **************************************************************************/ - if (numAttr == 0) - ADRhead = offset; - else { - OFF_T lastOffset; - if (!sX(FindLastAttr64(CDF,&lastOffset),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteADR64(CDF->fp,lastOffset, - ADR_ADRNEXT,&offset, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Update GDR fields. - **************************************************************************/ - numAttr++; - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_NUMATTR,&numAttr, - GDR_ADRHEAD,&ADRhead, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Select current attribute and entry offsets and pass back attribute - * number. - **************************************************************************/ - CDF->CURattrOffset64 = offset; - CDF->CURgrEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET64; - CDF->CURzEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET64; - *attrNumOut = ADR.Num; - break; - } - /**************************************************************************** - * Unknown item, must be the next function. - ****************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } -} -return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfcsi.c b/cdf36_3-dist/src/lib/cdfcsi.c deleted file mode 100644 index 246f7ae..0000000 --- a/cdf36_3-dist/src/lib/cdfcsi.c +++ /dev/null @@ -1,1795 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF C interface for non-macro'ed functions -* of the Standard Interface. -* -* Version 2.4a, 8-Mar-97, Hughes STX. -* -* Modification history: -* -* V1.0 1-Jun-91, J Love Original version (for CDF V2.1). This is a -* combination of cdf.c, cdfattr.c and cdfvar.c. -* Most of these functions can be replaced by -* the macros in 'cdf.h'. -* V1.1 30-Jul-91, J Love Use 'CDFlib'. -* V2.0 10-Feb-92, J Love IBM PC port. -* V2.1 21-Aug-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V2.2 18-Oct-93, J Love CDF V2.4. -* V2.3 9-Nov-94, J Love CDF V2.5. -* V2.4 14-Feb-96, J Love CDF V2.6 (renamed - previously `cdf_c_if.c'). -* V2.4a 8-Mar-97, J Love Windows NT for Visual C++ 4 on an IBM PC. -* V3.0 28-Aug-01, M Liu Add CDFgetrVarsRecordData, CDFgetzVarsRecordData, -* CDFputrVarsRecordData, CDFputzVarsRecordData. -* V3.1 31-May-05, M Liu Replaced CDFgetrVarsRecordData and -* CDFgetzVarsRecordData with a general function. -* So, are the CDFputrVarsRecordData and -* CDFputzVarsRecordData. -* V3.2 13-Apr-07, D. Han Modified CDFattrInquire not to select CDF id -* twice (performance improvement). -* V3.3 22-Oct-08, M. Liu Modified CDFgetVarsRecordDatabyNames and -* CDFputVarsRecordDatabyNames allocate buffers -* based on the number of variables involved. -* V3.4 03-Jan-12, M. Liu Added CDFgetVarAllRecordsByVarID, -* CDFgetVarRangeRecordsByVarID, -* CDFgetVarAllRecordsByVarName, -* CDFgetVarRangeRecordsByVarName functions, and -* a set of similar functions for put operations. -* V3.5 28-May-12, M. Liu Added CDFinsertVarRecordsByVarID and -* CDFinsertVarRecordsByVarName. -* V3.6 23-Sep-16, M. Liu Added functions: CDFreadzVarAllByVarID, -* CDFreadzVarAllByVarName, CDFreadzVarPadValue, -* CDFreadzVarDataByVarID, -* CDFreadzVarDataByVarName, -* CDFreadzVarRangeDataByVarID, -* CDFreadzVarRangeDataByVarName, CDFgetzVarSpec, -* CDFreadgAttrEntry and CDFreadzAttrEntry. -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -static int backward = 0; -static int setFileBackwardFlag = 0; - -static long checksum = 0; -static int setChecksumFlag = 0; - -/****************************************************************************** -* CDFcreateCDF. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFcreateCDF (cdfName, id) -char *cdfName; /* In -- CDF name. */ -CDFid *id; /* Out -- CDF id. */ -{ - CDFstatus pStatus = CDF_OK; - long dimSizes[1] = {0}; - if (!sX(CDFlib(CREATE_, CDF_, cdfName, 0L, dimSizes, id, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFattrInquire. -* Can't implement with macro because the attribute's scope determines which -* item(s) to use. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFattrInquire (id, attrNum, attrName, attrScope, - maxEntry) -CDFid id; /* In -- CDF id. */ -long attrNum; /* In -- Attribute number. */ -char *attrName; /* Out -- Attribute name. */ -long *attrScope; /* Out -- Attribute scope. */ -long *maxEntry; /* Out -- Maximum gEntry/rEntry number used. */ -{ - CDFstatus pStatus = CDF_OK; - if (!sX(CDFlib(SELECT_, CDF_, id, - ATTR_, attrNum, - GET_, ATTR_SCOPE_, attrScope, - NULL_), &pStatus)) return pStatus; - if (!sX(CDFlib(GET_, ATTR_NAME_, attrName, - BOO(GLOBALscope(*attrScope),ATTR_MAXgENTRY_, - ATTR_MAXrENTRY_), maxEntry, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFinquireAttr. -* Can't implement with macro because the attribute's scope determines which -* item(s) to use. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFinquireAttr (id, attrNum, attrName, scope, - maxgEntry, maxrEntry, maxzEntry) -CDFid id; /* In -- CDF id. */ -long attrNum; /* In -- Attribute number. */ -char *attrName; /* Out -- Attribute name. */ -long *scope; /* Out -- Attribute scope. */ -long *maxgEntry; /* Out -- Maximum gEntry number used for gAttribute. */ -long *maxrEntry; /* Out -- Maximum rEntry number used for vAttribute. */ -long *maxzEntry; /* Out -- Maximum zEntry number used for vAttribute. */ -{ - - CDFstatus pStatus = CDF_OK; - - *maxgEntry = -1L; - *maxrEntry = -1L; - *maxzEntry = -1L; - - if (!sX(CDFlib(SELECT_, CDF_, id, - ATTR_, attrNum, - GET_, ATTR_SCOPE_, scope, - NULL_), &pStatus)) return pStatus; - if (!sX(CDFlib(GET_, ATTR_NAME_, attrName, - (BOO(GLOBALscope(*scope),ATTR_MAXgENTRY_, - ATTR_MAXrENTRY_)), - (BOO(GLOBALscope(*scope),maxgEntry,maxrEntry)), - NULL_), &pStatus)) return pStatus; - if (!GLOBALscope(*scope)) { - if (!sX(CDFlib(GET_, ATTR_MAXzENTRY_, maxzEntry, - NULL_), &pStatus)) return pStatus; - } - - return pStatus; -} - -/****************************************************************************** -* CDFinquireAttrEntry. -* Can't implement with macro because the attribute's scope determines which -* item(s) to use. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFinquireAttrEntry (id, grzEntry, attrNum, - entryNum, dataType, numElems) -CDFid id; /* In -- CDF id. */ -int grzEntry; /* In -- Flag for g/r/zEntry. */ -long attrNum; /* In -- Attribute number. */ -long entryNum; /* In -- gEntry/rEntry/zEntry number. */ -long *dataType; /* Out -- gEntry/rEntry/zEntry data type. */ -long *numElems; /* Out -- gEntry/rEntry/zEntry number of elements. */ -{ - long scope; - CDFstatus pStatus = CDF_OK; - if (!sX(CDFlib(SELECT_, CDF_, id, - ATTR_, attrNum, - GET_, ATTR_SCOPE_, &scope, - NULL_), &pStatus)) return pStatus; - if (GLOBALscope(scope) && (grzEntry != 0) && (grzEntry != 1)) - return ILLEGAL_FOR_SCOPE; - if (!GLOBALscope(scope) && (grzEntry == 1)) return ILLEGAL_FOR_SCOPE; - - if (!sX(CDFlib(SELECT_, BOO((grzEntry == 3),zENTRY_, - (BOO(GLOBALscope(scope),gENTRY_, - rENTRY_))), entryNum, - GET_, BOO((grzEntry == 3),zENTRY_DATATYPE_, - (BOO(GLOBALscope(scope),gENTRY_DATATYPE_, - rENTRY_DATATYPE_))), dataType, - BOO((grzEntry == 3),zENTRY_NUMELEMS_, - (BOO(GLOBALscope(scope),gENTRY_NUMELEMS_, - rENTRY_NUMELEMS_))), numElems, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFputAttrEntry. -* Can't implement with macro because the attribute's scope determines which -* item(s) to use. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFputAttrEntry (id, grzEntry, attrNum, entryNum, - dataType, numElems, value) -CDFid id; /* In -- CDF id. */ -int grzEntry; /* In -- Flag for g/r/zEntry. */ -long attrNum; /* In -- Attribute number. */ -long entryNum; /* In -- gEntry/rEntry/zEntry number. */ -long dataType; /* In -- gEntry/rEntry/zEntry data type. */ -long numElems; /* In -- gEntry/rEntry/zEntry number of elements. */ -void *value; /* In -- Value. */ -{ - long scope; - CDFstatus pStatus = CDF_OK; - if (!sX(CDFlib(SELECT_, CDF_, id, - ATTR_, attrNum, - GET_, ATTR_SCOPE_, &scope, - NULL_), &pStatus)) return pStatus; - if (GLOBALscope(scope) && (grzEntry != 0) && (grzEntry != 1)) - return ILLEGAL_FOR_SCOPE; - if (!GLOBALscope(scope) && (grzEntry == 1)) return ILLEGAL_FOR_SCOPE; - - if (!sX(CDFlib(SELECT_, BOO((grzEntry == 3),zENTRY_, - (BOO(GLOBALscope(scope),gENTRY_, - rENTRY_))), entryNum, - PUT_, BOO((grzEntry == 3),zENTRY_DATA_, - (BOO(GLOBALscope(scope),gENTRY_DATA_, - rENTRY_DATA_))), dataType, numElems, value, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFgetAttrEntry. -* Can't implement with macro because the attribute's scope determines which -* item(s) to use. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFgetAttrEntry (id, grzEntry, attrNum, entryNum, - value) -CDFid id; /* In -- CDF id. */ -int grzEntry; /* In -- Flag for g/r/zEntry. */ -long attrNum; /* In -- Attribute number. */ -long entryNum; /* In -- gEntry/rEntry/zEntry number. */ -void *value; /* Out -- Value. */ -{ - long scope; - CDFstatus pStatus = CDF_OK; - if (!sX(CDFlib(SELECT_, CDF_, id, - ATTR_, attrNum, - GET_, ATTR_SCOPE_, &scope, - NULL_), &pStatus)) return pStatus; - if (GLOBALscope(scope) && (grzEntry != 0) && (grzEntry != 1)) - return ILLEGAL_FOR_SCOPE; - if (!GLOBALscope(scope) && (grzEntry == 1)) return ILLEGAL_FOR_SCOPE; - - if (!sX(CDFlib(SELECT_, BOO((grzEntry == 3),zENTRY_, - (BOO(GLOBALscope(scope),gENTRY_, - rENTRY_))), entryNum, - GET_, BOO((grzEntry == 3),zENTRY_DATA_, - (BOO(GLOBALscope(scope),gENTRY_DATA_, - rENTRY_DATA_))), value, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFdataFree. -* Free the dynamic space if it exists.It applies to pointer of CDFdata type. -******************************************************************************/ - -VISIBLE_PREFIX void CDFdataFree (data) -CDFdata data; /* In -- data buffer. */ -{ - if (data != NULL) free (data); -} - -/****************************************************************************** -* CDFreadgAttrEntry. -* This function reads a global attribute entry. This function passes back the -* pointer to the dynamically allocated space for the retrieved data. -* : Caller is responsible to free the allocated space. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFreadgAttrEntry (id, attrNum, entryNum, dataType, - numElems, value) -CDFid id; /* In -- CDF id. */ -long attrNum; /* In -- gAttribute number. */ -long entryNum; /* In -- gEntry number. */ -long *dataType; /* Out -- Entry's data type. */ -long *numElems; /* Out -- Entry's number of elements. */ -CDFdata *value; /* Out -- Entry's value. */ -{ - long scope; - CDFstatus pStatus = CDF_OK; - void *buf; - - *value = (CDFdata) NULL; - if (!sX(CDFlib(SELECT_, CDF_, id, - ATTR_, attrNum, - GET_, ATTR_SCOPE_, &scope, - NULL_), &pStatus)) return pStatus; - if (!GLOBALscope(scope)) return ILLEGAL_FOR_SCOPE; - if (!sX(CDFlib(SELECT_, gENTRY_, entryNum, - GET_, gENTRY_DATATYPE_, dataType, - gENTRY_NUMELEMS_, numElems, - NULL_), &pStatus)) return pStatus; - buf = (void *) malloc ((size_t) CDFelemSize(*dataType) * - (STRINGdataType(*dataType)?(*numElems+1):*numElems)); - if (buf == NULL) return BAD_MALLOC; - if (!sX(CDFlib(GET_, gENTRY_DATA_, buf, - NULL_), &pStatus)) return pStatus; - if (STRINGdataType (*dataType)) *((char *) buf + *numElems) = '\0'; - *value = (CDFdata) buf; - return pStatus; -} - -/****************************************************************************** -* CDFreadzAttrEntry. -* This function reads a zVariable attribute entry. This function passes back -* the pointer to the dynamically allocated space for the retrieved data. -* : Caller is responsible to free the allocated space. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFreadzAttrEntry (id, attrNum, entryNum, dataType, - numElems, value) -CDFid id; /* In -- CDF id. */ -long attrNum; /* In -- Attribute number. */ -long entryNum; /* In -- zEntry number. */ -long *dataType; /* Out -- Entry's data type. */ -long *numElems; /* Out -- Entry's number of elements. */ -CDFdata *value; /* Out -- Entry's value. */ -{ - long scope, dataTypeX; - CDFstatus pStatus = CDF_OK; - void *buf; - - *value = (CDFdata) NULL; - if (!sX(CDFlib(SELECT_, CDF_, id, - ATTR_, attrNum, - GET_, ATTR_SCOPE_, &scope, - NULL_), &pStatus)) return pStatus; - if (GLOBALscope(scope)) return ILLEGAL_FOR_SCOPE; - pStatus = CDFlib(SELECT_, CDF_, id, - zVAR_, entryNum, - GET_, zVAR_DATATYPE_, &dataTypeX, - NULL_); - if (pStatus != CDF_OK) return NO_SUCH_VAR; - if (!sX(CDFlib(SELECT_, zENTRY_, entryNum, - GET_, zENTRY_DATATYPE_, dataType, - zENTRY_NUMELEMS_, numElems, - NULL_), &pStatus)) return pStatus; - buf = (void *) malloc ((size_t) CDFelemSize(*dataType) * - (STRINGdataType(*dataType)?(*numElems+1):*numElems)); - if (buf == NULL) return BAD_MALLOC; - if (!sX(CDFlib(GET_, zENTRY_DATA_, buf, - NULL_), &pStatus)) return pStatus; - if (STRINGdataType (*dataType)) *((char *) buf + *numElems) = '\0'; - *value = (CDFdata) buf; - return pStatus; -} - -/****************************************************************************** -* CDFdeleteAttrEntry. -* Can't implement with macro because the attribute's scope determines which -* item(s) to use. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFdeleteAttrEntry (id, grzEntry, attrNum, entryNum) -CDFid id; /* In -- CDF id. */ -int grzEntry; /* In -- Flag for g/r/zEntry. */ -long attrNum; /* In -- Attribute number. */ -long entryNum; /* In -- gEntry/rEntry/zEntry number. */ -{ - long scope; - CDFstatus pStatus = CDF_OK; - if (!sX(CDFlib(SELECT_, CDF_, id, - ATTR_, attrNum, - GET_, ATTR_SCOPE_, &scope, - NULL_), &pStatus)) return pStatus; - if (GLOBALscope(scope) && (grzEntry != 1)) return ILLEGAL_FOR_SCOPE; - if (!GLOBALscope(scope) && (grzEntry != 2) && (grzEntry != 3)) - return ILLEGAL_FOR_SCOPE; - - if (!sX(CDFlib(SELECT_, BOO((grzEntry == 3),zENTRY_, - (BOO(GLOBALscope(scope),gENTRY_, - rENTRY_))), entryNum, - DELETE_, BOO((grzEntry == 3),zENTRY_, - (BOO(GLOBALscope(scope),gENTRY_, rENTRY_))), - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFsetAttrEntryDataSpec. -* Can't implement with macro because the attribute's scope determines which -* item(s) to use. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFsetAttrEntryDataSpec (id, grzEntry, attrNum, - entryNum, dataType, numElems) -CDFid id; /* In -- CDF id. */ -int grzEntry; /* In -- Flag for g/r/zEntry. */ -long attrNum; /* In -- Attribute number. */ -long entryNum; /* In -- gEntry/rEntry/zEntry number. */ -long dataType; /* In -- Data type. */ -long numElems; /* In -- Number of elements. */ -{ - long scope; - CDFstatus pStatus = CDF_OK; - if (!sX(CDFlib(SELECT_, CDF_, id, - ATTR_, attrNum, - GET_, ATTR_SCOPE_, &scope, - NULL_), &pStatus)) return pStatus; - if (GLOBALscope(scope) && (grzEntry != 1)) return ILLEGAL_FOR_SCOPE; - if (!GLOBALscope(scope) && (grzEntry != 2) && (grzEntry != 3)) - return ILLEGAL_FOR_SCOPE; - - if (!sX(CDFlib(SELECT_, BOO((grzEntry == 3),zENTRY_, - (BOO(GLOBALscope(scope),gENTRY_, - rENTRY_))), entryNum, - PUT_, BOO((grzEntry == 3),zENTRY_DATASPEC_, - (BOO(GLOBALscope(scope),gENTRY_DATASPEC_, - rENTRY_DATASPEC_))), - dataType, numElems, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFgetAttrNum. -* Can't implement with macro since it is the attribute number which is to be -* returned (unless an error). -******************************************************************************/ - -VISIBLE_PREFIX long CDFgetAttrNum (id,attrName) -CDFid id; /* In -- CDF id. */ -char *attrName; /* In -- attribute name. */ -{ - CDFstatus status; - long attrNum; - status = CDFlib (SELECT_, CDF_, id, - GET_, ATTR_NUMBER_, attrName, &attrNum, - NULL_); - if (StatusOK(status)) - return attrNum; - else - return status; -} - -/****************************************************************************** -* CDFgetVarNum. -* Can't implement with macro since it is the variable number which is to be -* returned (unless an error). -******************************************************************************/ - -VISIBLE_PREFIX long CDFgetVarNum (id,varName) -CDFid id; /* In -- CDF id. */ -char *varName; /* In -- variable name. */ -{ - CDFstatus status; - long varNum; - status = CDFlib (SELECT_, CDF_, id, - GET_, zVAR_NUMBER_, varName, &varNum, - NULL_); - if (StatusOK(status)) - return varNum; - else { - status = CDFlib (SELECT_, CDF_, id, - GET_, rVAR_NUMBER_, varName, &varNum, - NULL_); - if (StatusOK(status)) - return varNum; - } - return status; -} - -/****************************************************************************** -* CDFgetNumAttrEntries. -* Can't implement with macro because the attribute's scope determines which -* item(s) to use. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFgetNumAttrEntries (id, grzEntry, attrNum, - numEntries) -CDFid id; /* In -- CDF id. */ -int grzEntry; /* In -- Flag for g/r/zEntry. */ -long attrNum; /* In -- Attribute number. */ -long *numEntries; /* Out -- number of gEntries/rEntries/zEntries. */ -{ - long scope; - CDFstatus pStatus = CDF_OK; - if (!sX(CDFlib(SELECT_, CDF_, id, - ATTR_, attrNum, - GET_, ATTR_SCOPE_, &scope, - NULL_), &pStatus)) return pStatus; - if (GLOBALscope(scope) && (grzEntry != 1)) return ILLEGAL_FOR_SCOPE; - if (!GLOBALscope(scope) && (grzEntry != 2) && (grzEntry != 3)) - return ILLEGAL_FOR_SCOPE; - - if (!sX(CDFlib(GET_, BOO((grzEntry == 3), ATTR_NUMzENTRIES_, - (BOO(GLOBALscope(scope), ATTR_NUMgENTRIES_, - ATTR_NUMrENTRIES_))), numEntries, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFgetAttrMaxEntry. -* Can't implement with macro because the attribute's scope determines which -* item(s) to use. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFgetAttrMaxEntry (id, grzEntry, attrNum, maxEntry) -CDFid id; /* In -- CDF id. */ -int grzEntry; /* In -- Flag for g/r/zEntry. */ -long attrNum; /* In -- Attribute number. */ -long *maxEntry; /* Out -- Max. number of gEntry/rEntry/zEntry. */ -{ - long scope; - CDFstatus pStatus = CDF_OK; - if (!sX(CDFlib(SELECT_, CDF_, id, - ATTR_, attrNum, - GET_, ATTR_SCOPE_, &scope, - NULL_), &pStatus)) return pStatus; - if (GLOBALscope(scope) && (grzEntry != 1)) return ILLEGAL_FOR_SCOPE; - if (!GLOBALscope(scope) && (grzEntry != 2) && (grzEntry != 3)) - return ILLEGAL_FOR_SCOPE; - - if (!sX(CDFlib(GET_, BOO((grzEntry == 3), ATTR_MAXzENTRY_, - (BOO(GLOBALscope(scope), ATTR_MAXgENTRY_, - ATTR_MAXrENTRY_))), maxEntry, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFgetAttrEntryDataType. -* Can't implement with macro because the attribute's scope determines which -* item(s) to use. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFgetAttrEntryDataType (id, grzEntry, attrNum, - entryNum, dataType) -CDFid id; /* In -- CDF id. */ -int grzEntry; /* In -- Flag for g/r/zEntry. */ -long attrNum; /* In -- Attribute number. */ -long entryNum; /* In -- gEntry/rEntry/zEntry number. */ -long *dataType; /* Out -- gEntry/rEntry/zEntry dataType. */ -{ - long scope; - CDFstatus pStatus = CDF_OK; - if (!sX(CDFlib(SELECT_, CDF_, id, - ATTR_, attrNum, - GET_, ATTR_SCOPE_, &scope, - NULL_), &pStatus)) return pStatus; - if (GLOBALscope(scope) && (grzEntry != 1)) return ILLEGAL_FOR_SCOPE; - if (!GLOBALscope(scope) && (grzEntry != 2) && (grzEntry != 3)) - return ILLEGAL_FOR_SCOPE; - - if (!sX(CDFlib(SELECT_, BOO((grzEntry == 3), zENTRY_, - BOO(GLOBALscope(scope), gENTRY_, - rENTRY_)), entryNum, - GET_, BOO((grzEntry == 3), zENTRY_DATATYPE_, - BOO(GLOBALscope(scope), gENTRY_DATATYPE_, - rENTRY_DATATYPE_)), dataType, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFgetAttrEntryNumElements. -* Can't implement with macro because the attribute's scope determines which -* item(s) to use. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFgetAttrEntryNumElements (id, grzEntry, attrNum, - entryNum, numElements) -CDFid id; /* In -- CDF id. */ -int grzEntry; /* Flag for g/r/zEntry. */ -long attrNum; /* In -- Attribute number. */ -long entryNum; /* In -- gEntry/rEntry/zEntry number. */ -long *numElements; /* Out -- gEntry/rEntry/zEntry numElements. */ -{ - long scope; - CDFstatus pStatus = CDF_OK; - if (!sX(CDFlib(SELECT_, CDF_, id, - ATTR_, attrNum, - GET_, ATTR_SCOPE_, &scope, - NULL_), &pStatus)) return pStatus; - if (GLOBALscope(scope) && (grzEntry != 1)) return ILLEGAL_FOR_SCOPE; - if (!GLOBALscope(scope) && (grzEntry != 2) && (grzEntry != 3)) - return ILLEGAL_FOR_SCOPE; - - if (!sX(CDFlib(SELECT_, BOO((grzEntry == 3), zENTRY_, - BOO(GLOBALscope(scope), gENTRY_, - rENTRY_)), entryNum, - GET_, BOO((grzEntry == 3), zENTRY_NUMELEMS_, - BOO(GLOBALscope(scope), gENTRY_NUMELEMS_, - rENTRY_NUMELEMS_)), numElements, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFgetVarRecordData. -* Acquire a full record data from a given record of a variable. -* Retrieved data are filled into the buffer. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFgetVarRecordData (id, zVar, varNum, recNum, buffer) -CDFid id; /* In -- CDF id. */ -int zVar; /* In -- Flag for zVariable. */ -long varNum; /* In -- Variable number. */ -long recNum; /* In -- Record number to read. */ -void *buffer; /* Out -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - long numVars, varNums[CDF_MAX_DIMS]; - - numVars = 1; - varNums[0] = varNum; - - if (!sX(CDFlib(SELECT_, CDF_, id, - BOO((zVar==1),zVARs_RECNUMBER_,rVARs_RECNUMBER_), - recNum, - GET_, BOO((zVar==1),zVARs_RECDATA_,rVARs_RECDATA_), numVars, - varNums, buffer, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFputVarRecordData. -* Write a full record data for a given record of a variable. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFputVarRecordData (id, zVar, varNum, recNum, buffer) -CDFid id; /* In -- CDF id. */ -int zVar; /* In -- Flag for zVariable. */ -long varNum; /* In -- Variable number. */ -long recNum; /* In -- Record number to write. */ -void *buffer; /* In -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - long numVars, varNums[CDF_MAX_DIMS]; - - numVars = 1; - varNums[0] = varNum; - - if (!sX(CDFlib(SELECT_, CDF_, id, - BOO((zVar==1),zVARs_RECNUMBER_,rVARs_RECNUMBER_), - recNum, - PUT_, BOO((zVar==1),zVARs_RECDATA_,rVARs_RECDATA_), numVars, - varNums, buffer, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFgetVarAllRecordsByVarID. -* Acquire data from all records for a given variable (by zVar flag and id). -* Retrieved data are filled into the buffer. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFgetVarAllRecordsByVarID (id, zVar, varNum, buffer) -CDFid id; /* In -- CDF id. */ -int zVar; /* In -- Flag for zVariable. */ -long varNum; /* In -- Variable number. */ -void *buffer; /* Out -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - int i; - long lastRec, numDims; - long indices[CDF_MAX_DIMS], intervals[CDF_MAX_DIMS], dimSizes[CDF_MAX_DIMS]; - - if (zVar == 1) { - if (!sX(CDFgetzVarNumDims(id,varNum,&numDims), &pStatus)) return pStatus; - if (!sX(CDFgetzVarDimSizes(id,varNum,dimSizes), &pStatus)) return pStatus; - if (!sX(CDFgetVarMaxWrittenRecNum(id,1,varNum,&lastRec), &pStatus)) - return pStatus; - } else { - if (!sX(CDFgetrVarsNumDims(id,&numDims), &pStatus)) return pStatus; - if (!sX(CDFgetrVarsDimSizes(id,dimSizes), &pStatus)) return pStatus; - if (!sX(CDFgetVarMaxWrittenRecNum(id,0,varNum,&lastRec), &pStatus)) - return pStatus; - } - for (i = 0; i < (int) numDims; ++i) { - indices[i] = 0L; - intervals[i] = 1L; - } - if (!sX(CDFlib(SELECT_, CDF_, id, - BOO((zVar==1),zVAR_,rVAR_), varNum, - BOO((zVar==1),zVAR_RECNUMBER_,rVARs_RECNUMBER_),0L, - BOO((zVar==1),zVAR_RECCOUNT_,rVARs_RECCOUNT_), - lastRec+1, - BOO((zVar==1),zVAR_RECINTERVAL_,rVARs_RECINTERVAL_), - 1L, - BOO((zVar==1),zVAR_DIMINDICES_,rVARs_DIMINDICES_), - indices, - BOO((zVar==1),zVAR_DIMCOUNTS_,rVARs_DIMCOUNTS_), - dimSizes, - BOO((zVar==1),zVAR_DIMINTERVALS_,rVARs_DIMINTERVALS_), - intervals, - GET_, BOO((zVar==1),zVAR_HYPERDATA_,rVAR_HYPERDATA_),buffer, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFgetVarAllRecordsByVarName. -* Acquire data from all records for a given variable (by its unique name). -* Retrieved data are filled into the buffer. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFgetVarAllRecordsByVarName (id, varName, buffer) -CDFid id; /* In -- CDF id. */ -char *varName; /* In -- Variable name. */ -void *buffer; /* Out -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - int zVar; - long varNum; - - varNum = CDFgetVarNum(id, varName); - if (varNum < 0) return NO_SUCH_VAR; - if (CDFconfirmVarExistence(id, 1, varName) == CDF_OK) zVar = 1; - else zVar = 0; - if (!sX(CDFgetVarAllRecordsByVarID(id,zVar,varNum,buffer), &pStatus)) - return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFgetzVarSpec. -* Acquire a given zVariable's (by zVar id) specification. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFgetzVarSpec (id, varNum, dataType, numElems, - numDims, dimSizes, recVary, dimVarys) -CDFid id; /* In -- CDF id. */ -long varNum; /* In -- Variable number. */ -long *dataType; /* Out -- Variables' data type. */ -long *numElems; /* Out -- Variable's number of elements. */ -long *numDims; /* Out -- Variable's number of dimensions. */ -long *dimSizes; /* Out -- Variable's dimensional sizes. */ -long *recVary; /* Out -- Variable's record vary. */ -long *dimVarys; /* Out -- Variable's dimensional vary. */ - -{ - CDFstatus pStatus = CDF_OK; - - if (!sX(CDFgetzVarDataType(id,varNum,dataType), &pStatus)) return pStatus; - if (!sX(CDFgetzVarNumElements(id,varNum,numElems), &pStatus)) return pStatus; - if (!sX(CDFgetzVarNumDims(id,varNum,numDims), &pStatus)) return pStatus; - if (!sX(CDFgetzVarDimSizes(id,varNum,dimSizes), &pStatus)) return pStatus; - if (!sX(CDFgetzVarRecVariance(id,varNum,recVary), &pStatus)) return pStatus; - if (!sX(CDFgetzVarDimVariances(id,varNum,dimVarys), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFreadzVarAllByVarID. -* Acquire data from all records for a given zVariable (by zVar id). -* Retrieved data are filled into the buffer. For sparse record variables, -* virtual records will be filled with specified value. This function passes -* back the pointer to the dynamically allocated space for the retrieved data. -* The variable's spec is also returned with this function. -* : Caller is responsible to free the allocated space. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFreadzVarAllByVarID (id, varNum, numRecs, dataType, - numElems, numDims, dimSizes, - recVary, dimVarys, buffer) -CDFid id; /* In -- CDF id. */ -long varNum; /* In -- Variable number. */ -long *numRecs; /* Out -- Variable number of written records. */ -long *dataType; /* Out -- Variables' data type. */ -long *numElems; /* Out -- Variable's number of elements. */ -long *numDims; /* Out -- Variable's number of dimensions. */ -long *dimSizes; /* Out -- Variable's dimensional sizes. */ -long *recVary; /* Out -- Variable's record vary. */ -long *dimVarys; /* Out -- Variable's dimensional vary. */ -CDFdata *buffer; /* Out -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - int i; - long lastRec, totalValues; - long indices[CDF_MAX_DIMS], intervals[CDF_MAX_DIMS]; - void *buf; - - *buffer = (CDFdata) NULL; - *numRecs = 0L; - if (!sX(CDFgetzVarDataType(id,varNum,dataType), &pStatus)) return pStatus; - if (!sX(CDFgetzVarNumElements(id,varNum,numElems), &pStatus)) return pStatus; - if (!sX(CDFgetzVarNumDims(id,varNum,numDims), &pStatus)) return pStatus; - if (!sX(CDFgetzVarDimSizes(id,varNum,dimSizes), &pStatus)) return pStatus; - if (!sX(CDFgetzVarRecVariance(id,varNum,recVary), &pStatus)) return pStatus; - if (!sX(CDFgetzVarDimVariances(id,varNum,dimVarys), &pStatus)) return pStatus; - if (!sX(CDFgetVarMaxWrittenRecNum(id,1,varNum,&lastRec), &pStatus)) - return pStatus; - if (lastRec == -1) return CDF_OK; - *numRecs = lastRec + 1; - totalValues = *numRecs; - for (i = 0; i < (int) *numDims; ++i) { - indices[i] = 0L; - intervals[i] = 1L; - totalValues *= dimSizes[i]; - } - buf = (void *) malloc ((size_t) CDFelemSize (*dataType) * totalValues * - *numElems); - if (buf == NULL) return BAD_MALLOC; - if (!sX(CDFlib(SELECT_, CDF_, id, - zVAR_, varNum, - zVAR_RECNUMBER_, 0L, - zVAR_RECCOUNT_, *numRecs, - zVAR_RECINTERVAL_, 1L, - zVAR_DIMINDICES_, indices, - zVAR_DIMCOUNTS_, dimSizes, - zVAR_DIMINTERVALS_, intervals, - GET_, zVAR_HYPERDATA_, buf, - NULL_), &pStatus)) return pStatus; - *buffer = (CDFdata) buf; - return pStatus; -} - -/****************************************************************************** -* CDFreadzVarDataByVarID. -* Acquire data from all records for a given zVariable (by zVar id). -* Retrieved data are filled into the buffer. For sparse record variables, -* virtual records will be filled with specified value. This function passes -* back the pointer to the dynamically allocated space for the retrieved data. -* No variable spec is returned with this function. -* : Caller is responsible to free the allocated space. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFreadzVarDataByVarID (id, varNum, numRecs, buffer) -CDFid id; /* In -- CDF id. */ -long varNum; /* In -- Variable number. */ -long *numRecs; /* Out -- Number of records read into buffer. */ -CDFdata *buffer; /* Out -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - int i; - long dataType, numElems, numDims, lastRec, totalValues; - long dimSizes[CDF_MAX_DIMS], indices[CDF_MAX_DIMS], intervals[CDF_MAX_DIMS]; - void *buf; - - *buffer = (CDFdata) NULL; - *numRecs = 0L; - if (!sX(CDFgetzVarDataType(id,varNum,&dataType), &pStatus)) return pStatus; - if (!sX(CDFgetzVarNumElements(id,varNum,&numElems), &pStatus)) return pStatus; - if (!sX(CDFgetzVarNumDims(id,varNum,&numDims), &pStatus)) return pStatus; - if (!sX(CDFgetzVarDimSizes(id,varNum,dimSizes), &pStatus)) return pStatus; - if (!sX(CDFgetVarMaxWrittenRecNum(id,1,varNum,&lastRec), &pStatus)) - return pStatus; - if (lastRec == -1) return CDF_OK; - totalValues = lastRec + 1L; - for (i = 0; i < (int) numDims; ++i) { - indices[i] = 0L; - intervals[i] = 1L; - totalValues *= dimSizes[i]; - } - buf = (void *) malloc ((size_t) CDFelemSize (dataType) * totalValues * - numElems); - if (buf == NULL) return BAD_MALLOC; - if (!sX(CDFlib(SELECT_, CDF_, id, - zVAR_, varNum, - zVAR_RECNUMBER_, 0L, - zVAR_RECCOUNT_, (lastRec + 1L), - zVAR_RECINTERVAL_, 1L, - zVAR_DIMINDICES_, indices, - zVAR_DIMCOUNTS_, dimSizes, - zVAR_DIMINTERVALS_, intervals, - GET_, zVAR_HYPERDATA_, buf, - NULL_), &pStatus)) return pStatus; - *buffer = (CDFdata) buf; - *numRecs = lastRec + 1L; - return pStatus; -} - -/****************************************************************************** -* CDFreadzVarRangeDataByVarID. -* Acquire a range of records from a given zVariable (by zVar id). -* Retrieved data are filled into the buffer. For a sparse record variable, -* virtual record will be filled with specified value(s). This function passes -* back the pointer to the dynamically allocated space for the retrieved data. -* No spec from this variable is returned with this function. -* : Caller is responsible to free the allocated space. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFreadzVarRangeDataByVarID (id, varNum, strNum, - stpNum, buffer) -CDFid id; /* In -- CDF id. */ -long varNum; /* In -- Variable number. */ -long strNum; /* In -- Variable starting record number. */ -long stpNum; /* In -- Variable stopping record number. */ -CDFdata *buffer; /* Out -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - int i, j; - long dataType, numElems, numDims, totalValues; - long dimSizes[CDF_MAX_DIMS], indices[CDF_MAX_DIMS], intervals[CDF_MAX_DIMS]; - void *buf; - - *buffer = (CDFdata) NULL; - if (strNum > stpNum || stpNum < 0) return CANNOT_ALLOCATE_RECORDS; - if (!sX(CDFgetzVarDataType(id,varNum,&dataType), &pStatus)) return pStatus; - if (!sX(CDFgetzVarNumElements(id,varNum,&numElems), &pStatus)) return pStatus; - if (!sX(CDFgetzVarNumDims(id,varNum,&numDims), &pStatus)) return pStatus; - if (!sX(CDFgetzVarDimSizes(id,varNum,dimSizes), &pStatus)) return pStatus; - totalValues = stpNum - strNum + 1L; - for (i = 0; i < (int) numDims; ++i) { - indices[i] = 0L; - intervals[i] = 1L; - totalValues *= dimSizes[i]; - } - buf = (void *) malloc ((size_t) CDFelemSize (dataType) * totalValues * - numElems); - if (buf == NULL) return BAD_MALLOC; - if (!sX(CDFlib(SELECT_, CDF_, id, - zVAR_, varNum, - zVAR_RECNUMBER_, strNum, - zVAR_RECCOUNT_, (stpNum-strNum+1L), - zVAR_RECINTERVAL_, 1L, - zVAR_DIMINDICES_, indices, - zVAR_DIMCOUNTS_, dimSizes, - zVAR_DIMINTERVALS_, intervals, - GET_, zVAR_HYPERDATA_, buf, - NULL_), &pStatus)) return pStatus; - *buffer = (CDFdata) buf; - return pStatus; -} - -/****************************************************************************** -* CDFreadzVarAllByVarName. -* Acquire data from all records for a given variable (by its unique name). -* Retrieved data are filled into the buffer. For sparse record variables, -* virtual records will be filled with specified value. This function passes -* back the pointer to the dynamically allocated space for the retrieved data. -* The variable's spec is also returned with this function. -* : Caller is responsible to free the allocated space. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFreadzVarAllByVarName (id, varName, numRecs, - dataType, numElems, numDims, - dimSizes, recVary, dimVarys, - buffer) -CDFid id; /* In -- CDF id. */ -char *varName; /* In -- Variable name. */ -long *numRecs; /* Out -- Variable number of written records. */ -long *dataType; /* Out -- Variables' data type. */ -long *numElems; /* Out -- Variable's number of elements. */ -long *numDims; /* Out -- Variable's number of dimensions. */ -long *dimSizes; /* Out -- Variable's dimensional sizes. */ -long *recVary; /* Out -- Variable's record vary. */ -long *dimVarys; /* Out -- Variable's dimensional vary. */ -CDFdata *buffer; /* Out -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - long varNum; - - *numRecs = 0L; - *buffer = (CDFdata) NULL; - varNum = CDFgetVarNum(id, varName); - if (varNum < 0) return NO_SUCH_VAR; - if (!sX(CDFreadzVarAllByVarID(id,varNum,numRecs,dataType,numElems,numDims, - dimSizes,recVary, - dimVarys,buffer), - &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFreadzVarDataByVarName. -* Acquire data from all records for a given variable (by its unique name). -* Retrieved data are filled into the buffer. For sparse record variables, -* virtual records will be filled with specified value. This function passes -* back the pointer to the dynamically allocated space for the retrieved data. -* No spec from the variable is returned with this function. -* : Caller is responsible to free the allocated space. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFreadzVarDataByVarName (id, varName, numRecs, - buffer) -CDFid id; /* In -- CDF id. */ -char *varName; /* In -- Variable name. */ -long *numRecs; /* Out -- Number of records read into the buffer. */ -CDFdata *buffer; /* Out -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - long varNum; - - *buffer = (CDFdata) NULL; - *numRecs = 0; - varNum = CDFgetVarNum(id, varName); - if (varNum < 0) return NO_SUCH_VAR; - if (!sX(CDFreadzVarDataByVarID(id,varNum,numRecs,buffer), - &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFreadzVarRangeDataByVarName. -* Acquire a range of records for a given variable (by its unique name). -* Retrieved data are filled into the buffer. For a sparse record variable, -* virtual records will be filled with specified value(s). This function passes -* back the pointer to the dynamically allocated space for the retrieved data. -* The variable's spec is also returned with this function. -* : Caller is responsible to free the allocated space. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFreadzVarRangeDataByVarName (id, varName, strNum, - stpNum, buffer) -CDFid id; /* In -- CDF id. */ -char *varName; /* In -- Variable name. */ -long strNum; /* In -- Variable starting record number. */ -long stpNum; /* In -- Variable stopping record number. */ -CDFdata *buffer; /* Out -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - int zVar; - long varNum; - - *buffer = (CDFdata) NULL; - varNum = CDFgetVarNum(id, varName); - if (varNum < 0) return NO_SUCH_VAR; - if (!sX(CDFreadzVarRangeDataByVarID(id,varNum,strNum,stpNum,buffer), - &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFreadzVarPadValue. -* Acquire the pad data for a given variable (by its variable id). -* The status will return NO_PADVALUE_SPECIFIED (1005) if the pad value is not -* set. Otherwise, CDF_OK (0) is returned. -* : Caller is responsible to free the allocated space. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFreadzVarPadValue (id, varNum, dataType, numElms, - buffer) -CDFid id; /* In -- CDF id. */ -long varNum; /* In -- Variable id. */ -long *dataType; /* Out -- Pad value's data type (same as variable's).*/ -long *numElms; /* Out -- Pad value's number of elements. */ -CDFdata *buffer; /* Out -- Buffer for holding the pad data. */ - -{ - CDFstatus pStatus = CDF_OK; - void *temp; - - *buffer = (CDFdata) NULL; - pStatus = CDFgetzVarDataType(id, varNum, dataType); - pStatus = CDFgetzVarNumElements(id, varNum, numElms); - temp = (void *) malloc (CDFelemSize(*dataType) * *numElms + - (STRINGdataType(*dataType)?1:0)); - if (!sX(CDFgetzVarPadValue(id,varNum,temp),&pStatus)) return pStatus; - if (STRINGdataType(*dataType)) *((char *)temp+*numElms) = '\0'; - *buffer = (CDFdata) temp; - return pStatus; -} - -/****************************************************************************** -* CDFputVarAllRecordsByVarID. -* Write a numbr of records for a given variable (by zVar flag and id), -* staring from record 0. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFputVarAllRecordsByVarID (id, zVar, varNum, numRecs, - buffer) -CDFid id; /* In -- CDF id. */ -int zVar; /* In -- Flag for zVariable. */ -long varNum; /* In -- Variable number. */ -long numRecs; /* In -- Number of Records to write. */ -void *buffer; /* In -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - int i; - long numDims, maxRec; - long indices[CDF_MAX_DIMS], intervals[CDF_MAX_DIMS], dimSizes[CDF_MAX_DIMS]; - - if (zVar == 1) { - if (!sX(CDFgetzVarNumDims(id,varNum,&numDims), &pStatus)) return pStatus; - if (!sX(CDFgetzVarDimSizes(id,varNum,dimSizes), &pStatus)) return pStatus; - } else { - if (!sX(CDFgetrVarsNumDims(id,&numDims), &pStatus)) return pStatus; - if (!sX(CDFgetrVarsDimSizes(id,dimSizes), &pStatus)) return pStatus; - } - for (i = 0; i < (int) numDims; ++i) { - indices[i] = 0L; - intervals[i] = 1L; - } - if (!sX(CDFgetVarMaxWrittenRecNum(id,zVar,varNum,&maxRec),&pStatus)) - return pStatus; - if (!sX(CDFlib(SELECT_, CDF_, id, - BOO((zVar==1),zVAR_,rVAR_), varNum, - BOO((zVar==1),zVAR_RECNUMBER_,rVARs_RECNUMBER_),0L, - BOO((zVar==1),zVAR_RECCOUNT_,rVARs_RECCOUNT_), - numRecs, - BOO((zVar==1),zVAR_RECINTERVAL_,rVARs_RECINTERVAL_), - 1L, - BOO((zVar==1),zVAR_DIMINDICES_,rVARs_DIMINDICES_), - indices, - BOO((zVar==1),zVAR_DIMCOUNTS_,rVARs_DIMCOUNTS_), - dimSizes, - BOO((zVar==1),zVAR_DIMINTERVALS_,rVARs_DIMINTERVALS_), - intervals, - PUT_, BOO((zVar==1),zVAR_HYPERDATA_,rVAR_HYPERDATA_),buffer, - NULL_), &pStatus)) return pStatus; - /**************************************************************************** - * Update maximum record numbers. - ****************************************************************************/ - if (maxRec > (numRecs-1)) { - if (!sX(CDFlib(DELETE_, BOO((zVar==1),zVAR_RECORDS_,rVAR_RECORDS_), - numRecs, maxRec, - NULL_), &pStatus)) return pStatus; - } - return pStatus; -} - -/****************************************************************************** -* CDFputVarAllRecordsByVarName. -* Write a number of records for a given variable (by its unique name), staring -* from record 0. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFputVarAllRecordsByVarName (id, varName, numRecs, - buffer) -CDFid id; /* In -- CDF id. */ -char *varName; /* In -- Variable name. */ -long numRecs; /* In -- Number of Records to write. */ -void *buffer; /* In -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - int zVar; - long varNum; - - varNum = CDFgetVarNum(id, varName); - if (varNum < 0) return NO_SUCH_VAR; - if (CDFconfirmVarExistence(id, 1, varName) == CDF_OK) zVar = 1; - else zVar = 0; - if (!sX(CDFputVarAllRecordsByVarID(id,zVar,varNum,numRecs,buffer), &pStatus)) - return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFgetVarRangeRecordsByVarID. -* Acquire data from a range of records for a given variable (by zVar flag and -* id). Retrieved data are filled into the buffer. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFgetVarRangeRecordsByVarID (id, zVar, varNum, - startRec, stopRec, - buffer) -CDFid id; /* In -- CDF id. */ -int zVar; /* In -- Flag for zVariable. */ -long varNum; /* In -- Variable number. */ -long startRec; /* In -- Starting record number. */ -long stopRec; /* In -- Ending record number. */ -void *buffer; /* Out -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - int i; - long numDims; - long indices[CDF_MAX_DIMS], intervals[CDF_MAX_DIMS], dimSizes[CDF_MAX_DIMS]; - - if (zVar == 1) { - if (!sX(CDFgetzVarNumDims(id,varNum,&numDims), &pStatus)) return pStatus; - if (!sX(CDFgetzVarDimSizes(id,varNum,dimSizes), &pStatus)) return pStatus; - } else { - if (!sX(CDFgetrVarsNumDims(id,&numDims), &pStatus)) return pStatus; - if (!sX(CDFgetrVarsDimSizes(id,dimSizes), &pStatus)) return pStatus; - } - for (i = 0; i < (int) numDims; ++i) { - indices[i] = 0L; - intervals[i] = 1L; - } - if (!sX(CDFlib(SELECT_, CDF_, id, - BOO((zVar==1),zVAR_,rVAR_), varNum, - BOO((zVar==1),zVAR_RECNUMBER_,rVARs_RECNUMBER_), - startRec, - BOO((zVar==1),zVAR_RECCOUNT_,rVARs_RECCOUNT_), - stopRec-startRec+1, - BOO((zVar==1),zVAR_RECINTERVAL_,rVARs_RECINTERVAL_), - 1L, - BOO((zVar==1),zVAR_DIMINDICES_,rVARs_DIMINDICES_), - indices, - BOO((zVar==1),zVAR_DIMCOUNTS_,rVARs_DIMCOUNTS_), - dimSizes, - BOO((zVar==1),zVAR_DIMINTERVALS_,rVARs_DIMINTERVALS_), - intervals, - GET_, BOO((zVar==1),zVAR_HYPERDATA_,rVAR_HYPERDATA_),buffer, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFgetVarRangeRecordsByVarName. -* Acquire data from a range of records for a given variable (by its unique -* name). Retrieved data are filled into the buffer. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFgetVarRangeRecordsByVarName (id, varName, - startRec, stopRec, - buffer) -CDFid id; /* In -- CDF id. */ -char *varName; /* In -- Variable name. */ -long startRec; /* In -- Starting record number. */ -long stopRec; /* In -- Ending record number. */ -void *buffer; /* Out -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - int zVar; - long varNum; - - varNum = CDFgetVarNum(id, varName); - if (varNum < 0) return NO_SUCH_VAR; - if (CDFconfirmVarExistence(id, 1, varName) == CDF_OK) zVar = 1; - else zVar = 0; - if (!sX(CDFgetVarRangeRecordsByVarID(id,zVar,varNum,startRec,stopRec, - buffer), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFputVarRangeRecordsByVarID. -* Write a range of records for a given variable (by zVar flag and id). -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFputVarRangeRecordsByVarID (id, zVar, varNum, - startRec, stopRec, - buffer) -CDFid id; /* In -- CDF id. */ -int zVar; /* In -- Flag for zVariable. */ -long varNum; /* In -- Variable number. */ -long startRec; /* In -- Starting record number to write. */ -long stopRec; /* In -- Ending record number to write. */ -void *buffer; /* In -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - int i; - long numDims; - long indices[CDF_MAX_DIMS], intervals[CDF_MAX_DIMS], dimSizes[CDF_MAX_DIMS]; - - if (zVar == 1) { - if (!sX(CDFgetzVarNumDims(id,varNum,&numDims), &pStatus)) return pStatus; - if (!sX(CDFgetzVarDimSizes(id,varNum,dimSizes), &pStatus)) return pStatus; - } else { - if (!sX(CDFgetrVarsNumDims(id,&numDims), &pStatus)) return pStatus; - if (!sX(CDFgetrVarsDimSizes(id,dimSizes), &pStatus)) return pStatus; - } - for (i = 0; i < (int) numDims; ++i) { - indices[i] = 0L; - intervals[i] = 1L; - } - if (!sX(CDFlib(SELECT_, CDF_, id, - BOO((zVar==1),zVAR_,rVAR_), varNum, - BOO((zVar==1),zVAR_RECNUMBER_,rVARs_RECNUMBER_), - startRec, - BOO((zVar==1),zVAR_RECCOUNT_,rVARs_RECCOUNT_), - stopRec-startRec+1, - BOO((zVar==1),zVAR_RECINTERVAL_,rVARs_RECINTERVAL_), - 1L, - BOO((zVar==1),zVAR_DIMINDICES_,rVARs_DIMINDICES_), - indices, - BOO((zVar==1),zVAR_DIMCOUNTS_,rVARs_DIMCOUNTS_), - dimSizes, - BOO((zVar==1),zVAR_DIMINTERVALS_,rVARs_DIMINTERVALS_), - intervals, - PUT_, BOO((zVar==1),zVAR_HYPERDATA_,rVAR_HYPERDATA_),buffer, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFputVarRangeRecordsByVarName. -* Write a range of records for a given variable (by its unique name). -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFputVarRangeRecordsByVarName (id, varName, - startRec, stopRec, - buffer) -CDFid id; /* In -- CDF id. */ -char *varName; /* In -- Variable name. */ -long startRec; /* In -- Starting record number to write. */ -long stopRec; /* In -- Ending record number to write. */ -void *buffer; /* In -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - int zVar; - long varNum; - - varNum = CDFgetVarNum(id, varName); - if (varNum < 0) return NO_SUCH_VAR; - if (CDFconfirmVarExistence(id, 1, varName) == CDF_OK) zVar = 1; - else zVar = 0; - if (!sX(CDFputVarRangeRecordsByVarID(id,zVar,varNum,startRec,stopRec,buffer), - &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFinsertVarRecordsByVarID. -* Insert a number of records for a given variable (by zVar flag and id). -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFinsertVarRecordsByVarID (id, zVar, varNum, - startRec, numRecs, - buffer) -CDFid id; /* In -- CDF id. */ -int zVar; /* In -- Flag for zVariable. */ -long varNum; /* In -- Variable number. */ -long startRec; /* In -- Starting record number to insert. */ -long numRecs; /* In -- The number of records to insert. */ -void *buffer; /* In -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - int i; - long numDims, lastRec, dataType; - long indices[CDF_MAX_DIMS], intervals[CDF_MAX_DIMS], dimSizes[CDF_MAX_DIMS]; - long sparseness; - - if (numRecs < 1) return CDF_OK; - if (zVar == 1) { - if (!sX(CDFgetVarSparseRecords(id,1,varNum,&sparseness), &pStatus)) - return pStatus; - if (sparseness != NO_SPARSERECORDS) return CANNOT_INSERT_RECORDS; - if (!sX(CDFgetzVarNumDims(id,varNum,&numDims), &pStatus)) return pStatus; - if (!sX(CDFgetVarDataType(id,1,varNum,&dataType), &pStatus)) return pStatus; - if (!sX(CDFgetzVarDimSizes(id,varNum,dimSizes), &pStatus)) return pStatus; - if (!sX(CDFgetVarMaxWrittenRecNum(id,1,varNum,&lastRec), &pStatus)) - return pStatus; - } else { - if (!sX(CDFgetVarSparseRecords(id,0,varNum,&sparseness), &pStatus)) - return pStatus; - if (sparseness != NO_SPARSERECORDS) return CANNOT_INSERT_RECORDS; - if (!sX(CDFgetrVarsNumDims(id,&numDims), &pStatus)) return pStatus; - if (!sX(CDFgetVarDataType(id,0,varNum,&dataType), &pStatus)) return pStatus; - if (!sX(CDFgetrVarsDimSizes(id,dimSizes), &pStatus)) return pStatus; - if (!sX(CDFgetVarMaxWrittenRecNum(id,0,varNum,&lastRec), &pStatus)) - return pStatus; - } - for (i = 0; i < (int) numDims; ++i) { - indices[i] = 0L; - intervals[i] = 1L; - } - if (startRec <= lastRec) { - void *tmp; - long nRecordValues, startRecX, startRecY, recs, recs2; - int dimN; - for (dimN = 0, nRecordValues = 1; dimN < numDims; dimN++) { - nRecordValues *= dimSizes[dimN]; - } - recs2 = recs = lastRec - startRec + 1; - while (recs > 0) { - tmp = cdf_AllocateMemory ((size_t)recs * nRecordValues * - CDFelemSize(dataType), - NULL); - if (tmp != NULL) break; - recs = (int) (0.5 * recs + 0.5); - } - if (tmp == NULL) return BAD_MALLOC; - for (startRecX = lastRec - recs + 1; recs2 > 0; - recs2 -= recs, startRecX -= recs) { - if (startRecX < startRec) { - recs = recs - (startRec - startRecX); - startRecX = startRec; - } - if (!sX(CDFlib(SELECT_, CDF_, id, - BOO((zVar==1),zVAR_,rVAR_), varNum, - BOO((zVar==1),zVAR_RECNUMBER_,rVARs_RECNUMBER_), - startRecX, - BOO((zVar==1),zVAR_RECCOUNT_,rVARs_RECCOUNT_), - recs, - BOO((zVar==1),zVAR_RECINTERVAL_,rVARs_RECINTERVAL_), - 1L, - BOO((zVar==1),zVAR_DIMINDICES_,rVARs_DIMINDICES_), - indices, - BOO((zVar==1),zVAR_DIMCOUNTS_,rVARs_DIMCOUNTS_), - dimSizes, - BOO((zVar==1),zVAR_DIMINTERVALS_,rVARs_DIMINTERVALS_), - intervals, - GET_, BOO((zVar==1),zVAR_HYPERDATA_,rVAR_HYPERDATA_),tmp, - NULL_), &pStatus)) return pStatus; - startRecY = startRecX + numRecs; - if (!sX(CDFlib(SELECT_, CDF_, id, - BOO((zVar==1),zVAR_,rVAR_), varNum, - BOO((zVar==1),zVAR_RECNUMBER_,rVARs_RECNUMBER_), - startRecY, - BOO((zVar==1),zVAR_RECCOUNT_,rVARs_RECCOUNT_), - recs, - BOO((zVar==1),zVAR_RECINTERVAL_,rVARs_RECINTERVAL_), - 1L, - BOO((zVar==1),zVAR_DIMINDICES_,rVARs_DIMINDICES_), - indices, - BOO((zVar==1),zVAR_DIMCOUNTS_,rVARs_DIMCOUNTS_), - dimSizes, - BOO((zVar==1),zVAR_DIMINTERVALS_,rVARs_DIMINTERVALS_), - intervals, - PUT_, BOO((zVar==1),zVAR_HYPERDATA_,rVAR_HYPERDATA_),tmp, - NULL_), &pStatus)) return pStatus; - - } - cdf_FreeMemory (tmp, NULL); - } - if (!sX(CDFlib(SELECT_, CDF_, id, - BOO((zVar==1),zVAR_,rVAR_), varNum, - BOO((zVar==1),zVAR_RECNUMBER_,rVARs_RECNUMBER_), - startRec, - BOO((zVar==1),zVAR_RECCOUNT_,rVARs_RECCOUNT_), - numRecs, - BOO((zVar==1),zVAR_RECINTERVAL_,rVARs_RECINTERVAL_), - 1L, - BOO((zVar==1),zVAR_DIMINDICES_,rVARs_DIMINDICES_), - indices, - BOO((zVar==1),zVAR_DIMCOUNTS_,rVARs_DIMCOUNTS_), - dimSizes, - BOO((zVar==1),zVAR_DIMINTERVALS_,rVARs_DIMINTERVALS_), - intervals, - PUT_, BOO((zVar==1),zVAR_HYPERDATA_,rVAR_HYPERDATA_),buffer, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFinsertVarRecordsByVarName. -* Insert a number of records for a given variable (by its unique name). -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFinsertVarRecordsByVarName (id, varName, - startRec, numRecs, - buffer) -CDFid id; /* In -- CDF id. */ -char *varName; /* In -- Variable name. */ -long startRec; /* In -- Starting record number to insert. */ -long numRecs; /* In -- The number of records to insert. */ -void *buffer; /* In -- Buffer for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - int zVar; - long varNum; - - varNum = CDFgetVarNum(id, varName); - if (varNum < 0) return NO_SUCH_VAR; - if (CDFconfirmVarExistence(id, 1, varName) == CDF_OK) zVar = 1; - else zVar = 0; - if (!sX(CDFinsertVarRecordsByVarID(id,zVar,varNum,startRec,numRecs,buffer), - &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFgetVarsRecordDatabyNames. -* Acquire a full record data for a given record for a set of the selected -* r/zVariables. Retrieved data are filled into the buffers that are pointed to -* by the passed array of pointers. The selected variables are identified by -* their names. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFgetVarsRecordDatabyNames (id, zVar, numVars, - varNames, recNum, - buffptr) -CDFid id; /* In -- CDF id. */ -int zVar; /* In -- Flag for zVariable. */ -long numVars; /* In -- Number of variables. */ -char *varNames[]; /* In -- Array of variable names. */ -long recNum; /* In -- Record number to read. */ -void *buffptr[]; /* Out -- Array of buffer pointers for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - long dataType, numElems, numDims; - long dimSizes[CDF_MAX_DIMS], dimVarys[CDF_MAX_DIMS]; - long dataTypeSize, recNumValues, *phyRecSize; - long totalSize, offset, *varNums; - int i, j; - void *buffer; - - if (numVars <= 0) return pStatus; - - if (!sX(CDFlib(SELECT_, CDF_, id, - NULL_), &pStatus)) return pStatus; - - totalSize = 0; - phyRecSize = (long *) cdf_AllocateMemory ((size_t)numVars*sizeof(long)*2, NULL); - if (phyRecSize == NULL) return BAD_MALLOC; - varNums = phyRecSize+numVars; - - for (i = 0; i < numVars; i++) { - if (!sX(CDFlib(GET_, BOO((zVar==1),zVAR_NUMBER_,rVAR_NUMBER_), - varNames[i], &varNums[i], - NULL_), &pStatus)) return pStatus; - if (!sX(CDFlib(SELECT_, BOO((zVar==1),zVAR_,rVAR_), varNums[i], - GET_, BOO((zVar==1),zVAR_DATATYPE_,rVAR_DATATYPE_), - &dataType, - BOO((zVar==1),zVAR_NUMELEMS_,rVAR_NUMELEMS_), - &numElems, - BOO((zVar==1),zVAR_NUMDIMS_,rVARs_NUMDIMS_), - &numDims, - BOO((zVar==1),zVAR_DIMSIZES_,rVARs_DIMSIZES_), - dimSizes, - BOO((zVar==1),zVAR_DIMVARYS_,rVAR_DIMVARYS_), - dimVarys, - NULL_), &pStatus)) return pStatus; - if (!sX(CDFlib(GET_, DATATYPE_SIZE_, dataType, &dataTypeSize, - NULL_), &pStatus)) return pStatus; - - if (numDims == 0) { - numDims = 1; - dimSizes[0] = 1; - dimVarys[0] = 0; - } - - recNumValues = 1; - for (j = 0; j < numDims; j++) - if (dimVarys[j]) recNumValues *= dimSizes[j]; - phyRecSize[i] = recNumValues * dataTypeSize * numElems; - totalSize += phyRecSize[i]; - } - - buffer = (void *) cdf_AllocateMemory ((size_t)totalSize, NULL); - if (buffer == NULL) return BAD_MALLOC; - - if (!sX(CDFlib(SELECT_, BOO((zVar==1),zVARs_RECNUMBER_,rVARs_RECNUMBER_), - recNum, - GET_, BOO((zVar==1),zVARs_RECDATA_,rVARs_RECDATA_), numVars, - varNums, buffer, - NULL_), &pStatus)) return pStatus; - - offset = 0; - for (i = 0; i < numVars; i++) { - memcpy((char *) buffptr[i], (char *) buffer+offset, phyRecSize[i]); - offset += phyRecSize[i]; - } - cdf_FreeMemory (buffer, NULL); - cdf_FreeMemory (phyRecSize, NULL); - return CDF_OK; - -} - -/****************************************************************************** -* CDFputVarsRecordDatabyNames. -* Write a full record data for a given record for a set of the selected -* r/zVariables. Input data are pointed to by the passed array of pointers. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFputVarsRecordDatabyNames (id, zVar, numVars, - varNames, recNum, - buffptr) -CDFid id; /* In -- CDF id. */ -int zVar; /* In -- Flag for zVariable. */ -long numVars; /* In -- Number of variables. */ -char *varNames[]; /* In -- Array of variable names. */ -long recNum; /* In -- Record number to read. */ -void *buffptr[]; /* In -- Array of buffer pointers for holding data. */ - -{ - CDFstatus pStatus = CDF_OK; - long dataType, numElems, numDims; - long dimSizes[CDF_MAX_DIMS], dimVarys[CDF_MAX_DIMS]; - long dataTypeSize, recNumValues, *phyRecSize; - long totalSize, offset, *varNums; - int i, j; - void *buffer; - - if (numVars <= 0) return pStatus; - - if (!sX(CDFlib(SELECT_, CDF_, id, - NULL_), &pStatus)) return pStatus; - - phyRecSize = (long *) cdf_AllocateMemory ((size_t)numVars*sizeof(long)*2, NULL); - if (phyRecSize == NULL) return BAD_MALLOC; - varNums = phyRecSize+numVars; - - totalSize = 0; - for (i = 0; i < numVars; i++) { - if (!sX(CDFlib(GET_, BOO((zVar==1),zVAR_NUMBER_,rVAR_NUMBER_), - varNames[i], &varNums[i], - NULL_), &pStatus)) return pStatus; - if (!sX(CDFlib(SELECT_, BOO((zVar==1),zVAR_,rVAR_), varNums[i], - GET_, BOO((zVar==1),zVAR_DATATYPE_,rVAR_DATATYPE_), - &dataType, - BOO((zVar==1),zVAR_NUMELEMS_,rVAR_NUMELEMS_), - &numElems, - BOO((zVar==1),zVAR_NUMDIMS_,rVARs_NUMDIMS_), - &numDims, - BOO((zVar==1),zVAR_DIMSIZES_,rVARs_DIMSIZES_), - dimSizes, - BOO((zVar==1),zVAR_DIMVARYS_,rVAR_DIMVARYS_), - dimVarys, - NULL_), &pStatus)) return pStatus; - if (!sX(CDFlib(GET_, DATATYPE_SIZE_, dataType, &dataTypeSize, - NULL_), &pStatus)) return pStatus; - - if (numDims == 0) { - numDims = 1; - dimSizes[0] = 1; - dimVarys[0] = 0; - } - - recNumValues = 1; - for (j = 0; j < numDims; j++) - if (dimVarys[j]) recNumValues *= dimSizes[j]; - phyRecSize[i] = recNumValues * dataTypeSize * numElems; - totalSize += phyRecSize[i]; - } - - buffer = (void *) cdf_AllocateMemory ((size_t)totalSize, NULL); - if (buffer == NULL) return BAD_MALLOC; - - offset = 0; - for (i = 0; i < numVars; i++) { - memcpy((char *) buffer+offset, (char *) buffptr[i], phyRecSize[i]); - offset += phyRecSize[i]; - } - - if (!sX(CDFlib(SELECT_, BOO((zVar==1),zVARs_RECNUMBER_,rVARs_RECNUMBER_), - recNum, - PUT_, BOO((zVar==1),zVARs_RECDATA_,rVARs_RECDATA_), numVars, - varNums, buffer, - NULL_), &pStatus)) return pStatus; - - cdf_FreeMemory (buffer, NULL); - cdf_FreeMemory (phyRecSize, NULL); - return CDF_OK; - -} - -/****************************************************************************** -* CDFinquireAttrInfo. (Holding for backward version -- should not use) -* Can't implement with macro because the attribute's scope determines which -* item(s) to use. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFinquireAttrInfo (id, zEntry, attrNum, attrName, - scope, maxEntry) -CDFid id; /* In -- CDF id. */ -int zEntry; /* In -- Flag for zEntry. */ -long attrNum; /* In -- Attribute number. */ -char *attrName; /* Out -- Attribute name. */ -long *scope; /* Out -- Attribute scope. */ -long *maxEntry; /* Out -- Maximum g/r/zEntry number used. */ -{ - CDFstatus pStatus = CDF_OK; - if (!sX(CDFlib(SELECT_, CDF_, id, - ATTR_, attrNum, - GET_, ATTR_SCOPE_, scope, - NULL_), &pStatus)) return pStatus; - if (GLOBALscope(*scope) && (zEntry == 1)) return ILLEGAL_FOR_SCOPE; - if (!sX(CDFlib(GET_, ATTR_NAME_, attrName, - BOO((zEntry==1),ATTR_MAXzENTRY_, - (BOO(GLOBALscope(*scope),ATTR_MAXgENTRY_, - ATTR_MAXrENTRY_))), maxEntry, - NULL_), &pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CDFsetFileBackward. This function has precedence over the environment -* variable in determining whether a backward file is to be created. -******************************************************************************/ - -VISIBLE_PREFIX void CDFsetFileBackward (flag) -int flag; -{ - if (flag != 0) backward = 1; - else backward = 0; - /* - * Set setFileBackward flag. So, if the environment variable is also - * set, we can ignore that as calling CDFsetFileBackward function has - * precedence over the environment variable approach. - */ - setFileBackwardFlag = 1; -} - -/****************************************************************************** -* CDFsetFileBackward2. This function is called if the environment variable -* is set to create the backward file. However, if CDFsetFileBackward -* function has been called and as it has precedence over the environment -* variable, calling this function will have no effect at all. -******************************************************************************/ - -VISIBLE_PREFIX void CDFsetFileBackward2 (flag) -int flag; -{ - if (setFileBackwardFlag == 0) { /* True if CDFsetFileBackward is not */ - /* called. */ - if (flag != 0) backward = 1; - else backward = 0; - } -} - -/****************************************************************************** -* CDFsetChecksumMode. This function has precedence over the environment -* variable in determining whether a checksum is to be used. -******************************************************************************/ - -VISIBLE_PREFIX void CDFsetChecksumMode (flag) -long flag; -{ - checksum = flag; - /* - * Set setChecksum flag. So, if the environment variable is also - * set, we can ignore that as calling CDFsetChecksum function has - * precedence over the environment variable approach. - */ - setChecksumFlag = 1; -} - -/****************************************************************************** -* CDFgetFileBackward. -* Acquires the backward flag defined from CDFsetFileBackward function or -* the environment variable. -******************************************************************************/ - -VISIBLE_PREFIX int CDFgetFileBackward () -{ - return backward; -} - -/****************************************************************************** -* CDFgetChecksumMode. -* Acquires the checksum flag defined from CDFsetChecksum function or -* the environment variable. -******************************************************************************/ - -VISIBLE_PREFIX long CDFgetChecksumMode () -{ - return checksum; -} - -/****************************************************************************** -* CDFsetFileBackwardFlag. (Holding for backward version -- should not use.) -******************************************************************************/ - -VISIBLE_PREFIX void CDFsetFileBackwardFlag (flag) -int flag; -{ -/* - long version; - CDFstatus status; - status = CDFlib (GET_, LIB_VERSION_, &version, - NULL_); - if (version == 3) backward = flag; -*/ - backward = flag; -} - -/****************************************************************************** -* CDFgetFileBackwardFlag. (Holding for backward version -- should not use.) -******************************************************************************/ - -VISIBLE_PREFIX int CDFgetFileBackwardFlag () -{ - if (backward == 0) return 0; - else return 1; -} - -/****************************************************************************** -* CDFdeleteRecordsForAll. -* Delete a range of records for all variables in a CDF. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CDFdeleteRecordsForAll (id, startRec, endRec) -CDFid id; /* In -- CDF id. */ -long startRec; /* In -- Starting record to delete. */ -long endRec; /* In -- Ending record to delete. */ - -{ - CDFstatus pStatus = CDF_OK; - long numrVars, numzVars; - int i; - - if (!sX(CDFlib(SELECT_, CDF_, id, - GET_, CDF_NUMrVARS_, &numrVars, - CDF_NUMzVARS_, &numzVars, - NULL_), &pStatus)) return pStatus; - for (i = 0; i < (int) numrVars; i++) { - if (!sX(CDFlib(SELECT_, rVAR_, (long) i, - DELETE_, rVAR_RECORDS_RENUMBER_, startRec, endRec, - NULL_), &pStatus)) return pStatus; - } - for (i = 0; i < (int) numzVars; i++) { - if (!sX(CDFlib(SELECT_, zVAR_, (long) i, - DELETE_, zVAR_RECORDS_RENUMBER_, startRec, endRec, - NULL_), &pStatus)) return pStatus; - } - return CDF_OK; - -} - diff --git a/cdf36_3-dist/src/lib/cdfdel.c b/cdf36_3-dist/src/lib/cdfdel.c deleted file mode 100644 index abcbc6b..0000000 --- a/cdf36_3-dist/src/lib/cdfdel.c +++ /dev/null @@ -1,1995 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `delete' operations. -* -* Version 1.4b, 4-Mar-97, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 21-Aug-92, J Love CDF V2.3 (shareable/NeXT,zVar). -* V1.2 30-Nov-93, J Love CDF V2.4. Readonly mode, deleting V1 CDFs on -* all machines. -* V1.3 5-Dec-94, J Love CDF V2.5. -* V1.3a 6-Jan-95, J Love More cache-residency. -* V1.3b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.4 5-Sep-96, J Love CDF V2.6. -* V1.4a 21-Feb-97, J Love Removed RICE. -* V1.4b 4-Mar-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V2.0 08-Apr-04, M Liu Reset the current variable offset when that -* V2.1 08-Jan-09, M Liu Update the attrnum in AEDR when an attribute -* is deleted. -* V2.2 08-May-10, M Liu Reset firstRecInVVR/lastRecInVVR when a -* record(s) gets deleted. -* V2.3 09-May-14, M Liu Renumber the sparse records agter delete. -* -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* Local function prototypes. -******************************************************************************/ - -static CDFstatus WasteTree_r PROTOARGs(( - struct CDFstruct *CDF, Int32 vxrOffset -)); -static CDFstatus DeleteVarRecords PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 firstRec, Int32 lastRec, - Logical reNumber -)); -static CDFstatus DeleteRecords PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 firstRec, Int32 lastRec, - Int32 *deletedTo -)); -static CDFstatus DeleteRecords_r PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 firstVXRoffset, - Int32 firstRec, Int32 lastRec, Int32 *deletedTo, Logical *total -)); -static CDFstatus DeleteFromFront PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 last, - Int32 vxrOffset, struct VXRstruct *VXR, int entryN, Int32 irSize -)); -static CDFstatus DeleteFromMiddle PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 first, Int32 last, - Int32 vxrOffset, struct VXRstruct *VXR, int entryN, Int32 irSize -)); -static CDFstatus DeleteFromEnd PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 first, - Int32 vxrOffset, struct VXRstruct *VXR, int entryN, Int32 irSize -)); -static CDFstatus DeleteVXRentry PROTOARGs(( - struct CDFstruct *CDF, Int32 firstVXRoffset, Int32 delVXRoffset, - int delEntryN, Logical *total -)); -static CDFstatus InsertIndexEntry PROTOARGs(( - struct CDFstruct *CDF, Int32 vxrOffset, int entryN, Logical after, - Int32 first, Int32 last, Int32 offset -)); -static CDFstatus UpdateIndexEntries_r PROTOARGs(( - vFILE *fp, Int32 vxrOffset, Int32 aboveRecord, Int32 recordCount -)); -static CDFstatus WriteCVVRorVVR PROTOARGs(( - struct CDFstruct *CDF, Int32 cSize, Int32 stageOffset, Int32 uSize, - Int32 *newOffset -)); - -/****************************************************************************** -* CDFdel. -******************************************************************************/ - -STATICforIDL CDFstatus CDFdel (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ -CDFstatus tStatus, pStatus = CDF_OK; -switch (Va->item) { - /**************************************************************************** - * CDF_, delete an open CDF. - ****************************************************************************/ - case CDF_: { - struct CDFstruct *CDF; - SelectCDF (Cur->cdf, CDF) - if (!WriteAccess(CDF,TRUE,&pStatus)) return pStatus; - sX (DeleteCDFfiles(CDF), &pStatus); - if (CDF->uDotFp != NULL) { - if (!DELETEv(CDF->uDotFp,NULL)) sX (SCRATCH_DELETE_ERROR, &pStatus); - CDF->uDotFp = NULL; - } - if (CDF->stage.fp != NULL) { - if (!DELETEv(CDF->stage.fp,NULL)) sX (SCRATCH_DELETE_ERROR, &pStatus); - CDF->stage.fp = NULL; - } - if (CDF->compressFp != NULL) { - if (!DELETEv(CDF->compressFp,NULL)) sX (SCRATCH_DELETE_ERROR, &pStatus); - CDF->compressFp = NULL; - } - FreeCDFid (CDF, FALSE); - Cur->cdf = NULL; - break; - } - /**************************************************************************** - * zVAR_/rVAR_ - ****************************************************************************/ - case zVAR_: - case rVAR_: { - Logical zOp = (Va->item == zVAR_), zVar; - struct CDFstruct *CDF; struct VDRstruct VDR, VDRt; - Int32 vOffset, tOffset, rMaxRec = NO_RECORD, aOffset, eOffset; - Int32 scope, entryN, VDRhead, nVars; int varN; - /************************************************************************** - * Get pointer to current CDF and locate the current r/zVariable. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (!CDF->singleFile) return UNSUPPORTED_OPERATION; - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; -/* - if (!sX(LocateCurrentVar(CDF,zOp,&vOffset,&zVar,NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } -*/ - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) vOffset = CDF->CURzVarOffset; - else vOffset = CDF->CURrVarOffset; - - /************************************************************************** - * Read/get GDR field(s). - **************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - BOO(zVar,GDR_zVDRHEAD,GDR_rVDRHEAD),&VDRhead, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - nVars = BOO(zVar,CDF->NzVars,CDF->NrVars); - /************************************************************************** - * Read the VDR. - **************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,vOffset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)){ - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Switch to write access. - **************************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Remove the VDR from the list of r/zVariables and decrement the number - * of r/zVariables. If this is a true rVariable, check for the maximum - * record number written for the rVariables up to the one being deleted. - **************************************************************************/ - if (VDRhead == vOffset) - VDRhead = VDR.VDRnext; - else { - tOffset = VDRhead; - while (tOffset != 0) { - if (!sX(ReadVDR(CDF,CDF->fp,tOffset,zVar, - VDR_RECORD,&VDRt,NULL, - VDR_NULL),&pStatus)){ - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!zVar) rMaxRec = MAXIMUM (rMaxRec, VDRt.MaxRec); - if (VDRt.VDRnext == vOffset) { - VDRt.VDRnext = VDR.VDRnext; - if (!sX(WriteVDR(CDF,CDF->fp,tOffset,zVar, - VDR_RECORD,&VDRt,NULL, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - tOffset = VDRt.VDRnext; - } - if (tOffset == 0) { - AbortAccess (CDF, UPDATE, noDELETE); - return CORRUPTED_V2_CDF; - } - } - nVars--; - /************************************************************************** - * Renumber following VDRs. If this is a true rVariable, continue checking - * for the maximum record number written. - **************************************************************************/ - tOffset = VDR.VDRnext; - while (tOffset != 0) { - if (!sX(ReadVDR(CDF,CDF->fp,tOffset,zVar, - VDR_RECORD,&VDRt,NULL, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!zVar) rMaxRec = MAXIMUM (rMaxRec, VDRt.MaxRec); - VDRt.Num--; - if (!sX(WriteVDR(CDF,CDF->fp,tOffset,zVar, - VDR_RECORD,&VDRt,NULL, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - tOffset = VDRt.VDRnext; - } - /************************************************************************** - * Write/store the GDR fields that may have changed. - **************************************************************************/ - if (!zVar) { - CDF->rMaxRec = rMaxRec; - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - GDR_rMAXREC,&rMaxRec, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - BOO(zVar,GDR_zVDRHEAD,GDR_rVDRHEAD),&VDRhead, - BOO(zVar,GDR_NzVARS,GDR_NrVARS),&nVars, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (zVar) - CDF->NzVars = nVars; - else - CDF->NrVars = nVars; - /************************************************************************** - * Waste VDR. - **************************************************************************/ - if (!sX(WasteIR(CDF,vOffset,VDR.RecordSize),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Waste CPR/SPR (if one exists). - **************************************************************************/ - if (VDR.CPRorSPRoffset != NO_OFFSET) { - Int32 irSize; - if (!sX(ReadIrSize(CDF->fp, - VDR.CPRorSPRoffset, - &irSize),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WasteIR(CDF,VDR.CPRorSPRoffset,irSize),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Waste VXRs and VVRs/CVVRs. - **************************************************************************/ - if (!sX(WasteTree_r(CDF,VDR.VXRhead),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Free/adjust variable data structures kept in memory. Note that the - * number of z/rVariables has already been decremented. - **************************************************************************/ - if (zVar) { - if (CDF->zVars[(int)VDR.Num] != NULL) { - cdf_FreeMemory (CDF->zVars[(int)VDR.Num], NULL); - } - for (varN = (int) VDR.Num; varN < nVars; varN++) { - CDF->zVars[varN] = CDF->zVars[varN+1]; - if (CDF->zVars[varN] != NULL) CDF->zVars[varN]->varN = varN; - } - CDF->zVars[varN] = NULL; - } - else { - if (CDF->rVars[(int)VDR.Num] != NULL) { - cdf_FreeMemory (CDF->rVars[(int)VDR.Num], NULL); - } - for (varN = (int) VDR.Num; varN < nVars; varN++) { - CDF->rVars[varN] = CDF->rVars[varN+1]; - if (CDF->rVars[varN] != NULL) CDF->rVars[varN]->varN = varN; - } - CDF->rVars[varN] = NULL; - } - /************************************************************************** - * Reset the current r/zVariable number. - **************************************************************************/ - if (zOp) { - CDF->CURzVarNum = RESERVED_VARNUM; - CDF->CURzVarOffset = 0; - } else { - CDF->CURrVarNum = RESERVED_VARNUM; - CDF->CURrVarOffset = 0; - } - /************************************************************************** - * Delete the associated attribute entries and renumber the entries that - * are associated with the variables that followed the variable that was - * deleted. - **************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_ADRHEAD,&aOffset, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - while (aOffset != 0) { - /************************************************************************ - * Read the scope of the attribute. - ************************************************************************/ - if (!sX(ReadADR(CDF->fp,aOffset, - ADR_SCOPE,&scope, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (VARIABLEscope(scope)) { - Int32 maxEntry = NO_ENTRY; - /********************************************************************** - * Delete associated entry. - **********************************************************************/ - tStatus = FindEntryByNumber (CDF, aOffset, zVar, VDR.Num, &eOffset); - switch (tStatus) { - case CDF_OK: - if (!sX(DeleteEntry(CDF,aOffset,eOffset),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - case NO_SUCH_ENTRY: - break; - default: - AbortAccess (CDF, UPDATE, noDELETE); - return tStatus; - } - /********************************************************************** - * Renumber entries. Note that the entry numbers are not necessarily - * increasing. (The entries may have been written in any order.) Also - * determine the new maximum entry number. - **********************************************************************/ - if (!sX(ReadADR(CDF->fp,aOffset, - BOO(zVar,ADR_AzEDRHEAD,ADR_AgrEDRHEAD),&eOffset, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - while (eOffset != 0) { - if (!sX(ReadAEDR(CDF->fp,eOffset, - AEDR_NUM,&entryN, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (entryN > VDR.Num) { - entryN--; - if (!sX(WriteAEDR(CDF,CDF->fp,eOffset, - AEDR_NUM,&entryN, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - maxEntry = MAXIMUM (maxEntry, entryN); - if (!sX(ReadAEDR(CDF->fp,eOffset, - AEDR_AEDRNEXT,&eOffset, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /********************************************************************** - * Write new maximum entry number to the ADR. - **********************************************************************/ - if (!sX(WriteADR(CDF->fp,aOffset, - BOO(zVar,ADR_MAXzENTRY,ADR_MAXgrENTRY),&maxEntry, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************ - * Read offset of next ADR. - ************************************************************************/ - if (!sX(ReadADR(CDF->fp,aOffset, - ADR_ADRNEXT,&aOffset, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Reset the current entry offset (in case it was affected). - **************************************************************************/ - if (!sX(BOO(zOp,SetCURzEntry(CDF,FALSE,CDF->CURzEntryNum), - SetCURgrEntry(CDF,FALSE,CDF->CURgrEntryNum)),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * rVAR_RECORDS_/zVAR_RECORDS_/rVAR_RECORDS_RENUMBER_/zVAR_RECORDS__RENUMBER_ - ****************************************************************************/ - case rVAR_RECORDS_: - case zVAR_RECORDS_: - case rVAR_RECORDS_RENUMBER_: - case zVAR_RECORDS_RENUMBER_: { - Logical zOp = (Va->item == zVAR_RECORDS_ || - Va->item == zVAR_RECORDS_RENUMBER_); - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 firstRec = (Int32) va_arg (Va->ap, long); - Int32 lastRec = (Int32) va_arg (Va->ap, long); - Logical reNumber; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!CDF->singleFile) { - sX (MULTI_FILE_FORMAT, &pStatus); - break; - } - if (firstRec < 0) return BAD_REC_NUM; - if (lastRec < 0) return BAD_REC_NUM; - if (lastRec < firstRec) return BAD_REC_NUM; - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (Va->item == rVAR_RECORDS_RENUMBER_ || - Va->item == zVAR_RECORDS_RENUMBER_) reNumber = TRUE; - else reNumber = FALSE; - if (!sX(DeleteVarRecords(CDF,Var,firstRec,lastRec,reNumber),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * ATTR_ - ****************************************************************************/ - case ATTR_: { - struct CDFstruct *CDF; - Int32 tOffset; - struct GDRstruct GDR; - struct ADRstruct ADR, ADRt; - struct AEDRstruct AEDRt; - Int32 eOffset, eNext; - /************************************************************************** - * Get pointer to current CDF and locate the current attribute. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED(CDF)) return NO_ATTR_SELECTED; - /************************************************************************** - * Read the GDR and ADR. - **************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_RECORD,&GDR, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(ReadADR(CDF->fp,CDF->CURattrOffset, - ADR_RECORD,&ADR, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Switch to write access. - **************************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Remove the ADR from the list of attributes and decrement the number of - * attributes. - **************************************************************************/ - if (GDR.ADRhead == CDF->CURattrOffset) - GDR.ADRhead = ADR.ADRnext; - else { - tOffset = GDR.ADRhead; - while (tOffset != 0) { - if (!sX(ReadADR(CDF->fp,tOffset, - ADR_RECORD,&ADRt, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (ADRt.ADRnext == CDF->CURattrOffset) break; - tOffset = ADRt.ADRnext; - } - if (tOffset == 0) { - AbortAccess (CDF, UPDATE, noDELETE); - return CORRUPTED_V2_CDF; - } - ADRt.ADRnext = ADR.ADRnext; - if (!sX(WriteADR(CDF->fp,tOffset, - ADR_RECORD,&ADRt, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - GDR.NumAttr--; - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - GDR_RECORD,&GDR, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Renumber each of the following attributes. - **************************************************************************/ - tOffset = ADR.ADRnext; - while (tOffset != 0) { - if (!sX(ReadADR(CDF->fp,tOffset, - ADR_RECORD,&ADRt, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - ADRt.Num--; - if (!sX(WriteADR(CDF->fp,tOffset, - ADR_RECORD,&ADRt, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - eOffset = ADRt.AgrEDRhead; - while (eOffset != 0) { - if (!sX(ReadAEDR(CDF->fp,eOffset, - AEDR_AEDRNEXT,&eNext, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteAEDR(CDF,CDF->fp,eOffset, - AEDR_ATTRNUM,&ADRt.Num, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - eOffset = eNext; - } - eOffset = ADRt.AzEDRhead; - while (eOffset != 0) { - if (!sX(ReadAEDR(CDF->fp,eOffset, - AEDR_AEDRNEXT,&eNext, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteAEDR(CDF,CDF->fp,eOffset, - AEDR_ATTRNUM,&ADRt.Num, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - eOffset = eNext; - } - tOffset = ADRt.ADRnext; - } - /************************************************************************** - * Waste the ADR and each of the AgrEDR and AzEDR's for the attribute. - **************************************************************************/ - if (!sX(WasteIR(CDF,CDF->CURattrOffset,ADR.RecordSize),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - tOffset = ADR.AgrEDRhead; - while (tOffset != 0) { - if (!sX(ReadAEDR(CDF->fp,tOffset, - AEDR_RECORD,&AEDRt,NULL, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WasteIR(CDF,tOffset,AEDRt.RecordSize),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - tOffset = AEDRt.AEDRnext; - } - tOffset = ADR.AzEDRhead; - while (tOffset != 0) { - if (!sX(ReadAEDR(CDF->fp,tOffset, - AEDR_RECORD,&AEDRt,NULL, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WasteIR(CDF,tOffset,AEDRt.RecordSize),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - tOffset = AEDRt.AEDRnext; - } - /************************************************************************** - * Reset the current attribute offset and current entry offsets. - **************************************************************************/ - CDF->CURattrOffset = RESERVED_ATTROFFSET; - CDF->CURgrEntryOffset = RESERVED_ENTRYOFFSET; - CDF->CURzEntryOffset = RESERVED_ENTRYOFFSET; - break; - } - /**************************************************************************** - * gENTRY_/zENTRY_/rENTRY_ - ****************************************************************************/ - case gENTRY_: - case zENTRY_: - case rENTRY_: { - int entryType = E3p(Va->item,gENTRY_,rENTRY_,zENTRY_); - struct CDFstruct *CDF; - Int32 eOffset; - /************************************************************************** - * Get pointer to current CDF, locate the current attribute, and verify - * that a current entry number has been selected. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED(CDF)) return NO_ATTR_SELECTED; - if (E3(entryType, - CDF->CURgrEntryNum, - CDF->CURgrEntryNum, - CDF->CURzEntryNum) == RESERVED_ENTRYNUM) return NO_ENTRY_SELECTED; - /************************************************************************** - * Verify that the operation being performed is legal for the attribute's - * scope. - **************************************************************************/ - if (!sX(CheckEntryOp(CDF,entryType),&pStatus)) return pStatus; - /************************************************************************** - * Switch to write access. - **************************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Locate the entry to be deleted. - **************************************************************************/ - eOffset = E3(entryType,CDF->CURgrEntryOffset, - CDF->CURgrEntryOffset, - CDF->CURzEntryOffset); - if (eOffset == RESERVED_ENTRYOFFSET) return NO_SUCH_ENTRY; - /************************************************************************** - * Delete the entry. - **************************************************************************/ - if (!sX(DeleteEntry(CDF,CDF->CURattrOffset,eOffset),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Reset the current entry offset (to indicate the entry no longer exists). - **************************************************************************/ - switch (entryType) { - case gENTRYt: - case rENTRYt: - CDF->CURgrEntryOffset = RESERVED_ENTRYOFFSET; - break; - case zENTRYt: - CDF->CURzEntryOffset = RESERVED_ENTRYOFFSET; - break; - } - break; - } - /**************************************************************************** - * Unknown item, must be the next function. - ****************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } -} -return pStatus; -} - -/****************************************************************************** -* WasteTree_r. -******************************************************************************/ - -static CDFstatus WasteTree_r (CDF, vxrOffset) -struct CDFstruct *CDF; -Int32 vxrOffset; -{ - CDFstatus pStatus = CDF_OK; - int e; struct VXRstruct VXR; Int32 irType, irSize; - while (vxrOffset != ZERO_OFFSET) { - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - if (!sX(WasteIR(CDF,vxrOffset,VXR.RecordSize),&pStatus)) return pStatus; - for (e = 0; e < VXR.NusedEntries; e++) { - if (!sX(ReadIrType(CDF->fp, - VXR.Offset[e], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - if (!sX(WasteTree_r(CDF,VXR.Offset[e]),&pStatus)) return pStatus; - break; - case VVR_: - case CVVR_: - if (!sX(ReadIrSize(CDF->fp, - VXR.Offset[e], - &irSize),&pStatus)) return pStatus; - if (!sX(WasteIR(CDF, - VXR.Offset[e], - irSize),&pStatus)) return pStatus; - break; - default: - return CORRUPTED_V2_CDF; - } - } - vxrOffset = VXR.VXRnext; - } - return pStatus; -} - -/****************************************************************************** -* DeleteVarRecords. -******************************************************************************/ - -static CDFstatus DeleteVarRecords (CDF, Var, firstRec, lastRec, reNumber) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 firstRec; -Int32 lastRec; -Logical reNumber; -{ - CDFstatus pStatus = CDF_OK; Int32 deletedTo, recNum; Logical found; - /**************************************************************************** - * Base on the variable type... - ****************************************************************************/ - switch (Var->vType) { - /************************************************************************** - * Standard variable in a single-file CDF. - **************************************************************************/ - case STANDARD_: { - Int32 vxrHead, aboveRecord, deleteCount; - /************************************************************************ - * Verify/adjust the records to be deleted. - ************************************************************************/ - if (firstRec > Var->maxAllocated) return pStatus; - lastRec = MINIMUM(lastRec,Var->maxAllocated); - /************************************************************************ - * Delete the records. - ************************************************************************/ - for (recNum = firstRec; recNum <= lastRec; recNum = deletedTo + 1) { - if (!sX(DeleteRecords(CDF,Var,recNum, - lastRec,&deletedTo),&pStatus)) return pStatus; - } - deleteCount = lastRec - firstRec + 1; - /************************************************************************ - * Update the index entries. - ************************************************************************/ - aboveRecord = firstRec - 1; - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_VXRHEAD,&vxrHead, - VDR_NULL),&pStatus)) return pStatus; - if (!sX(UpdateIndexEntries_r(CDF->fp,vxrHead,aboveRecord,deleteCount), - &pStatus)) - return pStatus; - /************************************************************************ - * Update the control information. - ************************************************************************/ - if (firstRec <= Var->maxWritten) { - if (lastRec > Var->maxWritten) - Var->maxWritten = firstRec - 1; - else - Var->maxWritten -= deleteCount; - } - if (firstRec <= Var->maxAllocated) { - if (lastRec > Var->maxAllocated) - Var->maxAllocated = firstRec - 1; - else - Var->maxAllocated -= deleteCount; - } - Var->firstRecInVVR = NO_RECORD; - Var->lastRecInVVR = NO_RECORD; - Var->offsetOfVVR = NO_OFFSET; - /************************************************************************ - * Update the maximum record field in the VDR. - ************************************************************************/ - if (firstRec <= Var->maxRec) { - if (lastRec > Var->maxRec) - Var->maxRec = firstRec - 1; - else - Var->maxRec -= deleteCount; - if (!sX(WriteVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_MAXREC,&(Var->maxRec), - VDR_NULL),&pStatus)) return pStatus; - } - break; - } - /************************************************************************** - * Sparse records. - **************************************************************************/ - case SPARSE_RECORDS_: { - Int32 aboveRecord, deleteCount; - Int32 vxrHead; Int32 maxRec; - /************************************************************************ - * Flush staging area first. This will automatically clear the staging - * area as well. - ************************************************************************/ - if (!sX(FlushStage(CDF,Var),&pStatus)) return pStatus; - /************************************************************************ - * Verify/adjust the records to be deleted. - ************************************************************************/ - if (firstRec > Var->maxAllocated) return pStatus; - lastRec = MINIMUM(lastRec,Var->maxAllocated); - /************************************************************************ - * Delete the records. - ************************************************************************/ - for (recNum = firstRec; recNum <= lastRec; recNum = deletedTo + 1) { - if (!sX(DeleteRecords(CDF,Var,recNum, - lastRec,&deletedTo),&pStatus)) return pStatus; - } - if (reNumber) { - deleteCount = lastRec - firstRec + 1; - /********************************************************************** - * Update the index entries. - **********************************************************************/ - aboveRecord = firstRec - 1; - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_VXRHEAD,&vxrHead, - VDR_NULL),&pStatus)) return pStatus; - if (!sX(UpdateIndexEntries_r(CDF->fp,vxrHead,aboveRecord,deleteCount), - &pStatus)) - return pStatus; - /********************************************************************** - * Update the control information. - **********************************************************************/ - if (firstRec <= Var->maxWritten) { - if (lastRec > Var->maxWritten) - Var->maxWritten = firstRec - 1; - else - Var->maxWritten -= deleteCount; - } - if (firstRec <= Var->maxAllocated) { - if (lastRec > Var->maxAllocated) - Var->maxAllocated = firstRec - 1; - else - Var->maxAllocated -= deleteCount; - } - /********************************************************************** - * Update the maximum record field in the VDR. - **********************************************************************/ - maxRec = Var->maxRec; - if (firstRec <= Var->maxRec) { - if (lastRec > Var->maxRec) - maxRec = firstRec - 1; - else - maxRec -= deleteCount; - if (!sX(WriteVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_MAXREC,&(maxRec), - VDR_NULL),&pStatus)) return pStatus; - } - if (INCLUSIVE(firstRec,Var->maxRec,lastRec)) { - if (!sX(PrevRecord(CDF,Var->VDRoffset,Var->zVar, - (Int32)(firstRec - 1), - &(Var->maxRec),&found),&pStatus)) return pStatus; - if (!found) Var->maxRec = NO_RECORD; - if (!sX(WriteVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_MAXREC,&(Var->maxRec), - VDR_NULL),&pStatus)) return pStatus; - } else - Var->maxRec = maxRec; - } else { - /********************************************************************** - * Update the control information. - **********************************************************************/ - if (INCLUSIVE(firstRec,Var->maxWritten,lastRec)) { - if (!sX(PrevRecord(CDF,Var->VDRoffset,Var->zVar, - (Int32)(firstRec - 1), - &(Var->maxWritten),&found),&pStatus)) return - pStatus; - if (!found) Var->maxWritten = NO_RECORD; - } - if (INCLUSIVE(firstRec,Var->maxAllocated,lastRec)) { - if (!sX(PrevRecord(CDF,Var->VDRoffset,Var->zVar, - (Int32)(firstRec - 1), - &(Var->maxAllocated),&found),&pStatus)) return - pStatus; - if (!found) Var->maxAllocated = NO_RECORD; - } - /********************************************************************** - * Update the maximum record field in the VDR. - **********************************************************************/ - if (INCLUSIVE(firstRec,Var->maxRec,lastRec)) { - if (!sX(PrevRecord(CDF,Var->VDRoffset,Var->zVar, - (Int32)(firstRec - 1), - &(Var->maxRec),&found),&pStatus)) return pStatus; - if (!found) Var->maxRec = NO_RECORD; - if (!sX(WriteVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_MAXREC,&(Var->maxRec), - VDR_NULL),&pStatus)) return pStatus; - } - } - Var->firstRecInVVR = NO_RECORD; - Var->lastRecInVVR = NO_RECORD; - Var->offsetOfVVR = NO_OFFSET; - break; - } - /************************************************************************** - * Compressed records. - **************************************************************************/ - case COMPRESSED_: { - Int32 vxrHead, aboveRecord, deleteCount; - /************************************************************************ - * Flush/clear staging area first. - ************************************************************************/ - if (!sX(FlushStage(CDF,Var),&pStatus)) return pStatus; - Var->stage.firstRec = NO_RECORD; - Var->stage.lastRec = NO_RECORD; - Var->stage.dotOffset = NO_OFFSET; - Var->firstRecInVVR = NO_RECORD; - Var->lastRecInVVR = NO_RECORD; - Var->offsetOfVVR = NO_OFFSET; - /************************************************************************ - * Verify/adjust the records to be deleted. - ************************************************************************/ - if (firstRec > Var->maxRec) return pStatus; - lastRec = MINIMUM(lastRec,Var->maxRec); - /************************************************************************ - * Delete the records. - ************************************************************************/ - for (recNum = firstRec; recNum <= lastRec; recNum = deletedTo + 1) { - if (!sX(DeleteRecords(CDF,Var,recNum, - lastRec,&deletedTo),&pStatus)) return pStatus; - } - deleteCount = lastRec - firstRec + 1; - /************************************************************************ - * Update the index entries. - ************************************************************************/ - aboveRecord = firstRec - 1; - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_VXRHEAD,&vxrHead, - VDR_NULL),&pStatus)) return pStatus; - if (!sX(UpdateIndexEntries_r(CDF->fp,vxrHead,aboveRecord,deleteCount), - &pStatus)) - return pStatus; - /************************************************************************ - * Update the maximum record field in the VDR. - ************************************************************************/ - if (firstRec <= Var->maxRec) { - if (lastRec > Var->maxRec) - Var->maxRec = firstRec - 1; - else - Var->maxRec -= deleteCount; - if (!sX(WriteVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_MAXREC,&(Var->maxRec), - VDR_NULL),&pStatus)) return pStatus; - } - break; - } - /************************************************************************** - * Sparse compressed records. - **************************************************************************/ - case SPARSE_COMPRESSED_RECORDS_: - /************************************************************************ - * Flush/clear staging area first. - ************************************************************************/ - if (!sX(FlushStage(CDF,Var),&pStatus)) return pStatus; - Var->stage.firstRec = NO_RECORD; - Var->stage.lastRec = NO_RECORD; - Var->stage.dotOffset = NO_OFFSET; - Var->firstRecInVVR = NO_RECORD; - Var->lastRecInVVR = NO_RECORD; - Var->offsetOfVVR = NO_OFFSET; - /************************************************************************ - * Verify/adjust the records to be deleted. - ************************************************************************/ - if (firstRec > Var->maxRec) return pStatus; - lastRec = MINIMUM(lastRec,Var->maxRec); - /************************************************************************ - * Delete the records. - ************************************************************************/ - for (recNum = firstRec; recNum <= lastRec; recNum = deletedTo + 1) { - if (!sX(DeleteRecords(CDF,Var,recNum, - lastRec,&deletedTo),&pStatus)) return pStatus; - } - /************************************************************************ - * Update the maximum record field in the VDR. - ************************************************************************/ - if (INCLUSIVE(firstRec,Var->maxRec,lastRec)) { - if (!sX(PrevRecord(CDF,Var->VDRoffset,Var->zVar, - (Int32)(firstRec - 1), - &(Var->maxRec),&found),&pStatus)) return pStatus; - if (!found) Var->maxRec = NO_RECORD; - if (!sX(WriteVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_MAXREC,&(Var->maxRec), - VDR_NULL),&pStatus)) return pStatus; - } - break; - /************************************************************************** - * Oops. - **************************************************************************/ - default: - return CDF_INTERNAL_ERROR; - } - /**************************************************************************** - * Update the VXR tail field in the VDR. - ****************************************************************************/ - if (!sX(UpdateVXRtailInVDR(CDF,Var),&pStatus)) return pStatus; - /**************************************************************************** - * Update the maximum record field in the GDR if an rVariable. This is - * done in case this rVariable had the maximum record number. - ****************************************************************************/ - if (!Var->zVar) { - Int32 maxRec, vdrOffset; Logical zVar = FALSE; - CDF->rMaxRec = NO_RECORD; - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_rVDRHEAD,&vdrOffset, - GDR_NULL),&pStatus)) return pStatus; - while (vdrOffset != ZERO_OFFSET) { - if (!sX(ReadVDR(CDF,CDF->fp,vdrOffset,zVar, - VDR_MAXREC,&maxRec, - VDR_VDRNEXT,&vdrOffset, - VDR_NULL),&pStatus)) return pStatus; - CDF->rMaxRec = MAXIMUM(CDF->rMaxRec,maxRec); - } - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - GDR_rMAXREC,&(CDF->rMaxRec), - GDR_NULL),&pStatus)) return pStatus; - } - return pStatus; -} - -/****************************************************************************** -* DeleteRecords. -******************************************************************************/ - -static CDFstatus DeleteRecords (CDF, Var, firstRec, lastRec, deletedTo) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 firstRec; -Int32 lastRec; -Int32 *deletedTo; -{ - CDFstatus pStatus = CDF_OK; Logical total = FALSE; Int32 vxrOffset; - /**************************************************************************** - * Read offset of the first VXR... - ****************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_VXRHEAD,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * ...and start there. - ****************************************************************************/ - if (!sX(DeleteRecords_r(CDF,Var,vxrOffset,firstRec, - lastRec,deletedTo,&total),&pStatus)) return pStatus; - /**************************************************************************** - * If the top level of VXR(s) was totally deleted, set the VXR head/tail to - * ZERO_OFFSET. - ****************************************************************************/ - if (total) { - Int32 zeroOffset = ZERO_OFFSET; - if (!sX(WriteVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_VXRHEAD,&zeroOffset, - VDR_VXRTAIL,&zeroOffset, - VDR_NULL),&pStatus)) return pStatus; - } - return pStatus; -} - -/****************************************************************************** -* DeleteRecords_r. -******************************************************************************/ - -static CDFstatus DeleteRecords_r (CDF, Var, firstVXRoffset, firstRec, lastRec, - deletedTo, total) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 firstVXRoffset; -Int32 firstRec; -Int32 lastRec; -Int32 *deletedTo; -Logical *total; -{ - CDFstatus pStatus = CDF_OK; Int32 vxrOffset = firstVXRoffset; - struct VXRstruct VXR; int entryN; - /**************************************************************************** - * While another VXR... - ****************************************************************************/ - while (vxrOffset != ZERO_OFFSET) { - /************************************************************************** - * Read the VXR. - **************************************************************************/ - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************** - * For each VXR entry... - **************************************************************************/ - for (entryN = 0; entryN < VXR.NusedEntries; entryN++) { - /*********************************************************************** - * If some of the records to be deleted are within this entry... - ***********************************************************************/ - if (!(lastRec < VXR.First[entryN] || firstRec > VXR.Last[entryN])) { - Int32 first = MAXIMUM(firstRec,VXR.First[entryN]); - Int32 last = MINIMUM(lastRec,VXR.Last[entryN]); - Int32 irType; - /********************************************************************* - * Determine the type of internal record pointed to by this entry. - *********************************************************************/ - if (!sX(ReadIrType(CDF->fp, - VXR.Offset[entryN], - &irType),&pStatus)) return pStatus; - /********************************************************************* - * Based on the type of internal record... - *********************************************************************/ - switch (irType) { - /******************************************************************* - * Another VXR (in a branch at a lower level)... - *******************************************************************/ - case VXR_: { - Logical totalBelow = FALSE; - /***************************************************************** - * Recursively call this routine... - *****************************************************************/ - if (!sX(DeleteRecords_r(CDF,Var,VXR.Offset[entryN], - first,last,deletedTo, - &totalBelow),&pStatus)) return pStatus; - /***************************************************************** - * If the branch of VXRs below has not been totally deleted, update - * this entry for the records that remain and return. - *****************************************************************/ - if (!totalBelow) { - struct VXRstruct VXRbelow; - if (!sX(ReadVXR(CDF->fp,VXR.Offset[entryN], - VXR_RECORD,&VXRbelow, - VXR_NULL),&pStatus)) return pStatus; - VXR.First[entryN] = VXRbelow.First[0]; - while (VXRbelow.VXRnext != ZERO_OFFSET) { - if (!sX(ReadVXR(CDF->fp,VXRbelow.VXRnext, - VXR_RECORD,&VXRbelow, - VXR_NULL),&pStatus)) return pStatus; - } - VXR.Last[entryN] = VXRbelow.Last[(int)VXRbelow.NusedEntries-1]; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - return pStatus; - } - /***************************************************************** - * The branch of VXRs below has been totally deleted. Delete this - * entry by moving the following entries up. If this is the last - * entry, indicate to the caller that this branch has been totally - * deleted. - *****************************************************************/ - if (!sX(DeleteVXRentry(CDF,firstVXRoffset, - vxrOffset,entryN,total),&pStatus)) return - pStatus; - return pStatus; - } - /******************************************************************* - * A VVR or CVVR... - *******************************************************************/ - case VVR_: - case CVVR_: { - Int32 irSize; - /***************************************************************** - * Read the size of the CVVR/VVR. - *****************************************************************/ - if (!sX(ReadIrSize(CDF->fp, - VXR.Offset[entryN], - &irSize),&pStatus)) return pStatus; - /***************************************************************** - * Based on which records in the CVVR/VVR are being deleted... - *****************************************************************/ - if (first > VXR.First[entryN]) { - if (last < VXR.Last[entryN]) { - if (!sX(DeleteFromMiddle(CDF,Var,first,last, - vxrOffset,&VXR, - entryN,irSize),&pStatus)) return - pStatus; - } - else { - if (!sX(DeleteFromEnd(CDF,Var,first, - vxrOffset,&VXR, - entryN,irSize),&pStatus)) return - pStatus; - } - } - else { - if (last < VXR.Last[entryN]) { - if (!sX(DeleteFromFront(CDF,Var,last, - vxrOffset,&VXR, - entryN,irSize),&pStatus)) return - pStatus; - } - else { - /************************************************************* - * The entire block of records (ie. the entire CVVR/VVR) is - * being deleted. - *************************************************************/ - if (!sX(WasteIR(CDF,VXR.Offset[entryN], - irSize),&pStatus)) return pStatus; - if (!sX(DeleteVXRentry(CDF,firstVXRoffset, - vxrOffset, - entryN,total),&pStatus)) return - pStatus; - } - } - *deletedTo = last; - return pStatus; - } - /******************************************************************* - * Something else - this is bad. - *******************************************************************/ - default: - return CORRUPTED_V2_CDF; - } - } - } - /************************************************************************** - * On to the next VXR... - **************************************************************************/ - vxrOffset = VXR.VXRnext; - } - /**************************************************************************** - * The records to be deleted do not exist... - ****************************************************************************/ - *deletedTo = lastRec; - return pStatus; -} - -/****************************************************************************** -* DeleteFromFront. -******************************************************************************/ - -static CDFstatus DeleteFromFront (CDF, Var, last, vxrOffset, VXR, entryN, - irSize) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 last; -Int32 vxrOffset; -struct VXRstruct *VXR; -int entryN; -Int32 irSize; -{ - CDFstatus pStatus = CDF_OK; - switch (Var->vType) { - case STANDARD_: - case SPARSE_RECORDS_: { - Int32 deleteOffset, nDeleteRecords, nRemainingBytes; - Int32 nDeleteBytes, nRecords2, offset2, nBytes2, recordSize; - /************************************************************************ - * The records being deleted are at the beginning of the VVR. First - * calculate needed offsets and sizes. - ************************************************************************/ - deleteOffset = VXR->Offset[entryN] + VVR_BASE_SIZE; - nDeleteRecords = last - VXR->First[entryN] + 1; - nDeleteBytes = nDeleteRecords * Var->NphyRecBytes; - nRecords2 = VXR->Last[entryN] - last; - nBytes2 = nRecords2 * Var->NphyRecBytes; - offset2 = VXR->Offset[entryN] + VVR_BASE_SIZE + nDeleteBytes; - nRemainingBytes = irSize - VVR_BASE_SIZE - nBytes2; - /************************************************************************ - * Slide the remaining records to the beginning of the VVR. - ************************************************************************/ - if (!sX(CopyBytes(CDF->fp,offset2, - CDF_READ_ERROR, - nBytes2,CDF->fp, - deleteOffset, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - /************************************************************************ - * Update the VXR entry. - ************************************************************************/ - VXR->First[entryN] = last + 1; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************ - * If possible, waste the unused bytes that are now at the end of the - * VVR (and update the record size field). Otherwise, the record size - * field of the VVR remains unchanged. - ************************************************************************/ - if (nRemainingBytes >= UIR_BASE_SIZE) { - Int32 offset = deleteOffset + nBytes2; - if (!sX(WasteIR(CDF,offset, - nRemainingBytes),&pStatus)) return pStatus; - recordSize = VVR_BASE_SIZE + nBytes2; - if (!sX(WriteVVR(CDF->fp,VXR->Offset[entryN], - VVR_RECORDSIZE,&recordSize, - VVR_NULL),&pStatus)) return pStatus; - } - break; - } - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: { - Int32 nRecords = VXR->Last[entryN] - VXR->First[entryN] + 1; - Int32 uSize = nRecords * Var->NphyRecBytes; - Int32 firstRecord2, nRecords2, offset2, nBytes2, cSize, newOffset; - /************************************************************************ - * Initialize staging area and scratch space. - ************************************************************************/ - if (Var->stage.areaOffset == NO_OFFSET) { - Int32 nBytes = Var->blockingFactor * Var->NphyRecBytes; - if (!sX(InitVarStage(CDF,Var,nBytes),&pStatus)) return pStatus; - } - if (!sX(InitScratch(ScratchDirectory(CDF), - &(CDF->compressFp), - CDF->compressCacheSize),&pStatus)) return pStatus; - /************************************************************************ - * Bring the CVVR/VVR to the staging area. - ************************************************************************/ - if (!sX(DecompressToStage(CDF,Var, - VXR->Offset[entryN], - uSize),&pStatus)) return pStatus; - /************************************************************************ - * Waste the CVVR/VVR. - ************************************************************************/ - if (!sX(WasteIR(CDF,VXR->Offset[entryN],irSize),&pStatus)) return - pStatus; - /************************************************************************ - * Calculate sizes/offsets for the block of remaining records. - ************************************************************************/ - firstRecord2 = last + 1; - nRecords2 = VXR->Last[entryN] - last; - if (nRecords2 <= 0) break; - offset2 = Var->stage.areaOffset + - (Var->NphyRecBytes * (firstRecord2 - VXR->First[entryN])); - nBytes2 = nRecords2 * Var->NphyRecBytes; - /************************************************************************ - * Compress the block of remaining records... - ************************************************************************/ - if (!sX(Compress(CDF->stage.fp,offset2, - nBytes2,SCRATCH_READ_ERROR, - Var->cType,Var->cParms, - CDF->compressFp,ZERO_OFFSET, - &cSize,SCRATCH_WRITE_ERROR),&pStatus)) return pStatus; - /************************************************************************ - * ...and allocate/write the CVVR/VVR. - ************************************************************************/ - if (!sX(WriteCVVRorVVR(CDF,cSize,offset2, - nBytes2,&newOffset),&pStatus)) return pStatus; - /************************************************************************ - * Update the index entry for the block of remaining records. - ************************************************************************/ - VXR->First[entryN] = firstRecord2; - VXR->Offset[entryN] = newOffset; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,VXR, - VXR_NULL),&pStatus)) return pStatus; - break; - } - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* DeleteFromMiddle. -******************************************************************************/ - -static CDFstatus DeleteFromMiddle (CDF, Var, first, last, vxrOffset, VXR, - entryN, irSize) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 first; -Int32 last; -Int32 vxrOffset; -struct VXRstruct *VXR; -int entryN; -Int32 irSize; -{ - CDFstatus pStatus = CDF_OK; - switch (Var->vType) { - case STANDARD_: - case SPARSE_RECORDS_: { - Int32 nRecords1, nBytes1, deleteOffset, nDeleteRecords; - Int32 nDeleteBytes, firstRecord2, lastRecord2, nRecords2, offset2; - Int32 nBytes2, nExtraBytes, recordSize, vvrOffset, vvr_ = VVR_; - Int32 nRemainingBytes; - /************************************************************************ - * A block of records will remain at the beginning and at the end. First - * calculate needed offsets and sizes. Note that the number of bytes in - * the second remaining block of records takes into account any extra - * bytes that may exist at the end of the VVR. - ************************************************************************/ - nRecords1 = first - VXR->First[entryN]; - nBytes1 = nRecords1 * Var->NphyRecBytes; - deleteOffset = VXR->Offset[entryN] + VVR_BASE_SIZE + nBytes1; - nDeleteRecords = last - first + 1; - nDeleteBytes = nDeleteRecords * Var->NphyRecBytes; - firstRecord2 = last + 1; - lastRecord2 = VXR->Last[entryN]; - nRecords2 = lastRecord2 - firstRecord2 + 1; - offset2 = deleteOffset + nDeleteBytes; - nBytes2 = nRecords2 * Var->NphyRecBytes; - nExtraBytes = irSize - VVR_BASE_SIZE - nBytes1 - nDeleteBytes - nBytes2; - /************************************************************************ - * If the second block of remaining records cannot remain in the same - * place... - ************************************************************************/ - if (nDeleteBytes < VVR_BASE_SIZE) { - /********************************************************************** - * Move the second block of remaining records to a new VVR. - **********************************************************************/ - recordSize = VVR_BASE_SIZE + nBytes2; - if (!sX(AllocateIR(CDF,recordSize,&vvrOffset),&pStatus)) return - pStatus; - if (!sX(WriteVVR(CDF->fp,vvrOffset, - VVR_RECORDSIZE,&recordSize, - VVR_RECORDTYPE,&vvr_, - VVR_NULL),&pStatus)) return pStatus; - if (!sX(CopyBytes(CDF->fp,offset2, - CDF_READ_ERROR, - nBytes2,CDF->fp, - (Int32)(vvrOffset + VVR_BASE_SIZE), - CDF_WRITE_ERROR),&pStatus)) return pStatus; - /********************************************************************** - * If the remaining bytes can be changed to a UIR... - **********************************************************************/ - nRemainingBytes = nDeleteBytes + nBytes2 + nExtraBytes; - if (nRemainingBytes >= UIR_BASE_SIZE) { - recordSize = VVR_BASE_SIZE + nBytes1; - if (!sX(WriteVVR(CDF->fp,VXR->Offset[entryN], - VVR_RECORDSIZE,&recordSize, - VVR_NULL),&pStatus)) return pStatus; - if (!sX(WasteIR(CDF,deleteOffset, - nRemainingBytes),&pStatus)) return pStatus; - } - /********************************************************************** - * Update the VXR entry for the first block of remaining records. - **********************************************************************/ - VXR->Last[entryN] = first - 1; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,VXR, - VXR_NULL),&pStatus)) return pStatus; - /********************************************************************** - * Insert a VXR entry for the new VVR created for the second block of - * remaining records. - **********************************************************************/ - if (!sX(InsertIndexEntry(CDF,vxrOffset, - entryN,(Logical)TRUE, - firstRecord2,lastRecord2, - vvrOffset),&pStatus)) return pStatus; - } - else { - /********************************************************************** - * Update record size field of VVR for the first block of remaining - * records and create a UIR for the bytes being "deleted" that are not - * going to be used for the new VVR containing the second block of - * remaining records. - **********************************************************************/ - nRemainingBytes = nDeleteBytes - VVR_BASE_SIZE; - if (nRemainingBytes < UIR_BASE_SIZE) - recordSize = VVR_BASE_SIZE + nBytes1 + nRemainingBytes; - else { - recordSize = VVR_BASE_SIZE + nBytes1; - if (!sX(WasteIR(CDF,deleteOffset, - nRemainingBytes),&pStatus)) return pStatus; - } - if (!sX(WriteVVR(CDF->fp,VXR->Offset[entryN], - VVR_RECORDSIZE,&recordSize, - VVR_NULL),&pStatus)) return pStatus; - /********************************************************************** - * Update the VXR entry for the first block of remaining records. - **********************************************************************/ - VXR->Last[entryN] = first - 1; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,VXR, - VXR_NULL),&pStatus)) return pStatus; - /********************************************************************** - * Write the record size and type fields of the new VVR for the second - * block of remaining records. - **********************************************************************/ - vvrOffset = offset2 - VVR_BASE_SIZE; - recordSize = VVR_BASE_SIZE + nBytes2 + nExtraBytes; - if (!sX(WriteVVR(CDF->fp,vvrOffset, - VVR_RECORDSIZE,&recordSize, - VVR_RECORDTYPE,&vvr_, - VVR_NULL),&pStatus)) return pStatus; - /********************************************************************** - * Insert a VXR entry for the new VVR created for the second block of - * remaining records. - **********************************************************************/ - if (!sX(InsertIndexEntry(CDF,vxrOffset, - entryN,(Logical)TRUE, - firstRecord2,lastRecord2, - vvrOffset),&pStatus)) return pStatus; - } - break; - } - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: { - Int32 nRecords = VXR->Last[entryN] - VXR->First[entryN] + 1; - Int32 uSize = nRecords * Var->NphyRecBytes; - Int32 nRecords1, nBytes1, firstRecord2, lastRecord2, nRecords2; - Int32 offset2, nBytes2, cSize, newOffset; - /************************************************************************ - * Initialize staging area and scratch space. - ************************************************************************/ - if (Var->stage.areaOffset == NO_OFFSET) { - Int32 nBytes = Var->blockingFactor * Var->NphyRecBytes; - if (!sX(InitVarStage(CDF,Var,nBytes),&pStatus)) return pStatus; - } - if (!sX(InitScratch(ScratchDirectory(CDF), - &(CDF->compressFp), - CDF->compressCacheSize),&pStatus)) return pStatus; - /************************************************************************ - * Bring the CVVR/VVR to the staging area. - ************************************************************************/ - if (!sX(DecompressToStage(CDF,Var, - VXR->Offset[entryN], - uSize),&pStatus)) return pStatus; - /************************************************************************ - * Waste the CVVR/VVR. - ************************************************************************/ - if (!sX(WasteIR(CDF,VXR->Offset[entryN],irSize),&pStatus)) return - pStatus; - /************************************************************************ - * Calculate sizes/offsets for the first and second blocks of remaining - * records. - ************************************************************************/ - nRecords1 = first - VXR->First[entryN]; - nBytes1 = nRecords1 * Var->NphyRecBytes; - firstRecord2 = last + 1; - lastRecord2 = VXR->Last[entryN]; - nRecords2 = lastRecord2 - firstRecord2 + 1; - offset2 = Var->stage.areaOffset + - (Var->NphyRecBytes * (firstRecord2 - VXR->First[entryN])); - nBytes2 = nRecords2 * Var->NphyRecBytes; - /************************************************************************ - * Compress the first block of remaining records... - ************************************************************************/ - if (!sX(Compress(CDF->stage.fp, - Var->stage.areaOffset, - nBytes1,SCRATCH_READ_ERROR, - Var->cType,Var->cParms, - CDF->compressFp,ZERO_OFFSET, - &cSize,SCRATCH_WRITE_ERROR),&pStatus)) return pStatus; - /************************************************************************ - * ...and allocate/write the CVVR/VVR. - ************************************************************************/ - if (!sX(WriteCVVRorVVR(CDF,cSize, - Var->stage.areaOffset, - nBytes1,&newOffset),&pStatus)) return pStatus; - /************************************************************************ - * Update the index entry for the first block of remaining records. - ************************************************************************/ - VXR->Last[entryN] = first - 1; - VXR->Offset[entryN] = newOffset; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************ - * Compress the second block of remaining records... - ************************************************************************/ - if (!sX(Compress(CDF->stage.fp,offset2, - nBytes2,SCRATCH_READ_ERROR, - Var->cType,Var->cParms, - CDF->compressFp,ZERO_OFFSET, - &cSize,SCRATCH_WRITE_ERROR),&pStatus)) return pStatus; - /************************************************************************ - * ...and allocate/write the CVVR/VVR. - ************************************************************************/ - if (!sX(WriteCVVRorVVR(CDF,cSize,offset2, - nBytes2,&newOffset),&pStatus)) return pStatus; - /************************************************************************ - * Insert a new index entry for the second block of remaining records. - ************************************************************************/ - if (!sX(InsertIndexEntry(CDF,vxrOffset, - entryN,(Logical)TRUE, - firstRecord2,lastRecord2, - newOffset),&pStatus)) return pStatus; - break; - } - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* DeleteFromEnd. -******************************************************************************/ - -static CDFstatus DeleteFromEnd (CDF, Var, first, vxrOffset, VXR, entryN, - irSize) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 first; -Int32 vxrOffset; -struct VXRstruct *VXR; -int entryN; -Int32 irSize; -{ - CDFstatus pStatus = CDF_OK; - switch (Var->vType) { - case STANDARD_: - case SPARSE_RECORDS_: { - Int32 nRecords1, nBytes1, deleteOffset, recordSize, nRemainingBytes; - /************************************************************************ - * First calculate needed offsets and sizes. - ************************************************************************/ - nRecords1 = first - VXR->First[entryN]; - nBytes1 = nRecords1 * Var->NphyRecBytes; - deleteOffset = VXR->Offset[entryN] + VVR_BASE_SIZE + nBytes1; - nRemainingBytes = irSize - VVR_BASE_SIZE - nBytes1; - /************************************************************************ - * Update the VXR entry. - ************************************************************************/ - VXR->Last[entryN] = first - 1; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************ - * If enough bytes are being deleted for a UIR, waste them and update - * the record size field of the VVR. - ************************************************************************/ - if (nRemainingBytes >= UIR_BASE_SIZE) { - if (!sX(WasteIR(CDF,deleteOffset, - nRemainingBytes),&pStatus)) return pStatus; - recordSize = VVR_BASE_SIZE + nBytes1; - if (!sX(WriteVVR(CDF->fp,VXR->Offset[entryN], - VVR_RECORDSIZE,&recordSize, - VVR_NULL),&pStatus)) return pStatus; - } - break; - } - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: { - Int32 nRecords = VXR->Last[entryN] - VXR->First[entryN] + 1; - Int32 uSize = nRecords * Var->NphyRecBytes; - Int32 nRecords1, nBytes1, cSize, newOffset; - /************************************************************************ - * Initialize staging area and scratch space. - ************************************************************************/ - if (Var->stage.areaOffset == NO_OFFSET) { - Int32 nBytes = Var->blockingFactor * Var->NphyRecBytes; - if (!sX(InitVarStage(CDF,Var,nBytes),&pStatus)) return pStatus; - } - if (!sX(InitScratch(ScratchDirectory(CDF), - &(CDF->compressFp), - CDF->compressCacheSize),&pStatus)) return pStatus; - /************************************************************************ - * Bring the CVVR/VVR to the staging area. - ************************************************************************/ - if (!sX(DecompressToStage(CDF,Var, - VXR->Offset[entryN], - uSize),&pStatus)) return pStatus; - /************************************************************************ - * Waste the CVVR/VVR. - ************************************************************************/ - if (!sX(WasteIR(CDF,VXR->Offset[entryN],irSize),&pStatus)) return - pStatus; - /************************************************************************ - * Calculate sizes/offsets for the block of remaining records. - ************************************************************************/ - nRecords1 = first - VXR->First[entryN]; - nBytes1 = nRecords1 * Var->NphyRecBytes; - /************************************************************************ - * Compress the block of remaining records... - ************************************************************************/ - if (!sX(Compress(CDF->stage.fp, - Var->stage.areaOffset, - nBytes1,SCRATCH_READ_ERROR, - Var->cType,Var->cParms, - CDF->compressFp,ZERO_OFFSET, - &cSize,SCRATCH_WRITE_ERROR),&pStatus)) return pStatus; - /************************************************************************ - * ...and allocate/write the CVVR/VVR. - ************************************************************************/ - if (!sX(WriteCVVRorVVR(CDF,cSize, - Var->stage.areaOffset, - nBytes1,&newOffset),&pStatus)) return pStatus; - /************************************************************************ - * Update the index entry for the block of remaining records. - ************************************************************************/ - VXR->Last[entryN] = first - 1; - VXR->Offset[entryN] = newOffset; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,VXR, - VXR_NULL),&pStatus)) return pStatus; - break; - } - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* DeleteVXRentry. -******************************************************************************/ - -static CDFstatus DeleteVXRentry (CDF, firstVXRoffset, delVXRoffset, delEntryN, - total) -struct CDFstruct *CDF; -Int32 firstVXRoffset; -Int32 delVXRoffset; -int delEntryN; -Logical *total; -{ - CDFstatus pStatus = CDF_OK; - Int32 vxrOffset = firstVXRoffset, prevVXRoffset = ZERO_OFFSET; - struct VXRstruct VXR, nextVXR; int entryN, lastEntryN; - /**************************************************************************** - * Find the VXR in which an entry is being deleted while keeping track of the - * previous VXR. - ****************************************************************************/ - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - while (vxrOffset != delVXRoffset) { - prevVXRoffset = vxrOffset; - vxrOffset = VXR.VXRnext; - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * Until done... - ****************************************************************************/ - for (;;) { - /************************************************************************* - * Move the following entries up. Nothing will happen if there is only - * one entry. - *************************************************************************/ - for (entryN = delEntryN + 1; entryN < VXR.NusedEntries; entryN++) { - VXR.First[entryN-1] = VXR.First[entryN]; - VXR.Last[entryN-1] = VXR.Last[entryN]; - VXR.Offset[entryN-1] = VXR.Offset[entryN]; - } - lastEntryN = (int) (VXR.NusedEntries - 1); - /************************************************************************* - * If a VXR does not follow, erase the last entry if there was more than - * one or waste the VXR is there was only one (entry). - *************************************************************************/ - if (VXR.VXRnext == ZERO_OFFSET) { - if (VXR.NusedEntries > 1) { - VXR.First[lastEntryN] = NO_RECORD; - VXR.Last[lastEntryN] = NO_RECORD; - VXR.Offset[lastEntryN] = NO_OFFSET; - VXR.NusedEntries--; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - } - else { - if (!sX(WasteIR(CDF,vxrOffset, - VXR.RecordSize),&pStatus)) return pStatus; - if (prevVXRoffset != ZERO_OFFSET) { - Int32 zeroOffset = ZERO_OFFSET; - if (!sX(WriteVXR(CDF->fp,prevVXRoffset, - VXR_VXRNEXT,&zeroOffset, - VXR_NULL),&pStatus)) return pStatus; - } - else - *total = TRUE; - } - return pStatus; - } - /************************************************************************* - * Otherwise, read the next VXR, set the current VXR's last entry to the - * first entry of the next VXR, rewrite the current VXR, and then set the - * current VXR to the next VXR and set the first entry to be deleted and - * continue... - *************************************************************************/ - if (!sX(ReadVXR(CDF->fp,VXR.VXRnext, - VXR_RECORD,&nextVXR, - VXR_NULL),&pStatus)) return pStatus; - VXR.First[lastEntryN] = nextVXR.First[0]; - VXR.Last[lastEntryN] = nextVXR.Last[0]; - VXR.Offset[lastEntryN] = nextVXR.Offset[0]; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - prevVXRoffset = vxrOffset; - vxrOffset = VXR.VXRnext; - VXR = nextVXR; - delEntryN = 0; - } -} - -/****************************************************************************** -* InsertIndexEntry. -******************************************************************************/ - -static CDFstatus InsertIndexEntry (CDF, vxrOffset, entryN, after, first, last, - offset) -struct CDFstruct *CDF; -Int32 vxrOffset; -int entryN; -Logical after; /* TRUE: Insert the new entry after `entryN'. - FALSE: Insert the new entry at `entryN'. */ -Int32 first; -Int32 last; -Int32 offset; -{ - CDFstatus pStatus = CDF_OK; struct VXRstruct VXR; int eN, lastEntryN; - Int32 pushedFirst, pushedLast, pushedOffset, newVXRoffset; - /**************************************************************************** - * Read the VXR. - ****************************************************************************/ - if (!sX(ReadVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * If there is room in this VXR for another entry, simply insert it. - ****************************************************************************/ - if (VXR.NusedEntries < VXR.Nentries) { - if (after) { - for (eN = (int) VXR.NusedEntries; eN > entryN + 1; eN--) { - VXR.First[eN] = VXR.First[eN-1]; - VXR.Last[eN] = VXR.Last[eN-1]; - VXR.Offset[eN] = VXR.Offset[eN-1]; - } - VXR.First[entryN+1] = first; - VXR.Last[entryN+1] = last; - VXR.Offset[entryN+1] = offset; - } - else { - for (eN = (int) VXR.NusedEntries; eN > entryN; eN--) { - VXR.First[eN] = VXR.First[eN-1]; - VXR.Last[eN] = VXR.Last[eN-1]; - VXR.Offset[eN] = VXR.Offset[eN-1]; - } - VXR.First[entryN] = first; - VXR.Last[entryN] = last; - VXR.Offset[entryN] = offset; - } - VXR.NusedEntries++; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * No room for another entry... - ****************************************************************************/ - lastEntryN = (int) (VXR.NusedEntries - 1); - if (after) { - if (entryN == lastEntryN) { - pushedFirst = first; - pushedLast = last; - pushedOffset = offset; - } - else { - pushedFirst = VXR.First[lastEntryN]; - pushedLast = VXR.Last[lastEntryN]; - pushedOffset = VXR.Offset[lastEntryN]; - for (eN = lastEntryN; eN > entryN + 1; eN--) { - VXR.First[eN] = VXR.First[eN-1]; - VXR.Last[eN] = VXR.Last[eN-1]; - VXR.Offset[eN] = VXR.Offset[eN-1]; - } - VXR.First[entryN+1] = first; - VXR.Last[entryN+1] = last; - VXR.Offset[entryN+1] = offset; - } - } - else { - pushedFirst = VXR.First[lastEntryN]; - pushedLast = VXR.Last[lastEntryN]; - pushedOffset = VXR.Offset[lastEntryN]; - for (eN = lastEntryN; eN > entryN; eN--) { - VXR.First[eN] = VXR.First[eN-1]; - VXR.Last[eN] = VXR.Last[eN-1]; - VXR.Offset[eN] = VXR.Offset[eN-1]; - } - VXR.First[entryN] = first; - VXR.Last[entryN] = last; - VXR.Offset[entryN] = offset; - } - /**************************************************************************** - * If this is the last VXR on the linked list, allocate a new VXR, update - * this VXR with the new VXR's offset, and write the new VXR. - ****************************************************************************/ - if (VXR.VXRnext == ZERO_OFFSET) { - if (!sX(AllocateIR(CDF,(Int32)VXR_BASE_SIZE, - &newVXRoffset),&pStatus)) return pStatus; - VXR.VXRnext = newVXRoffset; - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - InitNewVXR (&VXR, pushedFirst, pushedLast, pushedOffset); - if (!sX(WriteVXR(CDF->fp,newVXRoffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * There is another VXR on the linked list - update this VXR and recursively - * call this routine to insert the entry that was pushed out in the first - * entry position. - ****************************************************************************/ - if (!sX(WriteVXR(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - if (!sX(InsertIndexEntry(CDF,VXR.VXRnext, - 0,(Logical)FALSE, - pushedFirst,pushedLast, - pushedOffset),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* UpdateIndexEntries_r. -******************************************************************************/ - -static CDFstatus UpdateIndexEntries_r (fp, vxrOffset, aboveRecord, recordCount) -vFILE *fp; -Int32 vxrOffset; -Int32 aboveRecord; -Int32 recordCount; -{ - CDFstatus pStatus = CDF_OK; struct VXRstruct VXR; int entryN; Int32 irType; - while (vxrOffset != ZERO_OFFSET) { - Logical modified = FALSE; - if (!sX(ReadVXR(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - for (entryN = 0; entryN < VXR.NusedEntries; entryN++) { - if (VXR.Last[entryN] > aboveRecord) { - if (!sX(ReadIrType(fp,VXR.Offset[entryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - if (!sX(UpdateIndexEntries_r(fp,VXR.Offset[entryN],aboveRecord, - recordCount),&pStatus)) - return pStatus; - break; - case VVR_: - case CVVR_: - break; - default: - return CORRUPTED_V2_CDF; - } - if (VXR.First[entryN] > aboveRecord) VXR.First[entryN] -= recordCount; - VXR.Last[entryN] -= recordCount; - modified = TRUE; - } - } - if (modified) { - if (!sX(WriteVXR(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - } - vxrOffset = VXR.VXRnext; - } - return pStatus; -} - -/****************************************************************************** -* WriteCVVRorVVR. -******************************************************************************/ - -static CDFstatus WriteCVVRorVVR (CDF, cSize, stageOffset, uSize, newOffset) -struct CDFstruct *CDF; -Int32 cSize; -Int32 stageOffset; -Int32 uSize; -Int32 *newOffset; -{ - CDFstatus pStatus = CDF_OK; Int32 recordSize, tOffset; - if (CVVR_BASE_SIZE + cSize < VVR_BASE_SIZE + uSize) { - struct CVVRstruct CVVR; - recordSize = CVVR_BASE_SIZE + cSize; - LoadCVVRx (CVVR, recordSize, cSize) - if (!sX(AllocateIR(CDF,recordSize,newOffset),&pStatus)) return pStatus; - if (!sX(WriteCVVR(CDF->fp,*newOffset, - CVVR_RECORDx,&CVVR, - CVVR_NULL),&pStatus)) return pStatus; - tOffset = *newOffset + CVVR_BASE_SIZE; - if (!sX(CopyBytes(CDF->compressFp,ZERO_OFFSET, - SCRATCH_READ_ERROR,cSize,CDF->fp, - tOffset,CDF_WRITE_ERROR),&pStatus)) return pStatus; - } - else { - struct VVRstruct VVR; - recordSize = VVR_BASE_SIZE + uSize; - LoadVVRx (VVR, recordSize) - if (!sX(AllocateIR(CDF,recordSize,newOffset),&pStatus)) return pStatus; - if (!sX(WriteVVR(CDF->fp,*newOffset, - VVR_RECORDx,&VVR, - VVR_NULL),&pStatus)) return pStatus; - tOffset = *newOffset + VVR_BASE_SIZE; - if (!sX(CopyBytes(CDF->stage.fp,stageOffset, - SCRATCH_READ_ERROR,uSize,CDF->fp, - tOffset,CDF_WRITE_ERROR),&pStatus)) return pStatus; - } - return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfdel64.c b/cdf36_3-dist/src/lib/cdfdel64.c deleted file mode 100644 index aea191b..0000000 --- a/cdf36_3-dist/src/lib/cdfdel64.c +++ /dev/null @@ -1,2019 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `delete' operations. -* -* Version 1.4b, 4-Mar-97, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 21-Aug-92, J Love CDF V2.3 (shareable/NeXT,zVar). -* V1.2 30-Nov-93, J Love CDF V2.4. Readonly mode, deleting V1 CDFs on -* all machines. -* V1.3 5-Dec-94, J Love CDF V2.5. -* V1.3a 6-Jan-95, J Love More cache-residency. -* V1.3b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.4 5-Sep-96, J Love CDF V2.6. -* V1.4a 21-Feb-97, J Love Removed RICE. -* V1.4b 4-Mar-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V2.0 08-Apr-04, M Liu Reset the current variable offset when that -* variable is deleted. -* V2.1 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* V2.2 08-Jan-09, M Liu Update the attrnum in AEDR when an attribute -* is deleted. -* V2.3 08-May-10, M Liu Reset firstRecInVVR/lastRecInVVR when a -* record(s) gets deleted. -* V2.4 24-Jan-11, M Liu Modified UpdateIndexEntries_r_64 to acquire -* physical record size to set VXR's last record. -* V2.5 09-May-12, M Liu Remodified UpdateIndexEntries_r_64. -* V2.6 27-May-14, M Liu Added renumbering the sparse records after -* deletion. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* Local function prototypes. -******************************************************************************/ - -static CDFstatus WasteTree_r_64 PROTOARGs(( - struct CDFstruct *CDF, OFF_T vxrOffset -)); -static CDFstatus DeleteVarRecords64 PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 firstRec, Int32 lastRec, - Logical reNumber -)); -static CDFstatus DeleteRecords64 PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 firstRec, Int32 lastRec, - Int32 *deletedTo -)); -static CDFstatus DeleteRecords_r_64 PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, OFF_T firstVXRoffset, - Int32 firstRec, Int32 lastRec, Int32 *deletedTo, Logical *total -)); -static CDFstatus DeleteFromFront64 PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 last, - OFF_T vxrOffset, struct VXRstruct64 *VXR, int entryN, OFF_T irSize -)); -static CDFstatus DeleteFromMiddle64 PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 first, Int32 last, - OFF_T vxrOffset, struct VXRstruct64 *VXR, int entryN, OFF_T irSize -)); -static CDFstatus DeleteFromEnd64 PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 first, - OFF_T vxrOffset, struct VXRstruct64 *VXR, int entryN, OFF_T irSize -)); -static CDFstatus DeleteVXRentry64 PROTOARGs(( - struct CDFstruct *CDF, OFF_T firstVXRoffset, OFF_T delVXRoffset, - int delEntryN, Logical *total -)); -static CDFstatus InsertIndexEntry64 PROTOARGs(( - struct CDFstruct *CDF, OFF_T vxrOffset, int entryN, Logical after, - Int32 first, Int32 last, OFF_T offset -)); -static CDFstatus UpdateIndexEntries_r_64 PROTOARGs(( - vFILE *fp, OFF_T vxrOffset, Int32 aboveRecord, Int32 recordCount -)); -static CDFstatus WriteCVVRorVVR64 PROTOARGs(( - struct CDFstruct *CDF, OFF_T cSize, OFF_T stageOffset, OFF_T uSize, - OFF_T *newOffset -)); - -/****************************************************************************** -* CDFdel64. -******************************************************************************/ - -STATICforIDL CDFstatus CDFdel64 (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ -CDFstatus tStatus, pStatus = CDF_OK; -switch (Va->item) { - /**************************************************************************** - * CDF_, delete an open CDF. - ****************************************************************************/ - case CDF_: { - struct CDFstruct *CDF; - SelectCDF (Cur->cdf, CDF) - if (!WriteAccess64(CDF,TRUE,&pStatus)) return pStatus; - sX (DeleteCDFfiles64(CDF), &pStatus); - if (CDF->uDotFp != NULL) { - if (!DELETEv64(CDF->uDotFp,NULL)) sX (SCRATCH_DELETE_ERROR, &pStatus); - CDF->uDotFp = NULL; - } - if (CDF->stage.fp != NULL) { - if (!DELETEv64(CDF->stage.fp,NULL)) sX (SCRATCH_DELETE_ERROR, &pStatus); - CDF->stage.fp = NULL; - } - if (CDF->compressFp != NULL) { - if (!DELETEv64(CDF->compressFp,NULL)) sX (SCRATCH_DELETE_ERROR, &pStatus); - CDF->compressFp = NULL; - } - FreeCDFid (CDF, FALSE); - Cur->cdf = NULL; - ReduceOpenCDFsCount(); - break; - } - /**************************************************************************** - * zVAR_/rVAR_ - ****************************************************************************/ - case zVAR_: - case rVAR_: { - Logical zOp = (Va->item == zVAR_), zVar; - struct CDFstruct *CDF; struct VDRstruct64 VDR, VDRt; - Int32 rMaxRec = NO_RECORD; - Int32 scope, entryN, nVars; int varN; - OFF_T vOffset, tOffset, aOffset, eOffset, VDRhead; - /************************************************************************** - * Get pointer to current CDF and locate the current r/zVariable. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (!CDF->singleFile) return UNSUPPORTED_OPERATION; - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - /************************************************************************** - * Switch to write access. - **************************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - -/* - if (!sX(LocateCurrentVar64(CDF,zOp,&vOffset,&zVar,NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } -*/ - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) vOffset = CDF->CURzVarOffset64; - else vOffset = CDF->CURrVarOffset64; - - /************************************************************************** - * Read/get GDR field(s). - **************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - BOO(zVar,GDR_zVDRHEAD,GDR_rVDRHEAD),&VDRhead, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - nVars = BOO(zVar,CDF->NzVars,CDF->NrVars); - /************************************************************************** - * Read the VDR. - **************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,vOffset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)){ - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Remove the VDR from the list of r/zVariables and decrement the number - * of r/zVariables. If this is a true rVariable, check for the maximum - * record number written for the rVariables up to the one being deleted. - **************************************************************************/ - if (VDRhead == vOffset) - VDRhead = VDR.VDRnext; - else { - tOffset = VDRhead; - while (tOffset != 0) { - if (!sX(ReadVDR64(CDF,CDF->fp,tOffset,zVar, - VDR_RECORD,&VDRt,NULL, - VDR_NULL),&pStatus)){ - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!zVar) rMaxRec = MAXIMUM (rMaxRec, VDRt.MaxRec); - if (VDRt.VDRnext == vOffset) { - VDRt.VDRnext = VDR.VDRnext; - if (!sX(WriteVDR64(CDF,CDF->fp,tOffset,zVar, - VDR_RECORD,&VDRt,NULL, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - tOffset = VDRt.VDRnext; - } - if (tOffset == 0) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return CORRUPTED_V3_CDF; - } - } - nVars--; - /************************************************************************** - * Renumber following VDRs. If this is a true rVariable, continue checking - * for the maximum record number written. - **************************************************************************/ - tOffset = VDR.VDRnext; - while (tOffset != 0) { - if (!sX(ReadVDR64(CDF,CDF->fp,tOffset,zVar, - VDR_RECORD,&VDRt,NULL, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!zVar) rMaxRec = MAXIMUM (rMaxRec, VDRt.MaxRec); - VDRt.Num--; - if (!sX(WriteVDR64(CDF,CDF->fp,tOffset,zVar, - VDR_RECORD,&VDRt,NULL, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - tOffset = VDRt.VDRnext; - } - /************************************************************************** - * Write/store the GDR fields that may have changed. - **************************************************************************/ - if (!zVar) { - CDF->rMaxRec = rMaxRec; - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_rMAXREC,&rMaxRec, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - BOO(zVar,GDR_zVDRHEAD,GDR_rVDRHEAD),&VDRhead, - BOO(zVar,GDR_NzVARS,GDR_NrVARS),&nVars, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (zVar) - CDF->NzVars = nVars; - else - CDF->NrVars = nVars; - /************************************************************************** - * Waste VDR. - **************************************************************************/ - if (!sX(WasteIR64(CDF,vOffset,VDR.RecordSize),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Waste CPR/SPR (if one exists). - **************************************************************************/ - if (VDR.CPRorSPRoffset != (OFF_T) NO_OFFSET64) { - OFF_T irSize; - if (!sX(ReadIrSize64(CDF->fp, - VDR.CPRorSPRoffset, - &irSize),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WasteIR64(CDF,VDR.CPRorSPRoffset,irSize),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Waste VXRs and VVRs/CVVRs. - **************************************************************************/ - if (!sX(WasteTree_r_64(CDF,VDR.VXRhead),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Free/adjust variable data structures kept in memory. Note that the - * number of z/rVariables has already been decremented. - **************************************************************************/ - if (zVar) { - if (CDF->zVars[(int)VDR.Num] != NULL) { - cdf_FreeMemory (CDF->zVars[(int)VDR.Num], NULL); - } - for (varN = (int) VDR.Num; varN < nVars; varN++) { - CDF->zVars[varN] = CDF->zVars[varN+1]; - if (CDF->zVars[varN] != NULL) CDF->zVars[varN]->varN = varN; - } - CDF->zVars[varN] = NULL; - } - else { - if (CDF->rVars[(int)VDR.Num] != NULL) { - cdf_FreeMemory (CDF->rVars[(int)VDR.Num], NULL); - } - for (varN = (int) VDR.Num; varN < nVars; varN++) { - CDF->rVars[varN] = CDF->rVars[varN+1]; - if (CDF->rVars[varN] != NULL) CDF->rVars[varN]->varN = varN; - } - CDF->rVars[varN] = NULL; - } - /************************************************************************** - * Reset the current r/zVariable number. - **************************************************************************/ - if (zOp) { - CDF->CURzVarNum = RESERVED_VARNUM; - CDF->CURzVarOffset64 = (OFF_T) 0; - } else { - CDF->CURrVarNum = RESERVED_VARNUM; - CDF->CURrVarOffset64 = (OFF_T) 0; - } - /************************************************************************** - * Delete the associated attribute entries and renumber the entries that - * are associated with the variables that followed the variable that was - * deleted. - **************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_ADRHEAD,&aOffset, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - while (aOffset != 0) { - /************************************************************************ - * Read the scope of the attribute. - ************************************************************************/ - if (!sX(ReadADR64(CDF->fp,aOffset, - ADR_SCOPE,&scope, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (VARIABLEscope(scope)) { - Int32 maxEntry = NO_ENTRY; - /********************************************************************** - * Delete associated entry. - **********************************************************************/ - tStatus = FindEntryByNumber64 (CDF, aOffset, zVar, VDR.Num, &eOffset); - switch (tStatus) { - case CDF_OK: - if (!sX(DeleteEntry64(CDF,aOffset,eOffset),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - case NO_SUCH_ENTRY: - break; - default: - AbortAccess64 (CDF, UPDATE, noDELETE); - return tStatus; - } - /********************************************************************** - * Renumber entries. Note that the entry numbers are not necessarily - * increasing. (The entries may have been written in any order.) Also - * determine the new maximum entry number. - **********************************************************************/ - if (!sX(ReadADR64(CDF->fp,aOffset, - BOO(zVar,ADR_AzEDRHEAD,ADR_AgrEDRHEAD),&eOffset, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - while (eOffset != 0) { - if (!sX(ReadAEDR64(CDF->fp,eOffset, - AEDR_NUM,&entryN, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (entryN > VDR.Num) { - entryN--; - if (!sX(WriteAEDR64(CDF,CDF->fp,eOffset, - AEDR_NUM,&entryN, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - maxEntry = MAXIMUM (maxEntry, entryN); - if (!sX(ReadAEDR64(CDF->fp,eOffset, - AEDR_AEDRNEXT,&eOffset, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /********************************************************************** - * Write new maximum entry number to the ADR. - **********************************************************************/ - if (!sX(WriteADR64(CDF->fp,aOffset, - BOO(zVar,ADR_MAXzENTRY,ADR_MAXgrENTRY),&maxEntry, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************ - * Read offset of next ADR. - ************************************************************************/ - if (!sX(ReadADR64(CDF->fp,aOffset, - ADR_ADRNEXT,&aOffset, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Reset the current entry offset (in case it was affected). - **************************************************************************/ - if (!sX(BOO(zOp,SetCURzEntry64(CDF,FALSE,CDF->CURzEntryNum), - SetCURgrEntry64(CDF,FALSE,CDF->CURgrEntryNum)),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * rVAR_RECORDS_/zVAR_RECORDS_/rVAR_RECORDS_RENUMBER_/zVAR_RECORDS_RENUMBER_ - ****************************************************************************/ - case rVAR_RECORDS_: - case zVAR_RECORDS_: - case rVAR_RECORDS_RENUMBER_: - case zVAR_RECORDS_RENUMBER_: { - Logical zOp = (Va->item == zVAR_RECORDS_ || - Va->item == zVAR_RECORDS_RENUMBER_); - Logical reNumber; - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 firstRec = (Int32) va_arg (Va->ap, long); - Int32 lastRec = (Int32) va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!CDF->singleFile) { - sX (MULTI_FILE_FORMAT, &pStatus); - break; - } - if (firstRec < 0) return BAD_REC_NUM; - if (lastRec < 0) return BAD_REC_NUM; - if (lastRec < firstRec) return BAD_REC_NUM; - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (Va->item == rVAR_RECORDS_RENUMBER_ || - Va->item == zVAR_RECORDS_RENUMBER_) - reNumber = TRUE; - else - reNumber = FALSE; - if (!sX(DeleteVarRecords64(CDF,Var,firstRec,lastRec,reNumber),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * ATTR_ - ****************************************************************************/ - case ATTR_: { - struct CDFstruct *CDF; - OFF_T tOffset; - struct GDRstruct64 GDR; - struct ADRstruct64 ADR, ADRt; - struct AEDRstruct64 AEDRt; - OFF_T eOffset, eNext; - /************************************************************************** - * Get pointer to current CDF and locate the current attribute. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED64(CDF)) return NO_ATTR_SELECTED; - /************************************************************************** - * Read the GDR and ADR. - **************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_RECORD,&GDR, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(ReadADR64(CDF->fp,CDF->CURattrOffset64, - ADR_RECORD,&ADR, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Switch to write access. - **************************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Remove the ADR from the list of attributes and decrement the number of - * attributes. - **************************************************************************/ - if (GDR.ADRhead == CDF->CURattrOffset64) - GDR.ADRhead = ADR.ADRnext; - else { - tOffset = GDR.ADRhead; - while (tOffset != 0) { - if (!sX(ReadADR64(CDF->fp,tOffset, - ADR_RECORD,&ADRt, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (ADRt.ADRnext == CDF->CURattrOffset64) break; - tOffset = ADRt.ADRnext; - } - if (tOffset == 0) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return CORRUPTED_V3_CDF; - } - ADRt.ADRnext = ADR.ADRnext; - if (!sX(WriteADR64(CDF->fp,tOffset, - ADR_RECORD,&ADRt, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - GDR.NumAttr--; - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_RECORD,&GDR, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Renumber each of the following attributes. - **************************************************************************/ - tOffset = ADR.ADRnext; - while (tOffset != 0) { - if (!sX(ReadADR64(CDF->fp,tOffset, - ADR_RECORD,&ADRt, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - ADRt.Num--; - if (!sX(WriteADR64(CDF->fp,tOffset, - ADR_RECORD,&ADRt, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - eOffset = ADRt.AgrEDRhead; - while (eOffset != 0) { - if (!sX(ReadAEDR64(CDF->fp,eOffset, - AEDR_AEDRNEXT,&eNext, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteAEDR64(CDF,CDF->fp,eOffset, - AEDR_ATTRNUM,&ADRt.Num, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - eOffset = eNext; - } - eOffset = ADRt.AzEDRhead; - while (eOffset != 0) { - if (!sX(ReadAEDR64(CDF->fp,eOffset, - AEDR_AEDRNEXT,&eNext, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteAEDR64(CDF,CDF->fp,eOffset, - AEDR_ATTRNUM,&ADRt.Num, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - eOffset = eNext; - } - tOffset = ADRt.ADRnext; - } - /************************************************************************** - * Waste the ADR and each of the AgrEDR and AzEDR's for the attribute. - **************************************************************************/ - if (!sX(WasteIR64(CDF,CDF->CURattrOffset64,ADR.RecordSize),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - tOffset = ADR.AgrEDRhead; - while (tOffset != 0) { - if (!sX(ReadAEDR64(CDF->fp,tOffset, - AEDR_RECORD,&AEDRt,NULL, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WasteIR64(CDF,tOffset,AEDRt.RecordSize),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - tOffset = AEDRt.AEDRnext; - } - tOffset = ADR.AzEDRhead; - while (tOffset != 0) { - if (!sX(ReadAEDR64(CDF->fp,tOffset, - AEDR_RECORD,&AEDRt,NULL, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WasteIR64(CDF,tOffset,AEDRt.RecordSize),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - tOffset = AEDRt.AEDRnext; - } - /************************************************************************** - * Reset the current attribute offset and current entry offsets. - **************************************************************************/ - CDF->CURattrOffset64 = (OFF_T) RESERVED_ATTROFFSET64; - CDF->CURgrEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET64; - CDF->CURzEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET64; - break; - } - /**************************************************************************** - * gENTRY_/zENTRY_/rENTRY_ - ****************************************************************************/ - case gENTRY_: - case zENTRY_: - case rENTRY_: { - int entryType = E3p(Va->item,gENTRY_,rENTRY_,zENTRY_); - struct CDFstruct *CDF; - OFF_T eOffset; - /************************************************************************** - * Get pointer to current CDF, locate the current attribute, and verify - * that a current entry number has been selected. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED64(CDF)) return NO_ATTR_SELECTED; - if (E3(entryType, - CDF->CURgrEntryNum, - CDF->CURgrEntryNum, - CDF->CURzEntryNum) == RESERVED_ENTRYNUM) return NO_ENTRY_SELECTED; - /************************************************************************** - * Verify that the operation being performed is legal for the attribute's - * scope. - **************************************************************************/ - if (!sX(CheckEntryOp64(CDF,entryType),&pStatus)) return pStatus; - /************************************************************************** - * Switch to write access. - **************************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Locate the entry to be deleted. - **************************************************************************/ - eOffset = E3(entryType,CDF->CURgrEntryOffset64, - CDF->CURgrEntryOffset64, - CDF->CURzEntryOffset64); - if (eOffset == (OFF_T) RESERVED_ENTRYOFFSET64) return NO_SUCH_ENTRY; - /************************************************************************** - * Delete the entry. - **************************************************************************/ - if (!sX(DeleteEntry64(CDF,CDF->CURattrOffset64,eOffset),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Reset the current entry offset (to indicate the entry no longer exists). - **************************************************************************/ - switch (entryType) { - case gENTRYt: - case rENTRYt: - CDF->CURgrEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET64; - break; - case zENTRYt: - CDF->CURzEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET64; - break; - } - break; - } - /**************************************************************************** - * Unknown item, must be the next function. - ****************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } -} -return pStatus; -} - -/****************************************************************************** -* WasteTree_r_64. -******************************************************************************/ - -static CDFstatus WasteTree_r_64 (CDF, vxrOffset) -struct CDFstruct *CDF; -OFF_T vxrOffset; -{ - CDFstatus pStatus = CDF_OK; - int e; struct VXRstruct64 VXR; Int32 irType; OFF_T irSize; - while (vxrOffset != (OFF_T) ZERO_OFFSET64) { - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - if (!sX(WasteIR64(CDF,vxrOffset,VXR.RecordSize),&pStatus)) return pStatus; - for (e = 0; e < VXR.NusedEntries; e++) { - if (!sX(ReadIrType64(CDF->fp, - VXR.Offset[e], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - if (!sX(WasteTree_r_64(CDF,VXR.Offset[e]),&pStatus)) return pStatus; - break; - case VVR_: - case CVVR_: - if (!sX(ReadIrSize64(CDF->fp, - VXR.Offset[e], - &irSize),&pStatus)) return pStatus; - if (!sX(WasteIR64(CDF, - VXR.Offset[e], - irSize),&pStatus)) return pStatus; - break; - default: - return CORRUPTED_V3_CDF; - } - } - vxrOffset = VXR.VXRnext; - } - return pStatus; -} - -/****************************************************************************** -* DeleteVarRecords64. -******************************************************************************/ - -static CDFstatus DeleteVarRecords64 (CDF, Var, firstRec, lastRec, reNumber) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 firstRec; -Int32 lastRec; -Logical reNumber; -{ - CDFstatus pStatus = CDF_OK; Int32 deletedTo, recNum; Logical found; - /**************************************************************************** - * Base on the variable type... - ****************************************************************************/ - switch (Var->vType) { - /************************************************************************** - * Standard variable in a single-file CDF. - **************************************************************************/ - case STANDARD_: { - Int32 aboveRecord, deleteCount; - OFF_T vxrHead; - /************************************************************************ - * Verify/adjust the records to be deleted. - ************************************************************************/ - if (firstRec > Var->maxAllocated) return pStatus; - lastRec = MINIMUM(lastRec,Var->maxAllocated); - /************************************************************************ - * Delete the records. - ************************************************************************/ - for (recNum = firstRec; recNum <= lastRec; recNum = deletedTo + 1) { - if (!sX(DeleteRecords64(CDF,Var,recNum, - lastRec,&deletedTo),&pStatus)) return pStatus; - } - deleteCount = lastRec - firstRec + 1; - /************************************************************************ - * Update the index entries. - ************************************************************************/ - aboveRecord = firstRec - 1; - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_VXRHEAD,&vxrHead, - VDR_NULL),&pStatus)) return pStatus; - if (!sX(UpdateIndexEntries_r_64(CDF->fp,vxrHead,aboveRecord,deleteCount), - &pStatus)) - return pStatus; - /************************************************************************ - * Update the control information. - ************************************************************************/ - if (firstRec <= Var->maxWritten) { - if (lastRec > Var->maxWritten) - Var->maxWritten = firstRec - 1; - else - Var->maxWritten -= deleteCount; - } - if (firstRec <= Var->maxAllocated) { - if (lastRec > Var->maxAllocated) - Var->maxAllocated = firstRec - 1; - else - Var->maxAllocated -= deleteCount; - } - Var->firstRecInVVR = NO_RECORD; - Var->lastRecInVVR = NO_RECORD; - Var->offsetOfVVR64 = (OFF_T) NO_OFFSET64; - /************************************************************************ - * Update the maximum record field in the VDR. - ************************************************************************/ - if (firstRec <= Var->maxRec) { - if (lastRec > Var->maxRec) - Var->maxRec = firstRec - 1; - else - Var->maxRec -= deleteCount; - if (!sX(WriteVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_MAXREC,&(Var->maxRec), - VDR_NULL),&pStatus)) return pStatus; - } - break; - } - /************************************************************************** - * Sparse records. - **************************************************************************/ - case SPARSE_RECORDS_: { - Int32 aboveRecord, deleteCount; - OFF_T vxrHead; long maxRec; - /************************************************************************ - * Flush staging area first. This will automatically clear the staging - * area as well. - ************************************************************************/ - if (!sX(FlushStage64(CDF,Var),&pStatus)) return pStatus; - /************************************************************************ - * Verify/adjust the records to be deleted. - ************************************************************************/ - if (firstRec > Var->maxAllocated) return pStatus; - lastRec = MINIMUM(lastRec,Var->maxAllocated); - /************************************************************************ - * Delete the records. - ************************************************************************/ - for (recNum = firstRec; recNum <= lastRec; recNum = deletedTo + 1) { - if (!sX(DeleteRecords64(CDF,Var,recNum, - lastRec,&deletedTo),&pStatus)) return pStatus; - } - if (reNumber) { - deleteCount = lastRec - firstRec + 1; - /********************************************************************* - * Update the index entries. - *********************************************************************/ - aboveRecord = firstRec - 1; - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_VXRHEAD,&vxrHead, - VDR_NULL),&pStatus)) return pStatus; - if (!sX(UpdateIndexEntries_r_64(CDF->fp,vxrHead,aboveRecord, - deleteCount),&pStatus)) - return pStatus; - /********************************************************************* - * Update the control information. - *********************************************************************/ - if (firstRec <= Var->maxWritten) { - if (lastRec > Var->maxWritten) - Var->maxWritten = firstRec - 1; - else - Var->maxWritten -= deleteCount; - } - if (firstRec <= Var->maxAllocated) { - if (lastRec > Var->maxAllocated) - Var->maxAllocated = firstRec - 1; - else - Var->maxAllocated -= deleteCount; - } - /********************************************************************* - * Update the maximum record field in the VDR. - *********************************************************************/ - maxRec = Var->maxRec; - if (firstRec <= Var->maxRec) { - if (lastRec > Var->maxRec) - maxRec = firstRec - 1; - else - maxRec -= deleteCount; - if (!sX(WriteVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_MAXREC,&(maxRec), - VDR_NULL),&pStatus)) return pStatus; - } - if (INCLUSIVE(firstRec,Var->maxRec,lastRec)) { - if (!sX(PrevRecord64(CDF,Var->VDRoffset64,Var->zVar, - (Int32)(firstRec - 1), - &(Var->maxRec),&found),&pStatus)) return - pStatus; - if (!found) Var->maxRec = NO_RECORD; - if (!sX(WriteVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_MAXREC,&(Var->maxRec), - VDR_NULL),&pStatus)) return pStatus; - } else - Var->maxRec = maxRec; - } else { - /********************************************************************* - * Update the control information. - *********************************************************************/ - if (INCLUSIVE(firstRec,Var->maxWritten,lastRec)) { - if (!sX(PrevRecord64(CDF,Var->VDRoffset64,Var->zVar, - (Int32)(firstRec - 1), - &(Var->maxWritten),&found),&pStatus)) return - pStatus; - if (!found) Var->maxWritten = NO_RECORD; - } - if (INCLUSIVE(firstRec,Var->maxAllocated,lastRec)) { - if (!sX(PrevRecord64(CDF,Var->VDRoffset64,Var->zVar, - (Int32)(firstRec - 1), - &(Var->maxAllocated),&found),&pStatus)) return - pStatus; - if (!found) Var->maxAllocated = NO_RECORD; - } - /********************************************************************* - * Update the maximum record field in the VDR. - *********************************************************************/ - if (INCLUSIVE(firstRec,Var->maxRec,lastRec)) { - if (!sX(PrevRecord64(CDF,Var->VDRoffset64,Var->zVar, - (Int32)(firstRec - 1), - &(Var->maxRec),&found),&pStatus)) return - pStatus; - if (!found) Var->maxRec = NO_RECORD; - if (!sX(WriteVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_MAXREC,&(Var->maxRec), - VDR_NULL),&pStatus)) return pStatus; - } - } - Var->firstRecInVVR = NO_RECORD; - Var->lastRecInVVR = NO_RECORD; - Var->offsetOfVVR64 = (OFF_T) NO_OFFSET64; - break; - } - /************************************************************************** - * Compressed records. - **************************************************************************/ - case COMPRESSED_: { - Int32 aboveRecord, deleteCount; - OFF_T vxrHead; - /************************************************************************ - * Flush/clear staging area first. - ************************************************************************/ - if (!sX(FlushStage64(CDF,Var),&pStatus)) return pStatus; - Var->stage.firstRec = NO_RECORD; - Var->stage.lastRec = NO_RECORD; - Var->stage.dotOffset64 = (OFF_T) NO_OFFSET64; - Var->firstRecInVVR = NO_RECORD; - Var->lastRecInVVR = NO_RECORD; - Var->offsetOfVVR64 = (OFF_T) NO_OFFSET64; - /************************************************************************ - * Verify/adjust the records to be deleted. - ************************************************************************/ - if (firstRec > Var->maxRec) return pStatus; - lastRec = MINIMUM(lastRec,Var->maxRec); - /************************************************************************ - * Delete the records. - ************************************************************************/ - for (recNum = firstRec; recNum <= lastRec; recNum = deletedTo + 1) { - if (!sX(DeleteRecords64(CDF,Var,recNum, - lastRec,&deletedTo),&pStatus)) return pStatus; - } - deleteCount = lastRec - firstRec + 1; - /************************************************************************ - * Update the index entries. - ************************************************************************/ - aboveRecord = firstRec - 1; - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_VXRHEAD,&vxrHead, - VDR_NULL),&pStatus)) return pStatus; - if (!sX(UpdateIndexEntries_r_64(CDF->fp,vxrHead,aboveRecord,deleteCount), - &pStatus)) - return pStatus; - /************************************************************************ - * Update the maximum record field in the VDR. - ************************************************************************/ - if (firstRec <= Var->maxRec) { - if (lastRec > Var->maxRec) - Var->maxRec = firstRec - 1; - else - Var->maxRec -= deleteCount; - if (!sX(WriteVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_MAXREC,&(Var->maxRec), - VDR_NULL),&pStatus)) return pStatus; - } - break; - } - /************************************************************************** - * Sparse compressed records. - **************************************************************************/ - case SPARSE_COMPRESSED_RECORDS_: - /************************************************************************ - * Flush/clear staging area first. - ************************************************************************/ - if (!sX(FlushStage64(CDF,Var),&pStatus)) return pStatus; - Var->stage.firstRec = NO_RECORD; - Var->stage.lastRec = NO_RECORD; - Var->stage.dotOffset64 = (OFF_T) NO_OFFSET64; - Var->firstRecInVVR = NO_RECORD; - Var->lastRecInVVR = NO_RECORD; - Var->offsetOfVVR64 = (OFF_T) NO_OFFSET64; - /************************************************************************ - * Verify/adjust the records to be deleted. - ************************************************************************/ - if (firstRec > Var->maxRec) return pStatus; - lastRec = MINIMUM(lastRec,Var->maxRec); - /************************************************************************ - * Delete the records. - ************************************************************************/ - for (recNum = firstRec; recNum <= lastRec; recNum = deletedTo + 1) { - if (!sX(DeleteRecords64(CDF,Var,recNum, - lastRec,&deletedTo),&pStatus)) return pStatus; - } - /************************************************************************ - * Update the maximum record field in the VDR. - ************************************************************************/ - if (INCLUSIVE(firstRec,Var->maxRec,lastRec)) { - if (!sX(PrevRecord64(CDF,Var->VDRoffset64,Var->zVar, - (Int32)(firstRec - 1), - &(Var->maxRec),&found),&pStatus)) return pStatus; - if (!found) Var->maxRec = NO_RECORD; - if (!sX(WriteVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_MAXREC,&(Var->maxRec), - VDR_NULL),&pStatus)) return pStatus; - } - break; - /************************************************************************** - * Oops. - **************************************************************************/ - default: - return CDF_INTERNAL_ERROR; - } - /**************************************************************************** - * Update the VXR tail field in the VDR. - ****************************************************************************/ - if (!sX(UpdateVXRtailInVDR64(CDF,Var),&pStatus)) return pStatus; - /**************************************************************************** - * Update the maximum record field in the GDR if an rVariable. This is - * done in case this rVariable had the maximum record number. - ****************************************************************************/ - if (!Var->zVar) { - Int32 maxRec; Logical zVar = FALSE; - OFF_T vdrOffset; - CDF->rMaxRec = NO_RECORD; - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_rVDRHEAD,&vdrOffset, - GDR_NULL),&pStatus)) return pStatus; - while (vdrOffset != (OFF_T) ZERO_OFFSET64) { - if (!sX(ReadVDR64(CDF,CDF->fp,vdrOffset,zVar, - VDR_MAXREC,&maxRec, - VDR_VDRNEXT,&vdrOffset, - VDR_NULL),&pStatus)) return pStatus; - CDF->rMaxRec = MAXIMUM(CDF->rMaxRec,maxRec); - } - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_rMAXREC,&(CDF->rMaxRec), - GDR_NULL),&pStatus)) return pStatus; - } - return pStatus; -} - -/****************************************************************************** -* DeleteRecords64. -******************************************************************************/ - -static CDFstatus DeleteRecords64 (CDF, Var, firstRec, lastRec, deletedTo) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 firstRec; -Int32 lastRec; -Int32 *deletedTo; -{ - CDFstatus pStatus = CDF_OK; Logical total = FALSE; OFF_T vxrOffset; - /**************************************************************************** - * Read offset of the first VXR... - ****************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_VXRHEAD,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * ...and start there. - ****************************************************************************/ - if (!sX(DeleteRecords_r_64(CDF,Var,vxrOffset,firstRec, - lastRec,deletedTo,&total),&pStatus)) return pStatus; - /**************************************************************************** - * If the top level of VXR(s) was totally deleted, set the VXR head/tail to - * ZERO_OFFSET. - ****************************************************************************/ - if (total) { - OFF_T zeroOffset = (OFF_T) ZERO_OFFSET64; - if (!sX(WriteVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_VXRHEAD,&zeroOffset, - VDR_VXRTAIL,&zeroOffset, - VDR_NULL),&pStatus)) return pStatus; - } - return pStatus; -} - -/****************************************************************************** -* DeleteRecords_r_64. -******************************************************************************/ - -static CDFstatus DeleteRecords_r_64 (CDF, Var, firstVXRoffset, firstRec, lastRec, - deletedTo, total) -struct CDFstruct *CDF; -struct VarStruct *Var; -OFF_T firstVXRoffset; -Int32 firstRec; -Int32 lastRec; -Int32 *deletedTo; -Logical *total; -{ - CDFstatus pStatus = CDF_OK; OFF_T vxrOffset = firstVXRoffset; - struct VXRstruct64 VXR; int entryN; - /**************************************************************************** - * While another VXR... - ****************************************************************************/ - while (vxrOffset != (OFF_T) ZERO_OFFSET64) { - /************************************************************************** - * Read the VXR. - **************************************************************************/ - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************** - * For each VXR entry... - **************************************************************************/ - for (entryN = 0; entryN < VXR.NusedEntries; entryN++) { - /*********************************************************************** - * If some of the records to be deleted are within this entry... - ***********************************************************************/ - if (!(lastRec < VXR.First[entryN] || firstRec > VXR.Last[entryN])) { - Int32 first = MAXIMUM(firstRec,VXR.First[entryN]); - Int32 last = MINIMUM(lastRec,VXR.Last[entryN]); - Int32 irType; - /********************************************************************* - * Determine the type of internal record pointed to by this entry. - *********************************************************************/ - if (!sX(ReadIrType64(CDF->fp, - VXR.Offset[entryN], - &irType),&pStatus)) return pStatus; - /********************************************************************* - * Based on the type of internal record... - *********************************************************************/ - switch (irType) { - /******************************************************************* - * Another VXR (in a branch at a lower level)... - *******************************************************************/ - case VXR_: { - Logical totalBelow = FALSE; - /***************************************************************** - * Recursively call this routine... - *****************************************************************/ - if (!sX(DeleteRecords_r_64(CDF,Var,VXR.Offset[entryN], - first,last,deletedTo, - &totalBelow),&pStatus)) return pStatus; - /***************************************************************** - * If the branch of VXRs below has not been totally deleted, update - * this entry for the records that remain and return. - *****************************************************************/ - if (!totalBelow) { - struct VXRstruct64 VXRbelow; - if (!sX(ReadVXR64(CDF->fp,VXR.Offset[entryN], - VXR_RECORD,&VXRbelow, - VXR_NULL),&pStatus)) return pStatus; - VXR.First[entryN] = VXRbelow.First[0]; - while (VXRbelow.VXRnext != (OFF_T) ZERO_OFFSET64) { - if (!sX(ReadVXR64(CDF->fp,VXRbelow.VXRnext, - VXR_RECORD,&VXRbelow, - VXR_NULL),&pStatus)) return pStatus; - } - VXR.Last[entryN] = VXRbelow.Last[(int)VXRbelow.NusedEntries-1]; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - return pStatus; - } - /***************************************************************** - * The branch of VXRs below has been totally deleted. Delete this - * entry by moving the following entries up. If this is the last - * entry, indicate to the caller that this branch has been totally - * deleted. - *****************************************************************/ - if (!sX(DeleteVXRentry64(CDF,firstVXRoffset, - vxrOffset,entryN,total),&pStatus)) return - pStatus; - return pStatus; - } - /******************************************************************* - * A VVR or CVVR... - *******************************************************************/ - case VVR_: - case CVVR_: { - OFF_T irSize; - /***************************************************************** - * Read the size of the CVVR/VVR. - *****************************************************************/ - if (!sX(ReadIrSize64(CDF->fp, - VXR.Offset[entryN], - &irSize),&pStatus)) return pStatus; - /***************************************************************** - * Based on which records in the CVVR/VVR are being deleted... - *****************************************************************/ - if (first > VXR.First[entryN]) { - if (last < VXR.Last[entryN]) { - if (!sX(DeleteFromMiddle64(CDF,Var,first,last, - vxrOffset,&VXR, - entryN,irSize),&pStatus)) return - pStatus; - } - else { - if (!sX(DeleteFromEnd64(CDF,Var,first, - vxrOffset,&VXR, - entryN,irSize),&pStatus)) return - pStatus; - } - } - else { - if (last < VXR.Last[entryN]) { - if (!sX(DeleteFromFront64(CDF,Var,last, - vxrOffset,&VXR, - entryN,irSize),&pStatus)) return - pStatus; - } - else { - /************************************************************* - * The entire block of records (ie. the entire CVVR/VVR) is - * being deleted. - *************************************************************/ - if (!sX(WasteIR64(CDF,VXR.Offset[entryN], - irSize),&pStatus)) return pStatus; - if (!sX(DeleteVXRentry64(CDF,firstVXRoffset, - vxrOffset, - entryN,total),&pStatus)) return - pStatus; - } - } - *deletedTo = last; - return pStatus; - } - /******************************************************************* - * Something else - this is bad. - *******************************************************************/ - default: - return CORRUPTED_V3_CDF; - } - } - } - /************************************************************************** - * On to the next VXR... - **************************************************************************/ - vxrOffset = VXR.VXRnext; - } - /**************************************************************************** - * The records to be deleted do not exist... - ****************************************************************************/ - *deletedTo = lastRec; - return pStatus; -} - -/****************************************************************************** -* DeleteFromFront. -******************************************************************************/ - -static CDFstatus DeleteFromFront64 (CDF, Var, last, vxrOffset, VXR, entryN, - irSize) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 last; -OFF_T vxrOffset; -struct VXRstruct64 *VXR; -int entryN; -OFF_T irSize; -{ - CDFstatus pStatus = CDF_OK; - switch (Var->vType) { - case STANDARD_: - case SPARSE_RECORDS_: { - Int32 nDeleteRecords; OFF_T nRemainingBytes; - Int32 nDeleteBytes, nRecords2, nBytes2; - OFF_T deleteOffset, offset2, recordSize; - /************************************************************************ - * The records being deleted are at the beginning of the VVR. First - * calculate needed offsets and sizes. - ************************************************************************/ - deleteOffset = VXR->Offset[entryN] + VVR_BASE_SIZE64; - nDeleteRecords = last - VXR->First[entryN] + 1; - nDeleteBytes = nDeleteRecords * Var->NphyRecBytes; - nRecords2 = VXR->Last[entryN] - last; - nBytes2 = nRecords2 * Var->NphyRecBytes; - offset2 = VXR->Offset[entryN] + VVR_BASE_SIZE64 + nDeleteBytes; - nRemainingBytes = irSize - VVR_BASE_SIZE64 - nBytes2; - /************************************************************************ - * Slide the remaining records to the beginning of the VVR. - ************************************************************************/ - if (!sX(CopyBytes64(CDF->fp,offset2, - CDF_READ_ERROR, - nBytes2,CDF->fp, - deleteOffset, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - /************************************************************************ - * Update the VXR entry. - ************************************************************************/ - VXR->First[entryN] = last + 1; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************ - * If possible, waste the unused bytes that are now at the end of the - * VVR (and update the record size field). Otherwise, the record size - * field of the VVR remains unchanged. - ************************************************************************/ - if (nRemainingBytes >= UIR_BASE_SIZE64) { - OFF_T offset = deleteOffset + nBytes2; - if (!sX(WasteIR64(CDF,offset, - nRemainingBytes),&pStatus)) return pStatus; - recordSize = VVR_BASE_SIZE64 + nBytes2; - if (!sX(WriteVVR64(CDF->fp,VXR->Offset[entryN], - VVR_RECORDSIZE,&recordSize, - VVR_NULL),&pStatus)) return pStatus; - } - break; - } - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: { - Int32 nRecords = VXR->Last[entryN] - VXR->First[entryN] + 1; - OFF_T uSize = nRecords * Var->NphyRecBytes; - Int32 firstRecord2, nRecords2; OFF_T cSize; - OFF_T offset2, newOffset, nBytes2; - /************************************************************************ - * Initialize staging area and scratch space. - ************************************************************************/ - if (Var->stage.areaOffset64 == (OFF_T) NO_OFFSET64) { - Int32 nBytes = Var->blockingFactor * Var->NphyRecBytes; - if (!sX(InitVarStage64(CDF,Var,nBytes),&pStatus)) return pStatus; - } - if (!sX(InitScratch64(ScratchDirectory(CDF), - &(CDF->compressFp), - CDF->compressCacheSize),&pStatus)) return pStatus; - /************************************************************************ - * Bring the CVVR/VVR to the staging area. - ************************************************************************/ - if (!sX(DecompressToStage64(CDF,Var, - VXR->Offset[entryN], - uSize),&pStatus)) return pStatus; - /************************************************************************ - * Waste the CVVR/VVR. - ************************************************************************/ - if (!sX(WasteIR64(CDF,VXR->Offset[entryN],irSize),&pStatus)) return - pStatus; - /************************************************************************ - * Calculate sizes/offsets for the block of remaining records. - ************************************************************************/ - firstRecord2 = last + 1; - nRecords2 = VXR->Last[entryN] - last; - if (nRecords2 <= 0) break; - offset2 = Var->stage.areaOffset64 + - (Var->NphyRecBytes * (firstRecord2 - VXR->First[entryN])); - nBytes2 = nRecords2 * Var->NphyRecBytes; - /************************************************************************ - * Compress the block of remaining records... - ************************************************************************/ - if (!sX(Compress64(CDF->stage.fp,offset2, - nBytes2,SCRATCH_READ_ERROR, - Var->cType,Var->cParms, - CDF->compressFp,(OFF_T) ZERO_OFFSET64, - &cSize,SCRATCH_WRITE_ERROR),&pStatus)) return pStatus; - /************************************************************************ - * ...and allocate/write the CVVR/VVR. - ************************************************************************/ - if (!sX(WriteCVVRorVVR64(CDF,cSize,offset2, - nBytes2,&newOffset),&pStatus)) return pStatus; - /************************************************************************ - * Update the index entry for the block of remaining records. - ************************************************************************/ - VXR->First[entryN] = firstRecord2; - VXR->Offset[entryN] = newOffset; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,VXR, - VXR_NULL),&pStatus)) return pStatus; - break; - } - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* DeleteFromMiddle64. -******************************************************************************/ - -static CDFstatus DeleteFromMiddle64 (CDF, Var, first, last, vxrOffset, VXR, - entryN, irSize) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 first; -Int32 last; -OFF_T vxrOffset; -struct VXRstruct64 *VXR; -int entryN; -OFF_T irSize; -{ - CDFstatus pStatus = CDF_OK; - switch (Var->vType) { - case STANDARD_: - case SPARSE_RECORDS_: { - Int32 nRecords1, nBytes1, nDeleteRecords; - Int32 nDeleteBytes, firstRecord2, lastRecord2, nRecords2; - Int32 nBytes2, nExtraBytes, vvr_ = VVR_; - OFF_T nRemainingBytes; - OFF_T deleteOffset, offset2, vvrOffset, recordSize; - /************************************************************************ - * A block of records will remain at the beginning and at the end. First - * calculate needed offsets and sizes. Note that the number of bytes in - * the second remaining block of records takes into account any extra - * bytes that may exist at the end of the VVR. - ************************************************************************/ - nRecords1 = first - VXR->First[entryN]; - nBytes1 = nRecords1 * Var->NphyRecBytes; - deleteOffset = VXR->Offset[entryN] + VVR_BASE_SIZE64 + nBytes1; - nDeleteRecords = last - first + 1; - nDeleteBytes = nDeleteRecords * Var->NphyRecBytes; - firstRecord2 = last + 1; - lastRecord2 = VXR->Last[entryN]; - nRecords2 = lastRecord2 - firstRecord2 + 1; - offset2 = deleteOffset + nDeleteBytes; - nBytes2 = nRecords2 * Var->NphyRecBytes; - nExtraBytes = (Int32) (irSize - VVR_BASE_SIZE64 - nBytes1 - nDeleteBytes - - nBytes2); - /************************************************************************ - * If the second block of remaining records cannot remain in the same - * place... - ************************************************************************/ - if (nDeleteBytes < VVR_BASE_SIZE64) { - /********************************************************************** - * Move the second block of remaining records to a new VVR. - **********************************************************************/ - recordSize = VVR_BASE_SIZE64 + nBytes2; - if (!sX(AllocateIR64(CDF,recordSize,&vvrOffset),&pStatus)) return - pStatus; - if (!sX(WriteVVR64(CDF->fp,vvrOffset, - VVR_RECORDSIZE,&recordSize, - VVR_RECORDTYPE,&vvr_, - VVR_NULL),&pStatus)) return pStatus; - if (!sX(CopyBytes64(CDF->fp,offset2, - CDF_READ_ERROR, - nBytes2,CDF->fp, - (vvrOffset + VVR_BASE_SIZE64), - CDF_WRITE_ERROR),&pStatus)) return pStatus; - /********************************************************************** - * If the remaining bytes can be changed to a UIR... - **********************************************************************/ - nRemainingBytes = (OFF_T) nDeleteBytes + nBytes2 + nExtraBytes; - if (nRemainingBytes >= UIR_BASE_SIZE64) { - recordSize = VVR_BASE_SIZE64 + nBytes1; - if (!sX(WriteVVR64(CDF->fp,VXR->Offset[entryN], - VVR_RECORDSIZE,&recordSize, - VVR_NULL),&pStatus)) return pStatus; - if (!sX(WasteIR64(CDF,deleteOffset, - nRemainingBytes),&pStatus)) return pStatus; - } - /********************************************************************** - * Update the VXR entry for the first block of remaining records. - **********************************************************************/ - VXR->Last[entryN] = first - 1; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,VXR, - VXR_NULL),&pStatus)) return pStatus; - /********************************************************************** - * Insert a VXR entry for the new VVR created for the second block of - * remaining records. - **********************************************************************/ - if (!sX(InsertIndexEntry64(CDF,vxrOffset, - entryN,(Logical)TRUE, - firstRecord2,lastRecord2, - vvrOffset),&pStatus)) return pStatus; - } - else { - /********************************************************************** - * Update record size field of VVR for the first block of remaining - * records and create a UIR for the bytes being "deleted" that are not - * going to be used for the new VVR containing the second block of - * remaining records. - **********************************************************************/ - nRemainingBytes = (OFF_T) nDeleteBytes - VVR_BASE_SIZE64; - if (nRemainingBytes < UIR_BASE_SIZE64) - recordSize = VVR_BASE_SIZE64 + nBytes1 + nRemainingBytes; - else { - recordSize = VVR_BASE_SIZE64 + nBytes1; - if (!sX(WasteIR64(CDF,deleteOffset, - nRemainingBytes),&pStatus)) return pStatus; - } - if (!sX(WriteVVR64(CDF->fp,VXR->Offset[entryN], - VVR_RECORDSIZE,&recordSize, - VVR_NULL),&pStatus)) return pStatus; - /********************************************************************** - * Update the VXR entry for the first block of remaining records. - **********************************************************************/ - VXR->Last[entryN] = first - 1; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,VXR, - VXR_NULL),&pStatus)) return pStatus; - /********************************************************************** - * Write the record size and type fields of the new VVR for the second - * block of remaining records. - **********************************************************************/ - vvrOffset = offset2 - VVR_BASE_SIZE64; - recordSize = VVR_BASE_SIZE64 + nBytes2 + nExtraBytes; - if (!sX(WriteVVR64(CDF->fp,vvrOffset, - VVR_RECORDSIZE,&recordSize, - VVR_RECORDTYPE,&vvr_, - VVR_NULL),&pStatus)) return pStatus; - /********************************************************************** - * Insert a VXR entry for the new VVR created for the second block of - * remaining records. - **********************************************************************/ - if (!sX(InsertIndexEntry64(CDF,vxrOffset, - entryN,(Logical)TRUE, - firstRecord2,lastRecord2, - vvrOffset),&pStatus)) return pStatus; - } - break; - } - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: { - Int32 nRecords = VXR->Last[entryN] - VXR->First[entryN] + 1; - OFF_T uSize = nRecords * Var->NphyRecBytes; - Int32 nRecords1, firstRecord2, lastRecord2, nRecords2; - OFF_T offset2, nBytes1, nBytes2, cSize, newOffset; - /************************************************************************ - * Initialize staging area and scratch space. - ************************************************************************/ - if (Var->stage.areaOffset64 == (OFF_T) NO_OFFSET64) { - Int32 nBytes = Var->blockingFactor * Var->NphyRecBytes; - if (!sX(InitVarStage64(CDF,Var,nBytes),&pStatus)) return pStatus; - } - if (!sX(InitScratch64(ScratchDirectory(CDF), - &(CDF->compressFp), - CDF->compressCacheSize),&pStatus)) return pStatus; - /************************************************************************ - * Bring the CVVR/VVR to the staging area. - ************************************************************************/ - if (!sX(DecompressToStage64(CDF,Var, - VXR->Offset[entryN], - uSize),&pStatus)) return pStatus; - /************************************************************************ - * Waste the CVVR/VVR. - ************************************************************************/ - if (!sX(WasteIR64(CDF,VXR->Offset[entryN],irSize),&pStatus)) return - pStatus; - /************************************************************************ - * Calculate sizes/offsets for the first and second blocks of remaining - * records. - ************************************************************************/ - nRecords1 = first - VXR->First[entryN]; - nBytes1 = nRecords1 * Var->NphyRecBytes; - firstRecord2 = last + 1; - lastRecord2 = VXR->Last[entryN]; - nRecords2 = lastRecord2 - firstRecord2 + 1; - offset2 = Var->stage.areaOffset64 + - (Var->NphyRecBytes * (firstRecord2 - VXR->First[entryN])); - nBytes2 = nRecords2 * Var->NphyRecBytes; - /************************************************************************ - * Compress the first block of remaining records... - ************************************************************************/ - if (!sX(Compress64(CDF->stage.fp, - Var->stage.areaOffset64, - nBytes1,SCRATCH_READ_ERROR, - Var->cType,Var->cParms, - CDF->compressFp,(OFF_T) ZERO_OFFSET64, - &cSize,SCRATCH_WRITE_ERROR),&pStatus)) return pStatus; - /************************************************************************ - * ...and allocate/write the CVVR/VVR. - ************************************************************************/ - if (!sX(WriteCVVRorVVR64(CDF,cSize, - Var->stage.areaOffset64, - nBytes1,&newOffset),&pStatus)) return pStatus; - /************************************************************************ - * Update the index entry for the first block of remaining records. - ************************************************************************/ - VXR->Last[entryN] = first - 1; - VXR->Offset[entryN] = newOffset; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************ - * Compress the second block of remaining records... - ************************************************************************/ - if (!sX(Compress64(CDF->stage.fp,offset2, - nBytes2,SCRATCH_READ_ERROR, - Var->cType,Var->cParms, - CDF->compressFp,(OFF_T) ZERO_OFFSET64, - &cSize,SCRATCH_WRITE_ERROR),&pStatus)) return pStatus; - /************************************************************************ - * ...and allocate/write the CVVR/VVR. - ************************************************************************/ - if (!sX(WriteCVVRorVVR64(CDF,cSize,offset2, - nBytes2,&newOffset),&pStatus)) return pStatus; - /************************************************************************ - * Insert a new index entry for the second block of remaining records. - ************************************************************************/ - if (!sX(InsertIndexEntry64(CDF,vxrOffset, - entryN,(Logical)TRUE, - firstRecord2,lastRecord2, - newOffset),&pStatus)) return pStatus; - break; - } - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* DeleteFromEnd64. -******************************************************************************/ - -static CDFstatus DeleteFromEnd64 (CDF, Var, first, vxrOffset, VXR, entryN, - irSize) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 first; -OFF_T vxrOffset; -struct VXRstruct64 *VXR; -int entryN; -OFF_T irSize; -{ - CDFstatus pStatus = CDF_OK; - switch (Var->vType) { - case STANDARD_: - case SPARSE_RECORDS_: { - Int32 nRecords1, nBytes1; - OFF_T nRemainingBytes, deleteOffset, recordSize; - /************************************************************************ - * First calculate needed offsets and sizes. - ************************************************************************/ - nRecords1 = first - VXR->First[entryN]; - nBytes1 = nRecords1 * Var->NphyRecBytes; - deleteOffset = VXR->Offset[entryN] + VVR_BASE_SIZE64 + nBytes1; - nRemainingBytes = irSize - VVR_BASE_SIZE64 - nBytes1; - /************************************************************************ - * Update the VXR entry. - ************************************************************************/ - VXR->Last[entryN] = first - 1; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************ - * If enough bytes are being deleted for a UIR, waste them and update - * the record size field of the VVR. - ************************************************************************/ - if (nRemainingBytes >= UIR_BASE_SIZE64) { - if (!sX(WasteIR64(CDF,deleteOffset, - nRemainingBytes),&pStatus)) return pStatus; - recordSize = VVR_BASE_SIZE64 + nBytes1; - if (!sX(WriteVVR64(CDF->fp,VXR->Offset[entryN], - VVR_RECORDSIZE,&recordSize, - VVR_NULL),&pStatus)) return pStatus; - } - break; - } - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: { - Int32 nRecords = VXR->Last[entryN] - VXR->First[entryN] + 1; - OFF_T uSize = nRecords * Var->NphyRecBytes; - Int32 nRecords1; OFF_T nBytes1, cSize; - OFF_T newOffset; - /************************************************************************ - * Initialize staging area and scratch space. - ************************************************************************/ - if (Var->stage.areaOffset64 == (OFF_T) NO_OFFSET64) { - Int32 nBytes = Var->blockingFactor * Var->NphyRecBytes; - if (!sX(InitVarStage64(CDF,Var,nBytes),&pStatus)) return pStatus; - } - if (!sX(InitScratch64(ScratchDirectory(CDF), - &(CDF->compressFp), - CDF->compressCacheSize),&pStatus)) return pStatus; - /************************************************************************ - * Bring the CVVR/VVR to the staging area. - ************************************************************************/ - if (!sX(DecompressToStage64(CDF,Var, - VXR->Offset[entryN], - uSize),&pStatus)) return pStatus; - /************************************************************************ - * Waste the CVVR/VVR. - ************************************************************************/ - if (!sX(WasteIR64(CDF,VXR->Offset[entryN],irSize),&pStatus)) return - pStatus; - /************************************************************************ - * Calculate sizes/offsets for the block of remaining records. - ************************************************************************/ - nRecords1 = first - VXR->First[entryN]; - nBytes1 = nRecords1 * Var->NphyRecBytes; - /************************************************************************ - * Compress the block of remaining records... - ************************************************************************/ - if (!sX(Compress64(CDF->stage.fp, - Var->stage.areaOffset64, - nBytes1,SCRATCH_READ_ERROR, - Var->cType,Var->cParms, - CDF->compressFp,(OFF_T) ZERO_OFFSET64, - &cSize,SCRATCH_WRITE_ERROR),&pStatus)) return pStatus; - /************************************************************************ - * ...and allocate/write the CVVR/VVR. - ************************************************************************/ - if (!sX(WriteCVVRorVVR64(CDF,cSize, - Var->stage.areaOffset64, - nBytes1,&newOffset),&pStatus)) return pStatus; - /************************************************************************ - * Update the index entry for the block of remaining records. - ************************************************************************/ - VXR->Last[entryN] = first - 1; - VXR->Offset[entryN] = newOffset; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,VXR, - VXR_NULL),&pStatus)) return pStatus; - break; - } - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* DeleteVXRentry64. -******************************************************************************/ - -static CDFstatus DeleteVXRentry64 (CDF, firstVXRoffset, delVXRoffset, delEntryN, - total) -struct CDFstruct *CDF; -OFF_T firstVXRoffset; -OFF_T delVXRoffset; -int delEntryN; -Logical *total; -{ - CDFstatus pStatus = CDF_OK; - OFF_T vxrOffset = firstVXRoffset, prevVXRoffset = (OFF_T) ZERO_OFFSET64; - struct VXRstruct64 VXR, nextVXR; int entryN, lastEntryN; - /**************************************************************************** - * Find the VXR in which an entry is being deleted while keeping track of the - * previous VXR. - ****************************************************************************/ - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - while (vxrOffset != delVXRoffset) { - prevVXRoffset = vxrOffset; - vxrOffset = VXR.VXRnext; - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * Until done... - ****************************************************************************/ - for (;;) { - /************************************************************************* - * Move the following entries up. Nothing will happen if there is only - * one entry. - *************************************************************************/ - for (entryN = delEntryN + 1; entryN < VXR.NusedEntries; entryN++) { - VXR.First[entryN-1] = VXR.First[entryN]; - VXR.Last[entryN-1] = VXR.Last[entryN]; - VXR.Offset[entryN-1] = VXR.Offset[entryN]; - } - lastEntryN = (int) (VXR.NusedEntries - 1); - /************************************************************************* - * If a VXR does not follow, erase the last entry if there was more than - * one or waste the VXR is there was only one (entry). - *************************************************************************/ - if (VXR.VXRnext == (OFF_T) ZERO_OFFSET64) { - if (VXR.NusedEntries > 1) { - VXR.First[lastEntryN] = NO_RECORD; - VXR.Last[lastEntryN] = NO_RECORD; - VXR.Offset[lastEntryN] = (OFF_T) NO_OFFSET64; - VXR.NusedEntries--; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - } - else { - if (!sX(WasteIR64(CDF,vxrOffset, - VXR.RecordSize),&pStatus)) return pStatus; - if (prevVXRoffset != (OFF_T) ZERO_OFFSET64) { - OFF_T zeroOffset = (OFF_T) ZERO_OFFSET64; - if (!sX(WriteVXR64(CDF->fp,prevVXRoffset, - VXR_VXRNEXT,&zeroOffset, - VXR_NULL),&pStatus)) return pStatus; - } - else - *total = TRUE; - } - return pStatus; - } - /************************************************************************* - * Otherwise, read the next VXR, set the current VXR's last entry to the - * first entry of the next VXR, rewrite the current VXR, and then set the - * current VXR to the next VXR and set the first entry to be deleted and - * continue... - *************************************************************************/ - if (!sX(ReadVXR64(CDF->fp,VXR.VXRnext, - VXR_RECORD,&nextVXR, - VXR_NULL),&pStatus)) return pStatus; - VXR.First[lastEntryN] = nextVXR.First[0]; - VXR.Last[lastEntryN] = nextVXR.Last[0]; - VXR.Offset[lastEntryN] = nextVXR.Offset[0]; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - prevVXRoffset = vxrOffset; - vxrOffset = VXR.VXRnext; - VXR = nextVXR; - delEntryN = 0; - } -} - -/****************************************************************************** -* InsertIndexEntry64. -******************************************************************************/ - -static CDFstatus InsertIndexEntry64 (CDF, vxrOffset, entryN, after, first, last, - offset) -struct CDFstruct *CDF; -OFF_T vxrOffset; -int entryN; -Logical after; /* TRUE: Insert the new entry after `entryN'. - FALSE: Insert the new entry at `entryN'. */ -Int32 first; -Int32 last; -OFF_T offset; -{ - CDFstatus pStatus = CDF_OK; struct VXRstruct64 VXR; int eN, lastEntryN; - Int32 pushedFirst, pushedLast; - OFF_T pushedOffset, newVXRoffset; - /**************************************************************************** - * Read the VXR. - ****************************************************************************/ - if (!sX(ReadVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * If there is room in this VXR for another entry, simply insert it. - ****************************************************************************/ - if (VXR.NusedEntries < VXR.Nentries) { - if (after) { - for (eN = (int) VXR.NusedEntries; eN > entryN + 1; eN--) { - VXR.First[eN] = VXR.First[eN-1]; - VXR.Last[eN] = VXR.Last[eN-1]; - VXR.Offset[eN] = VXR.Offset[eN-1]; - } - VXR.First[entryN+1] = first; - VXR.Last[entryN+1] = last; - VXR.Offset[entryN+1] = offset; - } - else { - for (eN = (int) VXR.NusedEntries; eN > entryN; eN--) { - VXR.First[eN] = VXR.First[eN-1]; - VXR.Last[eN] = VXR.Last[eN-1]; - VXR.Offset[eN] = VXR.Offset[eN-1]; - } - VXR.First[entryN] = first; - VXR.Last[entryN] = last; - VXR.Offset[entryN] = offset; - } - VXR.NusedEntries++; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * No room for another entry... - ****************************************************************************/ - lastEntryN = (int) (VXR.NusedEntries - 1); - if (after) { - if (entryN == lastEntryN) { - pushedFirst = first; - pushedLast = last; - pushedOffset = offset; - } - else { - pushedFirst = VXR.First[lastEntryN]; - pushedLast = VXR.Last[lastEntryN]; - pushedOffset = VXR.Offset[lastEntryN]; - for (eN = lastEntryN; eN > entryN + 1; eN--) { - VXR.First[eN] = VXR.First[eN-1]; - VXR.Last[eN] = VXR.Last[eN-1]; - VXR.Offset[eN] = VXR.Offset[eN-1]; - } - VXR.First[entryN+1] = first; - VXR.Last[entryN+1] = last; - VXR.Offset[entryN+1] = offset; - } - } - else { - pushedFirst = VXR.First[lastEntryN]; - pushedLast = VXR.Last[lastEntryN]; - pushedOffset = VXR.Offset[lastEntryN]; - for (eN = lastEntryN; eN > entryN; eN--) { - VXR.First[eN] = VXR.First[eN-1]; - VXR.Last[eN] = VXR.Last[eN-1]; - VXR.Offset[eN] = VXR.Offset[eN-1]; - } - VXR.First[entryN] = first; - VXR.Last[entryN] = last; - VXR.Offset[entryN] = offset; - } - /**************************************************************************** - * If this is the last VXR on the linked list, allocate a new VXR, update - * this VXR with the new VXR's offset, and write the new VXR. - ****************************************************************************/ - if (VXR.VXRnext == (OFF_T) ZERO_OFFSET64) { - if (!sX(AllocateIR64(CDF,(OFF_T) VXR_BASE_SIZE64, - &newVXRoffset),&pStatus)) return pStatus; - VXR.VXRnext = newVXRoffset; - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - InitNewVXR64 (&VXR, pushedFirst, pushedLast, pushedOffset); - if (!sX(WriteVXR64(CDF->fp,newVXRoffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * There is another VXR on the linked list - update this VXR and recursively - * call this routine to insert the entry that was pushed out in the first - * entry position. - ****************************************************************************/ - if (!sX(WriteVXR64(CDF->fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - if (!sX(InsertIndexEntry64(CDF,VXR.VXRnext, - 0,(Logical)FALSE, - pushedFirst,pushedLast, - pushedOffset),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* UpdateIndexEntries_r_64. -******************************************************************************/ - -static CDFstatus UpdateIndexEntries_r_64 (fp, vxrOffset, aboveRecord, recordCount) -vFILE *fp; -OFF_T vxrOffset; -Int32 aboveRecord; -Int32 recordCount; -{ - CDFstatus pStatus = CDF_OK; struct VXRstruct64 VXR; int entryN; Int32 irType; - while (vxrOffset != (OFF_T) ZERO_OFFSET64) { - Logical modified = FALSE; - if (!sX(ReadVXR64(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - for (entryN = 0; entryN < VXR.NusedEntries; entryN++) { - if (VXR.Last[entryN] > aboveRecord) { - if (!sX(ReadIrType64(fp,VXR.Offset[entryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - if (!sX(UpdateIndexEntries_r_64(fp,VXR.Offset[entryN],aboveRecord, - recordCount),&pStatus)) - return pStatus; - break; - case VVR_: - case CVVR_: - break; - default: - return CORRUPTED_V3_CDF; - } - if (VXR.First[entryN] > aboveRecord) VXR.First[entryN] -= recordCount; - VXR.Last[entryN] -= recordCount; - modified = TRUE; - } - } - if (modified) { - if (!sX(WriteVXR64(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - } - vxrOffset = VXR.VXRnext; - } - return pStatus; -} - -/****************************************************************************** -* WriteCVVRorVVR64. -******************************************************************************/ - -static CDFstatus WriteCVVRorVVR64 (CDF, cSize, stageOffset, uSize, newOffset) -struct CDFstruct *CDF; -OFF_T cSize; -OFF_T stageOffset; -OFF_T uSize; -OFF_T *newOffset; -{ - CDFstatus pStatus = CDF_OK; OFF_T recordSize; OFF_T tOffset; - if (CVVR_BASE_SIZE64 + cSize < VVR_BASE_SIZE64 + uSize) { - struct CVVRstruct64 CVVR; - recordSize = CVVR_BASE_SIZE64 + cSize; - LoadCVVRx64 (CVVR, recordSize, cSize) - if (!sX(AllocateIR64(CDF,recordSize,newOffset),&pStatus)) return pStatus; - if (!sX(WriteCVVR64(CDF->fp,*newOffset, - CVVR_RECORDx,&CVVR, - CVVR_NULL),&pStatus)) return pStatus; - tOffset = *newOffset + CVVR_BASE_SIZE64; - if (!sX(CopyBytes64(CDF->compressFp,(OFF_T) ZERO_OFFSET64, - SCRATCH_READ_ERROR,cSize,CDF->fp, - tOffset,CDF_WRITE_ERROR),&pStatus)) return pStatus; - } - else { - struct VVRstruct64 VVR; - recordSize = VVR_BASE_SIZE64 + uSize; - LoadVVRx64 (VVR, recordSize) - if (!sX(AllocateIR64(CDF,recordSize,newOffset),&pStatus)) return pStatus; - if (!sX(WriteVVR64(CDF->fp,*newOffset, - VVR_RECORDx,&VVR, - VVR_NULL),&pStatus)) return pStatus; - tOffset = *newOffset + VVR_BASE_SIZE64; - if (!sX(CopyBytes64(CDF->stage.fp,stageOffset, - SCRATCH_READ_ERROR,uSize,CDF->fp, - tOffset,CDF_WRITE_ERROR),&pStatus)) return pStatus; - } - return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfed.c b/cdf36_3-dist/src/lib/cdfed.c deleted file mode 100644 index 4daffbb..0000000 --- a/cdf36_3-dist/src/lib/cdfed.c +++ /dev/null @@ -1,3053 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF encoding/decoding. -* -* Version 1.3a, 18-Nov-97, Hughes STX. -* -* Modification history: -* -* V1.0 31-Jan-94, J Love Original version. -* V1.0a 8-Feb-94, J Love DEC Alpha/OpenVMS port. -* V1.1 9-Nov-94, J Love CDF V2.5. -* V1.1a 5-Jan-95, J Love Encode/decode changes. -* V1.1b 19-Jan-95, J Love IRIX 6.0 (64-bit). -* V1.1c 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.2 21-Mar-95, J Love POSIX. -* V1.2a 18-Apr-95, J Love More POSIX. -* V1.3 3-Oct-96, J Love CDF V2.6. -* V1.3a 18-Nov-97, J Love Windows NT/Visual C++. -* V3.3 10-Jan-09, M Liu Modifed to check input argument for numElems -* in ConvertBuffer. -* -******************************************************************************/ - -#include "cdflib.h" - -#if defined(alphavms) || defined(posixSHELLalpha) -#define DYNAMICfpSTRUCTs 1 -#define STATICfpSTRUCTs 0 -#else -#define STATICfpSTRUCTs 1 -#define DYNAMICfpSTRUCTs 0 -#endif - -#if defined(alphavmsD) || defined(posixSHELLalphaD) -#define LIMITfp3DOUBLEs 1 -#else -#define LIMITfp3DOUBLEs 0 -#endif - -/****************************************************************************** -* Minimums, maximums, and zeros. -******************************************************************************/ - -#if defined(FP1cpu) -#define FP1ZEROsingle 0x0,0x0,0x0,0x0,0x0,0x0 -#define FP2ZEROsingle 0x0,0x0,0x0,0x0,0x0,0x0 -#define FP34ZEROsingle 0x0,0x0,0x0,0x0,0x0,0x0 -#define FP1ZEROsingleNEG 0x1,0x0,0x0,0x0,0x0,0x0 -#define FP2ZEROsingleNEG 0x0,0x0,0x0,0x0,0x1,0x0 -#define FP34MINsingle 0x1,0x0,0x0,0x0,0x0,0x0 -#define FP34MAXsingle 0x1,0x7F,0x0,0x7F,0xFF,0xFF -#define FP1ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 -#define FP2ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 -#define FP3ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 -#define FP4ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 -#define FP1ZEROdoubleNEG 0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 -#define FP2ZEROdoubleNEG 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0 -#define FP3MINdouble 0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 -#define FP3MAXdouble 0x1,0x7F,0x0,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF -#define FP4MINdouble 0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 -#define FP4MAXdouble 0xF,0xF,0x0,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF -#endif - -#if defined(FP2cpu) || defined(FP3cpu) || defined(FP4cpu) -#define FP1ZEROsingle 0x0,0x0,0x0,0x0,0x0,0x0 -#define FP2ZEROsingle 0x0,0x0,0x0,0x0,0x0,0x0 -#define FP34ZEROsingle 0x0,0x0,0x0,0x0,0x0,0x0 -#define FP1ZEROsingleNEG 0x0,0x1,0x0,0x0,0x0,0x0 -#define FP2ZEROsingleNEG 0x0,0x0,0x0,0x0,0x0,0x1 -#define FP34MINsingle 0x0,0x1,0x0,0x0,0x0,0x0 -#define FP34MAXsingle 0x7F,0x1,0x7F,0x0,0xFF,0xFF -#define FP1ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 -#define FP2ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 -#define FP3ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 -#define FP4ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 -#define FP1ZEROdoubleNEG 0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 -#define FP2ZEROdoubleNEG 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1 -#define FP3MINdouble 0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 -#define FP3MAXdouble 0x7F,0x1,0x7F,0x0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF -#define FP4MINdouble 0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 -#define FP4MAXdouble 0xF,0xF,0x7F,0x0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF -#endif - -#if STATICfpSTRUCTs -static struct fp1struct4 FP1zeroSingle = { FP1ZEROsingle }; -static struct fp2struct4 FP2zeroSingle = { FP2ZEROsingle }; -static struct fp34struct4 FP34zeroSingle = { FP34ZEROsingle }; -static struct fp1struct4 FP1zeroSingleNeg = { FP1ZEROsingleNEG }; -static struct fp2struct4 FP2zeroSingleNeg = { FP2ZEROsingleNEG }; -static struct fp34struct4 FP34minSingle = { FP34MINsingle }; -static struct fp34struct4 FP34maxSingle = { FP34MAXsingle }; -static struct fp1struct8 FP1zeroDouble = { FP1ZEROdouble }; -static struct fp2struct8 FP2zeroDouble = { FP2ZEROdouble }; -static struct fp3struct8 FP3zeroDouble = { FP3ZEROdouble }; -static struct fp4struct8 FP4zeroDouble = { FP4ZEROdouble }; -static struct fp1struct8 FP1zeroDoubleNeg = { FP1ZEROdoubleNEG }; -static struct fp2struct8 FP2zeroDoubleNeg = { FP2ZEROdoubleNEG }; -static struct fp3struct8 FP3minDouble = { FP3MINdouble }; -static struct fp3struct8 FP3maxDouble = { FP3MAXdouble }; -static struct fp4struct8 FP4minDouble = { FP4MINdouble }; -static struct fp4struct8 FP4maxDouble = { FP4MAXdouble }; -#endif - -/****************************************************************************** -* ConvertBuffer. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus ConvertBuffer (srcEncoding, dstEncoding, negToPosFp0, - dataType, numElems, srcBuffer, dstBuffer) -Int32 srcEncoding; -Int32 dstEncoding; -Logical negToPosFp0; -Int32 dataType; -Int32 numElems; -void *srcBuffer; -void *dstBuffer; -{ - Int32 tSrcEncoding = BOO(srcEncoding == HOST_ENCODING, - HostEncoding(), srcEncoding); - Int32 tDstEncoding = BOO(dstEncoding == HOST_ENCODING, - HostEncoding(), dstEncoding); - - CDFstatus pStatus = CDF_OK; /* Pending status code. Note that the status - code from a routine is only checked in those - cases were NEGATIVE_FP_ZERO may be returned - (ie., when converting to a VMSish floating - point encoding). */ - - if (numElems < 1) return CDF_INTERNAL_ERROR; - - switch (dataType) { - /************************************************************************ - * Bytes/characters - these are the same on all supported computers so no - * conversion is necessary. - ************************************************************************/ - case CDF_BYTE: - case CDF_INT1: - case CDF_UINT1: - case CDF_CHAR: - case CDF_UCHAR: - MEMMOVE (dstBuffer, srcBuffer, (size_t) numElems) - break; - /************************************************************************ - * 2-byte integers. - ************************************************************************/ - case CDF_INT2: - case CDF_UINT2: - if (IntegerOrder(tSrcEncoding) == IntegerOrder(tDstEncoding)) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (2 * numElems)); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (2 * numElems)); - Reverse2 (dstBuffer, numElems); - } - break; - /************************************************************************ - * 4-byte integers. - ************************************************************************/ - case CDF_INT4: - case CDF_UINT4: - if (IntegerOrder(tSrcEncoding) == IntegerOrder(tDstEncoding)) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)); - Reverse4 (dstBuffer, numElems); - } - break; - /************************************************************************ - * 8-byte integers. - ************************************************************************/ - case CDF_INT8: - case CDF_TIME_TT2000: - if (IntegerOrder(tSrcEncoding) == IntegerOrder(tDstEncoding)) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)); - Reverse8 (dstBuffer, numElems); - } - break; - /************************************************************************ - * 4-byte floating-point values. - ************************************************************************/ - case CDF_REAL4: - case CDF_FLOAT: { - int srcFpType = FpType (tSrcEncoding); - int dstFpType = FpType (tDstEncoding); - switch (srcFpType) { - /******************************************************************** - * Floating-point/1 source encoding. - ********************************************************************/ - case FP_1: - switch (dstFpType) { - /**************************************************************** - * Floating-point/1 destination encoding desired. - ****************************************************************/ - case FP_1: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - FP1singleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - } - break; - /**************************************************************** - * Floating-point/2 destination encoding desired. - ****************************************************************/ - case FP_2: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - FP1toFP2singleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - Reverse4 (dstBuffer, numElems); - } - break; - /**************************************************************** - * Floating-point/34 destination encoding desired. - ****************************************************************/ - case FP_3: - case FP_4: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - FP1toFP34singleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - sX (FP1toFP34single(dstBuffer,numElems), &pStatus); - } - break; - } - break; - /******************************************************************** - * Floating-point/2 source encoding. - ********************************************************************/ - case FP_2: - switch (dstFpType) { - /**************************************************************** - * Floating-point/1 destination encoding desired. - ****************************************************************/ - case FP_1: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - FP2toFP1singleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - Reverse4 (dstBuffer, numElems); - } - break; - /**************************************************************** - * Floating-point/2 destination encoding desired. - ****************************************************************/ - case FP_2: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - FP2singleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - } - break; - /**************************************************************** - * Floating-point/34 destination encoding desired. - ****************************************************************/ - case FP_3: - case FP_4: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - FP2toFP34singleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - sX (FP2toFP34single(dstBuffer,numElems), &pStatus); - } - break; - } - break; - /******************************************************************** - * Floating-point/34 source encoding. - ********************************************************************/ - case FP_3: - case FP_4: - switch (dstFpType) { - /**************************************************************** - * Floating-point/1 destination encoding desired. - ****************************************************************/ - case FP_1: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - FP34toFP1singleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - FP34toFP1single (dstBuffer, numElems); - } - break; - /**************************************************************** - * Floating-point/2 destination encoding desired. - ****************************************************************/ - case FP_2: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - FP34toFP2singleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - FP34toFP2single (dstBuffer, numElems); - } - break; - /**************************************************************** - * Floating-point/34 destination encoding desired. - ****************************************************************/ - case FP_3: - case FP_4: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - FP34singleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems)) - } - break; - } - break; - } - break; - } - /************************************************************************ - * 8-byte floating-point values. - ************************************************************************/ - case CDF_REAL8: - case CDF_DOUBLE: - case CDF_EPOCH: { - int srcFpType = FpType (tSrcEncoding); - int dstFpType = FpType (tDstEncoding); - switch (srcFpType) { - /******************************************************************** - * Floating-point/1 source encoding. - ********************************************************************/ - case FP_1: - switch (dstFpType) { - /**************************************************************** - * Floating-point/1 destination encoding desired. - ****************************************************************/ - case FP_1: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP1doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - } - break; - /**************************************************************** - * Floating-point/2 destination encoding desired. - ****************************************************************/ - case FP_2: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP1toFP2doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - Reverse8 (dstBuffer, numElems); - } - break; - /**************************************************************** - * Floating-point/3 destination encoding desired. - ****************************************************************/ - case FP_3: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP1toFP3doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - sX (FP1toFP3double(dstBuffer,numElems), &pStatus); - } - break; - /**************************************************************** - * Floating-point/4 destination encoding desired. - ****************************************************************/ - case FP_4: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP1toFP4doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - sX (FP1toFP4double(dstBuffer,numElems), &pStatus); - } - break; - } - break; - /******************************************************************** - * Floating-point/2 source encoding. - ********************************************************************/ - case FP_2: - switch (dstFpType) { - /**************************************************************** - * Floating-point/1 destination encoding desired. - ****************************************************************/ - case FP_1: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP2toFP1doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - Reverse8 (dstBuffer, numElems); - } - break; - /**************************************************************** - * Floating-point/2 destination encoding desired. - ****************************************************************/ - case FP_2: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP2doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - } - break; - /**************************************************************** - * Floating-point/3 destination encoding desired. - ****************************************************************/ - case FP_3: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP2toFP3doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - sX (FP2toFP3double(dstBuffer,numElems), &pStatus); - } - break; - /**************************************************************** - * Floating-point/4 destination encoding desired. - ****************************************************************/ - case FP_4: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP2toFP4doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - sX (FP2toFP4double(dstBuffer,numElems), &pStatus); - } - break; - } - break; - /******************************************************************** - * Floating-point/3 source encoding. - ********************************************************************/ - case FP_3: - switch (dstFpType) { - /**************************************************************** - * Floating-point/1 destination encoding desired. - ****************************************************************/ - case FP_1: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP3toFP1doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP3toFP1double (dstBuffer, numElems); - } - break; - /**************************************************************** - * Floating-point/2 destination encoding desired. - ****************************************************************/ - case FP_2: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP3toFP2doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP3toFP2double (dstBuffer, numElems); - } - break; - /**************************************************************** - * Floating-point/3 destination encoding desired. - ****************************************************************/ - case FP_3: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP3doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) -#if LIMITfp3DOUBLEs - sX (FP3doubleLIMIT(dstBuffer,numElems), &pStatus); -#endif - } - break; - /**************************************************************** - * Floating-point/4 destination encoding desired. - ****************************************************************/ - case FP_4: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP3toFP4doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - sX (FP3toFP4double(dstBuffer,numElems), &pStatus); - } - break; - } - break; - /******************************************************************** - * Floating-point/4 source encoding. - ********************************************************************/ - case FP_4: - switch (dstFpType) { - /**************************************************************** - * Floating-point/1 destination encoding desired. - ****************************************************************/ - case FP_1: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP4toFP1doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP4toFP1double (dstBuffer, numElems); - } - break; - /**************************************************************** - * Floating-point/2 destination encoding desired. - ****************************************************************/ - case FP_2: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP4toFP2doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP4toFP2double (dstBuffer, numElems); - } - break; - /**************************************************************** - * Floating-point/3 destination encoding desired. - ****************************************************************/ - case FP_3: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP4toFP3doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - sX (FP4toFP3double(dstBuffer,numElems), &pStatus); - } - break; - /**************************************************************** - * Floating-point/4 destination encoding desired. - ****************************************************************/ - case FP_4: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - FP4doubleNEGtoPOS (dstBuffer, numElems); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems)) - } - break; - } - break; - } - break; - } - /************************************************************************ - * 2 8-byte floating-point values. - ************************************************************************/ - case CDF_EPOCH16: { - int srcFpType = FpType (tSrcEncoding); - int dstFpType = FpType (tDstEncoding); - switch (srcFpType) { - /******************************************************************** - * Floating-point/1 source encoding. - ********************************************************************/ - case FP_1: - switch (dstFpType) { - /**************************************************************** - * Floating-point/1 destination encoding desired. - ****************************************************************/ - case FP_1: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP1doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - } - break; - /**************************************************************** - * Floating-point/2 destination encoding desired. - ****************************************************************/ - case FP_2: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP1toFP2doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - Reverse8 (dstBuffer, numElems * 2); - } - break; - /**************************************************************** - * Floating-point/3 destination encoding desired. - ****************************************************************/ - case FP_3: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP1toFP3doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - sX (FP1toFP3double(dstBuffer,numElems * 2), &pStatus); - } - break; - /**************************************************************** - * Floating-point/4 destination encoding desired. - ****************************************************************/ - case FP_4: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP1toFP4doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - sX (FP1toFP4double(dstBuffer,numElems * 2), &pStatus); - } - break; - } - break; - /******************************************************************** - * Floating-point/2 source encoding. - ********************************************************************/ - case FP_2: - switch (dstFpType) { - /**************************************************************** - * Floating-point/1 destination encoding desired. - ****************************************************************/ - case FP_1: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP2toFP1doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - Reverse8 (dstBuffer, numElems * 2); - } - break; - /**************************************************************** - * Floating-point/2 destination encoding desired. - ****************************************************************/ - case FP_2: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP2doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - } - break; - /**************************************************************** - * Floating-point/3 destination encoding desired. - ****************************************************************/ - case FP_3: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP2toFP3doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - sX (FP2toFP3double(dstBuffer,numElems * 2), &pStatus); - } - break; - /**************************************************************** - * Floating-point/4 destination encoding desired. - ****************************************************************/ - case FP_4: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP2toFP4doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - sX (FP2toFP4double(dstBuffer,numElems * 2), &pStatus); - } - break; - } - break; - /******************************************************************** - * Floating-point/3 source encoding. - ********************************************************************/ - case FP_3: - switch (dstFpType) { - /**************************************************************** - * Floating-point/1 destination encoding desired. - ****************************************************************/ - case FP_1: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP3toFP1doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP3toFP1double (dstBuffer, numElems * 2); - } - break; - /**************************************************************** - * Floating-point/2 destination encoding desired. - ****************************************************************/ - case FP_2: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP3toFP2doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP3toFP2double (dstBuffer, numElems * 2); - } - break; - /**************************************************************** - * Floating-point/3 destination encoding desired. - ****************************************************************/ - case FP_3: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP3doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) -#if LIMITfp3DOUBLEs - sX (FP3doubleLIMIT(dstBuffer,numElems * 2), &pStatus); -#endif - } - break; - /**************************************************************** - * Floating-point/4 destination encoding desired. - ****************************************************************/ - case FP_4: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP3toFP4doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - sX (FP3toFP4double(dstBuffer,numElems * 2), &pStatus); - } - break; - } - break; - /******************************************************************** - * Floating-point/4 source encoding. - ********************************************************************/ - case FP_4: - switch (dstFpType) { - /**************************************************************** - * Floating-point/1 destination encoding desired. - ****************************************************************/ - case FP_1: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP4toFP1doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP4toFP1double (dstBuffer, numElems * 2); - } - break; - /**************************************************************** - * Floating-point/2 destination encoding desired. - ****************************************************************/ - case FP_2: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP4toFP2doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP4toFP2double (dstBuffer, numElems * 2); - } - break; - /**************************************************************** - * Floating-point/3 destination encoding desired. - ****************************************************************/ - case FP_3: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP4toFP3doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - sX (FP4toFP3double(dstBuffer,numElems * 2), &pStatus); - } - break; - /**************************************************************** - * Floating-point/4 destination encoding desired. - ****************************************************************/ - case FP_4: - if (negToPosFp0) { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - FP4doubleNEGtoPOS (dstBuffer, numElems * 2); - } - else { - MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2)) - } - break; - } - break; - } - break; - } - /************************************************************************ - * Unknown data type. - ************************************************************************/ - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* ConversionFunction. -******************************************************************************/ - -STATICforIDL CDFstatus ConversionFunction (dataType, encoding, decoding, - negToPosFp0, function) -Int32 dataType; -Int32 encoding; -Int32 decoding; -Logical negToPosFp0; -CDFstatus (**function) PROTOARGs((void *buffer, Int32 numElems)); -{ - Int32 tDecoding = BOO(decoding == HOST_DECODING,HostDecoding(), decoding); - switch (dataType) { - /************************************************************************** - * Bytes/characters - these are the same on all supported computers so no - * decoding is necessary. - **************************************************************************/ - case CDF_BYTE: - case CDF_INT1: - case CDF_UINT1: - case CDF_CHAR: - case CDF_UCHAR: - *function = NULL; - break; - /************************************************************************** - * 2-byte integers. - **************************************************************************/ - case CDF_INT2: - case CDF_UINT2: - if (IntegerOrder(encoding) == IntegerOrder(tDecoding)) - *function = NULL; - else - *function = Reverse2; - break; - /************************************************************************** - * 4-byte integers. - **************************************************************************/ - case CDF_INT4: - case CDF_UINT4: - if (IntegerOrder(encoding) == IntegerOrder(tDecoding)) - *function = NULL; - else - *function = Reverse4; - break; - /************************************************************************** - * 4-byte integers. - **************************************************************************/ - case CDF_INT8: - case CDF_TIME_TT2000: - if (IntegerOrder(encoding) == IntegerOrder(tDecoding)) - *function = NULL; - else - *function = Reverse8; - break; - /************************************************************************** - * 4-byte floating-point values. - **************************************************************************/ - case CDF_REAL4: - case CDF_FLOAT: { - int fpEncoding = FpType (encoding); - int fpDecoding = FpType (tDecoding); - switch (fpEncoding) { - /********************************************************************** - * Floating-point/1 encoding. - **********************************************************************/ - case FP_1: - switch (fpDecoding) { - /****************************************************************** - * Floating-point/1 encoding - floating-point/1 decoding desired. - ******************************************************************/ - case FP_1: - if (negToPosFp0) - *function = FP1singleNEGtoPOS; - else - *function = NULL; - break; - /****************************************************************** - * Floating-point/1 encoding - floating-point/2 decoding desired. - ******************************************************************/ - case FP_2: - if (negToPosFp0) - *function = FP1toFP2singleNEGtoPOS; - else - *function = Reverse4; - break; - /****************************************************************** - * Floating-point/1 encoding - floating-point/34 decoding desired. - ******************************************************************/ - case FP_3: - case FP_4: - if (negToPosFp0) - *function = FP1toFP34singleNEGtoPOS; - else - *function = FP1toFP34single; - break; - } - break; - /********************************************************************** - * Floating-point/2 encoding. - **********************************************************************/ - case FP_2: - switch (fpDecoding) { - /****************************************************************** - * Floating-point/2 encoding - floating-point/1 decoding desired. - ******************************************************************/ - case FP_1: - if (negToPosFp0) - *function = FP2toFP1singleNEGtoPOS; - else - *function = Reverse4; - break; - /****************************************************************** - * Floating-point/2 encoding - floating-point/2 decoding desired. - ******************************************************************/ - case FP_2: - if (negToPosFp0) - *function = FP2singleNEGtoPOS; - else - *function = NULL; - break; - /****************************************************************** - * Floating-point/2 encoding - floating-point/34 decoding desired. - ******************************************************************/ - case FP_3: - case FP_4: - if (negToPosFp0) - *function = FP2toFP34singleNEGtoPOS; - else - *function = FP2toFP34single; - break; - } - break; - /********************************************************************** - * Floating-point/34 encoding. - **********************************************************************/ - case FP_3: - case FP_4: - switch (fpDecoding) { - /****************************************************************** - * Floating-point/34 encoding - floating-point/1 decoding desired. - ******************************************************************/ - case FP_1: - if (negToPosFp0) - *function = FP34toFP1singleNEGtoPOS; - else - *function = FP34toFP1single; - break; - /****************************************************************** - * Floating-point/34 encoding - floating-point/2 decoding desired. - ******************************************************************/ - case FP_2: - if (negToPosFp0) - *function = FP34toFP2singleNEGtoPOS; - else - *function = FP34toFP2single; - break; - /****************************************************************** - * Floating-point/34 encoding - floating-point/34 decoding - * desired. - ******************************************************************/ - case FP_3: - case FP_4: - if (negToPosFp0) - *function = FP34singleNEGtoPOS; - else - *function = NULL; - break; - } - break; - } - break; - } - /************************************************************************** - * 8-byte floating-point values. - **************************************************************************/ - case CDF_REAL8: - case CDF_DOUBLE: - case CDF_EPOCH: { - int fpEncoding = FpType (encoding); - int fpDecoding = FpType (tDecoding); - switch (fpEncoding) { - /********************************************************************** - * Floating-point/1 encoding. - **********************************************************************/ - case FP_1: - switch (fpDecoding) { - /****************************************************************** - * Floating-point/1 encoding - floating-point/1 decoding desired. - ******************************************************************/ - case FP_1: - if (negToPosFp0) - *function = FP1doubleNEGtoPOS; - else - *function = NULL; - break; - /****************************************************************** - * Floating-point/1 encoding - floating-point/2 decoding desired. - ******************************************************************/ - case FP_2: - if (negToPosFp0) - *function = FP1toFP2doubleNEGtoPOS; - else - *function = Reverse8; - break; - /****************************************************************** - * Floating-point/1 encoding - floating-point/3 decoding desired. - ******************************************************************/ - case FP_3: - if (negToPosFp0) - *function = FP1toFP3doubleNEGtoPOS; - else - *function = FP1toFP3double; - break; - /****************************************************************** - * Floating-point/1 encoding - floating-point/4 decoding desired. - ******************************************************************/ - case FP_4: - if (negToPosFp0) - *function = FP1toFP4doubleNEGtoPOS; - else - *function = FP1toFP4double; - break; - } - break; - /********************************************************************** - * Floating-point/2 encoding. - **********************************************************************/ - case FP_2: - switch (fpDecoding) { - /****************************************************************** - * Floating-point/2 encoding - floating-point/1 decoding desired. - ******************************************************************/ - case FP_1: - if (negToPosFp0) - *function = FP2toFP1doubleNEGtoPOS; - else - *function = Reverse8; - break; - /****************************************************************** - * Floating-point/2 encoding - floating-point/2 decoding desired. - ******************************************************************/ - case FP_2: - if (negToPosFp0) - *function = FP2doubleNEGtoPOS; - else - *function = NULL; - break; - /****************************************************************** - * Floating-point/2 encoding - floating-point/3 decoding desired. - ******************************************************************/ - case FP_3: - if (negToPosFp0) - *function = FP2toFP3doubleNEGtoPOS; - else - *function = FP2toFP3double; - break; - /****************************************************************** - * Floating-point/2 encoding - floating-point/4 decoding desired. - ******************************************************************/ - case FP_4: - if (negToPosFp0) - *function = FP2toFP4doubleNEGtoPOS; - else - *function = FP2toFP4double; - break; - } - break; - /********************************************************************** - * Floating-point/3 encoding. - **********************************************************************/ - case FP_3: - switch (fpDecoding) { - /****************************************************************** - * Floating-point/3 encoding - floating-point/1 decoding desired. - ******************************************************************/ - case FP_1: - if (negToPosFp0) - *function = FP3toFP1doubleNEGtoPOS; - else - *function = FP3toFP1double; - break; - /****************************************************************** - * Floating-point/3 encoding - floating-point/2 decoding desired. - ******************************************************************/ - case FP_2: - if (negToPosFp0) - *function = FP3toFP2doubleNEGtoPOS; - else - *function = FP3toFP2double; - break; - /****************************************************************** - * Floating-point/3 encoding - floating-point/3 decoding desired. - ******************************************************************/ - case FP_3: - if (negToPosFp0) - *function = FP3doubleNEGtoPOS; - else -#if LIMITfp3DOUBLEs - *function = FP3doubleLIMIT; -#else - *function = NULL; -#endif - break; - /****************************************************************** - * Floating-point/3 encoding - floating-point/4 decoding desired. - ******************************************************************/ - case FP_4: - if (negToPosFp0) - *function = FP3toFP4doubleNEGtoPOS; - else - *function = FP3toFP4double; - break; - } - break; - /********************************************************************** - * Floating-point/4 encoding. - **********************************************************************/ - case FP_4: - switch (fpDecoding) { - /****************************************************************** - * Floating-point/4 encoding - floating-point/1 decoding desired. - ******************************************************************/ - case FP_1: - if (negToPosFp0) - *function = FP4toFP1doubleNEGtoPOS; - else - *function = FP4toFP1double; - break; - /****************************************************************** - * Floating-point/4 encoding - floating-point/2 decoding desired. - ******************************************************************/ - case FP_2: - if (negToPosFp0) - *function = FP4toFP2doubleNEGtoPOS; - else - *function = FP4toFP2double; - break; - /****************************************************************** - * Floating-point/4 encoding - floating-point/3 decoding desired. - ******************************************************************/ - case FP_3: - if (negToPosFp0) - *function = FP4toFP3doubleNEGtoPOS; - else - *function = FP4toFP3double; - break; - /****************************************************************** - * Floating-point/4 encoding - floating-point/4 decoding desired. - ******************************************************************/ - case FP_4: - if (negToPosFp0) - *function = FP4doubleNEGtoPOS; - else - *function = NULL; - break; - } - break; - } - break; - } - /************************************************************************** - * 2 8-byte floating-point values. - **************************************************************************/ - case CDF_EPOCH16: { - int fpEncoding = FpType (encoding); - int fpDecoding = FpType (tDecoding); - switch (fpEncoding) { - /********************************************************************** - * Floating-point/1 encoding. - **********************************************************************/ - case FP_1: - switch (fpDecoding) { - /****************************************************************** - * Floating-point/1 encoding - floating-point/1 decoding desired. - ******************************************************************/ - case FP_1: - if (negToPosFp0) - *function = FP1doubleNEGtoPOS; - else - *function = NULL; - break; - /****************************************************************** - * Floating-point/1 encoding - floating-point/2 decoding desired. - ******************************************************************/ - case FP_2: - if (negToPosFp0) - *function = FP1toFP2doubleNEGtoPOS; - else - *function = Reverse16; - break; - /****************************************************************** - * Floating-point/1 encoding - floating-point/3 decoding desired. - ******************************************************************/ - case FP_3: - if (negToPosFp0) - *function = FP1toFP3doubleNEGtoPOS; - else - *function = FP1toFP3double; - break; - /****************************************************************** - * Floating-point/1 encoding - floating-point/4 decoding desired. - ******************************************************************/ - case FP_4: - if (negToPosFp0) - *function = FP1toFP4doubleNEGtoPOS; - else - *function = FP1toFP4double; - break; - } - break; - /********************************************************************** - * Floating-point/2 encoding. - **********************************************************************/ - case FP_2: - switch (fpDecoding) { - /****************************************************************** - * Floating-point/2 encoding - floating-point/1 decoding desired. - ******************************************************************/ - case FP_1: - if (negToPosFp0) - *function = FP2toFP1doubleNEGtoPOS; - else - *function = Reverse16; - break; - /****************************************************************** - * Floating-point/2 encoding - floating-point/2 decoding desired. - ******************************************************************/ - case FP_2: - if (negToPosFp0) - *function = FP2doubleNEGtoPOS; - else - *function = NULL; - break; - /****************************************************************** - * Floating-point/2 encoding - floating-point/3 decoding desired. - ******************************************************************/ - case FP_3: - if (negToPosFp0) - *function = FP2toFP3doubleNEGtoPOS; - else - *function = FP2toFP3double; - break; - /****************************************************************** - * Floating-point/2 encoding - floating-point/4 decoding desired. - ******************************************************************/ - case FP_4: - if (negToPosFp0) - *function = FP2toFP4doubleNEGtoPOS; - else - *function = FP2toFP4double; - break; - } - break; - /********************************************************************** - * Floating-point/3 encoding. - **********************************************************************/ - case FP_3: - switch (fpDecoding) { - /****************************************************************** - * Floating-point/3 encoding - floating-point/1 decoding desired. - ******************************************************************/ - case FP_1: - if (negToPosFp0) - *function = FP3toFP1doubleNEGtoPOS; - else - *function = FP3toFP1double; - break; - /****************************************************************** - * Floating-point/3 encoding - floating-point/2 decoding desired. - ******************************************************************/ - case FP_2: - if (negToPosFp0) - *function = FP3toFP2doubleNEGtoPOS; - else - *function = FP3toFP2double; - break; - /****************************************************************** - * Floating-point/3 encoding - floating-point/3 decoding desired. - ******************************************************************/ - case FP_3: - if (negToPosFp0) - *function = FP3doubleNEGtoPOS; - else -#if LIMITfp3DOUBLEs - *function = FP3doubleLIMIT; -#else - *function = NULL; -#endif - break; - /****************************************************************** - * Floating-point/3 encoding - floating-point/4 decoding desired. - ******************************************************************/ - case FP_4: - if (negToPosFp0) - *function = FP3toFP4doubleNEGtoPOS; - else - *function = FP3toFP4double; - break; - } - break; - /********************************************************************** - * Floating-point/4 encoding. - **********************************************************************/ - case FP_4: - switch (fpDecoding) { - /****************************************************************** - * Floating-point/4 encoding - floating-point/1 decoding desired. - ******************************************************************/ - case FP_1: - if (negToPosFp0) - *function = FP4toFP1doubleNEGtoPOS; - else - *function = FP4toFP1double; - break; - /****************************************************************** - * Floating-point/4 encoding - floating-point/2 decoding desired. - ******************************************************************/ - case FP_2: - if (negToPosFp0) - *function = FP4toFP2doubleNEGtoPOS; - else - *function = FP4toFP2double; - break; - /****************************************************************** - * Floating-point/4 encoding - floating-point/3 decoding desired. - ******************************************************************/ - case FP_3: - if (negToPosFp0) - *function = FP4toFP3doubleNEGtoPOS; - else - *function = FP4toFP3double; - break; - /****************************************************************** - * Floating-point/4 encoding - floating-point/4 decoding desired. - ******************************************************************/ - case FP_4: - if (negToPosFp0) - *function = FP4doubleNEGtoPOS; - else - *function = NULL; - break; - } - break; - } - break; - } - /************************************************************************** - * Unknown data type. - **************************************************************************/ - default: - return CDF_INTERNAL_ERROR; - } - return CDF_OK; -} - -/****************************************************************************** -* FP1toFP34single. -* Floating-point/1 to floating-point/34, single-precision. -******************************************************************************/ - -STATICforIDL CDFstatus FP1toFP34single (buffer, numElems) -void *buffer; -Int32 numElems; -{ - uInt16 fp1e, fp34e; - uInt32 fp1m, fp34m; - struct fp1struct4 *fp1; - struct fp34struct4 *fp34, Fp34; - CDFstatus pStatus = CDF_OK; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp34struct4 FP34zeroSingle = { FP34ZEROsingle }; - struct fp34struct4 FP34minSingle = { FP34MINsingle }; - struct fp34struct4 FP34maxSingle = { FP34MAXsingle }; -#endif - for (elemN = 0, - fp1 = (struct fp1struct4 *) buffer, - fp34 = (struct fp34struct4 *) buffer; - elemN < numElems; - elemN++, fp1++, fp34++) { - /************************************************************************* - * Calculate FP1's exponent. - *************************************************************************/ - fp1e = (fp1->e1 << 1) | fp1->e0; - switch (fp1e) { - /*********************************************************************** - * FP1 exponent of zero (0) - what to do depends on the FP1 mantissa. - ***********************************************************************/ - case 0x0: - fp1m = (fp1->m2 << 16) | (fp1->m1 << 8) | fp1->m0; - /********************************************************************* - * If the FP1 mantissa is zero (0), set FP34 to 0.0 and use the sign - * from FP1. Also check for -0.0. - *********************************************************************/ - if (fp1m == 0x0) { - Fp34 = FP34zeroSingle; - Fp34.s = fp1->s; - if (Fp34.s == 0x1) pStatus = NEGATIVE_FP_ZERO; - break; - } - /********************************************************************* - * If the FP1 mantissa (with an FP1 exponent of zero [0]) puts the FP1 - * value below the smallest magnitude possible for FP34, set FP34 to - * its minimum magnitude but with FP1's sign. - *********************************************************************/ - if (fp1m < 0x200000) { - Fp34 = FP34minSingle; - Fp34.s = fp1->s; - break; - } - /********************************************************************* - * If the FP1 mantissa is in the range where it maps 1-to-4 to FP34 - * mantissas, set the FP34 mantissa to the first (lowest) value which - * maps. - *********************************************************************/ - if (fp1m < 0x400000) { - fp34e = 0x1; - Fp34.e1 = fp34e >> 1; - Fp34.e0 = fp34e; - fp34m = 4 * (fp1m - 0x200000); - Fp34.m2 = (Byte1) (fp34m >> 16); - Fp34.m1 = (Byte1) (fp34m >> 8); - Fp34.m0 = (Byte1) fp34m; - Fp34.s = fp1->s; - break; - } - /********************************************************************* - * The FP1 mantissa is in the range where it maps 1-to-2 to FP34 - * mantissas, set the FP34 mantissa to the first (lowest) value which - * maps. - *********************************************************************/ - fp34e = 0x2; - Fp34.e1 = fp34e >> 1; - Fp34.e0 = fp34e; - fp34m = 2 * (fp1m - 0x400000); - Fp34.m2 = (Byte1) (fp34m >> 16); - Fp34.m1 = (Byte1) (fp34m >> 8); - Fp34.m0 = (Byte1) fp34m; - Fp34.s = fp1->s; - break; - /*********************************************************************** - * The FP1 exponent puts the FP1 value beyond the largest magnitude - * possible for FP34 - set FP34 to its maximum magnitude but with FP1's - * sign. - ***********************************************************************/ - case 0xFE: - case 0xFF: - Fp34 = FP34maxSingle; - Fp34.s = fp1->s; - break; - /*********************************************************************** - * The FP1 value will `fit' into FP34. - ***********************************************************************/ - default: - fp34e = fp1e + 2; - Fp34.e1 = fp34e >> 1; - Fp34.e0 = fp34e; - Fp34.m2 = fp1->m2; - Fp34.m1 = fp1->m1; - Fp34.m0 = fp1->m0; - Fp34.s = fp1->s; - } - *fp34 = Fp34; - } - return pStatus; -} - -/****************************************************************************** -* FP1toFP34singleNEGtoPOS. -* Floating-point/1 to floating-point/34, single-precision. Convert -0.0 -* to 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP1toFP34singleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - CDFstatus status = FP1toFP34single (buffer, numElems); - if (status == NEGATIVE_FP_ZERO) FP34singleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP2toFP34single. -* Floating-point/2 to floating-point/34, single-precision. -* See FP1toFP34single for comments. -******************************************************************************/ - -STATICforIDL CDFstatus FP2toFP34single (buffer, numElems) -void *buffer; -Int32 numElems; -{ - uInt16 fp2e, fp34e; - uInt32 fp2m, fp34m; - struct fp2struct4 *fp2; - struct fp34struct4 *fp34, Fp34; - CDFstatus pStatus = CDF_OK; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp34struct4 FP34zeroSingle = { FP34ZEROsingle }; - struct fp34struct4 FP34minSingle = { FP34MINsingle }; - struct fp34struct4 FP34maxSingle = { FP34MAXsingle }; -#endif - for (elemN = 0, - fp2 = (struct fp2struct4 *) buffer, - fp34 = (struct fp34struct4 *) buffer; - elemN < numElems; - elemN++, fp2++, fp34++) { - fp2e = (fp2->e1 << 1) | fp2->e0; - switch (fp2e) { - case 0x0: - fp2m = (fp2->m2 << 16) | (fp2->m1 << 8) | fp2->m0; - if (fp2m == 0x0) { - Fp34 = FP34zeroSingle; - Fp34.s = fp2->s; - if (Fp34.s == 0x1) pStatus = NEGATIVE_FP_ZERO; - break; - } - if (fp2m < 0x200000) { - Fp34 = FP34minSingle; - Fp34.s = fp2->s; - break; - } - if (fp2m < 0x400000) { - fp34e = 0x1; - Fp34.e1 = fp34e >> 1; - Fp34.e0 = fp34e; - fp34m = 4 * (fp2m - 0x200000); - Fp34.m2 = (Byte1) (fp34m >> 16); - Fp34.m1 = (Byte1) (fp34m >> 8); - Fp34.m0 = (Byte1) fp34m; - Fp34.s = fp2->s; - break; - } - fp34e = 0x2; - Fp34.e1 = fp34e >> 1; - Fp34.e0 = fp34e; - fp34m = 2 * (fp2m - 0x400000); - Fp34.m2 = (Byte1) (fp34m >> 16); - Fp34.m1 = (Byte1) (fp34m >> 8); - Fp34.m0 = (Byte1) fp34m; - Fp34.s = fp2->s; - break; - case 0xFE: - case 0xFF: - Fp34 = FP34maxSingle; - Fp34.s = fp2->s; - break; - default: - fp34e = fp2e + 2; - Fp34.e1 = fp34e >> 1; - Fp34.e0 = fp34e; - Fp34.m2 = fp2->m2; - Fp34.m1 = fp2->m1; - Fp34.m0 = fp2->m0; - Fp34.s = fp2->s; - } - *fp34 = Fp34; - } - return pStatus; -} - -/****************************************************************************** -* FP2toFP34singleNEGtoPOS. -* Floating-point/2 to floating-point/34, single-precision. Convert -0.0 -* to 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP2toFP34singleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - CDFstatus status = FP2toFP34single (buffer, numElems); - if (status == NEGATIVE_FP_ZERO) FP34singleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP34toFP1single. -* Floating-point/34 to floating-point/1, single-precision. -******************************************************************************/ - -STATICforIDL CDFstatus FP34toFP1single (buffer, numElems) -void *buffer; -Int32 numElems; -{ - uInt16 fp34e, fp1e; - uInt32 fp34m, fp1m; - struct fp34struct4 *fp34; - struct fp1struct4 *fp1, Fp1; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp1struct4 FP1zeroSingle = { FP1ZEROsingle }; -#endif - for (elemN = 0, - fp34 = (struct fp34struct4 *) buffer, - fp1 = (struct fp1struct4 *) buffer; - elemN < numElems; - elemN++, fp34++, fp1++) { - /************************************************************************* - * Calculate the FP34 exponent. - *************************************************************************/ - fp34e = (fp34->e1 << 1) | fp34->e0; - switch (fp34e) { - /*********************************************************************** - * If the FP34 exponent is zero (0), the value is 0.0 regardless of the - * FP34 mantissa. The FP34 sign shouldn't be set either since -0.0 - * isn't valid value on VAXes. But since it might be set (for whatever - * reason), set FP1's sign to that of FP34. - ***********************************************************************/ - case 0x0: - Fp1 = FP1zeroSingle; - Fp1.s = fp34->s; - break; - /*********************************************************************** - * FP34 exponents of one (1) or two (2) indicate values whose mantissas - * are not the same between FP34 and FP1. For an FP34 exponent of one - * (1), the FP1 exponent is zero (0) and the full range of FP34 - * mantissas (0x0 through 0x7FFFFF) maps into the smaller range of FP1 - * mantissas from 0x200000 to 0x3FFFFF (a 4-to-1 mapping which means - * that only one out of four FP34 values in this range maps perfectly to - * FP1). For an FP34 exponent of two (2), the FP1 exponent is zero (0) - * and the full range of FP34 mantissas (0x0 through 0x7FFFFF) maps into - * the smaller range of FP1 mantissas from 0x400000 to 0x7FFFFF (a - * 2-to-1 mapping which means that only one out of two FP34 values in - * this range maps perfectly to FP1). - ***********************************************************************/ - case 0x1: - case 0x2: - fp34m = (fp34->m2 << 16) | (fp34->m1 << 8) | fp34->m0; - if (fp34e == 0x1) - fp1m = 0x200000 + (fp34m / 4); - else - fp1m = 0x400000 + (fp34m / 2); - Fp1.m2 = (Byte1) (fp1m >> 16); - Fp1.m1 = (Byte1) (fp1m >> 8); - Fp1.m0 = (Byte1) fp1m; - Fp1.e1 = 0x0; - Fp1.e0 = 0x0; - Fp1.s = fp34->s; - break; - /*********************************************************************** - * All other FP34 exponents are for FP34 values that map perfectly to FP1 - * (the FP1 exponent is just two less than the FP34 exponent). - ***********************************************************************/ - default: - Fp1.m2 = fp34->m2; - Fp1.m1 = fp34->m1; - Fp1.m0 = fp34->m0; - fp1e = fp34e - 2; - Fp1.e1 = fp1e >> 1; - Fp1.e0 = fp1e; - Fp1.s = fp34->s; - } - *fp1 = Fp1; - } - return CDF_OK; -} - -/****************************************************************************** -* FP34toFP1singleNEGtoPOS. -* Floating-point/34 to floating-point/1, single-precision. Convert -0.0 -* to 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP34toFP1singleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - FP34toFP1single (buffer, numElems); - FP1singleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP34toFP2single. -* Floating-point/34 to floating-point/2, single-precision. -* See FP34toFP1single for comments. -******************************************************************************/ - -STATICforIDL CDFstatus FP34toFP2single (buffer, numElems) -void *buffer; -Int32 numElems; -{ - uInt16 fp34e, fp2e; - uInt32 fp34m, fp2m; - struct fp34struct4 *fp34; - struct fp2struct4 *fp2, Fp2; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp2struct4 FP2zeroSingle = { FP2ZEROsingle }; -#endif - for (elemN = 0, - fp34 = (struct fp34struct4 *) buffer, - fp2 = (struct fp2struct4 *) buffer; - elemN < numElems; - elemN++, fp34++, fp2++) { - fp34e = (fp34->e1 << 1) | fp34->e0; - switch (fp34e) { - case 0x0: - Fp2 = FP2zeroSingle; - Fp2.s = fp34->s; - break; - case 0x1: - case 0x2: - fp34m = (fp34->m2 << 16) | (fp34->m1 << 8) | fp34->m0; - if (fp34e == 0x1) - fp2m = 0x200000 + (fp34m / 4); - else - fp2m = 0x400000 + (fp34m / 2); - Fp2.m2 = (Byte1) (fp2m >> 16); - Fp2.m1 = (Byte1) (fp2m >> 8); - Fp2.m0 = (Byte1) fp2m; - Fp2.e1 = 0x0; - Fp2.e0 = 0x0; - Fp2.s = fp34->s; - break; - default: - Fp2.m2 = fp34->m2; - Fp2.m1 = fp34->m1; - Fp2.m0 = fp34->m0; - fp2e = fp34e - 2; - Fp2.e1 = fp2e >> 1; - Fp2.e0 = fp2e; - Fp2.s = fp34->s; - } - *fp2 = Fp2; - } - return CDF_OK; -} - -/****************************************************************************** -* FP34toFP2singleNEGtoPOS. -* Floating-point/34 to floating-point/2, single-precision. Convert -0.0 -* to 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP34toFP2singleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - FP34toFP2single (buffer, numElems); - FP2singleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP1toFP3double. -* Floating-point/1 to floating-point/3, double-precision. -******************************************************************************/ - -STATICforIDL CDFstatus FP1toFP3double (buffer, numElems) -void *buffer; -Int32 numElems; -{ - uInt16 fp1e, fp3e; - struct fp1struct8 *fp1; - struct fp3struct8 *fp3, Fp3; - Int32 elemN; - CDFstatus pStatus = CDF_OK; -#if DYNAMICfpSTRUCTs - struct fp3struct8 FP3zeroDouble = { FP3ZEROdouble }; - struct fp3struct8 FP3minDouble = { FP3MINdouble }; - struct fp3struct8 FP3maxDouble = { FP3MAXdouble }; -#endif - for (elemN = 0, - fp1 = (struct fp1struct8 *) buffer, - fp3 = (struct fp3struct8 *) buffer; - elemN < numElems; - elemN++, fp1++, fp3++) { - /************************************************************************* - * Calculate the FP1 exponent. - *************************************************************************/ - fp1e = (fp1->e1 << 4) | fp1->e0; - /************************************************************************* - * Check if the FP1 exponent is too small for FP3 (but not 0.0). If so, - * set the FP3 value to its smallest possible magnitude (but use FP1's - * sign). Also check for -0.0. - *************************************************************************/ - if (fp1e < 0x37F) { - if (fp1e == 0x0 && - fp1->m0 == 0x0 && fp1->m1 == 0x0 && fp1->m2 == 0x0 && - fp1->m3 == 0x0 && fp1->m4 == 0x0 && fp1->m5 == 0x0 && - fp1->m6 == 0x0) { - Fp3 = FP3zeroDouble; - Fp3.s = fp1->s; - if (Fp3.s == 0x1) pStatus = NEGATIVE_FP_ZERO; - } - else { - Fp3 = FP3minDouble; - Fp3.s = fp1->s; - } - *fp3 = Fp3; - continue; - } - /************************************************************************* - * Check if the FP1 exponent is too large for FP3. If so, set the FP3 - * value to its largest possible magnitude (but use FP1's sign). - *************************************************************************/ - if (fp1e > 0x47D) { - Fp3 = FP3maxDouble; - Fp3.s = fp1->s; - *fp3 = Fp3; - continue; - } - /************************************************************************* - * The FP1 value will `fit' but the three (extra) least significant bits of - * the FP3 mantissa are set to zero when the FP1 mantissa is copied to the - * FP3 mantissa. - *************************************************************************/ - fp3e = fp1e - 0x37E; - Fp3.e0 = fp3e; - Fp3.e1 = fp3e >> 1; - Fp3.m0 = fp1->m0 << 3; - Fp3.m1 = (fp1->m1 << 3) | (fp1->m0 >> 5); - Fp3.m2 = (fp1->m2 << 3) | (fp1->m1 >> 5); - Fp3.m3 = (fp1->m3 << 3) | (fp1->m2 >> 5); - Fp3.m4 = (fp1->m4 << 3) | (fp1->m3 >> 5); - Fp3.m5 = (fp1->m5 << 3) | (fp1->m4 >> 5); - Fp3.m6 = (fp1->m6 << 3) | (fp1->m5 >> 5); - Fp3.s = fp1->s; - *fp3 = Fp3; - } -#if LIMITfp3DOUBLEs - /**************************************************************************** - * If this is a DEC Alpha (OpenVMS or POSIX Shell) built for a default of - * D_FLOAT, check that the values do not exceed the maximum. - ****************************************************************************/ - FP3doubleLIMIT (buffer, numElems); -#endif - return pStatus; -} - -/****************************************************************************** -* FP1toFP3doubleNEGtoPOS. -* Floating-point/1 to floating-point/3, double-precision. Convert -0.0 to -* 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP1toFP3doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - CDFstatus status = FP1toFP3double (buffer, numElems); - if (status == NEGATIVE_FP_ZERO) FP3doubleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP1toFP4double. -* Floating-point/1 to floating-point/4, double-precision. -******************************************************************************/ - -STATICforIDL CDFstatus FP1toFP4double (buffer, numElems) -void *buffer; -Int32 numElems; -{ - uInt16 fp1e, fp4e; - uInt32 fp1mH, fp1mL, fp4mH, fp4mL; - struct fp1struct8 *fp1; - struct fp4struct8 *fp4, Fp4; - CDFstatus pStatus = CDF_OK; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp4struct8 FP4zeroDouble = { FP4ZEROdouble }; - struct fp4struct8 FP4minDouble = { FP4MINdouble }; - struct fp4struct8 FP4maxDouble = { FP4MAXdouble }; -#endif - for (elemN = 0, - fp1 = (struct fp1struct8 *) buffer, - fp4 = (struct fp4struct8 *) buffer; - elemN < numElems; - elemN++, fp1++, fp4++) { - /************************************************************************* - * Calculate FP1's exponent. - *************************************************************************/ - fp1e = (fp1->e1 << 4) | fp1->e0; - switch (fp1e) { - /*********************************************************************** - * FP1 exponent of zero (0) - what to do depends on the FP1 mantissa. - ***********************************************************************/ - case 0x0: - fp1mH = (fp1->m6 << 16) | (fp1->m5 << 8) | fp1->m4; - fp1mL = (fp1->m3 << 24) | (fp1->m2 << 16) | (fp1->m1 << 8) | fp1->m0; - /********************************************************************* - * If the FP1 mantissa is zero (0), set FP34 to 0.0 and use the sign - * from FP1. Also check for -0.0. - *********************************************************************/ - if (fp1mH == 0x0 && fp1mL == 0x0) { - Fp4 = FP4zeroDouble; - Fp4.s = fp1->s; - if (Fp4.s == 0x1) pStatus = NEGATIVE_FP_ZERO; - break; - } - /********************************************************************* - * If the FP1 mantissa (with an FP1 exponent of zero [0]) puts the FP1 - * value below the smallest magnitude possible for FP4, set FP4 to its - * minimum magnitude but with FP1's sign. - *********************************************************************/ - if (fp1mH < 0x40000) { - Fp4 = FP4minDouble; - Fp4.s = fp1->s; - break; - } - /********************************************************************* - * If the FP1 mantissa is in the range where it maps 1-to-4 to FP4 - * mantissas, set the FP4 mantissa to the first (lowest) value which - * maps. - *********************************************************************/ - if (fp1mH < 0x80000) { - Fp4.e1 = 0x0; - Fp4.e0 = 0x1; - fp4mH = ((fp1mH - 0x40000) << 2) | (fp1mL >> 30); - fp4mL = fp1mL << 2; - Fp4.m6 = (Byte1) (fp4mH >> 16); - Fp4.m5 = (Byte1) (fp4mH >> 8); - Fp4.m4 = (Byte1) (fp4mH); - Fp4.m3 = (Byte1) (fp4mL >> 24); - Fp4.m2 = (Byte1) (fp4mL >> 16); - Fp4.m1 = (Byte1) (fp4mL >> 8); - Fp4.m0 = (Byte1) (fp4mL); - Fp4.s = fp1->s; - break; - } - /********************************************************************* - * The FP1 mantissa is in the range where it maps 1-to-2 to FP4 - * mantissas, set the FP4 mantissa to the first (lowest) value which - * maps. - *********************************************************************/ - Fp4.e1 = 0x0; - Fp4.e0 = 0x2; - fp4mH = ((fp1mH - 0x80000) << 1) | (fp1mL >> 31); - fp4mL = fp1mL << 1; - Fp4.m6 = (Byte1) (fp4mH >> 16); - Fp4.m5 = (Byte1) (fp4mH >> 8); - Fp4.m4 = (Byte1) (fp4mH); - Fp4.m3 = (Byte1) (fp4mL >> 24); - Fp4.m2 = (Byte1) (fp4mL >> 16); - Fp4.m1 = (Byte1) (fp4mL >> 8); - Fp4.m0 = (Byte1) (fp4mL); - Fp4.s = fp1->s; - break; - /*********************************************************************** - * The FP1 exponent puts the FP1 value beyond the largest magnitude - * possible for FP4 - set FP4 to its maximum magnitude but with FP1's - * sign. - ***********************************************************************/ - case 0x7FE: - case 0x7FF: - Fp4 = FP4maxDouble; - Fp4.s = fp1->s; - break; - /*********************************************************************** - * The FP1 value will `fit' into FP4. - ***********************************************************************/ - default: - fp4e = fp1e + 2; - Fp4.e1 = fp4e >> 4; - Fp4.e0 = fp4e; - Fp4.m6 = fp1->m6; - Fp4.m5 = fp1->m5; - Fp4.m4 = fp1->m4; - Fp4.m3 = fp1->m3; - Fp4.m2 = fp1->m2; - Fp4.m1 = fp1->m1; - Fp4.m0 = fp1->m0; - Fp4.s = fp1->s; - } - *fp4 = Fp4; - } - return pStatus; -} - -/****************************************************************************** -* FP1toFP4doubleNEGtoPOS. -* Floating-point/1 to floating-point/4, double-precision. Convert -0.0 to -* 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP1toFP4doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - CDFstatus status = FP1toFP4double (buffer, numElems); - if (status == NEGATIVE_FP_ZERO) FP4doubleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP2toFP3double. -* Floating-point/2 to floating-point/3, double-precision. -* See FP1toFP3double for comments. -******************************************************************************/ - -STATICforIDL CDFstatus FP2toFP3double (buffer, numElems) -void *buffer; -Int32 numElems; -{ - uInt16 fp2e, fp3e; - struct fp2struct8 *fp2; - struct fp3struct8 *fp3, Fp3; - Int32 elemN; - CDFstatus pStatus = CDF_OK; -#if DYNAMICfpSTRUCTs - struct fp3struct8 FP3zeroDouble = { FP3ZEROdouble }; - struct fp3struct8 FP3minDouble = { FP3MINdouble }; - struct fp3struct8 FP3maxDouble = { FP3MAXdouble }; -#endif - for (elemN = 0, - fp2 = (struct fp2struct8 *) buffer, - fp3 = (struct fp3struct8 *) buffer; - elemN < numElems; - elemN++, fp2++, fp3++) { - fp2e = (fp2->e1 << 4) | fp2->e0; - if (fp2e < 0x37F) { - if (fp2e == 0x0 && - fp2->m0 == 0x0 && fp2->m1 == 0x0 && fp2->m2 == 0x0 && - fp2->m3 == 0x0 && fp2->m4 == 0x0 && fp2->m5 == 0x0 && - fp2->m6 == 0x0) { - Fp3 = FP3zeroDouble; - Fp3.s = fp2->s; - if (Fp3.s == 0x1) pStatus = NEGATIVE_FP_ZERO; - } - else { - Fp3 = FP3minDouble; - Fp3.s = fp2->s; - } - *fp3 = Fp3; - continue; - } - if (fp2e > 0x47D) { - Fp3 = FP3maxDouble; - Fp3.s = fp2->s; - *fp3 = Fp3; - continue; - } - fp3e = fp2e - 0x37E; - Fp3.e0 = fp3e; - Fp3.e1 = fp3e >> 1; - Fp3.m0 = fp2->m0 << 3; - Fp3.m1 = (fp2->m1 << 3) | (fp2->m0 >> 5); - Fp3.m2 = (fp2->m2 << 3) | (fp2->m1 >> 5); - Fp3.m3 = (fp2->m3 << 3) | (fp2->m2 >> 5); - Fp3.m4 = (fp2->m4 << 3) | (fp2->m3 >> 5); - Fp3.m5 = (fp2->m5 << 3) | (fp2->m4 >> 5); - Fp3.m6 = (fp2->m6 << 3) | (fp2->m5 >> 5); - Fp3.s = fp2->s; - *fp3 = Fp3; - } -#if LIMITfp3DOUBLEs - /**************************************************************************** - * If this is a DEC Alpha (OpenVMS or POSIX Shell) built for a default of - * D_FLOAT, check that the values do not exceed the maximum. - ****************************************************************************/ - FP3doubleLIMIT (buffer, numElems); -#endif - return pStatus; -} - -/****************************************************************************** -* FP2toFP3doubleNEGtoPOS. -* Floating-point/2 to floating-point/3, double-precision. Convert -0.0 to -* 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP2toFP3doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - CDFstatus status = FP2toFP3double (buffer, numElems); - if (status == NEGATIVE_FP_ZERO) FP3doubleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP2toFP4double. -* Floating-point/2 to floating-point/4, double-precision. -* See FP1toFP4double for comments. -******************************************************************************/ - -STATICforIDL CDFstatus FP2toFP4double (buffer, numElems) -void *buffer; -Int32 numElems; -{ - uInt16 fp2e, fp4e; - uInt32 fp2mH, fp2mL, fp4mH, fp4mL; - struct fp2struct8 *fp2; - struct fp4struct8 *fp4, Fp4; - CDFstatus pStatus = CDF_OK; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp4struct8 FP4zeroDouble = { FP4ZEROdouble }; - struct fp4struct8 FP4minDouble = { FP4MINdouble }; - struct fp4struct8 FP4maxDouble = { FP4MAXdouble }; -#endif - for (elemN = 0, - fp2 = (struct fp2struct8 *) buffer, - fp4 = (struct fp4struct8 *) buffer; - elemN < numElems; - elemN++, fp2++, fp4++) { - fp2e = (fp2->e1 << 4) | fp2->e0; - switch (fp2e) { - case 0x0: - fp2mH = (fp2->m6 << 16) | (fp2->m5 << 8) | fp2->m4; - fp2mL = (fp2->m3 << 24) | (fp2->m2 << 16) | (fp2->m1 << 8) | fp2->m0; - if (fp2mH == 0x0 && fp2mL == 0x0) { - Fp4 = FP4zeroDouble; - Fp4.s = fp2->s; - if (Fp4.s == 0x1) pStatus = NEGATIVE_FP_ZERO; - break; - } - if (fp2mH < 0x40000) { - Fp4 = FP4minDouble; - Fp4.s = fp2->s; - break; - } - if (fp2mH < 0x80000) { - Fp4.e1 = 0x0; - Fp4.e0 = 0x1; - fp4mH = ((fp2mH - 0x40000) << 2) | (fp2mL >> 30); - fp4mL = fp2mL << 2; - Fp4.m6 = (Byte1) (fp4mH >> 16); - Fp4.m5 = (Byte1) (fp4mH >> 8); - Fp4.m4 = (Byte1) (fp4mH); - Fp4.m3 = (Byte1) (fp4mL >> 24); - Fp4.m2 = (Byte1) (fp4mL >> 16); - Fp4.m1 = (Byte1) (fp4mL >> 8); - Fp4.m0 = (Byte1) (fp4mL); - Fp4.s = fp2->s; - break; - } - Fp4.e1 = 0x0; - Fp4.e0 = 0x2; - fp4mH = ((fp2mH - 0x80000) << 1) | (fp2mL >> 31); - fp4mL = fp2mL << 1; - Fp4.m6 = (Byte1) (fp4mH >> 16); - Fp4.m5 = (Byte1) (fp4mH >> 8); - Fp4.m4 = (Byte1) (fp4mH); - Fp4.m3 = (Byte1) (fp4mL >> 24); - Fp4.m2 = (Byte1) (fp4mL >> 16); - Fp4.m1 = (Byte1) (fp4mL >> 8); - Fp4.m0 = (Byte1) (fp4mL); - Fp4.s = fp2->s; - break; - case 0x7FE: - case 0x7FF: - Fp4 = FP4maxDouble; - Fp4.s = fp2->s; - break; - default: - fp4e = fp2e + 2; - Fp4.e1 = fp4e >> 4; - Fp4.e0 = fp4e; - Fp4.m6 = fp2->m6; - Fp4.m5 = fp2->m5; - Fp4.m4 = fp2->m4; - Fp4.m3 = fp2->m3; - Fp4.m2 = fp2->m2; - Fp4.m1 = fp2->m1; - Fp4.m0 = fp2->m0; - Fp4.s = fp2->s; - } - *fp4 = Fp4; - } - return pStatus; -} - -/****************************************************************************** -* FP2toFP4doubleNEGtoPOS. -* Floating-point/1 to floating-point/4, double-precision. Convert -0.0 to -* 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP2toFP4doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - CDFstatus status = FP2toFP4double (buffer, numElems); - if (status == NEGATIVE_FP_ZERO) FP4doubleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP3toFP1double. -* Floating-point/3 to floating-point/1, double-precision. -******************************************************************************/ - -STATICforIDL CDFstatus FP3toFP1double (buffer, numElems) -void *buffer; -Int32 numElems; -{ - uInt16 fp3e, fp1e; - struct fp3struct8 *fp3; - struct fp1struct8 *fp1, Fp1; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp1struct8 FP1zeroDouble = { FP1ZEROdouble }; -#endif - for (elemN = 0, - fp3 = (struct fp3struct8 *) buffer, - fp1 = (struct fp1struct8 *) buffer; - elemN < numElems; - elemN++, fp3++, fp1++) { - /************************************************************************* - * Calculate the FP3 exponent. - *************************************************************************/ - fp3e = (fp3->e1 << 1) | fp3->e0; - /************************************************************************* - * If the FP3 exponent is zero (0), the FP3 value is 0.0 regardless of the - * mantissa's value. The FP3 sign bit shouldn't be set either since -0.0 - * is not a valid value on VAXes. But since it might be set (for whatever - * reason), set FP1's sign to that of FP3. - * If the FP3 exponent is not zero (0), the FP1 exponent is just 0x37E more - * than the FP3 exponent and the three (extra) least signification bits of - * the FP3 mantissa are lost (truncated) when the FP3 mantissa is copied to - * the FP1 mantissa. - *************************************************************************/ - if (fp3e == 0x0) { - Fp1 = FP1zeroDouble; - Fp1.s = fp3->s; - } - else { - fp1e = fp3e + 0x37E; - Fp1.e0 = fp1e; - Fp1.e1 = fp1e >> 4; - Fp1.m0 = (fp3->m1 << 5) | (fp3->m0 >> 3); - Fp1.m1 = (fp3->m2 << 5) | (fp3->m1 >> 3); - Fp1.m2 = (fp3->m3 << 5) | (fp3->m2 >> 3); - Fp1.m3 = (fp3->m4 << 5) | (fp3->m3 >> 3); - Fp1.m4 = (fp3->m5 << 5) | (fp3->m4 >> 3); - Fp1.m5 = (fp3->m6 << 5) | (fp3->m5 >> 3); - Fp1.m6 = fp3->m6 >> 3; - Fp1.s = fp3->s; - } - *fp1 = Fp1; - } - return CDF_OK; -} - -/****************************************************************************** -* FP3toFP1doubleNEGtoPOS. -* Floating-point/3 to floating-point/1, double-precision. Convert -0.0 to -* 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP3toFP1doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - FP3toFP1double (buffer, numElems); - FP1doubleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP3toFP2double. -* Floating-point/3 to floating-point/2, double-precision. -* See FP3toFP1double for comments. -******************************************************************************/ - -STATICforIDL CDFstatus FP3toFP2double (buffer, numElems) -void *buffer; -Int32 numElems; -{ - uInt16 fp3e, fp2e; - struct fp3struct8 *fp3; - struct fp2struct8 *fp2, Fp2; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp2struct8 FP2zeroDouble = { FP2ZEROdouble }; -#endif - for (elemN = 0, - fp3 = (struct fp3struct8 *) buffer, - fp2 = (struct fp2struct8 *) buffer; - elemN < numElems; - elemN++, fp3++, fp2++) { - fp3e = (fp3->e1 << 1) | fp3->e0; - if (fp3e == 0x0) { - Fp2 = FP2zeroDouble; - Fp2.s = fp3->s; - } - else { - fp2e = fp3e + 0x37E; - Fp2.e0 = fp2e; - Fp2.e1 = fp2e >> 4; - Fp2.m0 = (fp3->m1 << 5) | (fp3->m0 >> 3); - Fp2.m1 = (fp3->m2 << 5) | (fp3->m1 >> 3); - Fp2.m2 = (fp3->m3 << 5) | (fp3->m2 >> 3); - Fp2.m3 = (fp3->m4 << 5) | (fp3->m3 >> 3); - Fp2.m4 = (fp3->m5 << 5) | (fp3->m4 >> 3); - Fp2.m5 = (fp3->m6 << 5) | (fp3->m5 >> 3); - Fp2.m6 = fp3->m6 >> 3; - Fp2.s = fp3->s; - } - *fp2 = Fp2; - } - return CDF_OK; -} - -/****************************************************************************** -* FP3toFP2doubleNEGtoPOS. -* Floating-point/3 to floating-point/2, double-precision. Convert -0.0 to -* +0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP3toFP2doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - FP3toFP2double (buffer, numElems); - FP2doubleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP3toFP4double. -* Floating-point/3 to floating-point/4, double-precision. -******************************************************************************/ - -STATICforIDL CDFstatus FP3toFP4double (buffer, numElems) -void *buffer; -Int32 numElems; -{ - uInt16 fp3e, fp4e; - struct fp3struct8 *fp3; - struct fp4struct8 *fp4, Fp4; - Int32 elemN; - CDFstatus pStatus = CDF_OK; -#if DYNAMICfpSTRUCTs - struct fp4struct8 FP4zeroDouble = { FP4ZEROdouble }; -#endif - for (elemN = 0, - fp3 = (struct fp3struct8 *) buffer, - fp4 = (struct fp4struct8 *) buffer; - elemN < numElems; - elemN++, fp3++, fp4++) { - /************************************************************************* - * Calculate the FP3 exponent. - *************************************************************************/ - fp3e = (fp3->e1 << 1) | fp3->e0; - /************************************************************************* - * If the FP3 exponent is zero (0), the FP3 value is 0.0 regardless of the - * mantissa's value. The FP3 sign bit shouldn't be set either since -0.0 - * is not a valid value on VAXes or DEC Alphas. But since it might be set - * (for whatever reason), set FP4's sign to that of FP3 [and check for - * -0.0]. - * If the FP3 exponent is not zero (0), the FP4 exponent is just 0x380 more - * than the FP3 exponent and the three (extra) least signification bits of - * the FP3 mantissa are lost (truncated) when the FP3 mantissa is copied to - * the FP4 mantissa. - *************************************************************************/ - if (fp3e == 0x0) { - Fp4 = FP4zeroDouble; - Fp4.s = fp3->s; - if (Fp4.s == 0x1) pStatus = NEGATIVE_FP_ZERO; - } - else { - fp4e = fp3e + 0x380; - Fp4.e0 = fp4e; - Fp4.e1 = fp4e >> 4; - Fp4.m0 = (fp3->m1 << 5) | (fp3->m0 >> 3); - Fp4.m1 = (fp3->m2 << 5) | (fp3->m1 >> 3); - Fp4.m2 = (fp3->m3 << 5) | (fp3->m2 >> 3); - Fp4.m3 = (fp3->m4 << 5) | (fp3->m3 >> 3); - Fp4.m4 = (fp3->m5 << 5) | (fp3->m4 >> 3); - Fp4.m5 = (fp3->m6 << 5) | (fp3->m5 >> 3); - Fp4.m6 = fp3->m6 >> 3; - Fp4.s = fp3->s; - } - *fp4 = Fp4; - } - return pStatus; -} - -/****************************************************************************** -* FP3toFP4doubleNEGtoPOS. -* Floating-point/3 to floating-point/4, double-precision. Convert -0.0 to -* 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP3toFP4doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - CDFstatus status = FP3toFP4double (buffer, numElems); - if (status == NEGATIVE_FP_ZERO) FP4doubleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP4toFP1double. -* Floating-point/4 to floating-point/1, double-precision. -******************************************************************************/ - -STATICforIDL CDFstatus FP4toFP1double (buffer, numElems) -void *buffer; -Int32 numElems; -{ - uInt16 fp4e, fp1e; - uInt32 fp4mH, fp4mL, fp1mH, fp1mL; - struct fp4struct8 *fp4; - struct fp1struct8 *fp1, Fp1; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp1struct8 FP1zeroDouble = { FP1ZEROdouble }; -#endif - for (elemN = 0, - fp4 = (struct fp4struct8 *) buffer, - fp1 = (struct fp1struct8 *) buffer; - elemN < numElems; - elemN++, fp4++, fp1++) { - /************************************************************************* - * Calculate the FP4 exponent. - *************************************************************************/ - fp4e = (fp4->e1 << 4) | fp4->e0; - switch (fp4e) { - /*********************************************************************** - * If the FP4 exponent is zero (0), the value is assumed to be 0.0 - * regardless of the FP4 mantissa (non-zero mantissas are illegal on - * DEC Alphas). The FP4 sign shouldn't be set either since -0.0 isn't - * valid value on DEC Alphas. But since it might be set (for whatever - * reason), set FP1's sign to that of FP4. - ***********************************************************************/ - case 0x0: - Fp1 = FP1zeroDouble; - Fp1.s = fp4->s; - break; - /*********************************************************************** - * FP4 exponents of one (1) or two (2) indicate values whose mantissas - * are not the same between FP4 and FP1. For an FP4 exponent of one - * (1), the FP1 exponent is zero (0) and the full range of FP4 - * mantissas (0x0 through 0xFFFFFFFFFFFFF) maps into the smaller range - * of FP1 mantissas from 0x4000000000000 to 0x7FFFFFFFFFFFF (a 4-to-1 - * mapping which means that only one out of four FP4 values in this - * range maps perfectly to FP1). For an FP4 exponent of two (2), the - * FP1 exponent is zero (0) and the full range of FP4 mantissas (0x0 - * through 0xFFFFFFFFFFFFF) maps into the smaller range of FP1 mantissas - * from 0x8000000000000 to 0xFFFFFFFFFFFFF (a 2-to-1 mapping which means - * that only one out of two FP4 values in this range maps perfectly to - * FP1). - ***********************************************************************/ - case 0x1: - case 0x2: - fp4mH = (fp4->m6 << 16) | (fp4->m5 << 8) | fp4->m4; - fp4mL = (fp4->m3 << 24) | (fp4->m2 << 16) | (fp4->m1 << 8) | fp4->m0; - if (fp4e == 0x1) { - fp1mH = 0x40000 + (fp4mH >> 2); - fp1mL = (fp4mH << 30) | (fp4mL >> 2); - } - else { - fp1mH = 0x80000 + (fp4mH >> 1); - fp1mL = (fp4mH << 31) | (fp4mL >> 1); - } - Fp1.m6 = (Byte1) (fp1mH >> 16); - Fp1.m5 = (Byte1) (fp1mH >> 8); - Fp1.m4 = (Byte1) (fp1mH); - Fp1.m3 = (Byte1) (fp1mL >> 24); - Fp1.m2 = (Byte1) (fp1mL >> 16); - Fp1.m1 = (Byte1) (fp1mL >> 8); - Fp1.m0 = (Byte1) (fp1mL); - Fp1.e1 = 0x0; - Fp1.e0 = 0x0; - Fp1.s = fp4->s; - break; - /*********************************************************************** - * All other FP4 exponents are for FP4 values that map perfectly to FP1 - * (the FP1 exponent is just two less than the FP4 exponent). - ***********************************************************************/ - default: - Fp1.m6 = fp4->m6; - Fp1.m5 = fp4->m5; - Fp1.m4 = fp4->m4; - Fp1.m3 = fp4->m3; - Fp1.m2 = fp4->m2; - Fp1.m1 = fp4->m1; - Fp1.m0 = fp4->m0; - fp1e = fp4e - 2; - Fp1.e1 = fp1e >> 4; - Fp1.e0 = fp1e; - Fp1.s = fp4->s; - } - *fp1 = Fp1; - } - return CDF_OK; -} - -/****************************************************************************** -* FP4toFP1doubleNEGtoPOS. -* Floating-point/4 to floating-point/1, double-precision. Convert -0.0 to -* 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP4toFP1doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - FP4toFP1double (buffer, numElems); - FP1doubleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP4toFP2double. -* Floating-point/4 to floating-point/1, double-precision. -* See FP4toFP1double for comments. -******************************************************************************/ - -STATICforIDL CDFstatus FP4toFP2double (buffer, numElems) -void *buffer; -Int32 numElems; -{ - uInt16 fp4e, fp2e; - uInt32 fp4mH, fp4mL, fp2mH, fp2mL; - struct fp4struct8 *fp4; - struct fp2struct8 *fp2, Fp2; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp2struct8 FP2zeroDouble = { FP2ZEROdouble }; -#endif - for (elemN = 0, - fp4 = (struct fp4struct8 *) buffer, - fp2 = (struct fp2struct8 *) buffer; - elemN < numElems; - elemN++, fp4++, fp2++) { - fp4e = (fp4->e1 << 4) | fp4->e0; - switch (fp4e) { - case 0x0: - Fp2 = FP2zeroDouble; - Fp2.s = fp4->s; - break; - case 0x1: - case 0x2: - fp4mH = (fp4->m6 << 16) | (fp4->m5 << 8) | fp4->m4; - fp4mL = (fp4->m3 << 24) | (fp4->m2 << 16) | (fp4->m1 << 8) | fp4->m0; - if (fp4e == 0x1) { - fp2mH = 0x40000 + (fp4mH >> 2); - fp2mL = (fp4mH << 30) | (fp4mL >> 2); - } - else { - fp2mH = 0x80000 + (fp4mH >> 1); - fp2mL = (fp4mH << 31) | (fp4mL >> 1); - } - Fp2.m6 = (Byte1) (fp2mH >> 16); - Fp2.m5 = (Byte1) (fp2mH >> 8); - Fp2.m4 = (Byte1) (fp2mH); - Fp2.m3 = (Byte1) (fp2mL >> 24); - Fp2.m2 = (Byte1) (fp2mL >> 16); - Fp2.m1 = (Byte1) (fp2mL >> 8); - Fp2.m0 = (Byte1) (fp2mL); - Fp2.e1 = 0x0; - Fp2.e0 = 0x0; - Fp2.s = fp4->s; - break; - default: - Fp2.m6 = fp4->m6; - Fp2.m5 = fp4->m5; - Fp2.m4 = fp4->m4; - Fp2.m3 = fp4->m3; - Fp2.m2 = fp4->m2; - Fp2.m1 = fp4->m1; - Fp2.m0 = fp4->m0; - fp2e = fp4e - 2; - Fp2.e1 = fp2e >> 4; - Fp2.e0 = fp2e; - Fp2.s = fp4->s; - } - *fp2 = Fp2; - } - return CDF_OK; -} - -/****************************************************************************** -* FP4toFP2doubleNEGtoPOS. -* Floating-point/4 to floating-point/2, double-precision. Convert -0.0 to -* 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP4toFP2doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - FP4toFP2double (buffer, numElems); - FP2doubleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP4toFP3double. -* Floating-point/4 to floating-point/3, double-precision. -******************************************************************************/ - -STATICforIDL CDFstatus FP4toFP3double (buffer, numElems) -void *buffer; -Int32 numElems; -{ - uInt16 fp4e, fp3e; - struct fp4struct8 *fp4; - struct fp3struct8 *fp3, Fp3; - Int32 elemN; - CDFstatus pStatus = CDF_OK; -#if DYNAMICfpSTRUCTs - struct fp3struct8 FP3zeroDouble = { FP3ZEROdouble }; - struct fp3struct8 FP3minDouble = { FP3MINdouble }; - struct fp3struct8 FP3maxDouble = { FP3MAXdouble }; -#endif - for (elemN = 0, - fp4 = (struct fp4struct8 *) buffer, - fp3 = (struct fp3struct8 *) buffer; - elemN < numElems; - elemN++, fp4++, fp3++) { - /************************************************************************* - * Calculate the FP4 exponent. - *************************************************************************/ - fp4e = (fp4->e1 << 4) | fp4->e0; - /************************************************************************* - * Check if the FP4 exponent is too small for FP3 (but not 0.0). If so, - * set the FP3 value to its smallest possible magnitude (but use FP4's - * sign). Also check for -0.0. - *************************************************************************/ - if (fp4e < 0x381) { - if (fp4e == 0x0) { - Fp3 = FP3zeroDouble; - Fp3.s = fp4->s; - if (Fp3.s == 0x1) pStatus = NEGATIVE_FP_ZERO; - } - else { - Fp3 = FP3minDouble; - Fp3.s = fp4->s; - } - *fp3 = Fp3; - continue; - } - /************************************************************************* - * Check if the FP4 exponent is too large for FP3. If so, set the FP3 - * value to its largest possible magnitude (but use FP4's sign). - *************************************************************************/ - if (fp4e > 0x47F) { - Fp3 = FP3maxDouble; - Fp3.s = fp4->s; - *fp3 = Fp3; - continue; - } - /************************************************************************* - * The FP4 value will `fit' but the three (extra) least significant bits - * of the FP3 mantissa are set to zero when the FP4 mantissa is copied to - * the FP3 mantissa. - *************************************************************************/ - fp3e = fp4e - 0x380; - Fp3.e0 = fp3e; - Fp3.e1 = fp3e >> 1; - Fp3.m0 = fp4->m0 << 3; - Fp3.m1 = (fp4->m1 << 3) | (fp4->m0 >> 5); - Fp3.m2 = (fp4->m2 << 3) | (fp4->m1 >> 5); - Fp3.m3 = (fp4->m3 << 3) | (fp4->m2 >> 5); - Fp3.m4 = (fp4->m4 << 3) | (fp4->m3 >> 5); - Fp3.m5 = (fp4->m5 << 3) | (fp4->m4 >> 5); - Fp3.m6 = (fp4->m6 << 3) | (fp4->m5 >> 5); - Fp3.s = fp4->s; - *fp3 = Fp3; - } -#if LIMITfp3DOUBLEs - /**************************************************************************** - * If this is a DEC Alpha (OpenVMS or POSIX Shell) built for a default of - * D_FLOAT, check that the values do not exceed the maximum. - ****************************************************************************/ - FP3doubleLIMIT (buffer, numElems); -#endif - return pStatus; -} - -/****************************************************************************** -* FP4toFP3doubleNEGtoPOS. -* Floating-point/4 to floating-point/3, double-precision. Convert -0.0 to -* 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP4toFP3doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - CDFstatus status = FP4toFP3double (buffer, numElems); - if (status == NEGATIVE_FP_ZERO) FP3doubleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP1toFP2singleNEGtoPOS. -* Floating-point/1 to floating-point/2, single-precision. Convert -0.0 to -* 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP1toFP2singleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - Byte1 *ptr; Int32 elemN; - for (elemN = 0, ptr = (Byte1 *) buffer; - elemN < numElems; elemN++, ptr += 4) { - REVERSE4b (ptr) - } - FP2singleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP2toFP1singleNEGtoPOS. -* Floating-point/2 to floating-point/1, single-precision. Convert -0.0 to -* 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP2toFP1singleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - Byte1 *ptr; Int32 elemN; - for (elemN = 0, ptr = (Byte1 *) buffer; - elemN < numElems; elemN++, ptr += 4) { - REVERSE4b (ptr) - } - FP1singleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP1toFP2doubleNEGtoPOS. -* Floating-point/1 to floating-point/2, single-precision. Convert -0.0 to -* 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP1toFP2doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - Byte1 *ptr; Int32 elemN; - for (elemN = 0, ptr = (Byte1 *) buffer; - elemN < numElems; elemN++, ptr += 8) { - REVERSE8b (ptr) - } - FP2doubleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP2toFP1doubleNEGtoPOS. -* Floating-point/2 to floating-point/1, single-precision. Convert -0.0 to -* 0.0. -******************************************************************************/ - -STATICforIDL CDFstatus FP2toFP1doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - Byte1 *ptr; Int32 elemN; - for (elemN = 0, ptr = (Byte1 *) buffer; - elemN < numElems; elemN++, ptr += 8) { - REVERSE8b (ptr) - } - FP1doubleNEGtoPOS (buffer, numElems); - return CDF_OK; -} - -/****************************************************************************** -* FP1singleNEGtoPOS. -* Convert -0.0 to 0.0 for floating-point/1 single-precision. -******************************************************************************/ - -STATICforIDL CDFstatus FP1singleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - Byte1 *ptr; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp1struct4 FP1zeroSingle = { FP1ZEROsingle }; - struct fp1struct4 FP1zeroSingleNeg = { FP1ZEROsingleNEG }; -#endif - for (elemN = 0, ptr = (Byte1 *) buffer; elemN < numElems; elemN++, ptr += 4) { - if (*((uInt32 *) ptr) == *((uInt32 *) &FP1zeroSingleNeg)) { - *((struct fp1struct4 *) ptr) = FP1zeroSingle; - } - } - return CDF_OK; -} - -/****************************************************************************** -* FP2singleNEGtoPOS. -* Convert -0.0 to 0.0 for floating-point/2 single-precision. -******************************************************************************/ - -STATICforIDL CDFstatus FP2singleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - Byte1 *ptr; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp2struct4 FP2zeroSingle = { FP2ZEROsingle }; - struct fp2struct4 FP2zeroSingleNeg = { FP2ZEROsingleNEG }; -#endif - for (elemN = 0, ptr = (Byte1 *) buffer; elemN < numElems; elemN++, ptr += 4) { - if (*((uInt32 *) ptr) == *((uInt32 *) &FP2zeroSingleNeg)) { - *((struct fp2struct4 *) ptr) = FP2zeroSingle; - } - } - return CDF_OK; -} - -/****************************************************************************** -* FP34singleNEGtoPOS. -* Convert -0.0 to 0.0 for floating-point/34 single-precision. -******************************************************************************/ - -STATICforIDL CDFstatus FP34singleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - struct fp34struct4 *fp34; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp34struct4 FP34zeroSingle = { FP34ZEROsingle }; -#endif - for (elemN = 0, fp34 = (struct fp34struct4 *) buffer; - elemN < numElems; elemN++, fp34++) { - if (fp34->e1 == 0x0 && fp34->e0 == 0x0 && fp34->s == 0x1) { - *fp34 = FP34zeroSingle; - } - } - return CDF_OK; -} - -/****************************************************************************** -* FP1doubleNEGtoPOS. -* Convert -0.0 to 0.0 for floating-point/1 double-precision. -******************************************************************************/ - -STATICforIDL CDFstatus FP1doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - Byte1 *ptr; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp1struct8 FP1zeroDouble = { FP1ZEROdouble }; - struct fp1struct8 FP1zeroDoubleNeg = { FP1ZEROdoubleNEG }; -#endif - for (elemN = 0, ptr = (Byte1 *) buffer; elemN < numElems; elemN++, ptr += 8) { - if (*((uInt32 *) ptr) == *((uInt32 *) &FP1zeroDoubleNeg) && - *((uInt32 *) ptr + 1) == *((uInt32 *) &FP1zeroDoubleNeg + 1)) { - *((struct fp1struct8 *) ptr) = FP1zeroDouble; - } - } - return CDF_OK; -} - -/****************************************************************************** -* FP2doubleNEGtoPOS. -* Convert -0.0 to 0.0 for floating-point/2 double-precision. -******************************************************************************/ - -STATICforIDL CDFstatus FP2doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - Byte1 *ptr; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp2struct8 FP2zeroDouble = { FP2ZEROdouble }; - struct fp2struct8 FP2zeroDoubleNeg = { FP2ZEROdoubleNEG }; -#endif - for (elemN = 0, ptr = (Byte1 *) buffer; elemN < numElems; elemN++, ptr += 8) { - if (*((uInt32 *) ptr) == *((uInt32 *) &FP2zeroDoubleNeg) && - *((uInt32 *) ptr + 1) == *((uInt32 *) &FP2zeroDoubleNeg + 1)) { - *((struct fp2struct8 *) ptr) = FP2zeroDouble; - } - } - return CDF_OK; -} - -/****************************************************************************** -* FP3doubleNEGtoPOS. -* Convert -0.0 to 0.0 for floating-point/3 double-precision. -******************************************************************************/ - -STATICforIDL CDFstatus FP3doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - struct fp3struct8 *fp3; - Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp3struct8 FP3zeroDouble = { FP3ZEROdouble }; -#endif - for (elemN = 0, fp3 = (struct fp3struct8 *) buffer; - elemN < numElems; elemN++, fp3++) { - if (fp3->e1 == 0x0 && fp3->e0 == 0x0 && fp3->s == 0x1) { - *fp3 = FP3zeroDouble; - } - } -#if LIMITfp3DOUBLEs - /**************************************************************************** - * If this is a DEC Alpha (OpenVMS or POSIX Shell) built for a default of - * D_FLOAT, check that the values do not exceed the maximum. - ****************************************************************************/ - FP3doubleLIMIT (buffer, numElems); -#endif - return CDF_OK; -} - -/****************************************************************************** -* FP4doubleNEGtoPOS. -* Convert -0.0 to 0.0 for floating-point/4 double-precision. -******************************************************************************/ - -STATICforIDL CDFstatus FP4doubleNEGtoPOS (buffer, numElems) -void *buffer; -Int32 numElems; -{ - struct fp4struct8 *fp4; Int32 elemN; -#if DYNAMICfpSTRUCTs - struct fp4struct8 FP4zeroDouble = { FP4ZEROdouble }; -#endif - for (elemN = 0, fp4 = (struct fp4struct8 *) buffer; - elemN < numElems; elemN++, fp4++) { - if (fp4->e1 == 0x0 && fp4->e0 == 0x0 && fp4->s == 0x1) { - *fp4 = FP4zeroDouble; - } - } - return CDF_OK; -} - -/****************************************************************************** -* FP3doubleLIMIT. -* Check that the maximum double-precision, floating-point/3 value on a -* DEC Alpha (built for D_FLOAT) is not exceeded. The maximum allowed value -* has an exponent of 0xFF and a mantissa of 0x7FFFFFFFFFFFFB. -******************************************************************************/ - -STATICforIDL CDFstatus FP3doubleLIMIT (buffer, numElems) -void *buffer; -Int32 numElems; -{ - struct fp3struct8 *fp3; Int32 elemN; - for (elemN = 0, fp3 = (struct fp3struct8 *) buffer; - elemN < numElems; elemN++, fp3++) { - if (fp3->e1 == 0x7F && fp3->e0 == 0x1 && fp3->m6 == 0x7F && - fp3->m5 == 0xFF && fp3->m4 == 0xFF && fp3->m3 == 0xFF && - fp3->m2 == 0xFF && fp3->m1 == 0xFF && fp3->m0 > 0xFB) { - fp3->m0 = 0xFB; - } - } - return CDF_OK; -} - -/****************************************************************************** -* Reverse2. -******************************************************************************/ - -STATICforIDL CDFstatus Reverse2 (buffer, numElems) -void *buffer; -Int32 numElems; -{ - Byte1 *ptr; Int32 elemN; - for (elemN = 0, ptr = (Byte1 *) buffer; elemN < numElems; elemN++, ptr += 2) { - REVERSE2b (ptr) - } - return CDF_OK; -} - -/****************************************************************************** -* Reverse4. -******************************************************************************/ - -STATICforIDL CDFstatus Reverse4 (buffer, numElems) -void *buffer; -Int32 numElems; -{ - Byte1 *ptr; Int32 elemN; - for (elemN = 0, ptr = (Byte1 *) buffer; elemN < numElems; elemN++, ptr += 4) { - REVERSE4b (ptr) - } - return CDF_OK; -} - -/****************************************************************************** -* Reverse8. -******************************************************************************/ - -STATICforIDL CDFstatus Reverse8 (buffer, numElems) -void *buffer; -Int32 numElems; -{ - Byte1 *ptr; Int32 elemN; - for (elemN = 0, ptr = (Byte1 *) buffer; elemN < numElems; elemN++, ptr += 8) { - REVERSE8b (ptr) - } - return CDF_OK; -} - -/****************************************************************************** -* Reverse16. -******************************************************************************/ - -STATICforIDL CDFstatus Reverse16 (buffer, numElems) -void *buffer; -Int32 numElems; -{ - Byte1 *ptr; Int32 elemN; - for (elemN = 0, ptr = (Byte1 *) buffer; elemN < numElems; elemN++, ptr += 16) { - REVERSE8b (ptr) - REVERSE8b (ptr+8) - } - return CDF_OK; -} - - diff --git a/cdf36_3-dist/src/lib/cdffii.c b/cdf36_3-dist/src/lib/cdffii.c deleted file mode 100644 index b101bd4..0000000 --- a/cdf36_3-dist/src/lib/cdffii.c +++ /dev/null @@ -1,3780 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF Internal Interface/FORTRAN. -* -* Version 1.8b, 21-Feb-97, Hughes STX. -* -* Modification history: -* -* V1.0 30-Jan-91, J Love Original version (for CDF V2.1). -* V1.1 6-Aug-91, J Love Use 'CDFlib'. If variable is a character data -* type, check for %DESCR (if VMS). -* V1.2 24-Oct-91, J Love Modified for IBM-PC and IBM-RS6000 ports. -* V1.3 20-May-92, J Love CDF V2.2. -* V1.4 16-Sep-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.5 19-Jan-94, J Love CDF V2.4. -* V1.5a 4-Feb-94, J Love DEC Alpha/OpenVMS port. -* V1.5b 22-Feb-94, J Love Spelling lesson. -* V1.5c 29-Mar-94, J Love Solaris using GNU C compiler. -* V1.6 21-Dec-94, J Love CDF V2.5. -* V1.7 19-Jan-95, J Love IRIX 6.0 (64-bit). -* V1.7a 30-Jan-95, J Love `int sC' -> `Int32 sC'. -* V1.7b 13-Jun-95, J Love Linux. -* V1.8 5-Aug-96, J Love CDF V2.6 (renamed - previously `cdf_i_if.c'). -* V1.8a 2-Dec-96, J Love Fixed declaration of `i' (now `int'). -* V1.8b 21-Feb-97, J Love Removed RICE. -* -******************************************************************************/ - -/****************************************************************************** -* -* Notes: -* -* For the FORTRAN interfaces everything is indexed from one (1) while for -* the C interfaces everything is indexed from zero (0) [eg. variable and -* attribute numbers, record numbers, indices, entry numbers]. For this -* reason one (1) is subtracted from arguments passed in while one (1) is -* added to arguments passed out (where appropriate). -* -* The FORTRAN interfaces use INTEGER*4 as the data type for all numerical -* values passed in/out while the C interfaces use `long'. These are the same -* on all supported platforms except the DEC Alpha (where `long' is 8 bytes). -* For this reason temporary variables/arrays of size `long' are used in the -* calls to the CDF library (the direct C interface). This causes a small -* performance loss on the other platforms mainly when reading/writing single -* values repeatly (but then the hyper reads/writes should have been used -* instead). -* -******************************************************************************/ - -/****************************************************************************** -* -* Notes for VMS: -* -* To make the user's life a little easier, all names and attribute -* values (for attributes of data types CDF_CHAR and CDF_UCHAR) may be passed -* in and out by either reference or descriptor. The default passing mode -* for an embedded character string (e.g., CALL subr (..., 'string', ...)) or -* a CHARACTER variable symbol (e.g., CALL subr (..., ATTR_NAME, ...) where -* ATTR_NAME is defined as CHARACTER*8) is by descriptor when passing from -* FORTRAN to C in VMS. -* -* An embedded character string could be enclosed in %REF() to force -* passing by reference since the FORTRAN compiler puts a NUL character at -* the end of these strings as expected by the CDF V2.0 library (written in -* C). Enclosing a CHARACTER variable symbol in %REF() will result in -* an error, however, because a NUL character is not placed at the ends of -* these type strings by the FORTRAN compiler. The user would have to -* supply the terminating NUL. By letting the passing mode default to by- -* descriptor, this interface will supply the terminating NUL. -* -* The main difference here from CDF Version 1 is that the %REF() is -* not needed when passing out names and attribute values. Also, %REF() -* is not necessary when passing the value of a variable that is a character -* data type. -* -******************************************************************************/ - -/****************************************************************************** -* -* Notes for UNIX: -* -* All passing between FORTRAN and C on UNIX systems is done by reference. -* When character strings are passed between FORTRAN and C, extra arguments -* are added to the argument list containing the lengths of those character -* strings (EXCEPT on NeXT machines - FORTRAN applications must NUL-terminate -* passed character strings). -* -* Entry points have been made lowercase because the FORTRAN compiler -* converts all uppercase characters to lowercase in entry points. This way -* the linker will find everything. Unix FORTRAN compilers and linkers also -* seem to like trailing '_'s (except on the IBM-RS6000/AIX, HP9000/HP-UX, -* and NeXT/Mach). -* -******************************************************************************/ - -/****************************************************************************** -* -* Notes for Macintosh (MPW C/Fortran): -* -* In order to get the Internal Interface to work with MPW Fortran a separate -* entry point has been created for each possible number of arguments. They -* are called CDF_lib_1, CDF_lib_2,... CDF_lib_n. This is because MPW Fortran -* will not allow varying numbers of arguments to the same subroutine/function. -* An application must use CDF_lib_x when there are `x' arguments in the call. -* -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* Local function prototypes. -******************************************************************************/ - -static size_t PickMaxLen PROTOARGs((long requiredArgument, ...)); - -VISIBLE_PREFIX -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib__,cdf_lib_,cdf_lib,CDF_LIB) -VARPROTOARGs((Int32 *requiredFnc, ...)); - -#define CDF_LIBx Fif_ENTRYPOINT(cdf_lib__,cdf_lib_,cdf_lib,CDF_LIB) -static CDFid currentCDFid = NULL; -/****************************************************************************** -* CDF_lib. Note that CDFstatus is returned both as an argument (the last -* argument) and as the value of the function. -******************************************************************************/ - -VISIBLE_PREFIX -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib__,cdf_lib_,cdf_lib,CDF_LIB) -#if defined(STDARG) -(Int32 *requiredFnc, ...) -#else -(va_alist) -va_dcl -#endif -{ -CDFstatus pStatus = CDF_OK; /* Pending status. */ -CDFstatus tStatus; /* Temporary status. */ -Int32 *status; /* Address of `status' variable. */ -struct VAstruct Va; -struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - -#if !defined(STDARG) -Int32 *fncP; /* Pointer to required function. */ -#endif - -#if defined(Fif_GHOSTLEN) -int i; -Int32 sC = 0; /* String count. Number of (possible) strings - passed in. */ -Int32 *sCp; /* Pointer to string count. */ -Int32 *sLs; /* Lengths of (possible) character strings passed - in - some arguments may or may not be character - strings (eg. variable/entry data). */ -#endif - -#if defined(Fif_GHOSTLEN) -/****************************************************************************** -* Scan argument list counting number of (possible) strings passed in. -******************************************************************************/ - -#if defined(STDARG) -va_start (Va.ap, requiredFnc); -if (*requiredFnc == 0) { - sCp = requiredFnc; - Va.fnc = (long) *(va_arg (Va.ap, Int32 *)); -} -else { - sCp = &sC; - Va.fnc = (long) *requiredFnc; -} -#else -VA_START (Va.ap); -fncP = va_arg (Va.ap, Int32 *); -if (*fncP == 0) { - sCp = fncP; - Va.fnc = (long) *(va_arg (Va.ap, Int32 *)); -} -else { - sCp = &sC; - Va.fnc = (long) *fncP; -} -#endif - -while (Va.fnc != NULL_) { - switch (Va.fnc) { - /************************************************************************** - * CREATE_, - **************************************************************************/ - case CREATE_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * CREATE_,CDF_ - *******************************************************************/ - case CDF_: { - (void) va_arg (Va.ap, void *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (*sCp)++; - break; - } - /******************************************************************* - * CREATE_,rVAR_ - *******************************************************************/ - case rVAR_: { - (void) va_arg (Va.ap, void *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (*sCp)++; - break; - } - /******************************************************************* - * CREATE_,zVAR_ - *******************************************************************/ - case zVAR_: { - (void) va_arg (Va.ap, void *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (*sCp)++; - break; - } - /******************************************************************* - * CREATE_,ATTR_ - *******************************************************************/ - case ATTR_: { - (void) va_arg (Va.ap, void *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (*sCp)++; - break; - } - /******************************************************************* - * Unknown - hopefully the next operation. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - /************************************************************************** - * OPEN_, - **************************************************************************/ - case OPEN_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * OPEN_,CDF_ - *******************************************************************/ - case CDF_: { - (void) va_arg (Va.ap, void *); - (void) va_arg (Va.ap, Int32 *); - (*sCp)++; - break; - } - /******************************************************************* - * Unknown - hopefully the next operation. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - /************************************************************************** - * DELETE_, - **************************************************************************/ - case DELETE_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * DELETE_, - *******************************************************************/ - case CDF_: - case zVAR_: - case rVAR_: - case ATTR_: - case gENTRY_: - case zENTRY_: - case rENTRY_: - break; - /******************************************************************* - * DELETE_,r|zVAR_RECORDS_ - *******************************************************************/ - case rVAR_RECORDS_: - case zVAR_RECORDS_: { - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - break; - } - /******************************************************************* - * Unknown - hopefully the next operation. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - /************************************************************************** - * CLOSE_, - **************************************************************************/ - case CLOSE_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * CLOSE_,CDF_ - *******************************************************************/ - case CDF_: { - break; - } - /******************************************************************* - * CLOSE_,r/zVAR_ - *******************************************************************/ - case rVAR_: - case zVAR_: { - break; - } - /******************************************************************* - * Unknown - hopefully the next operation. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - /************************************************************************** - * SELECT_, - **************************************************************************/ - case SELECT_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * SELECT_, - *******************************************************************/ - case CDF_: - case CDF_STATUS_: - case CDF_READONLY_MODE_: - case CDF_zMODE_: - case CDF_NEGtoPOSfp0_MODE_: - case CDF_DECODING_: - case CDF_CACHESIZE_: - case STAGE_CACHESIZE_: - case COMPRESS_CACHESIZE_: - case rVARs_CACHESIZE_: - case zVARs_CACHESIZE_: - case rVAR_CACHESIZE_: - case zVAR_CACHESIZE_: - case rVAR_: - case zVAR_: - case rVARs_RECNUMBER_: - case zVARs_RECNUMBER_: - case zVAR_RECNUMBER_: - case rVARs_RECCOUNT_: - case zVAR_RECCOUNT_: - case rVARs_RECINTERVAL_: - case zVAR_RECINTERVAL_: - case rVARs_DIMINDICES_: - case zVAR_DIMINDICES_: - case rVARs_DIMCOUNTS_: - case zVAR_DIMCOUNTS_: - case rVARs_DIMINTERVALS_: - case zVAR_DIMINTERVALS_: - case rVAR_RESERVEPERCENT_: - case zVAR_RESERVEPERCENT_: - case ATTR_: - case gENTRY_: - case rENTRY_: - case zENTRY_: { - (void) va_arg (Va.ap, Int32 *); - break; - } - /******************************************************************* - * SELECT_, - *******************************************************************/ - case rVAR_SEQPOS_: - case zVAR_SEQPOS_: { - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - break; - } - /******************************************************************* - * SELECT_, - *******************************************************************/ - case CDF_SCRATCHDIR_: - case rVAR_NAME_: - case zVAR_NAME_: - case ATTR_NAME_: - case rENTRY_NAME_: - case zENTRY_NAME_: { - (void) va_arg (Va.ap, void *); - (*sCp)++; - break; - } - /******************************************************************* - * Unknown item - hopefully the next operation. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - /************************************************************************** - * CONFIRM_, - **************************************************************************/ - case CONFIRM_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * CONFIRM_, - *******************************************************************/ - case CURgENTRY_EXISTENCE_: - case CURrENTRY_EXISTENCE_: - case CURzENTRY_EXISTENCE_: - case CDF_CHECKSUM_: - break; - /******************************************************************* - * CONFIRM_, - *******************************************************************/ - case CDF_READONLY_MODE_: - case CDF_zMODE_: - case CDF_NEGtoPOSfp0_MODE_: - case CDF_DECODING_: - case CDF_CACHESIZE_: - case STAGE_CACHESIZE_: - case COMPRESS_CACHESIZE_: - case rVAR_CACHESIZE_: - case zVAR_CACHESIZE_: - case rVAR_: - case zVAR_: - case rVARs_RECNUMBER_: - case zVAR_RECNUMBER_: - case rVARs_RECCOUNT_: - case zVAR_RECCOUNT_: - case rVARs_RECINTERVAL_: - case zVAR_RECINTERVAL_: - case rVARs_DIMINDICES_: - case zVAR_DIMINDICES_: - case rVARs_DIMCOUNTS_: - case zVAR_DIMCOUNTS_: - case rVARs_DIMINTERVALS_: - case zVAR_DIMINTERVALS_: - case rVAR_RESERVEPERCENT_: - case zVAR_RESERVEPERCENT_: - case ATTR_: - case gENTRY_: - case rENTRY_: - case zENTRY_: - case gENTRY_EXISTENCE_: - case rENTRY_EXISTENCE_: - case zENTRY_EXISTENCE_: { - (void) va_arg (Va.ap, Int32 *); - break; - } - /******************************************************************* - * CONFIRM_, - *******************************************************************/ - case rVAR_SEQPOS_: - case zVAR_SEQPOS_: { - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - break; - } - /******************************************************************* - * CONFIRM_, - *******************************************************************/ - case CDF_NAME_: - case rVAR_EXISTENCE_: - case zVAR_EXISTENCE_: - case ATTR_EXISTENCE_: { - (void) va_arg (Va.ap, void *); - (*sCp)++; - break; - } - /******************************************************************* - * Unknown - hopefully the next operation. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - /************************************************************************** - * GET_, - **************************************************************************/ - case GET_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * GET_, - *******************************************************************/ - case rVARs_NUMDIMS_: - case zVAR_NUMDIMS_: - case rVARs_DIMSIZES_: - case zVAR_DIMSIZES_: - case CDF_ENCODING_: - case CDF_MAJORITY_: - case CDF_FORMAT_: - case CDF_LEAPSECONDLASTUPDATED_: - case CDF_NUMrVARS_: - case CDF_NUMzVARS_: - case CDF_NUMATTRS_: - case CDF_NUMgATTRS_: - case CDF_NUMvATTRS_: - case rVARs_MAXREC_: - case zVARs_MAXREC_: - case CDF_VERSION_: - case CDF_RELEASE_: - case CDF_INCREMENT_: - case LIB_VERSION_: - case LIB_RELEASE_: - case LIB_INCREMENT_: - case rVAR_DATATYPE_: - case zVAR_DATATYPE_: - case rVAR_NUMELEMS_: - case zVAR_NUMELEMS_: - case rVAR_RECVARY_: - case zVAR_RECVARY_: - case rVAR_DIMVARYS_: - case zVAR_DIMVARYS_: - case rVAR_MAXREC_: - case zVAR_MAXREC_: - case rVAR_MAXallocREC_: - case zVAR_MAXallocREC_: - case rVAR_NUMRECS_: - case zVAR_NUMRECS_: - case rVAR_NUMallocRECS_: - case zVAR_NUMallocRECS_: - case rVAR_BLOCKINGFACTOR_: - case zVAR_BLOCKINGFACTOR_: - case rVAR_nINDEXRECORDS_: - case zVAR_nINDEXRECORDS_: - case rVAR_nINDEXENTRIES_: - case zVAR_nINDEXENTRIES_: - case rVAR_nINDEXLEVELS_: - case zVAR_nINDEXLEVELS_: - case rVAR_SPARSERECORDS_: - case zVAR_SPARSERECORDS_: - case ATTR_SCOPE_: - case ATTR_MAXgENTRY_: - case ATTR_MAXrENTRY_: - case ATTR_MAXzENTRY_: - case ATTR_NUMgENTRIES_: - case ATTR_NUMrENTRIES_: - case ATTR_NUMzENTRIES_: - case gENTRY_DATATYPE_: - case rENTRY_DATATYPE_: - case zENTRY_DATATYPE_: - case gENTRY_NUMELEMS_: - case rENTRY_NUMELEMS_: - case zENTRY_NUMELEMS_: - case CDF_CHECKSUM_: { - (void) va_arg (Va.ap, Int32 *); - break; - } - /******************************************************************* - * GET_, - *******************************************************************/ - case rVAR_ALLOCATEDFROM_: - case zVAR_ALLOCATEDFROM_: - case rVAR_ALLOCATEDTO_: - case zVAR_ALLOCATEDTO_: - case DATATYPE_SIZE_: { - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - break; - } - /******************************************************************* - * GET_, - *******************************************************************/ - case CDF_COMPRESSION_: - case rVAR_COMPRESSION_: - case zVAR_COMPRESSION_: - case rVAR_SPARSEARRAYS_: - case zVAR_SPARSEARRAYS_: { - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - break; - } - /******************************************************************* - * GET_, - *******************************************************************/ - case CDF_COPYRIGHT_: - case LIB_COPYRIGHT_: - case LIB_subINCREMENT_: - case rVAR_NAME_: - case zVAR_NAME_: - case ATTR_NAME_: - case STATUS_TEXT_: { - (void) va_arg (Va.ap, void *); - (*sCp)++; - break; - } - /******************************************************************* - * GET_, - *******************************************************************/ - case rVAR_NUMBER_: - case zVAR_NUMBER_: - case ATTR_NUMBER_: { - (void) va_arg (Va.ap, void *); - (void) va_arg (Va.ap, Int32 *); - (*sCp)++; - break; - } - /******************************************************************* - * GET_, - *******************************************************************/ - case CDF_INFO_: { - (void) va_arg (Va.ap, void *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, void *); - (void) va_arg (Va.ap, void *); - (*sCp)++; - break; - } - /******************************************************************* - * GET_, - *******************************************************************/ - case rVAR_PADVALUE_: - case zVAR_PADVALUE_: - case rVAR_DATA_: - case zVAR_DATA_: - case rVAR_HYPERDATA_: - case zVAR_HYPERDATA_: - case rVAR_SEQDATA_: - case zVAR_SEQDATA_: - case gENTRY_DATA_: - case rENTRY_DATA_: - case zENTRY_DATA_: { - (void) va_arg (Va.ap, void *); - (*sCp)++; - break; - } - /******************************************************************* - * GET_, - *******************************************************************/ - case rVARs_RECDATA_: - case zVARs_RECDATA_: { - Int32 *nVars = va_arg (Va.ap, Int32 *); - Int32 *varNs = va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, void *); - break; - } - /******************************************************************* - * Unknown - hopefully the next operation. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - /************************************************************************** - * PUT_, - **************************************************************************/ - case PUT_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * PUT_, - *******************************************************************/ - case CDF_ENCODING_: - case CDF_MAJORITY_: - case CDF_FORMAT_: - case CDF_LEAPSECONDLASTUPDATED_: - case rVAR_RECVARY_: - case zVAR_RECVARY_: - case rVAR_DIMVARYS_: - case zVAR_DIMVARYS_: - case rVAR_ALLOCATERECS_: - case zVAR_ALLOCATERECS_: - case rVAR_INITIALRECS_: - case zVAR_INITIALRECS_: - case rVAR_BLOCKINGFACTOR_: - case zVAR_BLOCKINGFACTOR_: - case rVAR_SPARSERECORDS_: - case zVAR_SPARSERECORDS_: - case ATTR_SCOPE_: - case CDF_CHECKSUM_: { - (void) va_arg (Va.ap, Int32 *); - break; - } - /******************************************************************* - * PUT_, - *******************************************************************/ - case CDF_COMPRESSION_: - case rVAR_DATASPEC_: - case zVAR_DATASPEC_: - case rVAR_COMPRESSION_: - case zVAR_COMPRESSION_: - case rVAR_SPARSEARRAYS_: - case zVAR_SPARSEARRAYS_: - case rVAR_ALLOCATEBLOCK_: - case zVAR_ALLOCATEBLOCK_: - case gENTRY_DATASPEC_: - case rENTRY_DATASPEC_: - case zENTRY_DATASPEC_: { - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - break; - } - /******************************************************************* - * PUT_, - *******************************************************************/ - case rVAR_NAME_: - case zVAR_NAME_: - case ATTR_NAME_: { - (void) va_arg (Va.ap, void *); - (*sCp)++; - break; - } - /******************************************************************* - * PUT_, - *******************************************************************/ - case rVAR_PADVALUE_: - case zVAR_PADVALUE_: - case rVAR_DATA_: - case zVAR_DATA_: - case rVAR_HYPERDATA_: - case zVAR_HYPERDATA_: - case rVAR_SEQDATA_: - case zVAR_SEQDATA_: { - (void) va_arg (Va.ap, void *); - (*sCp)++; - break; - } - /******************************************************************* - * PUT_, - *******************************************************************/ - case rVARs_RECDATA_: - case zVARs_RECDATA_: { - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, void *); - break; - } - /******************************************************************* - * PUT_, - *******************************************************************/ - case gENTRY_DATA_: - case rENTRY_DATA_: - case zENTRY_DATA_: { - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, Int32 *); - (void) va_arg (Va.ap, void *); - (*sCp)++; - break; - } - /******************************************************************* - * Unknown - hopefully the next operation. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - /************************************************************************** - * Unknown - this is bad. We're lost. - **************************************************************************/ - default: - va_end (Va.ap); - return ((Int32) BAD_FNC_OR_ITEM); - } -} - -status = va_arg (Va.ap, Int32 *); - -/****************************************************************************** -* Return if only counting possible character strings. -******************************************************************************/ - -if (sCp != &sC) { - va_end (Va.ap); - return CDF_OK; -} - -/****************************************************************************** -* Store character string lengths. -******************************************************************************/ - -if (sC > 0) { - sLs = (Int32 *) cdf_AllocateMemory (sC * sizeof(Int32), NULL); - if (sLs == NULL) { - *status = (Int32) BAD_MALLOC; - return ((Int32) BAD_MALLOC); - } - for (i = 0; i < sC; i++) sLs[i] = Fif_GHOSTFETCH (Va.ap); -} -else - sLs = NULL; -va_end (Va.ap); -#endif - -/****************************************************************************** -* Scan argument list performing functions. -******************************************************************************/ - -#if defined(Fif_GHOSTLEN) -sC = 0; /* start at beginning of list of string lengths */ -#endif - -#if defined(STDARG) -va_start (Va.ap, requiredFnc); -Va.fnc = (long) *requiredFnc; -#else -VA_START (Va.ap); -Va.fnc = (long) *(va_arg (Va.ap, Int32 *)); -#endif - -while (Va.fnc != NULL_) - switch (Va.fnc) { - /************************************************************************** - * CREATE_ - **************************************************************************/ - case CREATE_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * CREATE_,CDF_ - *******************************************************************/ - case CDF_: { - void *CDFname = va_arg (Va.ap, void *); - Int32 numDims = *(va_arg (Va.ap, Int32 *)); - Int32 *dimSizes = va_arg (Va.ap, Int32 *); - Int32 *id = va_arg (Va.ap, Int32 *); - int dimN; long dimSizesT[CDF_MAX_DIMS]; CDFid idT; - if (StatusBAD(pStatus)) break; - if (numDims < 0 || numDims > CDF_MAX_DIMS) { - if (!sX(BAD_NUM_DIMS,&pStatus)) break; - } - for (dimN = 0; dimN < numDims; dimN++) { - dimSizesT[dimN] = (long) dimSizes[dimN]; - } - tStatus = CDFlib (CREATE_, CDF_, -#if defined(Fif_DESCR) - DESCRtoREFnul(CDFname, - CDF_PATHNAME_LEN, - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(CDFname,sLs[sC], - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(CDFname, - CDF_PATHNAME_LEN, - &ssh), -#endif - (long) numDims, dimSizesT, &idT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - -#if defined(Fif_GHOSTLEN) - sC++; -#endif - *id = CDFidToInt32 (idT); - currentCDFid = idT; - break; - } - /******************************************************************* - * CREATE_,rVAR_ - *******************************************************************/ - case rVAR_: { - void *varName = va_arg (Va.ap, void *); - Int32 dataType = *(va_arg (Va.ap, Int32 *)); - Int32 numElements = *(va_arg (Va.ap, Int32 *)); - Int32 recVariance = *(va_arg (Va.ap, Int32 *)); - Int32 *dimVariances = va_arg (Va.ap, Int32 *); - Int32 *var_num = va_arg (Va.ap, Int32 *); - int dimN; - long numDims, dimVarysT[CDF_MAX_DIMS], varNumT; - int LFS = FALSE; - if (currentCDFid != NULL) { - struct CDFstruct *CDF = (struct CDFstruct *)currentCDFid; - if (isLFS(CDF)) LFS = TRUE; - } - - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (GET_, rVARs_NUMDIMS_, &numDims, - NULL_); - if (!sX(tStatus,&pStatus)) break; - - for (dimN = 0; dimN < numDims; dimN++) { - dimVarysT[dimN] = (long) dimVariances[dimN]; - } - - tStatus = CDFlib (CREATE_, rVAR_, -#if defined(Fif_DESCR) - DESCRtoREFnul(varName, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(varName, - sLs[sC],&ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(varName, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif - (long) dataType, - (long) numElements, - (long) recVariance, - dimVarysT, &varNumT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - -#if defined(Fif_GHOSTLEN) - sC++; -#endif - *var_num = (Int32) (varNumT + 1); - break; - } - /******************************************************************* - * CREATE_,zVAR_ - *******************************************************************/ - case zVAR_: { - void *varName = va_arg (Va.ap, void *); - Int32 dataType = *(va_arg (Va.ap, Int32 *)); - Int32 numElements = *(va_arg (Va.ap, Int32 *)); - Int32 numDims = *(va_arg (Va.ap, Int32 *)); - Int32 *dimSizes = va_arg (Va.ap, Int32 *); - Int32 recVariance = *(va_arg (Va.ap, Int32 *)); - Int32 *dimVariances = va_arg (Va.ap, Int32 *); - Int32 *var_num = va_arg (Va.ap, Int32 *); - int dimN; - long varNumT, dimSizesT[CDF_MAX_DIMS], dimVarysT[CDF_MAX_DIMS]; - int LFS = FALSE; - if (currentCDFid != NULL) { - struct CDFstruct *CDF = (struct CDFstruct *)currentCDFid; - if (isLFS(CDF)) LFS = TRUE; - } - - if (StatusBAD(pStatus)) break; - - if (numDims < 0 || numDims > CDF_MAX_DIMS) - if (!sX(BAD_NUM_DIMS,&pStatus)) break; - - for (dimN = 0; dimN < numDims; dimN++) { - dimSizesT[dimN] = (long) dimSizes[dimN]; - dimVarysT[dimN] = (long) dimVariances[dimN]; - } - - tStatus = CDFlib (CREATE_, zVAR_, -#if defined(Fif_DESCR) - DESCRtoREFnul(varName, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(varName,sLs[sC], - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(varName, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif - (long) dataType, - (long) numElements, - (long) numDims, dimSizesT, - (long) recVariance, dimVarysT, - &varNumT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - -#if defined(Fif_GHOSTLEN) - sC++; -#endif - *var_num = (Int32) (varNumT + 1); - break; - } - /******************************************************************* - * CREATE_,ATTR_ - *******************************************************************/ - case ATTR_: { - void *attrName = va_arg (Va.ap, void *); - Int32 scope = *(va_arg (Va.ap, Int32 *)); - Int32 *attr_num = va_arg (Va.ap, Int32 *); - long attrNumT; - int LFS = FALSE; - if (currentCDFid != NULL) { - struct CDFstruct *CDF = (struct CDFstruct *)currentCDFid; - if (isLFS(CDF)) LFS = TRUE; - } - - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (CREATE_, ATTR_, -#if defined(Fif_DESCR) - DESCRtoREFnul(attrName, - (LFS ? - CDF_ATTR_NAME_LEN256 : - CDF_ATTR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(attrName,sLs[sC], - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(attrName, - (LFS ? - CDF_ATTR_NAME_LEN256 : - CDF_ATTR_NAME_LEN), - &ssh), -#endif - (long) scope, &attrNumT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - -#if defined(Fif_GHOSTLEN) - sC++; -#endif - *attr_num = (Int32) (attrNumT + 1); - break; - } - /******************************************************************* - * Unknown item - hopefully the next function. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - - /************************************************************************** - * OPEN_ - **************************************************************************/ - case OPEN_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * OPEN_,CDF_ - *******************************************************************/ - case CDF_: { - void *CDFname = va_arg (Va.ap, void *); - Int32 *id = va_arg (Va.ap, Int32 *); - CDFid idT; - - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (OPEN_, CDF_, -#if defined(Fif_DESCR) - DESCRtoREFnul(CDFname, - CDF_PATHNAME_LEN, - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(CDFname,sLs[sC], - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(CDFname, - CDF_PATHNAME_LEN,&ssh), -#endif - &idT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - -#if defined(Fif_GHOSTLEN) - sC++; -#endif - *id = CDFidToInt32 (idT); - break; - } - /******************************************************************* - * Unknown item - hopefully the next function. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - - /************************************************************************** - * DELETE_ - **************************************************************************/ - case DELETE_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * DELETE_, - *******************************************************************/ - case CDF_: - case zVAR_: - case rVAR_: - case ATTR_: - case gENTRY_: - case zENTRY_: - case rENTRY_: - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (DELETE_, Va.item, - NULL_); - if (!sX(tStatus,&pStatus)) break; - if (Va.item == CDF_) currentCDFid = NULL; - break; - /******************************************************************* - * DELETE_,r|zVAR_RECORDS_ - *******************************************************************/ - case rVAR_RECORDS_: - case zVAR_RECORDS_: { - Int32 *ptr1 = va_arg (Va.ap, Int32 *); - Int32 *ptr2 = va_arg (Va.ap, Int32 *); - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (DELETE_, Va.item, (long) (*ptr1 - 1), - (long) (*ptr2 - 1), - NULL_); - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * Unknown item - hopefully the next function. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - - /************************************************************************** - * CLOSE_ - **************************************************************************/ - case CLOSE_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * CLOSE_,CDF_ - *******************************************************************/ - case CDF_: { - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (CLOSE_, CDF_, - NULL_); - if (!sX(tStatus,&pStatus)) break; - currentCDFid = NULL; - break; - } - /******************************************************************* - * CLOSE_,rVAR_/zVAR_ - *******************************************************************/ - case rVAR_: - case zVAR_: { - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (CLOSE_, Va.item, - NULL_); - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * Unknown item - hopefully the next function. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - - /************************************************************************** - * SELECT_ - **************************************************************************/ - case SELECT_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * SELECT_, - *******************************************************************/ - case CDF_READONLY_MODE_: - case CDF_zMODE_: - case CDF_NEGtoPOSfp0_MODE_: - case CDF_DECODING_: - case CDF_CACHESIZE_: - case STAGE_CACHESIZE_: - case COMPRESS_CACHESIZE_: - case rVARs_CACHESIZE_: - case zVARs_CACHESIZE_: - case rVAR_CACHESIZE_: - case zVAR_CACHESIZE_: - case rVARs_RECCOUNT_: - case zVAR_RECCOUNT_: - case rVARs_RECINTERVAL_: - case zVAR_RECINTERVAL_: - case rVAR_RESERVEPERCENT_: - case zVAR_RESERVEPERCENT_: { - Int32 value = *(va_arg (Va.ap, Int32 *)); - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (SELECT_, Va.item, (long) value, - NULL_); - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * SELECT_, - *******************************************************************/ - case rVARs_DIMCOUNTS_: - case zVAR_DIMCOUNTS_: - case rVARs_DIMINTERVALS_: - case zVAR_DIMINTERVALS_: { - Int32 *ptr = va_arg (Va.ap, Int32 *); - Logical Z = (Va.item == zVAR_DIMCOUNTS_ || - Va.item == zVAR_DIMINTERVALS_); - long numDims, valuesT[CDF_MAX_DIMS]; - int dimN; - - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (GET_, BOO(Z,zVAR_NUMDIMS_, - rVARs_NUMDIMS_), &numDims, - NULL_); - if (!sX(tStatus,&pStatus)) break; - - for (dimN = 0; dimN < numDims; dimN++) { - valuesT[dimN] = (long) ptr[dimN]; - } - - tStatus = CDFlib (SELECT_, Va.item, valuesT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * SELECT_,<(Int32 *) - 1 [pass by value]> - *******************************************************************/ - case rVAR_: - case zVAR_: - case rVARs_RECNUMBER_: - case zVARs_RECNUMBER_: - case zVAR_RECNUMBER_: - case ATTR_: - case gENTRY_: - case rENTRY_: - case zENTRY_: { - Int32 value = *(va_arg (Va.ap, Int32 *)); - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (SELECT_, Va.item, (long) (value - 1), - NULL_); - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * SELECT_,<(Int32 [] - 1) [pass by reference] - CDF_MAX_DIMS - * maximum> - *******************************************************************/ - case rVARs_DIMINDICES_: - case zVAR_DIMINDICES_: { - Int32 *indices = va_arg (Va.ap, Int32 *); - Logical Z = (Va.item == zVAR_DIMINDICES_); - long numDims, indicesT[CDF_MAX_DIMS]; - int dimN; - - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (GET_, BOO(Z,zVAR_NUMDIMS_, - rVARs_NUMDIMS_), &numDims, - NULL_); - if (!sX(tStatus,&pStatus)) break; - - for (dimN = 0; dimN < numDims; dimN++) { - indicesT[dimN] = (long) (indices[dimN] - 1); - } - - tStatus = CDFlib (SELECT_, Va.item, indicesT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * SELECT_, - *******************************************************************/ - case CDF_SCRATCHDIR_: - case rVAR_NAME_: - case zVAR_NAME_: - case ATTR_NAME_: - case rENTRY_NAME_: - case zENTRY_NAME_: { - void *ptr = va_arg (Va.ap, void *); - int LFS = FALSE; - size_t maxLen; - - if (currentCDFid != NULL) { - struct CDFstruct *CDF = (struct CDFstruct *)currentCDFid; - if (isLFS(CDF)) LFS = TRUE; - } - -#if !defined(Fif_GHOSTLEN) - maxLen = PickMaxLen (Va.item, 4, - CDF_SCRATCHDIR_, (size_t) DU_MAX_DIR_LEN, - rVAR_NAME_, (LFS ? - (size_t) CDF_VAR_NAME_LEN256 : - (size_t) CDF_VAR_NAME_LEN), - zVAR_NAME_, (LFS ? - (size_t) CDF_VAR_NAME_LEN256 : - (size_t) CDF_VAR_NAME_LEN), - ATTR_NAME_, (LFS ? - (size_t) CDF_ATTR_NAME_LEN256 : - (size_t) CDF_ATTR_NAME_LEN)); -#endif - - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (SELECT_, Va.item, -#if defined(Fif_DESCR) - DESCRtoREFnul(ptr,maxLen,&ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(ptr,sLs[sC],&ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(ptr,maxLen,&ssh), -#endif - NULL_); - if (!sX(tStatus,&pStatus)) break; - -#if defined(Fif_GHOSTLEN) - sC++; -#endif - break; - } - /******************************************************************* - * SELECT_,CDF_ - *******************************************************************/ - case CDF_: { - Int32 *id = va_arg (Va.ap, Int32 *); - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - NULL_); - if (!sX(tStatus,&pStatus)) break; - currentCDFid = Int32ToCDFid(*id); - break; - } - /******************************************************************* - * SELECT_,CDF_STATUS_ - *******************************************************************/ - case CDF_STATUS_: { - Int32 newStatus = *(va_arg (Va.ap, Int32 *)); - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (SELECT_, CDF_STATUS_, (CDFstatus) newStatus, - NULL_); - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * SELECT_,rVAR_SEQPOS_/zVAR_SEQPOS_ - *******************************************************************/ - case rVAR_SEQPOS_: - case zVAR_SEQPOS_: { - Int32 rec_num = *(va_arg (Va.ap, Int32 *)); - Int32 *indices = va_arg (Va.ap, Int32 *); - Logical Z = (Va.item == zVAR_SEQPOS_); - long numDims, indicesT[CDF_MAX_DIMS]; - int dimN; - - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (GET_, BOO(Z,zVAR_NUMDIMS_, - rVARs_NUMDIMS_), &numDims, - NULL_); - if (!sX(tStatus,&pStatus)) break; - - for (dimN = 0; dimN < numDims; dimN++) { - indicesT[dimN] = (long) (indices[dimN] - 1); - } - - tStatus = CDFlib (SELECT_, Va.item, (long) (rec_num-1), indicesT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * Unknown item - hopefully the next function. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - - /************************************************************************** - * CONFIRM_ - **************************************************************************/ - case CONFIRM_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * CONFIRM_, - *******************************************************************/ - case CURgENTRY_EXISTENCE_: - case CURrENTRY_EXISTENCE_: - case CURzENTRY_EXISTENCE_: - case CDF_CHECKSUM_: { - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (CONFIRM_, Va.item, - NULL_); - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * CONFIRM_, - *******************************************************************/ - case CDF_READONLY_MODE_: - case CDF_zMODE_: - case CDF_NEGtoPOSfp0_MODE_: - case CDF_DECODING_: - case CDF_CACHESIZE_: - case STAGE_CACHESIZE_: - case COMPRESS_CACHESIZE_: - case rVAR_CACHESIZE_: - case zVAR_CACHESIZE_: - case rVARs_RECCOUNT_: - case zVAR_RECCOUNT_: - case rVARs_RECINTERVAL_: - case zVAR_RECINTERVAL_: - case rVAR_RESERVEPERCENT_: - case zVAR_RESERVEPERCENT_: { - Int32 *ptr = va_arg (Va.ap, Int32 *); - long valueT; - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (CONFIRM_, Va.item, &valueT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - *ptr = (Int32) valueT; - break; - } - /******************************************************************* - * CONFIRM_,<(Int32 *) + 1 [output]> - *******************************************************************/ - case rVAR_: - case zVAR_: - case rVARs_RECNUMBER_: - case zVAR_RECNUMBER_: - case ATTR_: - case gENTRY_: - case rENTRY_: - case zENTRY_: { - Int32 *ptr = va_arg (Va.ap, Int32 *); - long valueT; - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (CONFIRM_, Va.item, &valueT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - *ptr = (Int32) (valueT + 1); - break; - } - /******************************************************************* - * CONFIRM_,<(Int32 []) [output] - CDF_MAX_DIMS maximum> - *******************************************************************/ - case rVARs_DIMCOUNTS_: - case zVAR_DIMCOUNTS_: - case rVARs_DIMINTERVALS_: - case zVAR_DIMINTERVALS_: { - Int32 *ptr = va_arg (Va.ap, Int32 *); - Logical Z = (Va.item == zVAR_DIMCOUNTS_ || - Va.item == zVAR_DIMINTERVALS_); - long numDims, valuesT[CDF_MAX_DIMS]; - int dimN; - - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (GET_, BOO(Z,zVAR_NUMDIMS_, - rVARs_NUMDIMS_), &numDims, - CONFIRM_, Va.item, valuesT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - - for (dimN = 0; dimN < numDims; dimN++) { - ptr[dimN] = (Int32) valuesT[dimN]; - } - break; - } - /******************************************************************* - * CONFIRM_,<(Int32 [] + 1) [output] - CDF_MAX_DIMS maximum> - *******************************************************************/ - case rVARs_DIMINDICES_: - case zVAR_DIMINDICES_: { - Int32 *values = va_arg (Va.ap, Int32 *); - Logical Z = (Va.item == zVAR_DIMINDICES_); - long numDims, valuesT[CDF_MAX_DIMS]; - int dimN; - - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (GET_, BOO(Z,zVAR_NUMDIMS_, - rVARs_NUMDIMS_), &numDims, - CONFIRM_, Va.item, valuesT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - - for (dimN = 0; dimN < numDims; dimN++) { - values[dimN] = (Int32) (valuesT[dimN] + 1); - } - break; - } - /******************************************************************* - * CONFIRM_,<(Int32 *) - 1 [input]> - *******************************************************************/ - case gENTRY_EXISTENCE_: - case rENTRY_EXISTENCE_: - case zENTRY_EXISTENCE_: { - Int32 entryN = *(va_arg (Va.ap, Int32 *)); - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (CONFIRM_, Va.item, (long) (entryN - 1), - NULL_); - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * CONFIRM_, - *******************************************************************/ - case rVAR_EXISTENCE_: - case zVAR_EXISTENCE_: - case ATTR_EXISTENCE_: { - void *varName = va_arg (Va.ap, void *); - int LFS = FALSE; - size_t maxLen; - - if (currentCDFid != NULL) { - struct CDFstruct *CDF = (struct CDFstruct *)currentCDFid; - if (isLFS(CDF)) LFS = TRUE; - } - -#if !defined(Fif_GHOSTLEN) - maxLen = PickMaxLen (Va.item, 3, - rVAR_EXISTENCE_, (LFS ? - (size_t) CDF_VAR_NAME_LEN256 : - (size_t) CDF_VAR_NAME_LEN), - zVAR_EXISTENCE_, (LFS ? - (size_t) CDF_VAR_NAME_LEN256 : - (size_t) CDF_VAR_NAME_LEN), - ATTR_EXISTENCE_, (LFS ? - (size_t) CDF_ATTR_NAME_LEN256: - (size_t) CDF_ATTR_NAME_LEN)); -#endif - - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (CONFIRM_, Va.item, -#if defined(Fif_DESCR) - DESCRtoREFnul(varName, - maxLen,&ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(varName,sLs[sC], - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(varName,maxLen, - &ssh), -#endif - NULL_); - if (!sX(tStatus,&pStatus)) break; -#if defined(Fif_GHOSTLEN) - sC++; -#endif - break; - } - /******************************************************************* - * CONFIRM_,CDF_NAME_ - *******************************************************************/ - case CDF_NAME_: { - void *name = va_arg (Va.ap, void *); - char nameT[CDF_PATHNAME_LEN+1]; - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (CONFIRM_, CDF_NAME_, nameT, - NULL_); - if (!sX(tStatus,&pStatus)) break; -#if defined(Fif_GHOSTLEN) - CtoFORTstring (nameT, name, sLs[sC]); - sC++; -#else - CtoFORTstring (nameT, name, CDF_PATHNAME_LEN); -#endif - break; - } - /******************************************************************* - * CONFIRM_,rVAR_SEQPOS_/zVAR_SEQPOS_ - *******************************************************************/ - case rVAR_SEQPOS_: - case zVAR_SEQPOS_: { - Int32 *rec_num = va_arg (Va.ap, Int32 *); - Int32 *indices = va_arg (Va.ap, Int32 *); - Logical Z = (Va.item == zVAR_SEQPOS_); - long numDims, indicesT[CDF_MAX_DIMS], recNumT; - int dimN; - - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (GET_, BOO(Z,zVAR_NUMDIMS_, - rVARs_NUMDIMS_), &numDims, - CONFIRM_, Va.item, &recNumT, indicesT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - - *rec_num = (Int32) (recNumT + 1); - for (dimN = 0; dimN < numDims; dimN++) { - indices[dimN] = (Int32) (indicesT[dimN] + 1); - } - break; - } - /******************************************************************* - * Unknown item - hopefully the next function. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - - /************************************************************************** - * GET_ - **************************************************************************/ - case GET_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * GET_,. - *******************************************************************/ - case rVARs_NUMDIMS_: - case zVAR_NUMDIMS_: - case CDF_ENCODING_: - case CDF_MAJORITY_: - case CDF_FORMAT_: - case CDF_LEAPSECONDLASTUPDATED_: - case CDF_NUMrVARS_: - case CDF_NUMzVARS_: - case CDF_NUMATTRS_: - case CDF_NUMgATTRS_: - case CDF_NUMvATTRS_: - case CDF_VERSION_: - case CDF_RELEASE_: - case CDF_INCREMENT_: - case rVAR_DATATYPE_: - case zVAR_DATATYPE_: - case rVAR_NUMELEMS_: - case zVAR_NUMELEMS_: - case rVAR_RECVARY_: - case zVAR_RECVARY_: - case rVAR_BLOCKINGFACTOR_: - case zVAR_BLOCKINGFACTOR_: - case rVAR_nINDEXRECORDS_: - case zVAR_nINDEXRECORDS_: - case rVAR_nINDEXENTRIES_: - case zVAR_nINDEXENTRIES_: - case rVAR_nINDEXLEVELS_: - case zVAR_nINDEXLEVELS_: - case rVAR_NUMRECS_: - case zVAR_NUMRECS_: - case rVAR_NUMallocRECS_: - case zVAR_NUMallocRECS_: - case rVAR_SPARSERECORDS_: - case zVAR_SPARSERECORDS_: - case ATTR_SCOPE_: - case ATTR_NUMgENTRIES_: - case ATTR_NUMrENTRIES_: - case ATTR_NUMzENTRIES_: - case gENTRY_DATATYPE_: - case rENTRY_DATATYPE_: - case zENTRY_DATATYPE_: - case gENTRY_NUMELEMS_: - case rENTRY_NUMELEMS_: - case zENTRY_NUMELEMS_: - case LIB_VERSION_: - case LIB_RELEASE_: - case LIB_INCREMENT_: - case CDF_CHECKSUM_: { - Int32 *ptr = va_arg (Va.ap, Int32 *); - long valueT; - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (GET_, Va.item, &valueT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - *ptr = (Int32) valueT; - break; - } - /******************************************************************* - * GET_,. - *******************************************************************/ - case DATATYPE_SIZE_: { - Int32 *ptr1 = va_arg (Va.ap, Int32 *); - Int32 *ptr2 = va_arg (Va.ap, Int32 *); - long valueT; - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (GET_, Va.item, (long) *ptr1, &valueT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - *ptr2 = (Int32) valueT; - break; - } - /******************************************************************* - * GET_,<(Int32 * In) - 1, (Int32 * Out) + 1>. - *******************************************************************/ - case rVAR_ALLOCATEDTO_: - case zVAR_ALLOCATEDTO_: - case rVAR_ALLOCATEDFROM_: - case zVAR_ALLOCATEDFROM_: { - Int32 *ptr1 = va_arg (Va.ap, Int32 *); - Int32 *ptr2 = va_arg (Va.ap, Int32 *); - long valueT; - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (GET_, Va.item, (long) (*ptr1 - 1), &valueT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - *ptr2 = (Int32) (valueT + 1); - break; - } - /******************************************************************* - * GET_,<(Int32 *) + 1 (passed by reference)>. - *******************************************************************/ - case rVARs_MAXREC_: - case zVARs_MAXREC_: - case rVAR_MAXREC_: - case zVAR_MAXREC_: - case rVAR_MAXallocREC_: - case zVAR_MAXallocREC_: - case ATTR_MAXgENTRY_: - case ATTR_MAXrENTRY_: - case ATTR_MAXzENTRY_: { - Int32 *ptr = va_arg (Va.ap, Int32 *); - long valueT; - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (GET_, Va.item, &valueT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - *ptr = (Int32) (valueT + 1); - break; - } - /******************************************************************* - * GET_, - *******************************************************************/ - case rVARs_DIMSIZES_: - case zVAR_DIMSIZES_: - case rVAR_DIMVARYS_: - case zVAR_DIMVARYS_: { - Int32 *ptr = va_arg (Va.ap, Int32 *); - Logical Z = (Va.item == zVAR_DIMSIZES_ || - Va.item == zVAR_DIMVARYS_); - long valuesT[CDF_MAX_DIMS], numDims; - int dimN; - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (GET_, BOO(Z,zVAR_NUMDIMS_, - rVARs_NUMDIMS_), &numDims, - Va.item, valuesT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - for (dimN = 0; dimN < numDims; dimN++) { - ptr[dimN] = (Int32) valuesT[dimN]; - } - break; - } - /******************************************************************* - * GET_,. - *******************************************************************/ - case LIB_subINCREMENT_: - case LIB_COPYRIGHT_: - case CDF_COPYRIGHT_: - case rVAR_NAME_: - case zVAR_NAME_: - case ATTR_NAME_: { - void *ptr = va_arg (Va.ap, void *); - char *ptrT; - int LFS = FALSE; - size_t maxLen; - - if (currentCDFid != NULL) { - struct CDFstruct *CDF = (struct CDFstruct *)currentCDFid; - if (isLFS(CDF)) LFS = TRUE; - } - - if (StatusBAD(pStatus)) break; - maxLen = PickMaxLen (Va.item, 6, - LIB_subINCREMENT_, (size_t) 1, - LIB_COPYRIGHT_, (size_t) CDF_DOCUMENT_LEN, - CDF_COPYRIGHT_, (size_t) CDF_DOCUMENT_LEN, - rVAR_NAME_, (LFS ? - (size_t) CDF_VAR_NAME_LEN256 : - (size_t) CDF_VAR_NAME_LEN), - zVAR_NAME_, (LFS ? - (size_t) CDF_VAR_NAME_LEN256 : - (size_t) CDF_VAR_NAME_LEN), - ATTR_NAME_, (LFS ? - (size_t) CDF_ATTR_NAME_LEN256 : - (size_t) CDF_ATTR_NAME_LEN)); - ptrT = (char *) cdf_AllocateMemory (maxLen + 1, NULL); - if (ptrT == NULL) { - if (!sX(BAD_MALLOC,&pStatus)) break; - } - tStatus = CDFlib (GET_, Va.item, ptrT, - NULL_); - if (!sX(tStatus,&pStatus)) { - cdf_FreeMemory (ptrT, NULL); - break; - } -#if defined(Fif_GHOSTLEN) - CtoFORTstring (ptrT, ptr, sLs[sC]); - sC++; -#else - CtoFORTstring (ptrT, ptr, (int) maxLen); -#endif - cdf_FreeMemory (ptrT, NULL); - break; - } - /******************************************************************* - * GET_, - *******************************************************************/ - case rVAR_NUMBER_: - case zVAR_NUMBER_: - case ATTR_NUMBER_: { - void *ptr1 = va_arg (Va.ap, void *); - Int32 *ptr2 = va_arg (Va.ap, Int32 *); - long valueT; - int LFS = FALSE; - size_t maxLen; - - if (currentCDFid != NULL) { - struct CDFstruct *CDF = (struct CDFstruct *)currentCDFid; - if (isLFS(CDF)) LFS = TRUE; - } - -#if !defined(Fif_GHOSTLEN) - maxLen = PickMaxLen (Va.item, 3, - rVAR_NUMBER_, (LFS ? - (size_t) CDF_VAR_NAME_LEN256 : - (size_t) CDF_VAR_NAME_LEN), - zVAR_NUMBER_, (LFS ? - (size_t) CDF_VAR_NAME_LEN256 : - (size_t) CDF_VAR_NAME_LEN), - ATTR_NUMBER_, (LFS ? - (size_t) CDF_ATTR_NAME_LEN256 : - (size_t) CDF_ATTR_NAME_LEN)); -#endif - - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (GET_, Va.item, -#if defined(Fif_DESCR) - DESCRtoREFnul(ptr1,maxLen,&ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(ptr1,sLs[sC],&ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(ptr1,maxLen,&ssh), -#endif - &valueT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - -#if defined(Fif_GHOSTLEN) - sC++; -#endif - *ptr2 = (Int32) (valueT + 1); - break; - } - /******************************************************************* - * GET_,CDF_INFO_: - *******************************************************************/ - case CDF_INFO_: { - void *ptr1 = va_arg (Va.ap, void *); - Int32 *ptr2 = va_arg (Va.ap, Int32 *); - Int32 *ptr3 = va_arg (Va.ap, Int32 *); - void *ptr4 = va_arg (Va.ap, void *); - void *ptr5 = va_arg (Va.ap, void *); - long cType, cParms[CDF_MAX_PARMS]; /* cSize, uSize;*/ int p; - void *cSize, *uSize; - int LFS = FALSE; - if (currentCDFid != NULL) { - struct CDFstruct *CDF = (struct CDFstruct *)currentCDFid; - if (isLFS(CDF)) LFS = TRUE; - } - if (LFS) { - cSize = (OFF_T *) cdf_AllocateMemory(sizeof(OFF_T), NULL); - uSize = (OFF_T *) cdf_AllocateMemory(sizeof(OFF_T), NULL); - } else { - cSize = (long *) cdf_AllocateMemory(sizeof(long), NULL); - uSize = (long *) cdf_AllocateMemory(sizeof(long), NULL); - } - tStatus = CDFlib (GET_, Va.item, -#if defined(Fif_DESCR) - DESCRtoREFnul(ptr1, - CDF_PATHNAME_LEN, - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(ptr1,sLs[sC],&ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(ptr1, - CDF_PATHNAME_LEN, - &ssh), -#endif - &cType, cParms, cSize, uSize, - NULL_); - if (!sX(tStatus,&pStatus)) break; -#if defined(Fif_GHOSTLEN) - sC++; -#endif - *ptr2 = (Int32) cType; - for (p = 0; p < CompressionParmsCount((Int32)cType); p++) { - ptr3[p] = (Int32) cParms[p]; - } - memcpy(ptr4, cSize, sizeof(cSize)); - memcpy(ptr5, uSize, sizeof(uSize)); - cdf_FreeMemory (cSize, NULL); - cdf_FreeMemory (uSize, NULL); - break; - } - /******************************************************************* - * GET_,CDF_COMPRESSION_ - * GET_,rVAR_COMPRESSION_ - * GET_,zVAR_COMPRESSION_ - * GET_,rVAR_SPARSEARRAYS_ - * GET_,zVAR_SPARSEARRAYS_ - *******************************************************************/ - case CDF_COMPRESSION_: - case rVAR_COMPRESSION_: - case zVAR_COMPRESSION_: - case rVAR_SPARSEARRAYS_: - case zVAR_SPARSEARRAYS_: { - Logical sparse = (Va.item == rVAR_SPARSEARRAYS_ || - Va.item == zVAR_SPARSEARRAYS_); - Int32 *ptr1 = va_arg (Va.ap, Int32 *); - Int32 *ptr2 = va_arg (Va.ap, Int32 *); - Int32 *ptr3 = va_arg (Va.ap, Int32 *); - long type, parms[CDF_MAX_PARMS], pct; int pCount, p; - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (GET_, Va.item, &type, parms, &pct, - NULL_); - if (!sX(tStatus,&pStatus)) break; - *ptr1 = (Int32) type; - pCount = BOO(sparse,SparsenessParmsCount((Int32)type), - CompressionParmsCount((Int32)type)); - for (p = 0; p < pCount; p++) ptr2[p] = (Int32) parms[p]; - *ptr3 = (Int32) pct; - break; - } - /******************************************************************* - * GET_, - *******************************************************************/ - case rVAR_PADVALUE_: - case zVAR_PADVALUE_: - case rVAR_DATA_: - case zVAR_DATA_: - case rVAR_HYPERDATA_: - case zVAR_HYPERDATA_: - case rVAR_SEQDATA_: - case zVAR_SEQDATA_: { - void *ptr = va_arg (Va.ap, void *); - Logical Z = (Va.item == zVAR_PADVALUE_ || - Va.item == zVAR_DATA_ || - Va.item == zVAR_HYPERDATA_ || - Va.item == zVAR_SEQDATA_); - long dataType; - - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (GET_, BOO(Z,zVAR_DATATYPE_, - rVAR_DATATYPE_), &dataType, - NULL_); - if (!sX(tStatus,&pStatus)) break; - - tStatus = CDFlib (GET_, Va.item, -#if defined(Fif_DESCR) - STRINGdataType(dataType) ? - DESCRtoREF(ptr) : ptr, -#else - ptr, -#endif - NULL_); - if (!sX(tStatus,&pStatus)) break; - -#if defined(Fif_GHOSTLEN) - if (STRINGdataType(dataType)) sC++; -#endif - break; - } - /******************************************************************* - * GET_,r/zVARs_RECDATA_ - *******************************************************************/ - case rVARs_RECDATA_: - case zVARs_RECDATA_: { - Int32 *nVars = va_arg (Va.ap, Int32 *); - Int32 *varNs = va_arg (Va.ap, Int32 *); - void *ptr = va_arg (Va.ap, void *); - long *tVarNs; int varX; - if (StatusBAD(pStatus)) break; - if (*nVars < 1) { - if (!sX(BAD_NUM_VARS,&pStatus)) break; - } - tVarNs = (long *) cdf_AllocateMemory ((size_t)(*nVars*sizeof(long)), - NULL); - if (tVarNs == NULL) { - if (!sX(BAD_MALLOC,&pStatus)) break; - } - for (varX = 0; varX < *nVars; varX++) { - tVarNs[varX] = (long) (varNs[varX] - 1); - } - tStatus = CDFlib (GET_, Va.item, (long) *nVars, tVarNs, ptr, - NULL_); - cdf_FreeMemory (tVarNs, NULL); /*Before checking status.*/ - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * GET_,gENTRY_DATA_/rENTRY_DATA_/zENTRY_DATA_ - *******************************************************************/ - case gENTRY_DATA_: - case rENTRY_DATA_: - case zENTRY_DATA_: { - void *value = va_arg (Va.ap, void *); - int Et = E3p(Va.item,gENTRY_DATA_,rENTRY_DATA_,zENTRY_DATA_); - long dataType; - - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (GET_, E3(Et,gENTRY_DATATYPE_, - rENTRY_DATATYPE_, - zENTRY_DATATYPE_), &dataType, - NULL_); - if (!sX(tStatus,&pStatus)) break; - - tStatus = CDFlib (GET_, Va.item, -#if defined(Fif_DESCR) - STRINGdataType(dataType) ? - DESCRtoREF(value) : value, -#else - value, -#endif - NULL_); - if (!sX(tStatus,&pStatus)) break; - -#if defined(Fif_GHOSTLEN) - if (STRINGdataType(dataType)) sC++; -#endif - break; - } - /******************************************************************* - * GET_,STATUS_TEXT_ - *******************************************************************/ - case STATUS_TEXT_: { - void *textPtr = va_arg (Va.ap, void *); - char textT[CDF_STATUSTEXT_LEN+1]; - - if (StatusBAD(pStatus)) break; - - tStatus = CDFlib (GET_, STATUS_TEXT_, textT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - -#if defined(Fif_GHOSTLEN) - CtoFORTstring (textT, textPtr, sLs[sC]); - sC++; -#else - CtoFORTstring (textT, textPtr, CDF_STATUSTEXT_LEN); -#endif - break; - } - /******************************************************************* - * Unknown item - hopefully the next function. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - - /************************************************************************** - * PUT_ - **************************************************************************/ - case PUT_: - for (;;) { - Va.item = (long) *(va_arg (Va.ap, Int32 *)); - switch (Va.item) { - /******************************************************************* - * PUT_, - *******************************************************************/ - case CDF_ENCODING_: - case CDF_MAJORITY_: - case CDF_FORMAT_: - case CDF_LEAPSECONDLASTUPDATED_: - case rVAR_RECVARY_: - case zVAR_RECVARY_: - case rVAR_ALLOCATERECS_: - case zVAR_ALLOCATERECS_: - case rVAR_INITIALRECS_: - case zVAR_INITIALRECS_: - case rVAR_BLOCKINGFACTOR_: - case zVAR_BLOCKINGFACTOR_: - case rVAR_SPARSERECORDS_: - case zVAR_SPARSERECORDS_: - case ATTR_SCOPE_: - case CDF_CHECKSUM_: { - Int32 *ptr = va_arg (Va.ap, Int32 *); - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (PUT_, Va.item, (long) *ptr, - NULL_); - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * PUT_, - *******************************************************************/ - case rVAR_DIMVARYS_: - case zVAR_DIMVARYS_: { - Int32 *ptr = va_arg (Va.ap, Int32 *); - Logical Z = (Va.item == zVAR_DIMVARYS_); - long valuesT[CDF_MAX_DIMS], numDims; - int dimN; - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (GET_, BOO(Z,zVAR_NUMDIMS_, - rVARs_NUMDIMS_), &numDims, - NULL_); - if (!sX(tStatus,&pStatus)) break; - for (dimN = 0; dimN < numDims; dimN++) { - valuesT[dimN] = (long) ptr[dimN]; - } - tStatus = CDFlib (PUT_, Va.item, valuesT, - NULL_); - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * PUT_,CDF_COMPRESSION_ - * PUT_,rVAR_COMPRESSION_ - * PUT_,zVAR_COMPRESSION_ - * PUT_,rVAR_SPARSEARRAYS_ - * PUT_,zVAR_SPARSEARRAYS_ - *******************************************************************/ - case CDF_COMPRESSION_: - case rVAR_COMPRESSION_: - case zVAR_COMPRESSION_: - case rVAR_SPARSEARRAYS_: - case zVAR_SPARSEARRAYS_: { - Logical sparse = (Va.item == rVAR_SPARSEARRAYS_ || - Va.item == zVAR_SPARSEARRAYS_); - Int32 *ptr1 = va_arg (Va.ap, Int32 *); - Int32 *ptr2 = va_arg (Va.ap, Int32 *); - int p, pCount = BOO(sparse,SparsenessParmsCount(*ptr1), - CompressionParmsCount(*ptr1)); - long parms[CDF_MAX_PARMS]; - if (StatusBAD(pStatus)) break; - for (p = 0; p < pCount; p++) parms[p] = (long) ptr2[p]; - tStatus = CDFlib (PUT_, Va.item, (long) *ptr1, parms, - NULL_); - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * PUT_, - *******************************************************************/ - case rVAR_DATASPEC_: - case zVAR_DATASPEC_: - case gENTRY_DATASPEC_: - case rENTRY_DATASPEC_: - case zENTRY_DATASPEC_: { - Int32 value1 = *(va_arg (Va.ap, Int32 *)); - Int32 value2 = *(va_arg (Va.ap, Int32 *)); - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (PUT_, Va.item, (long) value1, (long) value2, - NULL_); - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * PUT_,<(Int32 *) - 1, (Int32 *) - 1> - *******************************************************************/ - case rVAR_ALLOCATEBLOCK_: - case zVAR_ALLOCATEBLOCK_: { - Int32 value1 = *(va_arg (Va.ap, Int32 *)) - 1; - Int32 value2 = *(va_arg (Va.ap, Int32 *)) - 1; - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (PUT_, Va.item, (long) value1, (long) value2, - NULL_); - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * PUT_, - *******************************************************************/ - case rVAR_NAME_: - case zVAR_NAME_: - case ATTR_NAME_: { - void *ptr = va_arg (Va.ap, void *); - int LFS = FALSE; - size_t maxLen; - - if (currentCDFid != NULL) { - struct CDFstruct *CDF = (struct CDFstruct *)currentCDFid; - if (isLFS(CDF)) LFS = TRUE; - } - -#if !defined(Fif_GHOSTLEN) - maxLen = PickMaxLen (Va.item, 3, - rVAR_NAME_,(LFS ? - (size_t) CDF_VAR_NAME_LEN256 : - (size_t) CDF_VAR_NAME_LEN), - zVAR_NAME_,(LFS? - (size_t) CDF_VAR_NAME_LEN256 : - (size_t) CDF_VAR_NAME_LEN), - ATTR_NAME_,(LFS? - (size_t) CDF_ATTR_NAME_LEN256 : - (size_t) CDF_ATTR_NAME_LEN)); -#endif - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (PUT_, Va.item, -#if defined(Fif_DESCR) - DESCRtoREFnul(ptr,maxLen,&ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(ptr,sLs[sC],&ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(ptr,maxLen,&ssh), -#endif - NULL_); - if (!sX(tStatus,&pStatus)) break; - -#if defined(Fif_GHOSTLEN) - sC++; -#endif - break; - } - /******************************************************************* - * PUT_, - *******************************************************************/ - case rVAR_PADVALUE_: - case zVAR_PADVALUE_: - case rVAR_DATA_: - case zVAR_DATA_: - case rVAR_HYPERDATA_: - case zVAR_HYPERDATA_: - case rVAR_SEQDATA_: - case zVAR_SEQDATA_: { - void *ptr = va_arg (Va.ap, void *); - Logical Z = (Va.item == zVAR_PADVALUE_ || - Va.item == zVAR_DATA_ || - Va.item == zVAR_HYPERDATA_ || - Va.item == zVAR_SEQDATA_); - long dataType; - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (GET_, BOO(Z,zVAR_DATATYPE_, - rVAR_DATATYPE_), &dataType, - NULL_); - if (!sX(tStatus,&pStatus)) break; - tStatus = CDFlib (PUT_, Va.item, -#if defined(Fif_DESCR) - STRINGdataType(dataType) ? - DESCRtoREF(ptr) : ptr, -#else - ptr, -#endif - NULL_); - if (!sX(tStatus,&pStatus)) break; -#if defined(Fif_GHOSTLEN) - if (STRINGdataType(dataType)) sC++; -#endif - break; - } - /******************************************************************* - * PUT_,r/zVARs_RECDATA_ - *******************************************************************/ - case rVARs_RECDATA_: - case zVARs_RECDATA_: { - Int32 *nVars = va_arg (Va.ap, Int32 *); - Int32 *varNs = va_arg (Va.ap, Int32 *); - void *ptr = va_arg (Va.ap, void *); - long *tVarNs; int varX; - if (StatusBAD(pStatus)) break; - if (*nVars < 1) { - if (!sX(BAD_NUM_VARS,&pStatus)) break; - } - tVarNs = (long *) cdf_AllocateMemory ((size_t)(*nVars*sizeof(long)), - NULL); - if (tVarNs == NULL) { - if (!sX(BAD_MALLOC,&pStatus)) break; - } - for (varX = 0; varX < *nVars; varX++) { - tVarNs[varX] = (long) (varNs[varX] - 1); - } - tStatus = CDFlib (PUT_, Va.item, (long) *nVars, tVarNs, ptr, - NULL_); - cdf_FreeMemory (tVarNs, NULL); /*Before checking status.*/ - if (!sX(tStatus,&pStatus)) break; - break; - } - /******************************************************************* - * PUT_,gENTRY_DATA_/rENTRY_DATA_/zENTRY_DATA_ - *******************************************************************/ - case gENTRY_DATA_: - case rENTRY_DATA_: - case zENTRY_DATA_: { - Int32 dataType = *(va_arg (Va.ap, Int32 *)); - Int32 numElements = *(va_arg (Va.ap, Int32 *)); - void *value = va_arg (Va.ap, void *); - if (StatusBAD(pStatus)) break; - tStatus = CDFlib (PUT_, Va.item, (long) dataType, - (long) numElements, -#if defined(Fif_DESCR) - STRINGdataType(dataType) ? - DESCRtoREF(value) : value, -#else - value, -#endif - NULL_); - if (!sX(tStatus,&pStatus)) break; -#if defined(Fif_GHOSTLEN) - if (STRINGdataType(dataType)) sC++; -#endif - break; - } - /******************************************************************* - * Unknown item - hopefully the next function. - *******************************************************************/ - default: { - Va.fnc = Va.item; - break; - } - } - if (Va.fnc == Va.item) break; - } - break; - /************************************************************************** - * Unknown function/item. This is bad - we're lost. - **************************************************************************/ - default: { -#if defined(Fif_GHOSTLEN) - if (sLs != NULL) cdf_FreeMemory (sLs, NULL); -#endif - FreeStrings (ssh); - va_end (Va.ap); - return ((Int32) BAD_FNC_OR_ITEM); - } - } - -#if defined(Fif_GHOSTLEN) -if (sLs != NULL) cdf_FreeMemory (sLs, NULL); -#endif - -status = va_arg (Va.ap, Int32 *); -*status = (Int32) pStatus; - -va_end (Va.ap); - -FreeStrings (ssh); -return ((Int32) pStatus); -} - -/****************************************************************************** -* PickMaxLen. -* Syntax: len = PickMaxLen (targetItem, nListed, -* listItem1, listLen1, -* listItem2, listLen2, -* . -* . -* . -* listItemN, listLenN); -******************************************************************************/ - -static size_t PickMaxLen -#if defined(STDARG) -(long requiredArgument, ...) -#else -(va_alist) -va_dcl -#endif -{ - va_list ap; - long targetItem; /* The item being sought. */ - int nListed; /* The number of listed items (the list - being searched for the target item). */ - int listN; /* Index into list of item/length pairs. */ -#if defined(STDARG) - va_start (ap, requiredArgument); - targetItem = requiredArgument; -#else - VA_START (ap); - targetItem = va_arg (ap, long); -#endif - nListed = va_arg (ap, int); - for (listN = 0; listN < nListed; listN++) { - long listItem = va_arg (ap, long); - size_t listLen = va_arg (ap, size_t); - if (listItem == targetItem) { - va_end (ap); - return listLen; - } - } - va_end (ap); - return (size_t) 0; -} - -/****************************************************************************** -* CDF_lib_4. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_4__,cdf_lib_4_,cdf_lib_4,CDF_LIB_4) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[4]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a3); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, l[0], l[1], l[2], l[3]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[4]; int i; void *a[4]; - va_list ap; CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 4; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], l[0], l[1], l[2], l[3]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3); -#else - void *a[4]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 4; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_5. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_5__,cdf_lib_5_,cdf_lib_5,CDF_LIB_5) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[5]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a4); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, - l[0], l[1], l[2], l[3], l[4]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[5]; int i; void *a[5]; - va_list ap; CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 5; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], - l[0], l[1], l[2], l[3], l[4]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4); -#else - void *a[5]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 5; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_6. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_6__,cdf_lib_6_,cdf_lib_6,CDF_LIB_6) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[6]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a5); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, - l[0], l[1], l[2], l[3], l[4], l[5]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[6]; int i; void *a[6]; - va_list ap; CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 6; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], - l[0], l[1], l[2], l[3], l[4], l[5]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5); -#else - void *a[6]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 6; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_7. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_7__,cdf_lib_7_,cdf_lib_7,CDF_LIB_7) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[7]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a6); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, - l[0], l[1], l[2], l[3], l[4], l[5], l[6]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[7]; int i; void *a[7]; - va_list ap; CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 7; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], - l[0], l[1], l[2], l[3], l[4], l[5], l[6]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6); -#else - void *a[7]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 7; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_8. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_8__,cdf_lib_8_,cdf_lib_8,CDF_LIB_8) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[8]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a7); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[8]; int i; void *a[8]; - va_list ap; CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 8; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7); -#else - void *a[8]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 8; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_9. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_9__,cdf_lib_9_,cdf_lib_9,CDF_LIB_9) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[9]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a8); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[9]; int i; void *a[9]; - va_list ap; CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 9; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8); -#else - void *a[9]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 9; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_10. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_10__,cdf_lib_10_,cdf_lib_10,CDF_LIB_10) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[10]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a9); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[10]; int i; void *a[10]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 10; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9); -#else - void *a[10]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 10; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_11. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_11__,cdf_lib_11_,cdf_lib_11,CDF_LIB_11) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, void *a10, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[11]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a10); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[11]; int i; void *a[11]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 11; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9], a[10]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); -#else - void *a[11]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 11; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_12. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_12__,cdf_lib_12_,cdf_lib_12,CDF_LIB_12) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, void *a10, void *a11, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[12]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a11); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[12]; int i; void *a[12]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 12; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9], a[10], a[11]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11); -#else - void *a[12]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 12; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_13. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_13__,cdf_lib_13_,cdf_lib_13,CDF_LIB_13) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, void *a10, void *a11, void *a12, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[13]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, - a12); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a12); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[13]; int i; void *a[13]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 13; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9], a[10], a[11], a[12]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12); -#else - void *a[13]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 13; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_14. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_14__,cdf_lib_14_,cdf_lib_14,CDF_LIB_14) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, void *a10, void *a11, void *a12, void *a13, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[14]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, - a12, a13); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a13); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[14]; int i; void *a[14]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 14; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9], a[10], a[11], a[12], a[13]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13); -#else - void *a[14]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 14; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_15. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_15__,cdf_lib_15_,cdf_lib_15,CDF_LIB_15) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, void *a10, void *a11, void *a12, void *a13, - void *a14, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[15]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, - a12, a13, a14); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a14); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[15]; int i; void *a[15]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 15; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9], a[10], a[11], a[12], a[13], a[14]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14); -#else - void *a[15]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 15; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_16. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_16__,cdf_lib_16_,cdf_lib_16,CDF_LIB_16) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, void *a10, void *a11, void *a12, void *a13, - void *a14, void *a15, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[16]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, - a12, a13, a14, a15); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a15); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[16]; int i; void *a[16]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 16; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15); -#else - void *a[16]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 16; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_17. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_17__,cdf_lib_17_,cdf_lib_17,CDF_LIB_17) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, void *a10, void *a11, void *a12, void *a13, - void *a14, void *a15, void *a16, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[17]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, - a12, a13, a14, a15, a16); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a16); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[17]; int i; void *a[17]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 17; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], - a[16]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16); -#else - void *a[17]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 17; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_18. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_18__,cdf_lib_18_,cdf_lib_18,CDF_LIB_18) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, void *a10, void *a11, void *a12, void *a13, - void *a14, void *a15, void *a16, void *a17, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[18]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, - a12, a13, a14, a15, a16, a17); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a17); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17, l[0], l[1], l[2], l[3], l[4], l[5], - l[6], l[7], l[8], l[9], l[10], l[11], l[12], l[13], l[14], - l[15], l[16], l[17]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[18]; int i; void *a[18]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 18; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], - a[16], a[17]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16], l[17]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17); -#else - void *a[18]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 18; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_19. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_19__,cdf_lib_19_,cdf_lib_19,CDF_LIB_19) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, void *a10, void *a11, void *a12, void *a13, - void *a14, void *a15, void *a16, void *a17, void *a18, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[19]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, - a12, a13, a14, a15, a16, a17, a18); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a18); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17, a18, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16], l[17], - l[18]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[19]; int i; void *a[19]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 19; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], - a[16], a[17], a[18]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], - a[18], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16], l[17], - l[18]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17, a18); -#else - void *a[19]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 19; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], - a[18]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_20. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_20__,cdf_lib_20_,cdf_lib_20,CDF_LIB_20) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, void *a10, void *a11, void *a12, void *a13, - void *a14, void *a15, void *a16, void *a17, void *a18, void *a19, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[20]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, - a12, a13, a14, a15, a16, a17, a18, a19); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a19); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17, a18, a19, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16], l[17], - l[18], l[19]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[20]; int i; void *a[20]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 20; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], - a[16], a[17], a[18], a[19]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], - a[18], a[19], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16], l[17], - l[18], l[19]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17, a18, a19); -#else - void *a[20]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 20; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], - a[18], a[19]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_21. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_21__,cdf_lib_21_,cdf_lib_21,CDF_LIB_21) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, void *a10, void *a11, void *a12, void *a13, - void *a14, void *a15, void *a16, void *a17, void *a18, void *a19, void *a20, - ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[21]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, - a12, a13, a14, a15, a16, a17, a18, a19, a20); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a20); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17, a18, a19, a20, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16], l[17], - l[18], l[19], l[20]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[21]; int i; void *a[21]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 21; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], - a[16], a[17], a[18], a[19], a[20]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], - a[18], a[19], a[20], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16], l[17], - l[18], l[19], l[20]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17, a18, a19, a20); -#else - void *a[21]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 21; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], - a[18], a[19], a[20]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_22. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_22__,cdf_lib_22_,cdf_lib_22,CDF_LIB_22) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, void *a10, void *a11, void *a12, void *a13, - void *a14, void *a15, void *a16, void *a17, void *a18, void *a19, void *a20, - void *a21, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[22]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, - a12, a13, a14, a15, a16, a17, a18, a19, a20, a21); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a21); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17, a18, a19, a20, a21, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16], l[17], - l[18], l[19], l[20], l[21]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[22]; int i; void *a[22]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 22; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], - a[16], a[17], a[18], a[19], a[20], a[21]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], - a[18], a[19], a[20], a[21], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16], l[17], - l[18], l[19], l[20], l[21]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17, a18, a19, a20, a21); -#else - void *a[22]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 22; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], - a[18], a[19], a[20], a[21]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_23. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_23__,cdf_lib_23_,cdf_lib_23,CDF_LIB_23) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, void *a10, void *a11, void *a12, void *a13, - void *a14, void *a15, void *a16, void *a17, void *a18, void *a19, void *a20, - void *a21, void *a22, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[23]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, - a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a22); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17, a18, a19, a20, a21, a22, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16], l[17], - l[18], l[19], l[20], l[21], l[22]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[23]; int i; void *a[23]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 23; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], - a[16], a[17], a[18], a[19], a[20], a[21], a[22]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], - a[18], a[19], a[20], a[21], a[22], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16], l[17], - l[18], l[19], l[20], l[21], l[22]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17, a18, a19, a20, a21, a22); -#else - void *a[23]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 23; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], - a[18], a[19], a[20], a[21], a[22]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_24. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_24__,cdf_lib_24_,cdf_lib_24,CDF_LIB_24) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, void *a10, void *a11, void *a12, void *a13, - void *a14, void *a15, void *a16, void *a17, void *a18, void *a19, void *a20, - void *a21, void *a22, void *a23, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[24]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, - a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, - a23); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a23); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16], l[17], - l[18], l[19], l[20], l[21], l[22], l[23]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[24]; int i; void *a[24]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 24; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], - a[16], a[17], a[18], a[19], a[20], a[21], a[22], a[23]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], - a[18], a[19], a[20], a[21], a[22], a[23], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16], l[17], - l[18], l[19], l[20], l[21], l[22], l[23]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17, a18, a19, a20, a21, a22, a23); -#else - void *a[24]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 24; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], - a[18], a[19], a[20], a[21], a[22], a[23]); -#endif -#endif -} - -/****************************************************************************** -* CDF_lib_25. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_lib_25__,cdf_lib_25_,cdf_lib_25,CDF_LIB_25) -#if defined(STDARG) -(void *a0, void *a1, void *a2, void *a3, void *a4, void *a5, void *a6, - void *a7, void *a8, void *a9, void *a10, void *a11, void *a12, void *a13, - void *a14, void *a15, void *a16, void *a17, void *a18, void *a19, void *a20, - void *a21, void *a22, void *a23, void *a24, ...) -#else -(va_alist) -va_dcl -#endif -{ -#if defined(Fif_GHOSTLEN) -#if defined(STDARG) - Int32 sC = 0; Fif_GHOSTTYPE l[25]; int i; va_list ap; CDFstatus tStatus; - tStatus = CDF_LIBx (&sC, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, - a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, - a23, a24); - if (StatusBAD(tStatus)) return tStatus; - va_start (ap, a24); - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16], l[17], - l[18], l[19], l[20], l[21], l[22], l[23], l[24]); -#else - Int32 sC = 0; Fif_GHOSTTYPE l[25]; int i; void *a[25]; va_list ap; - CDFstatus tStatus; - VA_START (ap); - for (i = 0; i < 25; i++) a[i] = va_arg (ap, void *); - tStatus = CDF_LIBx (&sC, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], - a[8], a[9], a[10], a[11], a[12], a[13], a[14], a[15], - a[16], a[17], a[18], a[19], a[20], a[21], a[22], a[23], - a[24]); - if (StatusBAD(tStatus)) return tStatus; - for (i = 0; i < sC; i++) l[i] = va_arg (ap, Fif_GHOSTTYPE); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], - a[18], a[19], a[20], a[21], a[22], a[23], a[24], - l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7], l[8], l[9], - l[10], l[11], l[12], l[13], l[14], l[15], l[16], l[17], - l[18], l[19], l[20], l[21], l[22], l[23], l[24]); -#endif -#else -#if defined(STDARG) - return CDF_LIBx (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, - a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24); -#else - void *a[25]; int i; va_list ap; - VA_START (ap); - for (i = 0; i < 25; i++) a[i] = va_arg (ap, void *); - va_end (ap); - return CDF_LIBx (a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], - a[10], a[11], a[12], a[13], a[14], a[15], a[16], a[17], - a[18], a[19], a[20], a[21], a[22], a[23], a[24]); -#endif -#endif -} diff --git a/cdf36_3-dist/src/lib/cdffsi.c b/cdf36_3-dist/src/lib/cdffsi.c deleted file mode 100644 index b7bf1fc..0000000 --- a/cdf36_3-dist/src/lib/cdffsi.c +++ /dev/null @@ -1,3089 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF Standard Interface (I) /FORTRAN. -* -* Version 2.7, 14-Feb-96, Hughes STX. -* -* Modification history: -* -* V1.0 22-Jan-91, J Love Original version (for CDF V2.0). -* V1.1 11-Feb-91, J Love Fixed max_rec in CDF_inquire. -* V2.0 1-Jun-91, J Love Renamed (was CDF_V2_FORTRAN_IF.C). Changed -* for new CDF V2.1 internal structures. Also -* calls INTERNAL i/f directly rather than using -* C i/f. -* V2.1 30-Jul-91, J Love Use 'CDFlib'. If variable data type is CHAR -* or UCHAR, check for %DESCR (if VMS). -* V2.2 20-May-92, J Love Modified for IBM-PC port (Microsoft C/FORTRAN -* necessary). CDF V2.2. -* V2.3 2-Sep-92, J Love CDF V2.3 (shareable/NeXT). -* V2.4 18-Oct-93, J Love CDF V2.4 (DEC Alpha ports [`int' != `long']). -* V2.4a 2-Mar-94, J Love Fixed `CDF_create' (dimensionality checking). -* V2.5 9-Nov-94, J Love CDF V2.5. -* V2.6 19-Jan-95, J Love IRIX 6.0 (64-bit). -* V2.6a 13-Jun-95, J Love Linux. -* V2.7 14-Feb-96, J Love CDF V2.6 (renamed - previously `cdf_f_if.c'). -* V3.0 28-Aug-01, M Liu Add CDF_getrVarsRecordData, -* CDF_getzVarsRecordData, CDF_putrVarsRecordData, -* CDF_putzVarsRecordData. -* V3.1 26-May-05, M Liu Initial version (for CDF V3.1). -* V3.2 23-Oct-08, M Liu Modified CDF_getrVarsRecordData, -* CDF_getzVarsRecordData, CDF_putrVarsRecordData, -* CDF_putzVarsRecordData to use the number of -* passed variables to allocate buffers. -* V3.3 10-Jan-09, M Liu Added CDF_set_Validate and CDF_get_Validate. -* -******************************************************************************/ - -/****************************************************************************** -* -* Notes: -* -* For the FORTRAN interfaces everything is indexed from one (1) while for -* the C interfaces everything is indexed from zero (0) [eg. variable and -* attribute numbers, record numbers, indices, entry numbers]. For this -* reason one (1) is subtracted from arguments passed in while one (1) is -* added to arguments passed out (where appropriate). -* -* The FORTRAN interfaces use INTEGER*4 as the data type for all numerical -* values passed in/out while the C interfaces use `long'. These are the same -* on all supported platforms except the DEC Alpha (where `long' is 8 bytes). -* For this reason temporary variables/arrays of size `long' are used in the -* calls to the CDF library (the direct C interface). This causes a small -* performance loss on the other platforms mainly when calling CDF_var_get or -* CDF_var_put (but then CDF_var_hyper_get and CDF_var_hyper_put should have -* been used instead). -* -******************************************************************************/ - -/****************************************************************************** -* -* Notes for VMS version: -* -* To make the user's life a little easier, all names and attribute -* values (for attributes of data types CDF_CHAR and CDF_UCHAR) may be passed -* in and out by either reference or descriptor. The default passing mode -* for an embedded character string (e.g., CALL subr (..., 'string', ...)) or -* a CHARACTER variable symbol (e.g., CALL subr (..., ATTR_NAME, ...) where -* ATTR_NAME is defined as CHARACTER*8) is by descriptor when passing from -* FORTRAN to C in VMS. -* -* An embedded character string could be enclosed in %REF() to force -* passing by reference since the FORTRAN compiler puts a NUL character at -* the end of these strings as expected by the CDF V2.0 library (written in -* C). Enclosing a CHARACTER variable symbol in %REF() will result in -* an error, however, because a NUL character is not placed at the ends of -* these type strings by the FORTRAN compiler. The user would have to -* supply the terminating NUL. By letting the passing mode default to -* by-descriptor, this interface will supply the terminating NUL. -* -* The main difference here from CDF Version 1 is that the %REF() is -* not needed when passing out names and attribute values. Also, variable -* values for character variables need not be enclosed in %REF(). -* -******************************************************************************/ - -/****************************************************************************** -* -* Notes for UNIX version: -* -* All passing between FORTRAN and C on UNIX systems is done by reference. -* When character strings are passed between FORTRAN and C, extra arguments -* are added to the argument list containing the lengths of those character -* strings (EXCEPT on NeXT machines - FORTRAN applications must NUL-terminate -* passed character strings). -* -* Entry points have been made lowercase because the FORTRAN compiler -* converts all uppercase characters to lowercase in entry points. This way -* the linker will find everything. Unix FORTRAN compilers and linkers also -* seem to like trailing '_'s (except on the IBM-RS6000/AIX, HP9000/HP-UX, -* and NeXT/Mach). -* -******************************************************************************/ - -/****************************************************************************** -* -* Notes for IBM PC version: -* -* The Standard Interface/FORTRAN is supported for the Microsoft FORTRAN -* compiler. Microsoft C must be used to compile/link the CDF library -* (including this file). -* -******************************************************************************/ - -/****************************************************************************** -* -* Notes for Macintosh version (MPW Fortran): -* -* The Standard Interface/FORTRAN is supported for the MPW FORTRAN compiler. -* MPW C must be used to compile/link the CDF library (including this file). -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* CDF_create. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_create__,cdf_create_,cdf_create,CDF_CREATE) -(CDF_name, num_dims, dim_sizes, encoding, majority, id, status - Fif_GHOSTARG(len)) -char *CDF_name; /* In: CDF name. */ -Int32 *num_dims; /* In: Number of dimensions. */ -Int32 dim_sizes[]; /* In: Dimension sizes. */ -Int32 *encoding; /* In: Host or network. */ -Int32 *majority; /* In: Row or column major. */ -Int32 *id; /* Out: CDF identifier. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "CDF_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - int dimN; - long dimSizesT[CDF_MAX_DIMS]; - CDFid idT; - long num_dimsT = (long) *num_dims; - long encodingT = (long) *encoding; - long majorityT = (long) *majority; - - if (num_dimsT < 0 || num_dimsT > CDF_MAX_DIMS) { - *status = (Int32) BAD_NUM_DIMS; - return; - } - - for (dimN = 0; dimN < num_dimsT; dimN++) { - dimSizesT[dimN] = (long) dim_sizes[dimN]; - } - - *status = (Int32) CDFlib (CREATE_, CDF_, -#if defined(Fif_DESCR) - DESCRtoREFnul(CDF_name, - CDF_PATHNAME_LEN, - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(CDF_name, - Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(CDF_name, - CDF_PATHNAME_LEN,&ssh), -#endif - num_dimsT, dimSizesT, &idT, - NULL_); - FreeStrings (ssh); - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (PUT_, CDF_ENCODING_, encodingT, - CDF_MAJORITY_, majorityT, - NULL_); - if (StatusBAD(*status)) { - CDFlib (DELETE_, CDF_, - NULL_); - return; - } - - *id = CDFidToInt32 (idT); - return; -} - -/****************************************************************************** -* CDF_create_cdf. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_create_cdf__, - cdf_create_cdf_, - cdf_create_cdf, - CDF_CREATE_CDF) -(CDF_name, id, status - Fif_GHOSTARG(len)) -char *CDF_name; /* In: CDF name. */ -Int32 *id; /* Out: CDF identifier. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "CDF_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - long dimSizesT[1] = {0}; - CDFid idT; - - *status = (Int32) CDFlib (CREATE_, CDF_, -#if defined(Fif_DESCR) - DESCRtoREFnul(CDF_name, - CDF_PATHNAME_LEN, - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(CDF_name, - Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(CDF_name, - CDF_PATHNAME_LEN,&ssh), -#endif - 0L, dimSizesT, &idT, - NULL_); - - FreeStrings (ssh); - if (StatusBAD(*status)) return; - - *id = CDFidToInt32 (idT); - return; -} - -/****************************************************************************** -* CDF_open. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_open__,cdf_open_,cdf_open,CDF_OPEN) -(CDF_name, id, status Fif_GHOSTARG(len)) -void *CDF_name; /* In: CDF name. */ -Int32 *id; /* Out: CDF identifier. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "CDF_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - CDFid idT; - - *status = (Int32) CDFlib (OPEN_, CDF_, -#if defined(Fif_DESCR) - DESCRtoREFnul(CDF_name, - CDF_PATHNAME_LEN,&ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(CDF_name, - Fif_GHOSTUSE(len),&ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(CDF_name,CDF_PATHNAME_LEN, - &ssh), -#endif - &idT, - NULL_); - FreeStrings (ssh); - if (StatusBAD(*status)) return; - - *id = CDFidToInt32 (idT); - return; -} - -/****************************************************************************** -* CDF_open_cdf. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_open_cdf__,cdf_open_cdf_,cdf_open_cdf,CDF_OPEN_CDF) -(CDF_name, id, status Fif_GHOSTARG(len)) -void *CDF_name; /* In: CDF name. */ -Int32 *id; /* Out: CDF identifier. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "CDF_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - CDFid idT; - - *status = (Int32) CDFlib (OPEN_, CDF_, -#if defined(Fif_DESCR) - DESCRtoREFnul(CDF_name, - CDF_PATHNAME_LEN,&ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(CDF_name, - Fif_GHOSTUSE(len),&ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(CDF_name,CDF_PATHNAME_LEN, - &ssh), -#endif - &idT, - NULL_); - FreeStrings (ssh); - if (StatusBAD(*status)) return; - - *id = CDFidToInt32 (idT); - return; -} - -/****************************************************************************** -* CDF_doc. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_doc__,cdf_doc_,cdf_doc,CDF_DOC) -(id, version, release, text, status Fif_GHOSTARG(text_len)) -Int32 *id; /* In: CDF identifier. */ -Int32 *version; /* Out: CDF version number (creating library - version number). */ -Int32 *release; /* Out: CDF release number (creating library - release number). */ -void *text; /* Out: Copyright text. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(text_len) /* Invisible length of "text" - (generated by FORTRAN compiler). */ -{ - char copyRightTextT[CDF_COPYRIGHT_LEN+1]; - long versionT, releaseT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, CDF_VERSION_, &versionT, - CDF_RELEASE_, &releaseT, - CDF_COPYRIGHT_, copyRightTextT, - NULL_); - if (StatusBAD(*status)) return; - - *version = (Int32) versionT; - *release = (Int32) releaseT; -#if defined(Fif_GHOSTLEN) - CtoFORTstring (copyRightTextT, text, Fif_GHOSTUSE(text_len)); -#else - CtoFORTstring (copyRightTextT, text, CDF_COPYRIGHT_LEN); -#endif - return; -} - -/****************************************************************************** -* CDF_inquire. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_inquire__,cdf_inquire_,cdf_inquire,CDF_INQUIRE) -(id, num_dims, dim_sizes, encoding, majority, max_rec, num_vars, num_attrs, -status) -Int32 *id; /* In: CDF identifier. */ -Int32 *num_dims; /* Out: Number of rDimensions. */ -Int32 dim_sizes[]; /* Out: rDimension sizes. */ -Int32 *encoding; /* Out: Host or network. */ -Int32 *majority; /* Out: Row or column major. */ -Int32 *max_rec; /* Out: Maximum rRecord number. */ -Int32 *num_vars; /* Out: Number of rVariables. */ -Int32 *num_attrs; /* Out: Number of attributes. */ -Int32 *status; /* Out: CDF status code. */ -{ - long maxRecT, numDimsT, dimSizesT[CDF_MAX_DIMS], encodingT, majorityT, - numVarsT, numAttrsT; - int dimN; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, rVARs_NUMDIMS_, &numDimsT, - rVARs_DIMSIZES_, dimSizesT, - CDF_ENCODING_, &encodingT, - CDF_MAJORITY_, &majorityT, - rVARs_MAXREC_, &maxRecT, - CDF_NUMrVARS_, &numVarsT, - CDF_NUMATTRS_, &numAttrsT, - NULL_); - if (StatusBAD(*status)) return; - - *num_dims = (Int32) numDimsT; - for (dimN = 0; dimN < (int) numDimsT; dimN++) { - dim_sizes[dimN] = (Int32) dimSizesT[dimN]; - } - *encoding = (Int32) encodingT; - *majority = (Int32) majorityT; - *max_rec = (Int32) (maxRecT + 1); - *num_vars = (Int32) numVarsT; - *num_attrs = (Int32) numAttrsT; - return; -} - -/****************************************************************************** -* CDF_inquire_cdf. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_inquire_cdf__,cdf_inquire_cdf_,cdf_inquire_cdf, - CDF_INQUIRE_CDF) -(id, num_dims, dim_sizes, encoding, majority, max_rrec, num_rvars, - max_zrec, num_zvars, num_attrs, -status) -Int32 *id; /* In: CDF identifier. */ -Int32 *num_dims; /* Out: Number of rDimensions. */ -Int32 dim_sizes[]; /* Out: rDimension sizes. */ -Int32 *encoding; /* Out: Host or network. */ -Int32 *majority; /* Out: Row or column major. */ -Int32 *max_rrec; /* Out: Maximum rRecord number. */ -Int32 *num_rvars; /* Out: Number of rVariables. */ -Int32 *max_zrec; /* Out: Maximum zRecord number. */ -Int32 *num_zvars; /* Out: Number of zVariables. */ -Int32 *num_attrs; /* Out: Number of attributes. */ -Int32 *status; /* Out: CDF status code. */ -{ - long maxrRecT, numDimsT, dimSizesT[CDF_MAX_DIMS], encodingT, majorityT, - numrVarsT, numAttrsT, numzVarsT, maxzRecT; - int dimN; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, rVARs_NUMDIMS_, &numDimsT, - rVARs_DIMSIZES_, dimSizesT, - CDF_ENCODING_, &encodingT, - CDF_MAJORITY_, &majorityT, - rVARs_MAXREC_, &maxrRecT, - CDF_NUMrVARS_, &numrVarsT, - zVARs_MAXREC_, &maxzRecT, - CDF_NUMzVARS_, &numzVarsT, - CDF_NUMATTRS_, &numAttrsT, - NULL_); - if (StatusBAD(*status)) return; - - *num_dims = (Int32) numDimsT; - for (dimN = 0; dimN < (int) numDimsT; dimN++) { - dim_sizes[dimN] = (Int32) dimSizesT[dimN]; - } - *encoding = (Int32) encodingT; - *majority = (Int32) majorityT; - *max_rrec = (Int32) (maxrRecT + 1); - *num_rvars = (Int32) numrVarsT; - *num_attrs = (Int32) numAttrsT; - *max_zrec = (Int32) (maxzRecT + 1); - *num_zvars = (Int32) numzVarsT; - return; -} - -/****************************************************************************** -* CDF_close. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_close__,cdf_close_,cdf_close,CDF_CLOSE) -(id, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *status; /* Out: CDF status code. */ -{ - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CLOSE_, CDF_, - NULL_); - return; -} - -/****************************************************************************** -* CDF_close_cdf. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_close_cdf__,cdf_close_cdf_,cdf_close_cdf,CDF_CLOSE_CDF) -(id, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *status; /* Out: CDF status code. */ -{ - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CLOSE_, CDF_, - NULL_); - return; -} - -/****************************************************************************** -* CDF_delete. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_delete__,cdf_delete_,cdf_delete,CDF_DELETE) -(id, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *status; /* Out: CDF status code. */ -{ - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - DELETE_, CDF_, - NULL_); - return; -} - -/****************************************************************************** -* CDF_delete_cdf. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_delete_cdf__,cdf_delete_cdf_,cdf_delete_cdf,CDF_DELETE_CDF) -(id, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *status; /* Out: CDF status code. */ -{ - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - DELETE_, CDF_, - NULL_); - return; -} - -/****************************************************************************** -* CDF_attr_create. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_attr_create__, - cdf_attr_create_, - cdf_attr_create, - CDF_ATTR_CREATE) -(id, attr_name, attr_scope, attr_num, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *attr_name; /* In: Attribute name. */ -Int32 *attr_scope; /* In: Attribute scope. */ -Int32 *attr_num; /* Out: Attribute number. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "attr_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - long attrNumT; - long scopeT = (long) *attr_scope; - int LFS = FALSE; - struct CDFstruct *CDF; - - CDF = (struct CDFstruct *)Int32ToCDFid(*id); - if (isLFS(CDF)) LFS = TRUE; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CREATE_, ATTR_, -#if defined(Fif_DESCR) - DESCRtoREFnul(attr_name, - (LFS ? - CDF_ATTR_NAME_LEN256 : - CDF_ATTR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(attr_name, - Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(attr_name, - (LFS ? - CDF_ATTR_NAME_LEN256 : - CDF_ATTR_NAME_LEN), - &ssh), -#endif - scopeT, &attrNumT, - NULL_); - FreeStrings (ssh); - if (StatusBAD(*status)) return; - - *attr_num = (Int32) (attrNumT + 1); - return; -} - -/****************************************************************************** -* CDF_create_attr. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_create_attr__, - cdf_create_attr_, - cdf_create_attr, - CDF_CREATE_ATTR) -(id, attr_name, attr_scope, attr_num, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *attr_name; /* In: Attribute name. */ -Int32 *attr_scope; /* In: Attribute scope. */ -Int32 *attr_num; /* Out: Attribute number. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "attr_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - long attrNumT; - long scopeT = (long) *attr_scope; - int LFS = FALSE; - struct CDFstruct *CDF; - - CDF = (struct CDFstruct *)Int32ToCDFid(*id); - if (isLFS(CDF)) LFS = TRUE; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CREATE_, ATTR_, -#if defined(Fif_DESCR) - DESCRtoREFnul(attr_name, - (LFS ? - CDF_ATTR_NAME_LEN256 : - CDF_ATTR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(attr_name, - Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(attr_name, - (LFS ? - CDF_ATTR_NAME_LEN256 : - CDF_ATTR_NAME_LEN), - &ssh), -#endif - scopeT, &attrNumT, - NULL_); - FreeStrings (ssh); - if (StatusBAD(*status)) return; - - *attr_num = (Int32) (attrNumT + 1); - return; -} - -/****************************************************************************** -* CDF_attr_num. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_attr_num__,cdf_attr_num_,cdf_attr_num,CDF_ATTR_NUM) -(id, attr_name Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *attr_name; /* In: Attribute name. */ -Fif_GHOSTDEF(len) /* Invisible length of "attr_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - CDFstatus status; - long attrNumT; - int LFS = FALSE; - struct CDFstruct *CDF; - - CDF = (struct CDFstruct *)Int32ToCDFid(*id); - if (isLFS(CDF)) LFS = TRUE; - - status = CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, ATTR_NUMBER_, -#if defined(Fif_DESCR) - DESCRtoREFnul(attr_name, - (LFS ? - CDF_ATTR_NAME_LEN256 : - CDF_ATTR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(attr_name, - Fif_GHOSTUSE(len),&ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(attr_name, - (LFS ? - CDF_ATTR_NAME_LEN256 : - CDF_ATTR_NAME_LEN), - &ssh), -#endif - &attrNumT, - NULL_); - FreeStrings (ssh); - - if (StatusOK(status)) - return ((Int32) (attrNumT + 1)); - else - return ((Int32) status); -} - -/****************************************************************************** -* CDF_get_attr_num. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_num__,cdf_get_attr_num_,cdf_get_attr_num, - CDF_GET_ATTR_NUM) -(id, attr_name Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *attr_name; /* In: Attribute name. */ -Fif_GHOSTDEF(len) /* Invisible length of "attr_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - CDFstatus status; - long attrNumT; - int LFS = FALSE; - struct CDFstruct *CDF; - - CDF = (struct CDFstruct *)Int32ToCDFid(*id); - if (isLFS(CDF)) LFS = TRUE; - - status = CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, ATTR_NUMBER_, -#if defined(Fif_DESCR) - DESCRtoREFnul(attr_name, - (LFS ? - CDF_ATTR_NAME_LEN256 : - CDF_ATTR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(attr_name, - Fif_GHOSTUSE(len),&ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(attr_name, - (LFS ? - CDF_ATTR_NAME_LEN256 : - CDF_ATTR_NAME_LEN), - &ssh), -#endif - &attrNumT, - NULL_); - FreeStrings (ssh); - - if (StatusOK(status)) - return ((Int32) (attrNumT + 1)); - else - return ((Int32) status); -} - -/****************************************************************************** -* CDF_attr_rename. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_attr_rename__, - cdf_attr_rename_, - cdf_attr_rename, - CDF_ATTR_RENAME) -(id, attr_num, attr_name, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -void *attr_name; /* In: New attribute name. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "attr_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - long attrNumT = (long) (*attr_num - 1); - int LFS = FALSE; - struct CDFstruct *CDF; - - CDF = (struct CDFstruct *)Int32ToCDFid(*id); - if (isLFS(CDF)) LFS = TRUE; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - PUT_, ATTR_NAME_, -#if defined(Fif_DESCR) - DESCRtoREFnul(attr_name, - (LFS ? - CDF_ATTR_NAME_LEN256 : - CDF_ATTR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(attr_name, - Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(attr_name, - (LFS ? - CDF_ATTR_NAME_LEN256 : - CDF_ATTR_NAME_LEN), - &ssh), -#endif - NULL_); - FreeStrings (ssh); - return; -} - -/****************************************************************************** -* CDF_rename_attr. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_rename_attr__, - cdf_rename_attr_, - cdf_rename_attr, - CDF_RENAME_ATTR) -(id, attr_num, attr_name, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -void *attr_name; /* In: New attribute name. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "attr_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - long attrNumT = (long) (*attr_num - 1); - int LFS = FALSE; - struct CDFstruct *CDF; - - CDF = (struct CDFstruct *)Int32ToCDFid(*id); - if (isLFS(CDF)) LFS = TRUE; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - PUT_, ATTR_NAME_, -#if defined(Fif_DESCR) - DESCRtoREFnul(attr_name, - (LFS ? - CDF_ATTR_NAME_LEN256 : - CDF_ATTR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(attr_name, - Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(attr_name, - (LFS ? - CDF_ATTR_NAME_LEN256 : - CDF_ATTR_NAME_LEN), - &ssh), -#endif - NULL_); - FreeStrings (ssh); - return; -} - -/****************************************************************************** -* CDF_attr_inquire. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_attr_inquire__, - cdf_attr_inquire_, - cdf_attr_inquire, - CDF_ATTR_INQUIRE) -(id, attr_num, attr_name, attr_scope, max_entry, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -void *attr_name; /* Out: Attribute name. */ -Int32 *attr_scope; /* Out: Attribute scope. */ -Int32 *max_entry; /* Out: Maximum gEntry/rEntry number used. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "attr_name" - (generated by FORTRAN compiler). */ -{ - char attrNameT[CDF_ATTR_NAME_LEN256]; - long maxEntryT, attrScopeT; - long attrNumT = (long) (*attr_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - GET_, ATTR_NAME_, attrNameT, - ATTR_SCOPE_, &attrScopeT, - NULL_); - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (GET_, BOO(GLOBALscope(attrScopeT), - ATTR_MAXgENTRY_, - ATTR_MAXrENTRY_), &maxEntryT, - NULL_); - if (StatusBAD(*status)) return; - -#if defined(Fif_GHOSTLEN) - CtoFORTstring (attrNameT, attr_name, Fif_GHOSTUSE(len)); -#else - CtoFORTstring (attrNameT, attr_name, CDF_ATTR_NAME_LEN256); -#endif - *attr_scope = (Int32) attrScopeT; - *max_entry = (Int32) (maxEntryT + 1); - return; -} - -/****************************************************************************** -* CDF_inquire_attr. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_inquire_attr__, - cdf_inquire_attr_, - cdf_inquire_attr, - CDF_INQUIRE_ATTR) -(id, attr_num, attr_name, attr_scope, max_gentry, max_rentry, max_zentry, - status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -void *attr_name; /* Out: Attribute name. */ -Int32 *attr_scope; /* Out: Attribute scope. */ -Int32 *max_gentry; /* Out: Maximum gEntry number if global attribute. */ -Int32 *max_rentry; /* Out: Maximum rEntry number if variable attribute. */ -Int32 *max_zentry; /* Out: Maximum zEntry number if variable attribute. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "attr_name" - (generated by FORTRAN compiler). */ -{ - char attrNameT[CDF_ATTR_NAME_LEN256]; - long maxgEntryT = -1, maxrEntryT = -1, maxzEntryT = -1, attrScopeT; - long attrNumT = (long) (*attr_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - GET_, ATTR_NAME_, attrNameT, - ATTR_SCOPE_, &attrScopeT, - NULL_); - if (StatusBAD(*status)) return; - - if (GLOBALscope(attrScopeT)) { - *status = (Int32) CDFlib (GET_, ATTR_MAXgENTRY_, &maxgEntryT, - NULL_); - if (StatusBAD(*status)) return; - } else { - *status = (Int32) CDFlib (GET_, ATTR_MAXrENTRY_, &maxrEntryT, - ATTR_MAXzENTRY_, &maxzEntryT, - NULL_); - if (StatusBAD(*status)) return; - } - -#if defined(Fif_GHOSTLEN) - CtoFORTstring (attrNameT, attr_name, Fif_GHOSTUSE(len)); -#else - CtoFORTstring (attrNameT, attr_name, CDF_ATTR_NAME_LEN256); -#endif - *attr_scope = (Int32) attrScopeT; - *max_gentry = (Int32) (maxgEntryT + 1); - *max_rentry = (Int32) (maxrEntryT + 1); - *max_zentry = (Int32) (maxzEntryT + 1); - return; -} - -/****************************************************************************** -* CDF_attr_entry_inquire. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_attr_entry_inquire__, - cdf_attr_entry_inquire_, - cdf_attr_entry_inquire, - CDF_ATTR_ENTRY_INQUIRE) -(id, attr_num, entry_num, data_type, num_elements, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: gEntry/rEntry number. */ -Int32 *data_type; /* Out: Data type. */ -Int32 *num_elements; /* Out: Number of elements. */ -Int32 *status; /* Out: CDF status code. */ -{ - long dataTypeT, numElementsT, scope; - long attrNumT = (long) (*attr_num - 1); - long entryNumT = (long) (*entry_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (SELECT_, BOO(GLOBALscope(scope), - gENTRY_,rENTRY_), entryNumT, - GET_, BOO(GLOBALscope(scope), - gENTRY_DATATYPE_, - rENTRY_DATATYPE_), &dataTypeT, - BOO(GLOBALscope(scope), - gENTRY_NUMELEMS_, - rENTRY_NUMELEMS_), &numElementsT, - NULL_); - if (StatusBAD(*status)) return; - - *data_type = (Int32) dataTypeT; - *num_elements = (Int32) numElementsT; - return; -} - -/****************************************************************************** -* CDF_inquire_attr_gentry. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_inquire_attr_gentry__, - cdf_inquire_attr_gentry_, - cdf_inquire_attr_gentry, - CDF_INQUIRE_ATTR_GENTRY) -(id, attr_num, entry_num, data_type, num_elements, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: gEntry number. */ -Int32 *data_type; /* Out: Data type. */ -Int32 *num_elements; /* Out: Number of elements. */ -Int32 *status; /* Out: CDF status code. */ -{ - long dataTypeT, numElementsT, scope; - long attrNumT = (long) (*attr_num - 1); - long entryNumT = (long) (*entry_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - if (!GLOBALscope(scope)) { - *status = (Int32) ILLEGAL_FOR_SCOPE; - return; - } - - *status = (Int32) CDFlib (SELECT_, gENTRY_, entryNumT, - GET_, gENTRY_DATATYPE_, &dataTypeT, - gENTRY_NUMELEMS_, &numElementsT, - NULL_); - if (StatusBAD(*status)) return; - - *data_type = (Int32) dataTypeT; - *num_elements = (Int32) numElementsT; - return; -} - -/****************************************************************************** -* CDF_inquire_attr_rentry. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_inquire_attr_rentry__, - cdf_inquire_attr_rentry_, - cdf_inquire_attr_rentry, - CDF_INQUIRE_ATTR_RENTRY) -(id, attr_num, entry_num, data_type, num_elements, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: rEntry number. */ -Int32 *data_type; /* Out: Data type. */ -Int32 *num_elements; /* Out: Number of elements. */ -Int32 *status; /* Out: CDF status code. */ -{ - long dataTypeT, numElementsT, scope; - long attrNumT = (long) (*attr_num - 1); - long entryNumT = (long) (*entry_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - if (GLOBALscope(scope)) { - *status = (Int32) ILLEGAL_FOR_SCOPE; - return; - } - - *status = (Int32) CDFlib (SELECT_, rENTRY_, entryNumT, - GET_, rENTRY_DATATYPE_, &dataTypeT, - rENTRY_NUMELEMS_, &numElementsT, - NULL_); - if (StatusBAD(*status)) return; - - *data_type = (Int32) dataTypeT; - *num_elements = (Int32) numElementsT; - return; -} - -/****************************************************************************** -* CDF_inquire_attr_zentry. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_inquire_attr_zentry__, - cdf_inquire_attr_zentry_, - cdf_inquire_attr_zentry, - CDF_INQUIRE_ATTR_ZENTRY) -(id, attr_num, entry_num, data_type, num_elements, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: zEntry number. */ -Int32 *data_type; /* Out: Data type. */ -Int32 *num_elements; /* Out: Number of elements. */ -Int32 *status; /* Out: CDF status code. */ -{ - long dataTypeT, numElementsT, scope; - long attrNumT = (long) (*attr_num - 1); - long entryNumT = (long) (*entry_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - if (GLOBALscope(scope)) { - *status = (Int32) ILLEGAL_FOR_SCOPE; - return; - } - - *status = (Int32) CDFlib (SELECT_, zENTRY_, entryNumT, - GET_, zENTRY_DATATYPE_, &dataTypeT, - zENTRY_NUMELEMS_, &numElementsT, - NULL_); - if (StatusBAD(*status)) return; - - *data_type = (Int32) dataTypeT; - *num_elements = (Int32) numElementsT; - return; -} - -/****************************************************************************** -* CDF_attr_put. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_attr_put__,cdf_attr_put_,cdf_attr_put,CDF_ATTR_PUT) -(id, attr_num, entry_num, data_type, num_elems, value, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: gEntry/rEntry number. */ -Int32 *data_type; /* In: Data type. */ -Int32 *num_elems; /* In: Number of elements. */ -void *value; /* In: Value. - VMS: If character data type, could - be passed by reference or - descriptor. */ -Int32 *status; /* Out: CDF status code. */ -{ - long scope; - long attrNumT = (long) (*attr_num - 1); - long entryNumT = (long) (*entry_num - 1); - long dataTypeT = (long) *data_type; - long numElemsT = (long) *num_elems; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (SELECT_, BOO(GLOBALscope(scope), - gENTRY_,rENTRY_), entryNumT, - PUT_, BOO(GLOBALscope(scope), - gENTRY_DATA_,rENTRY_DATA_), - dataTypeT, numElemsT, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataTypeT), - DESCRtoREF(value),value), -#else - value, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_put_attr_gentry. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_put_attr_gentry__, - cdf_put_attr_gentry_, - cdf_put_attr_gentry, - CDF_PUT_ATTR_GENTRY) -(id, attr_num, entry_num, data_type, num_elems, value, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: gEntry number. */ -Int32 *data_type; /* In: Data type. */ -Int32 *num_elems; /* In: Number of elements. */ -void *value; /* In: Value. - VMS: If character data type, could - be passed by reference or - descriptor. */ -Int32 *status; /* Out: CDF status code. */ -{ - long scope; - long attrNumT = (long) (*attr_num - 1); - long entryNumT = (long) (*entry_num - 1); - long dataTypeT = (long) *data_type; - long numElemsT = (long) *num_elems; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - - if (!GLOBALscope(scope)) { - *status = (Int32) ILLEGAL_FOR_SCOPE; - return; - } - - *status = (Int32) CDFlib (SELECT_, gENTRY_, entryNumT, - PUT_, gENTRY_DATA_, dataTypeT, numElemsT, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataTypeT), - DESCRtoREF(value),value), -#else - value, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_put_attr_rentry. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_put_attr_rentry__, - cdf_put_attr_rentry_, - cdf_put_attr_rentry, - CDF_PUT_ATTR_RENTRY) -(id, attr_num, entry_num, data_type, num_elems, value, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: rEntry number. */ -Int32 *data_type; /* In: Data type. */ -Int32 *num_elems; /* In: Number of elements. */ -void *value; /* In: Value. - VMS: If character data type, could - be passed by reference or - descriptor. */ -Int32 *status; /* Out: CDF status code. */ -{ - long scope; - long attrNumT = (long) (*attr_num - 1); - long entryNumT = (long) (*entry_num - 1); - long dataTypeT = (long) *data_type; - long numElemsT = (long) *num_elems; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - - if (GLOBALscope(scope)) { - *status = (Int32) ILLEGAL_FOR_SCOPE; - return; - } - - *status = (Int32) CDFlib (SELECT_, rENTRY_, entryNumT, - PUT_, rENTRY_DATA_, dataTypeT, numElemsT, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataTypeT), - DESCRtoREF(value),value), -#else - value, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_put_attr_zentry. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_put_attr_zentry__, - cdf_put_attr_zentry_, - cdf_put_attr_zentry, - CDF_PUT_ATTR_ZENTRY) -(id, attr_num, entry_num, data_type, num_elems, value, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: zEntry number. */ -Int32 *data_type; /* In: Data type. */ -Int32 *num_elems; /* In: Number of elements. */ -void *value; /* In: Value. - VMS: If character data type, could - be passed by reference or - descriptor. */ -Int32 *status; /* Out: CDF status code. */ -{ - long scope; - long attrNumT = (long) (*attr_num - 1); - long entryNumT = (long) (*entry_num - 1); - long dataTypeT = (long) *data_type; - long numElemsT = (long) *num_elems; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - - if (GLOBALscope(scope)) { - *status = (Int32) ILLEGAL_FOR_SCOPE; - return; - } - - *status = (Int32) CDFlib (SELECT_, zENTRY_, entryNumT, - PUT_, zENTRY_DATA_, dataTypeT, numElemsT, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataTypeT), - DESCRtoREF(value),value), -#else - value, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_attr_get. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_attr_get__, cdf_attr_get_, cdf_attr_get, CDF_ATTR_GET) -(id, attr_num, entry_num, value, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: gEntry/rEntry number. */ -void *value; /* Out: Value. - VMS: Could be passed out by reference - or descriptor if character data - type. */ -Int32 *status; /* Out: CDF status code. */ -{ - long dataType, scope; - long attrNumT = (long) (*attr_num - 1); - long entryNumT = (long) (*entry_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (SELECT_, BOO(GLOBALscope(scope), - gENTRY_,rENTRY_), entryNumT, - GET_, BOO(GLOBALscope(scope), - gENTRY_DATATYPE_, - rENTRY_DATATYPE_), &dataType, - NULL_); - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (GET_, BOO(GLOBALscope(scope), - gENTRY_DATA_,rENTRY_DATA_), -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(value),value), -#else - value, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_get_attr_gentry. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_gentry__, - cdf_get_attr_gentry_, - cdf_get_attr_gentry, - CDF_get_ATTR_GENTRY) -(id, attr_num, entry_num, value, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: gEntry number. */ -void *value; /* Out: Value. - VMS: Could be passed out by reference - or descriptor if character data - type. */ -Int32 *status; /* Out: CDF status code. */ -{ - long dataType, scope; - long attrNumT = (long) (*attr_num - 1); - long entryNumT = (long) (*entry_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - - if (!GLOBALscope(scope)) { - *status = (Int32) ILLEGAL_FOR_SCOPE; - return; - } - - *status = (Int32) CDFlib (SELECT_, gENTRY_, entryNumT, - GET_, gENTRY_DATATYPE_, &dataType, - NULL_); - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (GET_, gENTRY_DATA_, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(value),value), -#else - value, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_get_attr_rentry. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_rentry__, - cdf_get_attr_rentry_, - cdf_get_attr_rentry, - CDF_get_ATTR_RENTRY) -(id, attr_num, entry_num, value, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: rEntry number. */ -void *value; /* Out: Value. - VMS: Could be passed out by reference - or descriptor if character data - type. */ -Int32 *status; /* Out: CDF status code. */ -{ - long dataType, scope; - long attrNumT = (long) (*attr_num - 1); - long entryNumT = (long) (*entry_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - - if (GLOBALscope(scope)) { - *status = (Int32) ILLEGAL_FOR_SCOPE; - return; - } - - *status = (Int32) CDFlib (SELECT_, rENTRY_, entryNumT, - GET_, rENTRY_DATATYPE_, &dataType, - NULL_); - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (GET_, rENTRY_DATA_, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(value),value), -#else - value, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_get_attr_zentry. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_zentry__, - cdf_get_attr_zentry_, - cdf_get_attr_zentry, - CDF_get_ATTR_ZENTRY) -(id, attr_num, entry_num, value, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: zEntry number. */ -void *value; /* Out: Value. - VMS: Could be passed out by reference - or descriptor if character data - type. */ -Int32 *status; /* Out: CDF status code. */ -{ - long dataType, scope; - long attrNumT = (long) (*attr_num - 1); - long entryNumT = (long) (*entry_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, attrNumT, - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - - if (GLOBALscope(scope)) { - *status = (Int32) ILLEGAL_FOR_SCOPE; - return; - } - - *status = (Int32) CDFlib (SELECT_, zENTRY_, entryNumT, - GET_, zENTRY_DATATYPE_, &dataType, - NULL_); - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (GET_, zENTRY_DATA_, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(value),value), -#else - value, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_var_create. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_var_create__,cdf_var_create_,cdf_var_create,CDF_VAR_CREATE) -(id, var_name, data_type, num_elems, rec_variance, dim_variances, -var_num, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *var_name; /* In: rVariable name. */ -Int32 *data_type; /* In: Data type. */ -Int32 *num_elems; /* In: Number of elements of data_type. */ -Int32 *rec_variance; /* In: Record variance. */ -Int32 dim_variances[]; /* In: Dimension variances. */ -Int32 *var_num; /* Out: rVariable number. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "var_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - long varNumT, dimVarysT[CDF_MAX_DIMS], numDims; - int dimN; - long dataTypeT = (long) *data_type; - long numElemsT = (long) *num_elems; - long recVaryT = (long) *rec_variance; - int LFS = FALSE; - struct CDFstruct *CDF; - - CDF = (struct CDFstruct *)Int32ToCDFid(*id); - if (isLFS(CDF)) LFS = TRUE; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, rVARs_NUMDIMS_, &numDims, - NULL_); - if (StatusBAD(*status)) return; - - for (dimN = 0; dimN < (int) numDims; dimN++) { - dimVarysT[dimN] = (long) dim_variances[dimN]; - } - - *status = (Int32) CDFlib (CREATE_, rVAR_, -#if defined(Fif_DESCR) - DESCRtoREFnul(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(var_name, - Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif - dataTypeT, numElemsT, recVaryT, - dimVarysT, &varNumT, - NULL_); - FreeStrings (ssh); - if (StatusBAD(*status)) return; - - *var_num = (Int32) (varNumT + 1); - return; -} - -/****************************************************************************** -* CDF_create_zvar. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_create_zvar__, - cdf_create_zvar_, - cdf_create_zvar, - CDF_CREATE_ZVAR) -(id, var_name, data_type, num_elems, num_dims, dim_sizes, rec_variance, -dim_variances, var_num, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *var_name; /* In: zVariable name. */ -Int32 *data_type; /* In: Data type. */ -Int32 *num_elems; /* In: Number of elements of data_type. */ -Int32 *num_dims; /* In: Number of dimension. */ -Int32 dim_sizes[]; /* In: Dimension sizes. */ -Int32 *rec_variance; /* In: Record variance. */ -Int32 dim_variances[]; /* In: Dimension variances. */ -Int32 *var_num; /* Out: zVariable number. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "var_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - long varNumT, dimVarysT[CDF_MAX_DIMS], dimSizesT[CDF_MAX_DIMS], numDims; - int dimN; - long dataTypeT = (long) *data_type; - long numElemsT = (long) *num_elems; - long recVaryT = (long) *rec_variance; - int LFS = FALSE; - struct CDFstruct *CDF; - - CDF = (struct CDFstruct *)Int32ToCDFid(*id); - if (isLFS(CDF)) LFS = TRUE; - - numDims = (long) *num_dims; - - for (dimN = 0; dimN < (int) numDims; dimN++) { - dimSizesT[dimN] = (long) dim_sizes[dimN]; - dimVarysT[dimN] = (long) dim_variances[dimN]; - } - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CREATE_, zVAR_, -#if defined(Fif_DESCR) - DESCRtoREFnul(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(var_name, - Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif - dataTypeT, numElemsT, numDims, - dimSizesT, recVaryT, - dimVarysT, &varNumT, - NULL_); - FreeStrings (ssh); - if (StatusBAD(*status)) return; - - *var_num = (Int32) (varNumT + 1); - return; -} - -/****************************************************************************** -* CDF_var_num. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_var_num__,cdf_var_num_,cdf_var_num,CDF_VAR_NUM) -(id, var_name Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *var_name; /* In: Variable name. */ -Fif_GHOSTDEF(len) /* Invisible length of "var_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - CDFstatus status; - long varNumT; - int LFS = FALSE; - struct CDFstruct *CDF; - - CDF = (struct CDFstruct *)Int32ToCDFid(*id); - if (isLFS(CDF)) LFS = TRUE; - - status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, rVAR_NUMBER_, -#if defined(Fif_DESCR) - DESCRtoREFnul(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(var_name,Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif - &varNumT, - NULL_); - if (!StatusOK(status)) { - status = (Int32) CDFlib (GET_, zVAR_NUMBER_, -#if defined(Fif_DESCR) - DESCRtoREFnul(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(var_name,Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif - &varNumT, - NULL_); - } - - FreeStrings (ssh); - - if (StatusOK(status)) - return ((Int32) (varNumT + 1)); - else - return ((Int32) status); -} - -/****************************************************************************** -* CDF_get_var_num. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_var_num__, - cdf_get_var_num_, - cdf_get_var_num, - CDF_GET_VAR_NUM) -(id, var_name Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *var_name; /* In: Variable name. */ -Fif_GHOSTDEF(len) /* Invisible length of "var_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - CDFstatus status; - long varNumT; - int LFS = FALSE; - struct CDFstruct *CDF; - - CDF = (struct CDFstruct *)Int32ToCDFid(*id); - if (isLFS(CDF)) LFS = TRUE; - - status = CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, rVAR_NUMBER_, -#if defined(Fif_DESCR) - DESCRtoREFnul(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(var_name,Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif - &varNumT, - NULL_); - if (!StatusOK(status)) { - status = CDFlib (GET_, zVAR_NUMBER_, -#if defined(Fif_DESCR) - DESCRtoREFnul(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(var_name,Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif - &varNumT, - NULL_); - } - - FreeStrings (ssh); - - if (StatusOK(status)) - return (Int32) (varNumT + 1); - else - return ((Int32) status); -} - -/****************************************************************************** -* CDF_var_rename. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_var_rename__,cdf_var_rename_,cdf_var_rename,CDF_VAR_RENAME) -(id, var_num, var_name, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: rVariable number. */ -void *var_name; /* In: New variable name. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "var_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - long varNumT = (long) (*var_num - 1); - int LFS = FALSE; - struct CDFstruct *CDF; - - CDF = (struct CDFstruct *)Int32ToCDFid(*id); - if (isLFS(CDF)) LFS = TRUE; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - rVAR_, varNumT, - PUT_, rVAR_NAME_, -#if defined(Fif_DESCR) - DESCRtoREFnul(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(var_name, - Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif - NULL_); - FreeStrings (ssh); - return; -} - -/****************************************************************************** -* CDF_rename_zvar. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_rename_zvar__, - cdf_rename_zvar_, - cdf_rename_zvar, - CDF_RENAME_ZVAR) -(id, var_num, var_name, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: zVariable number. */ -void *var_name; /* In: New variable name. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "var_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - long varNumT = (long) (*var_num - 1); - int LFS = FALSE; - struct CDFstruct *CDF; - - CDF = (struct CDFstruct *)Int32ToCDFid(*id); - if (isLFS(CDF)) LFS = TRUE; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, varNumT, - PUT_, zVAR_NAME_, -#if defined(Fif_DESCR) - DESCRtoREFnul(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(var_name, - Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif - NULL_); - FreeStrings (ssh); - return; -} - -/****************************************************************************** -* CDF_var_inquire. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_var_inquire__, - cdf_var_inquire_, - cdf_var_inquire, - CDF_VAR_INQUIRE) -(id, var_num, var_name, data_type, num_elements, rec_variance, -dim_variances, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: rVariable number. */ -void *var_name; /* Out: rVariable name. */ -Int32 *data_type; /* Out: Data type. */ -Int32 *num_elements; /* Out: Number of elements. */ -Int32 *rec_variance; /* Out: Record variance. */ -Int32 dim_variances[]; /* Out: Dimension variances. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "var_name" - (generated by FORTRAN compiler). */ -{ - char varNameT[CDF_VAR_NAME_LEN256]; - long dataTypeT, numElemsT, recVaryT, dimVarysT[CDF_MAX_DIMS], numDims; - int dimN; - long varNumT = (long) (*var_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, rVARs_NUMDIMS_, &numDims, - NULL_); - if (StatusBAD(*status)) { - return; - } - - *status = (Int32) CDFlib (SELECT_, rVAR_, varNumT, - GET_, rVAR_NAME_, varNameT, - rVAR_DATATYPE_, &dataTypeT, - rVAR_NUMELEMS_, &numElemsT, - rVAR_RECVARY_, &recVaryT, - rVAR_DIMVARYS_, dimVarysT, - NULL_); - if (StatusBAD(*status)) { - return; - } - -#if defined(Fif_GHOSTLEN) - CtoFORTstring (varNameT, var_name, Fif_GHOSTUSE(len)); -#else - CtoFORTstring (varNameT, var_name, CDF_VAR_NAME_LEN256); -#endif - *data_type = (Int32) dataTypeT; - *num_elements = (Int32) numElemsT; - *rec_variance = (Int32) recVaryT; - for (dimN = 0; dimN < (int) numDims; dimN++) { - dim_variances[dimN] = (Int32) dimVarysT[dimN]; - } - return; -} - -/****************************************************************************** -* CDF_inquire_zvar. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_inquire_zvar__, - cdf_inquire_zvar_, - cdf_inquire_zvar, - CDF_INQUIRE_ZVAR) -(id, var_num, var_name, data_type, num_elements, num_dims, dim_sizes, -rec_variance, dim_variances, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: zVariable number. */ -void *var_name; /* Out: zVariable name. */ -Int32 *data_type; /* Out: Data type. */ -Int32 *num_elements; /* Out: Number of elements. */ -Int32 *num_dims; /* Out: Number of dimension. */ -Int32 dim_sizes[]; /* Out: Dimension sizes. */ -Int32 *rec_variance; /* Out: Record variance. */ -Int32 dim_variances[]; /* Out: Dimension variances. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "var_name" - (generated by FORTRAN compiler). */ -{ - char varNameT[CDF_VAR_NAME_LEN256]; - long dataTypeT, numElemsT, recVaryT, dimVarysT[CDF_MAX_DIMS]; - int dimN; - long numDimsT, dimSizesT[CDF_MAX_DIMS]; - long varNumT = (long) (*var_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, varNumT, - GET_, zVAR_NAME_, varNameT, - zVAR_DATATYPE_, &dataTypeT, - zVAR_NUMELEMS_, &numElemsT, - zVAR_NUMDIMS_, &numDimsT, - zVAR_DIMSIZES_, dimSizesT, - zVAR_RECVARY_, &recVaryT, - zVAR_DIMVARYS_, dimVarysT, - NULL_); - if (StatusBAD(*status)) return; - -#if defined(Fif_GHOSTLEN) - CtoFORTstring (varNameT, var_name, Fif_GHOSTUSE(len)); -#else - CtoFORTstring (varNameT, var_name, CDF_VAR_NAME_LEN256); -#endif - *data_type = (Int32) dataTypeT; - *num_elements = (Int32) numElemsT; - *num_dims = (Int32) numDimsT; - *rec_variance = (Int32) recVaryT; - for (dimN = 0; dimN < (int) numDimsT; dimN++) { - dim_variances[dimN] = (Int32) dimVarysT[dimN]; - dim_sizes[dimN] = (Int32) dimSizesT[dimN]; - } - return; -} - -/****************************************************************************** -* CDF_var_put. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_var_put__,cdf_var_put_,cdf_var_put,CDF_VAR_PUT) -(id, var_num, record_num, indices, value, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: rVariable number. */ -Int32 *record_num; /* In: Record number. */ -Int32 indices[]; /* In: Dimension indices. */ -void *value; /* In: Value. - VMS: If character data type, could - be passed by reference or by - descriptor. */ -Int32 *status; /* Out: CDF status code. */ -{ - int dimN; - long indicesT[CDF_MAX_DIMS], numDims, dataType; - long varNumT = (long) (*var_num - 1); - long recNumT = (long) (*record_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - rVAR_, varNumT, - GET_, rVARs_NUMDIMS_, &numDims, - rVAR_DATATYPE_, &dataType, - NULL_); - if (StatusBAD(*status)) return; - - for (dimN = 0; dimN < (int) numDims; dimN++) { - indicesT[dimN] = (long) (indices[dimN] - 1); - } - - *status = (Int32) CDFlib (SELECT_, rVARs_RECNUMBER_, recNumT, - rVARs_DIMINDICES_, indicesT, - PUT_, rVAR_DATA_, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(value),value), -#else - value, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_put_zvar_data. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_put_zvar_data__, - cdf_put_zvar_data_, - cdf_put_zvar_data, - CDF_PUT_ZVAR_DATA) -(id, var_num, record_num, indices, value, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: zVariable number. */ -Int32 *record_num; /* In: Record number. */ -Int32 indices[]; /* In: Dimension indices. */ -void *value; /* In: Value. - VMS: If character data type, could - be passed by reference or by - descriptor. */ -Int32 *status; /* Out: CDF status code. */ -{ - int dimN; - long indicesT[CDF_MAX_DIMS], numDims, dataType; - long varNumT = (long) (*var_num - 1); - long recNumT = (long) (*record_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, varNumT, - GET_, zVAR_NUMDIMS_, &numDims, - zVAR_DATATYPE_, &dataType, - NULL_); - if (StatusBAD(*status)) return; - - for (dimN = 0; dimN < (int) numDims; dimN++) { - indicesT[dimN] = (long) (indices[dimN] - 1); - } - - *status = (Int32) CDFlib (SELECT_, zVAR_RECNUMBER_, recNumT, - zVAR_DIMINDICES_, indicesT, - PUT_, zVAR_DATA_, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(value),value), -#else - value, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_var_get. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_var_get__,cdf_var_get_,cdf_var_get,CDF_VAR_GET) -(id, var_num, record_num, indices, value, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: rVariable number. */ -Int32 *record_num; /* In: Record number. */ -Int32 indices[]; /* In: Dimension indices. */ -void *value; /* In: Value. - VMS: If character data type, could - be passed by reference or by - descriptor. */ -Int32 *status; /* Out: CDF status code. */ -{ - long indicesT[CDF_MAX_DIMS], numDims, dataType; - int dimN; - long varNumT = (long) (*var_num - 1); - long recNumT = (long) (*record_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - rVAR_, varNumT, - GET_, rVARs_NUMDIMS_, &numDims, - rVAR_DATATYPE_, &dataType, - NULL_); - if (StatusBAD(*status)) return; - - for (dimN = 0; dimN < (int) numDims; dimN++) { - indicesT[dimN] = (long) (indices[dimN] - 1); - } - - *status = (Int32) CDFlib (SELECT_, rVARs_RECNUMBER_, recNumT, - rVARs_DIMINDICES_, indicesT, - GET_, rVAR_DATA_, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(value),value), -#else - value, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_get_zvar_data. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_data__, - cdf_get_zvar_data_, - cdf_get_zvar_data, - CDF_get_ZVAR_DATA) -(id, var_num, record_num, indices, value, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: zVariable number. */ -Int32 *record_num; /* In: Record number. */ -Int32 indices[]; /* In: Dimension indices. */ -void *value; /* In: Value. - VMS: If character data type, could - be passed by reference or by - descriptor. */ -Int32 *status; /* Out: CDF status code. */ -{ - long indicesT[CDF_MAX_DIMS], numDims, dataType; - int dimN; - long varNumT = (long) (*var_num - 1); - long recNumT = (long) (*record_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, varNumT, - GET_, zVAR_NUMDIMS_, &numDims, - zVAR_DATATYPE_, &dataType, - NULL_); - if (StatusBAD(*status)) return; - - for (dimN = 0; dimN < (int) numDims; dimN++) { - indicesT[dimN] = (long) (indices[dimN] - 1); - } - - *status = (Int32) CDFlib (SELECT_, zVAR_RECNUMBER_, recNumT, - zVAR_DIMINDICES_, indicesT, - GET_, zVAR_DATA_, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(value),value), -#else - value, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_var_hyper_put. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_var_hyper_put__, - cdf_var_hyper_put_, - cdf_var_hyper_put, - CDF_VAR_HYPER_PUT) -(id, var_num, rec_start, rec_count, rec_int, indices, counts, -intervals, buffer, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: rVariable number. */ -Int32 *rec_start; /* In: Starting record number. */ -Int32 *rec_count; /* In: Record count. */ -Int32 *rec_int; /* In: Record interval. */ -Int32 indices[]; /* In: Dimension indices. */ -Int32 counts[]; /* In: Dimension counts. */ -Int32 intervals[]; /* In: Dimension intervals. */ -void *buffer; /* In: Values. - VMS: If character data type, could - be passed by reference or - descriptor. */ -Int32 *status; /* Out: CDF status code. */ -{ - int dimN; - long indicesT[CDF_MAX_DIMS], countsT[CDF_MAX_DIMS], intervalsT[CDF_MAX_DIMS], - numDims, dataType; - long varNumT = (long) (*var_num - 1); - long recStartT = (long) (*rec_start - 1); - long recCountT = (long) *rec_count; - long recIntervalT = (long) *rec_int; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - rVAR_, varNumT, - GET_, rVARs_NUMDIMS_, &numDims, - rVAR_DATATYPE_, &dataType, - NULL_); - if (StatusBAD(*status)) return; - - for (dimN = 0; dimN < (int) numDims; dimN++) { - indicesT[dimN] = (long) (indices[dimN] - 1); - countsT[dimN] = (long) counts[dimN]; - intervalsT[dimN] = (long) intervals[dimN]; - } - - *status = (Int32) CDFlib (SELECT_, rVARs_RECNUMBER_, recStartT, - rVARs_RECCOUNT_, recCountT, - rVARs_RECINTERVAL_, recIntervalT, - rVARs_DIMINDICES_, indicesT, - rVARs_DIMCOUNTS_, countsT, - rVARs_DIMINTERVALS_, intervalsT, - PUT_, rVAR_HYPERDATA_, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(buffer),buffer), -#else - buffer, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_hyper_put_zvar_data. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_hyper_put_zvar_data__, - cdf_hyper_put_zvar_data_, - cdf_hyper_put_zvar_data, - CDF_HYPER_PUT_ZVAR_DATA) -(id, var_num, rec_start, rec_count, rec_int, indices, counts, -intervals, buffer, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: zVariable number. */ -Int32 *rec_start; /* In: Starting record number. */ -Int32 *rec_count; /* In: Record count. */ -Int32 *rec_int; /* In: Record interval. */ -Int32 indices[]; /* In: Dimension indices. */ -Int32 counts[]; /* In: Dimension counts. */ -Int32 intervals[]; /* In: Dimension intervals. */ -void *buffer; /* In: Values. - VMS: If character data type, could - be passed by reference or - descriptor. */ -Int32 *status; /* Out: CDF status code. */ -{ - int dimN; - long indicesT[CDF_MAX_DIMS], countsT[CDF_MAX_DIMS], intervalsT[CDF_MAX_DIMS], - numDims, dataType; - long varNumT = (long) (*var_num - 1); - long recStartT = (long) (*rec_start - 1); - long recCountT = (long) *rec_count; - long recIntervalT = (long) *rec_int; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, varNumT, - GET_, zVAR_NUMDIMS_, &numDims, - zVAR_DATATYPE_, &dataType, - NULL_); - if (StatusBAD(*status)) return; - - for (dimN = 0; dimN < (int) numDims; dimN++) { - indicesT[dimN] = (long) (indices[dimN] - 1); - countsT[dimN] = (long) counts[dimN]; - intervalsT[dimN] = (long) intervals[dimN]; - } - - *status = (Int32) CDFlib (SELECT_, zVAR_RECNUMBER_, recStartT, - zVAR_RECCOUNT_, recCountT, - zVAR_RECINTERVAL_, recIntervalT, - zVAR_DIMINDICES_, indicesT, - zVAR_DIMCOUNTS_, countsT, - zVAR_DIMINTERVALS_, intervalsT, - PUT_, zVAR_HYPERDATA_, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(buffer),buffer), -#else - buffer, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_var_hyper_get. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_var_hyper_get__, - cdf_var_hyper_get_, - cdf_var_hyper_get, - CDF_VAR_HYPER_GET) -(id, var_num, rec_start, rec_count, rec_int, indices, counts, -intervals, buffer, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: rVariable number. */ -Int32 *rec_start; /* In: Starting record number. */ -Int32 *rec_count; /* In: Record count. */ -Int32 *rec_int; /* In: Record interval. */ -Int32 indices[]; /* In: Dimension indices. */ -Int32 counts[]; /* In: Dimension counts. */ -Int32 intervals[]; /* In: Dimension intervals. */ -void *buffer; /* In: Values. - VMS: If character data type, could - be passed by reference or - descriptor. */ -Int32 *status; /* Out: CDF status code. */ -{ - int dimN; - long indicesT[CDF_MAX_DIMS], countsT[CDF_MAX_DIMS], intervalsT[CDF_MAX_DIMS], - numDims, dataType; - long varNumT = (long) (*var_num - 1); - long recStartT = (long) (*rec_start - 1); - long recCountT = (long) *rec_count; - long recIntervalT = (long) *rec_int; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - rVAR_, varNumT, - GET_, rVARs_NUMDIMS_, &numDims, - rVAR_DATATYPE_, &dataType, - NULL_); - if (StatusBAD(*status)) return; - - for (dimN = 0; dimN < (int) numDims; dimN++) { - indicesT[dimN] = (long) (indices[dimN] - 1); - countsT[dimN] = (long) counts[dimN]; - intervalsT[dimN] = (long) intervals[dimN]; - } - - *status = (Int32) CDFlib (SELECT_, rVARs_RECNUMBER_, recStartT, - rVARs_RECCOUNT_, recCountT, - rVARs_RECINTERVAL_, recIntervalT, - rVARs_DIMINDICES_, indicesT, - rVARs_DIMCOUNTS_, countsT, - rVARs_DIMINTERVALS_, intervalsT, - GET_, rVAR_HYPERDATA_, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(buffer),buffer), -#else - buffer, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_hyper_get_zvar_data. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_hyper_get_zvar_data__, - cdf_hyper_get_zvar_data_, - cdf_hyper_get_zvar_data, - CDF_HYPER_GET_ZVAR_DATA) -(id, var_num, rec_start, rec_count, rec_int, indices, counts, -intervals, buffer, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: zVariable number. */ -Int32 *rec_start; /* In: Starting record number. */ -Int32 *rec_count; /* In: Record count. */ -Int32 *rec_int; /* In: Record interval. */ -Int32 indices[]; /* In: Dimension indices. */ -Int32 counts[]; /* In: Dimension counts. */ -Int32 intervals[]; /* In: Dimension intervals. */ -void *buffer; /* In: Values. - VMS: If character data type, could - be passed by reference or - descriptor. */ -Int32 *status; /* Out: CDF status code. */ -{ - int dimN; - long indicesT[CDF_MAX_DIMS], countsT[CDF_MAX_DIMS], intervalsT[CDF_MAX_DIMS], - numDims, dataType; - long varNumT = (long) (*var_num - 1); - long recStartT = (long) (*rec_start - 1); - long recCountT = (long) *rec_count; - long recIntervalT = (long) *rec_int; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, varNumT, - GET_, zVAR_NUMDIMS_, &numDims, - zVAR_DATATYPE_, &dataType, - NULL_); - if (StatusBAD(*status)) return; - - for (dimN = 0; dimN < (int) numDims; dimN++) { - indicesT[dimN] = (long) (indices[dimN] - 1); - countsT[dimN] = (long) counts[dimN]; - intervalsT[dimN] = (long) intervals[dimN]; - } - - *status = (Int32) CDFlib (SELECT_, zVAR_RECNUMBER_, recStartT, - zVAR_RECCOUNT_, recCountT, - zVAR_RECINTERVAL_, recIntervalT, - zVAR_DIMINDICES_, indicesT, - zVAR_DIMCOUNTS_, countsT, - zVAR_DIMINTERVALS_, intervalsT, - GET_, zVAR_HYPERDATA_, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(buffer),buffer), -#else - buffer, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_var_close. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_var_close__,cdf_var_close_,cdf_var_close,CDF_VAR_CLOSE) -(id, var_num, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: rVariable number. */ -Int32 *status; /* Out: CDF status code. */ -{ - long varNumT = (long) (*var_num - 1); - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - rVAR_, varNumT, - CLOSE_, rVAR_, - NULL_); - return; -} - -/****************************************************************************** -* CDF_close_zvar. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_close_zvar__,cdf_close_zvar_,cdf_close_zvar,CDF_CLOSE_ZVAR) -(id, var_num, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: zVariable number. */ -Int32 *status; /* Out: CDF status code. */ -{ - long varNumT = (long) (*var_num - 1); - CDFstatus statusT; - - statusT = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, varNumT, - CLOSE_, zVAR_, - NULL_); - return; -} - -/****************************************************************************** -* CDF_error. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_error__,cdf_error_,cdf_error,CDF_ERROR) -(statusI, text, statusO Fif_GHOSTARG(text_len)) -Int32 *statusI; /* In: CDF status code. */ -void *text; /* Out: Character string to receive - explanation. */ -Int32 *statusO; /* Out: CDF operation status. */ -Fif_GHOSTDEF(text_len) /* Invisible length of "text" - (generated by FORTRAN compiler). */ -{ - char statusTextT[CDF_ERRTEXT_LEN+1]; - *statusO = (Int32) CDFlib (SELECT_, CDF_STATUS_, (CDFstatus) *statusI, - GET_, STATUS_TEXT_, statusTextT, - NULL_); - if (StatusOK(*statusO)) -#if defined(Fif_GHOSTLEN) - CtoFORTstring (statusTextT, text, Fif_GHOSTUSE(text_len)); -#else - CtoFORTstring (statusTextT, text, CDF_STATUSTEXT_LEN); -#endif - else -#if defined(Fif_GHOSTLEN) - CtoFORTstring ("Unknown CDF status code", text, Fif_GHOSTUSE(text_len)); -#else - CtoFORTstring ("Unknown CDF status code", text, CDF_STATUSTEXT_LEN); -#endif - return; -} - -/****************************************************************************** -* CDF_get_status_text. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_status_text__, - cdf_get_status_text_, - cdf_get_status_text, - CDF_GET_STATUS_TEXT) -(statusI, text, statusO Fif_GHOSTARG(text_len)) -Int32 *statusI; /* In: CDF status code. */ -void *text; /* Out: Character string to receive - explanation. */ -Int32 *statusO; /* Out: CDF operation status. */ -Fif_GHOSTDEF(text_len) /* Invisible length of "text" - (generated by FORTRAN compiler). */ -{ - char statusTextT[CDF_ERRTEXT_LEN+1]; - *statusO = (Int32) CDFlib (SELECT_, CDF_STATUS_, (CDFstatus) *statusI, - GET_, STATUS_TEXT_, statusTextT, - NULL_); - if (StatusOK(*statusO)) -#if defined(Fif_GHOSTLEN) - CtoFORTstring (statusTextT, text, Fif_GHOSTUSE(text_len)); -#else - CtoFORTstring (statusTextT, text, CDF_STATUSTEXT_LEN); -#endif - else -#if defined(Fif_GHOSTLEN) - CtoFORTstring ("Unknown CDF status code", text, Fif_GHOSTUSE(text_len)); -#else - CtoFORTstring ("Unknown CDF status code", text, CDF_STATUSTEXT_LEN); -#endif - return; -} - -/****************************************************************************** -* CDF_getrVarsRecordData. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_getrvarsrecorddata__, - cdf_getrvarsrecorddata_, - cdf_getrvarsrecorddata, - CDF_GETRVARSRECORDDATA) -(id, num_vars, varNums, rec_num, buffptr, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *num_vars; /* In: Number of rVariables. */ -Int32 varNums[]; /* In: rVariable numbers. */ -Int32 *rec_num; /* In: Record number. */ -void *buffptr; /* In: Pointer for input data */ -Int32 *status; /* Out: CDF status code. */ -{ - long num_varsT = (long) *num_vars; - long recNumT = (long) (*rec_num - 1); - long *varNumsT; - int i; - - if (*num_vars < 1) { - *status = (Int32) CDF_OK; - return; - } - - varNumsT = cdf_AllocateMemory ((size_t)*num_vars*sizeof(long), NULL); - if (varNumsT == NULL) { - *status = BAD_MALLOC; - return; - } - - for (i = 0; i < *num_vars; i++) varNumsT[i] = (long) varNums[i] - 1; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - NULL_); - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (SELECT_, rVARs_RECNUMBER_, recNumT, - GET_, rVARs_RECDATA_, num_varsT, varNumsT, buffptr, - NULL_); - cdf_FreeMemory (varNumsT, NULL); - return; - -} - -/****************************************************************************** -* CDF_getzVarsRecordData. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_getzvarsrecorddata__, - cdf_getzvarsrecorddata_, - cdf_getzvarsrecorddata, - CDF_GETZVARSRECORDDATA) -(id, num_vars, varNums, rec_num, buffptr, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *num_vars; /* In: Number of zVariables. */ -Int32 varNums[]; /* In: zVariable numbers. */ -Int32 *rec_num; /* In: Record number. */ -void *buffptr; /* In: Pointer for input data */ -Int32 *status; /* Out: CDF status code. */ -{ - long num_varsT = (long) *num_vars; - long recNumT = (long) (*rec_num - 1); - long *varNumsT; - int i; - - if (*num_vars < 1) { - *status = (Int32) CDF_OK; - return; - } - - varNumsT = cdf_AllocateMemory ((size_t)*num_vars*sizeof(long), NULL); - if (varNumsT == NULL) { - *status = BAD_MALLOC; - return; - } - - for (i = 0; i < *num_vars; i++) varNumsT[i] = (long) varNums[i] - 1; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - NULL_); - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (SELECT_, zVARs_RECNUMBER_, recNumT, - GET_, zVARs_RECDATA_, num_varsT, varNumsT, buffptr, - NULL_); - cdf_FreeMemory (varNumsT, NULL); - - return; - -} - -/****************************************************************************** -* CDF_putrVarsRecordData. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_putrvarsrecorddata__, - cdf_putrvarsrecorddata_, - cdf_putrvarsrecorddata, - CDF_PUTRVARSRECORDDATA) -(id, num_vars, varNums, rec_num, buffptr, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *num_vars; /* In: Number of rVariables. */ -Int32 varNums[]; /* In: rVariable numbers. */ -Int32 *rec_num; /* In: Record number. */ -void *buffptr; /* In: Pointer for output data */ -Int32 *status; /* Out: CDF status code. */ -{ - long num_varsT = (long) *num_vars; - long recNumT = (long) (*rec_num - 1); - long *varNumsT; - int i; - - if (*num_vars < 1) { - *status = (Int32) CDF_OK; - return; - } - - varNumsT = cdf_AllocateMemory ((size_t)*num_vars*sizeof(long), NULL); - if (varNumsT == NULL) { - *status = BAD_MALLOC; - return; - } - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - NULL_); - if (StatusBAD(*status)) return; - - for (i = 0; i < *num_vars; i++) varNumsT[i] = (long) varNums[i] - 1; - - *status = (Int32) CDFlib (SELECT_, rVARs_RECNUMBER_, recNumT, - PUT_, rVARs_RECDATA_, num_varsT, varNumsT, buffptr, - NULL_); - cdf_FreeMemory (varNumsT, NULL); - return; -} - -/****************************************************************************** -* CDF_putzVarsRecordData. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_putzvarsrecorddata__, - cdf_putzvarsrecorddata_, - cdf_putzvarsrecorddata, - CDF_PUTZVARSRECORDDATA) -(id, num_vars, varNums, rec_num, buffptr, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *num_vars; /* In: Number of zVariables. */ -Int32 varNums[]; /* In: zVariable numbers. */ -Int32 *rec_num; /* In: Record number. */ -void *buffptr; /* In: Pointer for output data */ -Int32 *status; /* Out: CDF status code. */ -{ - long num_varsT = (long) *num_vars; - long recNumT = (long) (*rec_num - 1); - long *varNumsT; - int i; - - if (*num_vars < 1) { - *status = (Int32) CDF_OK; - return; - } - - varNumsT = cdf_AllocateMemory ((size_t)*num_vars*sizeof(long), NULL); - if (varNumsT == NULL) { - *status = BAD_MALLOC; - return; - } - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - NULL_); - if (StatusBAD(*status)) return; - - for (i = 0; i < *num_vars; i++) varNumsT[i] = (long) varNums[i] - 1; - - *status = (Int32) CDFlib (SELECT_, zVARs_RECNUMBER_, recNumT, - PUT_, zVARs_RECDATA_, num_varsT, varNumsT, buffptr, - NULL_); - cdf_FreeMemory (varNumsT, NULL); - return; -} - -/****************************************************************************** -* CDF_get_zVars_RecordData. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvars_recorddata__, - cdf_get_zvars_recorddata_, - cdf_get_zvars_recorddata, - CDF_GET_ZVARS_RECORDDATA) -(id, num_vars, varNums, rec_num, buffptr, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *num_vars; /* In: Number of zVariables. */ -Int32 varNums[]; /* In: zVariable numbers. */ -Int32 *rec_num; /* In: Record number. */ -void *buffptr; /* In: Pointer for input data */ -Int32 *status; /* Out: CDF status code. */ -{ - long num_varsT = (long) *num_vars; - long recNumT = (long) (*rec_num - 1); - long *varNumsT; - int i; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - NULL_); - if (StatusBAD(*status)) return; - - varNumsT = cdf_AllocateMemory ((size_t)*num_vars*sizeof(long), NULL); - if (varNumsT == NULL) { - *status = BAD_MALLOC; - return; - } - - for (i = 0; i < *num_vars; i++) varNumsT[i] = (long) varNums[i] - 1; - - *status = (Int32) CDFlib (SELECT_, zVARs_RECNUMBER_, recNumT, - GET_, zVARs_RECDATA_, num_varsT, varNumsT, buffptr, - NULL_); - cdf_FreeMemory (varNumsT, NULL); - return; - -} - -/****************************************************************************** -* CDF_put_zVars_RecordData. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_put_zvars_recorddata__, - cdf_put_zvars_recorddata_, - cdf_put_zvars_recorddata, - CDF_PUT_ZVARS_RECORDDATA) -(id, num_vars, varNums, rec_num, buffptr, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *num_vars; /* In: Number of zVariables. */ -Int32 varNums[]; /* In: zVariable numbers. */ -Int32 *rec_num; /* In: Record number. */ -void *buffptr; /* In: Pointer for output data */ -Int32 *status; /* Out: CDF status code. */ -{ - long num_varsT = (long) *num_vars; - long recNumT = (long) (*rec_num - 1); - long *varNumsT; - int i; - - if (*num_vars < 1) { - *status = (Int32) CDF_OK; - return; - } - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - NULL_); - if (StatusBAD(*status)) return; - - varNumsT = cdf_AllocateMemory ((size_t)*num_vars*sizeof(long), NULL); - if (varNumsT == NULL) { - *status = BAD_MALLOC; - return; - } - - for (i = 0; i < *num_vars; i++) varNumsT[i] = (long) varNums[i] - 1; - - *status = (Int32) CDFlib (SELECT_, zVARs_RECNUMBER_, recNumT, - PUT_, zVARs_RECDATA_, num_varsT, varNumsT, buffptr, - NULL_); - cdf_FreeMemory (varNumsT, NULL); - return; -} - -/****************************************************************************** -* CDF_set_FileBackward. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_filebackward__,cdf_set_filebackward_, - cdf_set_filebackward, CDF_SET_FILEBACKWARD) -(flag) -Int32 *flag; /* In: Flag to set the file to old version. */ -{ - int fg = (int) *flag; - CDFsetFileBackward(fg); - return; -} - -/****************************************************************************** -* CDF_get_FileBackward. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_filebackward__,cdf_get_filebackward_, - cdf_get_filebackward, CDF_GET_FILEBACKWARD) -() -{ - - int flag; - flag = CDFgetFileBackward(); - if (flag == 0) return (Int32) 0; - else return (Int32) 1; -} - -/****************************************************************************** -* CDF_set_Validate. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_validate__,cdf_set_validate_, - cdf_set_validate, CDF_SET_VALIDATE) -(flag) -Int32 *flag; /* In: Flag to set the file to old version. */ -{ - int fg = (int) *flag; - CDFsetValidate(fg); - return; -} - -/****************************************************************************** -* CDF_get_validate. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_validate__,cdf_get_validate_, - cdf_get_validate, CDF_GET_VALIDATE) -() -{ - - int flag; - flag = CDFgetValidate(); - if (flag == 0) return (Int32) 0; - else return (Int32) 1; -} - diff --git a/cdf36_3-dist/src/lib/cdffsi2.c b/cdf36_3-dist/src/lib/cdffsi2.c deleted file mode 100644 index 9c9549a..0000000 --- a/cdf36_3-dist/src/lib/cdffsi2.c +++ /dev/null @@ -1,2470 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF Standard Interface (II) /FORTRAN. -* -* Version 3.1, 26-May-05, Raytheon ITSS. -* -* Modification history: -* -* V1.0 26-May-05, M Liu Original version (for CDF V3.1). -* V1.1 03-Jan-12, M Liu Added cdf_get_zvar_allrecords_varid, -* cdf_get_zvar_rangerecords_varid, -* cdf_get_var_allrecords_varname, -* cdf_get_var_rangerecords_name functions, and -* a set of similar functions for put operations. -* -******************************************************************************/ - -/****************************************************************************** -* This is the second part of the extended FORTRAN interfaces. -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* CDF_delete_attr. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_delete_attr__, - cdf_delete_attr_, - cdf_delete_attr, - CDF_DELETE_ATTR) -(id, attr_num, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - DELETE_, ATTR_, - NULL_); - return; -} - -/****************************************************************************** -* CDF_get_cachesize. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_cachesize__, - cdf_get_cachesize_, - cdf_get_cachesize, - CDF_GET_CACHESIZE) -(id, cache_size, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *cache_size; /* Out: CDF cache size. */ -Int32 *status; /* Out: CDF status code. */ -{ - long cacheSize; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CONFIRM_, CDF_CACHESIZE_, &cacheSize, - NULL_); - if (StatusOK(*status)) *cache_size = (Int32) cacheSize; - return; -} - -/****************************************************************************** -* CDF_get_decoding. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_decoding__, - cdf_get_decoding_, - cdf_get_decoding, - CDF_GET_DECODING) -(id, decoding, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *decoding; /* Out: CDF decoding. */ -Int32 *status; /* Out: CDF status code. */ -{ - long decodingT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CONFIRM_, CDF_DECODING_, &decodingT, - NULL_); - if (StatusOK(*status)) *decoding = (Int32) decodingT; - return; -} - -/****************************************************************************** -* CDF_get_negtoposfp0_mode. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_negtoposfp0_mode__, - cdf_get_negtoposfp0_mode_, - cdf_get_negtoposfp0_mode, - CDF_GET_NEGTOPOSFP0_MODE) -(id, negtoposfp0, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *negtoposfp0; /* Out: CDF NEGtoPOSfp0 mode. */ -Int32 *status; /* Out: CDF status code. */ -{ - long negtoposfp0T; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CONFIRM_, CDF_NEGtoPOSfp0_MODE_, &negtoposfp0T, - NULL_); - if (StatusOK(*status)) *negtoposfp0 = (Int32) negtoposfp0T; - return; -} - -/****************************************************************************** -* CDF_get_readonly_mode. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_readonly_mode__, - cdf_get_readonly_mode_, - cdf_get_readonly_mode, - CDF_GET_READONLY_MODE) -(id, readonlymode, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *readonlymode; /* Out: CDF read only mode. */ -Int32 *status; /* Out: CDF status code. */ -{ - long readOnlyModeT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CONFIRM_, CDF_READONLY_MODE_, &readOnlyModeT, - NULL_); - if (StatusOK(*status)) *readonlymode = (Int32) readOnlyModeT; - return; -} - -/****************************************************************************** -* CDF_get_zmode. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zmode__, - cdf_get_zmode_, - cdf_get_zmode, - CDF_GET_ZMODE) -(id, zmode, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *zmode; /* Out: CDF zMode. */ -Int32 *status; /* Out: CDF status code. */ -{ - long zModeT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CONFIRM_, CDF_zMODE_, &zModeT, - NULL_); - if (StatusOK(*status)) *zmode = (Int32) zModeT; - return; -} - -/****************************************************************************** -* CDF_get_compress_cachesize. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_compress_cachesize__, - cdf_get_compress_cachesize_, - cdf_get_compress_cachesize, - CDF_GET_COMPRESS_CACHESIZE) -(id, num_buffers, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *num_buffers; /* Out: CDF compression cache size. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numBuffers; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CONFIRM_, COMPRESS_CACHESIZE_, &numBuffers, - NULL_); - if (StatusOK(*status)) *num_buffers = (Int32) numBuffers; - return; -} - -/****************************************************************************** -* CDF_get_stage_cachesize. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_stage_cachesize__, - cdf_get_stage_cachesize_, - cdf_get_stage_cachesize, - CDF_GET_STAGE_CACHESIZE) -(id, num_buffers, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *num_buffers; /* Out: CDF stage cache size. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numBuffers; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CONFIRM_, STAGE_CACHESIZE_, &numBuffers, - NULL_); - if (StatusOK(*status)) *num_buffers = (Int32) numBuffers; - return; -} - -/****************************************************************************** -* CDF_get_zvar_cachesize. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_cachesize__, - cdf_get_zvar_cachesize_, - cdf_get_zvar_cachesize, - CDF_GET_ZVAR_CACHESIZE) -(id, var_num, cache_size, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* Out: zVariable number. */ -Int32 *cache_size; /* Out: zVariable's cache size. */ -Int32 *status; /* Out: CDF status code. */ -{ - long cacheSize; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - CONFIRM_, zVAR_CACHESIZE_, &cacheSize, - NULL_); - if (StatusOK(*status)) *cache_size = (Int32) cacheSize; - return; -} - -/****************************************************************************** -* CDF_get_zvar_reservepercent. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_reservepercent__, - cdf_get_zvar_reservepercent_, - cdf_get_zvar_reservepercent, - CDF_GET_ZVAR_RESERVEPERCENT) -(id, var_num, reserve_percent, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: zVariable number. */ -Int32 *reserve_percent; /* Out: zVariable's reserve percentage. */ -Int32 *status; /* Out: CDF status code. */ -{ - long reservePercent; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - CONFIRM_, zVAR_RESERVEPERCENT_, &reservePercent, - NULL_); - if (StatusOK(*status)) *reserve_percent = (Int32) reservePercent; - return; -} - -/****************************************************************************** -* CDF_get_zvar_seqpos. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_seqpos__, - cdf_get_zvar_seqpos_, - cdf_get_zvar_seqpos, - CDF_GET_ZVAR_SEQPOS) -(id, var_num, rec_num, indices, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: zVariable number. */ -Int32 *rec_num; /* out: zVariable's record number. */ -Int32 indices[]; /* Out: zVariable's record indices. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numDims, recNum, indicesT[CDF_MAX_DIMS]; - int ix; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_NUMDIMS_, &numDims, - NULL_); - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (CONFIRM_, zVAR_SEQPOS_, &recNum, indicesT, - NULL_); - if (StatusOK(*status)) { - *rec_num = (Int32) (recNum + 1); - for (ix = 0; ix < (int) numDims; ix++) - indices[ix] = (Int32) (indicesT[ix] + 1); - } - return; -} - -/****************************************************************************** -* CDF_get_attr_name. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_name__, - cdf_get_attr_name_, - cdf_get_attr_name, - CDF_GET_ATTR_NAME) -(id, attr_num, attr_name, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: CDF attribute number. */ -void *attr_name; /* Out: CDF attribute name. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "attr_name" - (generated by FORTRAN compiler). */ -{ - char attrName[CDF_ATTR_NAME_LEN256]; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - GET_, ATTR_NAME_, attrName, - NULL_); - if (StatusOK(*status)) { -#if defined(Fif_GHOSTLEN) - CtoFORTstring (attrName, attr_name, Fif_GHOSTUSE(len)); -#else - CtoFORTstring (attrName, attr_name, CDF_ATTR_NAME_LEN256); -#endif - } - - return; -} - -/****************************************************************************** -* CDF_get_attr_scope. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_scope__, - cdf_get_attr_scope_, - cdf_get_attr_scope, - CDF_GET_ATTR_SCOPE) -(id, attr_num, attr_scope, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *attr_scope; /* Out: Attribute scope. */ -Int32 *status; /* Out: CDF status code. */ -{ - long scope; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - *attr_scope = (Int32) scope; - - return; -} - -/****************************************************************************** -* CDF_delete_attr_gentry. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_delete_attr_gentry__, - cdf_delete_attr_gentry_, - cdf_delete_attr_gentry, - CDF_DELETE_ATTR_GENTRY) -(id, attr_num, entry_num, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: gEntry number. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - gENTRY_, (long) (*entry_num - 1), - DELETE_, gENTRY_, - NULL_); - return; -} - -/****************************************************************************** -* CDF_delete_attr_rentry. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_delete_attr_rentry__, - cdf_delete_attr_rentry_, - cdf_delete_attr_rentry, - CDF_DELETE_ATTR_RENTRY) -(id, attr_num, entry_num, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: rEntry number. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - rENTRY_, (long) (*entry_num - 1), - DELETE_, rENTRY_, - NULL_); - return; -} - -/****************************************************************************** -* CDF_delete_attr_zentry. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_delete_attr_zentry__, - cdf_delete_attr_zentry_, - cdf_delete_attr_zentry, - CDF_DELETE_ATTR_ZENTRY) -(id, attr_num, entry_num, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: zEntry number. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - zENTRY_, (long) (*entry_num - 1), - DELETE_, zENTRY_, - NULL_); - return; -} - -/****************************************************************************** -* CDF_get_attr_num_gentries. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_num_gentries__, - cdf_get_attr_num_gentries_, - cdf_get_attr_num_gentries, - CDF_GET_ATTR_NUM_GENTRIES) -(id, attr_num, entries, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entries; /* Out: Number of gEntries. */ -Int32 *status; /* Out: CDF status code. */ -{ - - long scope; - long entriesT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - - if (GLOBALscope(scope)) { - *status = (Int32) CDFlib (GET_, ATTR_NUMgENTRIES_, &entriesT, - NULL_); - if (StatusOK(*status)) - *entries = (Int32) entriesT; - else - *entries = (Int32) 0; - } else { - *entries = (Int32) 0; - *status = (Int32) ILLEGAL_FOR_SCOPE; - } - return; -} - -/****************************************************************************** -* CDF_get_attr_num_rentries. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_num_rentries__, - cdf_get_attr_num_rentries_, - cdf_get_attr_num_rentries, - CDF_GET_ATTR_NUM_RENTRIES) -(id, attr_num, entries, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entries; /* Out: Number of rEntries. */ -Int32 *status; /* Out: CDF status code. */ -{ - - long scope; - long entriesT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - - if (GLOBALscope(scope)) { - *entries = (Int32) 0; - *status = (Int32) ILLEGAL_FOR_SCOPE; - } else { - *status = (Int32) CDFlib (GET_, ATTR_NUMrENTRIES_, &entriesT, - NULL_); - if (StatusOK(*status)) - *entries = (Int32) entriesT; - else - *entries = (Int32) 0; - } - return; -} - -/****************************************************************************** -* CDF_get_attr_num_zentries. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_num_zentries__, - cdf_get_attr_num_zentries_, - cdf_get_attr_num_zentries, - CDF_GET_ATTR_NUM_ZENTRIES) -(id, attr_num, entries, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entries; /* Out: Number of zEntries. */ -Int32 *status; /* Out: CDF status code. */ -{ - - long scope; - long entriesT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - if (GLOBALscope(scope)) { - *entries = (Int32) 0; - *status = (Int32) ILLEGAL_FOR_SCOPE; - } else { - *status = (Int32) CDFlib (GET_, ATTR_NUMzENTRIES_, &entriesT, - NULL_); - if (StatusOK(*status)) - *entries = (Int32) entriesT; - else - *entries = (Int32) 0; - } - return; -} - -/****************************************************************************** -* CDF_get_attr_max_gentry. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_max_gentry__, - cdf_get_attr_max_gentry_, - cdf_get_attr_max_gentry, - CDF_GET_ATTR_MAX_GENTRY) -(id, attr_num, entry, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry; /* Out: Max number of gEntry. */ -Int32 *status; /* Out: CDF status code. */ -{ - - long scope; - long entryT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - GET_, ATTR_SCOPE_, &scope, - NULL_); - if (StatusBAD(*status)) return; - - if (GLOBALscope(scope)) { - *status = (Int32) CDFlib (GET_, ATTR_MAXgENTRY_, &entryT, - NULL_); - if (StatusOK(*status)) - *entry = (Int32) (entryT + 1); - else - *entry = (Int32) 0; - } else { - *entry = (Int32) 0; - *status = (Int32) ILLEGAL_FOR_SCOPE; - } - return; -} - -/****************************************************************************** -* CDF_get_attr_max_rentry. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_max_rentry__, - cdf_get_attr_max_rentry_, - cdf_get_attr_max_rentry, - CDF_GET_ATTR_MAX_RENTRY) -(id, attr_num, entry, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry; /* Out: Max number of rEntry. */ -Int32 *status; /* Out: CDF status code. */ -{ - - long scope; - long entryT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - GET_, ATTR_SCOPE_, &scope, - NULL_); - - if (StatusBAD(*status)) return; - - if (GLOBALscope(scope)) { - *entry = (Int32) 0; - *status = (Int32) ILLEGAL_FOR_SCOPE; - } else { - *status = (Int32) CDFlib (GET_, ATTR_MAXrENTRY_, &entryT, - NULL_); - if (StatusOK(*status)) - *entry = (Int32) (entryT + 1); - else - *entry = (Int32) 0; - } - return; -} - -/****************************************************************************** -* CDF_get_attr_max_zentry. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_max_zentry__, - cdf_get_attr_max_zentry_, - cdf_get_attr_max_zentry, - CDF_GET_ATTR_MAX_ZENTRY) -(id, attr_num, entry, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry; /* Out: Max number of zEntry. */ -Int32 *status; /* Out: CDF status code. */ -{ - - long scope; - long entryT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), ATTR_, (long) (*attr_num - 1), GET_, ATTR_SCOPE_, &scope, NULL_); - - if (StatusBAD(*status)) return; - - if (GLOBALscope(scope)) { - *entry = (Int32) 0; - *status = (Int32) ILLEGAL_FOR_SCOPE; - } else { - *status = (Int32) CDFlib (GET_, ATTR_MAXzENTRY_, &entryT, - NULL_); - if (StatusOK(*status)) - *entry = (Int32) (entryT + 1); - else - *entry = (Int32) 0; - } - return; -} - -/****************************************************************************** -* CDF_get_attr_gentry_datatype. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_gentry_datatype__, - cdf_get_attr_gentry_datatype_, - cdf_get_attr_gentry_datatype, - CDF_GET_ATTR_GENTRY_DATATYPE) -(id, attr_num, entry_num, data_type, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: gEntry number. */ -Int32 *data_type; /* Out: Data type. */ -Int32 *status; /* Out: CDF status code. */ -{ - - long dataTypeT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - gENTRY_, (long) (*entry_num - 1), - GET_, gENTRY_DATATYPE_, &dataTypeT, - NULL_); - if (StatusOK(*status)) *data_type = (Int32) dataTypeT; - return; -} - -/****************************************************************************** -* CDF_get_attr_rentry_datatype. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_rentry_datatype__, - cdf_get_attr_rentry_datatype_, - cdf_get_attr_rentry_datatype, - CDF_GET_ATTR_RENTRY_DATATYPE) -(id, attr_num, entry_num, data_type, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: rEntry number. */ -Int32 *data_type; /* Out: Data type. */ -Int32 *status; /* Out: CDF status code. */ -{ - - long dataTypeT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - rENTRY_, (long) (*entry_num - 1), - GET_, rENTRY_DATATYPE_, &dataTypeT, - NULL_); - if (StatusOK(*status)) *data_type = (Int32) dataTypeT; - return; -} - -/****************************************************************************** -* CDF_get_attr_zentry_datatype. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_zentry_datatype__, - cdf_get_attr_zentry_datatype_, - cdf_get_attr_zentry_datatype, - CDF_GET_ATTR_ZENTRY_DATATYPE) -(id, attr_num, entry_num, data_type, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: zEntry number. */ -Int32 *data_type; /* Out: Data type. */ -Int32 *status; /* Out: CDF status code. */ -{ - - long dataTypeT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - zENTRY_, (long) (*entry_num - 1), - GET_, zENTRY_DATATYPE_, &dataTypeT, - NULL_); - if (StatusOK(*status)) *data_type = (Int32) dataTypeT; - return; -} - -/****************************************************************************** -* CDF_get_attr_gentry_numelems. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_gentry_numelems__, - cdf_get_attr_gentry_numelems_, - cdf_get_attr_gentry_numelems, - CDF_GET_ATTR_GENTRY_NUMELEMS) -(id, attr_num, entry_num, num_elems, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: gEntry number. */ -Int32 *num_elems; /* Out: Number of elements. */ -Int32 *status; /* Out: CDF status code. */ -{ - - long numElemsT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - gENTRY_, (long) (*entry_num - 1), - GET_, gENTRY_NUMELEMS_, &numElemsT, - NULL_); - if (StatusOK(*status)) *num_elems = (Int32) numElemsT; - return; -} - -/****************************************************************************** -* CDF_get_attr_rentry_numelems. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_rentry_numelems__, - cdf_get_attr_rentry_numelems_, - cdf_get_attr_rentry_numelems, - CDF_GET_ATTR_RENTRY_NUMELEMS) -(id, attr_num, entry_num, num_elems, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: rEntry number. */ -Int32 *num_elems; /* Out: Number of elements. */ -Int32 *status; /* Out: CDF status code. */ -{ - - long numElemsT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - rENTRY_, (long) (*entry_num - 1), - GET_, rENTRY_NUMELEMS_, &numElemsT, - NULL_); - if (StatusOK(*status)) *num_elems = (Int32) numElemsT; - return; -} - -/****************************************************************************** -* CDF_get_attr_zentry_numelems. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_attr_zentry_numelems__, - cdf_get_attr_zentry_numelems_, - cdf_get_attr_zentry_numelems, - CDF_GET_ATTR_ZENTRY_NUMELEMS) -(id, attr_num, entry_num, num_elems, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: zEntry number. */ -Int32 *num_elems; /* Out: Number of elements. */ -Int32 *status; /* Out: CDF status code. */ -{ - - long numElemsT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - zENTRY_, (long) (*entry_num - 1), - GET_, zENTRY_NUMELEMS_, &numElemsT, - NULL_); - if (StatusOK(*status)) *num_elems = (Int32) numElemsT; - return; -} - -/****************************************************************************** -* CDF_delete_zvar. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_delete_zvar__, - cdf_delete_zvar_, - cdf_delete_zvar, - CDF_DELETE_ZVAR) -(id, var_num, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: zVariable number. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num -1), - DELETE_, zVAR_, - NULL_); - return; -} - -/****************************************************************************** -* CDF_delete_zvar_recs. -******************************************************************************/ -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_delete_zvar_recs__, - cdf_delete_zvar_recs_, - cdf_delete_zvar_recs, - CDF_DELETE_ZVAR_RECS) -(id, var_num, start_rec, end_rec, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: zVariable number. */ -Int32 *start_rec; /* In: zVariable's start record number. */ -Int32 *end_rec; /* In: zVariable's end record number. */ -Int32 *status; /* Out: CDF status code. */ -{ - long startRec = (long) (*start_rec - 1); - long endRec = (long) (*end_rec - 1); - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num -1), - DELETE_, zVAR_RECORDS_, startRec, endRec, - NULL_); - return; -} - -/****************************************************************************** -* CDF_delete_zvar_recs_renumber. -******************************************************************************/ -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_delete_zvar_recs_renumber__, - cdf_delete_zvar_recs_renumber_, - cdf_delete_zvar_recs_renumber, - CDF_DELETE_ZVAR_RECS_RENUMBER) -(id, var_num, start_rec, end_rec, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: zVariable number. */ -Int32 *start_rec; /* In: zVariable's start record number. */ -Int32 *end_rec; /* In: zVariable's end record number. */ -Int32 *status; /* Out: CDF status code. */ -{ - long startRec = (long) (*start_rec - 1); - long endRec = (long) (*end_rec - 1); - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num -1), - DELETE_, zVAR_RECORDS_RENUMBER_, startRec, endRec, - NULL_); - return; -} - -/****************************************************************************** -* CDF_insert_zvar_recs. -******************************************************************************/ -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_insert_zvar_recs__, - cdf_insert_zvar_recs_, - cdf_insert_zvar_recs, - CDF_INSERT_ZVAR_RECS) -(id, var_num, start_rec, num_recs, buffer, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: zVariable number. */ -Int32 *start_rec; /* In: zVariable's start record number. */ -Int32 *num_recs; /* In: Number of records to insert. */ -void *buffer; /* In: Buffer holding the inserted data. */ -Int32 *status; /* Out: CDF status code. */ -{ - long startRec = (long) (*start_rec - 1); - *status = (Int32) CDFinsertVarRecordsByVarID (Int32ToCDFid(*id), 1, - (long) (*var_num -1), - startRec, (long) *num_recs, - buffer); - return; -} - -/****************************************************************************** -* CDF_get_num_rvars. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_num_rvars__, - cdf_get_num_rvars_, - cdf_get_num_rvars, - CDF_GET_NUM_RVARS) -(id, num_vars, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *num_vars; /* Out: Number of rVariables. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numVars; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, CDF_NUMrVARS_, &numVars, - NULL_); - if (StatusOK(*status)) - *num_vars = (Int32) numVars; - return; -} - -/****************************************************************************** -* CDF_get_num_zvars. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_num_zvars__, - cdf_get_num_zvars_, - cdf_get_num_zvars, - CDF_GET_NUM_ZVARS) -(id, num_vars, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *num_vars; /* Out: Number of zVariables. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numVars; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, CDF_NUMzVARS_, &numVars, - NULL_); - if (StatusOK(*status)) - *num_vars = (Int32) numVars; - return; -} - -/****************************************************************************** -* CDF_get_compression. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_compression__, - cdf_get_compression_, - cdf_get_compression, - CDF_GET_COMPRESSION) -(id, compression_type, compression_parms, compression_percent, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *compression_type; /* Out: CDF compression type. */ -Int32 compression_parms[]; /* Out: CDF compression parameters. */ -Int32 *compression_percent; /* Out: CDF compression percentage. */ -Int32 *status; /* Out: CDF status code. */ -{ - long cType, cPct, cParms[CDF_MAX_PARMS]; - int ix; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, CDF_COMPRESSION_, &cType, cParms, &cPct, - NULL_); - if (StatusOK(*status)) { - *compression_type = (Int32) cType; - *compression_percent = (Int32) cPct; - for (ix = 0; ix < CDF_MAX_PARMS; ix++) - compression_parms[ix] = (Int32) cParms[ix]; - } - return; -} - -/****************************************************************************** -* CDF_get_copyright. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_copyright__, - cdf_get_copyright_, - cdf_get_copyright, - CDF_GET_COPYRIGHT) -(id, copy_right, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *copy_right; /* Out: Copyright. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "copy_right" - (generated by FORTRAN compiler). */ -{ - char copyRightT[CDF_COPYRIGHT_LEN+1]; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, CDF_COPYRIGHT_, copyRightT, - NULL_); - if (StatusBAD(*status)) { - return; - } - -#if defined(Fif_GHOSTLEN) - CtoFORTstring (copyRightT, copy_right, Fif_GHOSTUSE(len)); -#else - CtoFORTstring (copyRightT, copy_right, CDF_COPYRIGHT_LEN); -#endif - return; -} - -/****************************************************************************** -* CDF_get_encoding. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_encoding__, - cdf_get_encoding_, - cdf_get_encoding, - CDF_GET_ENCODING) -(id, encoding, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *encoding; /* Out: CDF encoding. */ -Int32 *status; /* Out: CDF status code. */ -{ - long encodingT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, CDF_ENCODING_, &encodingT, - NULL_); - if (StatusOK(*status)) *encoding = (Int32) encodingT; - - return; -} - -/****************************************************************************** -* CDF_get_format. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_format__, - cdf_get_format_, - cdf_get_format, - CDF_GET_FORMAT) -(id, format, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *format; /* Out: CDF format. */ -Int32 *status; /* Out: CDF status code. */ -{ - long formatT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, CDF_FORMAT_, &formatT, - NULL_); - if (StatusOK(*status)) *format = (Int32) formatT; - - return; -} - -/****************************************************************************** -* CDF_get_majority. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_majority__, - cdf_get_majority_, - cdf_get_majority, - CDF_GET_MAJORITY) -(id, majority, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *majority; /* Out: CDF majority. */ -Int32 *status; /* Out: CDF status code. */ -{ - long majorityT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, CDF_MAJORITY_, &majorityT, - NULL_); - if (StatusOK(*status)) *majority = (Int32) majorityT; - - return; -} - -/****************************************************************************** -* CDF_get_compress_info. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_compression_info__, - cdf_get_compression_info_, - cdf_get_compression_info, - CDF_GET_COMPRESSION_INFO) -(name, compress_type, compress_parms, compress_size, decompress_size, -status Fif_GHOSTARG(len)) -void *name; /* In: CDF name. */ -Int32 *compress_type; /* Out: CDF compression type. */ -Int32 compress_parms[]; /* Out: CDF compression parameters. */ -void *compress_size; /* Out: CDF compressed size. */ -void *decompress_size; /* Out: CDF decompressed size. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - long cType, cParms[CDF_MAX_PARMS]; - int ix; - - *status = (Int32) CDFlib (GET_, CDF_INFO_, -#if defined(Fif_DESCR) - DESCRtoREFnul(name, - CDF_PATHNAME_LEN, - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(name, - Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(name, - CDF_PATHNAME_LEN,&ssh), -#endif - &cType, cParms, compress_size, - decompress_size, - NULL_); - if (StatusOK(*status)) { - *compress_type = (Int32) cType; - for (ix = 0; ix < CDF_MAX_PARMS; ix++) - compress_parms[ix] = (Int32) cParms[ix]; - } - return; -} - -/****************************************************************************** -* CDF_get_num_attrs. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_num_attrs__, - cdf_get_num_attrs_, - cdf_get_num_attrs, - CDF_GET_NUM_ATTRS) -(id, num_attrs, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *num_attrs; /* Out: CDF number of attributes. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numAttrs; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, CDF_NUMATTRS_, &numAttrs, - NULL_); - if (StatusOK(*status)) *num_attrs = (Int32) numAttrs; - - return; -} - -/****************************************************************************** -* CDF_get_num_gattrs. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_num_gattrs__, - cdf_get_num_gattrs_, - cdf_get_num_gattrs, - CDF_GET_NUM_GATTRS) -(id, num_attrs, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *num_attrs; /* Out: CDF number of gAttributes. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numAttrs; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, CDF_NUMgATTRS_, &numAttrs, - NULL_); - if (StatusOK(*status)) *num_attrs = (Int32) numAttrs; - - return; -} - -/****************************************************************************** -* CDF_get_num_vattrs. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_num_vattrs__, - cdf_get_num_vattrs_, - cdf_get_num_vattrs, - CDF_GET_NUM_VATTRS) -(id, num_attrs, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *num_attrs; /* Out: CDF number of vAttributes. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numAttrs; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, CDF_NUMvATTRS_, &numAttrs, - NULL_); - if (StatusOK(*status)) *num_attrs = (Int32) numAttrs; - - return; -} - -/****************************************************************************** -* CDF_get_datatype_size. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_datatype_size__, - cdf_get_datatype_size_, - cdf_get_datatype_size, - CDF_GET_DATATYPE_SIZE) -(datatype, datatype_size, status) -Int32 *datatype; /* In: CDF data type. */ -Int32 *datatype_size; /* Out: CDF data type size. */ -Int32 *status; /* Out: CDF status code. */ -{ - long dtSize; - - *status = (Int32) CDFlib (GET_, DATATYPE_SIZE_, (long) *datatype, &dtSize, - NULL_); - if (StatusOK(*status)) *datatype_size = (Int32) dtSize; - - return; -} - -/****************************************************************************** -* CDF_get_lib_copyright. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_lib_copyright__, - cdf_get_lib_copyright_, - cdf_get_lib_copyright, - CDF_GET_LIB_COPYRIGHT) -(copy_right, status Fif_GHOSTARG(len)) -void *copy_right; /* Out: CDF library copy right. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "copy_right" - (generated by FORTRAN compiler). */ -{ - char copyRight[CDF_COPYRIGHT_LEN+1]; - - *status = (Int32) CDFlib (GET_, LIB_COPYRIGHT_, copyRight, - NULL_); - if (StatusOK(*status)) { -#if defined(Fif_GHOSTLEN) - CtoFORTstring (copyRight, copy_right, Fif_GHOSTUSE(len)); -#else - CtoFORTstring (copyRight, copy_right, CDF_COPYRIGHT_LEN); -#endif - } - - return; -} - -/****************************************************************************** -* CDF_get_lib_version. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_lib_version__, - cdf_get_lib_version_, - cdf_get_lib_version, - CDF_GET_LIB_VERSION) -(version, release, increment, subincrement, status Fif_GHOSTARG(len)) -Int32 *version; /* Out: CDF library version. */ -Int32 *release; /* Out: CDF library release. */ -Int32 *increment; /* Out: CDF library increment. */ -void *subincrement;/* Out: CDF library sub_increment. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "subincrement" - (generated by FORTRAN compiler). */ -{ - long versionT, releaseT, incrementT; - char subIncrementT; - - *status = (Int32) CDFlib (GET_, LIB_VERSION_, &versionT, - LIB_RELEASE_, &releaseT, - LIB_INCREMENT_, &incrementT, - LIB_subINCREMENT_, &subIncrementT, - NULL_); - if (StatusOK(*status)) { - *version = (Int32) versionT; - *release = (Int32) releaseT; - *increment = (Int32) incrementT; - } -#if defined(Fif_GHOSTLEN) - CtoFORTstring (&subIncrementT, subincrement, Fif_GHOSTUSE(len)); -#else - CtoFORTstring (&subIncrementT, subincrement, 1); -#endif - - return; -} - -/****************************************************************************** -* CDF_get_version. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_version__, - cdf_get_version_, - cdf_get_version, - CDF_GET_VERSION) -(id, version, release, increment, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *version; /* Out: CDF version. */ -Int32 *release; /* Out: CDF release. */ -Int32 *increment; /* Out: CDF increment. */ -Int32 *status; /* Out: CDF status code. */ -{ - long versionT, releaseT, incrementT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, CDF_VERSION_, &versionT, - CDF_RELEASE_, &releaseT, - CDF_INCREMENT_, &incrementT, - NULL_); - if (StatusOK(*status)) { - *version = (Int32) versionT; - *release = (Int32) releaseT; - *increment = (Int32) incrementT; - } - - return; -} - -/****************************************************************************** -* CDF_get_name. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_name__, - cdf_get_name_, - cdf_get_name, - CDF_GET_NAME) -(id, cdf_name, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *cdf_name; /* Out: CDF name. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "cdf_name" - (generated by FORTRAN compiler). */ -{ - char cdfName[CDF_PATHNAME_LEN+1]; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CONFIRM_, CDF_NAME_, cdfName, - NULL_); - if (StatusOK(*status)) { -#if defined(Fif_GHOSTLEN) - CtoFORTstring (cdfName, cdf_name, Fif_GHOSTUSE(len)); -#else - CtoFORTstring (cdfName, cdf_name, CDF_PATHNAME_LEN); -#endif - } - - return; -} - -/****************************************************************************** -* CDF_get_zvar_name. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_name__, - cdf_get_zvar_name_, - cdf_get_zvar_name, - CDF_GET_ZVAR_NAME) -(id, var_num, var_name, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -void *var_name; /* Out: CDF zVariable name. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "var_name" - (generated by FORTRAN compiler). */ -{ - char varName[CDF_VAR_NAME_LEN256]; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_NAME_, varName, - NULL_); - if (StatusOK(*status)) { -#if defined(Fif_GHOSTLEN) - CtoFORTstring (varName, var_name, Fif_GHOSTUSE(len)); -#else - CtoFORTstring (varName, var_name, CDF_VAR_NAME_LEN256); -#endif - } - - return; -} - -/****************************************************************************** -* CDF_get_zvar_maxwrittenrecnum. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_maxwrittenrecnum__, - cdf_get_zvar_maxwrittenrecnum_, - cdf_get_zvar_maxwrittenrecnum, - CDF_GET_ZVAR_MAXWRITTENRECNUM) -(id, var_num, rec_num, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *rec_num; /* Out: zVariable's maximum written record number. */ -Int32 *status; /* Out: CDF status code. */ -{ - long recNum; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_MAXREC_, &recNum, - NULL_); - if (StatusOK(*status)) *rec_num = (Int32) (recNum + 1); - - return; -} - -/****************************************************************************** -* CDF_get_zvar_maxallocrecnum. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_maxallocrecnum__, - cdf_get_zvar_maxallocrecnum_, - cdf_get_zvar_maxallocrecnum, - CDF_GET_ZVAR_MAXALLOCRECNUM) -(id, var_num, rec_num, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *rec_num; /* Out: zVariables's maximum allocated record number.*/ -Int32 *status; /* Out: CDF status code. */ -{ - long recNum; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_MAXallocREC_, &recNum, - NULL_); - if (StatusOK(*status)) *rec_num = (Int32) (recNum + 1); - - return; -} - -/****************************************************************************** -* CDF_get_zvars_maxwrittenrecnum. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvars_maxwrittenrecnum__, - cdf_get_zvars_maxwrittenrecnum_, - cdf_get_zvars_maxwrittenrecnum, - CDF_GET_ZVARS_MAXWRITTENRECNUM) -(id, rec_num, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *rec_num; /* Out: zVariables's maximum written record number. */ -Int32 *status; /* Out: CDF status code. */ -{ - long recNum; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, zVARs_MAXREC_, &recNum, - NULL_); - if (StatusOK(*status)) *rec_num = (Int32) (recNum + 1); - - return; -} - -/****************************************************************************** -* CDF_get_vars_maxwrittenrecnums. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_vars_maxwrittenrecnums__, - cdf_get_vars_maxwrittenrecnums_, - cdf_get_vars_maxwrittenrecnums, - CDF_GET_VARS_MAXWRITTENRECNUMS) -(id, rec_num1, rec_num2, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *rec_num1; /* Out: rVariables's maximum written record number. */ -Int32 *rec_num2; /* Out: zVariables's maximum written record number. */ -Int32 *status; /* Out: CDF status code. */ -{ - long recNum1, recNum2; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, rVARs_MAXREC_, &recNum1, - zVARs_MAXREC_, &recNum2, - NULL_); - if (StatusOK(*status)) { - *rec_num1 = (Int32) (recNum1 + 1); - *rec_num2 = (Int32) (recNum2 + 1); - } - - return; -} - -/****************************************************************************** -* CDF_get_zvar_allocrecs. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_allocrecs__, - cdf_get_zvar_allocrecs_, - cdf_get_zvar_allocrecs, - CDF_GET_ZVAR_ALLOCRECS) -(id, var_num, num_recs, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* zVariable number. */ -Int32 *num_recs; /* Out: zVariable's number of allocated records. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numRecs; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_NUMallocRECS_, &numRecs, - NULL_); - if (StatusOK(*status)) *num_recs = (Int32) numRecs; - - return; -} - -/****************************************************************************** -* CDF_get_zvar_datatype. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_datatype__, - cdf_get_zvar_datatype_, - cdf_get_zvar_datatype, - CDF_GET_ZVAR_DATATYPE) -(id, var_num, data_type, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *data_type; /* Out: zVariable's data type. */ -Int32 *status; /* Out: CDF status code. */ -{ - long dataType; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_DATATYPE_, &dataType, - NULL_); - if (StatusOK(*status)) *data_type = (Int32) dataType; - - return; -} - -/****************************************************************************** -* CDF_get_zvar_numelems. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_numelems__, - cdf_get_zvar_numelems_, - cdf_get_zvar_numelems, - CDF_GET_ZVAR_NUMELEMS) -(id, var_num, num_elems, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *num_elems; /* Out: zVariable's number of elements. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numElems; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_NUMELEMS_, &numElems, - NULL_); - if (StatusOK(*status)) *num_elems = (Int32) numElems; - - return; -} - -/****************************************************************************** -* CDF_get_zvar_numdims. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_numdims__, - cdf_get_zvar_numdims_, - cdf_get_zvar_numdims, - CDF_GET_ZVAR_NUMDIMS) -(id, var_num, num_dims, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *num_dims; /* Out: zVariable's number of dimensions. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numDims; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_NUMDIMS_, &numDims, - NULL_); - if (StatusOK(*status)) *num_dims = (Int32) numDims; - - return; -} - -/****************************************************************************** -* CDF_get_zvar_dimsizes. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_dimsizes__, - cdf_get_zvar_dimsizes_, - cdf_get_zvar_dimsizes, - CDF_GET_ZVAR_DIMSIZES) -(id, var_num, dim_sizes, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 dim_sizes[]; /* Out: zVariable's dimensional sizes. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numDims, dimSizes[CDF_MAX_DIMS]; - int ix; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_DIMSIZES_, dimSizes, - zVAR_NUMDIMS_, &numDims, - NULL_); - if (StatusOK(*status)) { - if (numDims > 0) { - for (ix = 0; ix < (int) numDims; ix++) - dim_sizes[ix] = (Int32) dimSizes[ix]; - } else { - dim_sizes[0] = 0; - } - } - return; -} - -/****************************************************************************** -* CDF_get_zvar_recvariance. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_recvariance__, - cdf_get_zvar_recvariance_, - cdf_get_zvar_recvariance, - CDF_GET_ZVAR_RECVARIANCE) -(id, var_num, rec_vary, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *rec_vary; /* Out: zVariable's record variance. */ -Int32 *status; /* Out: CDF status code. */ -{ - long recVary; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_RECVARY_, &recVary, - NULL_); - if (StatusOK(*status)) *rec_vary = (Int32) recVary; - - return; -} - -/****************************************************************************** -* CDF_get_zvar_dimvariances. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_dimvariances__, - cdf_get_zvar_dimvariances_, - cdf_get_zvar_dimvariances, - CDF_GET_ZVAR_DIMVARIANCES) -(id, var_num, dim_varys, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 dim_varys[]; /* Out: zVariable's dimensional variances. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numDims, dimVarys[CDF_MAX_DIMS]; - int ix; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_DIMVARYS_, dimVarys, - zVAR_NUMDIMS_, &numDims, - NULL_); - if (StatusOK(*status)) { - if (numDims > 0) { - for (ix = 0; ix < (int) numDims; ix++) - dim_varys[ix] = (Int32) dimVarys[ix]; - } else { - dim_varys[0] = 0; - } - } - return; -} - -/****************************************************************************** -* CDF_get_zvar_blockingfactor. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_blockingfactor__, - cdf_get_zvar_blockingfactor_, - cdf_get_zvar_blockingfactor, - CDF_GET_ZVAR_BLOCKINGFACTOR) -(id, var_num, blocking_factor, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *blocking_factor; /* Out: zVariable's blocking factor. */ -Int32 *status; /* Out: CDF status code. */ -{ - long blockingFactor; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_BLOCKINGFACTOR_, &blockingFactor, - NULL_); - if (StatusOK(*status)) *blocking_factor = (Int32) blockingFactor; - - return; -} - -/****************************************************************************** -* CDF_get_zvar_compression. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_compression__, - cdf_get_zvar_compression_, - cdf_get_zvar_compression, - CDF_GET_ZVAR_COMPRESSION) -(id, var_num, compress_type, compress_parms, compress_percent, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *compress_type; /* Out: zVariable's compression type. */ -Int32 compress_parms[]; /* Out: zVariable's compression parameters. */ -Int32 *compress_percent;/* Out: zVariable's compression percentage. */ -Int32 *status; /* Out: CDF status code. */ -{ - long cType, cPct, cParms[CDF_MAX_PARMS]; - int ix; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_COMPRESSION_, &cType, cParms, &cPct, - NULL_); - if (StatusOK(*status)) { - *compress_type = (Int32) cType; - *compress_percent = (Int32) cPct; - for (ix = 0; ix < CDF_MAX_PARMS; ix++) - compress_parms[ix] = (Int32) cParms[ix]; - } - return; -} - -/****************************************************************************** -* CDF_get_zvar_padvalue. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_padvalue__, - cdf_get_zvar_padvalue_, - cdf_get_zvar_padvalue, - CDF_GET_ZVAR_PADVALUE) -(id, var_num, pad_value, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -void *pad_value; /* Out: zVariable's pad value. */ -Int32 *status; /* Out: CDF status code. */ -{ - long dataType; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_DATATYPE_, &dataType, - NULL_); - - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (GET_, zVAR_PADVALUE_, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(pad_value),pad_value), -#else - pad_value, -#endif - NULL_); - return; -} - -/****************************************************************************** -* CDF_get_zvar_sparserecords. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_sparserecords__, - cdf_get_zvar_sparserecords_, - cdf_get_zvar_sparserecords, - CDF_GET_ZVAR_SPARSERECORDS) -(id, var_num, sparse_records, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *sparse_records; /* Out: zVariable's sparse records. */ -Int32 *status; /* Out: CDF status code. */ -{ - long sparseRecords; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_SPARSERECORDS_, &sparseRecords, - NULL_); - if (StatusOK(*status)) *sparse_records = (Int32) sparseRecords; - - return; -} - -/****************************************************************************** -* CDF_get_zvar_numrecs_written. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_numrecs_written__, - cdf_get_zvar_numrecs_written_, - cdf_get_zvar_numrecs_written, - CDF_GET_ZVAR_NUMRECS_WRITTEN) -(id, var_num, num_records, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *num_records; /* Out: zVariable's written records. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numRecords; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_NUMRECS_, &numRecords, - NULL_); - if (StatusOK(*status)) *num_records = (Int32) numRecords; - - return; -} - -/****************************************************************************** -* CDF_get_zvar_seqdata. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_seqdata__, - cdf_get_zvar_seqdata_, - cdf_get_zvar_seqdata, - CDF_GET_ZVAR_SEQDATA) -(id, var_num, data, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -void *data; /* Out: CDF zVariable's data. */ -Int32 *status; /* Out: CDF status code. */ -{ - long dataType; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_DATATYPE_, &dataType, - NULL_); - - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (GET_, zVAR_SEQDATA_, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(data),data), -#else - data, -#endif - NULL_); - - return; -} - -/****************************************************************************** -* CDF_get_zvar_recorddata. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_recorddata__, - cdf_get_zvar_recorddata_, - cdf_get_zvar_recorddata, - CDF_GET_ZVAR_RECORDDATA) -(id, var_num, rec_num, buffer, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *rec_num; /* In: CDF zVariable record number. */ -void *buffer; /* Out: zVariable's full record data. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numVars, varNums[1]; - - numVars = 1; - varNums[0] = (long) (*var_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVARs_RECNUMBER_, (long) (*rec_num - 1), - GET_, zVARs_RECDATA_, numVars, varNums, buffer, - NULL_); - return; -} - -/****************************************************************************** -* CDF_get_zvar_allrecords_varid. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_allrecords_varid__, - cdf_get_zvar_allrecords_varid_, - cdf_get_zvar_allrecords_varid, - CDF_GET_ZVAR_ALLRECORDS_VARID) -(id, var_num, buffer, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -void *buffer; /* Out: zVariable's full record data. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFgetVarAllRecordsByVarID (Int32ToCDFid(*id), 1, - (long) (*var_num - 1), - buffer); - return; -} - -/****************************************************************************** -* CDF_get_zvar_rangerecords_varid. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_zvar_rangerecords_varid__, - cdf_get_zvar_rangerecords_varid_, - cdf_get_zvar_rangerecords_varid, - CDF_GET_ZVAR_RANGERECORDS_VARID) -(id, var_num, start_rec, stop_rec, buffer, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *start_rec; /* In: Starting record number. */ -Int32 *stop_rec; /* In: Stopping record number. */ -void *buffer; /* Out: zVariable's full record data. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFgetVarRangeRecordsByVarID (Int32ToCDFid(*id), 1, - (long) (*var_num - 1), - (long) (*start_rec - 1), - (long) (*stop_rec - 1), - buffer); - return; -} - -/****************************************************************************** -* CDF_get_var_allrecords_varname. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_var_allrecords_varname__, - cdf_get_var_allrecords_varname_, - cdf_get_var_allrecords_varname, - CDF_GET_VAR_ALLRECORDS_VARNAME) -(id, var_name, buffer, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *var_name; /* In: CDF zVariable name. */ -void *buffer; /* Out: zVariable's all records' data. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "var_name" - (generated by FORTRAN compiler). */ -{ - int LFS = TRUE; - struct CDFstruct *CDF; - struct STRINGstruct *ssh = NULL; - *status = (Int32) CDFgetVarAllRecordsByVarName (Int32ToCDFid(*id), -#if defined(Fif_DESCR) - DESCRtoREFnul(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(var_name, - Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif - buffer); - return; -} - -/****************************************************************************** -* CDF_get_var_rangerecords_name. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_var_rangerecords_name__, - cdf_get_var_rangerecords_name_, - cdf_get_var_rangerecords_name, - CDF_GET_VAR_RANGERECORDS_NAME) -(id, var_name, start_rec, stop_rec, buffer, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *var_name; /* In: CDF zVariable name. */ -Int32 *start_rec; /* In: zVariable's starting record number. */ -Int32 *stop_rec; /* In: zVariable's stopping record number. */ -void *buffer; /* Out: zVariable's records' data. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "var_name" - (generated by FORTRAN compiler). */ -{ - int LFS = TRUE; - struct CDFstruct *CDF; - struct STRINGstruct *ssh = NULL; - *status = (Int32) CDFgetVarRangeRecordsByVarName (Int32ToCDFid(*id), -#if defined(Fif_DESCR) - DESCRtoREFnul(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(var_name, - Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif - (long) (*start_rec - 1), - (long) (*stop_rec - 1), - buffer); - return; -} - -/****************************************************************************** -* CDF_put_zvar_allrecords_varid. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_put_zvar_allrecords_varid__, - cdf_put_zvar_allrecords_varid_, - cdf_put_zvar_allrecords_varid, - CDF_PUT_ZVAR_ALLRECORDS_VARID) -(id, var_num, num_recs, buffer, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *num_recs; /* In: Number of zVariable records to write. */ -void *buffer; /* Out: zVariable's full record data. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFputVarAllRecordsByVarID (Int32ToCDFid(*id), 1, - (long) (*var_num - 1), - (long) *num_recs, - buffer); - return; -} - -/****************************************************************************** -* CDF_put_zvar_rangerecords_varid. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_put_zvar_rangerecords_varid__, - cdf_put_zvar_rangerecords_varid_, - cdf_put_zvar_rangerecords_varid, - CDF_PUT_ZVAR_RANGERECORDS_VARID) -(id, var_num, start_rec, stop_rec, buffer, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *start_rec; /* In: Starting record number. */ -Int32 *stop_rec; /* In: Stopping record number. */ -void *buffer; /* Out: zVariable's full record data. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFputVarRangeRecordsByVarID (Int32ToCDFid(*id), 1, - (long) (*var_num - 1), - (long) (*start_rec - 1), - (long) (*stop_rec - 1), - buffer); - return; -} - -/****************************************************************************** -* CDF_put_var_allrecords_varname. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_put_var_allrecords_varname__, - cdf_put_var_allrecords_varname_, - cdf_put_var_allrecords_varname, - CDF_PUT_VAR_ALLRECORDS_VARNAME) -(id, var_name, num_recs, buffer, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *var_name; /* In: CDF zVariable name. */ -Int32 *num_recs; /* In: Number of records to write. */ -void *buffer; /* Out: zVariable's all records' data. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "var_name" - (generated by FORTRAN compiler). */ -{ - int LFS = TRUE; - struct CDFstruct *CDF; - struct STRINGstruct *ssh = NULL; - *status = (Int32) CDFputVarAllRecordsByVarName (Int32ToCDFid(*id), -#if defined(Fif_DESCR) - DESCRtoREFnul(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(var_name, - Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif - (long) *num_recs, - buffer); - return; -} - -/****************************************************************************** -* CDF_put_var_rangerecords_name. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_put_var_rangerecords_name__, - cdf_put_var_rangerecords_name_, - cdf_put_var_rangerecords_name, - CDF_PUT_VAR_RANGERECORDS_NAME) -(id, var_name, start_rec, stop_rec, buffer, status Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *var_name; /* In: CDF zVariable name. */ -Int32 *start_rec; /* In: zVariable's starting record number. */ -Int32 *stop_rec; /* In: zVariable's stopping record number. */ -void *buffer; /* Out: zVariable's records' data. */ -Int32 *status; /* Out: CDF status code. */ -Fif_GHOSTDEF(len) /* Invisible length of "var_name" - (generated by FORTRAN compiler). */ -{ - int LFS = TRUE; - struct CDFstruct *CDF; - struct STRINGstruct *ssh = NULL; - *status = (Int32) CDFputVarRangeRecordsByVarName (Int32ToCDFid(*id), -#if defined(Fif_DESCR) - DESCRtoREFnul(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(var_name, - Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(var_name, - (LFS ? - CDF_VAR_NAME_LEN256 : - CDF_VAR_NAME_LEN), - &ssh), -#endif - (long) (*start_rec - 1), - (long) (*stop_rec - 1), - buffer); - return; -} - -/****************************************************************************** -* CDF_get_checksum. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_checksum__, - cdf_get_checksum_, - cdf_get_checksum, - CDF_GET_CHECKSUM) -(id, checksum, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *checksum; /* Out: CDF checksum. */ -Int32 *status; /* Out: CDF status code. */ -{ - long checksumT; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, CDF_CHECKSUM_, &checksumT, - NULL_); - if (StatusOK(*status)) *checksum = (Int32) checksumT; - - return; -} - - diff --git a/cdf36_3-dist/src/lib/cdffsi3.c b/cdf36_3-dist/src/lib/cdffsi3.c deleted file mode 100644 index b100286..0000000 --- a/cdf36_3-dist/src/lib/cdffsi3.c +++ /dev/null @@ -1,1269 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF Standard Interface (III) /FORTRAN. -* -* Version 3.1, 26-May-05, Raytheon ITSS. -* -* Modification history: -* -* V1.0 26-May-05, M Liu Original version (for CDF V3.1). -* V1.1 26-Jue-09, M Liu Added CDF_select_cdf function. -* -******************************************************************************/ - -/****************************************************************************** -* This is the third part of the extended FORTRAN interfaces. -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* CDF_confirm_attr_existence. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_confirm_attr_existence__, - cdf_confirm_attr_existence_, - cdf_confirm_attr_existence, - CDF_CONFIRM_ATTR_EXISTENCE) -(id, attr_name Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *attr_name; /* In: Attribute name. */ -Fif_GHOSTDEF(len) /* Invisible length of "attr_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - Int32 status; - - status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CONFIRM_, ATTR_EXISTENCE_, -#if defined(Fif_DESCR) - DESCRtoREFnul(attr_name, - CDF_ATTR_NAME_LEN256, - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(attr_name,Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(attr_name, - CDF_ATTR_NAME_LEN256, - &ssh), -#endif - NULL_); - - return status; -} - -/****************************************************************************** -* CDF_confirm_zvar_existence. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_confirm_zvar_existence__, - cdf_confirm_zvar_existence_, - cdf_confirm_zvar_existence, - CDF_CONFIRM_ZVAR_EXISTENCE) -(id, var_name Fif_GHOSTARG(len)) -Int32 *id; /* In: CDF identifier. */ -void *var_name; /* In: zVariable name. */ -Fif_GHOSTDEF(len) /* Invisible length of "var_name" - (generated by FORTRAN compiler). */ -{ - struct STRINGstruct *ssh = NULL; /* Head of STRINGstruct linked list. */ - Int32 status; - - status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CONFIRM_, zVAR_EXISTENCE_, -#if defined(Fif_DESCR) - DESCRtoREFnul(var_name, - CDF_VAR_NAME_LEN256, - &ssh), -#endif -#if defined(Fif_GHOSTLEN) - NULterminate(var_name,Fif_GHOSTUSE(len), - &ssh), -#endif -#if defined(Fif_NOLEN) - FindEndNUL(var_name, - CDF_VAR_NAME_LEN256, - &ssh), -#endif - NULL_); - - return status; -} - -/****************************************************************************** -* CDF_confirm_gentry_existence. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_confirm_gentry_existence__, - cdf_confirm_gentry_existence_, - cdf_confirm_gentry_existence, - CDF_CONFIRM_GENTRY_EXISTENCE) -(id, attr_num, entry_num) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: gEntry number. */ -{ - Int32 status; - - status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - CONFIRM_, gENTRY_EXISTENCE_, - (long) (*entry_num - 1), - NULL_); - - return status; -} - -/****************************************************************************** -* CDF_confirm_rentry_existence. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_confirm_rentry_existence__, - cdf_confirm_rentry_existence_, - cdf_confirm_rentry_existence, - CDF_CONFIRM_RENTRY_EXISTENCE) -(id, attr_num, entry_num) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: rEntry number. */ -{ - Int32 status; - - status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - CONFIRM_, rENTRY_EXISTENCE_, - (long) (*entry_num - 1), - NULL_); - - return status; -} - -/****************************************************************************** -* CDF_confirm_zentry_existence. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_confirm_zentry_existence__, - cdf_confirm_zentry_existence_, - cdf_confirm_zentry_existence, - CDF_CONFIRM_ZENTRY_EXISTENCE) -(id, attr_num, entry_num) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: zEntry number. */ -{ - Int32 status; - - status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - CONFIRM_, zENTRY_EXISTENCE_, - (long) (*entry_num - 1), - NULL_); - - return status; -} - -/****************************************************************************** -* CDF_confirm_zvar_padvalue_exist. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_confirm_zvar_padvalue_exist__, - cdf_confirm_zvar_padvalue_exist_, - cdf_confirm_zvar_padvalue_exist, - CDF_CONFIRM_ZVAR_PADVALUE_EXIST) -(id, var_num) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: zVariable number. */ -{ - Int32 status; - - status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - CONFIRM_, zVAR_PADVALUE_, - NULL_); - - return status; -} - -/****************************************************************************** -* CDF_set_decoding. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_decoding__, - cdf_set_decoding_, - cdf_set_decoding, - CDF_SET_DECODING) -(id, decoding, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *decoding; /* In: CDF decoding. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CDF_DECODING_, (long) *decoding, - NULL_); - - return; -} - -/****************************************************************************** -* CDF_set_readonly_mode. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_readonly_mode__, - cdf_set_readonly_mode_, - cdf_set_readonly_mode, - CDF_SET_READONLY_MODE) -(id, mode, status) -Int32 *id; /* in: cdf identifier. */ -Int32 *mode; /* in: cdf readonly mode. */ -Int32 *status; /* out: cdf status code. */ -{ - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CDF_READONLY_MODE_, (long) *mode, - NULL_); - - return; -} - -/****************************************************************************** -* CDF_set_negtoposfp0_mode. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_negtoposfp0_mode__, - cdf_set_negtoposfp0_mode_, - cdf_set_negtoposfp0_mode, - CDF_SET_NEGTOPOSFP0_MODE) -(id, mode, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *mode; /* In: CDF negtoposfp0 mode. */ -Int32 *status; /* Out: CDF status code. */ -{ - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CDF_NEGtoPOSfp0_MODE_, (long) *mode, - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_compress_cachesize. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_compress_cachesize__, - cdf_set_compress_cachesize_, - cdf_set_compress_cachesize, - CDF_SET_COMPRESS_CACHESIZE) -(id, cache_size, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *cache_size; /* In: CDF compress cache size. */ -Int32 *status; /* Out: CDF status code. */ -{ - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - COMPRESS_CACHESIZE_, (long) *cache_size, - NULL_); - - return; -} - -/****************************************************************************** -* CDF_set_stage_cachesize. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_stage_cachesize__, - cdf_set_stage_cachesize_, - cdf_set_stage_cachesize, - CDF_SET_STAGE_CACHESIZE) -(id, cache_size, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *cache_size; /* In: CDF stage cache size. */ -Int32 *status; /* Out: CDF status code. */ -{ - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - STAGE_CACHESIZE_, (long) *cache_size, - NULL_); - - return; -} - -/****************************************************************************** -* CDF_set_zvar_cachesize. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_zvar_cachesize__, - cdf_set_zvar_cachesize_, - cdf_set_zvar_cachesize, - CDF_SET_ZVAR_CACHESIZE) -(id, cache_size, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *cache_size; /* In: CDF zVariable cache size. */ -Int32 *status; /* Out: CDF status code. */ -{ - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_CACHESIZE_, (long) *cache_size, - NULL_); - - return; -} - -/****************************************************************************** -* CDF_set_zvars_cachesize. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_zvars_cachesize__, - cdf_set_zvars_cachesize_, - cdf_set_zvars_cachesize, - CDF_SET_ZVARS_CACHESIZE) -(id, cache_size, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *cache_size; /* In: CDF zVariables's cache size. */ -Int32 *status; /* Out: CDF status code. */ -{ - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVARs_CACHESIZE_, (long) *cache_size, - NULL_); - - return; -} - -/****************************************************************************** -* CDF_set_zvar_seqpos. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_zvar_seqpos__, - cdf_set_zvar_seqpos_, - cdf_set_zvar_seqpos, - CDF_SET_ZVAR_SEQPOS) -(id, var_num, rec_num, indices, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *rec_num; /* In: CDF zVariable record number. */ -Int32 indices[]; /* In: CDF zVariable indices. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numDims, indicesT[CDF_MAX_DIMS]; - int ix; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_NUMDIMS_, &numDims, - NULL_); - - if (StatusBAD(*status)) return; - - if (numDims > 0) { - for (ix = 0; ix < (int) numDims; ix++) - indicesT[ix] = (long) (indices[ix] - 1); - } else - indicesT[0] = 0; - - *status = (Int32) CDFlib (SELECT_, zVAR_SEQPOS_, (long) (*rec_num -1), - indicesT, - NULL_); - - return; -} - -/****************************************************************************** -* CDF_set_zvar_reservepercent. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_zvar_reservepercent__, - cdf_set_zvar_reservepercent_, - cdf_set_zvar_reservepercent, - CDF_SET_ZVAR_RESERVEPERCENT) -(id, var_num, percent, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *percent; /* In: CDF zVariable reserve percentage. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - zVAR_RESERVEPERCENT_, (long) *percent, - NULL_); - - return; -} - -/****************************************************************************** -* CDF_set_zmode. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_zmode__, - cdf_set_zmode_, - cdf_set_zmode, - CDF_SET_ZMODE) -(id, mode, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *mode; /* In: CDF zMode. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CDF_zMODE_, (long) *mode, - NULL_); - - return; -} - -/****************************************************************************** -* CDF_set_attr_scope. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_attr_scope__, - cdf_set_attr_scope_, - cdf_set_attr_scope, - CDF_SET_ATTR_SCOPE) -(id, attr_num, attr_scope, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *attr_scope; /* In: Attribute scope. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - PUT_, ATTR_SCOPE_, (long) *attr_scope, - NULL_); - - return; -} - -/****************************************************************************** -* CDF_set_attr_gentry_dataspec. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_attr_gentry_dataspec__, - cdf_set_attr_gentry_dataspec_, - cdf_set_attr_gentry_dataspec, - CDF_SET_ATTR_GENTRY_DATASPEC) -(id, attr_num, entry_num, data_type, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: gEntry number. */ -Int32 *data_type; /* In: Data Type. */ -Int32 *status; /* Out: CDF status code. */ -{ - - long scope; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - GET_, ATTR_SCOPE_, &scope, - NULL_); - - if (!StatusOK(*status)) return; - - if (GLOBALscope(scope)) { - *status = (Int32) CDFlib (SELECT_, gENTRY_, (long) (*entry_num - 1), - PUT_, gENTRY_DATASPEC_, (long) *data_type, - (long) -99, - NULL_); - } else { - *status = ILLEGAL_FOR_SCOPE; - } - - return; -} - -/****************************************************************************** -* CDF_set_attr_rentry_dataspec. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_attr_rentry_dataspec__, - cdf_set_attr_rentry_dataspec_, - cdf_set_attr_rentry_dataspec, - CDF_SET_ATTR_RENTRY_DATASPEC) -(id, attr_num, entry_num, data_type, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: rEntry number. */ -Int32 *data_type; /* In: Data Type. */ -Int32 *status; /* Out: CDF status code. */ -{ - - long scope; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - GET_, ATTR_SCOPE_, &scope, - NULL_); - - if (!StatusOK(*status)) return; - - if (!GLOBALscope(scope)) { - *status = (Int32) CDFlib (SELECT_, rENTRY_, (long) (*entry_num - 1), - PUT_, rENTRY_DATASPEC_, (long) *data_type, - (long) -99, - NULL_); - } else { - *status = ILLEGAL_FOR_SCOPE; - } - - return; -} - -/****************************************************************************** -* CDF_set_attr_zentry_dataspec. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_attr_zentry_dataspec__, - cdf_set_attr_zentry_dataspec_, - cdf_set_attr_zentry_dataspec, - CDF_SET_ATTR_ZENTRY_DATASPEC) -(id, attr_num, entry_num, data_type, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *attr_num; /* In: Attribute number. */ -Int32 *entry_num; /* In: zEntry number. */ -Int32 *data_type; /* In: Data Type. */ -Int32 *status; /* Out: CDF status code. */ -{ - - long scope; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - ATTR_, (long) (*attr_num - 1), - GET_, ATTR_SCOPE_, &scope, - NULL_); - - if (!StatusOK(*status)) return; - - if (!GLOBALscope(scope)) { - *status = (Int32) CDFlib (SELECT_, zENTRY_, (long) (*entry_num - 1), - PUT_, zENTRY_DATASPEC_, (long) *data_type, - (long) -99, - NULL_); - } else { - *status = ILLEGAL_FOR_SCOPE; - } - - return; -} - -/****************************************************************************** -* CDF_set_compression. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_compression__, - cdf_set_compression_, - cdf_set_compression, - CDF_SET_COMPRESSION) -(id, compress_type, compress_parms, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *compress_type; /* In: CDF Compression type. */ -Int32 compress_parms[]; /* In: CDF Compression parameters. */ -Int32 *status; /* Out: CDF status code. */ -{ - long cType, cParms[CDF_MAX_PARMS]; - int ix; - - cType = (long) *compress_type; - for (ix = 0; ix < CDF_MAX_PARMS; ix++) - cParms[ix] = (long) compress_parms[ix]; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - PUT_, CDF_COMPRESSION_, cType, cParms, - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_encoding. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_encoding__, - cdf_set_encoding_, - cdf_set_encoding, - CDF_SET_ENCODING) -(id, encoding, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *encoding; /* In: CDF encoding. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - PUT_, CDF_ENCODING_, (long) *encoding, - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_format. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_format__, - cdf_set_format_, - cdf_set_format, - CDF_SET_FORMAT) -(id, format, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *format; /* In: CDF format. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - PUT_, CDF_FORMAT_, (long) *format, - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_majority. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_majority__, - cdf_set_majority_, - cdf_set_majority, - CDF_SET_MAJORITY) -(id, majority, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *majority; /* In: CDF majority. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - PUT_, CDF_MAJORITY_, (long) *majority, - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_cachesize. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_cachesize__, - cdf_set_cachesize_, - cdf_set_cachesize, - CDF_SET_CACHESIZE) -(id, cache_size, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *cache_size; /* In: CDF cache size. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CDF_CACHESIZE_, (long) *cache_size, - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_zvar_dataspec. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_zvar_dataspec__, - cdf_set_zvar_dataspec_, - cdf_set_zvar_dataspec, - CDF_SET_ZVAR_DATASPEC) -(id, var_num, data_type, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *data_type; /* In: zVariable's data type. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - PUT_, zVAR_DATASPEC_, (long) *data_type, - (long) -99, - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_zvar_recvariance. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_zvar_recvariance__, - cdf_set_zvar_recvariance_, - cdf_set_zvar_recvariance, - CDF_SET_ZVAR_RECVARIANCE) -(id, var_num, rec_vary, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *rec_vary; /* In: zVariable's record variance. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - PUT_, zVAR_RECVARY_, (long) *rec_vary, - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_zvar_dimvariances. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_zvar_dimvariances__, - cdf_set_zvar_dimvariances_, - cdf_set_zvar_dimvariances, - CDF_SET_ZVAR_DIMVARIANCES) -(id, var_num, dim_varys, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF rVariable number. */ -Int32 dim_varys[]; /* In: zVariable's dimensional variances. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numDims, dimVarys[CDF_MAX_DIMS]; - int ix; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_NUMDIMS_, &numDims, - NULL_); - if (StatusBAD(*status)) return; - - if (numDims > 0) { - for (ix = 0; ix < (int) numDims; ix++) - dimVarys[ix] = (long) dim_varys[ix]; - } else - dimVarys[0] = 0; - - *status = (Int32) CDFlib (PUT_, zVAR_DIMVARYS_, dimVarys, - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_zvar_blockingfactor. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_zvar_blockingfactor__, - cdf_set_zvar_blockingfactor_, - cdf_set_zvar_blockingfactor, - CDF_SET_ZVAR_BLOCKINGFACTOR) -(id, var_num, blocking_factor, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *blocking_factor; /* Out: zVariable's blocking factor. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - PUT_, zVAR_BLOCKINGFACTOR_, - (long) *blocking_factor, - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_zvar_compression. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_zvar_compression__, - cdf_set_zvar_compression_, - cdf_set_zvar_compression, - CDF_SET_ZVAR_COMPRESSION) -(id, var_num, compress_type, compress_parms, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *compress_type; /* In: zVariable's compression type. */ -Int32 compress_parms[]; /* In: zVariable's compression parameters. */ -Int32 *status; /* Out: CDF status code. */ -{ - long cParms[CDF_MAX_PARMS]; - int ix; - - for (ix = 0; ix < CDF_MAX_PARMS; ix++) - cParms[ix] = (long) compress_parms[ix]; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - PUT_, zVAR_COMPRESSION_, (long) *compress_type, - cParms, - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_zvar_padvalue. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_zvar_padvalue__, - cdf_set_zvar_padvalue_, - cdf_set_zvar_padvalue, - CDF_SET_ZVAR_PADVALUE) -(id, var_num, pad_value, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -void *pad_value; /* In: zVariable's pad value. */ -Int32 *status; /* Out: CDF status code. */ -{ - long dataType; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_DATATYPE_, &dataType, - NULL_); - - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (PUT_, zVAR_PADVALUE_, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(pad_value),pad_value), -#else - pad_value, -#endif - - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_zvar_sparserecords. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_zvar_sparserecords__, - cdf_set_zvar_sparserecords_, - cdf_set_zvar_sparserecords, - CDF_SET_ZVAR_SPARSERECORDS) -(id, var_num, sparse_records, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *sparse_records; /* In: zVariable's sparse records. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - PUT_, zVAR_SPARSERECORDS_, (long) *sparse_records, - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_zvar_allocrecs. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_zvar_allocrecs__, - cdf_set_zvar_allocrecs_, - cdf_set_zvar_allocrecs, - CDF_SET_ZVAR_ALLOCRECS) -(id, var_num, rec_num, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *rec_num; /* In: zVariables's allocated record number. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - PUT_, zVAR_ALLOCATERECS_, (long) *rec_num, - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_zvar_allocblockrecs. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_zvar_allocblockrecs__, - cdf_set_zvar_allocblockrecs_, - cdf_set_zvar_allocblockrecs, - CDF_SET_ZVAR_ALLOCBLOCKRECS) -(id, var_num, start_rec, end_rec, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *start_rec; /* In: zVariables's allocated block start record no. */ -Int32 *end_rec; /* In: zVariables's allocated block end record no. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - PUT_, zVAR_ALLOCATEBLOCK_, (long) (*start_rec - 1), - (long) (*end_rec - 1), - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_zvar_initialrecs. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_zvar_initialrecs__, - cdf_set_zvar_initialrecs_, - cdf_set_zvar_initialrecs, - CDF_SET_ZVAR_INITIALRECS) -(id, var_num, num_rec, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *num_rec; /* In: zVariables's initially written records. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - PUT_, zVAR_INITIALRECS_, (long) *num_rec, - NULL_); - return; -} - -/****************************************************************************** -* CDF_put_zvar_seqdata. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_put_zvar_seqdata__, - cdf_put_zvar_seqdata_, - cdf_put_zvar_seqdata, - CDF_PUT_ZVAR_SEQDATA) -(id, var_num, data, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -void *data; /* In: CDF zVariable's data. */ -Int32 *status; /* Out: CDF status code. */ -{ - long dataType; - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVAR_, (long) (*var_num - 1), - GET_, zVAR_DATATYPE_, &dataType, - NULL_); - - if (StatusBAD(*status)) return; - - *status = (Int32) CDFlib (PUT_, zVAR_SEQDATA_, -#if defined(Fif_DESCR) - BOO(STRINGdataType(dataType), - DESCRtoREF(data),data), -#else - data, -#endif - - NULL_); - - return; -} - -/****************************************************************************** -* CDF_put_zvar_recorddata. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_put_zvar_recorddata__, - cdf_put_zvar_recorddata_, - cdf_put_zvar_recorddata, - CDF_PUT_ZVAR_RECORDDATA) -(id, var_num, rec_num, buffer, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *var_num; /* In: CDF zVariable number. */ -Int32 *rec_num; /* In: CDF zVariable record number. */ -void *buffer; /* In: zVariable's full record data. */ -Int32 *status; /* Out: CDF status code. */ -{ - long numVars, varNums[1]; - - numVars = 1; - varNums[0] = (long) (*var_num - 1); - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - zVARs_RECNUMBER_, (long) (*rec_num - 1), - PUT_, zVARs_RECDATA_, numVars, varNums, buffer, - NULL_); - return; -} - -/****************************************************************************** -* CDF_set_checksum. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_checksum__, - cdf_set_checksum_, - cdf_set_checksum, - CDF_SET_CHECKSUM) -(id, checksum, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *checksum; /* In: CDF checksum. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - PUT_, CDF_CHECKSUM_, (long) *checksum, - NULL_); - - return; -} - -/****************************************************************************** -* CDF_verify_checksum. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_verify_checksum__, - cdf_verify_checksum_, - cdf_verify_checksum, - CDF_VERIFY_CHECKSUM) -(id, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - CONFIRM_, CDF_CHECKSUM_, - NULL_); - - return; -} - -/****************************************************************************** -* CDF_select_cdf. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_select_cdf__, - cdf_select_cdf_, - cdf_select_cdf, - CDF_SELECT_CDF) -(id, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - NULL_); - - return; -} - -/****************************************************************************** -* CDF_delete_recordsforall. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_delete_recordsforall__, - cdf_delete_recordsforall_, - cdf_delete_recordsforall, - CDF_DELETE_RECORDSFORALL) -(id, startRec, endRec, status) -Int32 *id; /* In: CDF identifier. */ -Int32 startRec; /* In: Starting records to delete. */ -Int32 endRec; /* In: Ending records to delete. */ -Int32 *status; /* Out: CDF status code. */ -{ - - *status = CDFdeleteRecordsForAll (Int32ToCDFid(*id), startRec, endRec); - - return; -} - -/****************************************************************************** -* CDF_get_leapsecondlastupdated. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_get_leapsecondlastupdated__, - cdf_get_leapsecondlastupdated_, - cdf_get_leapsecondlastupdated, - CDF_GET_LEAPSECONDLASTUPDATED) -(id, lastUpdated, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *lastUpdated; /* Out: Last updated date for leap second. */ -Int32 *status; /* Out: CDF status code. */ -{ - long lastUpdatedT; - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - GET_, CDF_LEAPSECONDLASTUPDATED_, &lastUpdatedT, - NULL_); - if (StatusOK(*status)) *lastUpdated = (Int32) lastUpdatedT; - return; -} - -/****************************************************************************** -* CDF_set_leapsecondlastupdated. -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_set_leapsecondlastupdated__, - cdf_set_leapsecondlastupdated_, - cdf_set_leapsecondlastupdated, - CDF_SET_LEAPSECONDLASTUPDATED) -(id, lastUpdated, status) -Int32 *id; /* In: CDF identifier. */ -Int32 *lastUpdated; /* In: last updated date for leap second. */ -Int32 *status; /* Out: CDF status code. */ -{ - *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id), - PUT_, CDF_LEAPSECONDLASTUPDATED_, - (long)*lastUpdated, - NULL_); - return; -} - diff --git a/cdf36_3-dist/src/lib/cdfget.c b/cdf36_3-dist/src/lib/cdfget.c deleted file mode 100644 index 4db0277..0000000 --- a/cdf36_3-dist/src/lib/cdfget.c +++ /dev/null @@ -1,1816 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `get' operations. -* -* Version 1.4, 9-Sep-96, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 16-Sep-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 13-Dec-93, J Love CDF V2.4. -* V1.3 15-Dec-94, J Love CDF V2.5. -* V1.3a 9-Jan-95, J Love Encode/decode changes. More cache-residency. -* V1.3b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.3c 4-Aug-95, J Love CDFexport-related changes. -* V1.4 9-Sep-96, J Love CDF V2.6. -* V2.0 08-Apr-04, M Liu Removed call to LocateCurrentVar function as -* its offset becomes avilable when it is -* selected. -* V2.1 21-Jun-04, M Liu Modified the error message for NOT_A_CDF. -* V3.2 16-Oct-07, D Han The length of the pad value for a CDF_CHAR -* variable is the length of the variable (i.e. -* CHAR/162, etc.). If the length of the pad -* value is greater than 16, it causes -* segmentation fault for the IDL CDF interface -* routine. -******************************************************************************/ - -#include "cdflib.h" -#include "cdfrev.h" - -/****************************************************************************** -* CDFget. -******************************************************************************/ - -STATICforIDL CDFstatus CDFget (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ -CDFstatus tStatus, pStatus = CDF_OK; - -switch (Va->item) { - /**************************************************************************** - * CDF_INFO_ - ****************************************************************************/ - case CDF_INFO_: { - char CDFpathX[DU_MAX_PATH_LEN+1], CDFpathT[CDF_PATHNAME_LEN+1], *CDFpathP; - vFILE *dotFp; Logical upper_case_ext, version_numbers, no_append; - Int32 magicNumber1, magicNumber2; int i; - long *cType, *cParms, *cFileSize, *uFileSize; - CDFpathP = va_arg (Va->ap, char *); - cType = va_arg (Va->ap, long *); - cParms = va_arg (Va->ap, long *); - cFileSize = va_arg (Va->ap, long *); - uFileSize = va_arg (Va->ap, long *); - if (strlen(CDFpathP) > (size_t) CDF_PATHNAME_LEN) { - if (!sX(CDF_NAME_TRUNC,&pStatus)) return pStatus; - } - strcpyX (CDFpathT, CDFpathP, CDF_PATHNAME_LEN); -#if STRIP_TRAILING_BLANKS_FROM_CDFPATH - StripTrailingBlanks (CDFpathT); -#endif -#if defined(vms) || defined(dos) - MakeUpperString (CDFpathT); -#endif -/* if (!ValidCDFname(CDFpathT)) return BAD_CDF_NAME; */ - if (!sX(FindCDF(CDFpathT,&no_append, - &upper_case_ext, - &version_numbers),&pStatus)) return pStatus; - BuildFilePath (CDFt, CDFpathT, no_append, upper_case_ext, version_numbers, - INT32_ZERO, CDFpathX); - dotFp = V_open (CDFpathX, READ_ONLY_a_mode); - if (dotFp == NULL) return CDF_OPEN_ERROR; - if (!Read32(dotFp,&magicNumber1)) { - V_close (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - if (!Read32(dotFp,&magicNumber2)) { - V_close (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - switch (magicNumber1) { - case V1magicNUMBER_flip: - V_close (dotFp, NULL, NULL); - return ILLEGAL_ON_V1_CDF; - case V2magicNUMBER_1pre: - *cType = NO_COMPRESSION; - *cFileSize = 0; - if (!SEEKv(dotFp,0L,vSEEK_END)) { - V_close (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - *uFileSize = V_tell (dotFp); - break; - case V2magicNUMBER_1: - switch (magicNumber2) { - case V2magicNUMBER_2u: - *cType = NO_COMPRESSION; - *cFileSize = 0; - if (!SEEKv(dotFp,0L,vSEEK_END)) { - V_close (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - *uFileSize = V_tell (dotFp); - break; - case V2magicNUMBER_2c: { - struct CCRstruct CCR; struct CPRstruct CPR; - if (!sX(ReadCCR(dotFp,V2_CCR_OFFSET, - CCR_RECORD,&CCR, - CCR_NULL),&pStatus)) { - V_close (dotFp, NULL, NULL); - return pStatus; - } - if (CCR.uSize == 0) { - V_close (dotFp, NULL, NULL); - return EMPTY_COMPRESSED_CDF; - } - if (!sX(ReadCPR(dotFp,CCR.CPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) { - V_close (dotFp, NULL, NULL); - return pStatus; - } - *cType = (long) CPR.cType; - if (CPR.pCount > CDF_MAX_PARMS) { - V_close (dotFp, NULL, NULL); - return TOO_MANY_PARMS; - } - for (i = 0; i < CPR.pCount; i++) cParms[i] = (long) CPR.cParms[i]; - if (!SEEKv(dotFp,0L,vSEEK_END)) { - V_close (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - *cFileSize = V_tell (dotFp); - *uFileSize = (long) CCR.uSize + MAGIC_NUMBERS_SIZE; - break; - } - default: - V_close (dotFp, NULL, NULL); - return NOT_A_CDF; - } - break; - default: - V_close (dotFp, NULL, NULL); - return NOT_A_CDF_OR_NOT_SUPPORTED; - } - V_close (dotFp, NULL, NULL); - break; - } - /**************************************************************************** - * STATUS_TEXT_, - ****************************************************************************/ - case STATUS_TEXT_: { - char *textPtr; - textPtr = va_arg (Va->ap, char *); - CDFstatusText (Cur->status, textPtr); - break; - } - /**************************************************************************** - * DATATYPE_SIZE_, - ****************************************************************************/ - case DATATYPE_SIZE_: { - long dataType = va_arg (Va->ap, long); - long *numBytes = va_arg (Va->ap, long *); - if (!ValidDataType((Int32)dataType) || InValidDataType((Int32)dataType)) - return BAD_DATA_TYPE; - *numBytes = (long) CDFelemSize (dataType); - break; - } - /**************************************************************************** - * rVARs_NUMDIMS_/zVAR_NUMDIMS_ - * Note that inquiring the number of rVariable dimensions is allowed while - * in zMode. - ****************************************************************************/ - case rVARs_NUMDIMS_: { - struct CDFstruct *CDF; - long *numDims = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *numDims = CDF->rNumDims; - break; - } - case zVAR_NUMDIMS_: { - struct CDFstruct *CDF; - long *numDimsP = va_arg (Va->ap, long *); - Logical zVar; Int32 offset, numDims; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTvarSELECTED(CDF,TRUE)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,TRUE); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - if (!sX(CalcDimParms(CDF,offset,zVar,&numDims,NULL,NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - ASSIGNnotNULL (numDimsP, numDims) - break; - } - /**************************************************************************** - * rVARs_DIMSIZES_/zVAR_DIMSIZES_ - * Note that inquiring the rVariable dimension sizes is allowed while in - * zMode. - ****************************************************************************/ - case rVARs_DIMSIZES_: { - struct CDFstruct *CDF; - int dimN; - long *dimsize = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - for (dimN = 0; dimN < CDF->rNumDims; dimN++) { - dimsize[dimN] = CDF->rDimSizes[dimN]; - } - break; - } - case zVAR_DIMSIZES_: { - struct CDFstruct *CDF; Logical zVar; - Int32 offset, numDims, dimSizes[CDF_MAX_DIMS]; - long *dimSizesP = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTvarSELECTED(CDF,TRUE)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,TRUE); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - if (!sX(CalcDimParms(CDF,offset,zVar,&numDims,dimSizes,NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - ASSIGNnotNULLarray (dimSizesP, numDims, dimSizes) - break; - } - /**************************************************************************** - * CDF_ENCODING_, - ****************************************************************************/ - case CDF_ENCODING_: { - struct CDFstruct *CDF; - long *encoding = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *encoding = (long) CDF->encoding; - break; - } - /**************************************************************************** - * CDF_MAJORITY_, - ****************************************************************************/ - case CDF_MAJORITY_: { - struct CDFstruct *CDF; - long *majority = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *majority = BOO(CDF->rowMajor,ROW_MAJOR,COLUMN_MAJOR); - break; - } - /**************************************************************************** - * CDF_FORMAT_, - ****************************************************************************/ - case CDF_FORMAT_: { - struct CDFstruct *CDF; - long *format = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *format = BOO(CDF->singleFile,SINGLE_FILE,MULTI_FILE); - break; - } - /**************************************************************************** - * CDF_CHECKSUM_, - ****************************************************************************/ - case CDF_CHECKSUM_: { - struct CDFstruct *CDF; - long *checksum = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *checksum = CDF->checksum; - break; - } - /**************************************************************************** - * CDF_COMPRESSION_ - ****************************************************************************/ - case CDF_COMPRESSION_: { - long *cType = va_arg (Va->ap, long *); /* Compression type. */ - long *cParms = va_arg (Va->ap, long *); /* Compression parameters. */ - long *cPct = va_arg (Va->ap, long *); /* Compression percentage. */ - struct CDFstruct *CDF; struct CCRstruct CCR; struct CPRstruct CPR; - int i; Int32 cTotal, uTotal; - SelectCDF (Cur->cdf, CDF) - /************************************************************************** - * If multi-file or uncompressed... - **************************************************************************/ - if (!CDF->singleFile || CDF->uDotFp == NULL) { - *cType = NO_COMPRESSION; - *cPct = 100; - break; - } - /************************************************************************** - * ...otherwise, read the CCR and CPR. - **************************************************************************/ - if (!sX(ReadCCR(CDF->dotFp,V2_CCR_OFFSET, - CCR_RECORD,&CCR, - CCR_NULL),&pStatus)) return pStatus; - if (!sX(ReadCPR(CDF->dotFp,CCR.CPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) return pStatus; - *cType = CPR.cType; - if (CPR.pCount > CDF_MAX_PARMS) return TOO_MANY_PARMS; - for (i = 0; i < CPR.pCount; i++) cParms[i] = CPR.cParms[i]; - /************************************************************************** - * Calculate the percentage. If the `uSize' field of the CCR is zero, - * then the compressed CDF is empty (and the percentage is unknown). - **************************************************************************/ - if (CCR.uSize == 0) - *cPct = 0; - else { - cTotal = MAGIC_NUMBERS_SIZE + CCR.RecordSize + CPR.RecordSize; - uTotal = MAGIC_NUMBERS_SIZE + CCR.uSize; - *cPct = (long) (((100.0 * cTotal) / uTotal) + 0.5); - } - break; - } - /**************************************************************************** - * CDF_COPYRIGHT_ - ****************************************************************************/ - case CDF_COPYRIGHT_: { - struct CDFstruct *CDF; - char *copyRight = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - if (!sX(ReadCDR(CDF->fp,CDF->CDRoffset, - CDR_COPYRIGHT,copyRight, - CDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - copyRight[CDF_COPYRIGHT_LEN] = NUL; - break; - } - /**************************************************************************** - * LIB_COPYRIGHT_ - ****************************************************************************/ - case LIB_COPYRIGHT_: { - char *copyRight = va_arg (Va->ap, char *); - CDFcopyRight (copyRight); - break; - } - /**************************************************************************** - * CDF_NUMrVARS_/CDF_NUMzVARS_ - * Inquire number of r/z variables. When in zMode, the number of - * rVariables is always zero (0). (Inquiring the number of rVariables - * while in zMode is one of the few legal rVariable operations). - ****************************************************************************/ - case CDF_NUMrVARS_: - case CDF_NUMzVARS_: { - Logical zOp = (Va->item == CDF_NUMzVARS_); - struct CDFstruct *CDF; - long *numVars = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (zModeON(CDF)) - *numVars = BOO(zOp,CDF->NrVars + CDF->NzVars,0); - else - *numVars = BOO(zOp,CDF->NzVars,CDF->NrVars); - break; - } - /**************************************************************************** - * CDF_NUMATTRS_, - ****************************************************************************/ - case CDF_NUMATTRS_: { - struct CDFstruct *CDF; - long *numAttrs = va_arg (Va->ap, long *); - Int32 tNumAttrs; - SelectCDF (Cur->cdf, CDF) - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_NUMATTR,&tNumAttrs, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *numAttrs = tNumAttrs; - break; - } - /**************************************************************************** - * CDF_NUMgATTRS_/CDF_NUMvATTRS_ - ****************************************************************************/ - case CDF_NUMvATTRS_: - case CDF_NUMgATTRS_: { - Logical gOp = (Va->item == CDF_NUMgATTRS_); - struct CDFstruct *CDF; - long *numAttrs = va_arg (Va->ap, long *); - Int32 totalAttrs, offset, scope; - int attrX; - SelectCDF (Cur->cdf, CDF) - *numAttrs = 0; - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_NUMATTR,&totalAttrs, - GDR_ADRHEAD,&offset, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - for (attrX = 0; attrX < totalAttrs; attrX++) { - CDF->fp->CurADRIndex = attrX; - if (!sX(ReadADR(CDF->fp,offset, - ADR_SCOPE,&scope, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if ((gOp && GLOBALscope(scope)) || - (!gOp && VARIABLEscope(scope))) (*numAttrs)++; - if (!sX(ReadADR(CDF->fp,offset, - ADR_ADRNEXT,&offset, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - break; - } - /**************************************************************************** - * rVARs_MAXREC_/zVARs_MAXREC_ - * Maximum record number of all of the rVariables/zVariables. Note that - * inquiring the maximum rVariable record number is allowed while in zMode. - ****************************************************************************/ - case rVARs_MAXREC_: { - struct CDFstruct *CDF; - long *maxRec = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (zModeON(CDF)) - *maxRec = NO_RECORD; - else - *maxRec = CDF->rMaxRec; - break; - } - case zVARs_MAXREC_: { - struct CDFstruct *CDF; - long *maxRec = va_arg (Va->ap, long *); - Int32 offset, tMaxRec; - SelectCDF (Cur->cdf, CDF) - /************************************************************************** - * If zMode is on, consider both rVariables and zVariables. If zMode is - * not on, only consider the zVariables. Because zVariables did not exist - * in CDF V2.0, the problem with the `VDRnext' offset in the last VDR does - * not have to be considered here. - **************************************************************************/ - *maxRec = BOO(zModeON(CDF),CDF->rMaxRec,NO_RECORD); - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_zVDRHEAD,&offset, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - while (offset != ZERO_OFFSET) { - if (!sX(ReadVDR(CDF,CDF->fp,offset,TRUE, - VDR_MAXREC,&tMaxRec, - VDR_VDRNEXT,&offset, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *maxRec = MAXIMUM (*maxRec, tMaxRec); - } - break; - } - /**************************************************************************** - * CDF_VERSION_, - ****************************************************************************/ - case CDF_VERSION_: { - struct CDFstruct *CDF; - long *version = va_arg (Va->ap, long *); - Int32 tVersion; - SelectCDF (Cur->cdf, CDF) - if (!sX(ReadCDR(CDF->fp,CDF->CDRoffset, - CDR_VERSION,&tVersion, - CDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *version = tVersion; - break; - } - /**************************************************************************** - * CDF_RELEASE_, - ****************************************************************************/ - case CDF_RELEASE_: { - struct CDFstruct *CDF; - long *release = va_arg (Va->ap, long *); - Int32 tRelease; - SelectCDF (Cur->cdf, CDF) - if (!sX(ReadCDR(CDF->fp,CDF->CDRoffset, - CDR_RELEASE,&tRelease, - CDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *release = tRelease; - break; - } - /**************************************************************************** - * CDF_INCREMENT_, - ****************************************************************************/ - case CDF_INCREMENT_: { - struct CDFstruct *CDF; - long *increment = va_arg (Va->ap, long *); - Int32 tIncrement; - SelectCDF (Cur->cdf, CDF) - if (!sX(ReadCDR(CDF->fp,CDF->CDRoffset, - CDR_INCREMENT,&tIncrement, - CDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *increment = tIncrement; - break; - } - /**************************************************************************** - * LIB_VERSION_, - ****************************************************************************/ - case LIB_VERSION_: { - long *version = va_arg (Va->ap, long *); - *version = CDF_LIBRARY_VERSION; - break; - } - /**************************************************************************** - * LIB_RELEASE_, - ****************************************************************************/ - case LIB_RELEASE_: { - long *release = va_arg (Va->ap, long *); - *release = CDF_LIBRARY_RELEASE; - break; - } - /**************************************************************************** - * LIB_INCREMENT_, - ****************************************************************************/ - case LIB_INCREMENT_: { - long *increment = va_arg (Va->ap, long *); - *increment = CDF_LIBRARY_INCREMENT; - break; - } - /**************************************************************************** - * LIB_subINCREMENT_, - ****************************************************************************/ - case LIB_subINCREMENT_: { - char *subincrement = va_arg (Va->ap, char *); - *subincrement = CDF_LIBRARY_subINCREMENT; - break; - } - /**************************************************************************** - * CDF_LEAPSECONDLASTUPDATED_, - ****************************************************************************/ - case CDF_LEAPSECONDLASTUPDATED_: { - long *lastUpdated = va_arg (Va->ap, long *); - *lastUpdated = -1L; - break; - } - /**************************************************************************** - * rVAR_NAME_/zVAR_NAME_ - * Note that a temporary variable is used when reading the variable name. - * This is because the caller may have only allocated enough memory for the - * size name they expect (ie., less than CDF_VAR_NAME_LEN characters). Since - * the variable name is NUL-terminated in the CDF, only the actual characters - * of the name will be copied to the caller's buffer. - ****************************************************************************/ - case rVAR_NAME_: - case zVAR_NAME_: { - Logical zOp = (Va->item == zVAR_NAME_), zVar; - struct CDFstruct *CDF; - char *varName = va_arg (Va->ap, char *), tName[CDF_VAR_NAME_LEN+1]; - Int32 offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_NAME,tName, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - strcpyX (varName, tName, CDF_VAR_NAME_LEN); - break; - } - /**************************************************************************** - * rVAR_DATATYPE_/zVAR_DATATYPE_ - * If this for an rVarible named "EPOCH" in a CDF prior to CDF V2.1.1, - * then return the CDF_EPOCH data type if the actual data type is CDF_REAL8 - * or CDF_DOUBLE. (The CDF_EPOCH data type was not introduced until CDF - * V2.1.1). Note that only rVariables were supported prior to CDF V2.3. - ****************************************************************************/ - case rVAR_DATATYPE_: - case zVAR_DATATYPE_: { - Logical zOp = (Va->item == zVAR_DATATYPE_), zVar; - struct CDFstruct *CDF; - long *dataType = va_arg (Va->ap, long *); - Int32 tDataType, offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_DATATYPE,&tDataType, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!zVar && CDF->fakeEPOCH) { - char varName[CDF_VAR_NAME_LEN+1]; - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_NAME,varName, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!strcmpITB(varName,"EPOCH") && FLOAT8dataType(tDataType)) { - tDataType = CDF_EPOCH; - } else if (!strcmpITB(varName,"EPOCH") && FLOAT16dataType(tDataType)) { - tDataType = CDF_EPOCH16; - } - } - *dataType = tDataType; - break; - } - /**************************************************************************** - * rVAR_NUMELEMS_/zVAR_NUMELEMS_, - ****************************************************************************/ - case rVAR_NUMELEMS_: - case zVAR_NUMELEMS_: { - Logical zOp = (Va->item == zVAR_NUMELEMS_), zVar; - struct CDFstruct *CDF; - long *numElements = va_arg (Va->ap, long *); - Int32 offset, tNumElems; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_NUMELEMS,&tNumElems, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *numElements = tNumElems; - break; - } - /**************************************************************************** - * rVAR_RECVARY_/zVAR_RECVARY_, - ****************************************************************************/ - case rVAR_RECVARY_: - case zVAR_RECVARY_: { - Logical zOp = (Va->item == zVAR_RECVARY_), zVar; - struct CDFstruct *CDF; - long *recVary = va_arg (Va->ap, long *); - Int32 flags, offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_FLAGS,&flags, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *recVary = BOO(RECvaryBITset(flags),VARY,NOVARY); - break; - } - /**************************************************************************** - * rVAR_DIMVARYS_/zVAR_DIMVARYS_, - ****************************************************************************/ - case rVAR_DIMVARYS_: - case zVAR_DIMVARYS_: { - Logical zOp = (Va->item == zVAR_DIMVARYS_), zVar; - struct CDFstruct *CDF; Int32 offset, numDims, dimVarys[CDF_MAX_DIMS]; - long *dimVarysP = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - if (!sX(CalcDimParms(CDF,offset,zVar,&numDims,NULL,dimVarys),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - ASSIGNnotNULLarray (dimVarysP, numDims, dimVarys) - break; - } - /**************************************************************************** - * rVAR_MAXREC_/zVAR_MAXREC_, - ****************************************************************************/ - case rVAR_MAXREC_: - case zVAR_MAXREC_: { - Logical zOp = (Va->item == zVAR_MAXREC_), zVar; - struct CDFstruct *CDF; Int32 offset, tMaxRec; - long *maxRec = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_MAXREC,&tMaxRec, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *maxRec = (long) tMaxRec; - break; - } - /**************************************************************************** - * rVAR_MAXallocREC_/zVAR_MAXallocREC_, - ****************************************************************************/ - case rVAR_MAXallocREC_: - case zVAR_MAXallocREC_: { - Logical zOp = (Va->item == zVAR_MAXallocREC_), zVar; - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 offset, maxRec, lastAllocatedRecN; int vType; - long *maxAllocated = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_MAXREC,&maxRec, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(VariableType(CDF,offset,zVar,&vType),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - - /************************************************************************** - * If a single-file CDF, pass back the maximum record number allocated. - * If a multi-file CDF, pass back the maximum record number written (which - * will always be the maximum record allocated). - **************************************************************************/ - if (CDF->singleFile) { - if (!sX(LastRecord(CDF,offset,zVar,&lastAllocatedRecN),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (vType == SPARSE_RECORDS_) { - if (Var != NULL) { - if (Var->stage.areaOffset64 != (OFF_T) NO_OFFSET64 && - Var->stage.firstRec != NO_RECORD) { - Int32 tmp = (Var->stage.lastRec > maxRec ? maxRec : - Var->stage.lastRec); - lastAllocatedRecN += (tmp - Var->stage.firstRec + 1); - } - } - } else if (vType == COMPRESSED_ || - vType == SPARSE_COMPRESSED_RECORDS_) { - if (Var != NULL) { - if (Var->stage.areaOffset64 != (OFF_T) NO_OFFSET64 && - Var->stage.firstRec != NO_RECORD && - Var->stage.dotOffset64 == (OFF_T) NO_OFFSET64) { - Int32 tmp = (Var->stage.lastRec > maxRec ? maxRec : - Var->stage.lastRec); - lastAllocatedRecN += (tmp - Var->stage.firstRec + 1); - } - } - } - *maxAllocated = lastAllocatedRecN; - } - else - *maxAllocated = (long) maxRec; - break; - } - /**************************************************************************** - * rVAR_NUMRECS_/zVAR_NUMRECS_, - ****************************************************************************/ - case rVAR_NUMRECS_: - case zVAR_NUMRECS_: { - Logical zOp = (Va->item == zVAR_NUMRECS_), zVar; struct VarStruct *Var; - struct CDFstruct *CDF; Int32 vdrOffset, nRecords; int vType; - Int32 tMaxRec; - long *nRecordsP = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) vdrOffset = CDF->CURzVarOffset; - else vdrOffset = CDF->CURrVarOffset; - - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - - if (!sX(ReadVDR(CDF,CDF->fp,vdrOffset,zVar, - VDR_MAXREC,&tMaxRec, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(VariableType(CDF,vdrOffset,zVar,&vType),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Depending on the variable type... - **************************************************************************/ - switch (vType) { - case SPARSE_RECORDS_: - if (!sX(IndexingStatistics(CDF,vdrOffset,zVar, - NULL,NULL,NULL, - &nRecords,NULL),&pStatus)) return pStatus; - if (Var != NULL) { - if (Var->stage.areaOffset != NO_OFFSET && - Var->stage.firstRec != NO_RECORD) { - Int32 tmp = (Var->stage.lastRec > tMaxRec ? tMaxRec : Var->stage.lastRec); - nRecords += (tmp - Var->stage.firstRec + 1); - } - } - break; - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - if (!sX(IndexingStatistics(CDF,vdrOffset,zVar, - NULL,NULL,NULL, - &nRecords,NULL),&pStatus)) return pStatus; - if (Var != NULL) { - if (Var->stage.areaOffset != NO_OFFSET && - Var->stage.firstRec != NO_RECORD && - Var->stage.dotOffset == NO_OFFSET) { - Int32 tmp = (Var->stage.lastRec > tMaxRec ? tMaxRec : Var->stage.lastRec); - nRecords += (tmp - Var->stage.firstRec + 1); - } - } - break; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return CDF_INTERNAL_ERROR; - case STANDARD_: - case IN_MULTI_: { - Int32 maxRec; - if (!sX(ReadVDR(CDF,CDF->fp,vdrOffset,zVar, - VDR_MAXREC,&maxRec, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - nRecords = maxRec + 1; - break; - } - } - ASSIGNnotNULL (nRecordsP, nRecords) - break; - } - /**************************************************************************** - * rVAR_NUMallocRECS_/zVAR_NUMallocRECS_, - ****************************************************************************/ - case rVAR_NUMallocRECS_: - case zVAR_NUMallocRECS_: { - Logical zOp = (Va->item == zVAR_NUMallocRECS_), zVar; - struct CDFstruct *CDF; Int32 offset, nAllocated; int vType; - Int32 tMaxRec; struct VarStruct *Var; - long *nAllocatedP = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_MAXREC,&tMaxRec, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(VariableType(CDF,offset,zVar,&vType),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Depending on the variable type... - **************************************************************************/ - switch (vType) { - case STANDARD_: - case SPARSE_RECORDS_: - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: { - - if (!sX(IndexingStatistics(CDF,offset, - zVar,NULL,NULL, - &nAllocated, - NULL,NULL),&pStatus)) return pStatus; - if (vType == SPARSE_RECORDS_) { - if (Var != NULL) { - if (Var->stage.areaOffset != NO_OFFSET && - Var->stage.firstRec != NO_RECORD) { - Int32 tmp = (Var->stage.lastRec > tMaxRec ? tMaxRec : - Var->stage.lastRec); - nAllocated += (tmp - Var->stage.firstRec + 1); - } - } - } else if (vType == COMPRESSED_ || - vType == SPARSE_COMPRESSED_RECORDS_) { - if (Var != NULL) { - if (Var->stage.areaOffset != NO_OFFSET && - Var->stage.firstRec != NO_RECORD && - Var->stage.dotOffset == NO_OFFSET) { - Int32 tmp = (Var->stage.lastRec > tMaxRec ? tMaxRec : - Var->stage.lastRec); - nAllocated += (tmp - Var->stage.firstRec + 1); - } - } - } - break; - } - case IN_MULTI_: { - Int32 maxRec; - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_MAXREC,&maxRec, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - nAllocated = maxRec + 1; - break; - } - } - ASSIGNnotNULL (nAllocatedP, nAllocated) - break; - } - /**************************************************************************** - * rVAR_ALLOCATEDFROM_/zVAR_ALLOCATEDFROM_ - * Determines the next allocated record AT or AFTER `startRec' (meaning that - * `startRec' could be the record number returned). - ****************************************************************************/ - case rVAR_ALLOCATEDFROM_: - case zVAR_ALLOCATEDFROM_: { - Logical zOp = (Va->item == zVAR_ALLOCATEDFROM_), zVar, found; - struct CDFstruct *CDF; Int32 offset, nextRec; - Int32 startRec = (Int32) va_arg (Va->ap, long); - long *fromRec = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (startRec <= NO_RECORD) return BAD_REC_NUM; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - if (!sX(NextRecord(CDF,offset,zVar,startRec,&nextRec,&found),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!found) return NO_SUCH_RECORD; - *fromRec = (long) nextRec; - break; - } - /**************************************************************************** - * rVAR_ALLOCATEDTO_/zVAR_ALLOCATEDTO_ - * Determines the last record (before the next unallocated record) allocated - * AT or AFTER `startRec'. This can span non-contiguous blocks of records. - ****************************************************************************/ - case rVAR_ALLOCATEDTO_: - case zVAR_ALLOCATEDTO_: { - Logical zOp = (Va->item == zVAR_ALLOCATEDTO_), zVar, found; - struct CDFstruct *CDF; Int32 vdrOffset, lastRec; - Int32 startRec = (Int32) va_arg (Va->ap, long); - long *toRec = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (startRec <= NO_RECORD) return BAD_REC_NUM; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) vdrOffset = CDF->CURzVarOffset; - else vdrOffset = CDF->CURrVarOffset; - - /************************************************************************** - * Determine the last record in the block containing the starting record. - **************************************************************************/ - if (!sX(SearchForRecord(CDF,vdrOffset,zVar,startRec, - NULL,&lastRec,NULL,&found),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!found) return NO_SUCH_RECORD; - /************************************************************************** - * Keep searching until an unallocated record is encountered. - **************************************************************************/ - while (found) { - Int32 nextRec = (Int32) (lastRec + 1); - if (!sX(SearchForRecord(CDF,vdrOffset,zVar,nextRec, - NULL,&lastRec,NULL,&found),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Return the last allocated record detected. - **************************************************************************/ - *toRec = (long) lastRec; - break; - } - /**************************************************************************** - * rVAR_COMPRESSION_/zVAR_COMPRESSION_ - ****************************************************************************/ - case rVAR_COMPRESSION_: - case zVAR_COMPRESSION_: { - Logical zOp = (Va->item == zVAR_COMPRESSION_), zVar; - struct CDFstruct *CDF; /* struct VarStruct *Var; */ struct CPRstruct CPR; - Int32 VDRoffset, PRoffset, flags; int parmN; - long *cType = va_arg (Va->ap, long *); /* Compression type. */ - long *cParms = va_arg (Va->ap, long *); /* Compression parameters. */ - long *cPct = va_arg (Va->ap, long *); /* Compression percentage. */ - /************************************************************************** - * Select/validate/locate CDF and variable. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) VDRoffset = CDF->CURzVarOffset; - else VDRoffset = CDF->CURrVarOffset; - - /************************************************************************** - * Read fields from VDR. - **************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,VDRoffset,zVar, - VDR_FLAGS,&flags, - VDR_CPRorSPR,&PRoffset, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * If the compression bit is set, read the CPR. - **************************************************************************/ - if (VARcompressionBITset(flags)) { - if (!sX(ReadCPR(CDF->fp,PRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *cType = CPR.cType; - for (parmN = 0; parmN < CPR.pCount; parmN++) { - cParms[parmN] = CPR.cParms[parmN]; - } - if (!sX(CalcCompressionPct(CDF,VDRoffset,zVar,cPct),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - else { - *cType = NO_COMPRESSION; - *cPct = 100; - } - break; - } - /**************************************************************************** - * rVAR_SPARSEARRAYS_/zVAR_SPARSEARRAYS_ - ****************************************************************************/ - case rVAR_SPARSEARRAYS_: - case zVAR_SPARSEARRAYS_: { - Logical zOp = (Va->item == zVAR_SPARSEARRAYS_), zVar; - struct CDFstruct *CDF; /* struct VarStruct *Var; */ struct SPRstruct SPR; - Int32 VDRoffset, PRoffset, flags; int parmN; - long *sArraysType = va_arg (Va->ap, long *); /* Sparseness type. */ - long *sArraysParms = va_arg (Va->ap, long *); /* Sparseness parameters. */ - long *sArraysPct = va_arg (Va->ap, long *); /* Sparseness percentage. */ - /************************************************************************** - * Select/validate/locate CDF and variable. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) VDRoffset = CDF->CURzVarOffset; - else VDRoffset = CDF->CURrVarOffset; - - /************************************************************************** - * Read fields from VDR. - **************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,VDRoffset,zVar, - VDR_FLAGS,&flags, - VDR_CPRorSPR,&PRoffset, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * If the sparse arrays bit is set, read the SPR. - **************************************************************************/ - if (SPARSEarraysBITset(flags)) { - if (!sX(ReadSPR(CDF->fp,PRoffset, - SPR_RECORD,&SPR, - SPR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *sArraysType = SPR.sArraysType; - for (parmN = 0; parmN < SPR.pCount; parmN++) { - sArraysParms[parmN] = SPR.sArraysParms[parmN]; - } - *sArraysPct = 100; - } - else { - *sArraysType = NO_SPARSEARRAYS; - *sArraysPct = 100; - } - break; - } - /**************************************************************************** - * rVAR_SPARSERECORDS_/zVAR_SPARSERECORDS_ - ****************************************************************************/ - case rVAR_SPARSERECORDS_: - case zVAR_SPARSERECORDS_: { - Logical zOp = (Va->item == zVAR_SPARSERECORDS_), zVar; - struct CDFstruct *CDF; /* struct VarStruct *Var; */ - Int32 VDRoffset, sRecords; - long *sRecordsType = va_arg (Va->ap, long *); - /************************************************************************** - * Select/validate/locate CDF and variable. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) VDRoffset = CDF->CURzVarOffset; - else VDRoffset = CDF->CURrVarOffset; - - /************************************************************************** - * Read sparse records field from VDR. - **************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,VDRoffset,zVar, - VDR_sRECORDS,&sRecords, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *sRecordsType = sRecords; - break; - } - /**************************************************************************** - * rVAR_NUMBER_/zVAR_NUMBER_ - * Determines the variable number for a specified variable name. - ****************************************************************************/ - case rVAR_NUMBER_: - case zVAR_NUMBER_: { - Logical zOp = (Va->item == zVAR_NUMBER_), zVar; - struct CDFstruct *CDF; - char *varName = va_arg (Va->ap, char *); - long *varNum = va_arg (Va->ap, long *); - Int32 varN, offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - tStatus = FindVarByName (CDF, varName, &offset, &zVar, NULL); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_VAR: - return tStatus; - default: - if (!sX(tStatus,&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return tStatus; - } - } - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_NUM,&varN, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (zModeON(CDF)) - *varNum = BOO(zVar,CDF->NrVars,0) + varN; - else - if (zOp) - if (zVar) - *varNum = varN; - else - return NO_SUCH_VAR; /* Wrong type of variable. */ - else - if (zVar) - return NO_SUCH_VAR; /* Wrong type of variable. */ - else - *varNum = varN; - break; - } - /**************************************************************************** - * rVAR_BLOCKINGFACTOR_/zVAR_BLOCKINGFACTOR_, - ****************************************************************************/ - case rVAR_BLOCKINGFACTOR_: - case zVAR_BLOCKINGFACTOR_: { - Logical zOp = (Va->item == zVAR_BLOCKINGFACTOR_), zVar; - struct CDFstruct *CDF; - long *nExtendRecs = va_arg (Va->ap, long *); - Int32 tRecs, offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_BLOCKING,&tRecs, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *nExtendRecs = tRecs; - break; - } - /**************************************************************************** - * rVAR_nINDEXRECORDS_/zVAR_nINDEXRECORDS_, - * rVAR_nINDEXENTRIES_/zVAR_nINDEXENTRIES_, - * rVAR_nINDEXLEVELS_/zVAR_nINDEXLEVELS_, - ****************************************************************************/ - case rVAR_nINDEXRECORDS_: - case zVAR_nINDEXRECORDS_: - case rVAR_nINDEXENTRIES_: - case zVAR_nINDEXENTRIES_: - case rVAR_nINDEXLEVELS_: - case zVAR_nINDEXLEVELS_: { - Logical zOp = (Va->item == zVAR_nINDEXRECORDS_ || - Va->item == zVAR_nINDEXENTRIES_ || - Va->item == zVAR_nINDEXLEVELS_), zVar; - struct CDFstruct *CDF; Int32 offset, count; - long *countP = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - /************************************************************************** - * If a multi-file CDF, pass back a count of zero (0) and an info/warning - * status code. If a single-file CDF, scan through the linked list of VXRs - * counting the parameter requested. - **************************************************************************/ - if (!CDF->singleFile) { - count = 0; - sX (MULTI_FILE_FORMAT, &pStatus); - } - else { - switch (Va->item) { - case rVAR_nINDEXRECORDS_: - case zVAR_nINDEXRECORDS_: - if (!sX(IndexingStatistics(CDF,offset,zVar, - &count,NULL,NULL, - NULL,NULL),&pStatus)) return pStatus; - break; - case rVAR_nINDEXENTRIES_: - case zVAR_nINDEXENTRIES_: - if (!sX(IndexingStatistics(CDF,offset,zVar, - NULL,&count,NULL, - NULL,NULL),&pStatus)) return pStatus; - break; - case rVAR_nINDEXLEVELS_: - case zVAR_nINDEXLEVELS_: - if (!sX(IndexingStatistics(CDF,offset,zVar, - NULL,NULL,NULL, - NULL,&count),&pStatus)) return pStatus; - break; - } - } - ASSIGNnotNULL (countP, count) - break; - } - /**************************************************************************** - * rVAR_PADVALUE_/zVAR_PADVALUE_ - ****************************************************************************/ - case rVAR_PADVALUE_: - case zVAR_PADVALUE_: { - Logical zOp = (Va->item == zVAR_PADVALUE_), zVar; - struct CDFstruct *CDF; - void *padValue = va_arg (Va->ap, void *); - Int32 offset, dataType, numElems, flags; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_FLAGS,&flags, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - - /********************************************************************** - The length of the pad value for a CDF_CHAR variable is the - length of the variable (i.e. CHAR/162, etc.). If the length - of the pad value is greater than 16, it causes segmentation fault - for the IDL CDF interface routine. - ***********************************************************************/ - if (STRINGdataType(dataType)) - numElems = 1; - - if (PADvalueBITset(flags)) { - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_PADVALUE,padValue, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(ConvertBuffer(CDF->encoding,CDF->decoding, - CDF->negToPosFp0,dataType, - numElems,padValue,padValue),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - else { - DefaultPadValuePre350 (dataType, numElems, padValue); - if (!sX(ConvertBuffer(HostEncoding(),CDF->decoding, - CDF->negToPosFp0,dataType, - numElems,padValue,padValue),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - sX (NO_PADVALUE_SPECIFIED, &pStatus); - } - break; - } - /**************************************************************************** - * rVAR_DATA_/zVAR_DATA_, - ****************************************************************************/ - case rVAR_DATA_: - case zVAR_DATA_: { - Logical zOp = (Va->item == zVAR_DATA_); - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 phyRecNum, offset; struct rdSTRUCT *rd; - char *value = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - rd = BOO(zModeON(CDF),&(Var->zRD),BOO(zOp,&(Var->zRD),&(CDF->rRD))); - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar(CDF,Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - phyRecNum = BOO(Var->recVary,rd->recNumber,0); - offset = IndicesValueOffset(Var->numDims, - rd->dimIndices, - Var->dimVarys, - Var->nPhyDimValues) * Var->NvalueBytes; - if (!sX(ReadVarValues(CDF,Var,phyRecNum, - offset,INT32_ONE,value),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->accessed_at = CDF->pseudo_clock++; - break; - } - /**************************************************************************** - * rVAR_HYPERDATA_/zVAR_HYPERDATA_, - ****************************************************************************/ - case rVAR_HYPERDATA_: - case zVAR_HYPERDATA_: { - Logical zOp = (Va->item == zVAR_HYPERDATA_); - struct CDFstruct *CDF; - struct VarStruct *Var; - int dimN; - struct rdSTRUCT *rd; -#if LIMITof64K - long Nvalues, Nbytes; -#endif - char *buffer = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - rd = BOO(zModeON(CDF),&(Var->zRD),BOO(zOp,&(Var->zRD),&(CDF->rRD))); - for (dimN = 0; dimN < Var->numDims; dimN++) { - long maxIndex = rd->dimIndices[dimN] + - ((rd->dimCounts[dimN] - 1) * rd->dimIntervals[dimN]); - if (maxIndex >= Var->dimSizes[dimN]) return BAD_DIM_INDEX; - } -#if LIMITof64K - Nvalues = rd->recCount; - for (dimN = 0; dimN < Var->numDims; dimN++) Nvalues *= rd->dimCounts[dimN]; - Nbytes = Nvalues * Var->NvalueBytes; - if (TOObigIBMpc(Nbytes)) return IBM_PC_OVERFLOW; -#endif - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar(CDF,Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - if (!sX(HyperRead(CDF,Var,rd,buffer),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->accessed_at = CDF->pseudo_clock++; - break; - } - /**************************************************************************** - * rVAR_SEQDATA_/zVAR_SEQDATA_, - ****************************************************************************/ - case rVAR_SEQDATA_: - case zVAR_SEQDATA_: { - Logical zOp = (Va->item == zVAR_SEQDATA_); - struct CDFstruct *CDF; struct VarStruct *Var; Int32 recNum, offset; - void *value = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar(CDF,Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - recNum = Var->seqValueOffset / Var->NphyRecValues; - if (recNum > Var->maxRec) return END_OF_VAR; - offset = (Var->seqValueOffset % Var->NphyRecValues) * Var->NvalueBytes; - if (!sX(ReadVarValues(CDF,Var,recNum,offset,INT32_ONE,value),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->seqValueOffset++; - Var->accessed_at = CDF->pseudo_clock++; - break; - } - /**************************************************************************** - * rVARs_RECDATA_/zVARs_RECDATA_ - * Read data records for up to all of the rVariables/zVariables. - ****************************************************************************/ - case rVARs_RECDATA_: - case zVARs_RECDATA_: { - Logical zOp = (Va->item == zVARs_RECDATA_), zVar; - struct VarStruct *Var; struct CDFstruct *CDF; - Int32 recNum, varNt; Byte1 *tBuffer; int varX; - long nVars = va_arg (Va->ap, long); - long *varNs = va_arg (Va->ap, long *); - void *buffer = va_arg (Va->ap, char *); -#if LIMITof64K - long nBytes; -#endif - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (nVars < 1) return BAD_NUM_VARS; - for (varX = 0; varX < nVars; varX++) { - if (!sX(VarIdentity(CDF,(Int32)varNs[varX], - zOp,&varNt,&zVar,NULL),&pStatus)) { - return pStatus; - } - if (!sX(InitVar(CDF,varNt,zVar,NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } -#if LIMITof64K - for (varX = 0, nBytes = 0; varX < nVars; varX++) { - if (!sX(VarIdentity(CDF,varNs[varX],zOp,NULL,NULL,&Var),&pStatus)) { - return pStatus; - } - nBytes += Var->NphyRecBytes; - } - if (TOObigIBMpc(nBytes)) return IBM_PC_OVERFLOW; -#endif - for (varX = 0, tBuffer = buffer; varX < nVars; varX++) { - if (!sX(VarIdentity(CDF,(Int32)varNs[varX], - zOp,NULL,NULL,&Var),&pStatus)) { - return pStatus; - } - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar(CDF,Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - recNum = BOO(Var->recVary,BOO(zOp,Var->zRD.recNumber, - CDF->rRD.recNumber),0); - if (!sX(ReadVarValues(CDF,Var,recNum,INT32_ZERO, - Var->NphyRecValues,tBuffer),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - tBuffer += (size_t) Var->NphyRecBytes; - Var->accessed_at = CDF->pseudo_clock++; - } - - break; - } - /**************************************************************************** - * ATTR_NAME_, - * Note that a temporary variable is used when reading the attribute name. - * This is because the caller may have only allocated enough memory for the - * size name they expect (ie., less than CDF_ATTR_NAME_LEN characters). Since - * the attribute name is NUL-terminated in the CDF, only the actual characters - * of the name will be copied to the caller's buffer. - ****************************************************************************/ - case ATTR_NAME_: { - struct CDFstruct *CDF; - char *attrName = va_arg (Va->ap, char *), tName[CDF_ATTR_NAME_LEN+1]; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED(CDF)) return NO_ATTR_SELECTED; - if (!sX(ReadADR(CDF->fp,CDF->CURattrOffset, - ADR_NAME,tName, - ADR_NULL),&pStatus)){ - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - strcpyX (attrName, tName, CDF_ATTR_NAME_LEN); - break; - } - /**************************************************************************** - * ATTR_NUMBER_, - ****************************************************************************/ - case ATTR_NUMBER_: { - struct CDFstruct *CDF; - char *attrName = va_arg (Va->ap, char *); - long *attrNum = va_arg (Va->ap, long *); - Int32 attrNumT, offset; - SelectCDF (Cur->cdf, CDF) - tStatus = FindAttrByName (CDF, attrName, &offset); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_ATTR: - return tStatus; - default: - if (!sX(tStatus,&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return tStatus; - } - } - if (!sX(ReadADR(CDF->fp,offset, - ADR_NUM,&attrNumT, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *attrNum = attrNumT; - break; - } - /**************************************************************************** - * ATTR_SCOPE_, - ****************************************************************************/ - case ATTR_SCOPE_: { - struct CDFstruct *CDF; - long *scope = va_arg (Va->ap, long *); - Int32 tScope; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED(CDF)) return NO_ATTR_SELECTED; - if (!sX(ReadADR(CDF->fp,CDF->CURattrOffset, - ADR_SCOPE,&tScope, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - *scope = DEFINITEscope(tScope); - break; - } - /**************************************************************************** - * ATTR_MAXgENTRY_/ATTR_MAXrENTRY_/ATTR_MAXzENTRY_ - * ATTR_NUMgENTRIES_/ATTR_NUMrENTRIES_/ATTR_NUMzENTRIES_ - ****************************************************************************/ - case ATTR_MAXgENTRY_: - case ATTR_NUMgENTRIES_: - case ATTR_MAXrENTRY_: - case ATTR_NUMrENTRIES_: - case ATTR_MAXzENTRY_: - case ATTR_NUMzENTRIES_: { - Logical maxOp = ONEof3(Va->item,ATTR_MAXgENTRY_, - ATTR_MAXrENTRY_, - ATTR_MAXzENTRY_); - int entryType = BOO(maxOp,E3p(Va->item,ATTR_MAXgENTRY_, - ATTR_MAXrENTRY_, - ATTR_MAXzENTRY_), - E3p(Va->item,ATTR_NUMgENTRIES_, - ATTR_NUMrENTRIES_, - ATTR_NUMzENTRIES_)); - struct CDFstruct *CDF; - long *value = va_arg (Va->ap, long *); - Int32 scope, gr, z; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED(CDF)) return NO_ATTR_SELECTED; - if (!sX(ReadADR(CDF->fp,CDF->CURattrOffset, - ADR_SCOPE,&scope, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (GLOBALscope(scope)) { - if (entryType != gENTRYt) return ILLEGAL_FOR_SCOPE; - } - else { - if (entryType == gENTRYt) return ILLEGAL_FOR_SCOPE; - } - if (!sX(ReadADR(CDF->fp,CDF->CURattrOffset, - BOO(maxOp,ADR_MAXgrENTRY,ADR_NgrENTRIES),&gr, - BOO(maxOp,ADR_MAXzENTRY,ADR_NzENTRIES),&z, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (GLOBALscope(scope)) - *value = (long) gr; - else - if (zModeON(CDF)) - if (entryType == rENTRYt) - *value = (long) BOO(maxOp,NO_ENTRY,0); - /* Never any rEntries in zMode. */ - else - *value = (long) BOO(maxOp,BOO(z > NO_ENTRY,CDF->NrVars+z,gr),gr+z); - else - *value = (long) E3(entryType,BOO(maxOp,NO_ENTRY,0),gr,z); - break; - } - /**************************************************************************** - * gENTRY_DATATYPE_/rENTRY_DATATYPE_/zENTRY_DATATYPE_ - * gENTRY_NUMELEMS_/rENTRY_NUMELEMS_/zENTRY_NUMELEMS_ - * If this CDF is prior to CDF V2.1.1, the current attribute is named - * "VALIDMIN", "VALIDMAX", "SCALEMIN", or "SCALEMAX", this is a true rEntry, - * and the rEntry corresponds to an rVariable named "EPOCH", then return - * the CDF_EPOCH data type if the actual data type is CDF_REAL8 or CDF_DOUBLE. - * (The CDF_EPOCH data type was not introduced until CDF V2.1.1). Note that - * only rVariables were supported prior to CDF V2.3. - ****************************************************************************/ - case gENTRY_DATATYPE_: - case gENTRY_NUMELEMS_: - case rENTRY_DATATYPE_: - case rENTRY_NUMELEMS_: - case zENTRY_DATATYPE_: - case zENTRY_NUMELEMS_: { - Logical dataOp = ONEof3(Va->item,gENTRY_DATATYPE_, - rENTRY_DATATYPE_, - zENTRY_DATATYPE_); - int entryType = BOO(dataOp,E3p(Va->item,gENTRY_DATATYPE_, - rENTRY_DATATYPE_, - zENTRY_DATATYPE_), - E3p(Va->item,gENTRY_NUMELEMS_, - rENTRY_NUMELEMS_, - zENTRY_NUMELEMS_)); - struct CDFstruct *CDF; - long *value = va_arg (Va->ap, long *); - Int32 tValue, eOffset; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED(CDF)) return NO_ATTR_SELECTED; - if (E3(entryType, - CDF->CURgrEntryNum, - CDF->CURgrEntryNum, - CDF->CURzEntryNum) == RESERVED_ENTRYNUM) return NO_ENTRY_SELECTED; - if (!sX(CheckEntryOp(CDF,entryType),&pStatus)) return pStatus; - eOffset = E3(entryType,CDF->CURgrEntryOffset, - CDF->CURgrEntryOffset, - CDF->CURzEntryOffset); - if (eOffset == RESERVED_ENTRYOFFSET) return NO_SUCH_ENTRY; - if (!sX(ReadAEDR(CDF->fp,eOffset, - BOO(dataOp,AEDR_DATATYPE,AEDR_NUMELEMS),&tValue, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (dataOp && CDF->fakeEPOCH) { - char aName[CDF_ATTR_NAME_LEN+1]; - if (!sX(ReadADR(CDF->fp,CDF->CURattrOffset, - ADR_NAME,aName, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!strcmpITB(aName,"VALIDMIN") || !strcmpITB(aName,"VALIDMAX") || - !strcmpITB(aName,"SCALEMIN") || !strcmpITB(aName,"SCALEMAX")) { - Int32 vOffset; char vName[CDF_VAR_NAME_LEN+1]; - tStatus = FindVarByNumber (CDF, E3(entryType, CDF->CURgrEntryNum, - CDF->CURgrEntryNum, - CDF->CURzEntryNum), - FALSE, &vOffset); - switch (tStatus) { - case NO_SUCH_VAR: - break; - default: - if (!sX(tStatus,&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return tStatus; - } - if (!sX(ReadVDR(CDF,CDF->fp,vOffset,FALSE, - VDR_NAME,vName, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!strcmpITB(vName,"EPOCH") && - FLOAT8dataType(tValue)) tValue = CDF_EPOCH; - if (!strcmpITB(vName,"EPOCH") && - FLOAT16dataType(tValue)) tValue = CDF_EPOCH16; - break; - } - } - } - *value = tValue; - break; - } - /**************************************************************************** - * gENTRY_DATA_/rENTRY_DATA_/zENTRY_DATA_, - ****************************************************************************/ - case gENTRY_DATA_: - case rENTRY_DATA_: - case zENTRY_DATA_: { - int entryType = E3p(Va->item,gENTRY_DATA_,rENTRY_DATA_,zENTRY_DATA_); - struct CDFstruct *CDF; - Int32 offset, dataType, numElems; - void *value = va_arg (Va->ap, void *); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED(CDF)) return NO_ATTR_SELECTED; - if (E3(entryType, - CDF->CURgrEntryNum, - CDF->CURgrEntryNum, - CDF->CURzEntryNum) == RESERVED_ENTRYNUM) return NO_ENTRY_SELECTED; - if (!sX(CheckEntryOp(CDF,entryType),&pStatus)) return pStatus; - offset = E3(entryType,CDF->CURgrEntryOffset, - CDF->CURgrEntryOffset, - CDF->CURzEntryOffset); - if (offset == RESERVED_ENTRYOFFSET) return NO_SUCH_ENTRY; - if (!sX(ReadAEDR(CDF->fp,offset, - AEDR_DATATYPE,&dataType, - AEDR_NUMELEMS,&numElems, - AEDR_VALUE,value, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(ConvertBuffer(CDF->encoding,CDF->decoding, - CDF->negToPosFp0,dataType, - numElems,value,value),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * Unknown item, must be the next function. - ****************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } -} -return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfget64.c b/cdf36_3-dist/src/lib/cdfget64.c deleted file mode 100644 index 4a6f4a7..0000000 --- a/cdf36_3-dist/src/lib/cdfget64.c +++ /dev/null @@ -1,1919 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `get' operations. -* -* Version 1.4, 9-Sep-96, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 16-Sep-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 13-Dec-93, J Love CDF V2.4. -* V1.3 15-Dec-94, J Love CDF V2.5. -* V1.3a 9-Jan-95, J Love Encode/decode changes. More cache-residency. -* V1.3b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.3c 4-Aug-95, J Love CDFexport-related changes. -* V1.4 9-Sep-96, J Love CDF V2.6. -* V2.0 08-Apr-04, M Liu Removed call to LocateCurrentVar function as -* its offset becomes avilable when it is -* selected. -* V2.1 21-Jun-04, M Liu Modified the error message for NOT_A_CDF. -* V2.2 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* V3.2 16-Oct-07, D Han The length of the pad value for a CDF_CHAR -* variable is the length of the variable (i.e. -* CHAR/162, etc.). If the length of the pad -* value is greater than 16, it causes -* segmentation fault for the IDL CDF interface -* routine. -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" -#include "cdfrev.h" - -/****************************************************************************** -* CDFget64. -******************************************************************************/ - -STATICforIDL CDFstatus CDFget64 (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ -CDFstatus tStatus, pStatus = CDF_OK; - -switch (Va->item) { - /**************************************************************************** - * CDF_INFO_ - ****************************************************************************/ - case CDF_INFO_: { - char CDFpathX[DU_MAX_PATH_LEN+1], CDFpathT[CDF_PATHNAME_LEN+1], *CDFpathP; - vFILE *dotFp; Logical upper_case_ext, version_numbers, no_append; - Int32 magicNumber1, magicNumber2; int i; - long *cType, *cParms; - void *cFileSize, *uFileSize; - long cSize2, uSize2; - OFF_T cSize3, uSize3; - int whichVersion = 3; - CDFpathP = va_arg (Va->ap, char *); - cType = va_arg (Va->ap, long *); - cParms = va_arg (Va->ap, long *); - cFileSize = va_arg (Va->ap, void *); - uFileSize = va_arg (Va->ap, void *); - if (strlen(CDFpathP) > (size_t) CDF_PATHNAME_LEN) { - if (!sX(CDF_NAME_TRUNC,&pStatus)) return pStatus; - } - strcpyX (CDFpathT, CDFpathP, CDF_PATHNAME_LEN); -#if STRIP_TRAILING_BLANKS_FROM_CDFPATH - StripTrailingBlanks (CDFpathT); -#endif -#if defined(vms) || defined(dos) - MakeUpperString (CDFpathT); -#endif -/* if (!ValidCDFname(CDFpathT)) return BAD_CDF_NAME; */ - if (!sX(FindCDF(CDFpathT,&no_append, - &upper_case_ext, - &version_numbers),&pStatus)) return pStatus; - BuildFilePath (CDFt, CDFpathT, no_append, upper_case_ext, version_numbers, - INT32_ZERO, CDFpathX); - dotFp = V_open64 (CDFpathX, READ_ONLY_a_mode); - if (dotFp == NULL) return CDF_OPEN_ERROR; - if (!Read32_64(dotFp,&magicNumber1)) { - V_close64 (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - if (!Read32_64(dotFp,&magicNumber2)) { - V_close64 (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - if (magicNumber1 != V3magicNUMBER_1) { /* Not V3.0. */ - V_close64 (dotFp, NULL, NULL); /* Close it and then open it with V2.0. */ - dotFp = V_open (CDFpathX, READ_ONLY_a_mode); - if (dotFp == NULL) return CDF_OPEN_ERROR; - if (!Read32(dotFp,&magicNumber1)) { - V_close (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - if (!Read32(dotFp,&magicNumber2)) { - V_close (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - whichVersion = 2; - } - - switch (magicNumber1) { - case V1magicNUMBER_flip: - V_close (dotFp, NULL, NULL); - return ILLEGAL_ON_V1_CDF; - case V2magicNUMBER_1pre: - *cType = NO_COMPRESSION; - cSize2 = 0; - if (!SEEKv(dotFp,(OFF_T) 0,vSEEK_END)) { - V_close (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - uSize2 = V_tell (dotFp); - V_close (dotFp, NULL, NULL); - break; - case V2magicNUMBER_1: - switch (magicNumber2) { - case V2magicNUMBER_2u: - *cType = NO_COMPRESSION; - cSize2 = 0; - if (!SEEKv(dotFp,0L,vSEEK_END)) { - V_close (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - uSize2 = V_tell (dotFp); - V_close (dotFp, NULL, NULL); - break; - case V2magicNUMBER_2c: { - struct CCRstruct CCR; struct CPRstruct CPR; - if (!sX(ReadCCR(dotFp,V2_CCR_OFFSET, - CCR_RECORD,&CCR, - CCR_NULL),&pStatus)) { - V_close (dotFp, NULL, NULL); - return pStatus; - } - if (CCR.uSize == 0) { - V_close (dotFp, NULL, NULL); - return EMPTY_COMPRESSED_CDF; - } - if (!sX(ReadCPR(dotFp,CCR.CPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) { - V_close (dotFp, NULL, NULL); - return pStatus; - } - *cType = (long) CPR.cType; - if (CPR.pCount > CDF_MAX_PARMS) { - V_close (dotFp, NULL, NULL); - return TOO_MANY_PARMS; - } - for (i = 0; i < CPR.pCount; i++) cParms[i] = (long) CPR.cParms[i]; - if (!SEEKv(dotFp,0L,vSEEK_END)) { - V_close (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - cSize2 = V_tell (dotFp); - uSize2 = (long) CCR.uSize + MAGIC_NUMBERS_SIZE; - V_close (dotFp, NULL, NULL); - break; - } - } - break; - case V3magicNUMBER_1: - switch (magicNumber2) { - case V3magicNUMBER_2u: - *cType = NO_COMPRESSION; - cSize3 = 0; - if (!SEEKv64(dotFp,(OFF_T) 0,vSEEK_END)) { - V_close64 (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - uSize3 = V_tell64 (dotFp); - V_close64 (dotFp, NULL, NULL); - break; - case V3magicNUMBER_2c: { - struct CCRstruct64 CCR; struct CPRstruct64 CPR; - if (!sX(ReadCCR64(dotFp,V3_CCR_OFFSET64, - CCR_RECORD,&CCR, - CCR_NULL),&pStatus)) { - V_close64 (dotFp, NULL, NULL); - return pStatus; - } - if (CCR.uSize == 0) { - V_close64 (dotFp, NULL, NULL); - return EMPTY_COMPRESSED_CDF; - } - if (!sX(ReadCPR64(dotFp,CCR.CPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) { - V_close64 (dotFp, NULL, NULL); - return pStatus; - } - *cType = (long) CPR.cType; - if (CPR.pCount > CDF_MAX_PARMS) { - V_close64 (dotFp, NULL, NULL); - return TOO_MANY_PARMS; - } - for (i = 0; i < CPR.pCount; i++) cParms[i] = (long) CPR.cParms[i]; - if (!SEEKv64(dotFp,(OFF_T) 0,vSEEK_END)) { - V_close64 (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - cSize3 = V_tell64 (dotFp); - uSize3 = (OFF_T) CCR.uSize + MAGIC_NUMBERS_SIZE; - V_close64 (dotFp, NULL, NULL); - break; - } - default: - V_close64 (dotFp, NULL, NULL); - return NOT_A_CDF; - } - break; - default: - if (whichVersion == 3) - V_close64 (dotFp, NULL, NULL); - else - V_close (dotFp, NULL, NULL); - return NOT_A_CDF_OR_NOT_SUPPORTED; - } - if (whichVersion == 2) { - memcpy((long *)cFileSize, &cSize2, sizeof(long)); - memcpy((long *)uFileSize, &uSize2, sizeof(long)); - } else { - memcpy((OFF_T *)cFileSize, &cSize3, sizeof(OFF_T)); - memcpy((OFF_T *)uFileSize, &uSize3, sizeof(OFF_T)); - } - break; - } - /**************************************************************************** - * STATUS_TEXT_, - ****************************************************************************/ - case STATUS_TEXT_: { - char *textPtr; - textPtr = va_arg (Va->ap, char *); - CDFstatusText (Cur->status, textPtr); - break; - } - /**************************************************************************** - * DATATYPE_SIZE_, - ****************************************************************************/ - case DATATYPE_SIZE_: { - long dataType = va_arg (Va->ap, long); - long *numBytes = va_arg (Va->ap, long *); - if (!ValidDataType((Int32)dataType)) return BAD_DATA_TYPE; - *numBytes = (long) CDFelemSize (dataType); - break; - } - /**************************************************************************** - * rVARs_NUMDIMS_/zVAR_NUMDIMS_ - * Note that inquiring the number of rVariable dimensions is allowed while - * in zMode. - ****************************************************************************/ - case rVARs_NUMDIMS_: { - struct CDFstruct *CDF; - long *numDims = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *numDims = CDF->rNumDims; - break; - } - case zVAR_NUMDIMS_: { - struct CDFstruct *CDF; - long *numDimsP = va_arg (Va->ap, long *); - Logical zVar; Int32 numDims; - OFF_T offset; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTvarSELECTED(CDF,TRUE)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,TRUE); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - - if (!sX(CalcDimParms64(CDF,offset,zVar,&numDims,NULL,NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - ASSIGNnotNULL (numDimsP, numDims) - break; - } - /**************************************************************************** - * rVARs_DIMSIZES_/zVAR_DIMSIZES_ - * Note that inquiring the rVariable dimension sizes is allowed while in - * zMode. - ****************************************************************************/ - case rVARs_DIMSIZES_: { - struct CDFstruct *CDF; - int dimN; - long *dimsize = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - for (dimN = 0; dimN < CDF->rNumDims; dimN++) { - dimsize[dimN] = CDF->rDimSizes[dimN]; - } - break; - } - case zVAR_DIMSIZES_: { - struct CDFstruct *CDF; Logical zVar; - Int32 numDims, dimSizes[CDF_MAX_DIMS]; - OFF_T offset; - long *dimSizesP = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTvarSELECTED(CDF,TRUE)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,TRUE); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - - if (!sX(CalcDimParms64(CDF,offset,zVar,&numDims,dimSizes,NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - ASSIGNnotNULLarray (dimSizesP, numDims, dimSizes) - break; - } - /**************************************************************************** - * CDF_ENCODING_, - ****************************************************************************/ - case CDF_ENCODING_: { - struct CDFstruct *CDF; - long *encoding = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *encoding = (long) CDF->encoding; - break; - } - /**************************************************************************** - * CDF_MAJORITY_, - ****************************************************************************/ - case CDF_MAJORITY_: { - struct CDFstruct *CDF; - long *majority = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *majority = BOO(CDF->rowMajor,ROW_MAJOR,COLUMN_MAJOR); - break; - } - /**************************************************************************** - * CDF_FORMAT_, - ****************************************************************************/ - case CDF_FORMAT_: { - struct CDFstruct *CDF; - long *format = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *format = BOO(CDF->singleFile,SINGLE_FILE,MULTI_FILE); - break; - } - /**************************************************************************** - * CDF_CHECKSUM_, - ****************************************************************************/ - case CDF_CHECKSUM_: { - struct CDFstruct *CDF; - long *checksum = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - *checksum = CDF->checksum; - break; - } - /**************************************************************************** - * CDF_COMPRESSION_ - ****************************************************************************/ - case CDF_COMPRESSION_: { - long *cType = va_arg (Va->ap, long *); /* Compression type. */ - long *cParms = va_arg (Va->ap, long *); /* Compression parameters. */ - long *cPct = va_arg (Va->ap, long *); /* Compression percentage. */ - struct CDFstruct *CDF; struct CCRstruct64 CCR; struct CPRstruct64 CPR; - int i; OFF_T cTotal, uTotal; - SelectCDF (Cur->cdf, CDF) - /************************************************************************** - * If multi-file or uncompressed... - **************************************************************************/ - if (!CDF->singleFile || CDF->uDotFp == NULL) { - *cType = NO_COMPRESSION; - *cPct = 100; - break; - } - /************************************************************************** - * ...otherwise, read the CCR and CPR. - **************************************************************************/ - if (!sX(ReadCCR64(CDF->dotFp,V3_CCR_OFFSET64, - CCR_RECORD,&CCR, - CCR_NULL),&pStatus)) return pStatus; - if (!sX(ReadCPR64(CDF->dotFp,CCR.CPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) return pStatus; - *cType = CPR.cType; - if (CPR.pCount > CDF_MAX_PARMS) return TOO_MANY_PARMS; - for (i = 0; i < CPR.pCount; i++) cParms[i] = CPR.cParms[i]; - /************************************************************************** - * Calculate the percentage. If the `uSize' field of the CCR is zero, - * then the compressed CDF is empty (and the percentage is unknown). - **************************************************************************/ - if (CCR.uSize == 0) - *cPct = 0; - else { - cTotal = MAGIC_NUMBERS_SIZE + CCR.RecordSize + CPR.RecordSize; - uTotal = MAGIC_NUMBERS_SIZE + CCR.uSize; - *cPct = (long) (((100.0 * cTotal) / uTotal) + 0.5); - } - break; - } - /**************************************************************************** - * CDF_COPYRIGHT_ - ****************************************************************************/ - case CDF_COPYRIGHT_: { - struct CDFstruct *CDF; - char *copyRight = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - if (!sX(ReadCDR64(CDF->fp,CDF->CDRoffset64, - CDR_COPYRIGHT,copyRight, - CDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - copyRight[CDF_COPYRIGHT_LEN] = NUL; - break; - } - /**************************************************************************** - * LIB_COPYRIGHT_ - ****************************************************************************/ - case LIB_COPYRIGHT_: { - char *copyRight = va_arg (Va->ap, char *); - CDFcopyRight (copyRight); - break; - } - /**************************************************************************** - * CDF_NUMrVARS_/CDF_NUMzVARS_ - * Inquire number of r/z variables. When in zMode, the number of - * rVariables is always zero (0). (Inquiring the number of rVariables - * while in zMode is one of the few legal rVariable operations). - ****************************************************************************/ - case CDF_NUMrVARS_: - case CDF_NUMzVARS_: { - Logical zOp = (Va->item == CDF_NUMzVARS_); - struct CDFstruct *CDF; - long *numVars = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (zModeON(CDF)) - *numVars = BOO(zOp,CDF->NrVars + CDF->NzVars,0); - else - *numVars = BOO(zOp,CDF->NzVars,CDF->NrVars); - break; - } - /**************************************************************************** - * CDF_NUMATTRS_, - ****************************************************************************/ - case CDF_NUMATTRS_: { - struct CDFstruct *CDF; - long *numAttrs = va_arg (Va->ap, long *); - Int32 tNumAttrs; - SelectCDF (Cur->cdf, CDF) - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_NUMATTR,&tNumAttrs, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *numAttrs = tNumAttrs; - break; - } - /**************************************************************************** - * CDF_NUMgATTRS_/CDF_NUMvATTRS_ - ****************************************************************************/ - case CDF_NUMvATTRS_: - case CDF_NUMgATTRS_: { - Logical gOp = (Va->item == CDF_NUMgATTRS_); - struct CDFstruct *CDF; - long *numAttrs = va_arg (Va->ap, long *); - Int32 totalAttrs, scope; - OFF_T offset; - int attrX; - SelectCDF (Cur->cdf, CDF) - *numAttrs = 0; - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_NUMATTR,&totalAttrs, - GDR_ADRHEAD,&offset, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - for (attrX = 0; attrX < totalAttrs; attrX++) { - CDF->fp->CurADRIndex = attrX; - if (!sX(ReadADR64(CDF->fp,offset, - ADR_SCOPE,&scope, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if ((gOp && GLOBALscope(scope)) || - (!gOp && VARIABLEscope(scope))) (*numAttrs)++; - if (!sX(ReadADR64(CDF->fp,offset, - ADR_ADRNEXT,&offset, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - break; - } - /**************************************************************************** - * rVARs_MAXREC_/zVARs_MAXREC_ - * Maximum record number of all of the rVariables/zVariables. Note that - * inquiring the maximum rVariable record number is allowed while in zMode. - ****************************************************************************/ - case rVARs_MAXREC_: { - struct CDFstruct *CDF; - long *maxRec = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (zModeON(CDF)) - *maxRec = NO_RECORD; - else - *maxRec = CDF->rMaxRec; - break; - } - case zVARs_MAXREC_: { - struct CDFstruct *CDF; - long *maxRec = va_arg (Va->ap, long *); - Int32 tMaxRec; - OFF_T offset; - SelectCDF (Cur->cdf, CDF) - /************************************************************************** - * If zMode is on, consider both rVariables and zVariables. If zMode is - * not on, only consider the zVariables. Because zVariables did not exist - * in CDF V2.0, the problem with the `VDRnext' offset in the last VDR does - * not have to be considered here. - **************************************************************************/ - *maxRec = BOO(zModeON(CDF),CDF->rMaxRec,NO_RECORD); - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_zVDRHEAD,&offset, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - while (offset != (OFF_T) ZERO_OFFSET64) { - if (!sX(ReadVDR64(CDF,CDF->fp,offset,TRUE, - VDR_MAXREC,&tMaxRec, - VDR_VDRNEXT,&offset, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *maxRec = MAXIMUM (*maxRec, tMaxRec); - } - break; - } - /**************************************************************************** - * CDF_VERSION_, - ****************************************************************************/ - case CDF_VERSION_: { - struct CDFstruct *CDF; - long *version = va_arg (Va->ap, long *); - Int32 tVersion; - SelectCDF (Cur->cdf, CDF) - if (!sX(ReadCDR64(CDF->fp,CDF->CDRoffset64, - CDR_VERSION,&tVersion, - CDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *version = tVersion; - break; - } - /**************************************************************************** - * CDF_RELEASE_, - ****************************************************************************/ - case CDF_RELEASE_: { - struct CDFstruct *CDF; - long *release = va_arg (Va->ap, long *); - Int32 tRelease; - SelectCDF (Cur->cdf, CDF) - if (!sX(ReadCDR64(CDF->fp,CDF->CDRoffset64, - CDR_RELEASE,&tRelease, - CDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *release = tRelease; - break; - } - /**************************************************************************** - * CDF_INCREMENT_, - ****************************************************************************/ - case CDF_INCREMENT_: { - struct CDFstruct *CDF; - long *increment = va_arg (Va->ap, long *); - Int32 tIncrement; - SelectCDF (Cur->cdf, CDF) - if (!sX(ReadCDR64(CDF->fp,CDF->CDRoffset64, - CDR_INCREMENT,&tIncrement, - CDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *increment = tIncrement; - break; - } - /**************************************************************************** - * CDF_LEAPSECONDLASTUPDATED_, - ****************************************************************************/ - case CDF_LEAPSECONDLASTUPDATED_: { - struct CDFstruct *CDF; - long *lastUpdated = va_arg (Va->ap, long *); - Int32 tLastUpdated; - SelectCDF (Cur->cdf, CDF) - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_LEAPSECONDLASTUPDATED,&tLastUpdated, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *lastUpdated = tLastUpdated; - break; - } - /**************************************************************************** - * LIB_VERSION_, - ****************************************************************************/ - case LIB_VERSION_: { - long *version = va_arg (Va->ap, long *); - *version = CDF_LIBRARY_VERSION; - break; - } - /**************************************************************************** - * LIB_RELEASE_, - ****************************************************************************/ - case LIB_RELEASE_: { - long *release = va_arg (Va->ap, long *); - *release = CDF_LIBRARY_RELEASE; - break; - } - /**************************************************************************** - * LIB_INCREMENT_, - ****************************************************************************/ - case LIB_INCREMENT_: { - long *increment = va_arg (Va->ap, long *); - *increment = CDF_LIBRARY_INCREMENT; - break; - } - /**************************************************************************** - * LIB_subINCREMENT_, - ****************************************************************************/ - case LIB_subINCREMENT_: { - char *subincrement = va_arg (Va->ap, char *); - *subincrement = CDF_LIBRARY_subINCREMENT; - break; - } - /**************************************************************************** - * rVAR_NAME_/zVAR_NAME_ - * Note that a temporary variable is used when reading the variable name. - * This is because the caller may have only allocated enough memory for the - * size name they expect (ie., less than CDF_VAR_NAME_LEN characters). Since - * the variable name is NUL-terminated in the CDF, only the actual characters - * of the name will be copied to the caller's buffer. - ****************************************************************************/ - case rVAR_NAME_: - case zVAR_NAME_: { - Logical zOp = (Va->item == zVAR_NAME_), zVar; - struct CDFstruct *CDF; - char *varName = va_arg (Va->ap, char *), tName[CDF_VAR_NAME_LEN256+1]; - OFF_T offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_NAME,tName, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - strcpyX (varName, tName, CDF_VAR_NAME_LEN256); - break; - } - /**************************************************************************** - * rVAR_DATATYPE_/zVAR_DATATYPE_ - * If this for an rVarible named "EPOCH" in a CDF prior to CDF V2.1.1, - * then return the CDF_EPOCH data type if the actual data type is CDF_REAL8 - * or CDF_DOUBLE. (The CDF_EPOCH data type was not introduced until CDF - * V2.1.1). Note that only rVariables were supported prior to CDF V2.3. - ****************************************************************************/ - case rVAR_DATATYPE_: - case zVAR_DATATYPE_: { - Logical zOp = (Va->item == zVAR_DATATYPE_), zVar; - struct CDFstruct *CDF; - long *dataType = va_arg (Va->ap, long *); - Int32 tDataType; - OFF_T offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_DATATYPE,&tDataType, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!zVar && CDF->fakeEPOCH) { - char varName[CDF_VAR_NAME_LEN256+1]; - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_NAME,varName, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!strcmpITB(varName,"EPOCH") && FLOAT8dataType(tDataType)) { - tDataType = CDF_EPOCH; - } else if (!strcmpITB(varName,"EPOCH") && FLOAT16dataType(tDataType)) { - tDataType = CDF_EPOCH16; - } - } - *dataType = tDataType; - break; - } - /**************************************************************************** - * rVAR_NUMELEMS_/zVAR_NUMELEMS_, - ****************************************************************************/ - case rVAR_NUMELEMS_: - case zVAR_NUMELEMS_: { - Logical zOp = (Va->item == zVAR_NUMELEMS_), zVar; - struct CDFstruct *CDF; - long *numElements = va_arg (Va->ap, long *); - Int32 tNumElems; - OFF_T offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_NUMELEMS,&tNumElems, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *numElements = tNumElems; - break; - } - /**************************************************************************** - * rVAR_RECVARY_/zVAR_RECVARY_, - ****************************************************************************/ - case rVAR_RECVARY_: - case zVAR_RECVARY_: { - Logical zOp = (Va->item == zVAR_RECVARY_), zVar; - struct CDFstruct *CDF; - long *recVary = va_arg (Va->ap, long *); - Int32 flags; - OFF_T offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_FLAGS,&flags, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *recVary = BOO(RECvaryBITset(flags),VARY,NOVARY); - break; - } - /**************************************************************************** - * rVAR_DIMVARYS_/zVAR_DIMVARYS_, - ****************************************************************************/ - case rVAR_DIMVARYS_: - case zVAR_DIMVARYS_: { - Logical zOp = (Va->item == zVAR_DIMVARYS_), zVar; - struct CDFstruct *CDF; Int32 numDims, dimVarys[CDF_MAX_DIMS]; - OFF_T offset; - long *dimVarysP = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - if (!sX(CalcDimParms64(CDF,offset,zVar,&numDims,NULL,dimVarys),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - ASSIGNnotNULLarray (dimVarysP, numDims, dimVarys) - break; - } - /**************************************************************************** - * rVAR_MAXREC_/zVAR_MAXREC_, - ****************************************************************************/ - case rVAR_MAXREC_: - case zVAR_MAXREC_: { - Logical zOp = (Va->item == zVAR_MAXREC_), zVar; - struct CDFstruct *CDF; Int32 tMaxRec; OFF_T offset; - long *maxRec = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_MAXREC,&tMaxRec, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *maxRec = (long) tMaxRec; - break; - } - /**************************************************************************** - * rVAR_MAXallocREC_/zVAR_MAXallocREC_, - ****************************************************************************/ - case rVAR_MAXallocREC_: - case zVAR_MAXallocREC_: { - Logical zOp = (Va->item == zVAR_MAXallocREC_), zVar; - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 maxRec, lastAllocatedRecN; OFF_T offset; int vType; - long *maxAllocated = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_MAXREC,&maxRec, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(VariableType64(CDF,offset,zVar,&vType),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * If a single-file CDF, pass back the maximum record number allocated. - * If a multi-file CDF, pass back the maximum record number written (which - * will always be the maximum record allocated). - **************************************************************************/ - if (CDF->singleFile) { - if (!sX(LastRecord64(CDF,offset,zVar,&lastAllocatedRecN),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (vType == SPARSE_RECORDS_) { - if (Var != NULL) { - if (Var->stage.areaOffset64 != (OFF_T) NO_OFFSET64 && - Var->stage.firstRec != NO_RECORD) { - Int32 tmp = (Var->stage.lastRec > maxRec ? maxRec : - Var->stage.lastRec); - lastAllocatedRecN += (tmp - Var->stage.firstRec + 1); - } - } - } else if (vType == COMPRESSED_ || - vType == SPARSE_COMPRESSED_RECORDS_) { - if (Var != NULL) { - if (Var->stage.areaOffset64 != (OFF_T) NO_OFFSET64 && - Var->stage.firstRec != NO_RECORD && - Var->stage.dotOffset64 == (OFF_T) NO_OFFSET64) { - Int32 tmp = (Var->stage.lastRec > maxRec ? maxRec : - Var->stage.lastRec); - lastAllocatedRecN += (tmp - Var->stage.firstRec + 1); - } - } - } - *maxAllocated = lastAllocatedRecN; - } - else - *maxAllocated = (long) maxRec; - break; - } - /**************************************************************************** - * rVAR_NUMRECS_/zVAR_NUMRECS_, - ****************************************************************************/ - case rVAR_NUMRECS_: - case zVAR_NUMRECS_: { - Logical zOp = (Va->item == zVAR_NUMRECS_), zVar; struct VarStruct *Var; - struct CDFstruct *CDF; Int32 nRecords; int vType; OFF_T vdrOffset; - Int32 tMaxRec; - long *nRecordsP = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) vdrOffset = CDF->CURzVarOffset64; - else vdrOffset = CDF->CURrVarOffset64; - - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - - if (!sX(ReadVDR64(CDF,CDF->fp,vdrOffset,zVar, - VDR_MAXREC,&tMaxRec, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(VariableType64(CDF,vdrOffset,zVar,&vType),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Depending on the variable type... - **************************************************************************/ - switch (vType) { - case SPARSE_RECORDS_: - if (!sX(IndexingStatistics64(CDF,vdrOffset,zVar, - NULL,NULL,NULL, - &nRecords,NULL),&pStatus)) return pStatus; - if (Var != NULL) { - if (Var->stage.areaOffset64 != (OFF_T) NO_OFFSET64 && - Var->stage.firstRec != NO_RECORD) { - Int32 tmp = (Var->stage.lastRec > tMaxRec ? tMaxRec : Var->stage.lastRec); - nRecords += (tmp - Var->stage.firstRec + 1); - } - } - break; - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - if (!sX(IndexingStatistics64(CDF,vdrOffset,zVar, - NULL,NULL,NULL, - &nRecords,NULL),&pStatus)) return pStatus; - if (Var != NULL) { - if (Var->stage.areaOffset64 != (OFF_T) NO_OFFSET64 && - Var->stage.firstRec != NO_RECORD && - Var->stage.dotOffset64 == (OFF_T) NO_OFFSET64) { - Int32 tmp = (Var->stage.lastRec > tMaxRec ? tMaxRec : Var->stage.lastRec); - nRecords += (tmp - Var->stage.firstRec + 1); - } - } - break; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return CDF_INTERNAL_ERROR; - case STANDARD_: - case IN_MULTI_: { - Int32 maxRec; - if (!sX(ReadVDR64(CDF,CDF->fp,vdrOffset,zVar, - VDR_MAXREC,&maxRec, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - nRecords = maxRec + 1; - break; - } - } - ASSIGNnotNULL (nRecordsP, nRecords) - break; - } - /**************************************************************************** - * rVAR_NUMallocRECS_/zVAR_NUMallocRECS_, - ****************************************************************************/ - case rVAR_NUMallocRECS_: - case zVAR_NUMallocRECS_: { - Logical zOp = (Va->item == zVAR_NUMallocRECS_), zVar; - struct CDFstruct *CDF; Int32 nAllocated; int vType; OFF_T offset; - Int32 tMaxRec; struct VarStruct *Var; - long *nAllocatedP = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_MAXREC,&tMaxRec, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(VariableType64(CDF,offset,zVar,&vType),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Depending on the variable type... - **************************************************************************/ - switch (vType) { - case STANDARD_: - case SPARSE_RECORDS_: - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: { - if (!sX(IndexingStatistics64(CDF,offset, - zVar,NULL,NULL, - &nAllocated, - NULL,NULL),&pStatus)) return pStatus; - if (vType == SPARSE_RECORDS_) { - if (Var != NULL) { - if (Var->stage.areaOffset64 != (OFF_T) NO_OFFSET64 && - Var->stage.firstRec != NO_RECORD) { - Int32 tmp = (Var->stage.lastRec > tMaxRec ? tMaxRec : - Var->stage.lastRec); - nAllocated += (tmp - Var->stage.firstRec + 1); - } - } - } else if (vType == COMPRESSED_ || - vType == SPARSE_COMPRESSED_RECORDS_) { - if (Var != NULL) { - if (Var->stage.areaOffset64 != (OFF_T) NO_OFFSET64 && - Var->stage.firstRec != NO_RECORD && - Var->stage.dotOffset64 == (OFF_T) NO_OFFSET64) { - Int32 tmp = (Var->stage.lastRec > tMaxRec ? tMaxRec : - Var->stage.lastRec); - nAllocated += (tmp - Var->stage.firstRec + 1); - } - } - } - break; - } - case IN_MULTI_: { - Int32 maxRec; - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_MAXREC,&maxRec, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - nAllocated = maxRec + 1; - break; - } - } - ASSIGNnotNULL (nAllocatedP, nAllocated) - break; - } - /**************************************************************************** - * rVAR_ALLOCATEDFROM_/zVAR_ALLOCATEDFROM_ - * Determines the next allocated record AT or AFTER `startRec' (meaning that - * `startRec' could be the record number returned). - ****************************************************************************/ - case rVAR_ALLOCATEDFROM_: - case zVAR_ALLOCATEDFROM_: { - Logical zOp = (Va->item == zVAR_ALLOCATEDFROM_), zVar, found; - struct CDFstruct *CDF; Int32 nextRec; OFF_T offset; - Int32 startRec = (Int32) va_arg (Va->ap, long); - long *fromRec = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (startRec <= NO_RECORD) return BAD_REC_NUM; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - - if (!sX(NextRecord64(CDF,offset,zVar,startRec,&nextRec,&found),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!found) return NO_SUCH_RECORD; - *fromRec = (long) nextRec; - break; - } - /**************************************************************************** - * rVAR_ALLOCATEDTO_/zVAR_ALLOCATEDTO_ - * Determines the last record (before the next unallocated record) allocated - * AT or AFTER `startRec'. This can span non-contiguous blocks of records. - ****************************************************************************/ - case rVAR_ALLOCATEDTO_: - case zVAR_ALLOCATEDTO_: { - Logical zOp = (Va->item == zVAR_ALLOCATEDTO_), zVar, found; - struct CDFstruct *CDF; Int32 lastRec; OFF_T vdrOffset; - Int32 startRec = (Int32) va_arg (Va->ap, long); - long *toRec = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (startRec <= NO_RECORD) return BAD_REC_NUM; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) vdrOffset = CDF->CURzVarOffset64; - else vdrOffset = CDF->CURrVarOffset64; - - /************************************************************************** - * Determine the last record in the block containing the starting record. - **************************************************************************/ - if (!sX(SearchForRecord64(CDF,vdrOffset,zVar,startRec, - NULL,&lastRec,NULL,&found),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!found) return NO_SUCH_RECORD; - /************************************************************************** - * Keep searching until an unallocated record is encountered. - **************************************************************************/ - while (found) { - Int32 nextRec = (Int32) (lastRec + 1); - if (!sX(SearchForRecord64(CDF,vdrOffset,zVar,nextRec, - NULL,&lastRec,NULL,&found),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Return the last allocated record detected. - **************************************************************************/ - *toRec = (long) lastRec; - break; - } - /**************************************************************************** - * rVAR_COMPRESSION_/zVAR_COMPRESSION_ - ****************************************************************************/ - case rVAR_COMPRESSION_: - case zVAR_COMPRESSION_: { - Logical zOp = (Va->item == zVAR_COMPRESSION_), zVar; - struct CDFstruct *CDF; /* struct VarStruct *Var; */ struct CPRstruct64 CPR; - Int32 flags; int parmN; OFF_T VDRoffset, PRoffset; - long *cType = va_arg (Va->ap, long *); /* Compression type. */ - long *cParms = va_arg (Va->ap, long *); /* Compression parameters. */ - long *cPct = va_arg (Va->ap, long *); /* Compression percentage. */ - /************************************************************************** - * Select/validate/locate CDF and variable. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) VDRoffset = CDF->CURzVarOffset64; - else VDRoffset = CDF->CURrVarOffset64; - - /************************************************************************** - * Read fields from VDR. - **************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,VDRoffset,zVar, - VDR_FLAGS,&flags, - VDR_CPRorSPR,&PRoffset, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * If the compression bit is set, read the CPR. - **************************************************************************/ - if (VARcompressionBITset(flags)) { - if (!sX(ReadCPR64(CDF->fp,PRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *cType = CPR.cType; - for (parmN = 0; parmN < CPR.pCount; parmN++) { - cParms[parmN] = CPR.cParms[parmN]; - } - if (!sX(CalcCompressionPct64(CDF,VDRoffset,zVar,cPct),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - else { - *cType = NO_COMPRESSION; - *cPct = 100; - } - break; - } - /**************************************************************************** - * rVAR_SPARSEARRAYS_/zVAR_SPARSEARRAYS_ - ****************************************************************************/ - case rVAR_SPARSEARRAYS_: - case zVAR_SPARSEARRAYS_: { - Logical zOp = (Va->item == zVAR_SPARSEARRAYS_), zVar; - struct CDFstruct *CDF; /* struct VarStruct *Var; */ struct SPRstruct64 SPR; - Int32 flags; int parmN; OFF_T VDRoffset, PRoffset; - long *sArraysType = va_arg (Va->ap, long *); /* Sparseness type. */ - long *sArraysParms = va_arg (Va->ap, long *); /* Sparseness parameters. */ - long *sArraysPct = va_arg (Va->ap, long *); /* Sparseness percentage. */ - /************************************************************************** - * Select/validate/locate CDF and variable. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) VDRoffset = CDF->CURzVarOffset64; - else VDRoffset = CDF->CURrVarOffset64; - - /************************************************************************** - * Read fields from VDR. - **************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,VDRoffset,zVar, - VDR_FLAGS,&flags, - VDR_CPRorSPR,&PRoffset, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * If the sparse arrays bit is set, read the SPR. - **************************************************************************/ - if (SPARSEarraysBITset(flags)) { - if (!sX(ReadSPR64(CDF->fp,PRoffset, - SPR_RECORD,&SPR, - SPR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *sArraysType = SPR.sArraysType; - for (parmN = 0; parmN < SPR.pCount; parmN++) { - sArraysParms[parmN] = SPR.sArraysParms[parmN]; - } - *sArraysPct = 100; - } - else { - *sArraysType = NO_SPARSEARRAYS; - *sArraysPct = 100; - } - break; - } - /**************************************************************************** - * rVAR_SPARSERECORDS_/zVAR_SPARSERECORDS_ - ****************************************************************************/ - case rVAR_SPARSERECORDS_: - case zVAR_SPARSERECORDS_: { - Logical zOp = (Va->item == zVAR_SPARSERECORDS_), zVar; - struct CDFstruct *CDF; /* struct VarStruct *Var; */ - Int32 sRecords; OFF_T VDRoffset; - long *sRecordsType = va_arg (Va->ap, long *); - /************************************************************************** - * Select/validate/locate CDF and variable. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) VDRoffset = CDF->CURzVarOffset64; - else VDRoffset = CDF->CURrVarOffset64; - - /************************************************************************** - * Read sparse records field from VDR. - **************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,VDRoffset,zVar, - VDR_sRECORDS,&sRecords, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *sRecordsType = sRecords; - break; - } - /**************************************************************************** - * rVAR_NUMBER_/zVAR_NUMBER_ - * Determines the variable number for a specified variable name. - ****************************************************************************/ - case rVAR_NUMBER_: - case zVAR_NUMBER_: { - Logical zOp = (Va->item == zVAR_NUMBER_), zVar; - struct CDFstruct *CDF; - char *varName = va_arg (Va->ap, char *); - long *varNum = va_arg (Va->ap, long *); - Int32 varN; OFF_T offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - tStatus = FindVarByName64 (CDF, varName, &offset, &zVar, NULL); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_VAR: - return tStatus; - default: - if (!sX(tStatus,&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return tStatus; - } - } - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_NUM,&varN, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (zModeON(CDF)) - *varNum = BOO(zVar,CDF->NrVars,0) + varN; - else - if (zOp) - if (zVar) - *varNum = varN; - else - return NO_SUCH_VAR; /* Wrong type of variable. */ - else - if (zVar) - return NO_SUCH_VAR; /* Wrong type of variable. */ - else - *varNum = varN; - break; - } - /**************************************************************************** - * rVAR_BLOCKINGFACTOR_/zVAR_BLOCKINGFACTOR_, - ****************************************************************************/ - case rVAR_BLOCKINGFACTOR_: - case zVAR_BLOCKINGFACTOR_: { - Logical zOp = (Va->item == zVAR_BLOCKINGFACTOR_), zVar; - struct CDFstruct *CDF; - long *nExtendRecs = va_arg (Va->ap, long *); - Int32 tRecs; OFF_T offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_BLOCKING,&tRecs, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *nExtendRecs = tRecs; - break; - } - /**************************************************************************** - * rVAR_nINDEXRECORDS_/zVAR_nINDEXRECORDS_, - * rVAR_nINDEXENTRIES_/zVAR_nINDEXENTRIES_, - * rVAR_nINDEXLEVELS_/zVAR_nINDEXLEVELS_, - ****************************************************************************/ - case rVAR_nINDEXRECORDS_: - case zVAR_nINDEXRECORDS_: - case rVAR_nINDEXENTRIES_: - case zVAR_nINDEXENTRIES_: - case rVAR_nINDEXLEVELS_: - case zVAR_nINDEXLEVELS_: { - Logical zOp = (Va->item == zVAR_nINDEXRECORDS_ || - Va->item == zVAR_nINDEXENTRIES_ || - Va->item == zVAR_nINDEXLEVELS_), zVar; - struct CDFstruct *CDF; Int32 count; OFF_T offset; - long *countP = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - - /************************************************************************** - * If a multi-file CDF, pass back a count of zero (0) and an info/warning - * status code. If a single-file CDF, scan through the linked list of VXRs - * counting the parameter requested. - **************************************************************************/ - if (!CDF->singleFile) { - count = 0; - sX (MULTI_FILE_FORMAT, &pStatus); - } - else { - switch (Va->item) { - case rVAR_nINDEXRECORDS_: - case zVAR_nINDEXRECORDS_: - if (!sX(IndexingStatistics64(CDF,offset,zVar, - &count,NULL,NULL, - NULL,NULL),&pStatus)) return pStatus; - break; - case rVAR_nINDEXENTRIES_: - case zVAR_nINDEXENTRIES_: - if (!sX(IndexingStatistics64(CDF,offset,zVar, - NULL,&count,NULL, - NULL,NULL),&pStatus)) return pStatus; - break; - case rVAR_nINDEXLEVELS_: - case zVAR_nINDEXLEVELS_: - if (!sX(IndexingStatistics64(CDF,offset,zVar, - NULL,NULL,NULL, - NULL,&count),&pStatus)) return pStatus; - break; - } - } - ASSIGNnotNULL (countP, count) - break; - } - /**************************************************************************** - * rVAR_PADVALUE_/zVAR_PADVALUE_ - ****************************************************************************/ - case rVAR_PADVALUE_: - case zVAR_PADVALUE_: { - Logical zOp = (Va->item == zVAR_PADVALUE_), zVar; - struct CDFstruct *CDF; - void *padValue = va_arg (Va->ap, void *); - Int32 dataType, numElems, flags; OFF_T offset; - Int32 version, release; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_FLAGS,&flags, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - - /********************************************************************** - The length of the pad value for a CDF_CHAR variable is the - length of the variable (i.e. CHAR/162, etc.). If the length - of the pad value is greater than 16, it causes segmentation fault - for the IDL CDF interface routine. - ***********************************************************************/ - if (STRINGdataType(dataType)) - numElems = 1; - - if (PADvalueBITset(flags)) { - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_PADVALUE,padValue, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(ConvertBuffer(CDF->encoding,CDF->decoding, - CDF->negToPosFp0,dataType, - numElems,padValue,padValue),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - else { - if (!sX(ReadCDR64(CDF->fp,CDF->CDRoffset64, - CDR_VERSION,&version, - CDR_RELEASE,&release, - CDR_NULL),&pStatus)) return pStatus; - if (version*100+release < 305) - DefaultPadValuePre350 (dataType, numElems, padValue); - else - DefaultPadValue (dataType, numElems, padValue); - if (!sX(ConvertBuffer(HostEncoding(),CDF->decoding, - CDF->negToPosFp0,dataType, - numElems,padValue,padValue),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - sX (NO_PADVALUE_SPECIFIED, &pStatus); - } - break; - } - /**************************************************************************** - * rVAR_DATA_/zVAR_DATA_, - ****************************************************************************/ - case rVAR_DATA_: - case zVAR_DATA_: { - Logical zOp = (Va->item == zVAR_DATA_); - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 phyRecNum; struct rdSTRUCT *rd; Int32 offset; - char *value = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - rd = BOO(zModeON(CDF),&(Var->zRD),BOO(zOp,&(Var->zRD),&(CDF->rRD))); - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar64(CDF,Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - phyRecNum = BOO(Var->recVary,rd->recNumber,0); - offset = IndicesValueOffset(Var->numDims, - rd->dimIndices, - Var->dimVarys, - Var->nPhyDimValues) * Var->NvalueBytes; - if (!sX(ReadVarValues64(CDF,Var,phyRecNum, - offset,INT32_ONE,value),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->accessed_at = CDF->pseudo_clock++; - break; - } - /**************************************************************************** - * rVAR_HYPERDATA_/zVAR_HYPERDATA_, - ****************************************************************************/ - case rVAR_HYPERDATA_: - case zVAR_HYPERDATA_: { - Logical zOp = (Va->item == zVAR_HYPERDATA_); - struct CDFstruct *CDF; - struct VarStruct *Var; - int dimN; - struct rdSTRUCT *rd; -#if LIMITof64K - long Nvalues, Nbytes; -#endif - char *buffer = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - rd = BOO(zModeON(CDF),&(Var->zRD),BOO(zOp,&(Var->zRD),&(CDF->rRD))); - for (dimN = 0; dimN < Var->numDims; dimN++) { - long maxIndex = rd->dimIndices[dimN] + - ((rd->dimCounts[dimN] - 1) * rd->dimIntervals[dimN]); - if (maxIndex >= Var->dimSizes[dimN]) return BAD_DIM_INDEX; - } -#if LIMITof64K - Nvalues = rd->recCount; - for (dimN = 0; dimN < Var->numDims; dimN++) Nvalues *= rd->dimCounts[dimN]; - Nbytes = Nvalues * Var->NvalueBytes; - if (TOObigIBMpc(Nbytes)) return IBM_PC_OVERFLOW; -#endif - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar64(CDF,Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - if (!sX(HyperRead64(CDF,Var,rd,buffer),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->accessed_at = CDF->pseudo_clock++; - break; - } - /**************************************************************************** - * rVAR_SEQDATA_/zVAR_SEQDATA_, - ****************************************************************************/ - case rVAR_SEQDATA_: - case zVAR_SEQDATA_: { - Logical zOp = (Va->item == zVAR_SEQDATA_); - struct CDFstruct *CDF; struct VarStruct *Var; Int32 recNum; Int32 offset; - void *value = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar64(CDF,Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - recNum = (Int32) (Var->seqValueOffset64 / (OFF_T) Var->NphyRecValues); - if (recNum > Var->maxRec) return END_OF_VAR; - offset = (Int32) (Var->seqValueOffset64 % (OFF_T) Var->NphyRecValues) * - Var->NvalueBytes; - if (!sX(ReadVarValues64(CDF,Var,recNum,offset,INT32_ONE,value),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->seqValueOffset64++; - Var->accessed_at = CDF->pseudo_clock++; - break; - } - /**************************************************************************** - * rVARs_RECDATA_/zVARs_RECDATA_ - * Read data records for up to all of the rVariables/zVariables. - ****************************************************************************/ - case rVARs_RECDATA_: - case zVARs_RECDATA_: { - Logical zOp = (Va->item == zVARs_RECDATA_), zVar; - struct VarStruct *Var; struct CDFstruct *CDF; - Int32 recNum, varNt; Byte1 *tBuffer; int varX; - long nVars = va_arg (Va->ap, long); - long *varNs = va_arg (Va->ap, long *); - void *buffer = va_arg (Va->ap, char *); -#if LIMITof64K - long nBytes; -#endif - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (nVars < 1) return BAD_NUM_VARS; - for (varX = 0; varX < nVars; varX++) { - if (!sX(VarIdentity(CDF,(Int32)varNs[varX], - zOp,&varNt,&zVar,NULL),&pStatus)) { - return pStatus; - } - if (!sX(InitVar64(CDF,varNt,zVar,NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } -#if LIMITof64K - for (varX = 0, nBytes = 0; varX < nVars; varX++) { - if (!sX(VarIdentity(CDF,varNs[varX],zOp,NULL,NULL,&Var),&pStatus)) { - return pStatus; - } - nBytes += Var->NphyRecBytes; - } - if (TOObigIBMpc(nBytes)) return IBM_PC_OVERFLOW; -#endif - for (varX = 0, tBuffer = buffer; varX < nVars; varX++) { - if (!sX(VarIdentity(CDF,(Int32)varNs[varX], - zOp,NULL,NULL,&Var),&pStatus)) { - return pStatus; - } - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar64(CDF,Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - recNum = BOO(Var->recVary,BOO(zOp,Var->zRD.recNumber, - CDF->rRD.recNumber),0); - if (!sX(ReadVarValues64(CDF,Var,recNum,INT32_ZERO, - Var->NphyRecValues,tBuffer),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - tBuffer += (size_t) Var->NphyRecBytes; - Var->accessed_at = CDF->pseudo_clock++; - } - - break; - } - /**************************************************************************** - * ATTR_NAME_, - * Note that a temporary variable is used when reading the attribute name. - * This is because the caller may have only allocated enough memory for the - * size name they expect (ie., less than CDF_ATTR_NAME_LEN characters). Since - * the attribute name is NUL-terminated in the CDF, only the actual characters - * of the name will be copied to the caller's buffer. - ****************************************************************************/ - case ATTR_NAME_: { - struct CDFstruct *CDF; - char *attrName = va_arg (Va->ap, char *), tName[CDF_ATTR_NAME_LEN256+1]; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED64(CDF)) return NO_ATTR_SELECTED; - if (!sX(ReadADR64(CDF->fp,CDF->CURattrOffset64, - ADR_NAME,tName, - ADR_NULL),&pStatus)){ - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - strcpyX (attrName, tName, CDF_ATTR_NAME_LEN256); - break; - } - /**************************************************************************** - * ATTR_NUMBER_, - ****************************************************************************/ - case ATTR_NUMBER_: { - struct CDFstruct *CDF; - char *attrName = va_arg (Va->ap, char *); - long *attrNum = va_arg (Va->ap, long *); - Int32 attrNumT; OFF_T offset; - SelectCDF (Cur->cdf, CDF) - tStatus = FindAttrByName64 (CDF, attrName, &offset); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_ATTR: - return tStatus; - default: - if (!sX(tStatus,&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return tStatus; - } - } - if (!sX(ReadADR64(CDF->fp,offset, - ADR_NUM,&attrNumT, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *attrNum = attrNumT; - break; - } - /**************************************************************************** - * ATTR_SCOPE_, - ****************************************************************************/ - case ATTR_SCOPE_: { - struct CDFstruct *CDF; - long *scope = va_arg (Va->ap, long *); - Int32 tScope; - SelectCDF (Cur->cdf, CDF); - if (!CURRENTattrSELECTED64(CDF)) return NO_ATTR_SELECTED; - if (!sX(ReadADR64(CDF->fp,CDF->CURattrOffset64, - ADR_SCOPE,&tScope, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - *scope = DEFINITEscope(tScope); - break; - } - /**************************************************************************** - * ATTR_MAXgENTRY_/ATTR_MAXrENTRY_/ATTR_MAXzENTRY_ - * ATTR_NUMgENTRIES_/ATTR_NUMrENTRIES_/ATTR_NUMzENTRIES_ - ****************************************************************************/ - case ATTR_MAXgENTRY_: - case ATTR_NUMgENTRIES_: - case ATTR_MAXrENTRY_: - case ATTR_NUMrENTRIES_: - case ATTR_MAXzENTRY_: - case ATTR_NUMzENTRIES_: { - Logical maxOp = ONEof3(Va->item,ATTR_MAXgENTRY_, - ATTR_MAXrENTRY_, - ATTR_MAXzENTRY_); - int entryType = BOO(maxOp,E3p(Va->item,ATTR_MAXgENTRY_, - ATTR_MAXrENTRY_, - ATTR_MAXzENTRY_), - E3p(Va->item,ATTR_NUMgENTRIES_, - ATTR_NUMrENTRIES_, - ATTR_NUMzENTRIES_)); - struct CDFstruct *CDF; - long *value = va_arg (Va->ap, long *); - Int32 scope, gr, z; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED64(CDF)) return NO_ATTR_SELECTED; - if (!sX(ReadADR64(CDF->fp,CDF->CURattrOffset64, - ADR_SCOPE,&scope, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (GLOBALscope(scope)) { - if (entryType != gENTRYt) return ILLEGAL_FOR_SCOPE; - } - else { - if (entryType == gENTRYt) return ILLEGAL_FOR_SCOPE; - } - if (!sX(ReadADR64(CDF->fp,CDF->CURattrOffset64, - BOO(maxOp,ADR_MAXgrENTRY,ADR_NgrENTRIES),&gr, - BOO(maxOp,ADR_MAXzENTRY,ADR_NzENTRIES),&z, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (GLOBALscope(scope)) - *value = (long) gr; - else - if (zModeON(CDF)) - if (entryType == rENTRYt) - *value = (long) BOO(maxOp,NO_ENTRY,0); - /* Never any rEntries in zMode. */ - else - *value = (long) BOO(maxOp,BOO(z > NO_ENTRY,CDF->NrVars+z,gr),gr+z); - else - *value = (long) E3(entryType,BOO(maxOp,NO_ENTRY,0),gr,z); - break; - } - /**************************************************************************** - * gENTRY_DATATYPE_/rENTRY_DATATYPE_/zENTRY_DATATYPE_ - * gENTRY_NUMELEMS_/rENTRY_NUMELEMS_/zENTRY_NUMELEMS_ - * If this CDF is prior to CDF V2.1.1, the current attribute is named - * "VALIDMIN", "VALIDMAX", "SCALEMIN", or "SCALEMAX", this is a true rEntry, - * and the rEntry corresponds to an rVariable named "EPOCH", then return - * the CDF_EPOCH data type if the actual data type is CDF_REAL8 or CDF_DOUBLE. - * (The CDF_EPOCH data type was not introduced until CDF V2.1.1). Note that - * only rVariables were supported prior to CDF V2.3. - ****************************************************************************/ - case gENTRY_DATATYPE_: - case gENTRY_NUMELEMS_: - case rENTRY_DATATYPE_: - case rENTRY_NUMELEMS_: - case zENTRY_DATATYPE_: - case zENTRY_NUMELEMS_: { - Logical dataOp = ONEof3(Va->item,gENTRY_DATATYPE_, - rENTRY_DATATYPE_, - zENTRY_DATATYPE_); - int entryType = BOO(dataOp,E3p(Va->item,gENTRY_DATATYPE_, - rENTRY_DATATYPE_, - zENTRY_DATATYPE_), - E3p(Va->item,gENTRY_NUMELEMS_, - rENTRY_NUMELEMS_, - zENTRY_NUMELEMS_)); - struct CDFstruct *CDF; - long *value = va_arg (Va->ap, long *); - Int32 tValue; - OFF_T eOffset; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED64(CDF)) return NO_ATTR_SELECTED; - if (E3(entryType, - CDF->CURgrEntryNum, - CDF->CURgrEntryNum, - CDF->CURzEntryNum) == RESERVED_ENTRYNUM) return NO_ENTRY_SELECTED; - if (!sX(CheckEntryOp64(CDF,entryType),&pStatus)) return pStatus; - eOffset = E3(entryType,CDF->CURgrEntryOffset64, - CDF->CURgrEntryOffset64, - CDF->CURzEntryOffset64); - if (eOffset == (OFF_T) RESERVED_ENTRYOFFSET64) return NO_SUCH_ENTRY; - if (!sX(ReadAEDR64(CDF->fp,eOffset, - BOO(dataOp,AEDR_DATATYPE,AEDR_NUMELEMS),&tValue, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (dataOp && CDF->fakeEPOCH) { - char aName[CDF_ATTR_NAME_LEN256+1]; - if (!sX(ReadADR64(CDF->fp,CDF->CURattrOffset64, - ADR_NAME,aName, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!strcmpITB(aName,"VALIDMIN") || !strcmpITB(aName,"VALIDMAX") || - !strcmpITB(aName,"SCALEMIN") || !strcmpITB(aName,"SCALEMAX")) { - char vName[CDF_VAR_NAME_LEN256+1]; - OFF_T vOffset; - tStatus = FindVarByNumber64 (CDF, E3(entryType, CDF->CURgrEntryNum, - CDF->CURgrEntryNum, - CDF->CURzEntryNum), - FALSE, &vOffset); - switch (tStatus) { - case NO_SUCH_VAR: - break; - default: - if (!sX(tStatus,&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return tStatus; - } - if (!sX(ReadVDR64(CDF,CDF->fp,vOffset,FALSE, - VDR_NAME,vName, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!strcmpITB(vName,"EPOCH") && - FLOAT8dataType(tValue)) tValue = CDF_EPOCH; - if (!strcmpITB(vName,"EPOCH") && - FLOAT16dataType(tValue)) tValue = CDF_EPOCH16; - break; - } - } - } - *value = tValue; - break; - } - /**************************************************************************** - * gENTRY_DATA_/rENTRY_DATA_/zENTRY_DATA_, - ****************************************************************************/ - case gENTRY_DATA_: - case rENTRY_DATA_: - case zENTRY_DATA_: { - int entryType = E3p(Va->item,gENTRY_DATA_,rENTRY_DATA_,zENTRY_DATA_); - struct CDFstruct *CDF; - Int32 dataType, numElems; - OFF_T offset; - void *value = va_arg (Va->ap, void *); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED64(CDF)) return NO_ATTR_SELECTED; - if (E3(entryType, - CDF->CURgrEntryNum, - CDF->CURgrEntryNum, - CDF->CURzEntryNum) == RESERVED_ENTRYNUM) return NO_ENTRY_SELECTED; - if (!sX(CheckEntryOp64(CDF,entryType),&pStatus)) return pStatus; - offset = E3(entryType,CDF->CURgrEntryOffset64, - CDF->CURgrEntryOffset64, - CDF->CURzEntryOffset64); - if (offset == (OFF_T) RESERVED_ENTRYOFFSET64) return NO_SUCH_ENTRY; - if (!sX(ReadAEDR64(CDF->fp,offset, - AEDR_DATATYPE,&dataType, - AEDR_NUMELEMS,&numElems, - AEDR_VALUE,value, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(ConvertBuffer(CDF->encoding,CDF->decoding, - CDF->negToPosFp0,dataType, - numElems,value,value),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * Unknown item, must be the next function. - ****************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } -} -return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfgzip.c b/cdf36_3-dist/src/lib/cdfgzip.c deleted file mode 100644 index 9c1a81b..0000000 --- a/cdf36_3-dist/src/lib/cdfgzip.c +++ /dev/null @@ -1,201 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF GZIP compression/decompression -* based on ZLIB. -* -* Version 1.0, 27-Mar-12. -* -* Modification history: -* -* V1.0 18-Sep-12, M Liu Initial version. -* Compression/decompression is done by the -* open source ZLIB written by Jean-loup Gailly -* (compression) and Mark Adler (decompression). -* This version is based on their 1.2.7 release. -* Refer to: zlib.net for information. -* V1.1 18-Oct-13, M Liu Use zlib V1.2.8 with -DZ_PREFIX mode. -* -******************************************************************************/ - -#include "zlib/zconf.h" -#include "zlib/zlib.h" -#include "cdflib.h" - -#define CHUNK MIN_BLOCKING_BYTES_compressed - -/**************************************************************************** - * Local functions. - ****************************************************************************/ -static int defgzip(vFILE *src, vFILE *dst, Int32 iSize, Int32 *osize, int level); -static int infgzip(vFILE *src, Int32 iSize, vFILE *dst); - -/* Compress from file source to file dest until EOF on source. - defgzip() returns CDF_OK on success, or ZLIB_COMPRESS_ERROR for any error, - .e.g., if memory could not be allocated for processing, if an invalid - compression level is supplied, if the version of zlib.h and the - version of the library linked do not match, or if there is - an error reading or writing the files. */ - -static int defgzip(vFILE *source, vFILE *dest, Int32 iSize, Int32 *osize, - int level) -{ - int ret, flush; - unsigned have; - z_stream strm; - uChar in[CHUNK]; - uChar out[CHUNK]; - Int32 remaining; - unsigned mySize; - - *osize = 0; - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - ret = deflateInit2(&strm, level, Z_DEFLATED, MAX_WBITS+16, 8, 0); - if (ret != Z_OK) return ZLIB_COMPRESS_ERROR; - remaining = iSize; - do { - if (remaining > CHUNK) mySize = CHUNK; - else mySize = (unsigned) remaining; - strm.avail_in = (unsigned) V_read(in, (size_t) 1, (size_t) mySize, - source); - flush = (remaining == (Int32) mySize) ? Z_FINISH : Z_NO_FLUSH; - strm.next_in = in; - do { - strm.avail_out = CHUNK; - strm.next_out = out; - ret = deflate(&strm, flush); - if (ret == Z_STREAM_ERROR) - return ZLIB_COMPRESS_ERROR; - have = CHUNK - strm.avail_out; - if (have > 0) { - if (V_write(out, 1, (size_t) have, dest) != (size_t) have) { - (void) deflateEnd(&strm); - return ZLIB_COMPRESS_ERROR; - } - *osize += have; - } - } while (strm.avail_out == 0); - if (strm.avail_in != 0) - return ZLIB_COMPRESS_ERROR; - remaining -= (OFF_T) mySize; - } while (flush != Z_FINISH); - if (ret != Z_STREAM_END) - return ZLIB_COMPRESS_ERROR; - (void) deflateEnd(&strm); - return CDF_OK; -} - -/* Decompress from file source to file dest until stream ends or EOF. - infgzip() returns CDF_OK on success, or ZLIB_UNCOMPRESS_ERROR for any error, - e.g., if memory could not be allocated for processing, if the deflate data - is invalid or incomplete, if the version of zlib.h and - the version of the library linked do not match, or if there - is an error reading or writing the files. */ - -static int infgzip(vFILE *source, Int32 iSize, vFILE *dest) -{ - int ret; - unsigned int have; - z_stream strm; - uChar in[CHUNK]; - uChar out[CHUNK]; - - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - strm.avail_in = 0; - strm.next_in = Z_NULL; - ret = inflateInit2(&strm, 15+16); - if (ret != Z_OK) return ZLIB_UNCOMPRESS_ERROR; - do { - strm.avail_in = (unsigned) V_read(in, (size_t) 1, (size_t) CHUNK, - source); - ret = source->eof ? Z_STREAM_END : Z_NO_FLUSH; - if (strm.avail_in == 0) break; - strm.next_in = in; - do { - strm.avail_out = CHUNK; - strm.next_out = out; - ret = inflate(&strm, Z_NO_FLUSH); - if (ret == Z_STREAM_ERROR) - return ZLIB_UNCOMPRESS_ERROR; - switch (ret) { - case Z_NEED_DICT: - case Z_DATA_ERROR: - case Z_MEM_ERROR: - (void) inflateEnd(&strm); - return ZLIB_UNCOMPRESS_ERROR; - } - have = CHUNK - strm.avail_out; - if (have > 0) { - if (V_write(out, 1, (size_t) have, dest) != (size_t) have) { - (void) inflateEnd(&strm); - return ZLIB_UNCOMPRESS_ERROR; - } - } - } while (strm.avail_out == 0); - } while (ret != Z_STREAM_END); - (void) inflateEnd(&strm); - return ret == Z_STREAM_END ? CDF_OK : ZLIB_UNCOMPRESS_ERROR; - -} - -/****************************************************************************** -* CompressGZIP. -******************************************************************************/ - -STATICforIDL CDFstatus CompressGZIP (srcFp, srcOffset, srcSize, srcError, - destFp, destOffset, destSize, destError, - level) -vFILE *srcFp; -Int32 srcOffset; -Int32 srcSize; -CDFstatus srcError; -vFILE *destFp; -Int32 destOffset; -Int32 *destSize; -CDFstatus destError; -Int32 level; -{ -#if SUPPORT_GZIP - CDFstatus pStatus = CDF_OK; - if (!SEEKv(srcFp,srcOffset,vSEEK_SET)) return srcError; - if (!SEEKv(destFp,destOffset,vSEEK_SET)) return destError; - if (!sX(defgzip(srcFp,destFp,srcSize,destSize,level),&pStatus)) - return pStatus; - return pStatus; -#else - return UNKNOWN_COMPRESSION; -#endif -} - -/****************************************************************************** -* DecompressGZIP. -******************************************************************************/ - -STATICforIDL CDFstatus DecompressGZIP (srcFp, srcOffset, iSize, srcError, - destFp, destOffset, destError) -vFILE *srcFp; -Int32 srcOffset; -Int32 iSize; -CDFstatus srcError; -vFILE *destFp; -Int32 destOffset; -CDFstatus destError; -{ -#if SUPPORT_GZIP - CDFstatus pStatus = CDF_OK; - if (!SEEKv(srcFp,srcOffset,vSEEK_SET)) return srcError; - if (!SEEKv(destFp,destOffset,vSEEK_SET)) return destError; - if (!sX(infgzip(srcFp,iSize,destFp),&pStatus)) return pStatus; - return pStatus; -#else - return UNKNOWN_COMPRESSION; -#endif -} diff --git a/cdf36_3-dist/src/lib/cdfgzip64.c b/cdf36_3-dist/src/lib/cdfgzip64.c deleted file mode 100644 index dcee0b8..0000000 --- a/cdf36_3-dist/src/lib/cdfgzip64.c +++ /dev/null @@ -1,204 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF GZIP compression/decompression -* based on ZLIB. -* -* Version 1.0, 18-Sep-12. -* -* Modification history: -* -* V1.0 18-Sep-12, M Liu Initial version. -* Compression/decompression is done by the -* open source ZLIB written by Jean-loup Gailly -* (compression) and Mark Adler (decompression). -* This version is based on their 1.2.7 release. -* Refer to: zlib.net for information. -* V1.1 18-Oct-13, M Liu Use zlib V1.2.8 with -DZ_PREFIX mode. -* -******************************************************************************/ - -#include "zlib/zconf.h" -#include "zlib/zlib.h" -#include "cdflib.h" -#include "cdflib64.h" - -#define CHUNK MIN_BLOCKING_BYTES_compressed - -/**************************************************************************** - * Local functions. - ****************************************************************************/ -static int defgzip(vFILE *src, vFILE *dst, OFF_T iSize, OFF_T *osize, int level); -static int infgzip(vFILE *src, OFF_T iSize, vFILE *dst); - -/* Compress from file source to file dest until EOF on source. - defgzip() returns CDF_OK on success, or ZLIB_COMPRESS_ERROR for any error, - .e.g., if memory could not be allocated for processing, an invalid - compression level is supplied, the version of zlib.h and the - version of the library linked do not match, or there is - an error reading or writing the files. */ - -static int defgzip(vFILE *source, vFILE *dest, OFF_T iSize, OFF_T *osize, - int level) -{ - int ret, flush; - unsigned have; - z_stream strm; - uChar in[CHUNK]; - uChar out[CHUNK]; - OFF_T remaining; - unsigned mySize; - - *osize = 0; - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - ret = deflateInit2(&strm, level, Z_DEFLATED, MAX_WBITS+16, 8, 0); - if (ret != Z_OK) return ZLIB_COMPRESS_ERROR; - remaining = iSize; - do { - if (remaining > CHUNK) mySize = CHUNK; - else mySize = (unsigned) remaining; - strm.avail_in = (unsigned) V_read64(in, (size_t) 1, (size_t) mySize, - source); - flush = (remaining == (OFF_T) mySize) ? Z_FINISH : Z_NO_FLUSH; - strm.next_in = in; - do { - strm.avail_out = CHUNK; - strm.next_out = out; - ret = deflate(&strm, flush); - if (ret == Z_STREAM_ERROR) - return ZLIB_COMPRESS_ERROR; - have = CHUNK - strm.avail_out; - if (have > 0) { - if (V_write64(out, 1, (size_t) have, dest) != (size_t) have) { - (void) deflateEnd(&strm); - return ZLIB_COMPRESS_ERROR; - } - *osize += have; - } - } while (strm.avail_out == 0); - if (strm.avail_in != 0) - return ZLIB_COMPRESS_ERROR; - remaining -= (OFF_T) mySize; - } while (flush != Z_FINISH); - if (ret != Z_STREAM_END) - return ZLIB_COMPRESS_ERROR; - (void) deflateEnd(&strm); - return CDF_OK; - -} - -/* Decompress from file source to file dest until stream ends or EOF. - inflate will set the status to end when a full block of compressed data is - decompressed. infgzip() returns CDF_OK on success, or ZLIB_UNCOMPRESS_ERROR - for any error, e.g., if memory could not be allocated for processing, - the deflate data is invalid or incomplete, the version of zlib.h and - the version of the library linked do not match, or there - is an error reading or writing the files. */ - -static int infgzip(vFILE *source, OFF_T iSize, vFILE *dest) -{ - int ret; - unsigned int have; - z_stream strm; - uChar in[CHUNK]; - uChar out[CHUNK]; - - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - strm.avail_in = 0; - strm.next_in = Z_NULL; - ret = inflateInit2(&strm, 15+16); - if (ret != Z_OK) return ZLIB_UNCOMPRESS_ERROR; - do { - strm.avail_in = (unsigned) V_read64(in, (size_t) 1, (size_t) CHUNK, - source); - ret = source->eof ? Z_STREAM_END : Z_NO_FLUSH; - if (strm.avail_in == 0) break; - strm.next_in = in; - do { - strm.avail_out = CHUNK; - strm.next_out = out; - ret = inflate(&strm, Z_NO_FLUSH); - if (ret == Z_STREAM_ERROR) - return ZLIB_UNCOMPRESS_ERROR; - switch (ret) { - case Z_NEED_DICT: - case Z_DATA_ERROR: - case Z_MEM_ERROR: - (void) inflateEnd(&strm); - return ZLIB_UNCOMPRESS_ERROR; - } - have = CHUNK - strm.avail_out; - if (have > 0) { - if (V_write64(out, 1, (size_t) have, dest) != (size_t) have) { - (void) inflateEnd(&strm); - return ZLIB_UNCOMPRESS_ERROR; - } - } - } while (strm.avail_out == 0); - } while (ret != Z_STREAM_END); - (void) inflateEnd(&strm); - return ret == Z_STREAM_END ? CDF_OK : ZLIB_UNCOMPRESS_ERROR; - -} - -/****************************************************************************** -* CompressGZIP_64. -******************************************************************************/ - -STATICforIDL CDFstatus CompressGZIP_64 (srcFp, srcOffset, srcSize, srcError, - destFp, destOffset, destSize, destError, - level) -vFILE *srcFp; -OFF_T srcOffset; -OFF_T srcSize; -CDFstatus srcError; -vFILE *destFp; -OFF_T destOffset; -OFF_T *destSize; -CDFstatus destError; -Int32 level; -{ -#if SUPPORT_GZIP64 - CDFstatus pStatus = CDF_OK; - if (!SEEKv64(srcFp,srcOffset,vSEEK_SET)) return srcError; - if (!SEEKv64(destFp,destOffset,vSEEK_SET)) return destError; - if (!sX(defgzip(srcFp,destFp,srcSize,destSize,level),&pStatus)) - return pStatus; - return pStatus; -#else - return UNKNOWN_COMPRESSION; -#endif -} - -/****************************************************************************** -* DecompressGZIP_64. -******************************************************************************/ - -STATICforIDL CDFstatus DecompressGZIP_64 (srcFp, srcOffset, iSize, srcError, - destFp, destOffset, destError) -vFILE *srcFp; -OFF_T srcOffset; -OFF_T iSize; -CDFstatus srcError; -vFILE *destFp; -OFF_T destOffset; -CDFstatus destError; -{ -#if SUPPORT_GZIP64 - CDFstatus pStatus = CDF_OK; - if (!SEEKv64(srcFp,srcOffset,vSEEK_SET)) return srcError; - if (!SEEKv64(destFp,destOffset,vSEEK_SET)) return destError; - if (!sX(infgzip(srcFp,iSize,destFp),&pStatus)) return pStatus; - return pStatus; -#else - return UNKNOWN_COMPRESSION; -#endif -} diff --git a/cdf36_3-dist/src/lib/cdfhuff.c b/cdf36_3-dist/src/lib/cdfhuff.c deleted file mode 100644 index 5c05af0..0000000 --- a/cdf36_3-dist/src/lib/cdfhuff.c +++ /dev/null @@ -1,1281 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Huffman compression/decompression. -* -* Version 1.0b, 2-Sep-97, Hughes STX. -* -* Modification history: -* -* V1.0 22-Jul-96, J Love Original version. -* -* Algorithms in this file are from a book written -* by Mark Nelson, "The Data Compression Book." -* This book was published by M&T Books in 1992 -* and no copyright is claimed (see below). -* -* The Huffman code and Adaptive Huffman code -* are from pages 64-78 and 109-121, respectively. -* -* Slight modfications were made to the Huffman and -* Adpative Huffman algorithms to work with the -* existing CDF libray code. -* -* Limits of Liability and Disclaimer of Warranty -* The Author and Publisher of this book have used their best -* efforts in preparing the book and the programs contained in it. -* These efforts include the development, research, and testing -* of the theories and programs to determine their effectiveness. -* -* The Author and Publisher make no warranty of any kind, -* expressed or implied, with regard to these programs or the -* documentation contained in this book. The Author and -* Publisher shall not be liable in any event for incidental or -* consequential damages in connection with, or arising out of, -* the furnishing, performance, or use of these programs. -* -* Liberal Code Use Policy (http://marknelson.us/code-use-policy) -* It is my intention that anyone who buys the book or magazine be free -* to use the source code in any form they please. I only request that -* any use that involves public reproduction include proper attribution. -* any use that involves public reproduction include proper attribution. -* -* I assert that in no case will I initiate or cooperate with any attempt -* to enforce the copyright on the source code, whether it belongs to me -* or a publisher. -* -* The code I publish is written for clarity, not efficiency. Once you -* massage the code to work with your product, it is likely to be -* significantly different from the published code anyway. -* -* Nobody from any of the companies that publish my work is even remotely -* interested in pursuing people for unauthorized use of source code. -* They don’t have anyone on their staffs to deal with problems like this, -* and they probably don’t even want to think about it. -* -* What the publishers are concerned about is you writing books or -* articles that copy their stuff. Don’t do that, and you can be certain -* that they will be happy. -* -* None of the code I publish is warranted in any way by me or the -* publisher to be free of defects. If you need bullet-proof software -* that is guaranteed to work as promised you will need to adopt a -* methodology considerably more rigid than that of simply purchasing -* a book or magazine. -* -* V1.0a 28-Feb-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V1.0b 2-Sep-97, J Love Type casting for ANSI C. -* -******************************************************************************/ - -#include "cdflib.h" - -#if (!SUPPORT_HUFF || !SUPPORT_AHUFF) && defined(BORLANDC) -#pragma warn -par -#endif - -/****************************************************************************** -* Macros/prototypes. -******************************************************************************/ - -typedef uByte BYTE; -typedef uInt16 WORD; -typedef uInt32 DWORD; - -typedef uInt4 INT4; /* Needed to pass a WORD by value. */ - -/* - * The NODE structure is a node in the Huffman decoding tree. It has a - * count, which is its weight in the tree, and the node numbers of its - * two children. The saved_count member of the structure is only - * there for debugging purposes, and can be safely taken out at any - * time. It just holds the intial count for each of the symbols, since - * the count member is continually being modified as the tree grows. - */ -typedef struct tree_node { - WORD count; - WORD saved_count; - int child_0; - int child_1; -} NODE; - -/* - * A Huffman tree is set up for decoding, not encoding. When encoding, - * I first walk through the tree and build up a table of codes for - * each symbol. The codes are stored in this CODE structure. - */ -typedef struct code { - WORD code; - int code_bits; -} CODE; - -/* - * The special EOS symbol is 256, the first available symbol after all - * of the possible bytes. When decoding, reading this symbols - * indicates that all of the data has been read in. - */ -#define END_OF_STREAM 256 - -typedef struct bit_file { - vFILE *file; - BYTE mask; - int rack; -} BIT_FILE; - -#define END_OF_STREAM 256 -#define ESCAPE 257 -#define SYMBOL_COUNT 258 -#define NODE_TABLE_COUNT ((SYMBOL_COUNT*2)-1) -#define ROOT_NODE 0 -#define MAX_WEIGHT 0x8000 - -/* - * This data structure is all that is needed to maintain an adaptive - * Huffman tree for both encoding and decoding. The leaf array is a - * set of indices into the nodes that indicate which node is the - * parent of a symbol. For example, to encode 'A', we would find the - * leaf node by way of leaf[ 'A' ]. The next_free_node index is used - * to tell which node is the next one in the array that can be used. - * Since nodes are allocated when characters are read in for the first - * time, this pointer keeps track of where we are in the node array. - * Finally, the array of nodes is the actual Huffman tree. The child - * index is either an index pointing to a pair of children, or an - * actual symbol value, depending on whether 'child_is_leaf' is true - * or false. - */ - -typedef struct tree { - int leaf[ SYMBOL_COUNT ]; - int next_free_node; - struct node { - WORD weight; - int parent; - int child_is_leaf; - int child; - } nodes[ NODE_TABLE_COUNT ]; -} TREE; - -#if SUPPORT_HUFF || SUPPORT_AHUFF -static BIT_FILE *StartBitFile PROTOARGs((vFILE *fp)); -static Logical EndOutputBitFile PROTOARGs((BIT_FILE *bit_file)); -static Logical EndInputBitFile PROTOARGs((BIT_FILE *bit_file)); -static Logical OutputBits PROTOARGs(( - BIT_FILE *bit_file, DWORD code, int count -)); -static int InputBit PROTOARGs((BIT_FILE *bit_file)); -#endif - -#if SUPPORT_HUFF -static Logical output_counts PROTOARGs((BIT_FILE *output, NODE *nodes)); -static Logical count_bytes PROTOARGs(( - vFILE *input, DWORD *counts, Int32 iSize -)); -static void scale_counts PROTOARGs((DWORD *counts, NODE *nodes)); -static int build_tree PROTOARGs((NODE *nodes)); -static void convert_tree_to_code PROTOARGs(( - NODE *nodes, CODE *codes, INT4 code_so_far, int bits, int node -)); -static CDFstatus compress_data PROTOARGs(( - vFILE *input, BIT_FILE *output, CODE *codes, Int32 iSize, CDFstatus iError, - CDFstatus oError -)); -static Logical input_counts PROTOARGs((BIT_FILE *input, NODE *nodes)); -static CDFstatus expand_data PROTOARGs(( - BIT_FILE *input, vFILE *output, NODE *nodes, int root_node, CDFstatus iError, - CDFstatus oError -)); -#endif - -#if SUPPORT_AHUFF -static void InitializeTree PROTOARGs((TREE *tree)); -static Logical EncodeSymbol PROTOARGs((TREE *tree, INT4 c, BIT_FILE *output)); -static int DecodeSymbol PROTOARGs((TREE *tree, BIT_FILE *input)); -static void UpdateModel PROTOARGs((TREE *tree, int c)); -static void RebuildTree PROTOARGs((TREE *tree)); -static void swap_nodes PROTOARGs((TREE *tree, int i, int j)); -static void add_new_node PROTOARGs((TREE *tree, int c)); -static DWORD InputBits PROTOARGs((BIT_FILE *bit_file, int bit_count)); -#endif - -/****************************************************************************** -* CompressHUFF0. -******************************************************************************/ - -STATICforIDL CDFstatus CompressHUFF0 (input, iOffset, iSize, iError, - oFp, oOffset, oSize, oError) -vFILE *input; -Int32 iOffset; -Int32 iSize; -CDFstatus iError; -vFILE *oFp; -Int32 oOffset; -Int32 *oSize; -CDFstatus oError; -{ -#if SUPPORT_HUFF - BIT_FILE *output; DWORD *counts; NODE *nodes; CODE *codes; - CDFstatus pStatus = CDF_OK; int root_node; long newOffset; - if (!SEEKv(input,(long)iOffset,vSEEK_SET)) return iError; - if (!SEEKv(oFp,(long)oOffset,vSEEK_SET)) return oError; - output = StartBitFile (oFp); - if (output == NULL) return BAD_MALLOC; - *oSize = 0; - counts = (DWORD *) CallocateMemory (256, sizeof(DWORD), NULL); - if (counts == NULL) { - cdf_FreeMemory (output, NULL); - return BAD_MALLOC; - } - nodes = (NODE *) CallocateMemory (514, sizeof(NODE), NULL); - if (nodes == NULL) { - cdf_FreeMemory (counts, NULL); - cdf_FreeMemory (output, NULL); - return BAD_MALLOC; - } - codes = (CODE *) CallocateMemory (257, sizeof(CODE), NULL); - if (codes == NULL) { - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (counts, NULL); - cdf_FreeMemory (output, NULL); - return BAD_MALLOC; - } - if (!count_bytes(input,counts,iSize)) { - cdf_FreeMemory (codes, NULL); - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (counts, NULL); - cdf_FreeMemory (output, NULL); - return iError; - } - scale_counts (counts, nodes); - if (!output_counts(output,nodes)) { - cdf_FreeMemory (codes, NULL); - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (counts, NULL); - cdf_FreeMemory (output, NULL); - return oError; - } - root_node = build_tree (nodes); - convert_tree_to_code (nodes, codes, (INT4) 0, 0, root_node); - if (!sX(compress_data(input,output,codes,iSize,iError,oError),&pStatus)) { - cdf_FreeMemory (codes, NULL); - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (counts, NULL); - cdf_FreeMemory (output, NULL); - return pStatus; - } - if (!EndOutputBitFile(output)) { - cdf_FreeMemory (codes, NULL); - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (counts, NULL); - return oError; - } - newOffset = V_tell (oFp); - if (newOffset == EOF) { - cdf_FreeMemory (codes, NULL); - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (counts, NULL); - return oError; - } - *oSize = newOffset - oOffset; - cdf_FreeMemory (codes, NULL); - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (counts, NULL); - return pStatus; -#else - return UNKNOWN_COMPRESSION; -#endif -} - -/****************************************************************************** -* DecompressHUFF0. -******************************************************************************/ - -STATICforIDL CDFstatus DecompressHUFF0 (iFp, iOffset, iError, - output, oOffset, oError) -vFILE *iFp; -Int32 iOffset; -CDFstatus iError; -vFILE *output; -Int32 oOffset; -CDFstatus oError; -{ -#if SUPPORT_HUFF - CDFstatus pStatus = CDF_OK; BIT_FILE *input; NODE *nodes; int root_node; - if (!SEEKv(iFp,(long)iOffset,vSEEK_SET)) return iError; - if (!SEEKv(output,(long)oOffset,vSEEK_SET)) return oError; - input = StartBitFile (iFp); - if (input == NULL) return BAD_MALLOC; - nodes = (NODE *) CallocateMemory (514, sizeof(NODE), NULL); - if (nodes == NULL) { - cdf_FreeMemory (input, NULL); - return BAD_MALLOC; - } - if (!input_counts(input,nodes)) { - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (input, NULL); - return iError; - } - root_node = build_tree( nodes ); - if (!sX(expand_data(input,output,nodes,root_node,iError,oError),&pStatus)) { - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (input, NULL); - return pStatus; - } - if (!EndInputBitFile(input)) { - cdf_FreeMemory (nodes, NULL); - return iError; - } - cdf_FreeMemory (nodes, NULL); - return pStatus; -#else - return UNKNOWN_COMPRESSION; -#endif -} - -/****************************************************************************** -* CompressAHUFF0. -******************************************************************************/ - -/* - * The high level view of the compression routine is very simple. - * First, we initialize the Huffman tree, with just the ESCAPE and - * END_OF_STREAM symbols. Then, we sit in a loop, encoding symbols, - * and adding them to the model. When there are no more characters - * to send, the special END_OF_STREAM symbol is encoded. The decoder - * will later be able to use this symbol to know when to quit. - */ - -STATICforIDL CDFstatus CompressAHUFF0 (input, iOffset, iSize, iError, - oFp, oOffset, oSize, oError) -vFILE *input; -Int32 iOffset; -Int32 iSize; -CDFstatus iError; -vFILE *oFp; -Int32 oOffset; -Int32 *oSize; -CDFstatus oError; -{ -#if SUPPORT_AHUFF - CDFstatus pStatus = CDF_OK; BIT_FILE *output; TREE *Tree; - int c; Int32 i; long newOffset; - if (!SEEKv(input,(long)iOffset,vSEEK_SET)) return iError; - if (!SEEKv(oFp,(long)oOffset,vSEEK_SET)) return oError; - output = StartBitFile (oFp); - if (output == NULL) return BAD_MALLOC; - *oSize = 0; - Tree = (TREE *) CallocateMemory (1, sizeof(TREE), NULL); - if (Tree == NULL) { - cdf_FreeMemory (output, NULL); - return BAD_MALLOC; - } - InitializeTree (Tree); - for (i = 0; i < iSize; i++) { - if ((c = V_getc(input)) == EOF) { - cdf_FreeMemory (Tree, NULL); - cdf_FreeMemory (output, NULL); - return iError; - } - if (!EncodeSymbol(Tree,(INT4)c,output)) { - cdf_FreeMemory (Tree, NULL); - cdf_FreeMemory (output, NULL); - return oError; - } - UpdateModel (Tree, c); - } - if (!EncodeSymbol(Tree,(INT4)END_OF_STREAM,output)) { - cdf_FreeMemory (Tree, NULL); - cdf_FreeMemory (output, NULL); - return oError; - } - if (!EndOutputBitFile(output)) { - cdf_FreeMemory (Tree, NULL); - return oError; - } - newOffset = V_tell (oFp); - if (newOffset == EOF) { - cdf_FreeMemory (Tree, NULL); - return oError; - } - *oSize = newOffset - oOffset; - cdf_FreeMemory (Tree, NULL); - return pStatus; -#else - return UNKNOWN_COMPRESSION; -#endif -} - -/****************************************************************************** -* DecompressAHUFF0. -******************************************************************************/ - -STATICforIDL CDFstatus DecompressAHUFF0 (iFp, iOffset, iError, - output, oOffset, oError) -vFILE *iFp; -Int32 iOffset; -CDFstatus iError; -vFILE *output; -Int32 oOffset; -CDFstatus oError; -{ -#if SUPPORT_AHUFF - CDFstatus pStatus = CDF_OK; BIT_FILE *input; TREE *Tree; int c; - if (!SEEKv(iFp,(long)iOffset,vSEEK_SET)) return iError; - if (!SEEKv(output,(long)oOffset,vSEEK_SET)) return oError; - input = StartBitFile (iFp); - if (input == NULL) return BAD_MALLOC; - Tree = (TREE *) CallocateMemory (1, sizeof(TREE), NULL); - if (Tree == NULL) { - cdf_FreeMemory (input, NULL); - return BAD_MALLOC; - } - InitializeTree (Tree); - while ((c = DecodeSymbol(Tree,input)) != END_OF_STREAM) { - if (c == EOF) { - cdf_FreeMemory (Tree, NULL); - cdf_FreeMemory (input, NULL); - return iError; - } - if (V_putc(c,output) == EOF) { - cdf_FreeMemory (Tree, NULL); - cdf_FreeMemory (input, NULL); - return oError; - } - UpdateModel (Tree, c); - } - if (!EndInputBitFile(input)) { - cdf_FreeMemory (Tree, NULL); - return iError; - } - cdf_FreeMemory (Tree, NULL); - return pStatus; -#else - return UNKNOWN_COMPRESSION; -#endif -} - -#if SUPPORT_HUFF -/****************************************************************************** -* output_counts. -******************************************************************************/ -/* - * In order for the compressor to build the same model, I have to store - * the symbol counts in the compressed file so the expander can read - * them in. In order to save space, I don't save all 256 symbols - * unconditionally. The format used to store counts looks like this: - * - * start, stop, counts, start, stop, counts, ... 0 - * - * This means that I store runs of counts, until all the non-zero - * counts have been stored. At this time the list is terminated by - * storing a start value of 0. Note that at least 1 run of counts has - * to be stored, so even if the first start value is 0, I read it in. - * It also means that even in an empty file that has no counts, I have - * to pass at least one count. - * - * In order to efficiently use this format, I have to identify runs of - * non-zero counts. Because of the format used, I don't want to stop a - * run because of just one or two zeros in the count stream. So I have - * to sit in a loop looking for strings of three or more zero values in - * a row. - * - * This is simple in concept, but it ends up being one of the most - * complicated routines in the whole program. A routine that just - * writes out 256 values without attempting to optimize would be much - * simpler, but would hurt compression quite a bit on small files. - * - */ -static Logical output_counts (output, nodes) -BIT_FILE *output; -NODE *nodes; -{ - int first; - int last; - int next; - int i; - - first = 0; - while ( first < 255 && nodes[ first ].count == 0 ) - first++; -/* - * Each time I hit the start of the loop, I assume that first is the - * number for a run of non-zero values. The rest of the loop is - * concerned with finding the value for last, which is the end of the - * run, and the value of next, which is the start of the next run. - * At the end of the loop, I assign next to first, so it starts in on - * the next run. - */ - for ( ; first < 256 ; first = next ) { - last = first + 1; - for ( ; ; ) { - for ( ; last < 256 ; last++ ) - if ( nodes[ last ].count == 0 ) - break; - last--; - for ( next = last + 1; next < 256 ; next++ ) - if ( nodes[ next ].count != 0 ) - break; - if ( next > 255 ) - break; - if ( ( next - last ) > 3 ) - break; - last = next; - }; -/* - * Here is where I output first, last, and all the counts in between. - */ - if (V_putc(first,output->file) != first) return FALSE; - if (V_putc(last,output->file) != last) return FALSE; - for ( i = first ; i <= last ; i++ ) { - if (V_putc((int) nodes[ i ].count, output->file ) != - (int) nodes[ i ].count ) return FALSE; - } - } - if (V_putc(0,output->file) != 0) return FALSE; - return TRUE; -} -#endif - -#if SUPPORT_HUFF -/****************************************************************************** -* count_bytes. -******************************************************************************/ -/* - * This routine counts the frequency of occurence of every byte in - * the input file. It marks the place in the input stream where it - * started, counts up all the bytes, then returns to the place where - * it started. In most C implementations, the length of a file - * cannot exceed an unsigned long, so this routine should always - * work. - */ - -static Logical count_bytes( input, counts, iSize ) -vFILE *input; -DWORD *counts; -Int32 iSize; -{ - long input_marker; - int c; - Int32 i; - - input_marker = V_tell (input); - if (input_marker == EOF) return FALSE; - - for (i = 0; i < iSize; i++) { - if ((c = V_getc(input)) == EOF) return FALSE; - counts[c]++; - } - - if (!SEEKv(input,input_marker,vSEEK_SET)) return FALSE; - return TRUE; -} -#endif - -#if SUPPORT_HUFF -/****************************************************************************** -* scale_counts. -******************************************************************************/ -/* - * In order to limit the size of my Huffman codes to 16 bits, I scale - * my counts down so they fit in an unsigned char, and then store them - * all as initial weights in my NODE array. The only thing to be - * careful of is to make sure that a node with a non-zero count doesn't - * get scaled down to 0. Nodes with values of 0 don't get codes. - */ -static void scale_counts( counts, nodes ) -DWORD *counts; -NODE *nodes; -{ - DWORD max_count; - int i; - - max_count = 0; - for ( i = 0 ; i < 256 ; i++ ) - if ( counts[ i ] > max_count ) - max_count = counts[ i ]; - if ( max_count == 0 ) { - counts[ 0 ] = 1; - max_count = 1; - } - max_count = max_count / 255; - max_count = max_count + 1; - for ( i = 0 ; i < 256 ; i++ ) { - nodes[ i ].count = (WORD) ( counts[ i ] / max_count ); - if ( nodes[ i ].count == 0 && counts[ i ] != 0 ) - nodes[ i ].count = 1; - } - nodes[ END_OF_STREAM ].count = 1; -} -#endif - -#if SUPPORT_HUFF -/****************************************************************************** -* build_tree. -******************************************************************************/ -/* - * Building the Huffman tree is fairly simple. All of the active nodes - * are scanned in order to locate the two nodes with the minimum - * weights. These two weights are added together and assigned to a new - * node. The new node makes the two minimum nodes into its 0 child - * and 1 child. The two minimum nodes are then marked as inactive. - * This process repeats until their is only one node left, which is the - * root node. The tree is done, and the root node is passed back - * to the calling routine. - * - * Node 513 is used here to arbitratily provide a node with a guaranteed - * maximum value. It starts off being min_1 and min_2. After all active - * nodes have been scanned, I can tell if there is only one active node - * left by checking to see if min_1 is still 513. - */ -static int build_tree( nodes ) -NODE *nodes; -{ - int next_free; - int i; - int min_1; - int min_2; - - nodes[ 513 ].count = 0xffff; - for ( next_free = END_OF_STREAM + 1 ; ; next_free++ ) { - min_1 = 513; - min_2 = 513; - for ( i = 0 ; i < next_free ; i++ ) - if ( nodes[ i ].count != 0 ) { - if ( nodes[ i ].count < nodes[ min_1 ].count ) { - min_2 = min_1; - min_1 = i; - } else if ( nodes[ i ].count < nodes[ min_2 ].count ) - min_2 = i; - } - if ( min_2 == 513 ) - break; - nodes[ next_free ].count = nodes[ min_1 ].count - + nodes[ min_2 ].count; - nodes[ min_1 ].saved_count = nodes[ min_1 ].count; - nodes[ min_1 ].count = 0; - nodes[ min_2 ].saved_count = nodes[ min_2 ].count; - nodes[ min_2 ].count = 0; - nodes[ next_free ].child_0 = min_1; - nodes[ next_free ].child_1 = min_2; - } - next_free--; - nodes[ next_free ].saved_count = nodes[ next_free ].count; - return( next_free ); -} -#endif - -#if SUPPORT_HUFF -/****************************************************************************** -* convert_tree_to_code. -******************************************************************************/ -/* - * Since the Huffman tree is built as a decoding tree, there is - * no simple way to get the encoding values for each symbol out of - * it. This routine recursively walks through the tree, adding the - * child bits to each code until it gets to a leaf. When it gets - * to a leaf, it stores the code value in the CODE element, and - * returns. - */ -static void convert_tree_to_code( nodes, codes, code_so_far, bits, node ) -NODE *nodes; -CODE *codes; -INT4 code_so_far; -int bits; -int node; -{ - if (node <= END_OF_STREAM) { - codes[node].code = (WORD) code_so_far; - codes[node].code_bits = bits; - return; - } - code_so_far <<= 1; - bits++; - convert_tree_to_code (nodes, codes, code_so_far, bits, nodes[node].child_0 ); - convert_tree_to_code (nodes, codes, (INT4) (code_so_far | 1), - bits, nodes[node].child_1 ); - return; -} -#endif - -#if SUPPORT_HUFF -/****************************************************************************** -* compress_data. -******************************************************************************/ -/* - * Once the tree gets built, and the CODE table is built, compressing - * the data is a breeze. Each byte is read in, and its corresponding - * Huffman code is sent out. - */ - -static CDFstatus compress_data( input, output, codes, iSize, iError, oError) -vFILE *input; -BIT_FILE *output; -CODE *codes; -Int32 iSize; -CDFstatus iError; -CDFstatus oError; -{ - int c; - long i; - - for (i = 0; i < iSize; i++) { - if ((c = V_getc(input)) == EOF) return iError; - if (!OutputBits(output,(DWORD)codes[c].code,codes[ c ].code_bits)) { - return oError; - } - } - if (!OutputBits(output,(DWORD)codes[END_OF_STREAM].code, - codes[END_OF_STREAM].code_bits)) return oError; - return CDF_OK; -} -#endif - -#if SUPPORT_HUFF || SUPPORT_AHUFF -/****************************************************************************** -* StartBitFile. -******************************************************************************/ - -static BIT_FILE *StartBitFile (fp) -vFILE *fp; -{ - BIT_FILE *bit_file; - bit_file = (BIT_FILE *) CallocateMemory (1, sizeof(BIT_FILE), NULL); - if (bit_file == NULL) return NULL; - bit_file->file = fp; - bit_file->rack = 0; - bit_file->mask = 0x80; - return bit_file; -} -#endif - -#if SUPPORT_HUFF || SUPPORT_AHUFF -/****************************************************************************** -* EndOutputBitFile. -******************************************************************************/ - -static Logical EndOutputBitFile (bit_file) -BIT_FILE *bit_file; -{ - Logical status = TRUE; - if (bit_file->mask != 0x80) { - if (V_putc(bit_file->rack, - bit_file->file) != bit_file->rack) status = FALSE; - } - cdf_FreeMemory (bit_file, NULL); - return status; -} -#endif - -#if SUPPORT_HUFF || SUPPORT_AHUFF -/****************************************************************************** -* EndInputBitFile. -******************************************************************************/ - -static Logical EndInputBitFile (bit_file) -BIT_FILE *bit_file; -{ - cdf_FreeMemory (bit_file, NULL); - return TRUE; -} -#endif - -#if SUPPORT_HUFF || SUPPORT_AHUFF -/****************************************************************************** -* OutputBits. -******************************************************************************/ - -static Logical OutputBits( bit_file, code, count ) -BIT_FILE *bit_file; -DWORD code; -int count; -{ - DWORD mask; - - mask = 1L << ( count - 1 ); - while ( mask != 0) { - if ( mask & code ) bit_file->rack |= bit_file->mask; - bit_file->mask >>= 1; - if ( bit_file->mask == 0 ) { - if (V_putc( bit_file->rack, bit_file->file ) != bit_file->rack ) { - return FALSE; - } - bit_file->rack = 0; - bit_file->mask = 0x80; - } - mask >>= 1; - } - return TRUE; -} -#endif - -#if SUPPORT_HUFF || SUPPORT_AHUFF -/****************************************************************************** -* InputBit. -******************************************************************************/ - -static int InputBit (bit_file) -BIT_FILE *bit_file; -{ - int value; - if ( bit_file->mask == 0x80 ) { - bit_file->rack = V_getc( bit_file->file ); - if ( bit_file->rack == EOF ) return EOF; - } - value = bit_file->rack & bit_file->mask; - bit_file->mask >>= 1; - if ( bit_file->mask == 0 ) bit_file->mask = 0x80; - return ( value ? 1 : 0 ); -} -#endif - -#if SUPPORT_AHUFF -/****************************************************************************** -* InputBits. -******************************************************************************/ - -static DWORD InputBits( bit_file, bit_count ) - BIT_FILE *bit_file; - int bit_count; -{ - DWORD mask; - DWORD return_value; - - mask = 1L << ( bit_count - 1 ); - return_value = 0; - while ( mask != 0) { - if ( bit_file->mask == 0x80 ) { - bit_file->rack = V_getc( bit_file->file ); - if ( bit_file->rack == EOF ) return ((DWORD) EOF); - } - if ( bit_file->rack & bit_file->mask ) return_value |= mask; - mask >>= 1; - bit_file->mask >>= 1; - if ( bit_file->mask == 0 ) bit_file->mask = 0x80; - } - return( return_value ); -} -#endif - -#if SUPPORT_HUFF -/****************************************************************************** -* input_counts. -******************************************************************************/ -/* - * When expanding, I have to read in the same set of counts. This is - * quite a bit easier that the process of writing them out, since no - * decision making needs to be done. All I do is read in first, check - * to see if I am all done, and if not, read in last and a string of - * counts. - */ - -static Logical input_counts( input, nodes ) -BIT_FILE *input; -NODE *nodes; -{ - int first; - int last; - int i; - int c; - - for ( i = 0 ; i < 256 ; i++ ) nodes[ i ].count = 0; - if ( ( first = V_getc( input->file ) ) == EOF ) return FALSE; - if ( ( last = V_getc( input->file ) ) == EOF ) return FALSE; - for ( ; ; ) { - for ( i = first ; i <= last ; i++ ) { - if ( ( c = V_getc( input->file ) ) == EOF ) return FALSE; - nodes[ i ].count = (WORD) c; - } - if ( ( first = V_getc( input->file ) ) == EOF ) return FALSE; - if ( first == 0 ) break; - if ( ( last = V_getc( input->file ) ) == EOF ) return FALSE; - } - nodes[ END_OF_STREAM ].count = 1; - return TRUE; -} -#endif - -#if SUPPORT_HUFF -/****************************************************************************** -* expand_data. -******************************************************************************/ -/* - * Expanding compressed data is a little harder than the compression - * phase. As each new symbol is decoded, the tree is traversed, - * starting at the root node, reading a bit in, and taking either the - * child_0 or child_1 path. Eventually, the tree winds down to a - * leaf node, and the corresponding symbol is output. If the symbol - * is the END_OF_STREAM symbol, it doesn't get written out, and - * instead the whole process terminates. - */ -static CDFstatus expand_data( input, output, nodes, root_node, iError, oError) -BIT_FILE *input; -vFILE *output; -NODE *nodes; -int root_node; -CDFstatus iError; -CDFstatus oError; -{ - int node; - - for ( ; ; ) { - node = root_node; - do { - int bit = InputBit (input); - if (bit == EOF) return iError; - if (bit) - node = nodes[ node ].child_1; - else - node = nodes[ node ].child_0; - } while ( node > END_OF_STREAM ); - if ( node == END_OF_STREAM ) break; - if ( ( V_putc( node, output ) ) != node ) return oError; - } - return CDF_OK; -} -#endif - -#if SUPPORT_AHUFF -/****************************************************************************** -* InitializeTree. -******************************************************************************/ - -/* - * When performing adaptive compression, the Huffman tree starts out - * very nearly empty. The only two symbols present initially are the - * ESCAPE symbol and the END_OF_STREAM symbol. The ESCAPE symbol has to - * be included so we can tell the expansion prog that we are transmitting a - * previously unseen symbol. The END_OF_STREAM symbol is here because - * it is greater than eight bits, and our ESCAPE sequence only allows for - * eight bit symbols following the ESCAPE code. - * - * In addition to setting up the root node and its two children, this - * routine also initializes the leaf array. The ESCAPE and END_OF_STREAM - * leaf elements are the only ones initially defined, the rest of the leaf - * elements are set to -1 to show that they aren't present in the - * Huffman tree yet. - */ - -static void InitializeTree( tree ) -TREE *tree; -{ - int i; - - tree->nodes[ ROOT_NODE ].child = ROOT_NODE + 1; - tree->nodes[ ROOT_NODE ].child_is_leaf = FALSE; - tree->nodes[ ROOT_NODE ].weight = 2; - tree->nodes[ ROOT_NODE ].parent = -1; - - tree->nodes[ ROOT_NODE + 1 ].child = END_OF_STREAM; - tree->nodes[ ROOT_NODE + 1 ].child_is_leaf = TRUE; - tree->nodes[ ROOT_NODE + 1 ].weight = 1; - tree->nodes[ ROOT_NODE + 1 ].parent = ROOT_NODE; - tree->leaf[ END_OF_STREAM ] = ROOT_NODE + 1; - - tree->nodes[ ROOT_NODE + 2 ].child = ESCAPE; - tree->nodes[ ROOT_NODE + 2 ].child_is_leaf = TRUE; - tree->nodes[ ROOT_NODE + 2 ].weight = 1; - tree->nodes[ ROOT_NODE + 2 ].parent = ROOT_NODE; - tree->leaf[ ESCAPE ] = ROOT_NODE + 2; - - tree->next_free_node = ROOT_NODE + 3; - - for ( i = 0 ; i < END_OF_STREAM ; i++ ) tree->leaf[ i ] = -1; -} -#endif - -#if SUPPORT_AHUFF -/****************************************************************************** -* EncodeSymbol. -******************************************************************************/ - -/* - * This routine is responsible for taking a symbol, and converting - * it into the sequence of bits dictated by the Huffman tree. The - * only complication is that we are working are way up from the leaf - * to the root, and hence are getting the bits in reverse order. This - * means we have to rack up the bits in an integer and then send them - * out after they are all accumulated. In this version of the program, - * we keep our codes in a long integer, so the maximum count is set - * to an arbitray limit of 0x8000. It could be set as high as 65535 - * if desired. - */ - -static Logical EncodeSymbol( tree, c, output ) -TREE *tree; -INT4 c; -BIT_FILE *output; -{ - DWORD code; - DWORD current_bit; - int code_size; - int current_node; - - code = 0; - current_bit = 1; - code_size = 0; - current_node = tree->leaf[(int)c]; - if ( current_node == -1 ) current_node = tree->leaf[ ESCAPE ]; - while ( current_node != ROOT_NODE ) { - if ( ( current_node & 1 ) == 0 ) code |= current_bit; - current_bit <<= 1; - code_size++; - current_node = tree->nodes[ current_node ].parent; - }; - if (!OutputBits(output,code,code_size)) return FALSE; - if ( tree->leaf[(int)c] == -1 ) { - if (!OutputBits(output,(DWORD)c,8)) return FALSE; - add_new_node( tree, (int) c ); - } - return TRUE; -} -#endif - -#if SUPPORT_AHUFF -/****************************************************************************** -* DecodeSymbol. -******************************************************************************/ - -/* - * Decoding symbols is easy. We start at the root node, then go down - * the tree until we reach a leaf. At each node, we decide which - * child to take based on the next input bit. After getting to the - * leaf, we check to see if we read in the ESCAPE code. If we did, - * it means that the next symbol is going to come through in the next - * eight bits, unencoded. If that is the case, we read it in here, - * and add the new symbol to the table. - */ - -static int DecodeSymbol (tree, input) -TREE *tree; -BIT_FILE *input; -{ - int current_node; - int c; - int bit; - - current_node = ROOT_NODE; - while ( !tree->nodes[ current_node ].child_is_leaf ) { - current_node = tree->nodes[ current_node ].child; - bit = InputBit (input); - if (bit == EOF) return EOF; - current_node += bit; - } - c = tree->nodes[ current_node ].child; - if ( c == ESCAPE ) { - c = (int) InputBits( input, 8 ); - if (c == EOF) return EOF; - add_new_node( tree, c ); - } - return( c ); -} -#endif - -#if SUPPORT_AHUFF -/****************************************************************************** -* UpdateModel. -******************************************************************************/ - -/* - * UpdateModel is called to increment the count for a given symbol. - * After incrementing the symbol, this code has to work its way up - * through the parent nodes, incrementing each one of them. That is - * the easy part. The hard part is that after incrementing each - * parent node, we have to check to see if it is now out of the proper - * order. If it is, it has to be moved up the tree into its proper - * place. - */ - -static void UpdateModel( tree, c ) -TREE *tree; -int c; -{ - int current_node; - int new_node; - - if ( tree->nodes[ ROOT_NODE].weight == MAX_WEIGHT ) RebuildTree( tree ); - current_node = tree->leaf[ c ]; - while ( current_node != -1 ) { - tree->nodes[ current_node ].weight++; - for ( new_node = current_node ; new_node > ROOT_NODE ; new_node-- ) - if ( tree->nodes[ new_node - 1 ].weight >= - tree->nodes[ current_node ].weight ) - break; - if ( current_node != new_node ) { - swap_nodes( tree, current_node, new_node ); - current_node = new_node; - } - current_node = tree->nodes[ current_node ].parent; - } - - return; -} -#endif - -#if SUPPORT_AHUFF -/****************************************************************************** -* RebuildTree. -******************************************************************************/ - -/* - * Rebuilding the tree takes place when the counts have gone too - * high. From a simple point of view, rebuilding the tree just means that - * we divide every count by two. Unfortunately, due to truncation effects, - * this means that the tree's shape might change. Some nodes might move - * up due to cumulative increases, while others may move down. - */ - -static void RebuildTree( tree ) -TREE *tree; -{ - int i; - int j; - int k; - WORD weight; - -/* - * To start rebuilding the table, I collect all the leaves of the Huffman - * tree and put them in the end of the tree. While I am doing that, I - * scale the counts down by a factor of 2. - */ - j = tree->next_free_node - 1; - for ( i = j ; i >= ROOT_NODE ; i-- ) { - if ( tree->nodes[ i ].child_is_leaf ) { - tree->nodes[ j ] = tree->nodes[ i ]; - tree->nodes[ j ].weight = (tree->nodes[j].weight + 1) / ((WORD) 2); - j--; - } - } - -/* - * At this point, j points to the first free node. I now have all the - * leaves defined, and need to start building the higher nodes on the - * tree. I will start adding the new internal nodes at j. Every time - * I add a new internal node to the top of the tree, I have to check to - * see where it really belongs in the tree. It might stay at the top, - * but there is a good chance I might have to move it back down. If it - * does have to go down, I use the memmove() function to scoot everyone - * bigger up by one node. Note that memmove() may have to be change - * to memcpy() on some UNIX systems. The parameters are unchanged, as - * memmove and memcpy have the same set of parameters. - */ - for ( i = tree->next_free_node - 2 ; j >= ROOT_NODE ; i -= 2, j-- ) { - k = i + 1; - tree->nodes[ j ].weight = tree->nodes[ i ].weight + - tree->nodes[ k ].weight; - weight = tree->nodes[ j ].weight; - tree->nodes[ j ].child_is_leaf = FALSE; - for ( k = j + 1 ; weight < tree->nodes[ k ].weight ; k++ ) - ; - k--; - memmove( &tree->nodes[ j ], &tree->nodes[ j + 1 ], - ( k - j ) * sizeof( struct node ) ); - tree->nodes[ k ].weight = weight; - tree->nodes[ k ].child = i; - tree->nodes[ k ].child_is_leaf = FALSE; - } -/* - * The final step in tree reconstruction is to go through and set up - * all of the leaf and parent members. This can be safely done now - * that every node is in its final position in the tree. - */ - for ( i = tree->next_free_node - 1 ; i >= ROOT_NODE ; i-- ) { - if ( tree->nodes[ i ].child_is_leaf ) { - k = tree->nodes[ i ].child; - tree->leaf[ k ] = i; - } else { - k = tree->nodes[ i ].child; - tree->nodes[ k ].parent = tree->nodes[ k + 1 ].parent = i; - } - } - - return; -} -#endif - -#if SUPPORT_AHUFF -/****************************************************************************** -* swap_nodes. -******************************************************************************/ - -/* - * Swapping nodes takes place when a node has grown too big for its - * spot in the tree. When swapping nodes i and j, we rearrange the - * tree by exchanging the children under i with the children under j. - */ - -static void swap_nodes( tree, i, j ) -TREE *tree; -int i; -int j; -{ - struct node temp; - - if ( tree->nodes[ i ].child_is_leaf ) - tree->leaf[ tree->nodes[ i ].child ] = j; - else { - tree->nodes[ tree->nodes[ i ].child ].parent = j; - tree->nodes[ tree->nodes[ i ].child + 1 ].parent = j; - } - if ( tree->nodes[ j ].child_is_leaf ) - tree->leaf[ tree->nodes[ j ].child ] = i; - else { - tree->nodes[ tree->nodes[ j ].child ].parent = i; - tree->nodes[ tree->nodes[ j ].child + 1 ].parent = i; - } - temp = tree->nodes[ i ]; - tree->nodes[ i ] = tree->nodes[ j ]; - tree->nodes[ i ].parent = temp.parent; - temp.parent = tree->nodes[ j ].parent; - tree->nodes[ j ] = temp; - - return; -} -#endif - -#if SUPPORT_AHUFF -/****************************************************************************** -* add_new_node. -******************************************************************************/ - -/* - * Adding a new node to the tree is pretty simple. It is just a matter - * of splitting the lightest-weight node in the tree, which is the highest - * valued node. We split it off into two new nodes, one of which is the - * one being added to the tree. We assign the new node a weight of 0, - * so the tree doesn't have to be adjusted. It will be updated later when - * the normal update process occurs. Note that this code assumes that - * the lightest node has a leaf as a child. If this is not the case, - * the tree would be broken. - */ - -static void add_new_node( tree, c ) -TREE *tree; -int c; -{ - int lightest_node; - int new_node; - int zero_weight_node; - - lightest_node = tree->next_free_node - 1; - new_node = tree->next_free_node; - zero_weight_node = tree->next_free_node + 1; - tree->next_free_node += 2; - - tree->nodes[ new_node ] = tree->nodes[ lightest_node ]; - tree->nodes[ new_node ].parent = lightest_node; - tree->leaf[ tree->nodes[ new_node ].child ] = new_node; - - tree->nodes[ lightest_node ].child = new_node; - tree->nodes[ lightest_node ].child_is_leaf = FALSE; - - tree->nodes[ zero_weight_node ].child = c; - tree->nodes[ zero_weight_node ].child_is_leaf = TRUE; - tree->nodes[ zero_weight_node ].weight = 0; - tree->nodes[ zero_weight_node ].parent = lightest_node; - tree->leaf[ c ] = zero_weight_node; - return; -} -#endif diff --git a/cdf36_3-dist/src/lib/cdfhuff64.c b/cdf36_3-dist/src/lib/cdfhuff64.c deleted file mode 100644 index 5434d49..0000000 --- a/cdf36_3-dist/src/lib/cdfhuff64.c +++ /dev/null @@ -1,1282 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Huffman compression/decompression. -* -* Version 1.0b, 2-Sep-97, Hughes STX. -* -* Modification history: -* -* V1.0 22-Jul-96, J Love Original version. -* -* Algorithms in this file are from a book written -* by Mark Nelson, "The Data Compression Book." -* This book was published by M&T Books in 1992 -* and no copyright is claimed (see below). -* -* The Huffman code and Adaptive Huffman code -* are from pages 64-78 and 109-121, respectively. -* -* Slight modfications were made to the Huffman and -* Adpative Huffman algorithms to work with the -* existing CDF libray code. -* -* Limits of Liability and Disclaimer of Warranty -* The Author and Publisher of this book have used their best -* efforts in preparing the book and the programs contained in it. -* These efforts include the development, research, and testing -* of the theories and programs to determine their effectiveness. -* -* The Author and Publisher make no warranty of any kind, -* expressed or implied, with regard to these programs or the -* documentation contained in this book. The Author and -* Publisher shall not be liable in any event for incidental or -* consequential damages in connection with, or arising out of, -* the furnishing, performance, or use of these programs. -* -* Liberal Code Use Policy (http://marknelson.us/code-use-policy) -* It is my intention that anyone who buys the book or magazine be free -* to use the source code in any form they please. I only request that -* any use that involves public reproduction include proper attribution. -* any use that involves public reproduction include proper attribution. -* -* I assert that in no case will I initiate or cooperate with any attempt -* to enforce the copyright on the source code, whether it belongs to me -* or a publisher. -* -* The code I publish is written for clarity, not efficiency. Once you -* massage the code to work with your product, it is likely to be -* significantly different from the published code anyway. -* -* Nobody from any of the companies that publish my work is even remotely -* interested in pursuing people for unauthorized use of source code. -* They don’t have anyone on their staffs to deal with problems like this, -* and they probably don’t even want to think about it. -* -* What the publishers are concerned about is you writing books or -* articles that copy their stuff. Don’t do that, and you can be certain -* that they will be happy. -* -* None of the code I publish is warranted in any way by me or the -* publisher to be free of defects. If you need bullet-proof software -* that is guaranteed to work as promised you will need to adopt a -* methodology considerably more rigid than that of simply purchasing -* a book or magazine. -* -* V1.0a 28-Feb-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V1.0b 2-Sep-97, J Love Type casting for ANSI C. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -#if (!SUPPORT_HUFF64 || !SUPPORT_AHUFF64) && defined(BORLANDC) -#pragma warn -par -#endif - -/****************************************************************************** -* Macros/prototypes. -******************************************************************************/ - -typedef uByte BYTE; -typedef uInt16 WORD; -typedef uInt32 DWORD; - -typedef uInt4 INT4; /* Needed to pass a WORD by value. */ - -/* - * The NODE structure is a node in the Huffman decoding tree. It has a - * count, which is its weight in the tree, and the node numbers of its - * two children. The saved_count member of the structure is only - * there for debugging purposes, and can be safely taken out at any - * time. It just holds the intial count for each of the symbols, since - * the count member is continually being modified as the tree grows. - */ -typedef struct tree_node { - WORD count; - WORD saved_count; - int child_0; - int child_1; -} NODE; - -/* - * A Huffman tree is set up for decoding, not encoding. When encoding, - * I first walk through the tree and build up a table of codes for - * each symbol. The codes are stored in this CODE structure. - */ -typedef struct code { - WORD code; - int code_bits; -} CODE; - -/* - * The special EOS symbol is 256, the first available symbol after all - * of the possible bytes. When decoding, reading this symbols - * indicates that all of the data has been read in. - */ -#define END_OF_STREAM 256 - -typedef struct bit_file { - vFILE *file; - BYTE mask; - int rack; -} BIT_FILE; - -#define END_OF_STREAM 256 -#define ESCAPE 257 -#define SYMBOL_COUNT 258 -#define NODE_TABLE_COUNT ((SYMBOL_COUNT*2)-1) -#define ROOT_NODE 0 -#define MAX_WEIGHT 0x8000 - -/* - * This data structure is all that is needed to maintain an adaptive - * Huffman tree for both encoding and decoding. The leaf array is a - * set of indices into the nodes that indicate which node is the - * parent of a symbol. For example, to encode 'A', we would find the - * leaf node by way of leaf[ 'A' ]. The next_free_node index is used - * to tell which node is the next one in the array that can be used. - * Since nodes are allocated when characters are read in for the first - * time, this pointer keeps track of where we are in the node array. - * Finally, the array of nodes is the actual Huffman tree. The child - * index is either an index pointing to a pair of children, or an - * actual symbol value, depending on whether 'child_is_leaf' is true - * or false. - */ - -typedef struct tree { - int leaf[ SYMBOL_COUNT ]; - int next_free_node; - struct node { - WORD weight; - int parent; - int child_is_leaf; - int child; - } nodes[ NODE_TABLE_COUNT ]; -} TREE; - -#if SUPPORT_HUFF64 || SUPPORT_AHUFF64 -static BIT_FILE *StartBitFile PROTOARGs((vFILE *fp)); -static Logical EndOutputBitFile PROTOARGs((BIT_FILE *bit_file)); -static Logical EndInputBitFile PROTOARGs((BIT_FILE *bit_file)); -static Logical OutputBits PROTOARGs(( - BIT_FILE *bit_file, DWORD code, int count -)); -static int InputBit PROTOARGs((BIT_FILE *bit_file)); -#endif - -#if SUPPORT_HUFF64 -static Logical output_counts PROTOARGs((BIT_FILE *output, NODE *nodes)); -static Logical count_bytes PROTOARGs(( - vFILE *input, DWORD *counts, OFF_T iSize -)); -static void scale_counts PROTOARGs((DWORD *counts, NODE *nodes)); -static int build_tree PROTOARGs((NODE *nodes)); -static void convert_tree_to_code PROTOARGs(( - NODE *nodes, CODE *codes, INT4 code_so_far, int bits, int node -)); -static CDFstatus compress_data PROTOARGs(( - vFILE *input, BIT_FILE *output, CODE *codes, OFF_T iSize, CDFstatus iError, - CDFstatus oError -)); -static Logical input_counts PROTOARGs((BIT_FILE *input, NODE *nodes)); -static CDFstatus expand_data PROTOARGs(( - BIT_FILE *input, vFILE *output, NODE *nodes, int root_node, CDFstatus iError, - CDFstatus oError -)); -#endif - -#if SUPPORT_AHUFF64 -static void InitializeTree PROTOARGs((TREE *tree)); -static Logical EncodeSymbol PROTOARGs((TREE *tree, INT4 c, BIT_FILE *output)); -static int DecodeSymbol PROTOARGs((TREE *tree, BIT_FILE *input)); -static void UpdateModel PROTOARGs((TREE *tree, int c)); -static void RebuildTree PROTOARGs((TREE *tree)); -static void swap_nodes PROTOARGs((TREE *tree, int i, int j)); -static void add_new_node PROTOARGs((TREE *tree, int c)); -static DWORD InputBits PROTOARGs((BIT_FILE *bit_file, int bit_count)); -#endif - -/****************************************************************************** -* CompressHUFF0_64. -******************************************************************************/ - -STATICforIDL CDFstatus CompressHUFF0_64 (input, iOffset, iSize, iError, - oFp, oOffset, oSize, oError) -vFILE *input; -OFF_T iOffset; -OFF_T iSize; -CDFstatus iError; -vFILE *oFp; -OFF_T oOffset; -OFF_T *oSize; -CDFstatus oError; -{ -#if SUPPORT_HUFF64 - BIT_FILE *output; DWORD *counts; NODE *nodes; CODE *codes; - CDFstatus pStatus = CDF_OK; int root_node; OFF_T newOffset; - if (!SEEKv64(input,iOffset,vSEEK_SET)) return iError; - if (!SEEKv64(oFp,oOffset,vSEEK_SET)) return oError; - output = StartBitFile (oFp); - if (output == NULL) return BAD_MALLOC; - *oSize = 0; - counts = (DWORD *) CallocateMemory (256, sizeof(DWORD), NULL); - if (counts == NULL) { - cdf_FreeMemory (output, NULL); - return BAD_MALLOC; - } - nodes = (NODE *) CallocateMemory (514, sizeof(NODE), NULL); - if (nodes == NULL) { - cdf_FreeMemory (counts, NULL); - cdf_FreeMemory (output, NULL); - return BAD_MALLOC; - } - codes = (CODE *) CallocateMemory (257, sizeof(CODE), NULL); - if (codes == NULL) { - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (counts, NULL); - cdf_FreeMemory (output, NULL); - return BAD_MALLOC; - } - if (!count_bytes(input,counts,iSize)) { - cdf_FreeMemory (codes, NULL); - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (counts, NULL); - cdf_FreeMemory (output, NULL); - return iError; - } - scale_counts (counts, nodes); - if (!output_counts(output,nodes)) { - cdf_FreeMemory (codes, NULL); - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (counts, NULL); - cdf_FreeMemory (output, NULL); - return oError; - } - root_node = build_tree (nodes); - convert_tree_to_code (nodes, codes, (INT4) 0, 0, root_node); - if (!sX(compress_data(input,output,codes,iSize,iError,oError),&pStatus)) { - cdf_FreeMemory (codes, NULL); - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (counts, NULL); - cdf_FreeMemory (output, NULL); - return pStatus; - } - if (!EndOutputBitFile(output)) { - cdf_FreeMemory (codes, NULL); - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (counts, NULL); - return oError; - } - newOffset = V_tell64 (oFp); - if (newOffset == EOF) { - cdf_FreeMemory (codes, NULL); - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (counts, NULL); - return oError; - } - *oSize = newOffset - oOffset; - cdf_FreeMemory (codes, NULL); - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (counts, NULL); - return pStatus; -#else - return UNKNOWN_COMPRESSION; -#endif -} - -/****************************************************************************** -* DecompressHUFF0_64. -******************************************************************************/ - -STATICforIDL CDFstatus DecompressHUFF0_64 (iFp, iOffset, iError, - output, oOffset, oError) -vFILE *iFp; -OFF_T iOffset; -CDFstatus iError; -vFILE *output; -OFF_T oOffset; -CDFstatus oError; -{ -#if SUPPORT_HUFF64 - CDFstatus pStatus = CDF_OK; BIT_FILE *input; NODE *nodes; int root_node; - if (!SEEKv64(iFp,iOffset,vSEEK_SET)) return iError; - if (!SEEKv64(output,oOffset,vSEEK_SET)) return oError; - input = StartBitFile (iFp); - if (input == NULL) return BAD_MALLOC; - nodes = (NODE *) CallocateMemory (514, sizeof(NODE), NULL); - if (nodes == NULL) { - cdf_FreeMemory (input, NULL); - return BAD_MALLOC; - } - if (!input_counts(input,nodes)) { - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (input, NULL); - return iError; - } - root_node = build_tree( nodes ); - if (!sX(expand_data(input,output,nodes,root_node,iError,oError),&pStatus)) { - cdf_FreeMemory (nodes, NULL); - cdf_FreeMemory (input, NULL); - return pStatus; - } - if (!EndInputBitFile(input)) { - cdf_FreeMemory (nodes, NULL); - return iError; - } - cdf_FreeMemory (nodes, NULL); - return pStatus; -#else - return UNKNOWN_COMPRESSION; -#endif -} - -/****************************************************************************** -* CompressAHUFF0_64. -******************************************************************************/ - -/* - * The high level view of the compression routine is very simple. - * First, we initialize the Huffman tree, with just the ESCAPE and - * END_OF_STREAM symbols. Then, we sit in a loop, encoding symbols, - * and adding them to the model. When there are no more characters - * to send, the special END_OF_STREAM symbol is encoded. The decoder - * will later be able to use this symbol to know when to quit. - */ - -STATICforIDL CDFstatus CompressAHUFF0_64 (input, iOffset, iSize, iError, - oFp, oOffset, oSize, oError) -vFILE *input; -OFF_T iOffset; -OFF_T iSize; -CDFstatus iError; -vFILE *oFp; -OFF_T oOffset; -OFF_T *oSize; -CDFstatus oError; -{ -#if SUPPORT_AHUFF64 - CDFstatus pStatus = CDF_OK; BIT_FILE *output; TREE *Tree; - int c; Int32 i; OFF_T newOffset; - if (!SEEKv64(input,iOffset,vSEEK_SET)) return iError; - if (!SEEKv64(oFp,oOffset,vSEEK_SET)) return oError; - output = StartBitFile (oFp); - if (output == NULL) return BAD_MALLOC; - *oSize = 0; - Tree = (TREE *) CallocateMemory (1, sizeof(TREE), NULL); - if (Tree == NULL) { - cdf_FreeMemory (output, NULL); - return BAD_MALLOC; - } - InitializeTree (Tree); - for (i = 0; i < iSize; i++) { - if ((c = V_getc64(input)) == EOF) { - cdf_FreeMemory (Tree, NULL); - cdf_FreeMemory (output, NULL); - return iError; - } - if (!EncodeSymbol(Tree,(INT4)c,output)) { - cdf_FreeMemory (Tree, NULL); - cdf_FreeMemory (output, NULL); - return oError; - } - UpdateModel (Tree, c); - } - if (!EncodeSymbol(Tree,(INT4)END_OF_STREAM,output)) { - cdf_FreeMemory (Tree, NULL); - cdf_FreeMemory (output, NULL); - return oError; - } - if (!EndOutputBitFile(output)) { - cdf_FreeMemory (Tree, NULL); - return oError; - } - newOffset = V_tell64 (oFp); - if (newOffset == EOF) { - cdf_FreeMemory (Tree, NULL); - return oError; - } - *oSize = newOffset - oOffset; - cdf_FreeMemory (Tree, NULL); - return pStatus; -#else - return UNKNOWN_COMPRESSION; -#endif -} - -/****************************************************************************** -* DecompressAHUFF0_64. -******************************************************************************/ - -STATICforIDL CDFstatus DecompressAHUFF0_64 (iFp, iOffset, iError, - output, oOffset, oError) -vFILE *iFp; -OFF_T iOffset; -CDFstatus iError; -vFILE *output; -OFF_T oOffset; -CDFstatus oError; -{ -#if SUPPORT_AHUFF64 - CDFstatus pStatus = CDF_OK; BIT_FILE *input; TREE *Tree; int c; - if (!SEEKv64(iFp,iOffset,vSEEK_SET)) return iError; - if (!SEEKv64(output,oOffset,vSEEK_SET)) return oError; - input = StartBitFile (iFp); - if (input == NULL) return BAD_MALLOC; - Tree = (TREE *) CallocateMemory (1, sizeof(TREE), NULL); - if (Tree == NULL) { - cdf_FreeMemory (input, NULL); - return BAD_MALLOC; - } - InitializeTree (Tree); - while ((c = DecodeSymbol(Tree,input)) != END_OF_STREAM) { - if (c == EOF) { - cdf_FreeMemory (Tree, NULL); - cdf_FreeMemory (input, NULL); - return iError; - } - if (V_putc64(c,output) == EOF) { - cdf_FreeMemory (Tree, NULL); - cdf_FreeMemory (input, NULL); - return oError; - } - UpdateModel (Tree, c); - } - if (!EndInputBitFile(input)) { - cdf_FreeMemory (Tree, NULL); - return iError; - } - cdf_FreeMemory (Tree, NULL); - return pStatus; -#else - return UNKNOWN_COMPRESSION; -#endif -} - -#if SUPPORT_HUFF64 -/****************************************************************************** -* output_counts. -******************************************************************************/ -/* - * In order for the compressor to build the same model, I have to store - * the symbol counts in the compressed file so the expander can read - * them in. In order to save space, I don't save all 256 symbols - * unconditionally. The format used to store counts looks like this: - * - * start, stop, counts, start, stop, counts, ... 0 - * - * This means that I store runs of counts, until all the non-zero - * counts have been stored. At this time the list is terminated by - * storing a start value of 0. Note that at least 1 run of counts has - * to be stored, so even if the first start value is 0, I read it in. - * It also means that even in an empty file that has no counts, I have - * to pass at least one count. - * - * In order to efficiently use this format, I have to identify runs of - * non-zero counts. Because of the format used, I don't want to stop a - * run because of just one or two zeros in the count stream. So I have - * to sit in a loop looking for strings of three or more zero values in - * a row. - * - * This is simple in concept, but it ends up being one of the most - * complicated routines in the whole program. A routine that just - * writes out 256 values without attempting to optimize would be much - * simpler, but would hurt compression quite a bit on small files. - * - */ -static Logical output_counts (output, nodes) -BIT_FILE *output; -NODE *nodes; -{ - int first; - int last; - int next; - int i; - - first = 0; - while ( first < 255 && nodes[ first ].count == 0 ) - first++; -/* - * Each time I hit the start of the loop, I assume that first is the - * number for a run of non-zero values. The rest of the loop is - * concerned with finding the value for last, which is the end of the - * run, and the value of next, which is the start of the next run. - * At the end of the loop, I assign next to first, so it starts in on - * the next run. - */ - for ( ; first < 256 ; first = next ) { - last = first + 1; - for ( ; ; ) { - for ( ; last < 256 ; last++ ) - if ( nodes[ last ].count == 0 ) - break; - last--; - for ( next = last + 1; next < 256 ; next++ ) - if ( nodes[ next ].count != 0 ) - break; - if ( next > 255 ) - break; - if ( ( next - last ) > 3 ) - break; - last = next; - }; -/* - * Here is where I output first, last, and all the counts in between. - */ - if (V_putc64(first,output->file) != first) return FALSE; - if (V_putc64(last,output->file) != last) return FALSE; - for ( i = first ; i <= last ; i++ ) { - if (V_putc64((int) nodes[ i ].count, output->file ) != - (int) nodes[ i ].count ) return FALSE; - } - } - if (V_putc64(0,output->file) != 0) return FALSE; - return TRUE; -} -#endif - -#if SUPPORT_HUFF64 -/****************************************************************************** -* count_bytes. -******************************************************************************/ -/* - * This routine counts the frequency of occurence of every byte in - * the input file. It marks the place in the input stream where it - * started, counts up all the bytes, then returns to the place where - * it started. In most C implementations, the length of a file - * cannot exceed an unsigned long, so this routine should always - * work. - */ - -static Logical count_bytes( input, counts, iSize ) -vFILE *input; -DWORD *counts; -OFF_T iSize; -{ - OFF_T input_marker; - int c; - Int32 i; - - input_marker = V_tell64 (input); - if (input_marker == EOF) return FALSE; - - for (i = 0; i < iSize; i++) { - if ((c = V_getc64(input)) == EOF) return FALSE; - counts[c]++; - } - - if (!SEEKv64(input,input_marker,vSEEK_SET)) return FALSE; - return TRUE; -} -#endif - -#if SUPPORT_HUFF64 -/****************************************************************************** -* scale_counts. -******************************************************************************/ -/* - * In order to limit the size of my Huffman codes to 16 bits, I scale - * my counts down so they fit in an unsigned char, and then store them - * all as initial weights in my NODE array. The only thing to be - * careful of is to make sure that a node with a non-zero count doesn't - * get scaled down to 0. Nodes with values of 0 don't get codes. - */ -static void scale_counts( counts, nodes ) -DWORD *counts; -NODE *nodes; -{ - DWORD max_count; - int i; - - max_count = 0; - for ( i = 0 ; i < 256 ; i++ ) - if ( counts[ i ] > max_count ) - max_count = counts[ i ]; - if ( max_count == 0 ) { - counts[ 0 ] = 1; - max_count = 1; - } - max_count = max_count / 255; - max_count = max_count + 1; - for ( i = 0 ; i < 256 ; i++ ) { - nodes[ i ].count = (WORD) ( counts[ i ] / max_count ); - if ( nodes[ i ].count == 0 && counts[ i ] != 0 ) - nodes[ i ].count = 1; - } - nodes[ END_OF_STREAM ].count = 1; -} -#endif - -#if SUPPORT_HUFF64 -/****************************************************************************** -* build_tree. -******************************************************************************/ -/* - * Building the Huffman tree is fairly simple. All of the active nodes - * are scanned in order to locate the two nodes with the minimum - * weights. These two weights are added together and assigned to a new - * node. The new node makes the two minimum nodes into its 0 child - * and 1 child. The two minimum nodes are then marked as inactive. - * This process repeats until their is only one node left, which is the - * root node. The tree is done, and the root node is passed back - * to the calling routine. - * - * Node 513 is used here to arbitratily provide a node with a guaranteed - * maximum value. It starts off being min_1 and min_2. After all active - * nodes have been scanned, I can tell if there is only one active node - * left by checking to see if min_1 is still 513. - */ -static int build_tree( nodes ) -NODE *nodes; -{ - int next_free; - int i; - int min_1; - int min_2; - - nodes[ 513 ].count = 0xffff; - for ( next_free = END_OF_STREAM + 1 ; ; next_free++ ) { - min_1 = 513; - min_2 = 513; - for ( i = 0 ; i < next_free ; i++ ) - if ( nodes[ i ].count != 0 ) { - if ( nodes[ i ].count < nodes[ min_1 ].count ) { - min_2 = min_1; - min_1 = i; - } else if ( nodes[ i ].count < nodes[ min_2 ].count ) - min_2 = i; - } - if ( min_2 == 513 ) - break; - nodes[ next_free ].count = nodes[ min_1 ].count - + nodes[ min_2 ].count; - nodes[ min_1 ].saved_count = nodes[ min_1 ].count; - nodes[ min_1 ].count = 0; - nodes[ min_2 ].saved_count = nodes[ min_2 ].count; - nodes[ min_2 ].count = 0; - nodes[ next_free ].child_0 = min_1; - nodes[ next_free ].child_1 = min_2; - } - next_free--; - nodes[ next_free ].saved_count = nodes[ next_free ].count; - return( next_free ); -} -#endif - -#if SUPPORT_HUFF64 -/****************************************************************************** -* convert_tree_to_code. -******************************************************************************/ -/* - * Since the Huffman tree is built as a decoding tree, there is - * no simple way to get the encoding values for each symbol out of - * it. This routine recursively walks through the tree, adding the - * child bits to each code until it gets to a leaf. When it gets - * to a leaf, it stores the code value in the CODE element, and - * returns. - */ -static void convert_tree_to_code( nodes, codes, code_so_far, bits, node ) -NODE *nodes; -CODE *codes; -INT4 code_so_far; -int bits; -int node; -{ - if (node <= END_OF_STREAM) { - codes[node].code = (WORD) code_so_far; - codes[node].code_bits = bits; - return; - } - code_so_far <<= 1; - bits++; - convert_tree_to_code (nodes, codes, code_so_far, bits, nodes[node].child_0 ); - convert_tree_to_code (nodes, codes, (INT4) (code_so_far | 1), - bits, nodes[node].child_1 ); - return; -} -#endif - -#if SUPPORT_HUFF64 -/****************************************************************************** -* compress_data. -******************************************************************************/ -/* - * Once the tree gets built, and the CODE table is built, compressing - * the data is a breeze. Each byte is read in, and its corresponding - * Huffman code is sent out. - */ - -static CDFstatus compress_data( input, output, codes, iSize, iError, oError) -vFILE *input; -BIT_FILE *output; -CODE *codes; -OFF_T iSize; -CDFstatus iError; -CDFstatus oError; -{ - int c; - long i; - - for (i = 0; i < iSize; i++) { - if ((c = V_getc64(input)) == EOF) return iError; - if (!OutputBits(output,(DWORD)codes[c].code,codes[ c ].code_bits)) { - return oError; - } - } - if (!OutputBits(output,(DWORD)codes[END_OF_STREAM].code, - codes[END_OF_STREAM].code_bits)) return oError; - return CDF_OK; -} -#endif - -#if SUPPORT_HUFF6464 || SUPPORT_AHUFF64 -/****************************************************************************** -* StartBitFile. -******************************************************************************/ - -static BIT_FILE *StartBitFile (fp) -vFILE *fp; -{ - BIT_FILE *bit_file; - bit_file = (BIT_FILE *) CallocateMemory (1, sizeof(BIT_FILE), NULL); - if (bit_file == NULL) return NULL; - bit_file->file = fp; - bit_file->rack = 0; - bit_file->mask = 0x80; - return bit_file; -} -#endif - -#if SUPPORT_HUFF64 || SUPPORT_AHUFF64 -/****************************************************************************** -* EndOutputBitFile. -******************************************************************************/ - -static Logical EndOutputBitFile (bit_file) -BIT_FILE *bit_file; -{ - Logical status = TRUE; - if (bit_file->mask != 0x80) { - if (V_putc64(bit_file->rack, - bit_file->file) != bit_file->rack) status = FALSE; - } - cdf_FreeMemory (bit_file, NULL); - return status; -} -#endif - -#if SUPPORT_HUFF64 || SUPPORT_AHUFF64 -/****************************************************************************** -* EndInputBitFile. -******************************************************************************/ - -static Logical EndInputBitFile (bit_file) -BIT_FILE *bit_file; -{ - cdf_FreeMemory (bit_file, NULL); - return TRUE; -} -#endif - -#if SUPPORT_HUFF64 || SUPPORT_AHUFF64 -/****************************************************************************** -* OutputBits. -******************************************************************************/ - -static Logical OutputBits( bit_file, code, count ) -BIT_FILE *bit_file; -DWORD code; -int count; -{ - DWORD mask; - - mask = 1L << ( count - 1 ); - while ( mask != 0) { - if ( mask & code ) bit_file->rack |= bit_file->mask; - bit_file->mask >>= 1; - if ( bit_file->mask == 0 ) { - if (V_putc64( bit_file->rack, bit_file->file ) != bit_file->rack ) { - return FALSE; - } - bit_file->rack = 0; - bit_file->mask = 0x80; - } - mask >>= 1; - } - return TRUE; -} -#endif - -#if SUPPORT_HUFF64 || SUPPORT_AHUFF64 -/****************************************************************************** -* InputBit. -******************************************************************************/ - -static int InputBit (bit_file) -BIT_FILE *bit_file; -{ - int value; - if ( bit_file->mask == 0x80 ) { - bit_file->rack = V_getc64( bit_file->file ); - if ( bit_file->rack == EOF ) return EOF; - } - value = bit_file->rack & bit_file->mask; - bit_file->mask >>= 1; - if ( bit_file->mask == 0 ) bit_file->mask = 0x80; - return ( value ? 1 : 0 ); -} -#endif - -#if SUPPORT_AHUFF64 -/****************************************************************************** -* InputBits. -******************************************************************************/ - -static DWORD InputBits( bit_file, bit_count ) - BIT_FILE *bit_file; - int bit_count; -{ - DWORD mask; - DWORD return_value; - - mask = 1L << ( bit_count - 1 ); - return_value = 0; - while ( mask != 0) { - if ( bit_file->mask == 0x80 ) { - bit_file->rack = V_getc64( bit_file->file ); - if ( bit_file->rack == EOF ) return ((DWORD) EOF); - } - if ( bit_file->rack & bit_file->mask ) return_value |= mask; - mask >>= 1; - bit_file->mask >>= 1; - if ( bit_file->mask == 0 ) bit_file->mask = 0x80; - } - return( return_value ); -} -#endif - -#if SUPPORT_HUFF64 -/****************************************************************************** -* input_counts. -******************************************************************************/ -/* - * When expanding, I have to read in the same set of counts. This is - * quite a bit easier that the process of writing them out, since no - * decision making needs to be done. All I do is read in first, check - * to see if I am all done, and if not, read in last and a string of - * counts. - */ - -static Logical input_counts( input, nodes ) -BIT_FILE *input; -NODE *nodes; -{ - int first; - int last; - int i; - int c; - - for ( i = 0 ; i < 256 ; i++ ) nodes[ i ].count = 0; - if ( ( first = V_getc64( input->file ) ) == EOF ) return FALSE; - if ( ( last = V_getc64( input->file ) ) == EOF ) return FALSE; - for ( ; ; ) { - for ( i = first ; i <= last ; i++ ) { - if ( ( c = V_getc64( input->file ) ) == EOF ) return FALSE; - nodes[ i ].count = (WORD) c; - } - if ( ( first = V_getc64( input->file ) ) == EOF ) return FALSE; - if ( first == 0 ) break; - if ( ( last = V_getc64( input->file ) ) == EOF ) return FALSE; - } - nodes[ END_OF_STREAM ].count = 1; - return TRUE; -} -#endif - -#if SUPPORT_HUFF64 -/****************************************************************************** -* expand_data. -******************************************************************************/ -/* - * Expanding compressed data is a little harder than the compression - * phase. As each new symbol is decoded, the tree is traversed, - * starting at the root node, reading a bit in, and taking either the - * child_0 or child_1 path. Eventually, the tree winds down to a - * leaf node, and the corresponding symbol is output. If the symbol - * is the END_OF_STREAM symbol, it doesn't get written out, and - * instead the whole process terminates. - */ -static CDFstatus expand_data( input, output, nodes, root_node, iError, oError) -BIT_FILE *input; -vFILE *output; -NODE *nodes; -int root_node; -CDFstatus iError; -CDFstatus oError; -{ - int node; - - for ( ; ; ) { - node = root_node; - do { - int bit = InputBit (input); - if (bit == EOF) return iError; - if (bit) - node = nodes[ node ].child_1; - else - node = nodes[ node ].child_0; - } while ( node > END_OF_STREAM ); - if ( node == END_OF_STREAM ) break; - if ( ( V_putc64( node, output ) ) != node ) return oError; - } - return CDF_OK; -} -#endif - -#if SUPPORT_AHUFF64 -/****************************************************************************** -* InitializeTree. -******************************************************************************/ - -/* - * When performing adaptive compression, the Huffman tree starts out - * very nearly empty. The only two symbols present initially are the - * ESCAPE symbol and the END_OF_STREAM symbol. The ESCAPE symbol has to - * be included so we can tell the expansion prog that we are transmitting a - * previously unseen symbol. The END_OF_STREAM symbol is here because - * it is greater than eight bits, and our ESCAPE sequence only allows for - * eight bit symbols following the ESCAPE code. - * - * In addition to setting up the root node and its two children, this - * routine also initializes the leaf array. The ESCAPE and END_OF_STREAM - * leaf elements are the only ones initially defined, the rest of the leaf - * elements are set to -1 to show that they aren't present in the - * Huffman tree yet. - */ - -static void InitializeTree( tree ) -TREE *tree; -{ - int i; - - tree->nodes[ ROOT_NODE ].child = ROOT_NODE + 1; - tree->nodes[ ROOT_NODE ].child_is_leaf = FALSE; - tree->nodes[ ROOT_NODE ].weight = 2; - tree->nodes[ ROOT_NODE ].parent = -1; - - tree->nodes[ ROOT_NODE + 1 ].child = END_OF_STREAM; - tree->nodes[ ROOT_NODE + 1 ].child_is_leaf = TRUE; - tree->nodes[ ROOT_NODE + 1 ].weight = 1; - tree->nodes[ ROOT_NODE + 1 ].parent = ROOT_NODE; - tree->leaf[ END_OF_STREAM ] = ROOT_NODE + 1; - - tree->nodes[ ROOT_NODE + 2 ].child = ESCAPE; - tree->nodes[ ROOT_NODE + 2 ].child_is_leaf = TRUE; - tree->nodes[ ROOT_NODE + 2 ].weight = 1; - tree->nodes[ ROOT_NODE + 2 ].parent = ROOT_NODE; - tree->leaf[ ESCAPE ] = ROOT_NODE + 2; - - tree->next_free_node = ROOT_NODE + 3; - - for ( i = 0 ; i < END_OF_STREAM ; i++ ) tree->leaf[ i ] = -1; -} -#endif - -#if SUPPORT_AHUFF64 -/****************************************************************************** -* EncodeSymbol. -******************************************************************************/ - -/* - * This routine is responsible for taking a symbol, and converting - * it into the sequence of bits dictated by the Huffman tree. The - * only complication is that we are working are way up from the leaf - * to the root, and hence are getting the bits in reverse order. This - * means we have to rack up the bits in an integer and then send them - * out after they are all accumulated. In this version of the program, - * we keep our codes in a long integer, so the maximum count is set - * to an arbitray limit of 0x8000. It could be set as high as 65535 - * if desired. - */ - -static Logical EncodeSymbol( tree, c, output ) -TREE *tree; -INT4 c; -BIT_FILE *output; -{ - DWORD code; - DWORD current_bit; - int code_size; - int current_node; - - code = 0; - current_bit = 1; - code_size = 0; - current_node = tree->leaf[(int)c]; - if ( current_node == -1 ) current_node = tree->leaf[ ESCAPE ]; - while ( current_node != ROOT_NODE ) { - if ( ( current_node & 1 ) == 0 ) code |= current_bit; - current_bit <<= 1; - code_size++; - current_node = tree->nodes[ current_node ].parent; - }; - if (!OutputBits(output,code,code_size)) return FALSE; - if ( tree->leaf[(int)c] == -1 ) { - if (!OutputBits(output,(DWORD)c,8)) return FALSE; - add_new_node( tree, (int) c ); - } - return TRUE; -} -#endif - -#if SUPPORT_AHUFF64 -/****************************************************************************** -* DecodeSymbol. -******************************************************************************/ - -/* - * Decoding symbols is easy. We start at the root node, then go down - * the tree until we reach a leaf. At each node, we decide which - * child to take based on the next input bit. After getting to the - * leaf, we check to see if we read in the ESCAPE code. If we did, - * it means that the next symbol is going to come through in the next - * eight bits, unencoded. If that is the case, we read it in here, - * and add the new symbol to the table. - */ - -static int DecodeSymbol (tree, input) -TREE *tree; -BIT_FILE *input; -{ - int current_node; - int c; - int bit; - - current_node = ROOT_NODE; - while ( !tree->nodes[ current_node ].child_is_leaf ) { - current_node = tree->nodes[ current_node ].child; - bit = InputBit (input); - if (bit == EOF) return EOF; - current_node += bit; - } - c = tree->nodes[ current_node ].child; - if ( c == ESCAPE ) { - c = (int) InputBits( input, 8 ); - if (c == EOF) return EOF; - add_new_node( tree, c ); - } - return( c ); -} -#endif - -#if SUPPORT_AHUFF64 -/****************************************************************************** -* UpdateModel. -******************************************************************************/ - -/* - * UpdateModel is called to increment the count for a given symbol. - * After incrementing the symbol, this code has to work its way up - * through the parent nodes, incrementing each one of them. That is - * the easy part. The hard part is that after incrementing each - * parent node, we have to check to see if it is now out of the proper - * order. If it is, it has to be moved up the tree into its proper - * place. - */ - -static void UpdateModel( tree, c ) -TREE *tree; -int c; -{ - int current_node; - int new_node; - - if ( tree->nodes[ ROOT_NODE].weight == MAX_WEIGHT ) RebuildTree( tree ); - current_node = tree->leaf[ c ]; - while ( current_node != -1 ) { - tree->nodes[ current_node ].weight++; - for ( new_node = current_node ; new_node > ROOT_NODE ; new_node-- ) - if ( tree->nodes[ new_node - 1 ].weight >= - tree->nodes[ current_node ].weight ) - break; - if ( current_node != new_node ) { - swap_nodes( tree, current_node, new_node ); - current_node = new_node; - } - current_node = tree->nodes[ current_node ].parent; - } - - return; -} -#endif - -#if SUPPORT_AHUFF64 -/****************************************************************************** -* RebuildTree. -******************************************************************************/ - -/* - * Rebuilding the tree takes place when the counts have gone too - * high. From a simple point of view, rebuilding the tree just means that - * we divide every count by two. Unfortunately, due to truncation effects, - * this means that the tree's shape might change. Some nodes might move - * up due to cumulative increases, while others may move down. - */ - -static void RebuildTree( tree ) -TREE *tree; -{ - int i; - int j; - int k; - WORD weight; - -/* - * To start rebuilding the table, I collect all the leaves of the Huffman - * tree and put them in the end of the tree. While I am doing that, I - * scale the counts down by a factor of 2. - */ - j = tree->next_free_node - 1; - for ( i = j ; i >= ROOT_NODE ; i-- ) { - if ( tree->nodes[ i ].child_is_leaf ) { - tree->nodes[ j ] = tree->nodes[ i ]; - tree->nodes[ j ].weight = (tree->nodes[j].weight + 1) / ((WORD) 2); - j--; - } - } - -/* - * At this point, j points to the first free node. I now have all the - * leaves defined, and need to start building the higher nodes on the - * tree. I will start adding the new internal nodes at j. Every time - * I add a new internal node to the top of the tree, I have to check to - * see where it really belongs in the tree. It might stay at the top, - * but there is a good chance I might have to move it back down. If it - * does have to go down, I use the memmove() function to scoot everyone - * bigger up by one node. Note that memmove() may have to be change - * to memcpy() on some UNIX systems. The parameters are unchanged, as - * memmove and memcpy have the same set of parameters. - */ - for ( i = tree->next_free_node - 2 ; j >= ROOT_NODE ; i -= 2, j-- ) { - k = i + 1; - tree->nodes[ j ].weight = tree->nodes[ i ].weight + - tree->nodes[ k ].weight; - weight = tree->nodes[ j ].weight; - tree->nodes[ j ].child_is_leaf = FALSE; - for ( k = j + 1 ; weight < tree->nodes[ k ].weight ; k++ ) - ; - k--; - memmove( &tree->nodes[ j ], &tree->nodes[ j + 1 ], - ( k - j ) * sizeof( struct node ) ); - tree->nodes[ k ].weight = weight; - tree->nodes[ k ].child = i; - tree->nodes[ k ].child_is_leaf = FALSE; - } -/* - * The final step in tree reconstruction is to go through and set up - * all of the leaf and parent members. This can be safely done now - * that every node is in its final position in the tree. - */ - for ( i = tree->next_free_node - 1 ; i >= ROOT_NODE ; i-- ) { - if ( tree->nodes[ i ].child_is_leaf ) { - k = tree->nodes[ i ].child; - tree->leaf[ k ] = i; - } else { - k = tree->nodes[ i ].child; - tree->nodes[ k ].parent = tree->nodes[ k + 1 ].parent = i; - } - } - - return; -} -#endif - -#if SUPPORT_AHUFF64 -/****************************************************************************** -* swap_nodes. -******************************************************************************/ - -/* - * Swapping nodes takes place when a node has grown too big for its - * spot in the tree. When swapping nodes i and j, we rearrange the - * tree by exchanging the children under i with the children under j. - */ - -static void swap_nodes( tree, i, j ) -TREE *tree; -int i; -int j; -{ - struct node temp; - - if ( tree->nodes[ i ].child_is_leaf ) - tree->leaf[ tree->nodes[ i ].child ] = j; - else { - tree->nodes[ tree->nodes[ i ].child ].parent = j; - tree->nodes[ tree->nodes[ i ].child + 1 ].parent = j; - } - if ( tree->nodes[ j ].child_is_leaf ) - tree->leaf[ tree->nodes[ j ].child ] = i; - else { - tree->nodes[ tree->nodes[ j ].child ].parent = i; - tree->nodes[ tree->nodes[ j ].child + 1 ].parent = i; - } - temp = tree->nodes[ i ]; - tree->nodes[ i ] = tree->nodes[ j ]; - tree->nodes[ i ].parent = temp.parent; - temp.parent = tree->nodes[ j ].parent; - tree->nodes[ j ] = temp; - - return; -} -#endif - -#if SUPPORT_AHUFF64 -/****************************************************************************** -* add_new_node. -******************************************************************************/ - -/* - * Adding a new node to the tree is pretty simple. It is just a matter - * of splitting the lightest-weight node in the tree, which is the highest - * valued node. We split it off into two new nodes, one of which is the - * one being added to the tree. We assign the new node a weight of 0, - * so the tree doesn't have to be adjusted. It will be updated later when - * the normal update process occurs. Note that this code assumes that - * the lightest node has a leaf as a child. If this is not the case, - * the tree would be broken. - */ - -static void add_new_node( tree, c ) -TREE *tree; -int c; -{ - int lightest_node; - int new_node; - int zero_weight_node; - - lightest_node = tree->next_free_node - 1; - new_node = tree->next_free_node; - zero_weight_node = tree->next_free_node + 1; - tree->next_free_node += 2; - - tree->nodes[ new_node ] = tree->nodes[ lightest_node ]; - tree->nodes[ new_node ].parent = lightest_node; - tree->leaf[ tree->nodes[ new_node ].child ] = new_node; - - tree->nodes[ lightest_node ].child = new_node; - tree->nodes[ lightest_node ].child_is_leaf = FALSE; - - tree->nodes[ zero_weight_node ].child = c; - tree->nodes[ zero_weight_node ].child_is_leaf = TRUE; - tree->nodes[ zero_weight_node ].weight = 0; - tree->nodes[ zero_weight_node ].parent = lightest_node; - tree->leaf[ c ] = zero_weight_node; - return; -} -#endif diff --git a/cdf36_3-dist/src/lib/cdfhyper.c b/cdf36_3-dist/src/lib/cdfhyper.c deleted file mode 100644 index 852512e..0000000 --- a/cdf36_3-dist/src/lib/cdfhyper.c +++ /dev/null @@ -1,779 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF library hyper functions. -* -* Version 1.4, 26-Jun-96, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version. These functions were taken -* out of `cdflib.c'. -* V1.1 16-Sep-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 22-Nov-93, J Love CDF 2.4. New hyper algorithms. -* V1.3 7-Dec-94, J Love CDF V2.5. -* V1.3a 6-Jan-95, J Love Encode/decode changes. More cache-residency. -* V1.3b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.4 26-Jun-96, J Love CDF V2.6. -* V1.5 26-May-98, M Liu Add a parameter for HyperReadDim and -* HyperWriteDim function calls. For -* reading/writing data values of a non-full -* physical record, a temp. buffer is used to cut -* down the physical I/Os. -* -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* HyperRead. -******************************************************************************/ - -STATICforIDL CDFstatus HyperRead (CDF, Var, rd, buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct rdSTRUCT *rd; -void *buffer; -{ - Int32 nHypRecValues, nHypRecBytes, nHypDimValues[CDF_MAX_DIMS]; - Logical fullPhyRec, fullPhyDim[CDF_MAX_DIMS]; - Int32 firstHypRec, lastHypRec, firstPhyRec; - Int32 recNum, nValues, nRecords, phyRecN, i; Byte1 *tBuffer, *phyBuffer; - CDFstatus pStatus = CDF_OK; - int dimN, dimNt; - int firstDim; /* Based on majority, the "highest" dimension - (changes the slowest in memory/on disk). */ - int doneDim; /* When cycling through the dimensions, the - dimension at which to stop (the dimension - beyond the last). */ - int dimIncr; /* How to cycle through the dimensions. Incr- - ementing (+1) for row-major, decrementing - (-1) for column-major. */ - /**************************************************************************** - * Determine dimension ordering. - ****************************************************************************/ - if (Var->numDims > 0) { - firstDim = (int) (CDF->rowMajor ? 0 : Var->numDims - 1); - doneDim = (int) (CDF->rowMajor ? Var->numDims : -1); - dimIncr = (CDF->rowMajor ? 1 : -1); - } - /**************************************************************************** - * Determine if full physical dimensions can be read. In order for this to - * be so for a particular dimension... - * 1. If the dimension variance is TRUE, then the entire dimension must be - * read (the count equal to the size). If the dimension variance is - * FALSE, the count must be equal to one (only reading the single - * physical value). - * 2. For each `lower' dimension having a TRUE variance, the entire - * dimension must be read (the count equal to the size). - * 3. For each `lower' dimension having a FALSE variance, the count must - * be equal to one (only reading the single physical dimension). - * Also determine if full physical records can be read. If there are one or - * more dimensions, this depends on whether or not the first dimension can be - * read with a single physical read. If there are zero dimensions, then this - * is always true. - ****************************************************************************/ - if (Var->numDims > 0) { - for (dimN = firstDim; dimN != doneDim; dimN += dimIncr) { - fullPhyDim[dimN] = TRUE; - for (dimNt = dimN; dimNt != doneDim; dimNt += dimIncr) - if ((Var->dimVarys[dimNt] && - rd->dimCounts[dimNt] != Var->dimSizes[dimNt]) || - (!Var->dimVarys[dimNt] && rd->dimCounts[dimNt] > 1)) { - fullPhyDim[dimN] = FALSE; - break; - } - } - fullPhyRec = fullPhyDim[firstDim]; - } - else - fullPhyRec = TRUE; - /**************************************************************************** - * Determine if only one read is needed. In order for this to be so... - * 1. Full physical records must be being read, and - * 2a. If the record variance is TRUE, then the record interval must be one - * (or a record count of one) so that there is no skipping of records - * 2b. If the record variance is FALSE. - ****************************************************************************/ - firstHypRec = rd->recNumber; - lastHypRec = firstHypRec + (rd->recInterval * (rd->recCount - 1)); - firstPhyRec = (Var->recVary ? firstHypRec : 0); - if (fullPhyRec && - ((Var->recVary && (rd->recInterval == 1 || rd->recCount == 1)) - || - (!Var->recVary))) { - nRecords = lastHypRec - firstHypRec + 1; - nValues = nRecords * Var->NphyRecValues; - if (!sX(ReadVarValues(CDF,Var,firstPhyRec, - INT32_ZERO,nValues,buffer),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * A single read was not possible - read one record at a time. - ****************************************************************************/ - if (Var->numDims > 0) { - for (dimN = firstDim; dimN != doneDim; dimN += dimIncr) { - nHypDimValues[dimN] = 1; - for (dimNt = dimN + dimIncr; dimNt != doneDim; dimNt += dimIncr) - nHypDimValues[dimN] *= rd->dimCounts[dimNt]; - } - nHypRecValues = nHypDimValues[firstDim] * rd->dimCounts[firstDim]; - } - else - nHypRecValues = 1; - nHypRecBytes = nHypRecValues * Var->NvalueBytes; - for (i = 0, recNum = rd->recNumber, tBuffer = buffer; i < rd->recCount; - i++, recNum += rd->recInterval, tBuffer += (size_t) nHypRecBytes) { - phyRecN = BOO(Var->recVary,recNum,0); - if (fullPhyRec) { - /******************************************************************* - * The full physical record is being read, use one physical read. - *******************************************************************/ - if (!sX(ReadVarValues(CDF,Var,phyRecN,INT32_ZERO, - Var->NphyRecValues, - tBuffer),&pStatus)) return pStatus; - } - else { - /******************************************************************* - * Less than the full physical record is to be read. Allocate a - * physical record buffer if possible and read in the whole record - * and extract values from the buffer. Otherwise, get one value at a - * time from the file - *******************************************************************/ - phyBuffer = (Byte1 *) cdf_AllocateMemory((size_t) Var->NphyRecBytes,NULL); - if (phyBuffer != NULL) { - if (!sX(ReadVarValues(CDF,Var,phyRecN,INT32_ZERO,Var->NphyRecValues, - phyBuffer),&pStatus)) { - cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - } - if (!sX(HyperReadDim(Var->numDims,Var->dimSizes, - Var->dimVarys,rd->dimIndices, - rd->dimCounts,rd->dimIntervals, - nHypDimValues,Var->nPhyDimValues, - fullPhyDim,firstDim,dimIncr, - phyRecN,INT32_ZERO,tBuffer,phyBuffer, - CDF,Var),&pStatus)) { - if (phyBuffer != NULL) cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - if (phyBuffer != NULL) cdf_FreeMemory(phyBuffer,NULL); - } - } - return pStatus; -} - -/****************************************************************************** -* HyperReadDim. DANGER, DANGER, I'm recursive. -* NOTE: This routine could be called for a record which is virtual. -******************************************************************************/ - -STATICforIDL CDFstatus HyperReadDim (numDims, dimSizes, dimVarys, indices, - counts, intervals, nHypDimValues, - nPhyDimValues, fullPhyDim, firstDim, - dimIncr, recNum, offset, buffer, phyBuffer, - CDF, Var) -Int32 numDims; -Int32 *dimSizes; -Int32 *dimVarys; -Int32 *indices; -Int32 *counts; -Int32 *intervals; -Int32 *nHypDimValues; -Int32 *nPhyDimValues; -Logical *fullPhyDim; -int firstDim; -int dimIncr; -Int32 recNum; -Int32 offset; /* Byte offset within record. */ -void *buffer; -void *phyBuffer; -struct CDFstruct *CDF; -struct VarStruct *Var; -{ - Int32 tOffset; Int32 nValues, i; Byte1 *tBuffer; CDFstatus pStatus = CDF_OK; - /**************************************************************************** - * What to do depends on the number of dimensions. Note that this function - * should never be called with zero dimensions. - ****************************************************************************/ - switch (numDims) { - case 1: { - /************************************************************************ - * One dimension - read the values along the dimension. - ************************************************************************/ - if (dimVarys[0]) { - /********************************************************************** - * Dimension variance of TRUE, no virtual values to deal with - read - * physical values. - **********************************************************************/ - if (intervals[0] == 1) { - /******************************************************************** - * A contiguous strip of values. - ********************************************************************/ - tOffset = offset + (indices[0] * Var->NvalueBytes); - if (phyBuffer == NULL) { - if (!sX(ReadVarValues(CDF,Var,recNum, - tOffset,counts[0], - buffer),&pStatus)) return pStatus; - } else { - memmove (buffer, (size_t) tOffset + (Byte1 *) phyBuffer, - (size_t) (Var->NvalueBytes * counts[0])); - } - } - else { - /******************************************************************** - * Not contiguous, read one value at a time skipping over unwanted - * values. - ********************************************************************/ - tOffset = offset + (indices[0] * Var->NvalueBytes); - tBuffer = buffer; - for (i = 0; i < counts[0]; i++) { - if (phyBuffer == NULL) { - if (!sX(ReadVarValues(CDF,Var,recNum, - tOffset,INT32_ONE, - tBuffer),&pStatus)) return pStatus; - } else { - memmove (tBuffer, (size_t) tOffset+(Byte1 *) phyBuffer, - (size_t) Var->NvalueBytes); - } - tOffset += (intervals[0] * Var->NvalueBytes); - tBuffer += (size_t) Var->NvalueBytes; - } - } - } - else { - /********************************************************************** - * Dimension variance of FALSE, only one physical value exists. If the - * count is greater than one, virtual values will have to be generated. - **********************************************************************/ - if (phyBuffer == NULL) { - if (!sX(ReadVarValues(CDF,Var,recNum,offset, - INT32_ONE,buffer),&pStatus)) return pStatus; - } else { - memmove(buffer, (size_t) offset + (Byte1 *) phyBuffer, - (size_t) Var->NvalueBytes); - } - if (counts[0] > 1) { - for (i = 1, tBuffer = (Byte1 *) buffer + (size_t) Var->NvalueBytes; - i < counts[0]; i++, tBuffer += (size_t) Var->NvalueBytes) { - memmove (tBuffer, buffer, (size_t) Var->NvalueBytes); - } - } - } - break; - } - default: { - /************************************************************************ - * Two or more dimensions. - ************************************************************************/ - Int32 nPhyDimBytes = nPhyDimValues[firstDim] * Var->NvalueBytes; - Int32 nHypDimBytes = nHypDimValues[firstDim] * Var->NvalueBytes; - int nextDim = firstDim + dimIncr; - if (dimVarys[firstDim]) { - /********************************************************************** - * The first dimension's variance is TRUE. If the interval is one and - * only a single read is necessary for the "lower" dimension, use a - * single read. Otherwise, cycle through that dimension physically - * reading each subarray below it (skipping subarrays if necessary). - **********************************************************************/ - if (intervals[firstDim] == 1 && fullPhyDim[nextDim]) { - tOffset = offset + (indices[firstDim] * nPhyDimBytes); - nValues = counts[firstDim] * nPhyDimValues[firstDim]; - if (phyBuffer == NULL) { - if (!sX(ReadVarValues(CDF,Var,recNum, - tOffset,nValues, - buffer),&pStatus)) return pStatus; - } else { - memmove(buffer, (size_t) tOffset + (Byte1 *) phyBuffer, - (size_t) (Var->NvalueBytes * nValues)); - } - } - else { - tOffset = offset + (indices[firstDim] * nPhyDimBytes); - tBuffer = buffer; - for (i = 0; i < counts[firstDim]; i++) { - if (fullPhyDim[nextDim]) { - if (phyBuffer == NULL) { - if (!sX(ReadVarValues(CDF,Var,recNum, - tOffset,nPhyDimValues[firstDim], - tBuffer),&pStatus)) return pStatus; - } else { - memmove(tBuffer, (size_t) tOffset + (Byte1 *) phyBuffer, - (size_t) (Var->NvalueBytes * nPhyDimValues[firstDim])); - } - } - else { - int numDimsT = (int) (numDims - 1); - int firstDimT = (CDF->rowMajor ? 0 : numDimsT - 1); - int passDimT = (CDF->rowMajor ? 1 : 0); - if (!sX(HyperReadDim(numDimsT,&dimSizes[passDimT], - &dimVarys[passDimT], - &indices[passDimT], - &counts[passDimT], - &intervals[passDimT], - &nHypDimValues[passDimT], - &nPhyDimValues[passDimT], - &fullPhyDim[passDimT],firstDimT, - dimIncr,recNum,tOffset,tBuffer,phyBuffer, - CDF,Var),&pStatus)) return pStatus; - } - tOffset += (intervals[firstDim] * nPhyDimBytes); - tBuffer += (size_t) nHypDimBytes; - } - } - } - else { - /********************************************************************** - * The first dimension's variance is FALSE, physically read the only - * existing subarray and generate virtual subarrays if necessary. - **********************************************************************/ - if (fullPhyDim[nextDim]) { - if (phyBuffer == NULL) { - if (!sX(ReadVarValues(CDF,Var,recNum,offset, - nPhyDimValues[firstDim], - buffer),&pStatus)) return pStatus; - } else { - - memmove(buffer, (size_t) offset + (Byte1 *) phyBuffer, - (size_t) (Var->NvalueBytes * nPhyDimValues[firstDim])); - } - } - else { - int numDimsT = (int) (numDims - 1); - int firstDimT = (CDF->rowMajor ? 0 : numDimsT - 1); - int passDimT = (CDF->rowMajor ? 1 : 0); - if (!sX(HyperReadDim(numDimsT,&dimSizes[passDimT], - &dimVarys[passDimT],&indices[passDimT], - &counts[passDimT],&intervals[passDimT], - &nHypDimValues[passDimT], - &nPhyDimValues[passDimT], - &fullPhyDim[passDimT],firstDimT, - dimIncr,recNum,offset,buffer,phyBuffer, - CDF,Var),&pStatus)) return pStatus; - } - if (counts[firstDim] > 1) { - for (i = 1, tBuffer = (Byte1 *) buffer + (size_t) nHypDimBytes; - i < counts[firstDim]; i++, tBuffer += (size_t) nHypDimBytes) { - memmove (tBuffer, buffer, (size_t) nHypDimBytes); - } - } - } - break; - } - } - return pStatus; -} - -/****************************************************************************** -* HyperWrite. -******************************************************************************/ - -STATICforIDL CDFstatus HyperWrite (CDF, Var, rd, buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct rdSTRUCT *rd; -void *buffer; -{ - Int32 nHypRecValues, nHypRecBytes, nHypDimValues[CDF_MAX_DIMS]; - Logical fullPhyRec, fullPhyDim[CDF_MAX_DIMS]; - Int32 firstPhyRec, phyRecN, nValues; Byte1 *tBuffer; int dimN; Int32 i; - CDFstatus pStatus = CDF_OK; Byte1 *phyBuffer; - int firstDim; /* Based on majority, the "highest" dimension - (changes the slowest in memory/on disk). */ - int doneDim; /* When cycling through the dimensions, the - dimension at which to stop (the dimension - beyond the last). */ - int dimIncr; /* How to cycle through the dimensions. Incr- - ementing (+1) for row-major, decrementing - (-1) for column-major. */ - /**************************************************************************** - * Determine dimension ordering. - ****************************************************************************/ - if (Var->numDims > 0) { - firstDim = (int) (CDF->rowMajor ? 0 : Var->numDims - 1); - doneDim = (int) (CDF->rowMajor ? Var->numDims : -1); - dimIncr = (CDF->rowMajor ? 1 : -1); - } - /**************************************************************************** - * Determine if full physical dimensions can be written. In order for this to - * be so for a particular dimension... - * 1. If the dimension variance is TRUE, then the entire dimension must be - * written (the count equal to the size). If the dimension variance is - * FALSE, the count must be equal to one (only writing the single - * physical value). - * 2. For each `lower' dimension having a TRUE variance, the entire - * dimension must be written (the count equal to the size). - * 3. For each `lower' dimension having a FALSE variance, the count must - * be equal to one (only writing the single physical dimension). - * Also determine if full physical records can be written. If there are one - * or more dimensions, this depends on whether or not the first dimension can - * be written with a single physical write. If there are zero dimensions, - * then this is always true. - ****************************************************************************/ - if (Var->numDims > 0) { - for (dimN = firstDim; dimN != doneDim; dimN += dimIncr) { - int dimNt; - fullPhyDim[dimN] = TRUE; - for (dimNt = dimN; dimNt != doneDim; dimNt += dimIncr) - if ((Var->dimVarys[dimNt] && - rd->dimCounts[dimNt] != Var->dimSizes[dimNt]) || - (!Var->dimVarys[dimNt] && rd->dimCounts[dimNt] > 1)) { - fullPhyDim[dimN] = FALSE; - break; - } - } - fullPhyRec = fullPhyDim[firstDim]; - } - else - fullPhyRec = TRUE; - /**************************************************************************** - * Determine if only one write is needed. In order for this to be so... - * 1. Full physical records must be being written. - * 2. A record variance of FALSE, or if the record variance is TRUE, then - * the record interval must be one (or a record count of one) so that - * there is no skipping of records. - ****************************************************************************/ - phyRecN = 0; - if (fullPhyRec && - ((Var->recVary && (rd->recInterval == 1 || rd->recCount == 1)) || - (!Var->recVary))) { - if (Var->recVary) { - phyRecN = rd->recNumber; - tBuffer = buffer; - nValues = rd->recCount * Var->NphyRecValues; - } - else { - tBuffer = (Byte1 *) buffer + - (size_t) (Var->NphyRecBytes * (rd->recCount-1)); - nValues = Var->NphyRecValues; - } - if (!sX(WriteVarValues(CDF,Var,phyRecN,INT32_ZERO, - nValues,tBuffer),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * Only one write not possible - will have to write one record at a time. - * First calculate size of hyper records. - ****************************************************************************/ - if (Var->numDims > 0) { - for (dimN = firstDim; dimN != doneDim; dimN += dimIncr) { - int dimNt; - nHypDimValues[dimN] = 1; - for (dimNt = dimN + dimIncr; dimNt != doneDim; dimNt += dimIncr) - nHypDimValues[dimN] *= rd->dimCounts[dimNt]; - } - nHypRecValues = nHypDimValues[firstDim] * rd->dimCounts[firstDim]; - } - else - nHypRecValues = 1; - nHypRecBytes = nHypRecValues * Var->NvalueBytes; - firstPhyRec = BOO(Var->recVary,rd->recNumber,0); - /**************************************************************************** - * Write each record. - ****************************************************************************/ - if (Var->recVary) { - /************************************************************************** - * A TRUE record variance - write each physical record. - **************************************************************************/ - for (i = 0, phyRecN = firstPhyRec, tBuffer = buffer; - i < rd->recCount; - i++, phyRecN += rd->recInterval, tBuffer += (size_t) nHypRecBytes) { - if (fullPhyRec) { - /********************************************************************* - * The full physical record is being written, use one physical write. - *********************************************************************/ - if (!sX(WriteVarValues(CDF,Var,phyRecN,INT32_ZERO, - Var->NphyRecValues, - tBuffer),&pStatus)) return pStatus; - } - else { - /********************************************************************* - * Less than the full physical record is to be written. - * physical record buffer if possible and fill in the whole record - * with values from the buffer. Otherwise, write one value at a - * time to the file - *********************************************************************/ - phyBuffer = (Byte1 *) cdf_AllocateMemory((size_t) Var->NphyRecBytes,NULL); - if (phyBuffer != NULL) { - if (!sX(ReadVarValues(CDF,Var,phyRecN,INT32_ZERO, - Var->NphyRecValues, - phyBuffer),&pStatus)) { - if (pStatus != VIRTUAL_RECORD_DATA) { - cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - } - } - if (pStatus == VIRTUAL_RECORD_DATA) /* Don't want it to stop. */ - pStatus = CDF_OK; - if (!sX(HyperWriteDim(Var->numDims,Var->dimSizes, - Var->dimVarys,rd->dimIndices, - rd->dimCounts,rd->dimIntervals, - nHypDimValues,Var->nPhyDimValues, - fullPhyDim,firstDim, - dimIncr,phyRecN,INT32_ZERO,tBuffer,phyBuffer, - CDF,Var),&pStatus)) { - if (phyBuffer != NULL) { - cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - } - if (phyBuffer != NULL) { - if (!sX(WriteVarValues(CDF,Var,phyRecN,INT32_ZERO, - Var->NphyRecValues,phyBuffer),&pStatus)) { - cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - cdf_FreeMemory(phyBuffer,NULL); - } - } - } - } - else { - /************************************************************************** - * A FALSE record variance. Only one physical record to actually be - * written. No need to check if a full physical record can be written - * since that case would have been handled above (because of the FALSE - * record variance). If the record count is greater than one, the LAST - * record in the buffer will be written (as if the records before it had - * been written but then overwritten by the last one). - **************************************************************************/ - tBuffer = (Byte1 *) buffer + (size_t) (nHypRecBytes * (rd->recCount - 1)); - phyBuffer = (Byte1 *) cdf_AllocateMemory((size_t) Var->NphyRecBytes,NULL); - if (phyBuffer != NULL) { - if (!sX(ReadVarValues(CDF,Var,phyRecN,INT32_ZERO, - Var->NphyRecValues, - phyBuffer),&pStatus)) { - if (pStatus != VIRTUAL_RECORD_DATA) { - cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - } - } - if (pStatus == VIRTUAL_RECORD_DATA) /* Don't want it to stop */ - pStatus = CDF_OK; - if (!sX(HyperWriteDim(Var->numDims,Var->dimSizes,Var->dimVarys, - rd->dimIndices,rd->dimCounts, - rd->dimIntervals,nHypDimValues, - Var->nPhyDimValues,fullPhyDim, - firstDim,dimIncr, - INT32_ZERO,INT32_ZERO,tBuffer,phyBuffer, - CDF,Var),&pStatus)) { - if (phyBuffer != NULL) { - cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - } - if (phyBuffer != NULL) { - if (!sX(WriteVarValues(CDF,Var,phyRecN,INT32_ZERO, - Var->NphyRecValues,phyBuffer),&pStatus)) { - cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - cdf_FreeMemory(phyBuffer,NULL); - } - } - return pStatus; -} - -/****************************************************************************** -* HyperWriteDim. DANGER, DANGER, I'm recursive. -******************************************************************************/ - -STATICforIDL CDFstatus HyperWriteDim (numDims, dimSizes, dimVarys, indices, - counts, intervals, nHypDimValues, - nPhyDimValues, fullPhyDim, firstDim, - dimIncr, recNum, offset, buffer, phyBuffer, - CDF, Var) -Int32 numDims; -Int32 *dimSizes; -Int32 *dimVarys; -Int32 *indices; -Int32 *counts; -Int32 *intervals; -Int32 *nHypDimValues; -Int32 *nPhyDimValues; -Logical *fullPhyDim; -int firstDim; -int dimIncr; -Int32 recNum; /* Record number for this write. */ -Int32 offset; /* Byte offset within record at which to begin. */ -void *buffer; -void *phyBuffer; -struct CDFstruct *CDF; -struct VarStruct *Var; -{ - Int32 tOffset; Int32 i, nValues; Byte1 *tBuffer; - CDFstatus pStatus = CDF_OK; - /**************************************************************************** - * What to do depends on the number of dimensions. Note that this function - * should never be called with zero dimensions. - ****************************************************************************/ - switch (numDims) { - case 1: { - /************************************************************************ - * One dimension - write the values along the dimension. - ************************************************************************/ - if (dimVarys[0]) { - /********************************************************************** - * Dimension variance of TRUE, there are no virtual values to deal - * with (skip) - read physical values. - **********************************************************************/ - if (intervals[0] == 1) { - /******************************************************************** - * A contiguous strip of values. - ********************************************************************/ - tOffset = offset + (indices[0] * Var->NvalueBytes); - if (phyBuffer == NULL) { - if (!sX(WriteVarValues(CDF,Var,recNum, - tOffset,counts[0], - buffer),&pStatus)) return pStatus; - } else { - memmove ((size_t) tOffset + (Byte1 *) phyBuffer, buffer, - (size_t) (Var->NvalueBytes * counts[0])); - } - } - else { - /******************************************************************** - * Not contiguous, write one value at a time skipping over physical - * values not being written. - ********************************************************************/ - tOffset = offset + (indices[0] * Var->NvalueBytes); - tBuffer = buffer; - for (i = 0; i < counts[0]; i++) { - if (phyBuffer == NULL) { - if (!sX(WriteVarValues(CDF,Var,recNum, - tOffset,INT32_ONE, - tBuffer),&pStatus)) return pStatus; - } else { - memmove ((size_t) tOffset+(Byte1 *) phyBuffer, tBuffer, - (size_t) Var->NvalueBytes); - } - tOffset += (intervals[0] * Var->NvalueBytes); - tBuffer += (size_t) Var->NvalueBytes; - } - } - } - else { - /********************************************************************** - * Dimension variance of FALSE, only one physical value to be written. - * If the count is greater than one, skip to the last value in the - * buffer (this is an unlikely situation). - **********************************************************************/ - tBuffer = (Byte1 *) buffer + - (size_t) (Var->NvalueBytes * (counts[0] - 1)); - if (phyBuffer == NULL) { - if (!sX(WriteVarValues(CDF,Var,recNum,offset, - INT32_ONE,tBuffer),&pStatus)) return pStatus; - } else { - memmove((size_t) offset + (Byte1 *) phyBuffer, tBuffer, - (size_t) Var->NvalueBytes); - } - } - break; - } - default: { - /************************************************************************ - * Two or more dimensions. - ************************************************************************/ - Int32 nPhyDimBytes = nPhyDimValues[firstDim] * Var->NvalueBytes; - Int32 nHypDimBytes = nHypDimValues[firstDim] * Var->NvalueBytes; - int nextDim = firstDim + dimIncr; - if (dimVarys[firstDim]) { - /********************************************************************** - * The first dimension's variance is TRUE. If the interval is one and - * only a single write is necessary for the "lower" dimension, use a - * single write. Otherwise, cycle through that dimension physically - * writing each subarray below it (skipping subarrays if necessary). - **********************************************************************/ - if (intervals[firstDim] == 1 && fullPhyDim[nextDim]) { - tOffset = offset + (indices[firstDim] * nPhyDimBytes); - nValues = counts[firstDim] * nPhyDimValues[firstDim]; - if (phyBuffer == NULL) { - if (!sX(WriteVarValues(CDF,Var,recNum, - tOffset,nValues, - buffer),&pStatus)) return pStatus; - } else { - memmove((size_t) tOffset + (Byte1 *) phyBuffer, buffer, - (size_t) (Var->NvalueBytes * nValues)); - } - } - else { - tOffset = offset + (indices[firstDim] * nPhyDimBytes); - tBuffer = buffer; - for (i = 0; i < counts[firstDim]; i++) { - if (fullPhyDim[nextDim]) { - if (phyBuffer == NULL) { - if (!sX(WriteVarValues(CDF,Var,recNum,tOffset, - nPhyDimValues[firstDim], - tBuffer),&pStatus)) return pStatus; - } else { - memmove((size_t) tOffset + (Byte1 *) phyBuffer, tBuffer, - (size_t) (Var->NvalueBytes * nPhyDimValues[firstDim])); - } - } - else { - int numDimsT = (int) (numDims - 1); - int firstDimT = (CDF->rowMajor ? 0 : numDimsT - 1); - int passDimT = (CDF->rowMajor ? 1 : 0); - if (!sX(HyperWriteDim(numDimsT,&dimSizes[passDimT], - &dimVarys[passDimT], - &indices[passDimT], - &counts[passDimT], - &intervals[passDimT], - &nHypDimValues[passDimT], - &nPhyDimValues[passDimT], - &fullPhyDim[passDimT], - firstDimT,dimIncr,recNum, - tOffset,tBuffer,phyBuffer, - CDF,Var),&pStatus)) return pStatus; - } - tOffset += (intervals[firstDim] * nPhyDimBytes); - tBuffer += (size_t) nHypDimBytes; - } - } - } - else { - /********************************************************************** - * The first dimension's variance is FALSE, skip to the last subarray - * and write the single physical subarray. - **********************************************************************/ - tBuffer = (Byte1 *) buffer + - (size_t) (nHypDimBytes * (counts[firstDim] - 1)); - if (fullPhyDim[nextDim]) { - if (phyBuffer == NULL) { - if (!sX(WriteVarValues(CDF,Var,recNum,offset, - nPhyDimValues[firstDim], - tBuffer),&pStatus)) return pStatus; - } else { - memmove((size_t) offset + (Byte1 *) phyBuffer, tBuffer, - (size_t) (Var->NvalueBytes * nPhyDimValues[firstDim])); - } - } - else { - int numDimsT = (int) (numDims - 1); - int firstDimT = (CDF->rowMajor ? 0 : numDimsT - 1); - int passDimT = (CDF->rowMajor ? 1 : 0); - if (!sX(HyperWriteDim(numDimsT,&dimSizes[passDimT], - &dimVarys[passDimT], - &indices[passDimT], - &counts[passDimT], - &intervals[passDimT], - &nHypDimValues[passDimT], - &nPhyDimValues[passDimT], - &fullPhyDim[passDimT],firstDimT, - dimIncr,recNum,offset,tBuffer,phyBuffer, - CDF,Var),&pStatus)) return pStatus; - } - } - break; - } - } - - return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfhyper64.c b/cdf36_3-dist/src/lib/cdfhyper64.c deleted file mode 100644 index ce9e655..0000000 --- a/cdf36_3-dist/src/lib/cdfhyper64.c +++ /dev/null @@ -1,782 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF library hyper functions. -* -* Version 1.4, 26-Jun-96, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version. These functions were taken -* out of `cdflib.c'. -* V1.1 16-Sep-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 22-Nov-93, J Love CDF 2.4. New hyper algorithms. -* V1.3 7-Dec-94, J Love CDF V2.5. -* V1.3a 6-Jan-95, J Love Encode/decode changes. More cache-residency. -* V1.3b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.4 26-Jun-96, J Love CDF V2.6. -* V1.5 26-May-98, M Liu Add a parameter for HyperReadDim and -* HyperWriteDim function calls. For -* reading/writing data values of a non-full -* physical record, a temp. buffer is used to cut -* down the physical I/Os. -* V2.0 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* HyperRead64. -******************************************************************************/ - -STATICforIDL CDFstatus HyperRead64 (CDF, Var, rd, buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct rdSTRUCT *rd; -void *buffer; -{ - Int32 nHypRecValues, nHypRecBytes, nHypDimValues[CDF_MAX_DIMS]; - Logical fullPhyRec, fullPhyDim[CDF_MAX_DIMS]; - Int32 firstHypRec, lastHypRec, firstPhyRec; - Int32 recNum, nRecords, phyRecN, i; Byte1 *tBuffer, *phyBuffer; - CDFstatus pStatus = CDF_OK; OFF_T nValues; - int dimN, dimNt; - int firstDim; /* Based on majority, the "highest" dimension - (changes the slowest in memory/on disk). */ - int doneDim; /* When cycling through the dimensions, the - dimension at which to stop (the dimension - beyond the last). */ - int dimIncr; /* How to cycle through the dimensions. Incr- - ementing (+1) for row-major, decrementing - (-1) for column-major. */ - /**************************************************************************** - * Determine dimension ordering. - ****************************************************************************/ - if (Var->numDims > 0) { - firstDim = (int) (CDF->rowMajor ? 0 : Var->numDims - 1); - doneDim = (int) (CDF->rowMajor ? Var->numDims : -1); - dimIncr = (CDF->rowMajor ? 1 : -1); - } - /**************************************************************************** - * Determine if full physical dimensions can be read. In order for this to - * be so for a particular dimension... - * 1. If the dimension variance is TRUE, then the entire dimension must be - * read (the count equal to the size). If the dimension variance is - * FALSE, the count must be equal to one (only reading the single - * physical value). - * 2. For each `lower' dimension having a TRUE variance, the entire - * dimension must be read (the count equal to the size). - * 3. For each `lower' dimension having a FALSE variance, the count must - * be equal to one (only reading the single physical dimension). - * Also determine if full physical records can be read. If there are one or - * more dimensions, this depends on whether or not the first dimension can be - * read with a single physical read. If there are zero dimensions, then this - * is always true. - ****************************************************************************/ - if (Var->numDims > 0) { - for (dimN = firstDim; dimN != doneDim; dimN += dimIncr) { - fullPhyDim[dimN] = TRUE; - for (dimNt = dimN; dimNt != doneDim; dimNt += dimIncr) - if ((Var->dimVarys[dimNt] && - rd->dimCounts[dimNt] != Var->dimSizes[dimNt]) || - (!Var->dimVarys[dimNt] && rd->dimCounts[dimNt] > 1)) { - fullPhyDim[dimN] = FALSE; - break; - } - } - fullPhyRec = fullPhyDim[firstDim]; - } - else - fullPhyRec = TRUE; - /**************************************************************************** - * Determine if only one read is needed. In order for this to be so... - * 1. Full physical records must be being read, and - * 2a. If the record variance is TRUE, then the record interval must be one - * (or a record count of one) so that there is no skipping of records - * 2b. If the record variance is FALSE. - ****************************************************************************/ - firstHypRec = rd->recNumber; - lastHypRec = firstHypRec + (rd->recInterval * (rd->recCount - 1)); - firstPhyRec = (Var->recVary ? firstHypRec : 0); - if (fullPhyRec && - ((Var->recVary && (rd->recInterval == 1 || rd->recCount == 1)) - || - (!Var->recVary))) { - nRecords = lastHypRec - firstHypRec + 1; - nValues = (OFF_T) nRecords * Var->NphyRecValues; - if (!sX(ReadVarValues64(CDF,Var,firstPhyRec, - INT32_ZERO,nValues,buffer),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * A single read was not possible - read one record at a time. - ****************************************************************************/ - if (Var->numDims > 0) { - for (dimN = firstDim; dimN != doneDim; dimN += dimIncr) { - nHypDimValues[dimN] = 1; - for (dimNt = dimN + dimIncr; dimNt != doneDim; dimNt += dimIncr) - nHypDimValues[dimN] *= rd->dimCounts[dimNt]; - } - nHypRecValues = nHypDimValues[firstDim] * rd->dimCounts[firstDim]; - } - else - nHypRecValues = 1; - nHypRecBytes = nHypRecValues * Var->NvalueBytes; - for (i = 0, recNum = rd->recNumber, tBuffer = buffer; i < rd->recCount; - i++, recNum += rd->recInterval, tBuffer += (size_t) nHypRecBytes) { - phyRecN = BOO(Var->recVary,recNum,0); - if (fullPhyRec) { - /******************************************************************* - * The full physical record is being read, use one physical read. - *******************************************************************/ - if (!sX(ReadVarValues64(CDF,Var,phyRecN,INT32_ZERO, - Var->NphyRecValues, - tBuffer),&pStatus)) return pStatus; - } - else { - /******************************************************************* - * Less than the full physical record is to be read. Allocate a - * physical record buffer if possible and read in the whole record - * and extract values from the buffer. Otherwise, get one value at a - * time from the file - *******************************************************************/ - phyBuffer = (Byte1 *) cdf_AllocateMemory((size_t) Var->NphyRecBytes,NULL); - if (phyBuffer != NULL) { - if (!sX(ReadVarValues64(CDF,Var,phyRecN,INT32_ZERO,Var->NphyRecValues, - phyBuffer),&pStatus)) { - cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - } - if (!sX(HyperReadDim64(Var->numDims,Var->dimSizes, - Var->dimVarys,rd->dimIndices, - rd->dimCounts,rd->dimIntervals, - nHypDimValues,Var->nPhyDimValues, - fullPhyDim,firstDim,dimIncr, - phyRecN,INT32_ZERO,tBuffer,phyBuffer, - CDF,Var),&pStatus)) { - if (phyBuffer != NULL) cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - if (phyBuffer != NULL) cdf_FreeMemory(phyBuffer,NULL); - } - } - return pStatus; -} - -/****************************************************************************** -* HyperReadDim64. DANGER, DANGER, I'm recursive. -* NOTE: This routine could be called for a record which is virtual. -******************************************************************************/ - -STATICforIDL CDFstatus HyperReadDim64 (numDims, dimSizes, dimVarys, indices, - counts, intervals, nHypDimValues, - nPhyDimValues, fullPhyDim, firstDim, - dimIncr, recNum, offset, buffer, phyBuffer, - CDF, Var) -Int32 numDims; -Int32 *dimSizes; -Int32 *dimVarys; -Int32 *indices; -Int32 *counts; -Int32 *intervals; -Int32 *nHypDimValues; -Int32 *nPhyDimValues; -Logical *fullPhyDim; -int firstDim; -int dimIncr; -Int32 recNum; -Int32 offset; /* Byte offset within record. */ -void *buffer; -void *phyBuffer; -struct CDFstruct *CDF; -struct VarStruct *Var; -{ - Int32 tOffset; Int32 i; Byte1 *tBuffer; CDFstatus pStatus = CDF_OK; - OFF_T nValues; - /**************************************************************************** - * What to do depends on the number of dimensions. Note that this function - * should never be called with zero dimensions. - ****************************************************************************/ - switch (numDims) { - case 1: { - /************************************************************************ - * One dimension - read the values along the dimension. - ************************************************************************/ - if (dimVarys[0]) { - /********************************************************************** - * Dimension variance of TRUE, no virtual values to deal with - read - * physical values. - **********************************************************************/ - if (intervals[0] == 1) { - /******************************************************************** - * A contiguous strip of values. - ********************************************************************/ - tOffset = offset + (indices[0] * Var->NvalueBytes); - if (phyBuffer == NULL) { - if (!sX(ReadVarValues64(CDF,Var,recNum, - tOffset,counts[0], - buffer),&pStatus)) return pStatus; - } else { - memmove (buffer, (size_t) tOffset + (Byte1 *) phyBuffer, - (size_t) (Var->NvalueBytes * counts[0])); - } - } - else { - /******************************************************************** - * Not contiguous, read one value at a time skipping over unwanted - * values. - ********************************************************************/ - tOffset = offset + (indices[0] * Var->NvalueBytes); - tBuffer = buffer; - for (i = 0; i < counts[0]; i++) { - if (phyBuffer == NULL) { - if (!sX(ReadVarValues64(CDF,Var,recNum, - tOffset,(OFF_T) 1, - tBuffer),&pStatus)) return pStatus; - } else { - memmove (tBuffer, (size_t) tOffset+(Byte1 *) phyBuffer, - (size_t) Var->NvalueBytes); - } - tOffset += (intervals[0] * Var->NvalueBytes); - tBuffer += (size_t) Var->NvalueBytes; - } - } - } - else { - /********************************************************************** - * Dimension variance of FALSE, only one physical value exists. If the - * count is greater than one, virtual values will have to be generated. - **********************************************************************/ - if (phyBuffer == NULL) { - if (!sX(ReadVarValues64(CDF,Var,recNum,offset, - (OFF_T) 1,buffer),&pStatus)) return pStatus; - } else { - memmove(buffer, (size_t) offset + (Byte1 *) phyBuffer, - (size_t) Var->NvalueBytes); - } - if (counts[0] > 1) { - for (i = 1, tBuffer = (Byte1 *) buffer + (size_t) Var->NvalueBytes; - i < counts[0]; i++, tBuffer += (size_t) Var->NvalueBytes) { - memmove (tBuffer, buffer, (size_t) Var->NvalueBytes); - } - } - } - break; - } - default: { - /************************************************************************ - * Two or more dimensions. - ************************************************************************/ - Int32 nPhyDimBytes = nPhyDimValues[firstDim] * Var->NvalueBytes; - Int32 nHypDimBytes = nHypDimValues[firstDim] * Var->NvalueBytes; - int nextDim = firstDim + dimIncr; - if (dimVarys[firstDim]) { - /********************************************************************** - * The first dimension's variance is TRUE. If the interval is one and - * only a single read is necessary for the "lower" dimension, use a - * single read. Otherwise, cycle through that dimension physically - * reading each subarray below it (skipping subarrays if necessary). - **********************************************************************/ - if (intervals[firstDim] == 1 && fullPhyDim[nextDim]) { - tOffset = offset + (indices[firstDim] * nPhyDimBytes); - nValues = (OFF_T) counts[firstDim] * nPhyDimValues[firstDim]; - if (phyBuffer == NULL) { - if (!sX(ReadVarValues64(CDF,Var,recNum, - tOffset,nValues, - buffer),&pStatus)) return pStatus; - } else { - memmove(buffer, (size_t) tOffset + (Byte1 *) phyBuffer, - (size_t) (Var->NvalueBytes * nValues)); - } - } - else { - tOffset = offset + (indices[firstDim] * nPhyDimBytes); - tBuffer = buffer; - for (i = 0; i < counts[firstDim]; i++) { - if (fullPhyDim[nextDim]) { - if (phyBuffer == NULL) { - if (!sX(ReadVarValues64(CDF,Var,recNum, - tOffset,(OFF_T)nPhyDimValues[firstDim], - tBuffer),&pStatus)) return pStatus; - } else { - memmove(tBuffer, (size_t) tOffset + (Byte1 *) phyBuffer, - (size_t) (Var->NvalueBytes * nPhyDimValues[firstDim])); - } - } - else { - int numDimsT = (int) (numDims - 1); - int firstDimT = (CDF->rowMajor ? 0 : numDimsT - 1); - int passDimT = (CDF->rowMajor ? 1 : 0); - if (!sX(HyperReadDim64(numDimsT,&dimSizes[passDimT], - &dimVarys[passDimT], - &indices[passDimT], - &counts[passDimT], - &intervals[passDimT], - &nHypDimValues[passDimT], - &nPhyDimValues[passDimT], - &fullPhyDim[passDimT],firstDimT, - dimIncr,recNum,tOffset,tBuffer,phyBuffer, - CDF,Var),&pStatus)) return pStatus; - } - tOffset += (intervals[firstDim] * nPhyDimBytes); - tBuffer += (size_t) nHypDimBytes; - } - } - } - else { - /********************************************************************** - * The first dimension's variance is FALSE, physically read the only - * existing subarray and generate virtual subarrays if necessary. - **********************************************************************/ - if (fullPhyDim[nextDim]) { - if (phyBuffer == NULL) { - if (!sX(ReadVarValues64(CDF,Var,recNum,offset, - nPhyDimValues[firstDim], - buffer),&pStatus)) return pStatus; - } else { - - memmove(buffer, (size_t) offset + (Byte1 *) phyBuffer, - (size_t) (Var->NvalueBytes * nPhyDimValues[firstDim])); - } - } - else { - int numDimsT = (int) (numDims - 1); - int firstDimT = (CDF->rowMajor ? 0 : numDimsT - 1); - int passDimT = (CDF->rowMajor ? 1 : 0); - if (!sX(HyperReadDim64(numDimsT,&dimSizes[passDimT], - &dimVarys[passDimT],&indices[passDimT], - &counts[passDimT],&intervals[passDimT], - &nHypDimValues[passDimT], - &nPhyDimValues[passDimT], - &fullPhyDim[passDimT],firstDimT, - dimIncr,recNum,offset,buffer,phyBuffer, - CDF,Var),&pStatus)) return pStatus; - } - if (counts[firstDim] > 1) { - for (i = 1, tBuffer = (Byte1 *) buffer + (size_t) nHypDimBytes; - i < counts[firstDim]; i++, tBuffer += (size_t) nHypDimBytes) { - memmove (tBuffer, buffer, (size_t) nHypDimBytes); - } - } - } - break; - } - } - return pStatus; -} - -/****************************************************************************** -* HyperWrite64. -******************************************************************************/ - -STATICforIDL CDFstatus HyperWrite64 (CDF, Var, rd, buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -struct rdSTRUCT *rd; -void *buffer; -{ - Int32 nHypRecValues, nHypRecBytes, nHypDimValues[CDF_MAX_DIMS]; - Logical fullPhyRec, fullPhyDim[CDF_MAX_DIMS]; - Int32 firstPhyRec, phyRecN; Byte1 *tBuffer; int dimN; Int32 i; - CDFstatus pStatus = CDF_OK; Byte1 *phyBuffer; OFF_T nValues; - int firstDim; /* Based on majority, the "highest" dimension - (changes the slowest in memory/on disk). */ - int doneDim; /* When cycling through the dimensions, the - dimension at which to stop (the dimension - beyond the last). */ - int dimIncr; /* How to cycle through the dimensions. Incr- - ementing (+1) for row-major, decrementing - (-1) for column-major. */ - /**************************************************************************** - * Determine dimension ordering. - ****************************************************************************/ - if (Var->numDims > 0) { - firstDim = (int) (CDF->rowMajor ? 0 : Var->numDims - 1); - doneDim = (int) (CDF->rowMajor ? Var->numDims : -1); - dimIncr = (CDF->rowMajor ? 1 : -1); - } - /**************************************************************************** - * Determine if full physical dimensions can be written. In order for this to - * be so for a particular dimension... - * 1. If the dimension variance is TRUE, then the entire dimension must be - * written (the count equal to the size). If the dimension variance is - * FALSE, the count must be equal to one (only writing the single - * physical value). - * 2. For each `lower' dimension having a TRUE variance, the entire - * dimension must be written (the count equal to the size). - * 3. For each `lower' dimension having a FALSE variance, the count must - * be equal to one (only writing the single physical dimension). - * Also determine if full physical records can be written. If there are one - * or more dimensions, this depends on whether or not the first dimension can - * be written with a single physical write. If there are zero dimensions, - * then this is always true. - ****************************************************************************/ - if (Var->numDims > 0) { - for (dimN = firstDim; dimN != doneDim; dimN += dimIncr) { - int dimNt; - fullPhyDim[dimN] = TRUE; - for (dimNt = dimN; dimNt != doneDim; dimNt += dimIncr) - if ((Var->dimVarys[dimNt] && - rd->dimCounts[dimNt] != Var->dimSizes[dimNt]) || - (!Var->dimVarys[dimNt] && rd->dimCounts[dimNt] > 1)) { - fullPhyDim[dimN] = FALSE; - break; - } - } - fullPhyRec = fullPhyDim[firstDim]; - } - else - fullPhyRec = TRUE; - /**************************************************************************** - * Determine if only one write is needed. In order for this to be so... - * 1. Full physical records must be being written. - * 2. A record variance of FALSE, or if the record variance is TRUE, then - * the record interval must be one (or a record count of one) so that - * there is no skipping of records. - ****************************************************************************/ - phyRecN = 0; - if (fullPhyRec && - ((Var->recVary && (rd->recInterval == 1 || rd->recCount == 1)) || - (!Var->recVary))) { - if (Var->recVary) { - phyRecN = rd->recNumber; - tBuffer = buffer; - nValues = (OFF_T) rd->recCount * Var->NphyRecValues; - } - else { - tBuffer = (Byte1 *) buffer + - (size_t) (Var->NphyRecBytes * (rd->recCount-1)); - nValues = (OFF_T) Var->NphyRecValues; - } - if (!sX(WriteVarValues64(CDF,Var,phyRecN,INT32_ZERO, - nValues,tBuffer),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * Only one write not possible - will have to write one record at a time. - * First calculate size of hyper records. - ****************************************************************************/ - if (Var->numDims > 0) { - for (dimN = firstDim; dimN != doneDim; dimN += dimIncr) { - int dimNt; - nHypDimValues[dimN] = 1; - for (dimNt = dimN + dimIncr; dimNt != doneDim; dimNt += dimIncr) - nHypDimValues[dimN] *= rd->dimCounts[dimNt]; - } - nHypRecValues = nHypDimValues[firstDim] * rd->dimCounts[firstDim]; - } - else - nHypRecValues = 1; - nHypRecBytes = nHypRecValues * Var->NvalueBytes; - firstPhyRec = BOO(Var->recVary,rd->recNumber,0); - /**************************************************************************** - * Write each record. - ****************************************************************************/ - if (Var->recVary) { - /************************************************************************** - * A TRUE record variance - write each physical record. - **************************************************************************/ - for (i = 0, phyRecN = firstPhyRec, tBuffer = buffer; - i < rd->recCount; - i++, phyRecN += rd->recInterval, tBuffer += (size_t) nHypRecBytes) { - if (fullPhyRec) { - /********************************************************************* - * The full physical record is being written, use one physical write. - *********************************************************************/ - if (!sX(WriteVarValues64(CDF,Var,phyRecN,INT32_ZERO, - (OFF_T) Var->NphyRecValues, - tBuffer),&pStatus)) return pStatus; - } - else { - /********************************************************************* - * Less than the full physical record is to be written. - * physical record buffer if possible and fill in the whole record - * with values from the buffer. Otherwise, write one value at a - * time to the file - *********************************************************************/ - phyBuffer = (Byte1 *) cdf_AllocateMemory((size_t) Var->NphyRecBytes,NULL); - if (phyBuffer != NULL) { - if (!sX(ReadVarValues64(CDF,Var,phyRecN,INT32_ZERO, - Var->NphyRecValues, - phyBuffer),&pStatus)) { - if (pStatus != VIRTUAL_RECORD_DATA) { - cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - } - } - if (pStatus == VIRTUAL_RECORD_DATA) /* Don't want it to stop. */ - pStatus = CDF_OK; - if (!sX(HyperWriteDim64(Var->numDims,Var->dimSizes, - Var->dimVarys,rd->dimIndices, - rd->dimCounts,rd->dimIntervals, - nHypDimValues,Var->nPhyDimValues, - fullPhyDim,firstDim, - dimIncr,phyRecN,INT32_ZERO,tBuffer,phyBuffer, - CDF,Var),&pStatus)) { - if (phyBuffer != NULL) { - cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - } - if (phyBuffer != NULL) { - if (!sX(WriteVarValues64(CDF,Var,phyRecN,INT32_ZERO, - (OFF_T) Var->NphyRecValues,phyBuffer),&pStatus)) { - cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - cdf_FreeMemory(phyBuffer,NULL); - } - } - } - } - else { - /************************************************************************** - * A FALSE record variance. Only one physical record to actually be - * written. No need to check if a full physical record can be written - * since that case would have been handled above (because of the FALSE - * record variance). If the record count is greater than one, the LAST - * record in the buffer will be written (as if the records before it had - * been written but then overwritten by the last one). - **************************************************************************/ - tBuffer = (Byte1 *) buffer + (size_t) (nHypRecBytes * (rd->recCount - 1)); - phyBuffer = (Byte1 *) cdf_AllocateMemory((size_t) Var->NphyRecBytes,NULL); - if (phyBuffer != NULL) { - if (!sX(ReadVarValues64(CDF,Var,phyRecN,INT32_ZERO, - Var->NphyRecValues, - phyBuffer),&pStatus)) { - if (pStatus != VIRTUAL_RECORD_DATA) { - cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - } - } - if (pStatus != VIRTUAL_RECORD_DATA) /* Don't want it to stop */ - pStatus = CDF_OK; - if (!sX(HyperWriteDim64(Var->numDims,Var->dimSizes,Var->dimVarys, - rd->dimIndices,rd->dimCounts, - rd->dimIntervals,nHypDimValues, - Var->nPhyDimValues,fullPhyDim, - firstDim,dimIncr, - INT32_ZERO,INT32_ZERO,tBuffer,phyBuffer, - CDF,Var),&pStatus)) { - if (phyBuffer != NULL) { - cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - } - if (phyBuffer != NULL) { - if (!sX(WriteVarValues64(CDF,Var,phyRecN,INT32_ZERO, - (OFF_T) Var->NphyRecValues,phyBuffer),&pStatus)) { - cdf_FreeMemory(phyBuffer,NULL); - return pStatus; - } - cdf_FreeMemory(phyBuffer,NULL); - } - } - return pStatus; -} - -/****************************************************************************** -* HyperWriteDim64. DANGER, DANGER, I'm recursive. -******************************************************************************/ - -STATICforIDL CDFstatus HyperWriteDim64 (numDims, dimSizes, dimVarys, indices, - counts, intervals, nHypDimValues, - nPhyDimValues, fullPhyDim, firstDim, - dimIncr, recNum, offset, buffer, - phyBuffer, CDF, Var) -Int32 numDims; -Int32 *dimSizes; -Int32 *dimVarys; -Int32 *indices; -Int32 *counts; -Int32 *intervals; -Int32 *nHypDimValues; -Int32 *nPhyDimValues; -Logical *fullPhyDim; -int firstDim; -int dimIncr; -Int32 recNum; /* Record number for this write. */ -Int32 offset; /* Byte offset within record at which to begin. */ -void *buffer; -void *phyBuffer; -struct CDFstruct *CDF; -struct VarStruct *Var; -{ - Int32 tOffset; Int32 i; Byte1 *tBuffer; - CDFstatus pStatus = CDF_OK; OFF_T nValues; - /**************************************************************************** - * What to do depends on the number of dimensions. Note that this function - * should never be called with zero dimensions. - ****************************************************************************/ - switch (numDims) { - case 1: { - /************************************************************************ - * One dimension - write the values along the dimension. - ************************************************************************/ - if (dimVarys[0]) { - /********************************************************************** - * Dimension variance of TRUE, there are no virtual values to deal - * with (skip) - read physical values. - **********************************************************************/ - if (intervals[0] == 1) { - /******************************************************************** - * A contiguous strip of values. - ********************************************************************/ - tOffset = offset + (indices[0] * Var->NvalueBytes); - if (phyBuffer == NULL) { - if (!sX(WriteVarValues64(CDF,Var,recNum, - tOffset,(OFF_T) counts[0], - buffer),&pStatus)) return pStatus; - } else { - memmove ((size_t) tOffset + (Byte1 *) phyBuffer, buffer, - (size_t) (Var->NvalueBytes * counts[0])); - } - } - else { - /******************************************************************** - * Not contiguous, write one value at a time skipping over physical - * values not being written. - ********************************************************************/ - tOffset = offset + (indices[0] * Var->NvalueBytes); - tBuffer = buffer; - for (i = 0; i < counts[0]; i++) { - if (phyBuffer == NULL) { - if (!sX(WriteVarValues64(CDF,Var,recNum, - tOffset,(OFF_T) 1, - tBuffer),&pStatus)) return pStatus; - } else { - memmove ((size_t) tOffset+(Byte1 *) phyBuffer, tBuffer, - (size_t) Var->NvalueBytes); - } - tOffset += (intervals[0] * Var->NvalueBytes); - tBuffer += (size_t) Var->NvalueBytes; - } - } - } - else { - /********************************************************************** - * Dimension variance of FALSE, only one physical value to be written. - * If the count is greater than one, skip to the last value in the - * buffer (this is an unlikely situation). - **********************************************************************/ - tBuffer = (Byte1 *) buffer + - (size_t) (Var->NvalueBytes * (counts[0] - 1)); - if (phyBuffer == NULL) { - if (!sX(WriteVarValues64(CDF,Var,recNum,offset, - (OFF_T) 1,tBuffer),&pStatus)) return pStatus; - } else { - memmove((size_t) offset + (Byte1 *) phyBuffer, tBuffer, - (size_t) Var->NvalueBytes); - } - } - break; - } - default: { - /************************************************************************ - * Two or more dimensions. - ************************************************************************/ - Int32 nPhyDimBytes = nPhyDimValues[firstDim] * Var->NvalueBytes; - Int32 nHypDimBytes = nHypDimValues[firstDim] * Var->NvalueBytes; - int nextDim = firstDim + dimIncr; - if (dimVarys[firstDim]) { - /********************************************************************** - * The first dimension's variance is TRUE. If the interval is one and - * only a single write is necessary for the "lower" dimension, use a - * single write. Otherwise, cycle through that dimension physically - * writing each subarray below it (skipping subarrays if necessary). - **********************************************************************/ - if (intervals[firstDim] == 1 && fullPhyDim[nextDim]) { - tOffset = offset + (indices[firstDim] * nPhyDimBytes); - nValues = (OFF_T) counts[firstDim] * nPhyDimValues[firstDim]; - if (phyBuffer == NULL) { - if (!sX(WriteVarValues64(CDF,Var,recNum, - tOffset,nValues, - buffer),&pStatus)) return pStatus; - } else { - memmove((size_t) tOffset + (Byte1 *) phyBuffer, buffer, - (size_t) (Var->NvalueBytes * nValues)); - } - } - else { - tOffset = offset + (indices[firstDim] * nPhyDimBytes); - tBuffer = buffer; - for (i = 0; i < counts[firstDim]; i++) { - if (fullPhyDim[nextDim]) { - if (phyBuffer == NULL) { - if (!sX(WriteVarValues64(CDF,Var,recNum,tOffset, - (OFF_T) nPhyDimValues[firstDim], - tBuffer),&pStatus)) return pStatus; - } else { - memmove((size_t) tOffset + (Byte1 *) phyBuffer, tBuffer, - (size_t) (Var->NvalueBytes * nPhyDimValues[firstDim])); - } - } - else { - int numDimsT = (int) (numDims - 1); - int firstDimT = (CDF->rowMajor ? 0 : numDimsT - 1); - int passDimT = (CDF->rowMajor ? 1 : 0); - if (!sX(HyperWriteDim64(numDimsT,&dimSizes[passDimT], - &dimVarys[passDimT], - &indices[passDimT], - &counts[passDimT], - &intervals[passDimT], - &nHypDimValues[passDimT], - &nPhyDimValues[passDimT], - &fullPhyDim[passDimT], - firstDimT,dimIncr,recNum, - tOffset,tBuffer,phyBuffer, - CDF,Var),&pStatus)) return pStatus; - } - tOffset += (intervals[firstDim] * nPhyDimBytes); - tBuffer += (size_t) nHypDimBytes; - } - } - } - else { - /********************************************************************** - * The first dimension's variance is FALSE, skip to the last subarray - * and write the single physical subarray. - **********************************************************************/ - tBuffer = (Byte1 *) buffer + - (size_t) (nHypDimBytes * (counts[firstDim] - 1)); - if (fullPhyDim[nextDim]) { - if (phyBuffer == NULL) { - if (!sX(WriteVarValues64(CDF,Var,recNum,offset, - (OFF_T) nPhyDimValues[firstDim], - tBuffer),&pStatus)) return pStatus; - } else { - memmove((size_t) offset + (Byte1 *) phyBuffer, tBuffer, - (size_t) (Var->NvalueBytes * nPhyDimValues[firstDim])); - } - } - else { - int numDimsT = (int) (numDims - 1); - int firstDimT = (CDF->rowMajor ? 0 : numDimsT - 1); - int passDimT = (CDF->rowMajor ? 1 : 0); - if (!sX(HyperWriteDim64(numDimsT,&dimSizes[passDimT], - &dimVarys[passDimT], - &indices[passDimT], - &counts[passDimT], - &intervals[passDimT], - &nHypDimValues[passDimT], - &nPhyDimValues[passDimT], - &fullPhyDim[passDimT],firstDimT, - dimIncr,recNum,offset,tBuffer,phyBuffer, - CDF,Var),&pStatus)) return pStatus; - } - } - break; - } - } - - return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdflib.c b/cdf36_3-dist/src/lib/cdflib.c deleted file mode 100644 index 5600783..0000000 --- a/cdf36_3-dist/src/lib/cdflib.c +++ /dev/null @@ -1,263 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF INTERNAL interface to CDF. -* -* Version 2.8b, 8-Mar-97, Hughes STX. -* -* Modification history: -* -* V1.0 22-Jan-91, R Kulkarni Original version (for CDF V2.0). -* J Love -* V2.0 6-Jun-91, J Love Renamed (was cdfcore.c). Modified for -* V2.1 style INTERNAL interface (and -* fixes to CDF V2.0 distribution). Also -* renamed some symbols for clarity. -* V2.1 24-Jun-91, J Love Fixed PUT_,VAR_INITIALRECS. Stripped -* trailing blanks off of CDF names. -* Allow variable data type to be changed -* if "equivalent". Added CDF_EPOCH as -* a data type. -* V2.2 8-Aug-91, J Love Don't use #elif (for SGi port) and -* added support for Cray/UNICOS. -* INTERNAL i/f function renamed 'CDFlib'. -* Different numbers of CACHE buffers for -* different file types (VIO). Modified -* hyper access (and fixed part of it). -* Changed attribute entry access. Check -* for supported encoding when opening a -* CDF. -* V2.3 20-May-92, J Love Changed for IBM-PC port (split into -* smaller source files, etc.). Made -* shareable. -* V2.4 21-Aug-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V2.5 19-Jan-94, J Love CDF V2.4. -* V2.6 15-Dec-94, J Love CDF V2.5. -* V2.6a 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V2.7 19-Jul-95, J Love Virtual memory (Microsoft C 7.00). -* V2.7a 22-Sep-95, J Love Changed virtual memory control. -* V2.8 19-Aug-96, J Love CDF V2.6. -* V2.8a 14-Feb-97, J Love Fixed `va_arg' usage. -* V2.8b 8-Mar-97, J Love Windows NT for MS Visual C++ 4 on an -* IBM PC. -* -******************************************************************************/ - -#define CDFLIB -#include "cdflib.h" -#include "cdflib64.h" - -#if defined(BUILDINGforIDL) -#define CUR Cur -#else -static struct CurStruct Cur = { RESERVED_CDFID, RESERVED_CDFSTATUS }; -#define CUR &Cur -#endif - -#if defined(MICROSOFTC_700) && INCLUDEvMEMORY -static Logical first = TRUE; -#endif - -static Logical second = TRUE; - -/****************************************************************************** -* CDFlib. -******************************************************************************/ - -#if defined(STDARG) -#if defined(BUILDINGforIDL) -VISIBLE_PREFIX CDFstatus CDFlib (struct CurStruct *Cur, long requiredFnc, ...) -#else -VISIBLE_PREFIX CDFstatus CDFlib (long requiredFnc, ...) -#endif -#else -VISIBLE_PREFIX CDFstatus CDFlib (va_alist) -va_dcl -#endif -{ - CDFstatus pStatus = CDF_OK; - struct VAstruct Va; -#if defined(BUILDINGforIDL) -#if defined(VARARGS) - struct CurStruct *Cur; -#endif -#endif - /**************************************************************************** - * Process variable length argument list. - ****************************************************************************/ -#if defined(STDARG) - va_start (Va.ap, requiredFnc); - Va.fnc = requiredFnc; -#else - VA_START (Va.ap); -#if defined(BUILDINGforIDL) - Cur = va_arg (Va.ap, struct CurStruct *); -#endif - Va.fnc = va_arg (Va.ap, long); -#endif - /**************************************************************************** - * Initialize virtual memory parameters for Microsoft C 7.00. - ****************************************************************************/ -#if defined(MICROSOFTC_700) && INCLUDEvMEMORY - if (first) { - char *vsize = getenv("CDF_VSIZE"); - if (vsize != NULL) { - long nBytes; - if (sscanf(vsize,"%ld",&nBytes) == 1) { - switch (nBytes) { - case 0: - useVmem = FALSE; - break; - case DEFAULT_vMEMSIZE: - useVmem = TRUE; - vMemSize = DEFAULT_vMEMSIZE; - break; - default: - useVmem = FALSE; /* Until the mystery is solved... */ - vMemSize = nBytes; - } - if (useVmem) { - char *vmask = getenv("CDF_VMASK"); - if (vmask != NULL) { - uInt4 tMask = 0; - if (strstr(vmask,"EMS") != NULL || - strstr(vmask,"ems") != NULL) tMask |= _VM_EMS; - if (strstr(vmask,"XMS") != NULL || - strstr(vmask,"xms") != NULL) tMask |= _VM_XMS; - if (strstr(vmask,"DISK") != NULL || - strstr(vmask,"disk") != NULL) tMask |= _VM_DISK; - if (tMask != 0) vMemMask = tMask; - } - } - } - } - first = FALSE; - } -#endif - - /**************************************************************************** - * Scan list of arguments. - ****************************************************************************/ - while (Va.fnc != NULL_) { - switch (Va.fnc) { - case CREATE_: - for (;;) { - Va.item = va_arg (Va.ap, long); - if (second) { - if (CDFgetFileBackwardEnvVar() == 1) { - CDFsetFileBackward2 (BACKWARDFILEon); - } - second = FALSE; - } - if (Va.item == CDF_ && CDFgetFileBackward() == 1) { - if (!sX(CDFcre(&Va,CUR),&pStatus)) return pStatus; - } else if (Va.item == CDF_ && CDFgetFileBackward() == 0) { - if (!sX(CDFcre64(&Va,CUR),&pStatus)) return pStatus; - } else { - if (*CUR.cdf != NULL && !isLFS(*CUR.cdf)) { - if (!sX(CDFcre(&Va,CUR),&pStatus)) return pStatus; - } else { - if (!sX(CDFcre64(&Va,CUR),&pStatus)) return pStatus; - } - } - if (Va.fnc == Va.item) break; - } - break; - case OPEN_: - for (;;) { - Va.item = va_arg (Va.ap, long); - if (!sX(CDFope(&Va,CUR),&pStatus)) return pStatus; - if (Va.fnc == Va.item) break; - } - break; - case DELETE_: - for (;;) { - Va.item = va_arg (Va.ap, long); - if (*CUR.cdf != NULL && !isLFS(*CUR.cdf)) { - if (!sX(CDFdel(&Va,CUR),&pStatus)) return pStatus; - } else { - if (!sX(CDFdel64(&Va,CUR),&pStatus)) return pStatus; - } - if (Va.fnc == Va.item) break; - } - break; - case CLOSE_: - for (;;) { - Va.item = va_arg (Va.ap, long); - if (*CUR.cdf != NULL && !isLFS(*CUR.cdf)) { - if (!sX(CDFclo(&Va,CUR),&pStatus)) return pStatus; - } else { - if (!sX(CDFclo64(&Va,CUR),&pStatus)) return pStatus; - } - if (Va.fnc == Va.item) break; - } - break; - case SELECT_: - for (;;) { - Va.item = va_arg (Va.ap, long); - if (*CUR.cdf != NULL && !isLFS(*CUR.cdf)) { - if (!sX(CDFsel(&Va,CUR),&pStatus)) return pStatus; - } else { - if (!sX(CDFsel64(&Va,CUR),&pStatus)) return pStatus; - } - if (Va.fnc == Va.item) break; - } - break; - case CONFIRM_: - for (;;) { - Va.item = va_arg (Va.ap, long); - if (*CUR.cdf != NULL && !isLFS(*CUR.cdf)) { - if (!sX(CDFcon(&Va,CUR),&pStatus)) return pStatus; - } else { - if (!sX(CDFcon64(&Va,CUR),&pStatus)) return pStatus; - } - if (Va.fnc == Va.item) break; - } - break; - case GET_: - for (;;) { - Va.item = va_arg (Va.ap, long); - if (Va.item == CDF_INFO_) { - if (!sX(CDFget64(&Va,CUR),&pStatus)) return pStatus; - } else if (*CUR.cdf != NULL && !isLFS(*CUR.cdf)) { - if (!sX(CDFget(&Va,CUR),&pStatus)) return pStatus; - } else { - if (!sX(CDFget64(&Va,CUR),&pStatus)) return pStatus; - } - if (Va.fnc == Va.item) break; - } - break; - case PUT_: - for (;;) { - Va.item = va_arg (Va.ap, long); - if (*CUR.cdf != NULL && !isLFS(*CUR.cdf)) { - if (!sX(CDFput1(&Va,CUR),&pStatus)) return pStatus; - } else { - if (!sX(CDFput1_64(&Va,CUR),&pStatus)) return pStatus; - } - if (Va.fnc == Va.item) break; - } - break; - - case SAVE_: - for (;;) { - Va.item = va_arg (Va.ap, long); - if (!sX(CDFsav(&Va,CUR),&pStatus)) return pStatus; - if (Va.fnc == Va.item) break; - } - break; - - default: { - va_end (Va.ap); - return BAD_FNC_OR_ITEM; - } - } - } - va_end (Va.ap); - return pStatus; -} - diff --git a/cdf36_3-dist/src/lib/cdfmd5.c b/cdf36_3-dist/src/lib/cdfmd5.c deleted file mode 100644 index 004f8fd..0000000 --- a/cdf36_3-dist/src/lib/cdfmd5.c +++ /dev/null @@ -1,282 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `MD5 checksum' operations. -* -* Version 1.0, 21-Mar-06, Hughes STX. -* -* Modification history: -* -* V1.0 21-Mar-06, M Liu Original version. Introduced cdfmd5.h to include -* the data structure required by the MD5 -* algorithm and source code borrowed from -* http://www.fourmilab.ch/md5 - no source code -* modification was done. -* -* No copyright is claimed (see COPYING below -* for details). -* -* COPYING (from http://www.fourmilab.ch/md5) -* This software is in the public domain. Permission to use, copy, -* modify, and distribute this software and its documentation for any -* purpose and without fee is hereby granted, without any conditions or -* restrictions. This software is provided "as is" without express or -* implied warranty. -* -* ACKNOWLEDGEMENTS (from http://www.fourmilab.ch/md5) -* The MD5 algorithm was developed by Ron Rivest. The public domain -* C language implementation used in this program was written by -* Colin Plumb in 1993. -* -* -* This code implements the MD5 message-digest algorithm. -* The algorithm is due to Ron Rivest. This code was -* written by Colin Plumb in 1993, no copyright is claimed. -* This code is in the public domain; do with it what you wish. -* -* Equivalent code is available from RSA Data Security, Inc. -* This code has been tested against that, and is equivalent, -* except that you don't need to include two pages of legalese -* with every copy. -* -* To compute the message digest of a chunk of bytes, declare an -* MD5Context structure, pass it to MD5Init, call MD5Update as -* needed on buffers full of bytes, and then call MD5Final, which -* will fill a supplied 16-byte array with the digest. -* -* Brutally hacked by John Walker back from ANSI C to K&R (no -* prototypes) to maintain the tradition that Netfone will compile -* with Sun's original "cc". -******************************************************************************/ - -#include /* for memcpy() */ -#include "cdfmd5.h" - -#ifndef HIGHFIRST -#define byteReverse(buf, len) /* Nothing */ -#else -/* - * Note: this code is harmless on little-endian machines. - */ -void byteReverse(buf, longs) - uChar *buf; unsigned longs; -{ - uint32 t; - do { - t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 | - ((unsigned) buf[1] << 8 | buf[0]); - *(uint32 *) buf = t; - buf += 4; - } while (--longs); - -} -#endif -/* - * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious - * initialization constants. - */ -void MD5Init(ctx) - struct MD5Context *ctx; -{ - ctx->buf[0] = 0x67452301; - ctx->buf[1] = 0xefcdab89; - ctx->buf[2] = 0x98badcfe; - ctx->buf[3] = 0x10325476; - - ctx->bits[0] = 0; - ctx->bits[1] = 0; -} - -/* - * Update context to reflect the concatenation of another buffer full - * of bytes. - */ -void MD5Update(ctx, buf, len) - struct MD5Context *ctx; uChar *buf; unsigned len; -{ - uint32 t; - - /* Update bitcount */ - t = ctx->bits[0]; - if ((ctx->bits[0] = t + ((uint32) len << 3)) < t) - ctx->bits[1]++; /* Carry from low to high */ - ctx->bits[1] += len >> 29; - - t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ - - /* Handle any leading odd-sized chunks */ - - if (t) { - uChar *p = (uChar *) ctx->in + t; - - t = 64 - t; - if (len < t) { - memcpy(p, buf, len); - return; - } - memcpy(p, buf, t); - byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (uint32 *) ctx->in); - buf += t; - len -= t; - } - /* Process data in 64-byte chunks */ - while (len >= 64) { - memcpy(ctx->in, buf, 64); - byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (uint32 *) ctx->in); - buf += 64; - len -= 64; - } - /* Handle any remaining bytes of data. */ - memcpy(ctx->in, buf, len); -} - -/* - * Final wrapup - pad to 64-byte boundary with the bit pattern - * 1 0* (64-bit count of bits processed, MSB-first) - */ -void MD5FinalZ(digest, ctx) - uChar digest[16]; struct MD5Context *ctx; -{ - unsigned count; - uChar *p; - /* Compute number of bytes mod 64 */ - count = (ctx->bits[0] >> 3) & 0x3F; - /* Set the first char of padding to 0x80. This is safe since there is - always at least one byte free */ - p = ctx->in + count; - *p++ = 0x80; - - /* Bytes of padding needed to make 64 bytes */ - count = 64 - 1 - count; - /* Pad out to 56 mod 64 */ - if (count < 8) { - /* Two lots of padding: Pad the first block to 64 bytes */ - memset(p, 0, count); - byteReverse(ctx->in, 16); - MD5Transform(ctx->buf, (uint32 *) ctx->in); - /* Now fill the next block with 56 bytes */ - memset(ctx->in, 0, 56); - } else { - /* Pad block to 56 bytes */ - memset(p, 0, count - 8); - } - byteReverse(ctx->in, 14); - - /* Append length in bits and transform */ - ((uint32 *) ctx->in)[14] = ctx->bits[0]; - ((uint32 *) ctx->in)[15] = ctx->bits[1]; - - MD5Transform(ctx->buf, (uint32 *) ctx->in); - byteReverse((uChar *) ctx->buf, 4); - memcpy(digest, ctx->buf, 16); - memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ -} - - -/* The four core functions - F1 is optimized somewhat */ - -/* #define F1(x, y, z) (x & y | ~x & z) */ -#define F1(x, y, z) (z ^ (x & (y ^ z))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) - -/* This is the central step in the MD5 algorithm. */ -#define MD5STEP(f, w, x, y, z, data, s) \ - ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) - -/* - * The core of the MD5 algorithm, this alters an existing MD5 hash to - * reflect the addition of 16 longwords of new data. MD5Update blocks - * the data and converts bytes into longwords for this routine. - */ -void MD5Transform(buf, in) - uint32 buf[4]; uint32 in[16]; -{ -/* register uint32 a, b, c, d; */ - uint32 a, b, c, d; - - a = buf[0]; - b = buf[1]; - c = buf[2]; - d = buf[3]; - - MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); - MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); - MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); - MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); - MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); - MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); - MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); - MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); - MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); - MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); - MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); - MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); - MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); - MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); - MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); - MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); - - MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); - MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); - MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); - MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); - MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); - MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); - MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); - MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); - MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); - MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); - MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); - MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); - MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); - MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); - MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); - MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); - - MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); - MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); - MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); - MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); - MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); - MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); - MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); - MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); - MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); - MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); - MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); - MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); - MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); - MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); - MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); - MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); - - MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); - MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); - MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); - MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); - MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); - MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); - MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); - MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); - MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); - MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); - MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); - MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); - MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); - MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); - MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); - MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); - - buf[0] += a; - buf[1] += b; - buf[2] += c; - buf[3] += d; -} diff --git a/cdf36_3-dist/src/lib/cdfmem.c b/cdf36_3-dist/src/lib/cdfmem.c deleted file mode 100644 index 5435ef1..0000000 --- a/cdf36_3-dist/src/lib/cdfmem.c +++ /dev/null @@ -1,577 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Memory Functions. -* -* Version 1.2b, 29-Oct-97, Hughes STX. -* -* Modification history: -* -* V1.0 17-May-95, J Love Original version. -* J Williams -* V1.1 25-Jul-95, J Love Simple virtual memory function. -* V1.1a 6-Sep-95, J Love Added `nBytes' to MEMLOG_. -* V1.1b 22-Sep-95, J Love Fixed call to `FreeVMemory'. -* V1.2 16-Aug-96, J Love CDF V2.6. -* V1.2a 28-Oct-96, J Love Added `return' statement to cdf_FreeMemory for -* when building for IDL. -* V1.2b 29-Oct-97, J Love More Windows NT. -* V2.0 19-May-05, M Liu Added "cdf_" to FreeMemory, AllocateMemory, -* ReallocateMemory functions. -* V2.1 12-Aug-10, M Liu Modified tmp string to allow the maximum -* location value in cdf_FreeMemoryX. Modified -* cdf_AllocateMemory to address potential large -* minor page faults issue for linux/cygwin. -* V2.2 20-May-12, M Liu Modified to remove mallopt calls as the -* allocated spaces stay in virtual memory ( -* within IDL). -* V2.3 09-Aug-13, M Liu Added cdfid_AllocateMemory, cdfid_getCDFid, -* cdfid_FreeMemory for each open/created 64-bit -* CDF id when called from Fortran as it uses -* only 4-byte to keep the CDFid. -******************************************************************************/ - -#define CDFMEM -#include "cdflib.h" -#include "cdflib64.h" -#if defined(linux) || defined(__CYGWIN__) -#include -#endif - -#define MEMLOG 0 -#define TO_STDOUT 0 -/* -static long numAllocs = 0; -static long numAlloc2 = 0; -static long numAlloc3 = 0; -*/ -/****************************************************************************** -* MEM structures/typedef's/global variables. -******************************************************************************/ - -#if !defined(BUILDINGforIDL) -typedef struct memSTRUCT { /* Structure. */ - void *ptr; - struct memSTRUCT *next; - size_t nBytes; -} MEM; -typedef MEM *MEMp; /* Pointer (to structure). */ -static MEMp memHeadP = NULL; /* Head of memory linked list. */ - -typedef struct CDFidSTRUCT { /* Structure. */ - void *ptr; - struct CDFidSTRUCT *next; -} CDFidMEM; -typedef CDFidMEM *CDFidMEMp; /* Pointer (to structure). */ -static CDFidMEMp cdfidHeadP = NULL; /* Head of cdfid memory linked list. */ -#endif - -/****************************************************************************** -* Local function prototypes. -******************************************************************************/ - -#if defined(MICROSOFTC_700) && INCLUDEvMEMORY -static Logical InitVMemory PROTOARGs((void)); -static void TermVMemory PROTOARGs((void)); -#endif - -#if MEMLOG -static uLongx TotalBytes PROTOARGs((MEMp memHeadP)); -#endif - -/****************************************************************************** -* Debugging macros. -******************************************************************************/ - -#if MEMLOG -#if TO_STDOUT -#define ALLOCFAILED(type,which,nBytes) \ - {FILE *fp = FOPEN("mem.log","a"); \ - fprintf (fp, "%sllocation FAILED [%d]: %lu bytes\n", \ - type, which, (uLongx) nBytes); \ - fprintf (stdout, "%sllocation FAILED [%d]: %lu bytes\n", \ - type, which, (uLongx) nBytes); \ - fclose (fp);} -#else -#define ALLOCFAILED(type,which,nBytes) \ - {FILE *fp = FOPEN("mem.log","a"); \ - fprintf (fp, "%sllocation FAILED [%d]: %lu bytes\n", \ - type, which, (uLongx) nBytes); \ - fclose (fp);} -#endif -#else -#define ALLOCFAILED(type,which,nBytes) \ - -#endif - -#if MEMLOG -#if TO_STDOUT -#define ALLOCSUCCESS(type,nBytes,ptr,totalBytes) \ - {FILE *fp = FOPEN("mem.log","a"); uLongx totalBytesSave = totalBytes; \ - fprintf (fp, "%sllocated: %lu bytes at %p (%lu bytes total)\n", \ - type, (uLongx) nBytes, ptr, totalBytesSave); \ - fprintf (stdout, "%sllocated: %lu bytes at %p (%lu bytes total)\n", \ - type, (uLongx) nBytes, ptr, totalBytesSave); \ - fclose (fp);} -#else -#define ALLOCSUCCESS(type,nBytes,ptr,totalBytes) \ - {FILE *fp = FOPEN("mem.log","a"); \ - fprintf (fp, "%sllocated: %lu bytes at %p (%lu bytes total)\n", \ - type, (uLongx) nBytes, ptr, totalBytes); \ - fclose (fp);} -#endif -#else -#define ALLOCSUCCESS(type,nBytes,ptr,totalBytes) \ - -#endif - -#if MEMLOG -#if TO_STDOUT -#define FREESUCCESS(type,ptr,nBytes) \ - {FILE *fp = FOPEN("mem.log","a"); \ - fprintf (fp, "Freed (%s): %p, %lu bytes\n", type, ptr, (uLongx) nBytes); \ - fprintf (stdout, "Freed (%s): %p, %lu bytes\n", type, ptr, (uLongx) nBytes); \ - fclose (fp);} -#else -#define FREESUCCESS(type,ptr,nBytes) \ - {FILE *fp = FOPEN("mem.log","a"); \ - fprintf (fp, "Freed (%s): %p, %lu bytes\n", type, ptr, (uLongx) nBytes); \ - fclose (fp);} -#endif -#else -#define FREESUCCESS(type,ptr,nBytes) \ - -#endif - -#if MEMLOG -#if TO_STDOUT -#define FREEFAILED(ptr) \ - {FILE *fp = FOPEN("mem.log","a"); \ - fprintf (fp, "Free failed [pointer not found]: %p\n", ptr); \ - fprintf (stdout, "Free failed [pointer not found]: %p\n", ptr); \ - fclose (fp);} -#else -#define FREEFAILED(ptr) \ - {FILE *fp = FOPEN("mem.log","a"); \ - fprintf (fp, "Free failed [pointer not found]: %p\n", ptr); \ - fclose (fp);} -#endif -#else -#define FREEFAILED(ptr) \ - -#endif - -/****************************************************************************** -* cdf_AllocateMemory. -******************************************************************************/ - -VISIBLE_PREFIX void *cdf_AllocateMemory (nBytes, fatalFnc) -size_t nBytes; -void (*fatalFnc) PROTOARGs((char *msg)); -{ -#if defined(BUILDINGforIDL) - /* ++numAllocs; */ /* printf("(+1)numAllocs=%ld\n",numAllocs); */ - return malloc(nBytes); -#else - MEMp mem; - /* ++numAllocs; */ /* printf("(+1)numAllocs=%ld\n",numAllocs); */ -#if defined(linux) || defined(__CYGWIN__) -/* mallopt(M_MMAP_MAX, 0); */ -/* mallopt(M_TRIM_THRESHOLD, -1); */ -#endif - if (nBytes < 1) { - ALLOCFAILED("A",1,nBytes) - return NULL; - } - mem = (MEMp) malloc (sizeof(MEM)); - if (mem == NULL) { - ALLOCFAILED("A",2,nBytes) - if (fatalFnc != NULL) (*fatalFnc)("Unable to allocate memory buffer [1]."); - return NULL; - } - mem->ptr = (void *) malloc (nBytes); - if (mem->ptr == NULL) { - ALLOCFAILED("A",3,nBytes) - free (mem); - if (fatalFnc != NULL) (*fatalFnc)("Unable to allocate memory buffer [2]."); - return NULL; - } - mem->nBytes = nBytes; - mem->next = memHeadP; - memHeadP = mem; - ALLOCSUCCESS("A",mem->nBytes,mem->ptr,TotalBytes(memHeadP)) - return mem->ptr; -#endif -} - -/****************************************************************************** -* cdf_ReallocateMemory. -******************************************************************************/ - -VISIBLE_PREFIX void *cdf_ReallocateMemory (ptr, nBytes, fatalFnc) -void *ptr; -size_t nBytes; -void (*fatalFnc) PROTOARGs((char *msg)); -{ -#if defined(BUILDINGforIDL) - return realloc(ptr,nBytes); -#else - MEMp mem = memHeadP; - while (mem != NULL) { - if (mem->ptr == ptr) { - void *newPtr = (void *) realloc (ptr, nBytes); - if (newPtr == NULL) { - ALLOCFAILED("Rea",1,nBytes) - if (fatalFnc != NULL) { - (*fatalFnc)("Unable to reallocate memory buffer [1]."); - } - return NULL; - } - mem->ptr = newPtr; - mem->nBytes = nBytes; - ALLOCSUCCESS("Rea",mem->nBytes,mem->ptr,TotalBytes(memHeadP)) - return newPtr; - } - mem = mem->next; - } - ALLOCFAILED("Rea",2,nBytes) - if (fatalFnc != NULL) (*fatalFnc)("Unable to reallocate memory buffer [2]."); - return NULL; -#endif -} - -/****************************************************************************** -* cdf_FreeMemory. -* If NULL is passed as the pointer to free, then free the entire list of -* allocated memory blocks. -******************************************************************************/ - -VISIBLE_PREFIX int cdf_FreeMemory (ptr, fatalFnc) -void *ptr; -void (*fatalFnc) PROTOARGs((char *msg)); -{ -#if defined(BUILDINGforIDL) - /* --numAllocs; */ /* printf("(-1)numAllocs=%ld\n",numAllocs); */ - free (ptr); - return 1; -#else - /* --numAllocs; */ /* printf("(-1)numAllocs=%ld\n",numAllocs); */ - if (ptr == NULL) { - int count = 0; - MEMp mem = memHeadP; - while (mem != NULL) { - MEMp memX = mem; - mem = mem->next; - FREESUCCESS("NULL",memX->ptr,memX->nBytes) - free (memX->ptr); - free (memX); - count++; - } - memHeadP = NULL; - return count; - } - else { - MEMp mem = memHeadP, memPrev = NULL; - while (mem != NULL) { - if (mem->ptr == ptr) { - MEMp memX = mem; - if (memPrev == NULL) - memHeadP = mem->next; - else - memPrev->next = mem->next; - FREESUCCESS("one",memX->ptr,memX->nBytes) - free (memX->ptr); - free (memX); - return 1; - } - memPrev = mem; - mem = mem->next; - } - FREEFAILED(ptr) - if (fatalFnc != NULL) (*fatalFnc)("Unable to free memory buffer."); - return 0; - } -#endif -} - -/****************************************************************************** -* cdfid_AllocateMemory. -* Used for saving the CDFid pointer in 64-bit mode for Fortran interface. -******************************************************************************/ - -VISIBLE_PREFIX void cdfid_AllocateMemory (id, fatalFnc) -void *id; -void (*fatalFnc) PROTOARGs((char *msg)); -{ - CDFidMEMp mem; - /* ++numAlloc3; */ /* printf("(+1)numAlloc3=%ld\n",numAlloc3); */ - mem = (CDFidMEMp) malloc (sizeof(CDFidMEM)); - if (mem == NULL) { - if (fatalFnc != NULL) (*fatalFnc)("Unable to allocate memory buffer [1]."); - return; - } - mem->ptr = id; - mem->next = cdfidHeadP; - cdfidHeadP = mem; -} - -/****************************************************************************** -* cdfid_getCDFid. -* Return 8-byte CDF id based on the 4-byte information from Fortran interface. -******************************************************************************/ - -VISIBLE_PREFIX CDFid cdfid_getCDFid (shortId, fatalFnc) -Int32 shortId; -void (*fatalFnc) PROTOARGs((char *msg)); -{ - CDFidMEMp mem = cdfidHeadP; - union { - CDFid id; - Int32 i[2]; - } u; - u.i[0] = u.i[1] = 0; - while (mem != NULL) { - u.id = mem->ptr; - if (u.i[0] == shortId || u.i[1] == shortId) return (CDFid) mem->ptr; - mem = mem->next; - } - return NULL; -} - -/****************************************************************************** -* cdfid_FreeMemory. -* If NULL is passed as the pointer to free, then free the entire list of -* allocated memory blocks. -******************************************************************************/ - -VISIBLE_PREFIX int cdfid_FreeMemory (ptr, fatalFnc) -void *ptr; -void (*fatalFnc) PROTOARGs((char *msg)); -{ - if (ptr == NULL) { - int count = 0; - CDFidMEMp mem = cdfidHeadP; - while (mem != NULL) { - CDFidMEMp memX = mem; - mem = mem->next; - FREESUCCESS("NULL",memX->ptr,8) - free (memX); - /* --numAlloc3; */ /* printf("(-1)numAlloc3=%ld\n",numAlloc3); */ - count++; - } - cdfidHeadP = NULL; - return count; - } - else { - CDFidMEMp mem = cdfidHeadP, memPrev = NULL; - while (mem != NULL) { - if (mem->ptr == ptr) { - CDFidMEMp memX = mem; - if (memPrev == NULL) - cdfidHeadP = mem->next; - else - memPrev->next = mem->next; - FREESUCCESS("one",memX->ptr,8) - free (memX); - /* --numAlloc3; */ /* printf("(-1)numAlloc3=%ld\n",numAlloc3); */ - return 1; - } - memPrev = mem; - mem = mem->next; - } - FREEFAILED(ptr) - if (fatalFnc != NULL) (*fatalFnc)("Unable to free memory buffer."); - return 0; - } -} - -/****************************************************************************** -* cdf_FreeMemoryX. -* If NULL is passed as the pointer to free, then free the entire list of -* allocated memory blocks. -******************************************************************************/ - -VISIBLE_PREFIX int cdf_FreeMemoryX (ptr, fatalFnc, loc) -void *ptr; -void (*fatalFnc) PROTOARGs((char *msg)); -int loc; -{ -#if defined(BUILDINGforIDL) - /* --numAlloc2; */ /* printf("(-1)numAlloc2=%ld\n",numAlloc2); */ - free (ptr); - return 1; -#else - /* --numAlloc2; */ /* printf("(-1)numAlloc2=%ld\n",numAlloc2); */ - if (ptr == NULL) { - int count = 0; - MEMp mem = memHeadP; - while (mem != NULL) { - MEMp memX = mem; - mem = mem->next; - FREESUCCESS("NULL",memX->ptr,memX->nBytes) - free (memX->ptr); - free (memX); - count++; - } - memHeadP = NULL; - return count; - } - else { - MEMp mem = memHeadP, memPrev = NULL; - while (mem != NULL) { - if (mem->ptr == ptr) { - MEMp memX = mem; - if (memPrev == NULL) - memHeadP = mem->next; - else - memPrev->next = mem->next; - FREESUCCESS("one",memX->ptr,memX->nBytes) - free (memX->ptr); - free (memX); - return 1; - } - memPrev = mem; - mem = mem->next; - } - FREEFAILED(ptr) - if (fatalFnc != NULL) { - char tmp[32+20+1]; - strcpy (tmp, "Unable to free memory buffer at "); - snprintf (EofS(tmp), (size_t) sizeof(tmp)-strlen(tmp), "%d", loc); - (*fatalFnc)(tmp); - } - return 0; - } -#endif -} - -/****************************************************************************** -* CallocateMemory. -* Using `calloc' might be more efficient on some platforms if the memory can -* be cleared faster than the loop used here. -******************************************************************************/ - -VISIBLE_PREFIX void *CallocateMemory (nObjects, objSize, fatalFnc) -size_t nObjects; -size_t objSize; -void (*fatalFnc) PROTOARGs((char *msg)); -{ -#if defined(BUILDINGforIDL) - return calloc(nObjects,objSize); -#else - size_t nBytes = nObjects * objSize; - void *ptr = cdf_AllocateMemory (nBytes, fatalFnc); - if (ptr != NULL) memset (ptr, 0, nBytes); - return ptr; -#endif -} - -/****************************************************************************** -* InitVMemory. -* NOTE: It is a mystery as to why values of `maxParagraphs' other than 128 -* (or near 128) cause allocation/loading failures (as well as other nasty -* things). Be a hero, solve the mystery... -******************************************************************************/ - -#if defined(MICROSOFTC_700) && INCLUDEvMEMORY -static Logical InitVMemory () { - uInt4 maxParagraphs = (uInt4) (vMemSize / 16); - if (!_vheapinit(0U,maxParagraphs,vMemMask)) return FALSE; - return TRUE; -} -#endif - -/****************************************************************************** -* TermVMemory. -******************************************************************************/ - -#if defined(MICROSOFTC_700) && INCLUDEvMEMORY -static void TermVMemory () { - _vheapterm(); -} -#endif - -/****************************************************************************** -* AllocateVMemory. -******************************************************************************/ - -#if defined(MICROSOFTC_700) && INCLUDEvMEMORY -STATICforIDL MemHandle AllocateVMemory (nBytes) -size_t nBytes; -{ - MemHandle handle; - static int first = TRUE; - if (first) { - first = FALSE; - if (!InitVMemory()) return NULL; - _fatexit (TermVMemory); - } - if ((handle = _vmalloc(nBytes)) == _VM_NULL) return NULL; - return handle; -} -#endif - -/****************************************************************************** -* LoadVMemory. -******************************************************************************/ - -#if defined(MICROSOFTC_700) && INCLUDEvMEMORY -STATICforIDL void *LoadVMemory (handle, writeFlag) -MemHandle handle; -Logical writeFlag; /* TRUE if virtual memory will be written to. */ -{ - void *buffer = _vload(handle,BOO(writeFlag,_VM_DIRTY,_VM_CLEAN)); - if (buffer == NULL) { - FreeVMemory (handle); - return NULL; - } - return buffer; -} -#endif - -/****************************************************************************** -* FreeVMemory. -******************************************************************************/ - -#if defined(MICROSOFTC_700) && INCLUDEvMEMORY -STATICforIDL int FreeVMemory (handle) -MemHandle handle; -{ - _vfree (handle); - return 1; -} -#endif - -/****************************************************************************** -* TotalBytes. -******************************************************************************/ - -#if MEMLOG -static uLongx TotalBytes (memHeadP) -MEMp memHeadP; -{ - MEMp mem = memHeadP; uLongx totalBytes = 0; - while (mem != NULL) { - totalBytes += (uLongx) mem->nBytes; - mem = mem->next; - } - return totalBytes; -} -#endif - - -/****************************************************************************** -* Display malloc/free counts. -******************************************************************************/ -/* -VISIBLE_PREFIX void ShowMemoryAllocCounts () -{ - printf("*** cdf_AllocateMemory/cdf_FreeMemory: %d\n cdfid_AllocateMemory/cdfid_FreeMemory: %d\n", - numAllocs,numAlloc3); -} -*/ - diff --git a/cdf36_3-dist/src/lib/cdfmisc1.c b/cdf36_3-dist/src/lib/cdfmisc1.c deleted file mode 100644 index 1002734..0000000 --- a/cdf36_3-dist/src/lib/cdfmisc1.c +++ /dev/null @@ -1,2294 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF library miscellaneous functions, part 1. -* -* Version 1.3e, 18-Nov-97, Hughes STX. -* -* Modification history: -* -* V1.0 19-Dec-94, J Love Original version. -* V1.0a 29-Dec-94, J Love WriteBuffer: increment buffer pointer in the -* case where the memory allocation failed. -* V1.1 13-Jan-95, J Love Encode/decode changes. More cache-residency. -* Allow all possible extensions on all machines. -* V1.1a 19-Jan-95, J Love IRIX 6.x (64-bit). -* V1.1b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.2 21-Mar-95, J Love POSIX. -* V1.2a 18-Apr-95, J Love More POSIX. MEMLOG_. -* V1.2b 19-Apr-95, J Love Memory functions moved to `cdfmem.c'. -* V1.2c 7-Sep-95, J Love Corrected status codes being returned. Try -* progressively smaller temporary buffers in -* `WriteVarElems'. -* V1.3 10-Sep-96, J Love CDF V2.6. -* V1.3a 21-Feb-97, J Love Removed RICE. -* V1.3b 28-Feb-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V1.3c 11-Sep-97, J Love Magic numbers are now uInt32. -* V1.3d 20-Oct-97, J Love Properly cast the uInt32 magic numbers. More -* Windows NT. -* V1.3e 18-Nov-97, J Love Even more Windows NT. -* V2.0 08/Apr-04, M liu Replaced VSTREAM.STATS with VSTREAM_STATS. -* V2.1 13-Oct-06, M Liu Changed to allow upper and lower case CDF -* name to be used on win32. -* V2.2 12-Aug-10, M Liu Ensured the filled file path name not overrun -* the defined string in BuildFilePath. -* V2.3 22-Aug-10, M Liu Modified NulPad to use memset to speed up the -* padding process. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" -#include "cdfrev.h" - -/****************************************************************************** -* CorrectV20eof. -******************************************************************************/ - -STATICforIDL CDFstatus CorrectV20eof (CDF) -struct CDFstruct *CDF; -{ - CDFstatus pStatus = CDF_OK; - Int32 eof = 0, size, vOffset, aOffset, eOffset, nAttrs, nEntries; - int varX, attrX, entryX; - /**************************************************************************** - * Check if CDR is last internal record. - ****************************************************************************/ - if (!sX(ReadCDR(CDF->fp,CDF->CDRoffset, - CDR_RECORDSIZE,&size, - CDR_NULL),&pStatus)) return pStatus; - eof = MaxInt32 (eof, CDF->CDRoffset + size); - /**************************************************************************** - * Check if GDR is last internal record. - ****************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_RECORDSIZE,&size, - GDR_NULL),&pStatus)) return pStatus; - eof = MaxInt32 (eof, CDF->GDRoffset + size); - /**************************************************************************** - * Scan through rVDRs checking if each is the last internal record. Note - * that V2.0 CDFs won't have zVDRs, VXRs, or VVRs. - ****************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_rVDRHEAD,&vOffset, - GDR_NULL),&pStatus)) return pStatus; - for (varX = 0; varX < CDF->NrVars; varX++) { - if (!sX(ReadVDR(CDF,CDF->fp,vOffset,FALSE, - VDR_RECORDSIZE,&size, - VDR_NULL),&pStatus)) return pStatus; - eof = MaxInt32 (eof, vOffset + size); - if (!sX(ReadVDR(CDF,CDF->fp,vOffset,FALSE, - VDR_VDRNEXT,&vOffset, - VDR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * Scan through the ADRs checking if each is the last internal record. - ****************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_NUMATTR,&nAttrs, - GDR_ADRHEAD,&aOffset, - GDR_NULL),&pStatus)) return pStatus; - for (attrX = 0; attrX < nAttrs; attrX++) { - if (!sX(ReadADR(CDF->fp,aOffset, - ADR_RECORDSIZE,&size, - ADR_NULL),&pStatus)) return pStatus; - eof = MaxInt32 (eof, aOffset + size); - /************************************************************************* - * Scan through the ArEDRs checking if each is the last internal record. - * Note that V2.0 CDFs won't have AzEDRs. - *************************************************************************/ - if (!sX(ReadADR(CDF->fp,aOffset, - ADR_AgrEDRHEAD,&eOffset, - ADR_NgrENTRIES,&nEntries, - ADR_NULL),&pStatus)) return pStatus; - for (entryX = 0; entryX < nEntries; entryX++) { - if (!sX(ReadAEDR(CDF->fp,eOffset, - AEDR_RECORDSIZE,&size, - AEDR_NULL),&pStatus)) return pStatus; - eof = MaxInt32 (eof, eOffset + size); - if (!sX(ReadAEDR(CDF->fp,eOffset, - AEDR_AEDRNEXT,&eOffset, - AEDR_NULL),&pStatus)) return pStatus; - } - if (!sX(ReadADR(CDF->fp,aOffset, - ADR_ADRNEXT,&aOffset, - ADR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * Save correct EOF and return. - ****************************************************************************/ - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CorrectV20offsets. -******************************************************************************/ - -STATICforIDL CDFstatus CorrectV20offsets (CDF) -struct CDFstruct *CDF; -{ - CDFstatus pStatus = CDF_OK; - Int32 zero = 0, size, vOffset, aOffset, eOffset, nAttrs, nEntries; - int varX, attrX, entryX; - /**************************************************************************** - * Scan through rVDRs fixing the next VDR field of the last one (setting it - * to an offset of zero). Note that V2.0 CDFs won't have zVDRs, VXRs, or - * VVRs. - ****************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_rVDRHEAD,&vOffset, - GDR_NULL),&pStatus)) return pStatus; - for (varX = 0; varX < CDF->NrVars; varX++) { - if (!sX(ReadVDR(CDF,CDF->fp,vOffset,FALSE, - VDR_RECORDSIZE,&size, - VDR_NULL),&pStatus)) return pStatus; - if (varX == CDF->NrVars - 1) { - if (!sX(WriteVDR(CDF,CDF->fp,vOffset,FALSE, - VDR_VDRNEXT,&zero, - VDR_NULL),&pStatus)) return pStatus; - } - else { - if (!sX(ReadVDR(CDF,CDF->fp,vOffset,FALSE, - VDR_VDRNEXT,&vOffset, - VDR_NULL),&pStatus)) return pStatus; - } - } - /**************************************************************************** - * Scan through the ADRs fixing the next ADR field of the last one (setting - * it to an offset of zero). - ****************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_NUMATTR,&nAttrs, - GDR_ADRHEAD,&aOffset, - GDR_NULL),&pStatus)) return pStatus; - for (attrX = 0; attrX < nAttrs; attrX++) { - if (!sX(ReadADR(CDF->fp,aOffset, - ADR_RECORDSIZE,&size, - ADR_NULL),&pStatus)) return pStatus; - /************************************************************************* - * Scan through the ArEDRs fixing the next ArEDR field of the last one - * (setting it to an offset of zero). Note that V2.0 CDFs won't have - * AzEDRs. - *************************************************************************/ - if (!sX(ReadADR(CDF->fp,aOffset, - ADR_AgrEDRHEAD,&eOffset, - ADR_NgrENTRIES,&nEntries, - ADR_NULL),&pStatus)) return pStatus; - for (entryX = 0; entryX < nEntries; entryX++) { - if (!sX(ReadAEDR(CDF->fp,eOffset, - AEDR_RECORDSIZE,&size, - AEDR_NULL),&pStatus)) return pStatus; - if (entryX == nEntries - 1) { - if (!sX(WriteAEDR(CDF,CDF->fp,eOffset, - AEDR_AEDRNEXT,&zero, - AEDR_NULL),&pStatus)) return pStatus; - } - else { - if (!sX(ReadAEDR(CDF->fp,eOffset, - AEDR_AEDRNEXT,&eOffset, - AEDR_NULL),&pStatus)) return pStatus; - } - } - if (attrX == nAttrs - 1) { - if (!sX(WriteADR(CDF->fp,aOffset, - ADR_ADRNEXT,&zero, - ADR_NULL),&pStatus)) return pStatus; - } - else { - if (!sX(ReadADR(CDF->fp,aOffset, - ADR_ADRNEXT,&aOffset, - ADR_NULL),&pStatus)) return pStatus; - } - } - return pStatus; -} - -/****************************************************************************** -* UpdateDotCDF. -* If this routine is called when aborting a CDF, we cannot assume that -* the CDF structure is complete - it may have been only partially initialized -* when the CDF was aborted. If it is called to save the CDF without closing -* it, the data will be properly preserved. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus UpdateDotCDF (CDF) -struct CDFstruct *CDF; -{ - CDFstatus pStatus = CDF_OK; int varN; struct VarStruct *Var; Logical zVar; - /************************************************************************** - * Update r/zVariables depending on the variable type... - **************************************************************************/ - for (zVar = 0; zVar <= 1; zVar++) { - if (BOO(zVar,CDF->zVars,CDF->rVars) != NULL) { - Int32 nVars = BOO(zVar,CDF->NzVars,CDF->NrVars); - for (varN = 0; varN < nVars; varN++) { - Var = BOO(zVar,CDF->zVars[varN],CDF->rVars[varN]); - if (Var != NULL) { - switch (Var->vType) { - case SPARSE_RECORDS_: { - if (!sX(FlushStage(CDF,Var),&pStatus)) break; - /* No `break' is intentional. */ - case STANDARD_: - if (Var->maxWritten < Var->maxAllocated) { - Int32 padFrom = Var->maxWritten + 1; - if (!sX(PadUnRecords(CDF,Var,padFrom, - Var->maxAllocated),&pStatus)) break; - Var->maxWritten = Var->maxAllocated; - } - break; - } - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - if (!sX(FlushStage(CDF,Var),&pStatus)) break; - break; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - sX (UNKNOWN_SPARSENESS, &pStatus); - break; - case IN_MULTI_: - break; - default: - sX (CDF_INTERNAL_ERROR, &pStatus); - break; - } - } - } - } - } - return pStatus; -} - -/****************************************************************************** -* CloseVarFiles. -* -* Close the open variable files of the specified CDF. This routine closes all -* of the open variable files regardless of the number of errors detected. -* -* Because this routine is called when aborting a CDF, we cannot assume -* that the CDF structure is complete. Eg., it may have been only partially -* initialized when the CDF was aborted. -******************************************************************************/ - -STATICforIDL CDFstatus CloseVarFiles (CDF) -struct CDFstruct *CDF; -{ - CDFstatus pStatus = CDF_OK; struct VarStruct *Var; int varN; - /**************************************************************************** - * If a multi-file CDF, close the variable files. - ****************************************************************************/ - if (!CDF->singleFile) { - /************************************************************************** - * Close rVariable files. If the pointer to the rVariable is NULL, then - * the rVariable has yet to be initialized (and is obviously closed). - **************************************************************************/ - if (CDF->rVars != NULL) { - for (varN = 0; varN < CDF->NrVars; varN++) { - Var = CDF->rVars[varN]; - if (Var != NULL) { - if (Var->fp != NULL) { - if (!CLOSEv(Var->fp,NULL,NULL)) sX (VAR_CLOSE_ERROR, &pStatus); - Var->fp = NULL; - } - } - } - } - /************************************************************************** - * Close zVariable files. If the pointer to the zVariable is NULL, then - * the zVariable has yet to be initialized (and is obviously closed). - **************************************************************************/ - if (CDF->zVars != NULL) { - for (varN = 0; varN < CDF->NzVars; varN++) { - Var = CDF->zVars[varN]; - if (Var != NULL) { - if (Var->fp != NULL) { - if (!CLOSEv(Var->fp,NULL,NULL)) sX (VAR_CLOSE_ERROR, &pStatus); - Var->fp = NULL; - } - } - } - } - } - return pStatus; -} - -/****************************************************************************** -* WriteAccess. -* Close and then reopen a CDF for read/write access (it was opened with -* read-only access initially). If the CDF is earlier than CDF V2.5, then -* some of the fields will have to be fixed and the CDR will be truncated for -* a shorter copyright length (unless the CDF is being deleted in which case -* it would be a waste of time to do these things). -******************************************************************************/ - -STATICforIDL Logical WriteAccess (CDF, forDelete, pStatus) -struct CDFstruct *CDF; -Logical forDelete; /* Is the write access is needed to delete the CDF? */ -CDFstatus *pStatus; /* Returned status. */ -{ -#if BUILD_READ_ONLY_DISTRIBUTION - *pStatus = READ_ONLY_DISTRIBUTION; - return FALSE; -#else - char pathName[DU_MAX_PATH_LEN+1]; vSTATS vStats; - /*************************************************************************** - * Check if write access already. - ***************************************************************************/ - if (CDF->status == READ_WRITE) return TRUE; - /*************************************************************************** - * Check if this CDF is in read-only mode. - ***************************************************************************/ - if (CDF->readOnly) { - *pStatus = READ_ONLY_MODE; - return FALSE; - } - /*************************************************************************** - * Close (the possibly compressed) dotCDF file and the variable files (if - * a multi-file CDF). An uncompressed dotCDF file and any scratch files - * stay open. - ***************************************************************************/ - if (!CLOSEv(CDF->dotFp,NULL,&vStats)) { - CDF->dotFp = NULL; - AbortAccess (CDF, noUPDATE, noDELETE); - return FALSE; - } - CDF->dotFp = NULL; - AddTOvStats (&CDF->dotCDFvStats, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "DotCDF..", &vStats); -#endif - if (!sX(CloseVarFiles(CDF),pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - return FALSE; - } - /*************************************************************************** - * Open dotCDF file with read-write access. If read-write access is not - * allowed, try to return to read-only access. If reopening with read-only - * access fails, free CDF structures as if CDF had been closed. - ***************************************************************************/ - BuildFilePath (CDFt, CDF->CDFname, CDF->no_append, CDF->upper_case_ext, - CDF->version_numbers, 0L, pathName); - CDF->dotFp = V_open (pathName, READ_PLUS_a_mode); - if (CDF->dotFp == NULL) { - CDF->dotFp = V_open (pathName, READ_ONLY_a_mode); - if (CDF->dotFp == NULL) { - AbortAccess (CDF, noUPDATE, noDELETE); - *pStatus = CDF_OPEN_ERROR; - return FALSE; - } - else { - CDF->status = READ_ONLY; - *pStatus = NO_WRITE_ACCESS; /* Don't return yet. */ - } - } - else - CDF->status = READ_WRITE; - /*************************************************************************** - * If the CDF is not compressed, reassign the "working" file pointer and - * reset the cache size (unless deleting). If the CDF is compressed, the - * cache size of the "working" file pointer does not have to be reset. - ***************************************************************************/ - if (CDF->uDotFp == NULL) { - CDF->fp = CDF->dotFp; - if (!forDelete) { - if (!CACHEv(CDF->fp,CDF->workingCacheSize)) { - *pStatus = BAD_CACHE_SIZE; - AbortAccess (CDF, noUPDATE, noDELETE); - return FALSE; - } - } - } - /*************************************************************************** - * Fix various fields (if write access was obtained) unless write access - * was needed to delete the CDF. - ***************************************************************************/ - if (CDF->status == READ_WRITE && !forDelete) { - Int32 versionNew = CDF_LIBRARY_VERSION, - releaseNew = CDF_LIBRARY_RELEASE, - incrementNew = CDF_LIBRARY_INCREMENT; - uInt32 magicNumber1 = V2magicNUMBER_1, - magicNumber2 = V2magicNUMBER_2u; - char copyRight[CDF_COPYRIGHT_LEN+1]; - /************************************************************************* - * Update magic numbers. - *************************************************************************/ - if (!SEEKv(CDF->fp,(long)V2_MAGIC_OFFSET_1,vSEEK_SET)) { - AbortAccess (CDF, noUPDATE, noDELETE); - *pStatus = CDF_WRITE_ERROR; - return FALSE; - } - if (!Write32(CDF->fp,(Int32 *)&magicNumber1)) { - AbortAccess (CDF, noUPDATE, noDELETE); - *pStatus = CDF_WRITE_ERROR; - return FALSE; - } - if (!Write32(CDF->fp,(Int32 *)&magicNumber2)) { - AbortAccess (CDF, noUPDATE, noDELETE); - *pStatus = CDF_WRITE_ERROR; - return FALSE; - } - /************************************************************************* - * If a V2.0 CDF, correct the EOF field. - *************************************************************************/ - if (CDF->badEOF) { - if (!sX(CorrectV20eof(CDF),pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - return FALSE; - } - CDF->badEOF = FALSE; - } - /************************************************************************* - * If a V2.0 CDF, correct the terminating offset fields. NOTE: Fix these - * fields before the other "fixing" routines (which may depend on these - * fields). - *************************************************************************/ - if (CDF->badTerminatingOffsets) { - if (!sX(CorrectV20offsets(CDF),pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - return FALSE; - } - CDF->badTerminatingOffsets = FALSE; - } - /************************************************************************* - * If prior to CDF V2.1.1, then change the data type associated with the - * "EPOCH" rVariable/rEntries to CDF_EPOCH. - *************************************************************************/ - if (CDF->fakeEPOCH) { - if (!sX(CorrectEPOCH(CDF),pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - return FALSE; - } - CDF->fakeEPOCH = FALSE; - } - /************************************************************************* - * If prior to CDF V2.5, then truncate the CDR for a shorter copyright - * field and shorten each VDR to reclaim the wasted space. - *************************************************************************/ - if (CDF->wastedSpace) { - if (!sX(ShortenCDR(CDF),pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - return FALSE; - } - if (!sX(ShortenVDRs(CDF),pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - return FALSE; - } - CDF->wastedSpace = FALSE; - } - /************************************************************************* - * If prior to CDF V2.5, then convert all assumed scopes to definite - * scopes. - *************************************************************************/ - if (CDF->assumedScopes) { - if (!sX(CorrectScopes(CDF),pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - return FALSE; - } - CDF->assumedScopes = FALSE; - } - /************************************************************************* - * Fix blocking factors for variables having a recVary of NOVARY. - *************************************************************************/ - if (!sX(CorrectBlockingFactors(CDF),pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - return FALSE; - } - /************************************************************************* - * Update version/release/increment - should never happen as for older - * versioned (V2.7 and older) CDFs, we want to keep its original data - * structure. - *************************************************************************/ - if (isLFS(CDF)) { /* It should be false all the time. */ - if (!sX(WriteCDR(CDF->fp,V2_CDR_OFFSET, - CDR_VERSION,&versionNew, - CDR_RELEASE,&releaseNew, - CDR_INCREMENT,&incrementNew, - CDR_NULL),pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - return FALSE; - } - } - /************************************************************************* - * Update copyright. - *************************************************************************/ - CDFcopyRight (copyRight); - NulPad (copyRight, CDF_COPYRIGHT_LEN); - if (!sX(WriteCDR(CDF->fp,V2_CDR_OFFSET, - CDR_COPYRIGHT,copyRight, - CDR_NULL),pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - return FALSE; - } - } - /*************************************************************************** - * Return based on whether or not write access was obtained. - ***************************************************************************/ - return (CDF->status == READ_WRITE); -#endif -} - -/****************************************************************************** -* WriteBuffer. -* Write occurs at current offset (assumed to have been set before this -* routine is called). On IBM PCs, it is assumed that `nBytes' will not -* exceed 65535. -******************************************************************************/ - -STATICforIDL CDFstatus WriteBuffer (CDF, fp, dataType, numElems, buffer) -struct CDFstruct *CDF; -vFILE *fp; -Int32 dataType; -Int32 numElems; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; - size_t nElemBytes = (size_t) CDFelemSize(dataType); - size_t nBytes = (size_t) (numElems * nElemBytes); - double eValue; Int32 elemN; Byte1 *ptr; void *tBuffer; - /**************************************************************************** - * Try to encode/write entire buffer. - ****************************************************************************/ - tBuffer = cdf_AllocateMemory (nBytes, NULL); - if (tBuffer != NULL) { - if (!sX(ConvertBuffer(HostEncoding(),CDF->encoding,CDF->negToPosFp0, - dataType,numElems,buffer,tBuffer),&pStatus)) { - cdf_FreeMemory (tBuffer, NULL); - return pStatus; - } - if (!WRITEv(tBuffer,1,nBytes,fp)) { - cdf_FreeMemory (tBuffer, NULL); - return CDF_WRITE_ERROR; - } - cdf_FreeMemory (tBuffer, NULL); - return pStatus; - } - /**************************************************************************** - * If that failed, encode/write one element at a time. - ****************************************************************************/ - for (elemN = 0, ptr = buffer; elemN < numElems; elemN++, ptr += nElemBytes) { - if (!sX(ConvertBuffer(HostEncoding(),CDF->encoding, - CDF->negToPosFp0,dataType,1L,ptr, - &eValue),&pStatus)) return pStatus; - if (!WRITEv(&eValue,1,nElemBytes,fp)) return CDF_WRITE_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* NegativeZeroReal4. -* Checks for -0.0 (on any type computer). Assumed to be in host encoding. -******************************************************************************/ - -VISIBLE_PREFIX Logical NegativeZeroReal4 (value) -float *value; -{ -#if defined(FP1cpu) || defined(FP2cpu) - return (*((uInt32 *) value) == (uInt32) 0x80000000); -#endif -#if defined(FP3cpu) || defined(FP4cpu) - /**************************************************************************** - * On VAXes and DEC Alphas running OpenVMS/POSIXshell we're only interested - * in the sign bit and exponent. - ****************************************************************************/ - return ((*((uInt32 *) value) & (uInt32) 0x0000FF80) == (uInt32) 0x00008000); -#endif -} - -/****************************************************************************** -* NegativeZeroReal8. -* Checks for -0.0 (on any type computer). Assumed to be in host encoding. -******************************************************************************/ - -VISIBLE_PREFIX Logical NegativeZeroReal8 (value) -double *value; -{ -#if defined(FP1cpu) - return ((*((uInt32 *) value) == (uInt32) 0x80000000) && - (*((uInt32 *) value+1) == (uInt32) 0x00000000)); -#endif -#if defined(FP2cpu) - return ((*((uInt32 *) value) == (uInt32) 0x00000000) && - (*((uInt32 *) value+1) == (uInt32) 0x80000000)); -#endif -#if defined(FP3cpu) - /**************************************************************************** - * On VAXes and DEC Alphas running OpenVMS/POSIXshell in D_FLOAT mode we're - * only interested in the sign bit and exponent (which are in the first - * longword [32-bit]). - ****************************************************************************/ - return ((*((uInt32 *) value) & (uInt32) 0x0000FF80) == (uInt32) 0x00008000); -#endif -#if defined(FP4cpu) - /**************************************************************************** - * On DEC Alphas running OpenVMS/POSIXshell in G_FLOAT mode we're only - * interested in the sign bit and exponent (which are in the first longword - * [32-bit]). - ****************************************************************************/ - return ((*((uInt32 *) value) & (uInt32) 0x0000FFF0) == (uInt32) 0x00008000); -#endif -} - -/****************************************************************************** -* StripTrailingBlanks. -******************************************************************************/ - -STATICforIDL void StripTrailingBlanks (string) -char *string; -{ - int i; - for (i = strlen(string) - 1; i >= 0 && string[i] == ' '; i--) { - string[i] = NUL; - } - return; -} - -/****************************************************************************** -* MakeUpperString. -* Convert string to upper-case. -******************************************************************************/ - -VISIBLE_PREFIX void MakeUpperString (string) -char *string; -{ - int i; - for (i = 0; string[i] != NUL; i++) { - string[i] = (char) MakeUpper((int)string[i]); - } - return; -} - -/****************************************************************************** -* MakeLowerString. -* Convert string to lower-case. -******************************************************************************/ - -VISIBLE_PREFIX void MakeLowerString (string) -char *string; -{ - int i; - for (i = 0; string[i] != NUL; i++) { - string[i] = (char) MakeLower((int)string[i]); - } - return; -} - -/****************************************************************************** -* SetBit32. -******************************************************************************/ - -STATICforIDL void SetBit32 (value, bit) -Int32 *value; -int bit; -{ - *value = *value | (1 << bit); - return; -} - -/****************************************************************************** -* ClearBit32. -******************************************************************************/ - -STATICforIDL void ClearBit32 (value, bit) -Int32 *value; -int bit; -{ - *value = *value & ~(1 << bit); - return; -} - -/****************************************************************************** -* FindCDF. -* Tries various extensions on the specified CDF path to see if the CDF -* exists. The extensions tried are those which should be present on the -* various platforms plus the extensions which might be generated by a CD-ROM -* driver. Finally, the pathname is tried without an extension being added -* in case the CDF had been renamed with a different extension or no extension. -******************************************************************************/ - -STATICforIDL CDFstatus FindCDF (path, no_append, upper, version) -char *path; /* Base pathname. */ -Logical *no_append; /* Should extensions/version numbers be appended? */ -Logical *upper; /* Should extensions be upper case? */ -Logical *version; /* Should a version number of `;1' be appended? */ -{ - char pathT[DU_MAX_PATH_LEN+1]; - size_t pathLen; - - pathLen = strlen (path); - - strcpyX (pathT, path, DU_MAX_PATH_LEN); - if (pathLen < 4 || strcmp(pathT+(pathLen-4), ".cdf") != 0) - strcatX (pathT, ".cdf", DU_MAX_PATH_LEN); - if (IsReg(pathT)) { - *no_append = FALSE; - *upper = FALSE; - *version = FALSE; - return CDF_OK; - } - - strcpyX (pathT, path, DU_MAX_PATH_LEN); - if (pathLen < 4 || strcmp(pathT+(pathLen-4), ".CDF") != 0) - strcatX (pathT, ".CDF", DU_MAX_PATH_LEN); - if (IsReg(pathT)) { - *no_append = FALSE; - *upper = TRUE; - *version = FALSE; - return CDF_OK; - } - - strcpyX (pathT, path, DU_MAX_PATH_LEN); - if (pathLen < 6 || !StrStrIgCaseX(pathT+(pathLen-6), ".cdf;1")) - strcatX (pathT, ".cdf;1", DU_MAX_PATH_LEN); - if (IsReg(pathT)) { - *no_append = FALSE; - *upper = FALSE; - *version = TRUE; - return CDF_OK; - } - - strcpyX (pathT, path, DU_MAX_PATH_LEN); - if (pathLen < 6 || !StrStrIgCaseX(pathT+(pathLen-6), ".CDF;1")) - strcatX (pathT, ".CDF;1", DU_MAX_PATH_LEN); - if (IsReg(pathT)) { - *no_append = FALSE; - *upper = TRUE; - *version = TRUE; - return CDF_OK; - } - -/* -#if defined(unix) || defined(dos) || defined(win32) -*/ -#if defined(win32) || defined(dos) - strcpyX (pathT, path, DU_MAX_PATH_LEN); - MakeUpperString (pathT); - if (pathLen < 4 || !StrStrIgCaseX(pathT+(pathLen-4), ".CDF")) - strcatX (pathT, ".CDF", DU_MAX_PATH_LEN); - if (IsReg(pathT)) { - *no_append = FALSE; - *upper = TRUE; - *version = FALSE; - return CDF_OK; - } -/* - strcpyX (pathT, path, DU_MAX_PATH_LEN); - MakeUpperString (pathT); - if (IsReg(pathT)) { - *no_append = TRUE; - *upper = TRUE; - *version = FALSE; - return CDF_OK; - } -*/ -#endif - - if (IsReg(path)) { - *no_append = TRUE; - *upper = FALSE; - *version = FALSE; - return CDF_OK; - } - - return NO_SUCH_CDF; -} - -/****************************************************************************** -* BuildFilePath. -******************************************************************************/ - -STATICforIDL void BuildFilePath (fileType, pathBase, noAppend, upperCase, - versionNumber, varN, pathX) -int fileType; /* Type of file. */ -char *pathBase; /* Base pathname. */ -Logical noAppend; /* Should extensions/version numbers be appended? */ -Logical upperCase; /* Should uppercase extensions be appended? */ -Logical versionNumber; /* Should a version number of `;1' be appended? */ -Int32 varN; /* Variable number. N/a if a `cdf' file. */ -char pathX[DU_MAX_PATH_LEN+1]; - /* The expanded path w/ extensions/version numbers. */ -{ - ExpandPath (pathBase, pathX); - if (!noAppend) { - switch (fileType) { - case CDFt: - strcatX (pathX, (upperCase ? ".CDF" : ".cdf"), DU_MAX_PATH_LEN); - break; - case Vt: - strcatX (pathX, (upperCase ? ".V" : ".v"), DU_MAX_PATH_LEN); - snprintf (EofS(pathX), (size_t) DU_MAX_PATH_LEN+1-strlen(pathX), - "%d", (int) varN); - break; - case Zt: - strcatX (pathX, (upperCase ? ".Z" : ".z"), DU_MAX_PATH_LEN); - snprintf (EofS(pathX), (size_t) DU_MAX_PATH_LEN+1-strlen(pathX), - "%d", (int) varN); - break; - } - strcatX (pathX, (versionNumber ? ";1" : ""), DU_MAX_PATH_LEN); - } - return; -} - -/****************************************************************************** -* NulPad. -* Pads with NUL characters to the length specified. Also NUL-terminates -* the string. -******************************************************************************/ - -STATICforIDL void NulPad (string, length) -char *string; -int length; -{ - int i; - int j; -/* - for (i = (int) strlen(string); i < length; i++) string[i] = NUL; - string[length] = NUL; -*/ - j = (int) strlen(string); - i = length - j; - if (i > 0) - memset(string+j, '\0', i+1); - return; -} - -/****************************************************************************** -* UpdateMaxRec. -******************************************************************************/ - -STATICforIDL CDFstatus UpdateMaxRec (CDF, Var, recNum) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -struct VarStruct *Var; /* In: Pointer to variable. */ -Int32 recNum; /* In: Possible new maximum record number. */ -{ - CDFstatus pStatus = CDF_OK; - if (recNum > Var->maxRec) { - Var->maxRec = recNum; - if (!sX(WriteVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_MAXREC,&recNum, - VDR_NULL),&pStatus)) return pStatus; - } - if (!Var->zVar) { - if (recNum > CDF->rMaxRec) { - CDF->rMaxRec = recNum; - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - GDR_rMAXREC,&recNum, - GDR_NULL),&pStatus)) return pStatus; - } - } - return pStatus; -} - -/****************************************************************************** -* CalcDimParms. -* Calculates a variable's number of dimensions, dimension sizes, and -* dimension variances depending on the current zMode. -******************************************************************************/ - -STATICforIDL CDFstatus CalcDimParms (CDF, offset, zVar, numDimsP, dimSizesP, - dimVarysP) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -Int32 offset; /* In: Offset of VDR. */ -Logical zVar; /* In: TRUE if a true zVariable. FALSE if a - true rVariable. */ -Int32 *numDimsP; /* Out: Number of dimensions. */ -Int32 dimSizesP[]; /* Out: Dimension sizes. */ -Int32 dimVarysP[]; /* Out: Dimension variances. */ -{ - CDFstatus pStatus = CDF_OK; int dN; - Int32 tNumDims, tDimSizes[CDF_MAX_DIMS], tDimVarys[CDF_MAX_DIMS]; - Int32 numDims, dimSizes[CDF_MAX_DIMS], dimVarys[CDF_MAX_DIMS]; - /**************************************************************************** - * Determine `true' parameters. - ****************************************************************************/ - if (zVar) { - if (!sX(ReadVDR(CDF,CDF->fp,offset,TRUE, - VDR_zNUMDIMS,&tNumDims, - VDR_zDIMSIZES,tDimSizes, - VDR_DIMVARYS,tDimVarys, - VDR_NULL),&pStatus)) return pStatus; - } - else { - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_rNUMDIMS,&tNumDims, - GDR_rDIMSIZES,tDimSizes, - GDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadVDR(CDF,CDF->fp,offset,FALSE, - VDR_DIMVARYS,tDimVarys, - VDR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * Determine parameters based on zMode and if r/zVariable. - ****************************************************************************/ - if (CDF->zMode == zMODEon2 && !zVar) { - for (dN = 0, numDims = 0; dN < tNumDims; dN++) { - if (tDimVarys[dN]) { - dimSizes[(int)numDims] = tDimSizes[dN]; - dimVarys[(int)numDims] = VARY; - numDims++; - } - } - } - else { - numDims = tNumDims; - for (dN = 0; dN < tNumDims; dN++) { - dimSizes[dN] = tDimSizes[dN]; - dimVarys[dN] = tDimVarys[dN]; - } - } - /**************************************************************************** - * Assign those values requested. - ****************************************************************************/ - ASSIGNnotNULL (numDimsP, numDims) - ASSIGNnotNULLarray (dimSizesP, numDims, dimSizes) - ASSIGNnotNULLarray (dimVarysP, numDims, dimVarys) - return pStatus; -} - -/****************************************************************************** -* NULterminateMAX. -* NUL-terminate a string but only if a NUL is not found before the maximum -* length is reached. -******************************************************************************/ - -VISIBLE_PREFIX void NULterminateMAX (string, maxLen) -char *string; -size_t maxLen; -{ - int i; - for (i = 0; i < (int) maxLen; i++) - if (string[i] == NUL) return; - string[maxLen] = NUL; - return; -} - -/****************************************************************************** -* ClearBytes. -******************************************************************************/ - -VISIBLE_PREFIX void ClearBytes (buffer, firstByte, lastByte) -void *buffer; -int firstByte; -int lastByte; -{ - memset ((Byte1 *)buffer+firstByte, 0, (size_t) (lastByte - firstByte + 1)); - return; -} - -/****************************************************************************** -* WasteIR. -******************************************************************************/ - -STATICforIDL CDFstatus WasteIR (CDF, wasteOffset, size) -struct CDFstruct *CDF; -Int32 wasteOffset; -Int32 size; -{ - CDFstatus pStatus = CDF_OK; - struct UIRstruct newUIR, firstUIR, tUIR, nextUIR; - Int32 tOffset, nextOffset, UIRhead; - - /**************************************************************************** - * Begin initializing UIR. - ****************************************************************************/ - newUIR.RecordSize = size; - newUIR.RecordType = UIR_; - /**************************************************************************** - * Check that the internal record being wasted is big enough for the `next' - * and `previous' fields. If not, mark it as wasted but don't place it in - * the linked list of UIRs. Note that there will always be enough room for - * the `size' and `type' fields. If not, an internal logic error has occured. - ****************************************************************************/ - if (size < UIR_BASE_SIZE) { - if (size < UUIR_BASE_SIZE) return CDF_INTERNAL_ERROR; - if (!sX(WriteUIR(CDF->fp,wasteOffset, - UIR_RECORDSIZE,&(newUIR.RecordSize), - UIR_RECORDTYPE,&(newUIR.RecordType), - UIR_NULL),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * Read offset of first UIR. - ****************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_UIRHEAD,&UIRhead, - GDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * Check if no UIRs exist yet. - ****************************************************************************/ - if (UIRhead == 0) { - newUIR.NextUIR = 0; - newUIR.PrevUIR = 0; - if (!sX(WriteUIR(CDF->fp,wasteOffset, - UIR_RECORD,&newUIR, - UIR_NULL),&pStatus)) return pStatus; - UIRhead = wasteOffset; - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - GDR_UIRHEAD,&UIRhead, - GDR_NULL),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * At least one UIR exists, check if the new UIR is before the first UIR. - ****************************************************************************/ - if (wasteOffset < UIRhead) { - if (!sX(ReadUIR(CDF->fp,UIRhead, - UIR_RECORD,&firstUIR, - UIR_NULL),&pStatus)) return pStatus; - newUIR.NextUIR = UIRhead; - newUIR.PrevUIR = 0; - if (!sX(WriteUIR(CDF->fp,wasteOffset, - UIR_RECORD,&newUIR, - UIR_NULL),&pStatus)) return pStatus; - firstUIR.PrevUIR = wasteOffset; - if (!sX(WriteUIR(CDF->fp,UIRhead, - UIR_RECORD,&firstUIR, - UIR_NULL),&pStatus)) return pStatus; - UIRhead = wasteOffset; - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - GDR_UIRHEAD,&UIRhead, - GDR_NULL),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * The new UIR is not before the first UIR. Scan the UIRs to find the point - * at which it should be inserted. - ****************************************************************************/ - tOffset = UIRhead; - if (!sX(ReadUIR(CDF->fp,tOffset, - UIR_RECORD,&tUIR, - UIR_NULL),&pStatus)) return pStatus; - while (tUIR.NextUIR != 0) { - if (wasteOffset < tUIR.NextUIR) { - nextOffset = tUIR.NextUIR; - if (!sX(ReadUIR(CDF->fp,nextOffset, - UIR_RECORD,&nextUIR, - UIR_NULL),&pStatus)) return pStatus; - newUIR.NextUIR = tUIR.NextUIR; - newUIR.PrevUIR = tOffset; - if (!sX(WriteUIR(CDF->fp,wasteOffset, - UIR_RECORD,&newUIR, - UIR_NULL),&pStatus)) return pStatus; - tUIR.NextUIR = wasteOffset; - if (!sX(WriteUIR(CDF->fp,tOffset, - UIR_RECORD,&tUIR, - UIR_NULL),&pStatus)) return pStatus; - nextUIR.PrevUIR = wasteOffset; - if (!sX(WriteUIR(CDF->fp,nextOffset, - UIR_RECORD,&nextUIR, - UIR_NULL),&pStatus)) return pStatus; - return pStatus; - } - tOffset = tUIR.NextUIR; - if (!sX(ReadUIR(CDF->fp,tOffset, - UIR_RECORD,&tUIR, - UIR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * The new UIR is going to be the last UIR. - ****************************************************************************/ - newUIR.NextUIR = 0; - newUIR.PrevUIR = tOffset; - if (!sX(WriteUIR(CDF->fp,wasteOffset, - UIR_RECORD,&newUIR, - UIR_NULL),&pStatus)) return pStatus; - tUIR.NextUIR = wasteOffset; - if (!sX(WriteUIR(CDF->fp,tOffset, - UIR_RECORD,&tUIR, - UIR_NULL),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* AllocateIR. -******************************************************************************/ - -STATICforIDL CDFstatus AllocateIR (CDF, size, offset) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -Int32 size; /* In: Size of internal record (bytes). */ -Int32 *offset; /* Out: Offset of allocated internal record. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 sOffset, eOffset, tSize, UIRhead, eof, uir_ = UIR_; - struct UIRstruct sUIR, eUIR; - /**************************************************************************** - * Read EOF and offset of first UIR from GDR. - ****************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_UIRHEAD,&UIRhead, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * If UIRs exist, try to use one or more of them (if contiguous) for the new - * internal record. - ****************************************************************************/ - if (UIRhead != 0) { - sOffset = UIRhead; - if (!sX(ReadUIR(CDF->fp,sOffset, - UIR_RECORD,&sUIR, - UIR_NULL),&pStatus)) return pStatus; - eOffset = sOffset; - eUIR = sUIR; - tSize = sUIR.RecordSize; - for (;;) { - /*********************************************************************** - * Check if the starting to ending UIRs are the exact size needed. - ***********************************************************************/ - if (size == tSize) { - if (!sX(RemoveUIRs(CDF,sOffset,eOffset),&pStatus)) return pStatus; - if (!sX(WriteIrSize(CDF->fp,sOffset,&size),&pStatus)) return pStatus; - if (!sX(WriteIrType(CDF->fp,sOffset,&uir_),&pStatus)) return pStatus; - *offset = sOffset; - return pStatus; - } - /*********************************************************************** - * Check if the starting to ending UIRs are big enough for the new - * internal record and for a new UIR to fill the remaining space. - ***********************************************************************/ - if (size + UIR_BASE_SIZE <= tSize) { - if (!sX(RemoveUIRs(CDF,sOffset,eOffset),&pStatus)) return pStatus; - if (!sX(WasteIR(CDF,sOffset+size,tSize-size),&pStatus)) { - return pStatus; - } - if (!sX(WriteIrSize(CDF->fp,sOffset,&size),&pStatus)) return pStatus; - if (!sX(WriteIrType(CDF->fp,sOffset,&uir_),&pStatus)) return pStatus; - *offset = sOffset; - return pStatus; - } - /*********************************************************************** - * Check if the end of the UIRs has been reached. If so, check if the - * ending UIR is the last IR in the dotCDF file. - ***********************************************************************/ - if (eUIR.NextUIR == 0) { - if (eOffset + eUIR.RecordSize == eof) { - /******************************************************************* - * The ending UIR is the last internal record in the CDF. Check to - * see if after allocating the new internal record less than - * UIR_BASE_SIZE bytes will remain before the EOF. If so, waste an - * internal record at the location of those bytes so that a UIR is - * at the end (rather than stranded bytes). - *******************************************************************/ - if (!sX(RemoveUIRs(CDF,sOffset,eOffset),&pStatus)) return pStatus; - if (size < tSize) { - if (!sX(WasteIR(CDF,sOffset+size, - UIR_BASE_SIZE),&pStatus)) return pStatus; - eof = sOffset + size + UIR_BASE_SIZE; - } - else - eof = sOffset + size; - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - if (!sX(WriteIrSize(CDF->fp, - sOffset, - &size),&pStatus)) return pStatus; - if (!sX(WriteIrType(CDF->fp, - sOffset, - &uir_),&pStatus)) return pStatus; - *offset = sOffset; - return pStatus; - } - else { - /******************************************************************* - * Non-UIRs follow the ending UIR. The new internal record will - * have to be allocated at the EOF. - *******************************************************************/ - *offset = eof; - if (!sX(WriteIrSize(CDF->fp,eof,&size),&pStatus)) return pStatus; - if (!sX(WriteIrType(CDF->fp,eof,&uir_),&pStatus)) return pStatus; - eof += size; - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - return pStatus; - } - } - /*********************************************************************** - * If the next UIR is contiguous with the ending UIR, make it the ending - * UIR. Otherwise, make the next UIR the starting and ending UIRs. - ***********************************************************************/ - if (eOffset + eUIR.RecordSize == eUIR.NextUIR) { - eOffset = eUIR.NextUIR; - if (!sX(ReadUIR(CDF->fp,eOffset, - UIR_RECORD,&eUIR, - UIR_NULL),&pStatus)) return pStatus; - tSize += eUIR.RecordSize; - } - else { - sOffset = eUIR.NextUIR; - if (!sX(ReadUIR(CDF->fp,sOffset, - UIR_RECORD,&sUIR, - UIR_NULL),&pStatus)) return pStatus; - eOffset = sOffset; - eUIR = sUIR; - tSize = sUIR.RecordSize; - } - } - } - /**************************************************************************** - * No UIRs exist. The new internal record will have to be allocated at the - * EOF. - ****************************************************************************/ - *offset = eof; - if (!sX(WriteIrSize(CDF->fp,eof,&size),&pStatus)) return pStatus; - if (!sX(WriteIrType(CDF->fp,eof,&uir_),&pStatus)) return pStatus; - eof += size; - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* ResizeIR. -******************************************************************************/ - -STATICforIDL CDFstatus ResizeIR (CDF, curOffset, newSize, newOffset, move, - success) -struct CDFstruct *CDF; -Int32 curOffset; /* In: Current offset of internal record. */ -Int32 newSize; /* In: New size of internal record. This may be - smaller or larger than the current size. */ -Int32 *newOffset; /* Out: New offset of internal record. This variable - is not modified if an error occurs or the internal - record cannot be extended (when `move' is FALSE). */ -Logical move; /* In: TRUE if the internal record can be moved if - necessary. */ -Logical *success; /* Out: TRUE if the internal record was successfully - extended (whether or not it had to be moved). */ -{ - CDFstatus pStatus = CDF_OK; Int32 curSize; Int32 eof; - /**************************************************************************** - * Determine current size of internal record. - ****************************************************************************/ - if (!sX(ReadIrSize(CDF->fp,curOffset,&curSize),&pStatus)) return pStatus; - /**************************************************************************** - * Check sizes... - ****************************************************************************/ - if (newSize > curSize) { - /************************************************************************** - * The internal record is growing. First check if it is the last one in - * the CDF. - **************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - if (curOffset + curSize == eof) { - /************************************************************************ - * Last internal record. Simply extend the CDF. - ************************************************************************/ - ASSIGNnotNULL (newOffset, curOffset) - eof += (newSize - curSize); - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - if (!sX(WriteIrSize(CDF->fp, - curOffset, - &newSize),&pStatus)) return pStatus; - ASSIGNnotNULL (success, TRUE) - return pStatus; - } - else { - /************************************************************************ - * Not the last internal record. If the internal record may be moved, - * first mark it as unused and then allocate a new internal record. - * Marking it unused first allows the possibility that if will be used - * as part of the allocated internal record. If the internal record can - * not be moved, check if unused records immediately follow. - ************************************************************************/ - if (move) { - if (!sX(WasteIR(CDF,curOffset,curSize),&pStatus)) return pStatus; - if (!sX(AllocateIR(CDF,newSize,newOffset),&pStatus)) return pStatus; - ASSIGNnotNULL (success, TRUE) - return pStatus; - } - else { - Int32 sOffset, eOffset, tSize, UIRhead, irType; - struct UIRstruct sUIR, eUIR; - /********************************************************************** - * First check if there are any UIRs in the CDF. This is done because - * CDF V2.5.0* (alpha/beta) created UIRs without the next and previous - * UIR fields and didn't use the `UIRhead' field in the GDR. Because - * we don't want to use UIRs in those CDFs (because they are not the - * same as the current UIRs), this will keep us from doing so (because - * the `UIRhead' fields will always contain zero if a V2.5.0* CDF). - **********************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_UIRHEAD,&UIRhead, - GDR_NULL),&pStatus)) return pStatus; - if (UIRhead == 0) { - ASSIGNnotNULL (success, FALSE) - return pStatus; - } - /********************************************************************** - * Read the internal record which immediately follows the internal - * record being resized. If it is a UIR make it the starting UIR. - * ---------------------------- DANGER --------------------------------- - * Don't try to read an entire UIR. First read only the record type - * field and check if it is UIR_. Then read the entire UIR. This is - * because the next internal record could be smaller than a UIR (or - * larger but not entirely written yet [eg. a VVR]). - **********************************************************************/ - sOffset = curOffset + curSize; - if (!sX(ReadIrType(CDF->fp,sOffset,&irType),&pStatus)) return pStatus; - if (irType != UIR_) { - ASSIGNnotNULL (success, FALSE) - return pStatus; - } - if (!sX(ReadUIR(CDF->fp,sOffset, - UIR_RECORD,&sUIR, - UIR_NULL),&pStatus)) return pStatus; - tSize = curSize + sUIR.RecordSize; - eOffset = sOffset; - eUIR = sUIR; - for (;;) { - /******************************************************************* - * Check if the exact amount of available space has been found. - *******************************************************************/ - if (newSize == tSize) { - if (!sX(RemoveUIRs(CDF,sOffset,eOffset),&pStatus)) return pStatus; - if (!sX(WriteIrSize(CDF->fp, - curOffset, - &newSize),&pStatus)) return pStatus; - ASSIGNnotNULL (newOffset, curOffset) - ASSIGNnotNULL (success, TRUE) - return pStatus; - } - /******************************************************************* - * Check if enough available space has been found to increase the - * internal record and then create a new UIR in the remaining space. - *******************************************************************/ - if (newSize + UIR_BASE_SIZE <= tSize) { - if (!sX(RemoveUIRs(CDF,sOffset,eOffset),&pStatus)) return pStatus; - if (!sX(WasteIR(CDF,curOffset+newSize,tSize-newSize),&pStatus)) { - return pStatus; - } - if (!sX(WriteIrSize(CDF->fp, - curOffset, - &newSize),&pStatus)) return pStatus; - ASSIGNnotNULL (newOffset, curOffset) - ASSIGNnotNULL (success, TRUE) - return pStatus; - } - /******************************************************************* - * Check if the end of the UIRs has been reached. - *******************************************************************/ - if (eUIR.NextUIR == 0) { - /***************************************************************** - * If the ending UIR is at the EOF, then the internal record can - * be extended beyond the EOF or up to it with the creation of a - * new UIR at the very end. - *****************************************************************/ - if (eOffset + eUIR.RecordSize == eof) { - if (!sX(RemoveUIRs(CDF,sOffset,eOffset),&pStatus)) return - pStatus; - if (newSize < tSize) { - if (!sX(WasteIR(CDF,curOffset+newSize, - UIR_BASE_SIZE),&pStatus)) return pStatus; - eof = curOffset + newSize + UIR_BASE_SIZE; - } - else - eof = curOffset + newSize; - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - if (!sX(WriteIrSize(CDF->fp, - curOffset, - &newSize),&pStatus)) return pStatus; - ASSIGNnotNULL (newOffset, curOffset) - ASSIGNnotNULL (success, TRUE) - return pStatus; - } - else { - ASSIGNnotNULL (success, FALSE) - return pStatus; - } - } - /******************************************************************* - * If the next UIR is contiguous with the ending UIR, make it the - * ending UIR. - *******************************************************************/ - if (eOffset + eUIR.RecordSize == eUIR.NextUIR) { - eOffset = eUIR.NextUIR; - if (!sX(ReadUIR(CDF->fp,eOffset, - UIR_RECORD,&eUIR, - UIR_NULL),&pStatus)) return pStatus; - tSize += eUIR.RecordSize; - } - else { - ASSIGNnotNULL (success, FALSE) - return pStatus; - } - } - } - } - } - else { - /************************************************************************** - * The internal record is shrinking. Check if it can be shrunk in place - * and a UIR created to occupy the extra space. If not, waste it and then - * allocate a new internal record (if moving it is allowed). - **************************************************************************/ - if (newSize <= (curSize - UIR_BASE_SIZE)) { - if (!sX(WasteIR(CDF,curOffset + newSize, - curSize - newSize),&pStatus)) return pStatus; - if (!sX(WriteIrSize(CDF->fp, - curOffset, - &newSize),&pStatus)) return pStatus; - ASSIGNnotNULL (newOffset, curOffset) - ASSIGNnotNULL (success, TRUE) - } - else { - if (move) { - if (!sX(WasteIR(CDF,curOffset,curSize),&pStatus)) return pStatus; - if (!sX(AllocateIR(CDF,newSize,newOffset),&pStatus)) return pStatus; - ASSIGNnotNULL (success, TRUE) - } - else { - ASSIGNnotNULL (success, FALSE) - } - } - return pStatus; - } -} - -/****************************************************************************** -* RemoveUIRs. -******************************************************************************/ - -STATICforIDL CDFstatus RemoveUIRs (CDF, sOffset, eOffset) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -Int32 sOffset; /* In: Offset of starting UIR. */ -Int32 eOffset; /* In: Offset of ending UIR. */ -{ - CDFstatus pStatus = CDF_OK; - struct UIRstruct sUIR, eUIR; - Int32 UIRhead; - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_UIRHEAD,&UIRhead, - GDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadUIR(CDF->fp,sOffset, - UIR_RECORD,&sUIR, - UIR_NULL),&pStatus)) return pStatus; - if (!sX(ReadUIR(CDF->fp,eOffset, - UIR_RECORD,&eUIR, - UIR_NULL),&pStatus)) return pStatus; - if (UIRhead == sOffset) { - UIRhead = eUIR.NextUIR; - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - GDR_UIRHEAD,&UIRhead, - GDR_NULL),&pStatus)) return pStatus; - } - else { - struct UIRstruct prevUIR; - if (!sX(ReadUIR(CDF->fp,sUIR.PrevUIR, - UIR_RECORD,&prevUIR, - UIR_NULL),&pStatus)) return pStatus; - prevUIR.NextUIR = eUIR.NextUIR; - if (!sX(WriteUIR(CDF->fp,sUIR.PrevUIR, - UIR_RECORD,&prevUIR, - UIR_NULL),&pStatus)) return pStatus; - } - if (eUIR.NextUIR != 0) { - struct UIRstruct nextUIR; - if (!sX(ReadUIR(CDF->fp,eUIR.NextUIR, - UIR_RECORD,&nextUIR, - UIR_NULL),&pStatus)) return pStatus; - nextUIR.PrevUIR = sUIR.PrevUIR; - if (!sX(WriteUIR(CDF->fp,eUIR.NextUIR, - UIR_RECORD,&nextUIR, - UIR_NULL),&pStatus)) return pStatus; - } - return pStatus; -} - -/****************************************************************************** -* PriorTo. -******************************************************************************/ - -VISIBLE_PREFIX Logical PriorTo (spec, version, release, increment) -char *spec; -Int32 version; -Int32 release; -Int32 increment; -{ - int ver, rel, incr; - switch (sscanf(spec,"%d.%d.%d",&ver,&rel,&incr)) { - case 1: - if (version < ver) return TRUE; - break; - case 2: - if (version < ver) return TRUE; - if (version == ver && release < rel) return TRUE; - break; - case 3: - if (version < ver) return TRUE; - if (version == ver && release < rel) return TRUE; - if (version == ver && release == rel && increment < incr) return TRUE; - break; - } - return FALSE; -} - -/****************************************************************************** -* ShortenCDR. -******************************************************************************/ - -STATICforIDL CDFstatus ShortenCDR (CDF) -struct CDFstruct *CDF; -{ - CDFstatus pStatus = CDF_OK; - Int32 offset, oldRecordSize, newRecordSize, nBytes; - if (!sX(ReadCDR(CDF->fp,CDF->CDRoffset, - CDR_RECORDSIZE,&oldRecordSize, - CDR_NULL),&pStatus)) - return pStatus; - newRecordSize = CDR_BASE_SIZE + CDF_COPYRIGHT_LEN; - if (!sX(WriteCDR(CDF->fp,V2_CDR_OFFSET, - CDR_RECORDSIZE,&newRecordSize, - CDR_NULL),&pStatus)) return pStatus; - offset = CDF->CDRoffset + newRecordSize; - nBytes = oldRecordSize - newRecordSize; - if (!sX(WasteIR(CDF,offset,nBytes),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CorrectScopes. -* It is assumed that the last ADR offset has already been fixed. -******************************************************************************/ - -STATICforIDL CDFstatus CorrectScopes (CDF) -struct CDFstruct *CDF; -{ - Int32 tOffset, attrScope; - CDFstatus pStatus = CDF_OK; - /**************************************************************************** - * Read the offset of the first ADR from the GDR. - ****************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_ADRHEAD,&tOffset, - GDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * Read the ADRs correcting each assumed scope. - ****************************************************************************/ - while (tOffset != 0) { - if (!sX(ReadADR(CDF->fp,tOffset, - ADR_SCOPE,&attrScope, - ADR_NULL),&pStatus)) return pStatus; - switch (attrScope) { - case GLOBALscopeASSUMED: - attrScope = GLOBAL_SCOPE; - if (!sX(WriteADR(CDF->fp,tOffset, - ADR_SCOPE,&attrScope, - ADR_NULL),&pStatus)) return pStatus; - break; - case VARIABLEscopeASSUMED: - attrScope = VARIABLE_SCOPE; - if (!sX(WriteADR(CDF->fp,tOffset, - ADR_SCOPE,&attrScope, - ADR_NULL),&pStatus)) return pStatus; - break; - } - if (!sX(ReadADR(CDF->fp,tOffset, - ADR_ADRNEXT,&tOffset, - ADR_NULL),&pStatus)) return pStatus; - } - return pStatus; -} - -/****************************************************************************** -* ShortenVDRs. -* It is assumed that the last rVDR offset has already been fixed. -******************************************************************************/ - -STATICforIDL CDFstatus ShortenVDRs (CDF) -struct CDFstruct *CDF; -{ - Int32 vOffset, nextOffset, recordSize, nTailBytes; - void *tBuffer; - Int32 tOffset; - CDFstatus pStatus = CDF_OK; - int i; - for (i = 0; i < 2; i++) { - Logical zVar = (i == 0); - /************************************************************************* - * Read the offset of the first rVDR from the GDR. - *************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - BOO(zVar,GDR_zVDRHEAD,GDR_rVDRHEAD),&vOffset, - GDR_NULL),&pStatus)) return pStatus; - /************************************************************************* - * Read the rVDRs shortening each. - *************************************************************************/ - while (vOffset != ZERO_OFFSET) { - if (!sX(ReadVDR(CDF,CDF->fp,vOffset,zVar, - VDR_VDRNEXT,&nextOffset, - VDR_RECORDSIZE,&recordSize, - VDR_NULL),&pStatus)) return pStatus; - nTailBytes = recordSize - VDR_WASTED_OFFSET - VDR_WASTED_SIZE; - recordSize -= VDR_WASTED_SIZE; - if (!sX(WriteVDR(CDF,CDF->fp,vOffset,zVar, - VDR_RECORDSIZE,&recordSize, - VDR_NULL),&pStatus)) return pStatus; - tBuffer = cdf_AllocateMemory ((size_t) nTailBytes, NULL); - if (tBuffer != NULL) { - tOffset = vOffset + VDR_WASTED_OFFSET + VDR_WASTED_SIZE; - if (!SEEKv(CDF->fp,tOffset,vSEEK_SET)) return CDF_READ_ERROR; - if (!READv(tBuffer,(size_t)nTailBytes,1,CDF->fp)) return - CDF_READ_ERROR; - tOffset = vOffset + VDR_WASTED_OFFSET; - if (!SEEKv(CDF->fp,tOffset,vSEEK_SET)) return CDF_WRITE_ERROR; - if (!WRITEv(tBuffer,(size_t)nTailBytes,1,CDF->fp)) return - CDF_WRITE_ERROR; - cdf_FreeMemory (tBuffer, NULL); - } - else { - Int32 oldOffset = vOffset + VDR_WASTED_OFFSET + VDR_WASTED_SIZE, - newOffset = vOffset + VDR_WASTED_OFFSET, byteX; - Byte1 tByte; - for (byteX = 0; byteX < nTailBytes; byteX++) { - if (!SEEKv(CDF->fp,oldOffset,vSEEK_SET)) return CDF_READ_ERROR; - if (!READv(&tByte,1,1,CDF->fp)) return CDF_READ_ERROR; - if (!SEEKv(CDF->fp,newOffset,vSEEK_SET)) return CDF_WRITE_ERROR; - if (!WRITEv(&tByte,1,1,CDF->fp)) return CDF_WRITE_ERROR; - oldOffset++; - newOffset++; - } - } - if (!sX(WasteIR(CDF,vOffset+recordSize,VDR_WASTED_SIZE),&pStatus)) { - return pStatus; - } - vOffset = nextOffset; - } - } - return pStatus; -} - -/****************************************************************************** -* CorrectBlockingFactors. -* It is assumed that the last rVDR offset has already been fixed. -******************************************************************************/ - -STATICforIDL CDFstatus CorrectBlockingFactors (CDF) -struct CDFstruct *CDF; -{ - CDFstatus pStatus = CDF_OK; Int32 nVars, vdrOffset; int varN; - Logical zVar; struct VDRstruct VDR; struct VarStruct **Vars, *Var; - for (zVar = 0; zVar <= 1; zVar++) { - Vars = BOO(zVar,CDF->zVars,CDF->rVars); - nVars = BOO(zVar,CDF->NzVars,CDF->NrVars); - for (varN = 0; varN < nVars; varN++) { - Var = Vars[varN]; - if (Var == NULL) { - if (!sX(FindVarByNumber(CDF,(Int32)varN, - zVar,&vdrOffset),&pStatus)) return pStatus; - } - else - vdrOffset = Var->VDRoffset; - if (!sX(ReadVDR(CDF,CDF->fp,vdrOffset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) return pStatus; - if (!RECvaryBITset(VDR.Flags) && VDR.blockingFactor > 1) { - VDR.blockingFactor = 1; - if (!sX(WriteVDR(CDF,CDF->fp,vdrOffset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) return pStatus; - if (Var != NULL) { - if (!sX(CalcBF(CDF,Var),&pStatus)) return pStatus; - } - } - } - } - return pStatus; -} - -/****************************************************************************** -* CorrectEPOCH. -******************************************************************************/ - -STATICforIDL CDFstatus CorrectEPOCH (CDF) -struct CDFstruct *CDF; -{ - CDFstatus tStatus, pStatus = CDF_OK; - Int32 dataType, vNum, vOffset, aOffset, eOffset; - Logical zVar; - int i; - /**************************************************************************** - * Search for EPOCH rVariable. - ****************************************************************************/ - tStatus = FindVarByName (CDF, "EPOCH", &vOffset, &zVar, NULL); - switch (tStatus) { - case CDF_OK: - if (!sX(ReadVDR(CDF,CDF->fp,vOffset,zVar, - VDR_NUM,&vNum, - VDR_DATATYPE,&dataType, - VDR_NULL),&pStatus)) return pStatus; - if (FLOAT8dataType(dataType)) dataType = CDF_EPOCH; - if (!sX(WriteVDR(CDF,CDF->fp,vOffset,zVar, - VDR_DATATYPE,&dataType, - VDR_NULL),&pStatus)) return pStatus; - /************************************************************************ - * Search for associated VALIDMIN/VALIDMAX/SCALEMIN/SCALEMAX rEntries. - ************************************************************************/ - for (i = 0; i < 4; i++) { - char aName[8+1]; - switch (i) { - case 0: strcpy (aName, "VALIDMIN"); break; - case 1: strcpy (aName, "VALIDMAX"); break; - case 2: strcpy (aName, "SCALEMIN"); break; - case 3: strcpy (aName, "SCALEMAX"); break; - } - tStatus = FindAttrByName (CDF,aName,&aOffset); - switch (tStatus) { - case CDF_OK: - tStatus = FindEntryByNumber (CDF, aOffset, zVar, vNum, - &eOffset); /* We can do this since - only rVariables will - exist. */ - switch (tStatus) { - case CDF_OK: - if (!sX(ReadAEDR(CDF->fp,eOffset, - AEDR_DATATYPE,&dataType, - AEDR_NULL),&pStatus)) return pStatus; - if (FLOAT8dataType(dataType)) dataType = CDF_EPOCH; - if (!sX(WriteAEDR(CDF,CDF->fp,eOffset, - AEDR_DATATYPE,&dataType, - AEDR_NULL),&pStatus)) return pStatus; - break; - case NO_SUCH_ENTRY: - break; - default: - return tStatus; - } - break; - case NO_SUCH_ATTR: - break; - default: - return tStatus; - } - } - break; - case NO_SUCH_VAR: - break; - default: - return tStatus; - } - return pStatus; -} - -/****************************************************************************** -* CDFdeleteFile. -******************************************************************************/ - -STATICforIDL Logical CDFdeleteFile (path) -char *path; -{ -#if defined(vms) - char tPath[DU_MAX_PATH_LEN+1]; - strcpyX (tPath, path, DU_MAX_PATH_LEN); - strcatX (tPath, ";0", DU_MAX_PATH_LEN); /* Only most recent is deleted. */ - return (delete(tPath) == 0); -#endif -#if defined(unix) || defined(dos) - return (unlink(path) == 0); -#endif -#if defined(mac) || defined(posixSHELL) || defined(win32) - return (remove(path) == 0); -#endif -} - -/****************************************************************************** -* KillAbortedCDF. -******************************************************************************/ - -STATICforIDL void KillAbortedCDF (CDF, Cur) -struct CDFstruct *CDF; -struct CurStruct *Cur; -{ - CDF->magic = KILLEDid_MAGIC_NUMBER; - cdf_FreeMemory (CDF, NULL); - Cur->cdf = NULL; - return; -} - -/****************************************************************************** -* AbortAccess. -******************************************************************************/ - -STATICforIDL void AbortAccess (CDF, updateCDF, deleteCDF) -struct CDFstruct *CDF; -Logical updateCDF; /* Update "working" dotCDF file (if read/write - access has been obtained)? */ -Logical deleteCDF; /* Delete CDF file(s)? */ -{ - /**************************************************************************** - * If the CDF is to be deleted do that first and then skip the updating and/or - * closing of the CDF files. - ****************************************************************************/ - if (deleteCDF) { - DeleteCDFfiles (CDF); - if (CDF->uDotFp != NULL) V_delete (CDF->uDotFp, NULL); - } - else { - /************************************************************************** - * Update the dotCDF file if requested, if the current access is read/write, - * and if the "working" dotCDF file has not already been closed or deleted. - **************************************************************************/ - if (CDF->status == READ_WRITE && updateCDF && - (CDF->fp == CDF->dotFp || CDF->fp == CDF->uDotFp)) UpdateDotCDF (CDF); - /************************************************************************** - * Close all of the CDF files if they are not already closed (or deleted). - **************************************************************************/ - if (CDF->dotFp != NULL) V_close (CDF->dotFp, - ((updateCDF==UPDATE)?CDF:NULL), NULL); - if (CDF->uDotFp != NULL) V_close (CDF->uDotFp, - ((updateCDF==UPDATE)?CDF:NULL), NULL); - CloseVarFiles (CDF); - } - /**************************************************************************** - * Delete the scratch files that still exist. - ****************************************************************************/ - if (CDF->stage.fp != NULL) V_delete (CDF->stage.fp, NULL); - if (CDF->compressFp != NULL) V_delete (CDF->compressFp, NULL); - /**************************************************************************** - * Free the memory used by the CDF. - ****************************************************************************/ - FreeCDFid (CDF, TRUE); - return; -} - -/****************************************************************************** -* DeleteCDFfiles. -* The files may be open or closed. This routine does not delete the -* uncompressed dotCDF file (if one exists). -******************************************************************************/ - -STATICforIDL CDFstatus DeleteCDFfiles (CDF) -struct CDFstruct *CDF; -{ - char tmpFile[DU_MAX_PATH_LEN+1]; CDFstatus pStatus = CDF_OK; - /************************************************************************** - * Delete dotCDF file. - **************************************************************************/ - if (CDF->dotFp == NULL) { - BuildFilePath (CDFt, CDF->CDFname, CDF->no_append, CDF->upper_case_ext, - CDF->version_numbers, INT32_ZERO, tmpFile); - if (!CDFdeleteFile(tmpFile)) sX (CDF_DELETE_ERROR, &pStatus); - } - else { - if (!DELETEv(CDF->dotFp,NULL)) sX (CDF_DELETE_ERROR, &pStatus); - CDF->dotFp = NULL; - } - /************************************************************************** - * Delete the variable files (if multi-file). Both rVariable and zVariable - * files are deleted. - **************************************************************************/ - if (!CDF->singleFile) { - int varN; - for (varN = 0; varN < CDF->NrVars; varN++) { - struct VarStruct *Var = CDF->rVars[varN]; - if (Var != NULL) { - if (Var->fp != NULL) { - if (!DELETEv(Var->fp,NULL)) sX (VAR_DELETE_ERROR, &pStatus); - Var->fp = NULL; - continue; - } - } - BuildFilePath (Vt, CDF->CDFname, CDF->no_append, CDF->upper_case_ext, - CDF->version_numbers, varN, tmpFile); - if (!CDFdeleteFile(tmpFile)) sX (VAR_DELETE_ERROR, &pStatus); - } - for (varN = 0; varN < CDF->NzVars; varN++) { - struct VarStruct *Var = CDF->zVars[varN]; - if (Var != NULL) { - if (Var->fp != NULL) { - if (!DELETEv(Var->fp,NULL)) sX (VAR_DELETE_ERROR, &pStatus); - Var->fp = NULL; - continue; - } - } - BuildFilePath (Zt, CDF->CDFname, CDF->no_append, CDF->upper_case_ext, - CDF->version_numbers, varN, tmpFile); - if (!CDFdeleteFile(tmpFile)) sX (VAR_DELETE_ERROR, &pStatus); - } - } - return pStatus; -} - -/****************************************************************************** -* DeleteEntry. -******************************************************************************/ - -STATICforIDL CDFstatus DeleteEntry (CDF, aOffset, eOffset) -struct CDFstruct *CDF; -Int32 aOffset; -Int32 eOffset; -{ - CDFstatus pStatus = CDF_OK; - struct ADRstruct ADR; - struct AEDRstruct AEDR, AEDRt; - Int32 prevEntryOffset; - Logical zEntry; - /**************************************************************************** - * Read the ADR and the AEDR being deleted. - ****************************************************************************/ - if (!sX(ReadADR(CDF->fp,aOffset, - ADR_RECORD,&ADR, - ADR_NULL),&pStatus)) return pStatus; - if (!sX(ReadAEDR(CDF->fp,eOffset, - AEDR_RECORD,&AEDR,NULL, - AEDR_NULL),&pStatus)) return pStatus; - zEntry = (AEDR.RecordType == AzEDR_); - /**************************************************************************** - * Remove the AEDR from the list of entries. - ****************************************************************************/ - if (!sX(FindPrevEntry(CDF,aOffset,eOffset, - zEntry,&prevEntryOffset),&pStatus)) return pStatus; - if (prevEntryOffset == 0) { - /************************************************************************** - * The first entry on the linked list is being deleted. Point the ADR to - * the entry being pointed to by the entry being deleted. - **************************************************************************/ - if (zEntry) - ADR.AzEDRhead = AEDR.AEDRnext; - else - ADR.AgrEDRhead = AEDR.AEDRnext; - } - else { - /************************************************************************** - * The entry being deleted is not the first entry on the linked list. Point - * the previous entry to the entry pointed to by the entry being deleted. - **************************************************************************/ - if (!sX(ReadAEDR(CDF->fp,prevEntryOffset, - AEDR_RECORD,&AEDRt,NULL, - AEDR_NULL),&pStatus)) return pStatus; - AEDRt.AEDRnext = AEDR.AEDRnext; - if (!sX(WriteAEDR(CDF,CDF->fp,prevEntryOffset, - AEDR_RECORD,&AEDRt,NULL, - AEDR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * Decrement the number of entries and recalculate the maximum entry (if - * necessary). - ****************************************************************************/ - if (zEntry) - ADR.NzEntries--; - else - ADR.NgrEntries--; - if (BOO(zEntry,ADR.MAXzEntry,ADR.MAXgrEntry) == AEDR.Num) { - Int32 maxEntry = NO_ENTRY; - Int32 tOffset = BOO(zEntry,ADR.AzEDRhead,ADR.AgrEDRhead); - while (tOffset != 0) { - if (!sX(ReadAEDR(CDF->fp,tOffset, - AEDR_RECORD,&AEDRt,NULL, - AEDR_NULL),&pStatus)) return pStatus; - maxEntry = MaxInt32 (maxEntry, AEDRt.Num); - tOffset = AEDRt.AEDRnext; - } - if (zEntry) - ADR.MAXzEntry = maxEntry; - else - ADR.MAXgrEntry = maxEntry; - } - /**************************************************************************** - * Rewrite the ADR and waste the AEDR (of the entry being deleted). - ****************************************************************************/ - if (!sX(WriteADR(CDF->fp,aOffset, - ADR_RECORD,&ADR, - ADR_NULL),&pStatus)) return pStatus; - if (!sX(WasteIR(CDF,eOffset,AEDR.RecordSize),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CtoPstr/PtoCstr. -******************************************************************************/ - -#if defined(MPW_C) -STATICforIDL uChar *CtoPstr (string) -char *string; -{ - size_t length = MINIMUM(strlen(string),255); - if (length > 0) memmove (&string[1], string, length); - string[0] = (char) length; - return ((uChar *) string); -} -#endif - -#if defined(MPW_C) -STATICforIDL char *PtoCstr (string) -uChar *string; -{ - size_t length = (size_t) string[0]; - if (length > 0) memmove (string, &string[1], length); - string[length] = (uChar) NUL; - return ((char *) string); -} -#endif - -/****************************************************************************** -* PadUnRecords. -* Pad all allocated records within the first/last record range. Note that -* in the case of sparse records some of the records may not be allocated (and -* should not be padded of course). -******************************************************************************/ - -STATICforIDL CDFstatus PadUnRecords (CDF, Var, firstRec, lastRec) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 firstRec; -Int32 lastRec; -{ - CDFstatus pStatus = CDF_OK; Int32 offset; int how; void *buffer; - Int32 recNum, nRecords, toRec, lastRecInVVR; Logical found; - /**************************************************************************** - * Pad the records. - * NOTE: Padding in a single-file CDF could be made more efficient by not - * allocating/freeing the pad buffer over and over... - ****************************************************************************/ - if (CDF->singleFile) { - /************************************************************************** - * Single-file...first determine the first allocated record to be padded. - **************************************************************************/ - if (!sX(NextRecord(CDF,Var->VDRoffset,Var->zVar, - firstRec,&recNum,&found),&pStatus)) return pStatus; - if (!found) return pStatus; - /************************************************************************** - * While the first record to be padded is within the range... - **************************************************************************/ - while (recNum <= lastRec) { - if (!sX(RecordByteOffset(CDF,Var,recNum, - &offset),&pStatus)) return pStatus; - if (!sX(SearchForRecord(CDF,Var->VDRoffset, - Var->zVar,recNum, - NULL,&lastRecInVVR, - NULL,NULL),&pStatus)) return pStatus; - toRec = MINIMUM(lastRec,lastRecInVVR); - nRecords = toRec - recNum + 1; - if (!sX(BuildPadBuffer(CDF,Var,nRecords, - &how,&buffer,TRUE),&pStatus)) return pStatus; - if (!sX(WritePadValues(Var,CDF->fp,offset, - nRecords,how,buffer),&pStatus)) { - cdf_FreeMemory (buffer, NULL); - return pStatus; - } - cdf_FreeMemory (buffer, NULL); - recNum += nRecords; - /************************************************************************ - * Determine the next `first' record to be padded. - ************************************************************************/ - if (!sX(NextRecord(CDF,Var->VDRoffset,Var->zVar, - recNum,&recNum,&found),&pStatus)) return pStatus; - if (!found) return pStatus; - } - } - else { - /************************************************************************** - * Multi-file... - **************************************************************************/ - if (!sX(RecordByteOffset(CDF,Var, - firstRec, - &offset),&pStatus)) return pStatus; - nRecords = lastRec - firstRec + 1; - if (!sX(BuildPadBuffer(CDF,Var,nRecords, - &how,&buffer,TRUE),&pStatus)) return pStatus; - if (!sX(WritePadValues(Var,Var->fp,offset,nRecords,how,buffer),&pStatus)) { - cdf_FreeMemory (buffer, NULL); - return pStatus; - } - cdf_FreeMemory (buffer, NULL); - } - return pStatus; -} - -/****************************************************************************** -* WritePadValues. -* NOTE: It is assumed that the records are contiguous (in a single-file CDF) -* and that on a DOS machine the buffer does not exceed 64K bytes. It is also -* assumed that the values have already been encoded for the CDF. -******************************************************************************/ - -STATICforIDL CDFstatus WritePadValues (Var, fp, offset, nRecords, how, buffer) -struct VarStruct *Var; -vFILE *fp; -Int32 offset; -Int32 nRecords; -int how; -void *buffer; -{ - Int32 nBytes, nValues, recX, valueX; - /**************************************************************************** - * Seek to desired offset. - ****************************************************************************/ - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return VAR_WRITE_ERROR; - /**************************************************************************** - * Write records... - ****************************************************************************/ - switch (how) { - case ALLrecordsATonce: - nBytes = nRecords * Var->NphyRecBytes; - if (!WRITEv(buffer,(size_t)nBytes,1,fp)) return VAR_WRITE_ERROR; - break; - case ONErecordATaTIME: - for (recX = 0; recX < nRecords; recX++) { - if (!WRITEv(buffer,(size_t)Var->NphyRecBytes,1,fp)) { - return VAR_WRITE_ERROR; - } - } - break; - case ONEvalueATaTIME: - nValues = nRecords * Var->NphyRecValues; - for (valueX = 0; valueX < nValues; valueX++) { - if (!WRITEv(buffer,(size_t)Var->NvalueBytes,1,fp)) { - return VAR_WRITE_ERROR; - } - } - break; - } - return CDF_OK; -} - -/****************************************************************************** -* MinInt/Int32/Long. -* These are used to avoid double evaluation in macro expansions (eg. MINIMUM). -******************************************************************************/ - -VISIBLE_PREFIX int MinInt (a, b) -int a; -int b; -{ - return MINIMUM(a,b); -} - -VISIBLE_PREFIX Int32 MinInt32 (a, b) -Int32 a; -Int32 b; -{ - return MINIMUM(a,b); -} - -VISIBLE_PREFIX long MinLong (a, b) -long a; -long b; -{ - return MINIMUM(a,b); -} - -/****************************************************************************** -* MaxInt/Int32/Long. -* These are used to avoid double evaluation in macro expansions (eg. MAXIMUM). -******************************************************************************/ - -VISIBLE_PREFIX int MaxInt (a, b) -int a; -int b; -{ - return MAXIMUM(a,b); -} - -VISIBLE_PREFIX Int32 MaxInt32 (a, b) -Int32 a; -Int32 b; -{ - return MAXIMUM(a,b); -} - -VISIBLE_PREFIX long MaxLong (a, b) -long a; -long b; -{ - return MAXIMUM(a,b); -} - -/****************************************************************************** -* AddTOvStats. -******************************************************************************/ - -STATICforIDL void AddTOvStats (vStatsTO, vStats) -vSTATS *vStatsTO; /* If NULL, do nothing. */ -vSTATS *vStats; /* If NULL, initialize (to zero). */ -{ - if (vStatsTO != NULL) { - if (vStats == NULL) { - vStatsTO->nBuffers = 0; - vStatsTO->maxBuffers = 0; - vStatsTO->nV_reads = 0; - vStatsTO->nV_writes = 0; - vStatsTO->nPageIns = 0; - vStatsTO->nPageOuts = 0; - vStatsTO->nBlockReads = 0; - vStatsTO->nBlockWrites = 0; - } - else { - vStatsTO->nBuffers = MAXIMUM(vStatsTO->nBuffers,vStats->nBuffers); - vStatsTO->maxBuffers = MAXIMUM(vStatsTO->maxBuffers,vStats->maxBuffers); - vStatsTO->nV_reads += vStats->nV_reads; - vStatsTO->nV_writes += vStats->nV_writes; - vStatsTO->nPageIns += vStats->nPageIns; - vStatsTO->nPageOuts += vStats->nPageOuts; - vStatsTO->nBlockReads += vStats->nBlockReads; - vStatsTO->nBlockWrites += vStats->nBlockWrites; - } - } - return; -} - -/****************************************************************************** -* FillSpacesToString. -* This function scans for Nul in a string buffer. If found, it fills space(s) -* until the end of the number of elements. This happens when a string is -* entered with a length shorter than the defined number of elements. The -* buffer's size is a number of numElms, which could contain multiple strings. -******************************************************************************/ -STATICforIDL void FillSpacesToString (buffer, totalBytes, numElems) -char *buffer; -int totalBytes; -int numElems; -{ - int i, j, k, l; - if ((totalBytes == numElems) && ((int)strlen(buffer) == totalBytes)) return; - l = totalBytes / numElems; - for (i = 0; i < l; ++i) { - if ((int)strlen(buffer+i*numElems) >= numElems) continue; - for (j = 0; j < numElems; ++j) { - if (*(buffer+i*numElems+j) == '\0') { - for (k = j; k < numElems; ++k) - *(buffer+i*numElems+k) = ' '; - break; - } - } - } - return; -} -/****************************************************************************** -* DisplayVs. -******************************************************************************/ - -#if defined(DEBUG) -STATICforIDL void DisplayVs (toWhere, label, vStats) -char *toWhere; -char *label; -vSTATS *vStats; -{ - if (toWhere != NULL) { - FILE *fp = BOO(strcmp(toWhere,"STDOUT"),FOPEN(toWhere,"a"),stdout); - if (fp == NULL) return; - fprintf (fp, "%s", label); - fprintf (fp, "..BUF:%03ldu/%03ldx", vStats->nBuffers, vStats->maxBuffers); - fprintf (fp, " V_:%06ldr/%06ldw", vStats->nV_reads, vStats->nV_writes); - fprintf (fp, " PAGE:%05ldi/%05ldo", vStats->nPageIns, vStats->nPageOuts); - fprintf (fp, " BLK:%05ldr/%05ldw", - vStats->nBlockReads, vStats->nBlockWrites); - fprintf (fp, "\n"); - if (fp != stdout) fclose (fp); - } - return; -} -#endif diff --git a/cdf36_3-dist/src/lib/cdfmisc1_64.c b/cdf36_3-dist/src/lib/cdfmisc1_64.c deleted file mode 100644 index d32a326..0000000 --- a/cdf36_3-dist/src/lib/cdfmisc1_64.c +++ /dev/null @@ -1,1507 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF library miscellaneous functions, part 1. -* -* Version 1.3e, 18-Nov-97, Hughes STX. -* -* Modification history: -* -* V1.0 19-Dec-94, J Love Original version. -* V1.0a 29-Dec-94, J Love WriteBuffer: increment buffer pointer in the -* case where the memory allocation failed. -* V1.1 13-Jan-95, J Love Encode/decode changes. More cache-residency. -* Allow all possible extensions on all machines. -* V1.1a 19-Jan-95, J Love IRIX 6.x (64-bit). -* V1.1b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.2 21-Mar-95, J Love POSIX. -* V1.2a 18-Apr-95, J Love More POSIX. MEMLOG_. -* V1.2b 19-Apr-95, J Love Memory functions moved to `cdfmem.c'. -* V1.2c 7-Sep-95, J Love Corrected status codes being returned. Try -* progressively smaller temporary buffers in -* `WriteVarElems'. -* V1.3 10-Sep-96, J Love CDF V2.6. -* V1.3a 21-Feb-97, J Love Removed RICE. -* V1.3b 28-Feb-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V1.3c 11-Sep-97, J Love Magic numbers are now uInt32. -* V1.3d 20-Oct-97, J Love Properly cast the uInt32 magic numbers. More -* Windows NT. -* V1.3e 18-Nov-97, J Love Even more Windows NT. -* V2.0 08/Apr-04, M liu Replaced VSTREAM.STATS with VSTREAM_STATS. -* V2.1 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* V2.2 26-Oct-12, M Liu Change CDF version/release/increment and -* copyright only when a newer version apps -* is applying the modification. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" -#include "cdfrev.h" - -/****************************************************************************** -* Max/MinLongLong. -******************************************************************************/ - -VISIBLE_PREFIX OFF_T MaxLongLong (a, b) -OFF_T a; -OFF_T b; -{ - return MAXIMUM64(a,b); -} - -VISIBLE_PREFIX OFF_T MinLongLong (a, b) -OFF_T a; -OFF_T b; -{ - return MINIMUM64(a,b); -} - -/****************************************************************************** -* UpdateDotCDF64. -* If this routine is called when aborting a CDF, we cannot assume that -* the CDF structure is complete - it may have been only partially initialized -* when the CDF was aborted. If it is called to save the CDF without closing -* it, the data will be properly preserved. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus UpdateDotCDF64 (CDF) -struct CDFstruct *CDF; -{ - CDFstatus pStatus = CDF_OK; int varN; struct VarStruct *Var; Logical zVar; - /************************************************************************** - * Update r/zVariables depending on the variable type... - **************************************************************************/ - for (zVar = 0; zVar <= 1; zVar++) { - if (BOO(zVar,CDF->zVars,CDF->rVars) != NULL) { - Int32 nVars = BOO(zVar,CDF->NzVars,CDF->NrVars); - for (varN = 0; varN < nVars; varN++) { - Var = BOO(zVar,CDF->zVars[varN],CDF->rVars[varN]); - if (Var != NULL) { - switch (Var->vType) { - case SPARSE_RECORDS_: { - if (!sX(FlushStage64(CDF,Var),&pStatus)) break; - /* No `break' is intentional. */ - case STANDARD_: - if (Var->maxWritten < Var->maxAllocated) { - Int32 padFrom = Var->maxWritten + 1; - if (!sX(PadUnRecords64(CDF,Var,padFrom, - Var->maxAllocated),&pStatus)) break; - Var->maxWritten = Var->maxAllocated; - } - break; - } - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - if (!sX(FlushStage64(CDF,Var),&pStatus)) break; - break; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - sX (UNKNOWN_SPARSENESS, &pStatus); - break; - case IN_MULTI_: - break; - default: - sX (CDF_INTERNAL_ERROR, &pStatus); - break; - } - } - } - } - } - return pStatus; -} - -/****************************************************************************** -* CloseVarFiles64. -* -* Close the open variable files of the specified CDF. This routine closes all -* of the open variable files regardless of the number of errors detected. -* -* Because this routine is called when aborting a CDF, we cannot assume -* that the CDF structure is complete. Eg., it may have been only partially -* initialized when the CDF was aborted. -******************************************************************************/ - -STATICforIDL CDFstatus CloseVarFiles64 (CDF) -struct CDFstruct *CDF; -{ - CDFstatus pStatus = CDF_OK; struct VarStruct *Var; int varN; - /**************************************************************************** - * If a multi-file CDF, close the variable files. - ****************************************************************************/ - if (!CDF->singleFile) { - /************************************************************************** - * Close rVariable files. If the pointer to the rVariable is NULL, then - * the rVariable has yet to be initialized (and is obviously closed). - **************************************************************************/ - if (CDF->rVars != NULL) { - for (varN = 0; varN < CDF->NrVars; varN++) { - Var = CDF->rVars[varN]; - if (Var != NULL) { - if (Var->fp != NULL) { - if (!CLOSEv64(Var->fp,NULL,NULL)) sX (VAR_CLOSE_ERROR, &pStatus); - Var->fp = NULL; - } - } - } - } - /************************************************************************** - * Close zVariable files. If the pointer to the zVariable is NULL, then - * the zVariable has yet to be initialized (and is obviously closed). - **************************************************************************/ - if (CDF->zVars != NULL) { - for (varN = 0; varN < CDF->NzVars; varN++) { - Var = CDF->zVars[varN]; - if (Var != NULL) { - if (Var->fp != NULL) { - if (!CLOSEv64(Var->fp,NULL,NULL)) sX (VAR_CLOSE_ERROR, &pStatus); - Var->fp = NULL; - } - } - } - } - } - return pStatus; -} - -/****************************************************************************** -* WriteAccess64. -* Close and then reopen a CDF for read/write access (it was opened with -* read-only access initially). If the CDF is earlier than CDF V2.5, then -* some of the fields will have to be fixed and the CDR will be truncated for -* a shorter copyright length (unless the CDF is being deleted in which case -* it would be a waste of time to do these things). -******************************************************************************/ - -STATICforIDL Logical WriteAccess64 (CDF, forDelete, pStatus) -struct CDFstruct *CDF; -Logical forDelete; /* Is the write access is needed to delete the CDF? */ -CDFstatus *pStatus; /* Returned status. */ -{ -#if BUILD_READ_ONLY_DISTRIBUTION - *pStatus = READ_ONLY_DISTRIBUTION; - return FALSE; -#else - char pathName[DU_MAX_PATH_LEN+1]; vSTATS vStats; - /*************************************************************************** - * Check if write access already. - ***************************************************************************/ - if (CDF->status == READ_WRITE) return TRUE; - /*************************************************************************** - * Check if this CDF is in read-only mode. - ***************************************************************************/ - if (CDF->readOnly) { - *pStatus = READ_ONLY_MODE; - return FALSE; - } - /*************************************************************************** - * Close (the possibly compressed) dotCDF file and the variable files (if - * a multi-file CDF). An uncompressed dotCDF file and any scratch files - * stay open. - ***************************************************************************/ - if (!CLOSEv64(CDF->dotFp,NULL,&vStats)) { - CDF->dotFp = NULL; - AbortAccess64 (CDF, noUPDATE, noDELETE); - return FALSE; - } - CDF->dotFp = NULL; - AddTOvStats (&CDF->dotCDFvStats, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "DotCDF..", &vStats); -#endif - if (!sX(CloseVarFiles64(CDF),pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - return FALSE; - } - /*************************************************************************** - * Open dotCDF file with read-write access. If read-write access not is - * allowed, try to return to read-only access. If reopening with read-only - * access fails, free CDF structures as if CDF had been closed. - ***************************************************************************/ - BuildFilePath (CDFt, CDF->CDFname, CDF->no_append, CDF->upper_case_ext, - CDF->version_numbers, 0L, pathName); - CDF->dotFp = V_open64 (pathName, READ_PLUS_a_mode); - if (CDF->dotFp == NULL) { - CDF->dotFp = V_open64 (pathName, READ_ONLY_a_mode); - if (CDF->dotFp == NULL) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - *pStatus = CDF_OPEN_ERROR; - return FALSE; - } - else { - CDF->status = READ_ONLY; - *pStatus = NO_WRITE_ACCESS; /* Don't return yet. */ - } - } - else - CDF->status = READ_WRITE; - /*************************************************************************** - * If the CDF is not compressed, reassign the "working" file pointer and - * reset the cache size (unless deleting). If the CDF is compressed, the - * cache size of the "working" file pointer does not have to be reset. - ***************************************************************************/ - if (CDF->uDotFp == NULL) { - CDF->fp = CDF->dotFp; - if (!forDelete) { - if (!CACHEv64(CDF->fp,CDF->workingCacheSize)) { - *pStatus = BAD_CACHE_SIZE; - AbortAccess64 (CDF, noUPDATE, noDELETE); - return FALSE; - } - } - } - /*************************************************************************** - * Fix various fields (if write access was obtained) unless write access - * was needed to delete the CDF. - ***************************************************************************/ - if (CDF->status == READ_WRITE && !forDelete) { - Int32 versionNew = CDF_LIBRARY_VERSION, - releaseNew = CDF_LIBRARY_RELEASE, - incrementNew = CDF_LIBRARY_INCREMENT; - Int32 versionCur, releaseCur, incrementCur; - uInt32 magicNumber1 = V3magicNUMBER_1, - magicNumber2 = V3magicNUMBER_2u; - char copyRight[CDF_COPYRIGHT_LEN+1]; - /************************************************************************* - * Update magic numbers. - *************************************************************************/ - if (!SEEKv64(CDF->fp,(OFF_T)V3_MAGIC_OFFSET_1,vSEEK_SET)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - *pStatus = CDF_WRITE_ERROR; - return FALSE; - } - if (!Write32_64(CDF->fp,(Int32 *)&magicNumber1)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - *pStatus = CDF_WRITE_ERROR; - return FALSE; - } - if (!Write32_64(CDF->fp,(Int32 *)&magicNumber2)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - *pStatus = CDF_WRITE_ERROR; - return FALSE; - } - /************************************************************************* - * If a V2.0 CDF, correct the EOF field. - *************************************************************************/ - if (CDF->badEOF) { - if (!sX(CorrectV20eof(CDF),pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - return FALSE; - } - CDF->badEOF = FALSE; - } - /************************************************************************* - * If a V2.0 CDF, correct the terminating offset fields. NOTE: Fix these - * fields before the other "fixing" routines (which may depend on these - * fields). - *************************************************************************/ - if (CDF->badTerminatingOffsets) { - if (!sX(CorrectV20offsets(CDF),pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - return FALSE; - } - CDF->badTerminatingOffsets = FALSE; - } - /************************************************************************* - * If prior to CDF V2.1.1, then change the data type associated with the - * "EPOCH" rVariable/rEntries to CDF_EPOCH. - *************************************************************************/ - if (CDF->fakeEPOCH) { - if (!sX(CorrectEPOCH(CDF),pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - return FALSE; - } - CDF->fakeEPOCH = FALSE; - } - /************************************************************************* - * If prior to CDF V2.5, then truncate the CDR for a shorter copyright - * field and shorten each VDR to reclaim the wasted space. - *************************************************************************/ - if (CDF->wastedSpace) { - if (!sX(ShortenCDR(CDF),pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - return FALSE; - } - if (!sX(ShortenVDRs(CDF),pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - return FALSE; - } - CDF->wastedSpace = FALSE; - } - /************************************************************************* - * If prior to CDF V2.5, then convert all assumed scopes to definite - * scopes. - *************************************************************************/ - if (CDF->assumedScopes) { - if (!sX(CorrectScopes(CDF),pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - return FALSE; - } - CDF->assumedScopes = FALSE; - } - /************************************************************************* - * Fix blocking factors for variables having a recVary of NOVARY. - *************************************************************************/ - if (!sX(CorrectBlockingFactors64(CDF),pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - return FALSE; - } - if (isLFS(CDF)) { - /********************************************************************* - * Update version/release/increment and copywright only if a newer - * library version is modifying the CDF. - *********************************************************************/ - if (!sX(ReadCDR64(CDF->fp,V3_CDR_OFFSET64, - CDR_VERSION,&versionCur, - CDR_RELEASE,&releaseCur, - CDR_INCREMENT,&incrementCur, - CDR_NULL),pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - return FALSE; - } - if ((versionCur * 10000 + releaseCur * 100 + incrementCur) < - (versionNew * 10000 + releaseNew * 100 + incrementNew)) { - if (!sX(WriteCDR64(CDF->fp,V3_CDR_OFFSET64, - CDR_VERSION,&versionNew, - CDR_RELEASE,&releaseNew, - CDR_INCREMENT,&incrementNew, - CDR_NULL),pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - return FALSE; - } - CDFcopyRight (copyRight); - NulPad (copyRight, CDF_COPYRIGHT_LEN); - if (!sX(WriteCDR64(CDF->fp,V3_CDR_OFFSET64, - CDR_COPYRIGHT,copyRight, - CDR_NULL),pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - return FALSE; - } - } - } - } - /*************************************************************************** - * Return based on whether or not write access was obtained. - ***************************************************************************/ - return (CDF->status == READ_WRITE); -#endif -} - -/****************************************************************************** -* UpdateTT2000header. -* The leap second last updated header is to be updated from the leap second -* table if it is an earlier day (not zero). -******************************************************************************/ - -STATICforIDL Logical UpdateTT2000header (CDF, pStatus) -struct CDFstruct *CDF; -CDFstatus *pStatus; -{ - long year, month, day; - Int32 tLastUpdated, tLastUpdated2; - /*************************************************************************** - * Check if updated already. - ***************************************************************************/ - if (CDF->tt2000Updated == 1) return TRUE; - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_LEAPSECONDLASTUPDATED,&tLastUpdated, - GDR_NULL),pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - return FALSE; - } - if (tLastUpdated != 0) { -#if defined(vms) - CDFgetLastDateinLeapSecondsTBL (&year, &month, &day); -#else - CDFgetLastDateinLeapSecondsTable (&year, &month, &day); -#endif - tLastUpdated2 = 10000*(Int32)year + 100*(Int32)month + (Int32)day; - if (tLastUpdated2 > tLastUpdated) { - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_LEAPSECONDLASTUPDATED,&tLastUpdated2, - GDR_NULL),pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - return FALSE; - } - } - } - CDF->tt2000Updated = 1; - return TRUE; -} - -/****************************************************************************** -* WriteBuffer64. -* Write occurs at current offset (assumed to have been set before this -* routine is called). On IBM PCs, it is assumed that `nBytes' will not -* exceed 65535. -******************************************************************************/ - -STATICforIDL CDFstatus WriteBuffer64 (CDF, fp, dataType, numElems, buffer) -struct CDFstruct *CDF; -vFILE *fp; -Int32 dataType; -Int32 numElems; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; - size_t nElemBytes = (size_t) CDFelemSize(dataType); - size_t nBytes = (size_t) (numElems * nElemBytes); - double eValue; Int32 elemN; Byte1 *ptr; void *tBuffer; - /**************************************************************************** - * Try to encode/write entire buffer. - ****************************************************************************/ - tBuffer = cdf_AllocateMemory (nBytes, NULL); - if (tBuffer != NULL) { - if (!sX(ConvertBuffer(HostEncoding(),CDF->encoding,CDF->negToPosFp0, - dataType,numElems,buffer,tBuffer),&pStatus)) { - cdf_FreeMemory (tBuffer, NULL); - return pStatus; - } - if (!WRITEv64(tBuffer,1,nBytes,fp)) { - cdf_FreeMemory (tBuffer, NULL); - return CDF_WRITE_ERROR; - } - cdf_FreeMemory (tBuffer, NULL); - return pStatus; - } - /**************************************************************************** - * If that failed, encode/write one element at a time. - ****************************************************************************/ - for (elemN = 0, ptr = buffer; elemN < numElems; elemN++, ptr += nElemBytes) { - if (!sX(ConvertBuffer(HostEncoding(),CDF->encoding, - CDF->negToPosFp0,dataType,1L,ptr, - &eValue),&pStatus)) return pStatus; - if (!WRITEv64(&eValue,1,nElemBytes,fp)) return CDF_WRITE_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* UpdateMaxRec64. -******************************************************************************/ - -STATICforIDL CDFstatus UpdateMaxRec64 (CDF, Var, recNum) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -struct VarStruct *Var; /* In: Pointer to variable. */ -Int32 recNum; /* In: Possible new maximum record number. */ -{ - CDFstatus pStatus = CDF_OK; - if (recNum > Var->maxRec) { - Var->maxRec = recNum; - if (!sX(WriteVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_MAXREC,&recNum, - VDR_NULL),&pStatus)) return pStatus; - } - if (!Var->zVar) { - if (recNum > CDF->rMaxRec) { - CDF->rMaxRec = recNum; - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_rMAXREC,&recNum, - GDR_NULL),&pStatus)) return pStatus; - } - } - return pStatus; -} - -/****************************************************************************** -* CalcDimParms64. -* Calculates a variable's number of dimensions, dimension sizes, and -* dimension variances depending on the current zMode. -******************************************************************************/ - -STATICforIDL CDFstatus CalcDimParms64 (CDF, offset, zVar, numDimsP, dimSizesP, - dimVarysP) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -OFF_T offset; /* In: Offset of VDR. */ -Logical zVar; /* In: TRUE if a true zVariable. FALSE if a - true rVariable. */ -Int32 *numDimsP; /* Out: Number of dimensions. */ -Int32 dimSizesP[]; /* Out: Dimension sizes. */ -Int32 dimVarysP[]; /* Out: Dimension variances. */ -{ - CDFstatus pStatus = CDF_OK; int dN; - Int32 tNumDims, tDimSizes[CDF_MAX_DIMS], tDimVarys[CDF_MAX_DIMS]; - Int32 numDims, dimSizes[CDF_MAX_DIMS], dimVarys[CDF_MAX_DIMS]; - /**************************************************************************** - * Determine `true' parameters. - ****************************************************************************/ - if (zVar) { - if (!sX(ReadVDR64(CDF,CDF->fp,offset,TRUE, - VDR_zNUMDIMS,&tNumDims, - VDR_zDIMSIZES,tDimSizes, - VDR_DIMVARYS,tDimVarys, - VDR_NULL),&pStatus)) return pStatus; - } - else { - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_rNUMDIMS,&tNumDims, - GDR_rDIMSIZES,tDimSizes, - GDR_NULL),&pStatus)) { - return pStatus; - } - if (!sX(ReadVDR64(CDF,CDF->fp,offset,FALSE, - VDR_DIMVARYS,tDimVarys, - VDR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * Determine parameters based on zMode and if r/zVariable. - ****************************************************************************/ - if (CDF->zMode == zMODEon2 && !zVar) { - for (dN = 0, numDims = 0; dN < tNumDims; dN++) { - if (tDimVarys[dN]) { - dimSizes[(int)numDims] = tDimSizes[dN]; - dimVarys[(int)numDims] = VARY; - numDims++; - } - } - } - else { - numDims = tNumDims; - for (dN = 0; dN < tNumDims; dN++) { - dimSizes[dN] = tDimSizes[dN]; - dimVarys[dN] = tDimVarys[dN]; - } - } - /**************************************************************************** - * Assign those values requested. - ****************************************************************************/ - ASSIGNnotNULL (numDimsP, numDims) - ASSIGNnotNULLarray (dimSizesP, numDims, dimSizes) - ASSIGNnotNULLarray (dimVarysP, numDims, dimVarys) - return pStatus; -} - -/****************************************************************************** -* WasteIR64. -******************************************************************************/ - -STATICforIDL CDFstatus WasteIR64 (CDF, wasteOffset, size) -struct CDFstruct *CDF; -OFF_T wasteOffset; -OFF_T size; -{ - CDFstatus pStatus = CDF_OK; - struct UIRstruct64 newUIR, firstUIR, tUIR, nextUIR; - OFF_T tOffset, nextOffset, UIRhead; - /**************************************************************************** - * Begin initializing UIR. - ****************************************************************************/ - newUIR.RecordSize = size; - newUIR.RecordType = UIR_; - /**************************************************************************** - * Check that the internal record being wasted is big enough for the `next' - * and `previous' fields. If not, mark it as wasted but don't place it in - * the linked list of UIRs. Note that there will always be enough room for - * the `size' and `type' fields. If not, an internal logic error has occured. - ****************************************************************************/ - if (size < UIR_BASE_SIZE64) { - if (size < UUIR_BASE_SIZE64) return CDF_INTERNAL_ERROR; - if (!sX(WriteUIR64(CDF->fp,wasteOffset, - UIR_RECORDSIZE,&(newUIR.RecordSize), - UIR_RECORDTYPE,&(newUIR.RecordType), - UIR_NULL),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * Read offset of first UIR. - ****************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_UIRHEAD,&UIRhead, - GDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * Check if no UIRs exist yet. - ****************************************************************************/ - if (UIRhead == 0) { - newUIR.NextUIR = 0; - newUIR.PrevUIR = 0; - if (!sX(WriteUIR64(CDF->fp,wasteOffset, - UIR_RECORD,&newUIR, - UIR_NULL),&pStatus)) return pStatus; - UIRhead = wasteOffset; - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_UIRHEAD,&UIRhead, - GDR_NULL),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * At least one UIR exists, check if the new UIR is before the first UIR. - ****************************************************************************/ - if (wasteOffset < UIRhead) { - if (!sX(ReadUIR64(CDF->fp,UIRhead, - UIR_RECORD,&firstUIR, - UIR_NULL),&pStatus)) return pStatus; - newUIR.NextUIR = UIRhead; - newUIR.PrevUIR = 0; - if (!sX(WriteUIR64(CDF->fp,wasteOffset, - UIR_RECORD,&newUIR, - UIR_NULL),&pStatus)) return pStatus; - firstUIR.PrevUIR = wasteOffset; - if (!sX(WriteUIR64(CDF->fp,UIRhead, - UIR_RECORD,&firstUIR, - UIR_NULL),&pStatus)) return pStatus; - UIRhead = wasteOffset; - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_UIRHEAD,&UIRhead, - GDR_NULL),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * The new UIR is not before the first UIR. Scan the UIRs to find the point - * at which it should be inserted. - ****************************************************************************/ - tOffset = UIRhead; - if (!sX(ReadUIR64(CDF->fp,tOffset, - UIR_RECORD,&tUIR, - UIR_NULL),&pStatus)) return pStatus; - while (tUIR.NextUIR != 0) { - if (wasteOffset < tUIR.NextUIR) { - nextOffset = tUIR.NextUIR; - if (!sX(ReadUIR64(CDF->fp,nextOffset, - UIR_RECORD,&nextUIR, - UIR_NULL),&pStatus)) return pStatus; - newUIR.NextUIR = tUIR.NextUIR; - newUIR.PrevUIR = tOffset; - if (!sX(WriteUIR64(CDF->fp,wasteOffset, - UIR_RECORD,&newUIR, - UIR_NULL),&pStatus)) return pStatus; - tUIR.NextUIR = wasteOffset; - if (!sX(WriteUIR64(CDF->fp,tOffset, - UIR_RECORD,&tUIR, - UIR_NULL),&pStatus)) return pStatus; - nextUIR.PrevUIR = wasteOffset; - if (!sX(WriteUIR64(CDF->fp,nextOffset, - UIR_RECORD,&nextUIR, - UIR_NULL),&pStatus)) return pStatus; - return pStatus; - } - tOffset = tUIR.NextUIR; - if (!sX(ReadUIR64(CDF->fp,tOffset, - UIR_RECORD,&tUIR, - UIR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * The new UIR is going to be the last UIR. - ****************************************************************************/ - newUIR.NextUIR = 0; - newUIR.PrevUIR = tOffset; - if (!sX(WriteUIR64(CDF->fp,wasteOffset, - UIR_RECORD,&newUIR, - UIR_NULL),&pStatus)) return pStatus; - tUIR.NextUIR = wasteOffset; - if (!sX(WriteUIR64(CDF->fp,tOffset, - UIR_RECORD,&tUIR, - UIR_NULL),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* AllocateIR64. -******************************************************************************/ - -STATICforIDL CDFstatus AllocateIR64 (CDF, size, offset) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -OFF_T size; /* In: Size of internal record (bytes). */ -OFF_T *offset; /* Out: Offset of allocated internal record. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 uir_ = UIR_; - OFF_T tSize, sOffset, eOffset, UIRhead, eof; - struct UIRstruct64 sUIR, eUIR; - /**************************************************************************** - * Read EOF and offset of first UIR from GDR. - ****************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_UIRHEAD,&UIRhead, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * If UIRs exist, try to use one or more of them (if contiguous) for the new - * internal record. - ****************************************************************************/ - if (UIRhead != 0) { - sOffset = UIRhead; - if (!sX(ReadUIR64(CDF->fp,sOffset, - UIR_RECORD,&sUIR, - UIR_NULL),&pStatus)) return pStatus; - eOffset = sOffset; - eUIR = sUIR; - tSize = sUIR.RecordSize; - for (;;) { - /*********************************************************************** - * Check if the starting to ending UIRs are the exact size needed. - ***********************************************************************/ - if (size == tSize) { - if (!sX(RemoveUIRs64(CDF,sOffset,eOffset),&pStatus)) return pStatus; - if (!sX(WriteIrSize64(CDF->fp,sOffset,&size),&pStatus)) return pStatus; - if (!sX(WriteIrType64(CDF->fp,sOffset,&uir_),&pStatus)) return pStatus; - *offset = sOffset; - return pStatus; - } - /*********************************************************************** - * Check if the starting to ending UIRs are big enough for the new - * internal record and for a new UIR to fill the remaining space. - ***********************************************************************/ - if (size + UIR_BASE_SIZE64 <= tSize) { - if (!sX(RemoveUIRs64(CDF,sOffset,eOffset),&pStatus)) return pStatus; - if (!sX(WasteIR64(CDF,sOffset+size,tSize-size),&pStatus)) { - return pStatus; - } - if (!sX(WriteIrSize64(CDF->fp,sOffset,&size),&pStatus)) return pStatus; - if (!sX(WriteIrType64(CDF->fp,sOffset,&uir_),&pStatus)) return pStatus; - *offset = sOffset; - return pStatus; - } - /*********************************************************************** - * Check if the end of the UIRs has been reached. If so, check if the - * ending UIR is the last IR in the dotCDF file. - ***********************************************************************/ - if (eUIR.NextUIR == 0) { - if (eOffset + (OFF_T) eUIR.RecordSize == eof) { - /******************************************************************* - * The ending UIR is the last internal record in the CDF. Check to - * see if after allocating the new internal record less than - * UIR_BASE_SIZE64 bytes will remain before the EOF. If so, waste an - * internal record at the location of those bytes so that a UIR is - * at the end (rather than stranded bytes). - *******************************************************************/ - if (!sX(RemoveUIRs64(CDF,sOffset,eOffset),&pStatus)) return pStatus; - if (size < tSize) { - if (!sX(WasteIR64(CDF,sOffset+size, - UIR_BASE_SIZE64),&pStatus)) return pStatus; - eof = sOffset + (OFF_T) (size + UIR_BASE_SIZE64); - } - else - eof = sOffset + (OFF_T) size; - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - if (!sX(WriteIrSize64(CDF->fp, - sOffset, - &size),&pStatus)) return pStatus; - if (!sX(WriteIrType64(CDF->fp, - sOffset, - &uir_),&pStatus)) return pStatus; - *offset = sOffset; - return pStatus; - } - else { - /******************************************************************* - * Non-UIRs follow the ending UIR. The new internal record will - * have to be allocated at the EOF. - *******************************************************************/ - *offset = eof; - if (!sX(WriteIrSize64(CDF->fp,eof,&size),&pStatus)) return pStatus; - if (!sX(WriteIrType64(CDF->fp,eof,&uir_),&pStatus)) return pStatus; - eof += (OFF_T) size; - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - return pStatus; - } - } - /*********************************************************************** - * If the next UIR is contiguous with the ending UIR, make it the ending - * UIR. Otherwise, make the next UIR the starting and ending UIRs. - ***********************************************************************/ - if (eOffset + eUIR.RecordSize == eUIR.NextUIR) { - eOffset = eUIR.NextUIR; - if (!sX(ReadUIR64(CDF->fp,eOffset, - UIR_RECORD,&eUIR, - UIR_NULL),&pStatus)) return pStatus; - tSize += eUIR.RecordSize; - } - else { - sOffset = eUIR.NextUIR; - if (!sX(ReadUIR64(CDF->fp,sOffset, - UIR_RECORD,&sUIR, - UIR_NULL),&pStatus)) return pStatus; - eOffset = sOffset; - eUIR = sUIR; - tSize = sUIR.RecordSize; - } - } - } - /**************************************************************************** - * No UIRs exist. The new internal record will have to be allocated at the - * EOF. - ****************************************************************************/ - *offset = eof; - if (!sX(WriteIrSize64(CDF->fp,eof,&size),&pStatus)) return pStatus; - if (!sX(WriteIrType64(CDF->fp,eof,&uir_),&pStatus)) return pStatus; - eof += size; - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* ResizeIR64. -******************************************************************************/ - -STATICforIDL CDFstatus ResizeIR64 (CDF, curOffset, newSize, newOffset, move, - success) -struct CDFstruct *CDF; -OFF_T curOffset; /* In: Current offset of internal record. */ -OFF_T newSize; /* In: New size of internal record. This may be - smaller or larger than the current size. */ -OFF_T *newOffset; /* Out: New offset of internal record. This variable - is not modified if an error occurs or the internal - record cannot be extended (when `move' is FALSE). */ -Logical move; /* In: TRUE if the internal record can be moved if - necessary. */ -Logical *success; /* Out: TRUE if the internal record was successfully - extended (whether or not it had to be moved). */ -{ - CDFstatus pStatus = CDF_OK; OFF_T curSize; - OFF_T eof; - /**************************************************************************** - * Determine current size of internal record. - ****************************************************************************/ - if (!sX(ReadIrSize64(CDF->fp,curOffset,&curSize),&pStatus)) return pStatus; - /**************************************************************************** - * Check sizes... - ****************************************************************************/ - if (newSize > curSize) { - /************************************************************************** - * The internal record is growing. First check if it is the last one in - * the CDF. - **************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - if (curOffset + (OFF_T) curSize == eof) { - /************************************************************************ - * Last internal record. Simply extend the CDF. - ************************************************************************/ - ASSIGNnotNULL (newOffset, curOffset) - eof += (OFF_T) (newSize - curSize); - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - if (!sX(WriteIrSize64(CDF->fp, - curOffset, - &newSize),&pStatus)) return pStatus; - ASSIGNnotNULL (success, TRUE) - return pStatus; - } - else { - /************************************************************************ - * Not the last internal record. If the internal record may be moved, - * first mark it as unused and then allocate a new internal record. - * Marking it unused first allows the possibility that if will be used - * as part of the allocated internal record. If the internal record can - * not be moved, check if unused records immediately follow. - ************************************************************************/ - if (move) { - if (!sX(WasteIR64(CDF,curOffset,curSize),&pStatus)) return pStatus; - if (!sX(AllocateIR64(CDF,newSize,newOffset),&pStatus)) return pStatus; - ASSIGNnotNULL (success, TRUE) - return pStatus; - } - else { - Int32 irType; - OFF_T sOffset, eOffset, tSize, UIRhead; - struct UIRstruct64 sUIR, eUIR; - /********************************************************************** - * First check if there are any UIRs in the CDF. This is done because - * CDF V2.5.0* (alpha/beta) created UIRs without the next and previous - * UIR fields and didn't use the `UIRhead' field in the GDR. Because - * we don't want to use UIRs in those CDFs (because they are not the - * same as the current UIRs), this will keep us from doing so (because - * the `UIRhead' fields will always contain zero if a V2.5.0* CDF). - **********************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_UIRHEAD,&UIRhead, - GDR_NULL),&pStatus)) return pStatus; - if (UIRhead == 0) { - ASSIGNnotNULL (success, FALSE) - return pStatus; - } - /********************************************************************** - * Read the internal record which immediately follows the internal - * record being resized. If it is a UIR make it the starting UIR. - * ---------------------------- DANGER --------------------------------- - * Don't try to read an entire UIR. First read only the record type - * field and check if it is UIR_. Then read the entire UIR. This is - * because the next internal record could be smaller than a UIR (or - * larger but not entirely written yet [eg. a VVR]). - **********************************************************************/ - sOffset = curOffset + curSize; - if (!sX(ReadIrType64(CDF->fp,sOffset,&irType),&pStatus)) return pStatus; - if (irType != UIR_) { - ASSIGNnotNULL (success, FALSE) - return pStatus; - } - if (!sX(ReadUIR64(CDF->fp,sOffset, - UIR_RECORD,&sUIR, - UIR_NULL),&pStatus)) return pStatus; - tSize = curSize + sUIR.RecordSize; - eOffset = sOffset; - eUIR = sUIR; - for (;;) { - /******************************************************************* - * Check if the exact amount of available space has been found. - *******************************************************************/ - if (newSize == tSize) { - if (!sX(RemoveUIRs64(CDF,sOffset,eOffset),&pStatus)) return pStatus; - if (!sX(WriteIrSize64(CDF->fp, - curOffset, - &newSize),&pStatus)) return pStatus; - ASSIGNnotNULL (newOffset, curOffset) - ASSIGNnotNULL (success, TRUE) - return pStatus; - } - /******************************************************************* - * Check if enough available space has been found to increase the - * internal record and then create a new UIR in the remaining space. - *******************************************************************/ - if (newSize + UIR_BASE_SIZE64 <= tSize) { - if (!sX(RemoveUIRs64(CDF,sOffset,eOffset),&pStatus)) return pStatus; - if (!sX(WasteIR64(CDF,curOffset+newSize,tSize-newSize),&pStatus)) { - return pStatus; - } - if (!sX(WriteIrSize64(CDF->fp, - curOffset, - &newSize),&pStatus)) return pStatus; - ASSIGNnotNULL (newOffset, curOffset) - ASSIGNnotNULL (success, TRUE) - return pStatus; - } - /******************************************************************* - * Check if the end of the UIRs has been reached. - *******************************************************************/ - if (eUIR.NextUIR == 0) { - /***************************************************************** - * If the ending UIR is at the EOF, then the internal record can - * be extended beyond the EOF or up to it with the creation of a - * new UIR at the very end. - *****************************************************************/ - if (eOffset + (OFF_T) eUIR.RecordSize == eof) { - if (!sX(RemoveUIRs64(CDF,sOffset,eOffset),&pStatus)) return - pStatus; - if (newSize < tSize) { - if (!sX(WasteIR64(CDF,curOffset+newSize, - UIR_BASE_SIZE64),&pStatus)) return pStatus; - eof = curOffset + (OFF_T) (newSize + UIR_BASE_SIZE64); - } - else - eof = curOffset + (OFF_T) newSize; - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - if (!sX(WriteIrSize64(CDF->fp, - curOffset, - &newSize),&pStatus)) return pStatus; - ASSIGNnotNULL (newOffset, curOffset) - ASSIGNnotNULL (success, TRUE) - return pStatus; - } - else { - ASSIGNnotNULL (success, FALSE) - return pStatus; - } - } - /******************************************************************* - * If the next UIR is contiguous with the ending UIR, make it the - * ending UIR. - *******************************************************************/ - if (eOffset + eUIR.RecordSize == eUIR.NextUIR) { - eOffset = eUIR.NextUIR; - if (!sX(ReadUIR64(CDF->fp,eOffset, - UIR_RECORD,&eUIR, - UIR_NULL),&pStatus)) return pStatus; - tSize += eUIR.RecordSize; - } - else { - ASSIGNnotNULL (success, FALSE) - return pStatus; - } - } - } - } - } - else { - /************************************************************************** - * The internal record is shrinking. Check if it can be shrunk in place - * and a UIR created to occupy the extra space. If not, waste it and then - * allocate a new internal record (if moving it is allowed). - **************************************************************************/ - if (newSize <= (curSize - UIR_BASE_SIZE64)) { - if (!sX(WasteIR64(CDF,curOffset + newSize, - curSize - newSize),&pStatus)) return pStatus; - if (!sX(WriteIrSize64(CDF->fp, - curOffset, - &newSize),&pStatus)) return pStatus; - ASSIGNnotNULL (newOffset, curOffset) - ASSIGNnotNULL (success, TRUE) - } - else { - if (move) { - if (!sX(WasteIR64(CDF,curOffset,curSize),&pStatus)) return pStatus; - if (!sX(AllocateIR64(CDF,newSize,newOffset),&pStatus)) return pStatus; - ASSIGNnotNULL (success, TRUE) - } - else { - ASSIGNnotNULL (success, FALSE) - } - } - return pStatus; - } -} - -/****************************************************************************** -* RemoveUIRs64. -******************************************************************************/ - -STATICforIDL CDFstatus RemoveUIRs64 (CDF, sOffset, eOffset) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -OFF_T sOffset; /* In: Offset of starting UIR. */ -OFF_T eOffset; /* In: Offset of ending UIR. */ -{ - CDFstatus pStatus = CDF_OK; - struct UIRstruct64 sUIR, eUIR; - OFF_T UIRhead; - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_UIRHEAD,&UIRhead, - GDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadUIR64(CDF->fp,sOffset, - UIR_RECORD,&sUIR, - UIR_NULL),&pStatus)) return pStatus; - if (!sX(ReadUIR64(CDF->fp,eOffset, - UIR_RECORD,&eUIR, - UIR_NULL),&pStatus)) return pStatus; - if (UIRhead == sOffset) { - UIRhead = eUIR.NextUIR; - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_UIRHEAD,&UIRhead, - GDR_NULL),&pStatus)) return pStatus; - } - else { - struct UIRstruct64 prevUIR; - if (!sX(ReadUIR64(CDF->fp,sUIR.PrevUIR, - UIR_RECORD,&prevUIR, - UIR_NULL),&pStatus)) return pStatus; - prevUIR.NextUIR = eUIR.NextUIR; - if (!sX(WriteUIR64(CDF->fp,sUIR.PrevUIR, - UIR_RECORD,&prevUIR, - UIR_NULL),&pStatus)) return pStatus; - } - if (eUIR.NextUIR != 0) { - struct UIRstruct64 nextUIR; - if (!sX(ReadUIR64(CDF->fp,eUIR.NextUIR, - UIR_RECORD,&nextUIR, - UIR_NULL),&pStatus)) return pStatus; - nextUIR.PrevUIR = sUIR.PrevUIR; - if (!sX(WriteUIR64(CDF->fp,eUIR.NextUIR, - UIR_RECORD,&nextUIR, - UIR_NULL),&pStatus)) return pStatus; - } - return pStatus; -} - -/****************************************************************************** -* CorrectBlockingFactors64. -* It is assumed that the last rVDR offset has already been fixed. -******************************************************************************/ - -STATICforIDL CDFstatus CorrectBlockingFactors64 (CDF) -struct CDFstruct *CDF; -{ - CDFstatus pStatus = CDF_OK; Int32 nVars; OFF_T vdrOffset; int varN; - Logical zVar; struct VDRstruct64 VDR; struct VarStruct **Vars, *Var; - for (zVar = 0; zVar <= 1; zVar++) { - Vars = BOO(zVar,CDF->zVars,CDF->rVars); - nVars = BOO(zVar,CDF->NzVars,CDF->NrVars); - for (varN = 0; varN < nVars; varN++) { - Var = Vars[varN]; - if (Var == NULL) { - if (!sX(FindVarByNumber64(CDF,(Int32)varN, - zVar,&vdrOffset),&pStatus)) return pStatus; - } - else - vdrOffset = Var->VDRoffset64; - if (!sX(ReadVDR64(CDF,CDF->fp,vdrOffset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) return pStatus; - if (!RECvaryBITset(VDR.Flags) && VDR.blockingFactor > 1) { - VDR.blockingFactor = 1; - if (!sX(WriteVDR64(CDF,CDF->fp,vdrOffset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) return pStatus; - if (Var != NULL) { - if (!sX(CalcBF64(CDF,Var),&pStatus)) return pStatus; - } - } - } - } - return pStatus; -} - -/****************************************************************************** -* AbortAccess64. -******************************************************************************/ - -STATICforIDL void AbortAccess64 (CDF, updateCDF, deleteCDF) -struct CDFstruct *CDF; -Logical updateCDF; /* Update "working" dotCDF file (if read/write - access has been obtained)? */ -Logical deleteCDF; /* Delete CDF file(s)? */ -{ - /**************************************************************************** - * If the CDF is to be deleted do that first and then skip the updating and/or - * closing of the CDF files. - ****************************************************************************/ - if (deleteCDF) { - DeleteCDFfiles64 (CDF); - if (CDF->uDotFp != NULL) V_delete64 (CDF->uDotFp, NULL); - } - else { - /************************************************************************** - * Update the dotCDF file if requested, if the current access is read/write, - * and if the "working" dotCDF file has not already been closed or deleted. - **************************************************************************/ - if (CDF->status == READ_WRITE && updateCDF && - (CDF->fp == CDF->dotFp || CDF->fp == CDF->uDotFp)) UpdateDotCDF64 (CDF); - /************************************************************************** - * Close all of the CDF files if they are not already closed (or deleted). - **************************************************************************/ - if (CDF->dotFp != NULL) V_close64 (CDF->dotFp, - ((updateCDF==UPDATE)?CDF:NULL), NULL); - if (CDF->uDotFp != NULL) V_close64 (CDF->uDotFp, - ((updateCDF==UPDATE)?CDF:NULL), NULL); - CloseVarFiles64 (CDF); - } - /**************************************************************************** - * Delete the scratch files that still exist. - ****************************************************************************/ - if (CDF->stage.fp != NULL) V_delete64 (CDF->stage.fp, NULL); - if (CDF->compressFp != NULL) V_delete64 (CDF->compressFp, NULL); - /**************************************************************************** - * Free the memory used by the CDF. - ****************************************************************************/ - FreeCDFid (CDF, TRUE); - return; -} - -/****************************************************************************** -* DeleteCDFfiles64. -* The files may be open or closed. This routine does not delete the -* uncompressed dotCDF file (if one exists). -******************************************************************************/ - -STATICforIDL CDFstatus DeleteCDFfiles64 (CDF) -struct CDFstruct *CDF; -{ - char tmpFile[DU_MAX_PATH_LEN+1]; CDFstatus pStatus = CDF_OK; - /************************************************************************** - * Delete dotCDF file. - **************************************************************************/ - if (CDF->dotFp == NULL) { - BuildFilePath (CDFt, CDF->CDFname, CDF->no_append, CDF->upper_case_ext, - CDF->version_numbers, INT32_ZERO, tmpFile); - if (!CDFdeleteFile(tmpFile)) sX (CDF_DELETE_ERROR, &pStatus); - } - else { - if (!DELETEv64(CDF->dotFp,NULL)) sX (CDF_DELETE_ERROR, &pStatus); - CDF->dotFp = NULL; - } - /************************************************************************** - * Delete the variable files (if multi-file). Both rVariable and zVariable - * files are deleted. - **************************************************************************/ - if (!CDF->singleFile) { - int varN; - for (varN = 0; varN < CDF->NrVars; varN++) { - struct VarStruct *Var = CDF->rVars[varN]; - if (Var != NULL) { - if (Var->fp != NULL) { - if (!DELETEv64(Var->fp,NULL)) sX (VAR_DELETE_ERROR, &pStatus); - Var->fp = NULL; - continue; - } - } - BuildFilePath (Vt, CDF->CDFname, CDF->no_append, CDF->upper_case_ext, - CDF->version_numbers, varN, tmpFile); - if (!CDFdeleteFile(tmpFile)) sX (VAR_DELETE_ERROR, &pStatus); - } - for (varN = 0; varN < CDF->NzVars; varN++) { - struct VarStruct *Var = CDF->zVars[varN]; - if (Var != NULL) { - if (Var->fp != NULL) { - if (!DELETEv64(Var->fp,NULL)) sX (VAR_DELETE_ERROR, &pStatus); - Var->fp = NULL; - continue; - } - } - BuildFilePath (Zt, CDF->CDFname, CDF->no_append, CDF->upper_case_ext, - CDF->version_numbers, varN, tmpFile); - if (!CDFdeleteFile(tmpFile)) sX (VAR_DELETE_ERROR, &pStatus); - } - } - return pStatus; -} - -/****************************************************************************** -* DeleteEntry64. -******************************************************************************/ - -STATICforIDL CDFstatus DeleteEntry64 (CDF, aOffset, eOffset) -struct CDFstruct *CDF; -OFF_T aOffset; -OFF_T eOffset; -{ - CDFstatus pStatus = CDF_OK; - struct ADRstruct64 ADR; - struct AEDRstruct64 AEDR, AEDRt; - OFF_T prevEntryOffset; - Logical zEntry; - /**************************************************************************** - * Read the ADR and the AEDR being deleted. - ****************************************************************************/ - if (!sX(ReadADR64(CDF->fp,aOffset, - ADR_RECORD,&ADR, - ADR_NULL),&pStatus)) return pStatus; - if (!sX(ReadAEDR64(CDF->fp,eOffset, - AEDR_RECORD,&AEDR,NULL, - AEDR_NULL),&pStatus)) return pStatus; - zEntry = (AEDR.RecordType == AzEDR_); - /**************************************************************************** - * Remove the AEDR from the list of entries. - ****************************************************************************/ - if (!sX(FindPrevEntry64(CDF,aOffset,eOffset, - zEntry,&prevEntryOffset),&pStatus)) return pStatus; - if (prevEntryOffset == 0) { - /************************************************************************** - * The first entry on the linked list is being deleted. Point the ADR to - * the entry being pointed to by the entry being deleted. - **************************************************************************/ - if (zEntry) - ADR.AzEDRhead = AEDR.AEDRnext; - else - ADR.AgrEDRhead = AEDR.AEDRnext; - } - else { - /************************************************************************** - * The entry being deleted is not the first entry on the linked list. Point - * the previous entry to the entry pointed to by the entry being deleted. - **************************************************************************/ - if (!sX(ReadAEDR64(CDF->fp,prevEntryOffset, - AEDR_RECORD,&AEDRt,NULL, - AEDR_NULL),&pStatus)) return pStatus; - AEDRt.AEDRnext = AEDR.AEDRnext; - if (!sX(WriteAEDR64(CDF,CDF->fp,prevEntryOffset, - AEDR_RECORD,&AEDRt,NULL, - AEDR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * Decrement the number of entries and recalculate the maximum entry (if - * necessary). - ****************************************************************************/ - if (zEntry) - ADR.NzEntries--; - else - ADR.NgrEntries--; - if (BOO(zEntry,ADR.MAXzEntry,ADR.MAXgrEntry) == AEDR.Num) { - Int32 maxEntry = NO_ENTRY; - OFF_T tOffset = BOO(zEntry,ADR.AzEDRhead,ADR.AgrEDRhead); - while (tOffset != 0) { - if (!sX(ReadAEDR64(CDF->fp,tOffset, - AEDR_RECORD,&AEDRt,NULL, - AEDR_NULL),&pStatus)) return pStatus; - maxEntry = MaxInt32 (maxEntry, AEDRt.Num); - tOffset = AEDRt.AEDRnext; - } - if (zEntry) - ADR.MAXzEntry = maxEntry; - else - ADR.MAXgrEntry = maxEntry; - } - /**************************************************************************** - * Rewrite the ADR and waste the AEDR (of the entry being deleted). - ****************************************************************************/ - if (!sX(WriteADR64(CDF->fp,aOffset, - ADR_RECORD,&ADR, - ADR_NULL),&pStatus)) return pStatus; - if (!sX(WasteIR64(CDF,eOffset,AEDR.RecordSize),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* PadUnRecords64. -* Pad all allocated records within the first/last record range. Note that -* in the case of sparse records some of the records may not be allocated (and -* should not be padded of course). -******************************************************************************/ - -STATICforIDL CDFstatus PadUnRecords64 (CDF, Var, firstRec, lastRec) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 firstRec; -Int32 lastRec; -{ - CDFstatus pStatus = CDF_OK; OFF_T offset; int how; void *buffer; - Int32 recNum, nRecords, toRec, lastRecInVVR; Logical found; - /**************************************************************************** - * Pad the records. - * NOTE: Padding in a single-file CDF could be made more efficient by not - * allocating/freeing the pad buffer over and over... - ****************************************************************************/ - if (CDF->singleFile) { - /************************************************************************** - * Single-file...first determine the first allocated record to be padded. - **************************************************************************/ - if (!sX(NextRecord64(CDF,Var->VDRoffset64,Var->zVar, - firstRec,&recNum,&found),&pStatus)) return pStatus; - if (!found) return pStatus; - /************************************************************************** - * While the first record to be padded is within the range... - **************************************************************************/ - while (recNum <= lastRec) { - if (!sX(RecordByteOffset64(CDF,Var,recNum, - &offset),&pStatus)) return pStatus; - if (!sX(SearchForRecord64(CDF,Var->VDRoffset64, - Var->zVar,recNum, - NULL,&lastRecInVVR, - NULL,NULL),&pStatus)) return pStatus; - toRec = MINIMUM(lastRec,lastRecInVVR); - nRecords = toRec - recNum + 1; - if (!sX(BuildPadBuffer64(CDF,Var,nRecords, - &how,&buffer,TRUE),&pStatus)) return pStatus; - if (!sX(WritePadValues64(Var,CDF->fp,offset, - nRecords,how,buffer),&pStatus)) { - cdf_FreeMemory (buffer, NULL); - return pStatus; - } - cdf_FreeMemory (buffer, NULL); - recNum += nRecords; - /************************************************************************ - * Determine the next `first' record to be padded. - ************************************************************************/ - if (!sX(NextRecord64(CDF,Var->VDRoffset64,Var->zVar, - recNum,&recNum,&found),&pStatus)) return pStatus; - if (!found) return pStatus; - } - } - else { - /************************************************************************** - * Multi-file... - **************************************************************************/ - if (!sX(RecordByteOffset64(CDF,Var, - firstRec, - &offset),&pStatus)) return pStatus; - nRecords = lastRec - firstRec + 1; - if (!sX(BuildPadBuffer64(CDF,Var,nRecords, - &how,&buffer,TRUE),&pStatus)) return pStatus; - if (!sX(WritePadValues64(Var,Var->fp,offset,nRecords,how,buffer),&pStatus)) { - cdf_FreeMemory (buffer, NULL); - return pStatus; - } - cdf_FreeMemory (buffer, NULL); - } - return pStatus; -} - -/****************************************************************************** -* WritePadValues64. -* NOTE: It is assumed that the records are contiguous (in a single-file CDF) -* and that on a DOS machine the buffer does not exceed 64K bytes. It is also -* assumed that the values have already been encoded for the CDF. -******************************************************************************/ - -STATICforIDL CDFstatus WritePadValues64 (Var, fp, offset, nRecords, how, buffer) -struct VarStruct *Var; -vFILE *fp; -OFF_T offset; -Int32 nRecords; -int how; -void *buffer; -{ - Int32 nBytes, nValues, recX, valueX; - /**************************************************************************** - * Seek to desired offset. - ****************************************************************************/ - if (!SEEKv64(fp,offset,vSEEK_SET)) return VAR_WRITE_ERROR; - /**************************************************************************** - * Write records... - ****************************************************************************/ - switch (how) { - case ALLrecordsATonce: - nBytes = nRecords * Var->NphyRecBytes; - if (!WRITEv64(buffer,(size_t)nBytes,1,fp)) return VAR_WRITE_ERROR; - break; - case ONErecordATaTIME: - for (recX = 0; recX < nRecords; recX++) { - if (!WRITEv64(buffer,(size_t)Var->NphyRecBytes,1,fp)) { - return VAR_WRITE_ERROR; - } - } - break; - case ONEvalueATaTIME: - nValues = nRecords * Var->NphyRecValues; - for (valueX = 0; valueX < nValues; valueX++) { - if (!WRITEv64(buffer,(size_t)Var->NvalueBytes,1,fp)) { - return VAR_WRITE_ERROR; - } - } - break; - } - return CDF_OK; -} - -/****************************************************************************** -* SetLeapSecondLastUpdate. -* Set the last updated date for CDF that has TT2000 variable. -******************************************************************************/ - -STATICforIDL CDFstatus SetLeapSecondLastUpdate (CDF, Var, zVar) -struct CDFstruct *CDF; -struct VarStruct *Var; /* the variable */ -Logical zVar; -{ - Int32 dataType, LeapSecondLastUpdated, version, release, increment; - long year, month, day; - CDFstatus pStatus = CDF_OK; - if (CDF->leapSecondUpdated == 1) return CDF_OK; - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,zVar, - VDR_DATATYPE,&dataType, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - return pStatus; - } - if (dataType != CDF_TIME_TT2000) return CDF_OK; - if (!sX(ReadCDR64(CDF->fp,V3_CDR_OFFSET64, - CDR_VERSION,&version, - CDR_RELEASE,&release, - CDR_INCREMENT,&increment, - CDR_NULL),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - return pStatus; - } - /********************************************************************* - * Update version/release/increment and copywright only if a newer - * library version is modifying the CDF. - *********************************************************************/ - if (!PriorTo("3.6.0",version,release,increment)) { -#if defined(vms) - CDFgetLastDateinLeapSecondsTBL (&year, &month, &day); -#else - CDFgetLastDateinLeapSecondsTable (&year, &month, &day); -#endif - LeapSecondLastUpdated = (Int32) (10000*year + 100*month + day); - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_LEAPSECONDLASTUPDATED,&LeapSecondLastUpdated, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, CDFDELETE); - cdf_FreeMemory (CDF, NULL); - return pStatus; - } - CDF->leapSecondUpdated = 1; - } - return CDF_OK; -} diff --git a/cdf36_3-dist/src/lib/cdfmisc2.c b/cdf36_3-dist/src/lib/cdfmisc2.c deleted file mode 100644 index 22b2dac..0000000 --- a/cdf36_3-dist/src/lib/cdfmisc2.c +++ /dev/null @@ -1,2783 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF library miscellaneous functions, part 2. -* -* Version 1.3b, 4-Mar-97, Hughes STX. -* -* Modification history: -* -* V1.0 15-Dec-94, J Love Original version. -* V1.1 6-Jan-95, J Love Encode/decode changes. More cache-residency. -* V1.1a 20-Jan-95, J Love IRIX 6.0 (64-bit). -* V1.1b 15-Mar-95, J Love Solaris 2.3 IDL i/f. Fixed `recNum' parameter -* of `LastAllocatedRecord'. Gnu C on OSF/1. -* V1.2 21-Mar-95, J Love POSIX. -* V1.2a 18-Apr-95, J Love More POSIX. -* V1.2b 13-Jun-95, J Love Linux. -* V1.2c 7-Sep-95, J Love CDFexport-related changes. Fixed possible -* memory leak. -* V1.3 5-Sep-96, J Love CDF V2.6. -* V1.3a 21-Feb-97, J Love Removed RICE. -* V1.3b 4-Mar-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V2.0 08-Apr-04, M Liu Modified LocateCurrentVar function to save -* the current selected variable's offset. -* Modified FindVarByNumber and FindVarByName -* functions to start searching for the variable -* from the current selected variable, if it's -* cwselected, instead of always from the -* beginning. Remove the calls to FindVarByNumber -* if a variable is already selected. -* V2.1 04-May-04, M Liu Corrected Int32ToCDFid and CDFidToInt32 to -* handle 64-bit for Solaris/sparc. -* V2.2 21-Jun-05, M Liu Corrected Int32ToCDFid and CDFidToInt32 to -* handle 64-bit Intel/AMD running Linux. -* V3.2 20-Jun-07, D Berger Modified the "FindAttr...", "FindEntry..." -* routines, and the "SetCUR..." routines and -* added ResetReadOnlyState to handle READONLYon -* mode. -* V3.5 09-Aug-13, M Liu Modified CDFidToInt32 and Int32ToCDFid so -* 8-byte CDFid can be preserved and restored -* from the 4-byte id in Fortran. -* -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* sX. -* Determine what should be done with a status code. For each call to -* `CDFlib', status is returned as follows... -* -* 1. The first ERROR encountered terminates the call and is returned. This -* routine will not overwrite an existing error code. -* 2. The last WARNING encountered is returned. INFOs encountered after a -* WARNING are ignored. -* 3. In the absence of any WARNINGs, the last INFO is returned. -* 4. In the absence of any WARNINGs or INFOs, CDF_OK is returned. -* -* This routine returns FALSE if the pending status code is an ERROR; otherwise -* it returns TRUE. -* -******************************************************************************/ - -VISIBLE_PREFIX Logical sX (cStatus, pStatus) -CDFstatus cStatus; /* Status code to be checked. */ -CDFstatus *pStatus; /* Pending status code. */ -{ - if (cStatus == CDF_OK) return TRUE; /* Ok, do nothing. */ - if (cStatus < CDF_WARN) { /* Error. */ - if (*pStatus > CDF_WARN) *pStatus = cStatus; - return FALSE; - } - if (cStatus > CDF_OK) { /* Info. */ - if (CDF_OK <= *pStatus) *pStatus = cStatus; - return TRUE; - } - *pStatus = cStatus; /* Warning. */ - return TRUE; -} - -/****************************************************************************** -* LocateCurrentVar. -******************************************************************************/ - -STATICforIDL CDFstatus LocateCurrentVar (CDF, zOp, offset, zVar, Var) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -Logical zOp; /* In: TRUE if current zVariable is to be - accessed; FALSE if current rVariable. N/A - if zMode is on (since the current zVariable - number will always be used). */ -Int32 *offset; /* Out: Offset of the current variable's VDR. - This may be a NULL pointer. */ -Logical *zVar; /* Out: TRUE if a true zVariable; FALSE if - a true rVariable. This may be a NULL - pointer. */ -struct VarStruct **Var; /* Out: Pointer to variable. This will be NULL - if the variable has yet to be initialized. - This may be a NULL pointer. */ -{ - CDFstatus tStatus; - Int32 tOffset; - /**************************************************************************** - * Pass back the offset of the VDR. - ****************************************************************************/ - if (zModeON(CDF)) { - if (CDF->CURzVarNum < CDF->NrVars) { - ASSIGNnotNULL(zVar, FALSE) - tStatus = FindVarByNumber (CDF, CDF->CURzVarNum, FALSE, &tOffset); - if (StatusOK(tStatus)) { - ASSIGNnotNULL (Var, CDF->rVars[(int)CDF->CURzVarNum]) - ASSIGNnotNULL (offset, tOffset) - CDF->CURzVarOffset = tOffset; - } - } - else { - ASSIGNnotNULL(zVar, TRUE) - tStatus = FindVarByNumber (CDF, CDF->CURzVarNum - CDF->NrVars, TRUE, - &tOffset); - if (StatusOK(tStatus)) { - ASSIGNnotNULL (Var, CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]) - ASSIGNnotNULL (offset, tOffset) - CDF->CURzVarOffset = tOffset; - } - } - } - else { - ASSIGNnotNULL (zVar, zOp) - tStatus = FindVarByNumber (CDF,BOO(zOp,CDF->CURzVarNum, - CDF->CURrVarNum),zOp,&tOffset); - if (StatusOK(tStatus)) { - ASSIGNnotNULL (Var, BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum])) - ASSIGNnotNULL (offset, tOffset) - if (zOp) - CDF->CURzVarOffset = tOffset; - else - CDF->CURrVarOffset = tOffset; - } - } - return tStatus; -} - -/****************************************************************************** -* CurrentVarMode. -******************************************************************************/ - -STATICforIDL Logical CurrentVarMode (CDF, zOp) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -Logical zOp; /* In: TRUE if current zVariable is to be - accessed; FALSE if current rVariable. N/A - if zMode is on (since the current zVariable - number will always be used). */ -{ - - if (zModeON(CDF)) { - if (CDF->CURzVarNum < CDF->NrVars) - return FALSE; - else - return TRUE; - } - else - return zOp; -} - -/****************************************************************************** -* InitCurrentVar. -******************************************************************************/ - -STATICforIDL CDFstatus InitCurrentVar (CDF, zOp, Var) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -Logical zOp; /* In: TRUE if current zVariable is to be - accessed; FALSE if current rVariable. N/A - if zMode is on (since the current zVariable - number will always be used [even when a real - rVariable is being accessed]). */ -struct VarStruct **Var; /* Out: Pointer to variable. */ -{ - CDFstatus tStatus; - /**************************************************************************** - * Pass back the pointer to its variable structure. The variable will - * be initialized for access if necessary. - ****************************************************************************/ - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - tStatus = InitVar (CDF, CDF->CURzVarNum, FALSE, Var); - else - tStatus = InitVar (CDF, CDF->CURzVarNum - CDF->NrVars, TRUE, Var); - else - tStatus = InitVar (CDF,BOO(zOp,CDF->CURzVarNum,CDF->CURrVarNum),zOp,Var); - return tStatus; -} - -/****************************************************************************** -* InitVar. -******************************************************************************/ - -STATICforIDL CDFstatus InitVar (CDF, varN, zVar, VarP) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -Int32 varN; /* In: Real variable number (ignoring the - zMode). */ -Logical zVar; /* In: TRUE if a real zVariable (ignoring - the zMode). */ -struct VarStruct **VarP; /* Out: Pointer to variable. */ -{ - CDFstatus pStatus = CDF_OK; - struct VarStruct *Var = BOO(zVar,CDF->zVars[(int)varN], - CDF->rVars[(int)varN]); - /**************************************************************************** - * Check if the variable has already been initialized. If not, allocate and - * initialize its variable structure. - ****************************************************************************/ - if (Var == NULL) { - /************************************************************************** - * Allocate a variable structure. - **************************************************************************/ - Var = (struct VarStruct *) cdf_AllocateMemory ((size_t)sizeof(struct VarStruct), NULL); - if (Var == NULL) return BAD_MALLOC; - /************************************************************************** - * Determine offset of the VDR in the dotCDF file. - **************************************************************************/ - if (!sX(FindVarByNumber(CDF,varN,zVar,&(Var->VDRoffset)),&pStatus)) { - cdf_FreeMemory (Var, NULL); - return pStatus; - } - - /************************************************************************** - * Initialize miscellaneous fields of the variable structure. - **************************************************************************/ - Var->zVar = zVar; - Var->varN = varN; - Var->fp = NULL; - Var->varCacheSize = NUMcacheVAR; /* N/A if single-file CDF. */ - Var->accessed_at = CDF->pseudo_clock++; - Var->firstRecInVVR = NO_RECORD; - Var->lastRecInVVR = NO_RECORD; - Var->offsetOfVVR = NO_OFFSET; - /************************************************************************** - * Read fields to be held in memory for efficiency. - **************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_MAXREC,&(Var->maxRec), - VDR_NULL),&pStatus)) { - cdf_FreeMemory (Var, NULL); - return pStatus; - } - /************************************************************************** - * More initialization. - **************************************************************************/ - if (!sX(InitVar2(CDF,Var),&pStatus)) { - cdf_FreeMemory (Var, NULL); - return pStatus; - } - /************************************************************************** - * Store pointer to variable structure. - **************************************************************************/ - if (zVar) - CDF->zVars[(int)varN] = Var; - else - CDF->rVars[(int)varN] = Var; - } - /**************************************************************************** - * Pass back pointer to variable. - ****************************************************************************/ - ASSIGNnotNULL (VarP, Var) - return pStatus; -} - -/****************************************************************************** -* InitVar2. -******************************************************************************/ - -STATICforIDL CDFstatus InitVar2 (CDF, Var) -struct CDFstruct *CDF; -struct VarStruct *Var; -{ - int dimN; CDFstatus pStatus = CDF_OK; struct CPRstruct CPR; int i; - Int32 flags, dataType, numElems, CPRoffset, sRecords; - /**************************************************************************** - * Read necessary fields from the VDR. - ****************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_FLAGS,&flags, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_sRECORDS,&sRecords, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * Determine if the variable has a known data type. - ****************************************************************************/ - if (!ValidDataType(dataType) || InValidDataType(dataType)) - return BAD_DATA_TYPE; - /**************************************************************************** - * Calculate the dimensionality and variances of the variable based on the - * current zMode. - ****************************************************************************/ - if (!sX(CalcDimParms(CDF,Var->VDRoffset, - Var->zVar,&(Var->numDims), - Var->dimSizes,Var->dimVarys),&pStatus)) return pStatus; - Var->recVary = BOO(RECvaryBITset(flags),VARY,NOVARY); - /**************************************************************************** - * Calculate the number of values for each dimension. - ****************************************************************************/ - CalcNumDimValues (CDF, Var); - /**************************************************************************** - * Calculate the element and value sizes. - ****************************************************************************/ - Var->NvalueElems = numElems; - Var->NelemBytes = (Int32) CDFelemSize (dataType); - Var->NvalueBytes = Var->NvalueElems * Var->NelemBytes; - /**************************************************************************** - * Calculate the number of physical and virtual values per record. - ****************************************************************************/ - CalcRecValues (Var); - /**************************************************************************** - * Calculate the number of elements and the size (in bytes) of physical and - * conceptual records. - ****************************************************************************/ - Var->NphyRecElems = Var->NphyRecValues * Var->NvalueElems; - Var->NvirtRecElems = Var->NvirtRecValues * Var->NvalueElems; - Var->NphyRecBytes = Var->NphyRecValues * Var->NvalueBytes; - Var->NvirtRecBytes = Var->NvirtRecValues * Var->NvalueBytes; - /************************************************************************** - * Initialize current positioning. - **************************************************************************/ - Var->seqValueOffset = 0; - Var->zRD.recNumber = 0; - Var->zRD.recCount = 1; - Var->zRD.recInterval = 1; - for (dimN = 0; dimN < Var->numDims; dimN++) { - Var->zRD.dimIndices[dimN] = 0; - Var->zRD.dimCounts[dimN] = Var->dimSizes[dimN]; - Var->zRD.dimIntervals[dimN] = 1; - } - /**************************************************************************** - * Determine variable type. - ****************************************************************************/ - if (!sX(VariableType(CDF,Var->VDRoffset, - Var->zVar,&(Var->vType)),&pStatus)) return pStatus; - /************************************************************************** - * What to do if a record is missing. - **************************************************************************/ - Var->prevIfMissing = (sRecords == PREV_SPARSERECORDS); - /************************************************************************** - * Based on the variable type... - **************************************************************************/ - switch (Var->vType) { - case STANDARD_: - case SPARSE_RECORDS_: - if (!sX(LastRecord(CDF,Var->VDRoffset,Var->zVar, - &(Var->maxAllocated)),&pStatus)) return pStatus; - Var->maxWritten = Var->maxAllocated; - break; - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_CPRorSPR,&CPRoffset, - VDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadCPR(CDF->fp,CPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) return pStatus; - Var->cType = CPR.cType; - for (i = 0; i < CPR.pCount; i++) Var->cParms[i] = CPR.cParms[i]; - Var->reservePct = 0; - break; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return UNKNOWN_SPARSENESS; - case IN_MULTI_: - break; - default: - return CDF_INTERNAL_ERROR; - } - /************************************************************************** - * Initialize staging area (although n/a for most variable types). - **************************************************************************/ - Var->stage.areaOffset = NO_OFFSET; - Var->stage.firstRec = NO_RECORD; - Var->stage.lastRec = NO_RECORD; - Var->stage.dotOffset = NO_OFFSET; - Var->stage.modified = FALSE; - /**************************************************************************** - * Calculate the blocking factor based on variable type... - ****************************************************************************/ - if (!sX(CalcBF(CDF,Var),&pStatus)) return pStatus; - /**************************************************************************** - * Determine the encoding and decoding functions to be used. - ****************************************************************************/ - if (!sX(ConversionFunction(dataType,HostEncoding(), - CDF->encoding,CDF->negToPosFp0, - &(Var->EncodeFunction)),&pStatus)) return pStatus; - if (!sX(ConversionFunction(dataType,CDF->encoding, - CDF->decoding,CDF->negToPosFp0, - &(Var->DecodeFunction)),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CalcRecValues. -******************************************************************************/ - -STATICforIDL void CalcRecValues (Var) -struct VarStruct *Var; -{ - int dimN; - Var->NphyRecValues = 1; - Var->NvirtRecValues = 1; - for (dimN = 0; dimN < Var->numDims; dimN++) { - Var->NvirtRecValues *= Var->dimSizes[dimN]; - if (Var->dimVarys[dimN]) Var->NphyRecValues *= Var->dimSizes[dimN]; - } - return; -} - -/****************************************************************************** -* CalcNumDimValues. -******************************************************************************/ - -STATICforIDL void CalcNumDimValues (CDF, Var) -struct CDFstruct *CDF; -struct VarStruct *Var; -{ - int dimN, dimNx; - if (!CDF->rowMajor) { - for (dimN = 0; dimN < Var->numDims; dimN++) { - Var->nPhyDimValues[dimN] = 1; - for (dimNx = 0; dimNx < dimN; dimNx++) { - if (Var->dimVarys[dimNx]) { - Var->nPhyDimValues[dimN] *= Var->dimSizes[dimNx]; - } - } - } - } - else { - for (dimN = 0; dimN < Var->numDims; dimN++) { - Var->nPhyDimValues[dimN] = 1; - for (dimNx = dimN + 1; dimNx < Var->numDims; dimNx++) { - if (Var->dimVarys[dimNx]) { - Var->nPhyDimValues[dimN] *= Var->dimSizes[dimNx]; - } - } - } - } - return; -} - -/****************************************************************************** -* CalcBF. -******************************************************************************/ - -STATICforIDL CDFstatus CalcBF (CDF, Var) -struct CDFstruct *CDF; -struct VarStruct *Var; -{ - CDFstatus pStatus = CDF_OK; Int32 bF; - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_BLOCKING,&bF, - VDR_NULL),&pStatus)) return pStatus; - switch (Var->vType) { - case STANDARD_: - if (Var->recVary) - if (bF == 0) { - Int32 min = ((MIN_BLOCKING_BYTES_standard-1)/Var->NphyRecBytes)+1; - Var->blockingFactor = MAXIMUM(min,MIN_BLOCKING_RECS_standard); - } - else - Var->blockingFactor = bF; - else - Var->blockingFactor = 1; - break; - case SPARSE_RECORDS_: - if (Var->recVary) - if (bF == 0) { - Int32 min = ((MIN_BLOCKING_BYTES_sparse-1)/Var->NphyRecBytes)+1; - Var->blockingFactor = MAXIMUM(min,MIN_BLOCKING_RECS_sparse); - } - else - Var->blockingFactor = bF; - else - Var->blockingFactor = 1; - break; - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - Var->blockingFactor = bF; - break; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return UNKNOWN_SPARSENESS; - case IN_MULTI_: - Var->blockingFactor = 1; - break; - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* UpdateConversions. -******************************************************************************/ - -STATICforIDL CDFstatus UpdateConversions (CDF) -struct CDFstruct *CDF; -{ - CDFstatus pStatus = CDF_OK; Logical zVar; - for (zVar = 0; zVar <= 1; zVar++) { - int varN; Int32 nVars = BOO(zVar,CDF->NzVars,CDF->NrVars); - for (varN = 0; varN < nVars; varN++) { - struct VarStruct *Var = BOO(zVar,CDF->zVars[varN],CDF->rVars[varN]); - if (Var != NULL) { - Int32 dataType; - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_DATATYPE,&dataType, - VDR_NULL),&pStatus)) return pStatus; - if (!sX(ConversionFunction(dataType,HostEncoding(), - CDF->encoding,CDF->negToPosFp0, - &(Var->EncodeFunction)),&pStatus)) return - pStatus; - if (!sX(ConversionFunction(dataType,CDF->encoding, - CDF->decoding,CDF->negToPosFp0, - &(Var->DecodeFunction)),&pStatus)) return - pStatus; - } - } - } - return pStatus; -} - -/****************************************************************************** -* UpdateNEWzMode. -******************************************************************************/ - -STATICforIDL CDFstatus UpdateNEWzMode (CDF) -struct CDFstruct *CDF; -{ - CDFstatus pStatus = CDF_OK; Logical zVar; - for (zVar = 0; zVar <= 1; zVar++) { - int varN; Int32 nVars = BOO(zVar,CDF->NzVars,CDF->NrVars); - for (varN = 0; varN < nVars; varN++) { - struct VarStruct *Var = BOO(zVar,CDF->zVars[varN],CDF->rVars[varN]); - if (Var != NULL) { - if (!sX(CalcDimParms(CDF,Var->VDRoffset, - Var->zVar,&(Var->numDims), - Var->dimSizes, - Var->dimVarys),&pStatus)) return pStatus; - CalcNumDimValues (CDF, Var); - CalcRecValues (Var); - Var->NvirtRecElems = Var->NvirtRecValues * Var->NvalueElems; - Var->NvirtRecBytes = Var->NvirtRecValues * Var->NvalueBytes; - } - } - } - return pStatus; -} - -/****************************************************************************** -* VarIdentity. -* Returns information about the real identity of a variable. -******************************************************************************/ - -STATICforIDL CDFstatus VarIdentity (CDF, varN, zOp, varNt, zVar, Var) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -Int32 varN; /* In: Variable number - zModed. */ -Logical zOp; /* In: TRUE if zVariable; FALSE if rVariable. - This is also zModed. */ -Int32 *varNt; /* Out: Real variable number. */ -Logical *zVar; /* Out: Real variable type: TRUE if a - zVariable; FALSE if an rVariable. */ -struct VarStruct **Var; /* Out: Pointer to variable. */ -{ - if (zModeON(CDF)) - if (0 <= varN && varN < CDF->NrVars) { - ASSIGNnotNULL (varNt, varN) - ASSIGNnotNULL (zVar, FALSE) - ASSIGNnotNULL (Var, CDF->rVars[(int)varN]) - } - else - if (varN < CDF->NrVars + CDF->NzVars) { - ASSIGNnotNULL (varNt, varN - CDF->NrVars) - ASSIGNnotNULL (zVar, TRUE) - ASSIGNnotNULL (Var, CDF->zVars[(int)varN-CDF->NrVars]) - } - else - return NO_SUCH_VAR; - else - if (0 <= varN && varN < BOO(zOp,CDF->NzVars,CDF->NrVars)) { - ASSIGNnotNULL (varNt, varN) - ASSIGNnotNULL (zVar, zOp) - ASSIGNnotNULL (Var, BOO(zOp,CDF->zVars[(int)varN], - CDF->rVars[(int)varN])) - } - else - return NO_SUCH_VAR; - return CDF_OK; -} - -/****************************************************************************** -* OpenVar. -* Open a variable for read and/or write access (if this is a multi-file CDF -* and the variable file is closed). It is assumed that the variable has been -* initialized for access and that the variable is closed (and in a multi-file -* CDF). -******************************************************************************/ - -STATICforIDL CDFstatus OpenVar (CDF, Var) -struct CDFstruct *CDF; -struct VarStruct *Var; -{ - CDFstatus pStatus = CDF_OK; - char a_mode[MAX_aMODE_LEN+1], pathname[DU_MAX_PATH_LEN+1]; - /**************************************************************************** - * Try to open the variable file. - ****************************************************************************/ - BuildFilePath (BOO(Var->zVar,Zt,Vt), CDF->CDFname, CDF->no_append, - CDF->upper_case_ext, CDF->version_numbers, Var->varN, - pathname); - if (CDF->status == READ_WRITE) - strcpyX (a_mode, READ_PLUS_a_mode, MAX_aMODE_LEN); - else - strcpyX (a_mode, READ_ONLY_a_mode, MAX_aMODE_LEN); - Var->fp = V_open (pathname, a_mode); - /**************************************************************************** - * If the open failed, close a variable file and try. If that attempt fails - * return an error. - ****************************************************************************/ - if (Var->fp == NULL) { - if (!sX(CloseLRUvar(CDF),&pStatus)) return pStatus; - Var->fp = V_open (pathname, a_mode); - if (Var->fp == NULL) return VAR_OPEN_ERROR; - } - /**************************************************************************** - * The open was successful - try to set the proper cache size. - ****************************************************************************/ - if (!CACHEv(Var->fp,Var->varCacheSize)) { - V_close (Var->fp, NULL, NULL); - Var->fp = NULL; - return BAD_CACHE_SIZE; - } - return pStatus; -} - -/****************************************************************************** -* LastRecord. -******************************************************************************/ - -STATICforIDL CDFstatus LastRecord (CDF, VDRoffset, zVar, recNum) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -Int32 VDRoffset; /* In: Offset of VDR. */ -Logical zVar; /* In: TRUE if a real zVariable; FALSE if rVariable. */ -Int32 *recNum; /* Out: Last record allocated. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 VXRoffset, nUsedEntries, lastRecs[MAX_VXR_ENTRIES]; - if (!sX(ReadVDR(CDF,CDF->fp,VDRoffset,zVar, - VDR_VXRTAIL,&VXRoffset, - VDR_NULL),&pStatus)) return pStatus; - if (VXRoffset == 0) - *recNum = NO_RECORD; - else { - if (!sX(ReadVXR(CDF->fp,VXRoffset, - VXR_NUSEDENTRIES,&nUsedEntries, - VXR_LASTREC,lastRecs, - VXR_NULL),&pStatus)) return pStatus; - if ((int)nUsedEntries > MAX_VXR_ENTRIES) return CORRUPTED_V2_CDF; - *recNum = lastRecs[(int)(nUsedEntries-1)]; - } - return pStatus; -} - -/****************************************************************************** -* IndicesValueOffset. -******************************************************************************/ - -STATICforIDL Int32 IndicesValueOffset (numDims, dimIndices, dimVarys, - nPhyDimValues) -Int32 numDims; -Int32 *dimIndices; -Int32 *dimVarys; -Int32 *nPhyDimValues; -{ - Int32 offset = 0; int dimN; - for (dimN = 0; dimN < numDims; dimN++) { - if (dimVarys[dimN]) offset += (dimIndices[dimN] * nPhyDimValues[dimN]); - } - return offset; -} - -/****************************************************************************** -* ValueOffsetIndices. -******************************************************************************/ - -STATICforIDL void ValueOffsetIndices (offset, rowMajor, numDims, dimVarys, - nPhyDimValues, indices) -Int32 offset; -Logical rowMajor; -Int32 numDims; -Int32 *dimVarys; -Int32 *nPhyDimValues; -Int32 *indices; -{ - int dimN, i; - for (i = 0, dimN = BOO(rowMajor,0,(int)(numDims-1)); - i < numDims; i++, BOO(rowMajor,dimN++,dimN--)) { - if (dimVarys[dimN]) { - indices[dimN] = offset / nPhyDimValues[dimN]; - offset = offset % nPhyDimValues[dimN]; - } - else - indices[dimN] = 0; - } - return; -} - -/****************************************************************************** -* RecordByteOffset. -******************************************************************************/ - -STATICforIDL CDFstatus RecordByteOffset (CDF, Var, phyRecN, offsetP) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 phyRecN; -Int32 *offsetP; -{ - CDFstatus pStatus = CDF_OK; - Int32 firstRec=-1, lastRec=-1, offset=-1; - switch (Var->vType) { - case STANDARD_: - case SPARSE_RECORDS_: { - if (Var->firstRecInVVR <= phyRecN && phyRecN <= Var->lastRecInVVR) { - *offsetP = (Int32) (Var->offsetOfVVR + VVR_BASE_SIZE + - (Var->NphyRecBytes * (phyRecN - Var->firstRecInVVR))); - break; - } - else { - if (!sX(SearchForRecord(CDF,Var->VDRoffset,Var->zVar, - phyRecN,&firstRec,&lastRec, - &offset,NULL),&pStatus)) return pStatus; - *offsetP = (Int32) (offset + VVR_BASE_SIZE + - (Var->NphyRecBytes * (phyRecN - firstRec))); - Var->firstRecInVVR = firstRec; - Var->lastRecInVVR = lastRec; - Var->offsetOfVVR = offset; - break; - } - } - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return CDF_INTERNAL_ERROR; - case IN_MULTI_: - *offsetP = (Int32) (phyRecN * Var->NphyRecBytes); - break; - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* ConfigureNEWzMode. -******************************************************************************/ - -STATICforIDL CDFstatus ConfigureNEWzMode (CDF) -struct CDFstruct *CDF; -{ - CDFstatus pStatus = CDF_OK; - if (!sX(UpdateNEWzMode(CDF),&pStatus)) return pStatus; - InitCURobjectsStates (CDF); - return pStatus; -} - -/****************************************************************************** -* InitCURobjectsStates. -* Note that initializing is done regardless of the current zMode. -******************************************************************************/ - -STATICforIDL void InitCURobjectsStates (CDF) -struct CDFstruct *CDF; -{ - struct VarStruct *Var; int dimN, varNum; - /**************************************************************************** - * Initialize current attributes/entries/variables. - ****************************************************************************/ - CDF->CURattrOffset = RESERVED_ATTROFFSET; - CDF->CURattrOffset64 = (OFF_T) RESERVED_ATTROFFSET; - CDF->CURgrEntryNum = RESERVED_ENTRYNUM; - CDF->CURgrEntryOffset = RESERVED_ENTRYOFFSET; - CDF->CURgrEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET; - CDF->CURzEntryNum = RESERVED_ENTRYNUM; - CDF->CURzEntryOffset = RESERVED_ENTRYOFFSET; - CDF->CURzEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET; - CDF->CURrVarNum = RESERVED_VARNUM; - CDF->CURzVarNum = RESERVED_VARNUM; - - if (CDF->fp != NULL) - { - CDF->fp->CurADRIndex = RESERVED_ENTRYNUM; - CDF->fp->CurAEDRIndex = RESERVED_ENTRYNUM; - }; - - /**************************************************************************** - * Initialize current positioning for EACH rVariable. - ****************************************************************************/ - for (varNum = 0; varNum < CDF->NrVars; varNum++) { - Var = CDF->rVars[varNum]; - if (Var != NULL) { - Var->seqValueOffset = 0; - Var->seqValueOffset64 = (OFF_T) 0; - Var->zRD.recNumber = 0; - Var->zRD.recCount = 1; - Var->zRD.recInterval = 1; - for (dimN = 0; dimN < Var->numDims; dimN++) { - Var->zRD.dimIndices[dimN] = 0; - Var->zRD.dimCounts[dimN] = Var->dimSizes[dimN]; - Var->zRD.dimIntervals[dimN] = 1; - } - } - } - /**************************************************************************** - * Initialize current positioning for EACH zVariable. - ****************************************************************************/ - for (varNum = 0; varNum < CDF->NzVars; varNum++) { - Var = CDF->zVars[varNum]; - if (Var != NULL) { - Var->seqValueOffset = 0; - Var->seqValueOffset64 = (OFF_T) 0; - Var->zRD.recNumber = 0; - Var->zRD.recCount = 1; - Var->zRD.recInterval = 1; - for (dimN = 0; dimN < Var->numDims; dimN++) { - Var->zRD.dimIndices[dimN] = 0; - Var->zRD.dimCounts[dimN] = Var->dimSizes[dimN]; - Var->zRD.dimIntervals[dimN] = 1; - } - } - } - /**************************************************************************** - * Initialize current positioning for ALL rVariables. - ****************************************************************************/ - CDF->rRD.recNumber = 0; - CDF->rRD.recCount = 1; - CDF->rRD.recInterval = 1; - for (dimN = 0; dimN < CDF->rNumDims; dimN++) { - CDF->rRD.dimIndices[dimN] = 0; - CDF->rRD.dimCounts[dimN] = CDF->rDimSizes[dimN]; - CDF->rRD.dimIntervals[dimN] = 1; - } - return; -} - -/****************************************************************************** -* FindAttrByName. -******************************************************************************/ - -STATICforIDL CDFstatus FindAttrByName (CDF, searchName, offset) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -char *searchName; /* In: Attribute name to find. */ -Int32 *offset; /* Out: Offset of ADR that was found. */ -{ - Int32 numAttrs, tOffset, nextADR, fstADR; - char attrName[CDF_ATTR_NAME_LEN+1]; - CDFstatus pStatus = CDF_OK; - int attrN; - long read_only_mode; - - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - - /************************************************************************** - * If in READONLYon mode, set CurADRIndex to the referenced attribute number. - ***************************************************************************/ - if (read_only_mode == READONLYon) - { - for (attrN = 0; attrN < CDF->fp->GDR->NumAttr; attrN++) - { - if (!strcmpITB(CDF->fp->ADRList[attrN]->Name,searchName)) - { - CDF->fp->CurADRIndex = attrN; - ASSIGNnotNULL (offset, DUMMY_ENTRYOFFSET); - return CDF_OK; - }; - }; - } - else - { - /************************************************************************ - * Read number of attributes and the offset of the first ADR from the GDR. - ************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_NUMATTR,&numAttrs, - GDR_ADRHEAD,&fstADR, - GDR_NULL),&pStatus)) return pStatus; - /************************************************************************ - * Read from ADRs until a matching attribute name is found. - * Note that if this is a V2.0 CDF, the last ADR will not have an - * offset of zero for the next ADR. For that reason, we will loop - * through the number of attributes read from the GDR (and then stop). - ************************************************************************/ - if (CDF->CURattrOffset != RESERVED_ATTROFFSET) - tOffset = CDF->CURattrOffset; - else - tOffset = fstADR; - - for (attrN = 0; attrN < numAttrs; attrN++) { - if (!sX(ReadADR(CDF->fp,tOffset, - ADR_NAME,attrName, - ADR_ADRNEXT,&nextADR, - ADR_NULL),&pStatus)) return pStatus; - if (!strcmpITB(attrName,searchName)) { - ASSIGNnotNULL (offset, tOffset) - return CDF_OK; - } - if (nextADR != 0) - tOffset = nextADR; - else - tOffset = fstADR; - } - }; - /**************************************************************************** - * Attribute name not found, return error. - ****************************************************************************/ - return NO_SUCH_ATTR; -} - -/****************************************************************************** -* FindAttrByNumber. -******************************************************************************/ - -STATICforIDL CDFstatus FindAttrByNumber (CDF, searchNum, offset) -struct CDFstruct *CDF; /* In: Pointer to the CDF. */ -Int32 searchNum; /* In: The attribute number to be found. */ -Int32 *offset; /* Out: The offset of the located ADR. */ -{ - Int32 numAttrs, tOffset, attrNum, nextADR, fstADR; - CDFstatus pStatus = CDF_OK; - Int32 attrN; - long read_only_mode; - /**************************************************************************** - * Validate. - ****************************************************************************/ - if (searchNum < 0) return BAD_ATTR_NUM; - /**************************************************************************** - * First check if the next attribute is the one being searched for. For this - * to be the case, an attribute must currently be selected, the next attribute - * must exist, and the next attribute's number must be the attribute number - * being searched for. But don't try this if a V2.0 CDF because of the bad - * terminating offset of the ADR linked list in those CDFs. - ****************************************************************************/ -/* - if (!CDF->badTerminatingOffsets) { - if (CDF->CURattrOffset != RESERVED_ATTROFFSET) { - Int32 nextOffset; - if (!sX(ReadADR(CDF->fp,CDF->CURattrOffset, - ADR_ADRNEXT,&nextOffset, - ADR_NULL),&pStatus)) return pStatus; - if (nextOffset != 0) { - Int32 nextNum; - if (!sX(ReadADR(CDF->fp,nextOffset, - ADR_NUM,&nextNum, - ADR_NULL),&pStatus)) return pStatus; - if (nextNum == searchNum) { - *offset = nextOffset; - return pStatus; - } - } - } - } -*/ - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - - /*************************************************************************** - * If in read only mode, set CurADRIndex to the searched for atribute number. - ***************************************************************************/ - if (read_only_mode == READONLYon) - { - if (CDF->fp->GDR->NumAttr <= searchNum) return NO_SUCH_ATTR; - if (searchNum < 0 || searchNum >= CDF->fp->GDR->NumAttr) - return NO_SUCH_ATTR; - CDF->fp->CurADRIndex = searchNum; - ASSIGNnotNULL (offset, DUMMY_ENTRYOFFSET); - return CDF_OK; - } - else - { - /************************************************************************ - * The next attribute isn't the one being searched for. First read the - * number of attributes and the offset of the first ADR from the GDR. - ************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_NUMATTR,&numAttrs, - GDR_ADRHEAD,&fstADR, - GDR_NULL),&pStatus)) return pStatus; - if (numAttrs <= searchNum) return NO_SUCH_ATTR; - - if (CDF->CURattrOffset != RESERVED_ATTROFFSET) - tOffset = CDF->CURattrOffset; - else - tOffset = fstADR; - /************************************************************************ - * Read from ADRs until a matching attribute number is found. - * Note that if this is a V2.0 CDF, the last ADR will not have an - * offset of zero for the next ADR. For that reason, we will loop - * through the number of attributes read from the GDR (and then stop). - ************************************************************************/ - for (attrN = 0; attrN < numAttrs; attrN++) { - if (!sX(ReadADR(CDF->fp,tOffset, - ADR_NUM,&attrNum, - ADR_ADRNEXT,&nextADR, - ADR_NULL),&pStatus)) return pStatus; - if (attrNum == searchNum) { - ASSIGNnotNULL (offset, tOffset) - return CDF_OK; - } - if (nextADR != 0) - tOffset = nextADR; - else - tOffset = fstADR; - } - /************************************************************************ - * Attribute number not found, internal error or corrupted CDF. - ************************************************************************/ - return CORRUPTED_V2_CDF; - } -} - -/****************************************************************************** -* FindEntryByNumber. -******************************************************************************/ - -STATICforIDL CDFstatus FindEntryByNumber (CDF, ADRoffset, zEntry, entryN, - offset) -struct CDFstruct *CDF; /* In: Pointer to the CDF. */ -Int32 ADRoffset; /* In: Offset of attribute's ADR. */ -Logical zEntry; /* In: TRUE if AzEDR list to be searched. - FALSE if AgrEDR list to be searched. */ -Int32 entryN; /* In: The entry number being searched for. */ -Int32 *offset; /* Out: The offset of the located AEDR. */ -{ - Int32 numEntries, tOffset, entryNum, nextADR; - CDFstatus pStatus = CDF_OK; - Int32 entryX; - long read_only_mode; - /**************************************************************************** - * Read number of entries and the offset of the first AEDR from the ADR. - ****************************************************************************/ - if (!sX(ReadADR(CDF->fp,ADRoffset, - BOO(zEntry,ADR_NzENTRIES,ADR_NgrENTRIES),&numEntries, - BOO(zEntry,ADR_AzEDRHEAD,ADR_AgrEDRHEAD),&tOffset, - ADR_NULL),&pStatus)) return pStatus; - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - if (read_only_mode == READONLYon) - { - /*********************************************************************** - * If the requested entry exists, set CurAEDRIndex to the entry number and - * set CURzEntrySel to reflect if the entry is in the z list or the gr - * list. - ************************************************************************/ - if (zEntry && entryN <= CDF->fp->ADRList[CDF->fp->CurADRIndex]->MAXzEntry) - { - if (CDF->fp->ADRList[CDF->fp->CurADRIndex]->zAEDRList[entryN] != NULL) - { - CDF->fp->CURzEntrySel = TRUE; - CDF->fp->CurAEDRIndex = entryN; - ASSIGNnotNULL (offset, DUMMY_ENTRYOFFSET); - return pStatus; - } - else - { - return NO_SUCH_ENTRY; - } - } - else if (!zEntry && entryN <= CDF->fp->ADRList[CDF->fp->CurADRIndex]-> - MAXgrEntry) - { - if (CDF->fp->ADRList[CDF->fp->CurADRIndex]->grAEDRList[entryN] - != NULL) - { - CDF->fp->CURzEntrySel = FALSE; - CDF->fp->CurAEDRIndex = entryN; - ASSIGNnotNULL (offset, DUMMY_ENTRYOFFSET); - return pStatus; - } - else - { - return NO_SUCH_ENTRY; - }; - } - - else - { - return NO_SUCH_ENTRY; - }; - }; - /**************************************************************************** - * Read from AEDRs until a matching entry number is found. - * Note that if this is a V2.0 CDF, the last AEDR will not have an - * offset of zero for the next AEDR. For that reason, we will loop - * through the number of entries read from the ADR (and then stop). - ****************************************************************************/ - for (entryX = 0; entryX < numEntries; entryX++) { - if (!sX(ReadAEDR(CDF->fp,tOffset, - AEDR_NUM,&entryNum, - AEDR_AEDRNEXT,&nextADR, - AEDR_NULL),&pStatus)) return pStatus; - if (entryNum == entryN) { - ASSIGNnotNULL (offset, tOffset) - return CDF_OK; - } - tOffset = nextADR; - } - /**************************************************************************** - * Entry number not found. - ****************************************************************************/ - return NO_SUCH_ENTRY; -} - -/****************************************************************************** -* FindLastAttr. -******************************************************************************/ - -STATICforIDL CDFstatus FindLastAttr (CDF, lastOffset) -struct CDFstruct *CDF; /* In: Pointer to the CDF. */ -Int32 *lastOffset; /* Out: Offset of last attribute's ADR. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 nAttrs, offset; - Int32 attrN; - long read_only_mode; - - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - - /************************************************************************* - * If in READONLYon mode, set CurADRIndex to the index of the last - * attribute in menmory. - *************************************************************************/ - if (read_only_mode == READONLYon) - { - *lastOffset = DUMMY_ATTROFFSET; - CDF->fp->CurADRIndex = CDF->fp->GDR->NumAttr - 1; - } - else - { - /************************************************************************ - * Read number of attributes and the offset of the first ADR. If there are - * no attributes, return an offset of zero. - ************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_NUMATTR,&nAttrs, - GDR_NULL),&pStatus)) return pStatus; - if (nAttrs == 0) { - *lastOffset = 0; - return pStatus; - } - /************************************************************************ - * There is at least one attribute. - * Note that if this is a V2.0 CDF, the last ADR will not have an offset of - * zero for the next ADR. For that reason, we will loop through the number - * of attributes read from the GDR (and then stop). - ************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_ADRHEAD,&offset, - GDR_NULL),&pStatus)) return pStatus; - for (attrN = 0; attrN < nAttrs - 1; attrN++) { - if (!sX(ReadADR(CDF->fp,offset, - ADR_ADRNEXT,&offset, - ADR_NULL),&pStatus)) return pStatus; - } - *lastOffset = offset; - }; - return pStatus; -} - -/****************************************************************************** -* FindLastEntry. -******************************************************************************/ - -STATICforIDL CDFstatus FindLastEntry (CDF, ADRoffset, zEntry, lastOffset) -struct CDFstruct *CDF; /* In: Pointer to the CDF. */ -Int32 ADRoffset; /* In: Offset of attribute's ADR. */ -Logical zEntry; /* In: TRUE if (real) zEntry is being searched - for; FALSE if gEntry/rEntry. */ -Int32 *lastOffset; /* Out: The offset of the last AEDR. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 offset, nEntries; - Int32 entryX; - long read_only_mode; - - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - - /*********************************************************************** - * If in READONLYon mode, set CurAEDRIndex to MAXzEntry or MAXgrEntry, as - * appropriate. - ***********************************************************************/ - if (read_only_mode == READONLYon) - { - *lastOffset = DUMMY_ENTRYOFFSET; - if (zEntry == TRUE) - { - CDF->fp->CurAEDRIndex = - CDF->fp->ADRList[CDF->fp->CurADRIndex]->MAXzEntry; - } - else - { - CDF->fp->CurAEDRIndex = - CDF->fp->ADRList[CDF->fp->CurADRIndex]->MAXgrEntry; }; - } - else - { - /************************************************************************ - * Read offset of first AEDR and determine if there are any entries (of the - * specified type). If there are none, pass back an offset of zero. - ************************************************************************/ - if (!sX(ReadADR(CDF->fp,ADRoffset, - BOO(zEntry,ADR_AzEDRHEAD,ADR_AgrEDRHEAD), - &offset,ADR_NULL),&pStatus)) return pStatus; - if (offset == 0) { - *lastOffset = 0; - return pStatus; - } - /************************************************************************ - * There is at least one entry. Read the actual number of entries and then - * scan through to the last one. - * Note that if this is a V2.0 CDF, the last AEDR will not have an - * offset of zero for the next AEDR. For that reason, we will loop - * through the number of entries (minus one) read from the ADR (and then - * stop). - ************************************************************************/ - if (!sX(ReadADR(CDF->fp,ADRoffset, - BOO(zEntry,ADR_NzENTRIES,ADR_NgrENTRIES),&nEntries, - ADR_NULL),&pStatus)) return pStatus; - for (entryX = 0; entryX < nEntries - 1; entryX++) { - if (!sX(ReadAEDR(CDF->fp,offset, - AEDR_AEDRNEXT,&offset, - AEDR_NULL),&pStatus)) return pStatus; - } - *lastOffset = offset; - } - return pStatus; -} - -/****************************************************************************** -* FindPrevEntry. -******************************************************************************/ - -STATICforIDL CDFstatus FindPrevEntry (CDF, ADRoffset, searchOffset, zEntry, - prevOffset) -struct CDFstruct *CDF; /* Pointer to the CDF. */ -Int32 ADRoffset; /* Offset of attribute's ADR. */ -Int32 searchOffset; /* The entry offset being searched for. */ -Logical zEntry; /* TRUE if (real) zEntry is being searched for; - FALSE if gEntry/rEntry. */ -Int32 *prevOffset; /* The offset of the previous AEDR. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 offset, nEntries, nextOffset; - Int32 entryX; - /**************************************************************************** - * Read the offset of the first AEDR. If that offset is the same as the - * search offset, return an offset of zero. - ****************************************************************************/ - if (!sX(ReadADR(CDF->fp,ADRoffset, - BOO(zEntry,ADR_AzEDRHEAD,ADR_AgrEDRHEAD),&offset, - ADR_NULL),&pStatus)) return pStatus; - if (offset == searchOffset) { - *prevOffset = 0; - return pStatus; - } - /**************************************************************************** - * The first AEDR is not at the search offset. Read the actual number of - * entries and then scan through them looking for the AEDR offset being - * searched for. If the search offset is not found, then either the CDF is - * corrupted or an internal logic error has occurred. - * Note that if this is a V2.0 CDF, the last AEDR will not have an - * offset of zero for the next AEDR. For that reason, we will loop - * through the number of entries read from the ADR (and then stop). - ****************************************************************************/ - if (!sX(ReadADR(CDF->fp,ADRoffset, - BOO(zEntry,ADR_NzENTRIES,ADR_NgrENTRIES),&nEntries, - ADR_NULL),&pStatus)) return pStatus; - for (entryX = 0; entryX < nEntries; entryX++) { - if (!sX(ReadAEDR(CDF->fp,offset, - AEDR_AEDRNEXT,&nextOffset, - AEDR_NULL),&pStatus)) return pStatus; - if (nextOffset == searchOffset) { - *prevOffset = offset; - return pStatus; - } - offset = nextOffset; - } - return CORRUPTED_V2_CDF; -} - -/****************************************************************************** -* FindVarByName. -* Both the rVariable and zVariable lists are searched (since variable names -* are unique in a CDF). -******************************************************************************/ - -STATICforIDL CDFstatus FindVarByName (CDF, searchName, offset, zVar, Var) -struct CDFstruct *CDF; /* In: Pointer to the CDF. */ -char *searchName; /* In: The variable name being searched for. */ -Int32 *offset; /* Out: Offset of the zVDR/rVDR. */ -Logical *zVar; /* Out: TRUE if a zVariable. */ -struct VarStruct **Var; /* Out: Pointer to variable structure. */ -{ - int varN; - char varName[CDF_VAR_NAME_LEN+1]; - CDFstatus pStatus = CDF_OK; - Int32 tOffset, nextVDR; - Int32 headOffset; - /**************************************************************************** - * Read from rVDRs until a matching variable name is found. - * Note that if this is a V2.0 CDF, the last rVDR will not have an - * offset of zero for the next rVDR. For that reason, we will loop - * through the number of rVariables (and then stop). - ****************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_rVDRHEAD,&headOffset, - GDR_NULL),&pStatus)) return pStatus; - - if (CDF->CURrVarNum != RESERVED_VARNUM) - tOffset = CDF->CURrVarOffset; - else - tOffset = headOffset; - - for (varN = 0; varN < CDF->NrVars; varN++) { - if (!sX(ReadVDR(CDF,CDF->fp,tOffset,FALSE, - VDR_NAME,varName, - VDR_VDRNEXT,&nextVDR, - VDR_NULL),&pStatus)) return pStatus; - if (!strcmpITB(varName,searchName)) { - ASSIGNnotNULL (offset, tOffset) - ASSIGNnotNULL (zVar, FALSE) - ASSIGNnotNULL (Var, CDF->rVars[varN]) - return CDF_OK; - } - if (nextVDR == 0) tOffset = headOffset; - else tOffset = nextVDR; - } - /**************************************************************************** - * Read from zVDRs until a matching variable name is found. - ****************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_zVDRHEAD,&headOffset, - GDR_NULL),&pStatus)) return pStatus; -/* - if (CDF->CURzVarNum != RESERVED_VARNUM) - tOffset = CDF->CURzVarOffset; - else -*/ - tOffset = headOffset; - - for (varN = 0; varN < CDF->NzVars; varN++) { - if (!sX(ReadVDR(CDF,CDF->fp,tOffset,TRUE, - VDR_NAME,varName, - VDR_VDRNEXT,&nextVDR, - VDR_NULL),&pStatus)) return pStatus; - if (!strcmpITB(varName,searchName)) { - ASSIGNnotNULL (offset, tOffset) - ASSIGNnotNULL (zVar, TRUE) - ASSIGNnotNULL (Var, CDF->zVars[varN]) - return CDF_OK; - } - if (nextVDR == 0) tOffset = headOffset; - else tOffset = nextVDR; - } - /**************************************************************************** - * Variable name not found, return error. - ****************************************************************************/ - return NO_SUCH_VAR; -} - -/****************************************************************************** -* FindVarByNumber. -******************************************************************************/ - -STATICforIDL CDFstatus FindVarByNumber (CDF, searchNum, zVar, offset) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -Int32 searchNum; /* In: Variable number to be searched for. */ -Logical zVar; /* In: TRUE if a (real) zVariable number should be - found. */ -Int32 *offset; /* Out: offset of the VDR. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 nVars = BOO(zVar,CDF->NzVars,CDF->NrVars); - Int32 tOffset, varNum, nextVDR, fstOffset; - int varN; - /**************************************************************************** - * Read offset of first VDR. - ****************************************************************************/ - if (searchNum < 0) return BAD_VAR_NUM; - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - BOO(zVar,GDR_zVDRHEAD,GDR_rVDRHEAD),&fstOffset, - GDR_NULL),&pStatus)) return pStatus; - if (nVars <= searchNum) return NO_SUCH_VAR; - /**************************************************************************** - * Read from VDRs until a matching variable number is found. - * Note that if this is a V2.0 CDF, the last VDR will not have an - * offset of zero for the next VDR. For that reason, we will loop - * through the number of variables (and then stop). - ****************************************************************************/ - - if (zModeON(CDF)) { - tOffset = fstOffset; - if (CDF->CURzVarNum != RESERVED_VARNUM) { - long numT = BOO(zVar, CDF->CURzVarNum-CDF->NrVars, CDF->CURzVarNum); - if (numT > -1 && numT <= searchNum) tOffset = CDF->CURzVarOffset; - } - } - else { - if (zVar) { - if (CDF->CURzVarNum != RESERVED_VARNUM && CDF->CURzVarNum < searchNum) - tOffset = CDF->CURzVarOffset; - else - tOffset = fstOffset; - } else { - if (CDF->CURrVarNum != RESERVED_VARNUM && CDF->CURrVarNum < searchNum) - tOffset = CDF->CURrVarOffset; - else - tOffset = fstOffset; - } - } - - /**************************************************************************** - * Search for the variable from the current selected variabale, instead of - * the top of the variable list. It will speed up the search process if the - * variables are accessed in a orderly sequence. - ****************************************************************************/ - for (varN = 0; varN < nVars; varN++) { - if (!sX(ReadVDR(CDF,CDF->fp,tOffset,zVar, - VDR_NUM,&varNum, - VDR_VDRNEXT, &nextVDR, - VDR_NULL),&pStatus)) return pStatus; - if (varNum == searchNum) { - ASSIGNnotNULL (offset, tOffset) - return CDF_OK; - } - if (nextVDR != 0) /* Reaching the end of the list? */ - tOffset = nextVDR; /* No.... Continue. */ - else - tOffset = fstOffset; /* Yes... Go back to the top. */ - } - /**************************************************************************** - * Variable number not found, return error. - ****************************************************************************/ - return CORRUPTED_V2_CDF; -} - -/****************************************************************************** -* VerifyNoRecordsWritten. -* Verifies that no records have been written. Both the rVariable and -* zVariable lists are searched. -******************************************************************************/ - -STATICforIDL CDFstatus VerifyNoRecordsWritten (CDF, no) -struct CDFstruct *CDF; /* In: Pointer to the CDF. */ -Logical *no; /* Out: If TRUE, no records written. */ -{ - CDFstatus pStatus = CDF_OK; Int32 tOffset, maxRec; int varN; Logical zVar; - /**************************************************************************** - * Read from r/zVDRs until a maximum record greater than NO_RECORD is found. - * Note that if this is a V2.0 CDF, the last rVDR will not have an - * offset of zero for the next rVDR. For that reason, we will loop - * through the number of variables (and then stop). - ****************************************************************************/ - for (zVar = 0; zVar <= 1; zVar++) { - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - BOO(zVar,GDR_zVDRHEAD,GDR_rVDRHEAD),&tOffset, - GDR_NULL),&pStatus)) return pStatus; - for (varN = 0; varN < BOO(zVar,CDF->NzVars,CDF->NrVars); varN++) { - if (!sX(ReadVDR(CDF,CDF->fp,tOffset,zVar, - VDR_MAXREC,&maxRec, - VDR_VDRNEXT,&tOffset, - VDR_NULL),&pStatus)) return pStatus; - if (maxRec > NO_RECORD) { - *no = FALSE; - return pStatus; - } - } - } - /**************************************************************************** - * No records written. - ****************************************************************************/ - *no = TRUE; - return pStatus; -} - -/****************************************************************************** -* VerifyNoPadsSpecified. -* Verifies that no pad values have been specified. Both the rVariable -* and zVariable lists are searched. -******************************************************************************/ - -STATICforIDL CDFstatus VerifyNoPadsSpecified (CDF, no) -struct CDFstruct *CDF; /* In: Pointer to the CDF. */ -Logical *no; /* Out: If TRUE, no pad values written. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 tOffset, flags32; - int varN; - /**************************************************************************** - * Read from rVDRs until a pad value is found. - * Note that if this is a V2.0 CDF, the last rVDR will not have an - * offset of zero for the next rVDR. For that reason, we will loop - * through the number of rVariables (and then stop). - ****************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_rVDRHEAD,&tOffset, - GDR_NULL),&pStatus)) return pStatus; - for (varN = 0; varN < CDF->NrVars; varN++) { - if (!sX(ReadVDR(CDF,CDF->fp,tOffset,FALSE, - VDR_FLAGS,&flags32, - VDR_NULL),&pStatus)) return pStatus; - if (PADvalueBITset(flags32)) { - *no = FALSE; - return pStatus; - } - if (!sX(ReadVDR(CDF,CDF->fp,tOffset,FALSE, - VDR_VDRNEXT,&tOffset, - VDR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * Read from zVDRs until a pad value is found. - ****************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_zVDRHEAD,&tOffset, - GDR_NULL),&pStatus)) return pStatus; - for (varN = 0; varN < CDF->NzVars; varN++) { - if (!sX(ReadVDR(CDF,CDF->fp,tOffset,TRUE, - VDR_FLAGS,&flags32, - VDR_NULL),&pStatus)) return pStatus; - if (PADvalueBITset(flags32)) { - *no = FALSE; - return pStatus; - } - if (!sX(ReadVDR(CDF,CDF->fp,tOffset,TRUE, - VDR_VDRNEXT,&tOffset, - VDR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * No pad values specified. - ****************************************************************************/ - *no = TRUE; - return pStatus; -} - -/****************************************************************************** -* VerifyNoEntriesWritten. -******************************************************************************/ - -STATICforIDL CDFstatus VerifyNoEntriesWritten (CDF, no) -struct CDFstruct *CDF; -Logical *no; -{ - CDFstatus pStatus = CDF_OK; - Int32 numAttrs, tOffset, nEntries; - int attrN; - /**************************************************************************** - * Read number of attributes and the offset of the first ADR from the GDR. - ****************************************************************************/ - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_NUMATTR,&numAttrs, - GDR_ADRHEAD,&tOffset, - GDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * Read from ADRs until an entry is found. - * Note that if this is a V2.0 CDF, the last ADR will not have an - * offset of zero for the next ADR. For that reason, we will loop - * through the number of attributes read from the GDR (and then stop). - ****************************************************************************/ - for (attrN = 0; attrN < numAttrs; attrN++) { - if (!sX(ReadADR(CDF->fp,tOffset, - ADR_NgrENTRIES,&nEntries, - ADR_NULL),&pStatus)) return pStatus; - if (nEntries > 0) { - *no = FALSE; - return pStatus; - } - if (!sX(ReadADR(CDF->fp,tOffset, - ADR_NzENTRIES,&nEntries, - ADR_NULL),&pStatus)) return pStatus; - if (nEntries > 0) { - *no = FALSE; - return pStatus; - } - if (!sX(ReadADR(CDF->fp,tOffset, - ADR_ADRNEXT,&tOffset, - ADR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * No entries detected. - ****************************************************************************/ - *no = TRUE; - return pStatus; -} - -/****************************************************************************** -* DefaultPadValue. -* `memmove' is used rather than an assignment statement (for the data -* types greater in size than one byte) because there is no guarantee that the -* address which receives the pad value is aligned properly. If it isn't, a -* bus error could occur on some computers. -******************************************************************************/ - -STATICforIDL void DefaultPadValue (dataType, numElems, padValue) -Int32 dataType; -Int32 numElems; -void *padValue; -{ - size_t nBytes = (size_t) CDFelemSize (dataType); - Byte1 *ptr = padValue; - double padE[2]; /* The "largest" data type element. */ - int i; - switch (dataType) { - case CDF_BYTE: - *((sChar *) &padE) = (sChar) DEFAULT_BYTE_PADVALUE; - break; - case CDF_INT1: - *((sChar *) &padE) = (sChar) DEFAULT_INT1_PADVALUE; - break; - case CDF_UINT1: - *((uChar *) &padE) = (uChar) DEFAULT_UINT1_PADVALUE; - break; - case CDF_INT2: - *((Int16 *) &padE) = (Int16) DEFAULT_INT2_PADVALUE; - break; - case CDF_UINT2: - *((uInt16 *) &padE) = (uInt16) DEFAULT_UINT2_PADVALUE; - break; - case CDF_INT4: - *((Int32 *) &padE) = (Int32) DEFAULT_INT4_PADVALUE; - break; - case CDF_UINT4: - *((uInt32 *) &padE) = (uInt32) DEFAULT_UINT4_PADVALUE; - break; - case CDF_INT8: - *((Int64 *) &padE) = (Int64) DEFAULT_INT8_PADVALUE; - break; - case CDF_REAL4: - *((float *) &padE) = (float) DEFAULT_REAL4_PADVALUE; - break; - case CDF_FLOAT: - *((float *) &padE) = (float) DEFAULT_FLOAT_PADVALUE; - break; - case CDF_REAL8: - *((double *) &padE) = (double) DEFAULT_REAL8_PADVALUE; - break; - case CDF_DOUBLE: - *((double *) &padE) = (double) DEFAULT_DOUBLE_PADVALUE; - break; - case CDF_EPOCH: - *((double *) &padE) = (double) DEFAULT_EPOCH_PADVALUE; - break; - case CDF_EPOCH16: - *((double *) &padE) = (double) DEFAULT_EPOCH16_PADVALUE; - *(((double *) &padE) + 1) = (double) DEFAULT_EPOCH16_PADVALUE; - break; - case CDF_TIME_TT2000: - *((long long *) &padE) = (long long) DEFAULT_TT2000_PADVALUE; - break; - case CDF_CHAR: - *((sChar *) &padE) = (sChar) DEFAULT_CHAR_PADVALUE; - break; - case CDF_UCHAR: - *((uChar *) &padE) = (uChar) DEFAULT_UCHAR_PADVALUE; - break; - } - for (i = 0; i < numElems; i++, ptr += nBytes) memmove (ptr, &padE, nBytes); - return; -} - -/****************************************************************************** -* DefaultPadValuePre350. -* Reset the pad value to its pre-3.5.0 value for pre-3.5.0 file. -******************************************************************************/ -STATICforIDL void DefaultPadValuePre350 (dataType, numElems, padValue) - -Int32 dataType; -Int32 numElems; -void *padValue; -{ - size_t nBytes = (size_t) CDFelemSize (dataType); - Byte1 *ptr = padValue; - double padE[2]; /* The "largest" data type element. */ - int i; - switch (dataType) { - case CDF_BYTE: - *((sChar *) &padE) = (sChar) 0; - break; - case CDF_INT1: - *((sChar *) &padE) = (sChar) 0; - break; - case CDF_UINT1: - *((uChar *) &padE) = (uChar) 0; - break; - case CDF_INT2: - *((Int16 *) &padE) = (Int16) 0; - break; - case CDF_UINT2: - *((uInt16 *) &padE) = (uInt16) 0; - break; - case CDF_INT4: - *((Int32 *) &padE) = (Int32) 0; - break; - case CDF_UINT4: - *((uInt32 *) &padE) = (uInt32) 0; - break; - case CDF_INT8: - *((Int64 *) &padE) = (Int64) -9223372036854775807LL-1; - break; - case CDF_REAL4: - *((float *) &padE) = (float) 0.0; - break; - case CDF_FLOAT: - *((float *) &padE) = (float) 0.0; - break; - case CDF_REAL8: - *((double *) &padE) = (double) 0.0; - break; - case CDF_DOUBLE: - *((double *) &padE) = (double) 0.0; - break; - case CDF_EPOCH: - *((double *) &padE) = (double) 0.0; - break; - case CDF_EPOCH16: - *((double *) &padE) = (double) 0.0; - *(((double *) &padE) + 1) = (double) 0.0; - break; - case CDF_TIME_TT2000: - *((long long *) &padE) = (long long) -9223372036854775807LL; - break; - case CDF_CHAR: - *((sChar *) &padE) = (sChar) ' '; - break; - case CDF_UCHAR: - *((uChar *) &padE) = (uChar) ' '; - break; - } - for (i = 0; i < numElems; i++, ptr += nBytes) memmove (ptr, &padE, nBytes); - return; -} - -/****************************************************************************** -* DefaultPadBuffer. -******************************************************************************/ - -STATICforIDL CDFstatus DefaultPadBuffer (CDF, Var, nValues, buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 nValues; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; - Byte1 *tBuffer = buffer; Int32 i; Int32 dataType, numElems; - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_NULL),&pStatus)) return pStatus; - for (i = 0; i < nValues; i++, tBuffer += (int) Var->NvalueBytes) { - DefaultPadValuePre350 (dataType, numElems, tBuffer); - } - return pStatus; -} - -/****************************************************************************** -* PadBuffer. -******************************************************************************/ - -STATICforIDL CDFstatus PadBuffer (CDF, Var, nValues, buffer) -struct CDFstruct *CDF; /* Pointer to CDF. */ -struct VarStruct *Var; /* Pointer to variable. */ -Int32 nValues; /* Number of values in buffer. */ -void *buffer; /* Buffer to pad. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 flags, dataType, numElems; - /**************************************************************************** - * Read the flags, data type, and number of elements fields of the VDR. - ****************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_FLAGS,&flags, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * If a pad value has been specified for the variable, read the pad value - * from the VDR and duplicate for the desired number of values. Otherwise, - * copy the desired number of default pad values into the buffer. Then - * convert the padded buffer into the desired decoding. - ****************************************************************************/ - if (PADvalueBITset(flags)) { - Byte1 *tBuffer = buffer; Int32 valueN; - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_PADVALUE,tBuffer, - VDR_NULL),&pStatus)) return pStatus; - for (valueN = 1; valueN < nValues; valueN++) { - memmove (tBuffer + ((size_t) Var->NvalueBytes), tBuffer, - (size_t) Var->NvalueBytes); - tBuffer += (size_t) Var->NvalueBytes; - } - if (!sX(ConvertBuffer(CDF->encoding,CDF->decoding, - CDF->negToPosFp0,dataType, - (nValues * numElems), - buffer,buffer),&pStatus)) return pStatus; - } - else { - if (!sX(DefaultPadBuffer(CDF,Var,nValues,buffer),&pStatus)) return pStatus; - if (!sX(ConvertBuffer(HostEncoding(),CDF->decoding, - CDF->negToPosFp0,dataType, - (nValues * numElems), - buffer,buffer),&pStatus)) return pStatus; - } - return pStatus; -} - -/****************************************************************************** -* HostEncoding. -* Returns encoding type of host machine. -******************************************************************************/ - -STATICforIDL Int32 HostEncoding () -{ -#if defined(sun) - return ((Int32) SUN_ENCODING); -#endif -#if defined(vax) - return ((Int32) VAX_ENCODING); -#endif -#if defined(MIPSEL) - return ((Int32) DECSTATION_ENCODING); -#endif -#if defined(MIPSEB) - return ((Int32) SGi_ENCODING); -#endif -#if defined(IBMPC) || defined(macosXintel) - return ((Int32) IBMPC_ENCODING); -#endif -#if defined(IBMRS) - return ((Int32) IBMRS_ENCODING); -#endif -#if defined(HP) - return ((Int32) HP_ENCODING); -#endif -#if defined(NeXT) - return ((Int32) NeXT_ENCODING); -#endif -#if defined(alphaosf) - return ((Int32) ALPHAOSF1_ENCODING); -#endif -#if defined(alphavmsD) || defined(posixSHELLalphaD) - return ((Int32) ALPHAVMSd_ENCODING); -#endif -#if defined(alphavmsG) || defined(posixSHELLalphaG) - return ((Int32) ALPHAVMSg_ENCODING); -#endif -#if defined(alphavmsI) || defined(posixSHELLalphaI) - return ((Int32) ALPHAVMSi_ENCODING); -#endif -#if defined(mac) || defined(POWERPC) || defined(macosXppc) - return ((Int32) PPC_ENCODING); -#endif -} - -/****************************************************************************** -* HostDecoding. -* Returns decoding type of host machine. -******************************************************************************/ - -STATICforIDL Int32 HostDecoding () -{ -#if defined(sun) - return ((Int32) SUN_DECODING); -#endif -#if defined(vax) - return ((Int32) VAX_DECODING); -#endif -#if defined(MIPSEL) - return ((Int32) DECSTATION_DECODING); -#endif -#if defined(MIPSEB) - return ((Int32) SGi_DECODING); -#endif -#if defined(IBMPC) || defined(macosXintel) - return ((Int32) IBMPC_DECODING); -#endif -#if defined(IBMRS) - return ((Int32) IBMRS_DECODING); -#endif -#if defined(HP) - return ((Int32) HP_DECODING); -#endif -#if defined(NeXT) - return ((Int32) NeXT_DECODING); -#endif -#if defined(alphaosf) - return ((Int32) ALPHAOSF1_DECODING); -#endif -#if defined(alphavmsD) || defined(posixSHELLalphaD) - return ((Int32) ALPHAVMSd_DECODING); -#endif -#if defined(alphavmsG) || defined(posixSHELLalphaG) - return ((Int32) ALPHAVMSg_DECODING); -#endif -#if defined(alphavmsI) - return ((Int32) ALPHAVMSi_DECODING); -#endif -#if defined(mac) || defined(POWERPC) || defined(macosXppc) - return ((Int32) PPC_DECODING); -#endif -} - -/****************************************************************************** -* IntegerOrder. -* Returns integer order based on encoding (decoding). -******************************************************************************/ - -STATICforIDL int IntegerOrder (ed) -Int32 ed; /* Encoding/decoding. */ -{ - switch (ed) { - case NETWORK_ENCODING: - case SUN_ENCODING: - case SGi_ENCODING: - case IBMRS_ENCODING: - case HP_ENCODING: - case NeXT_ENCODING: - case PPC_ENCODING: - return BIGendianORDER; - case DECSTATION_ENCODING: - case ALPHAOSF1_ENCODING: - case ALPHAVMSd_ENCODING: - case ALPHAVMSg_ENCODING: - case ALPHAVMSi_ENCODING: - case IBMPC_ENCODING: - case VAX_ENCODING: - return LITTLEendianORDER; - default: - return 0; /* Internal error. */ - } -} - -/****************************************************************************** -* FpType. -* Returns floating-point type based on encoding (decoding). -******************************************************************************/ - -STATICforIDL int FpType (ed) -Int32 ed; /* Encoding/decoding. */ -{ - switch (ed) { - case NETWORK_ENCODING: - case SUN_ENCODING: - case SGi_ENCODING: - case IBMRS_ENCODING: - case HP_ENCODING: - case NeXT_ENCODING: - case PPC_ENCODING: - return FP_1; - case DECSTATION_ENCODING: - case ALPHAOSF1_ENCODING: - case IBMPC_ENCODING: - case ALPHAVMSi_ENCODING: - return FP_2; - case VAX_ENCODING: - case ALPHAVMSd_ENCODING: - return FP_3; - case ALPHAVMSg_ENCODING: - return FP_4; - default: - return 0; - } -} - -/****************************************************************************** -* CDFelemSize. -******************************************************************************/ - -STATICforIDL int CDFelemSize (dataType) -long dataType; -{ - switch (dataType) { - case CDF_BYTE: return 1; - case CDF_INT1: return 1; - case CDF_INT2: return 2; - case CDF_INT4: return 4; - case CDF_INT8: return 8; - case CDF_UINT1: return 1; - case CDF_UINT2: return 2; - case CDF_UINT4: return 4; - case CDF_REAL4: return 4; - case CDF_REAL8: return 8; - case CDF_FLOAT: return 4; - case CDF_DOUBLE: return 8; - case CDF_EPOCH: return 8; - case CDF_EPOCH16: return 16; - case CDF_TIME_TT2000: return 8; - case CDF_CHAR: return 1; - case CDF_UCHAR: return 1; - } - return 0; -} - -/****************************************************************************** -* EquivDataTypes. -******************************************************************************/ - -STATICforIDL Logical EquivDataTypes (dataType1, dataType2) -Int32 dataType1; -Int32 dataType2; -{ - switch (dataType1) { - case CDF_BYTE: - case CDF_INT1: - case CDF_UINT1: - case CDF_CHAR: - case CDF_UCHAR: - switch (dataType2) { - case CDF_BYTE: - case CDF_INT1: - case CDF_UINT1: - case CDF_CHAR: - case CDF_UCHAR: - return TRUE; - default: - return FALSE; - } - case CDF_INT2: - case CDF_UINT2: - switch (dataType2) { - case CDF_INT2: - case CDF_UINT2: - return TRUE; - default: - return FALSE; - } - case CDF_INT4: - case CDF_UINT4: - switch (dataType2) { - case CDF_INT4: - case CDF_UINT4: - return TRUE; - default: - return FALSE; - } - case CDF_INT8: - case CDF_TIME_TT2000: - switch (dataType2) { - case CDF_INT8: - case CDF_TIME_TT2000: - return TRUE; - default: - return FALSE; - } - case CDF_REAL4: - case CDF_FLOAT: - switch (dataType2) { - case CDF_REAL4: - case CDF_FLOAT: - return TRUE; - default: - return FALSE; - } - case CDF_REAL8: - case CDF_DOUBLE: - case CDF_EPOCH: - switch (dataType2) { - case CDF_REAL8: - case CDF_DOUBLE: - case CDF_EPOCH: - return TRUE; - default: - return FALSE; - } - case CDF_EPOCH16: - switch (dataType2) { - case CDF_EPOCH16: - return TRUE; - default: - return FALSE; - } - } - return FALSE; /* CDF_INTERNAL_ERROR or CORRUPTED_V2_CDF? */ -} - -/****************************************************************************** -* strcmpITB. Do a STRing CoMPare Ignoring any Trailing Blanks. -******************************************************************************/ - -STATICforIDL int strcmpITB (string1, string2) -char *string1; -char *string2; -{ - size_t len1 = strlen(string1); - size_t len2 = strlen(string2); - while (len1 > 0 && string1[len1-1] == ' ') len1--; - while (len2 > 0 && string2[len2-1] == ' ') len2--; - if (len1 == len2) - return strncmp (string1, string2, len1); - else - return strcmp (string1, string2); -} - - -/****************************************************************************** -* FreeCDFid. -* Free a CDF's dynamically allocated memory. -******************************************************************************/ - -STATICforIDL void FreeCDFid (CDF, aborting) -struct CDFstruct *CDF; -Logical aborting; -{ - /**************************************************************************** - * Free file names/paths. - ****************************************************************************/ - if (CDF->CDFname != NULL) cdf_FreeMemory (CDF->CDFname, NULL); - if (CDF->scratchDir != NULL) cdf_FreeMemory (CDF->scratchDir, NULL); - /**************************************************************************** - * Free rVariable structures. - ****************************************************************************/ - if (CDF->rVars != NULL) { - int varNum; - for (varNum = 0; varNum < CDF->NrVars; varNum++) { - if (CDF->rVars[varNum] != NULL) cdf_FreeMemory (CDF->rVars[varNum], NULL); - } - cdf_FreeMemory (CDF->rVars, NULL); - } - /**************************************************************************** - * Free zVariable structures. - ****************************************************************************/ - if (CDF->zVars != NULL) { - int varNum; - for (varNum = 0; varNum < CDF->NzVars; varNum++) { - if (CDF->zVars[varNum] != NULL) cdf_FreeMemory (CDF->zVars[varNum], NULL); - } - cdf_FreeMemory (CDF->zVars, NULL); - } - /**************************************************************************** - * Free CDF structure. The CDF structure's magic number is "killed" just in - * case the application tries to use the CDFid again. - ****************************************************************************/ - if (sizeof(CDF) == 8) cdfid_FreeMemory (CDF, NULL); - if (aborting) - CDF->magic = ABORTEDid_MAGIC_NUMBER; - else { - CDF->magic = KILLEDid_MAGIC_NUMBER; - cdf_FreeMemory (CDF, NULL); - } - return; -} - -/****************************************************************************** -* CloseLRUvar. -* Close a variable/zVariable file to free a file pointer. -******************************************************************************/ - -STATICforIDL CDFstatus CloseLRUvar (CDF) -struct CDFstruct *CDF; -{ - struct VarStruct *Var, *oldestVar = NULL; - uLongx oldest_access = CDF->pseudo_clock; int varNum; - /**************************************************************************** - * Scan through rVariables looking for oldest access. - ****************************************************************************/ - for (varNum = 0; varNum < CDF->NrVars; varNum++) { - Var = CDF->rVars[varNum]; - if (Var != NULL) { - if (Var->fp != NULL) { - if (Var->accessed_at < oldest_access) { - oldest_access = Var->accessed_at; - oldestVar = Var; - } - } - } - } - /**************************************************************************** - * Scan through zVariables looking for oldest access. - ****************************************************************************/ - for (varNum = 0; varNum < CDF->NzVars; varNum++) { - Var = CDF->zVars[varNum]; - if (Var != NULL) { - if (Var->fp != NULL) { - if (Var->accessed_at < oldest_access) { - oldest_access = Var->accessed_at; - oldestVar = Var; - } - } - } - } - /**************************************************************************** - * If a variable was found, close the associated file. - ****************************************************************************/ - if (oldestVar != NULL) { - if (!CLOSEv(oldestVar->fp,NULL,NULL)) { - oldestVar->fp = NULL; - return VAR_CLOSE_ERROR; - } - oldestVar->fp = NULL; - } - return CDF_OK; -} - -/****************************************************************************** -* CheckEntryOp. -******************************************************************************/ - -STATICforIDL CDFstatus CheckEntryOp (CDF, entryType) -struct CDFstruct *CDF; -int entryType; -{ - Int32 scope; CDFstatus pStatus = CDF_OK; - if (!sX(ReadADR(CDF->fp,CDF->CURattrOffset, - ADR_SCOPE,&scope, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (GLOBALscope(scope)) { - if (entryType != gENTRYt) return ILLEGAL_FOR_SCOPE; - } - else { - if (entryType == gENTRYt) return ILLEGAL_FOR_SCOPE; - if (BADzOP(CDF,entryType == rENTRYt)) return ILLEGAL_IN_zMODE; - } - return pStatus; -} - -/****************************************************************************** -* SetCURgrEntry. -******************************************************************************/ - -STATICforIDL CDFstatus SetCURgrEntry (CDF, useCurrent, entryNum) -struct CDFstruct *CDF; -Logical useCurrent; /* TRUE if current g/rEntry offset can be used to speed - up the search. */ -Int32 entryNum; /* The new g/rEntry number. */ -{ - CDFstatus pStatus = CDF_OK, tStatus; - Int32 scope, offset, attrNum, attrNumX, entryNumX, nextOffset; - long read_only_mode; - /**************************************************************************** - * Check if the new g/rEntry number is the reserved entry number. - ****************************************************************************/ - if (entryNum == RESERVED_ENTRYNUM) { - CDF->CURgrEntryNum = RESERVED_ENTRYNUM; - CDF->fp->CurAEDRIndex = RESERVED_ENTRYNUM; - CDF->CURgrEntryOffset = RESERVED_ENTRYOFFSET; - return pStatus; - } - /**************************************************************************** - * Check that a current attribute is selected. - ****************************************************************************/ - if (CDF->CURattrOffset == RESERVED_ATTROFFSET) { - CDF->CURgrEntryNum = entryNum; - CDF->fp->CurAEDRIndex = RESERVED_ENTRYNUM; - CDF->CURgrEntryOffset = RESERVED_ENTRYOFFSET; - return pStatus; - } - /**************************************************************************** - * Get the scope and number of the current attribute. If READONLYon, the - * scope and number are already in th mteadata structures. - ****************************************************************************/ - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - if (read_only_mode == READONLYon) - { - scope = CDF->fp->ADRList[CDF->fp->CurADRIndex]->Scope; - attrNum = CDF->fp->CurADRIndex; - } - else - { - if (!sX(ReadADR(CDF->fp,CDF->CURattrOffset, - ADR_SCOPE,&scope, - ADR_NUM,&attrNum, - ADR_NULL),&pStatus)) return pStatus; - }; - /**************************************************************************** - * If the current attribute is variable-scoped and zMode is on, then the - * current g/rEntry offset is n/a. - ****************************************************************************/ - if (VARIABLEscope(scope) && zModeON(CDF)) { - CDF->CURgrEntryNum = entryNum; - CDF->fp->CurAEDRIndex = RESERVED_ENTRYNUM; - CDF->CURgrEntryOffset = RESERVED_ENTRYOFFSET; - return pStatus; - } - /**************************************************************************** - * IF READONLYoff, check if the next entry is the one being searched for. - * For this to be the case, an entry must currently be selected and must be - * associated with the current attribute, the next entry must exist, and the - * next entry's number must be the entry number being searched for. But - * don't try this if a V2.0 CDF because of the bad terminating offset of the - * AEDR linked lists in those CDFs. - ****************************************************************************/ - if (read_only_mode == READONLYoff && useCurrent && - !CDF->badTerminatingOffsets) { - if (CDF->CURgrEntryOffset != RESERVED_ENTRYOFFSET) { - if (!sX(ReadAEDR(CDF->fp,CDF->CURgrEntryOffset, - AEDR_ATTRNUM,&attrNumX, - AEDR_AEDRNEXT,&nextOffset, - AEDR_NULL),&pStatus)) return pStatus; - if (attrNumX == attrNum && nextOffset != 0) { - if (!sX(ReadAEDR(CDF->fp,nextOffset, - AEDR_NUM,&entryNumX, - AEDR_NULL),&pStatus)) return pStatus; - if (entryNumX == entryNum) { - CDF->CURgrEntryNum = entryNum; - CDF->CURgrEntryOffset = nextOffset; - return pStatus; - } - } - } - } - /**************************************************************************** - * Search the list of AEDRs for the entry. - ****************************************************************************/ - tStatus = FindEntryByNumber (CDF, CDF->CURattrOffset, FALSE, entryNum, - &offset); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_ENTRY: - offset = RESERVED_ENTRYOFFSET; - break; - default: - return tStatus; - } - CDF->CURgrEntryNum = entryNum; - CDF->CURgrEntryOffset = offset; - return pStatus; -} - -/****************************************************************************** -* SetCURzEntry. -******************************************************************************/ - -STATICforIDL CDFstatus SetCURzEntry (CDF, useCurrent, entryNum) -struct CDFstruct *CDF; -Logical useCurrent; /* TRUE if current zEntry offset can be used to speed - up the search. */ -Int32 entryNum; /* The new zEntry number. */ -{ - CDFstatus pStatus = CDF_OK, tStatus; - Int32 scope, offset, attrNum, attrNumX, entryNumX, nextOffset; - Logical zEntry; - Int32 entryN; - long read_only_mode; - /**************************************************************************** - * Check if the new zEntry number is the reserved entry number. - ****************************************************************************/ - if (entryNum == RESERVED_ENTRYNUM) { - CDF->CURzEntryNum = RESERVED_ENTRYNUM; - CDF->fp->CurAEDRIndex = RESERVED_ENTRYNUM; - CDF->CURzEntryOffset = RESERVED_ENTRYOFFSET; - return pStatus; - } - /**************************************************************************** - * Check that a current attribute is selected. - ****************************************************************************/ - if (CDF->CURattrOffset == RESERVED_ATTROFFSET) { - CDF->CURzEntryNum = entryNum; - CDF->fp->CurAEDRIndex = RESERVED_ENTRYNUM; - CDF->CURzEntryOffset = RESERVED_ENTRYOFFSET; - return pStatus; - } - /**************************************************************************** - * Read the scope and number of the current attribute. If READONLYon, they - * are already in memory. - ****************************************************************************/ - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - if (read_only_mode == READONLYon) - { - scope = CDF->fp->ADRList[CDF->fp->CurADRIndex]->Scope; - attrNum = CDF->fp->CurADRIndex; - } - else - { - if (!sX(ReadADR(CDF->fp,CDF->CURattrOffset, - ADR_SCOPE,&scope, - ADR_NUM,&attrNum, - ADR_NULL),&pStatus)) return pStatus; - }; - /**************************************************************************** - * If the current attribute is global-scoped, then the current zEntry offset - * is n/a. - ****************************************************************************/ - if (GLOBALscope(scope)) { - CDF->CURzEntryNum = entryNum; - CDF->fp->CurAEDRIndex = RESERVED_ENTRYNUM; - CDF->CURzEntryOffset = RESERVED_ENTRYOFFSET; - return pStatus; - } - /**************************************************************************** - * Determine if a AgrEDR or AzEDR and the true entry number. - ****************************************************************************/ - if (zModeON(CDF)) { - if (entryNum < CDF->NrVars) { - zEntry = FALSE; - entryN = entryNum; - } - else { - zEntry = TRUE; - entryN = entryNum - CDF->NrVars; - } - } - else { - zEntry = TRUE; - entryN = entryNum; - } - /**************************************************************************** - * IF READONLYoff, check if the next entry is the one being searched for. - * For this to be the case, an entry must currently be selected and must be - * associated with the current attribute, the next entry must exist, and the - * next entry's number must be the entry number being searched for. But don't - * try this if a V2.0 CDF because of the bad terminating offset of the AEDR - * linked lists in those CDFs. - ****************************************************************************/ - if (read_only_mode == READONLYoff && useCurrent && - !CDF->badTerminatingOffsets) { - if (CDF->CURzEntryOffset != RESERVED_ENTRYOFFSET) { - if (!sX(ReadAEDR(CDF->fp,CDF->CURzEntryOffset, - AEDR_ATTRNUM,&attrNumX, - AEDR_AEDRNEXT,&nextOffset, - AEDR_NULL),&pStatus)) return pStatus; - if (attrNumX == attrNum && nextOffset != 0) { - if (!sX(ReadAEDR(CDF->fp,nextOffset, - AEDR_NUM,&entryNumX, - AEDR_NULL),&pStatus)) return pStatus; - if (entryNumX == entryN) { - CDF->CURzEntryNum = entryNum; - CDF->CURzEntryOffset = nextOffset; - return pStatus; - } - } - } - } - /**************************************************************************** - * Search the list of AEDRs for the entry. - ****************************************************************************/ - tStatus = FindEntryByNumber (CDF, CDF->CURattrOffset, zEntry, entryN, - &offset); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_ENTRY: - offset = RESERVED_ENTRYOFFSET; - break; - default: - return tStatus; - } - CDF->CURzEntryNum = entryNum; - CDF->CURzEntryOffset = offset; - return pStatus; -} - -/****************************************************************************** -* Int32ToCDFid. -******************************************************************************/ - -STATICforIDL CDFid Int32ToCDFid (id) -Int32 id; -{ -#if defined(alphaosf) || defined(IRIX64bit) || defined(_LP64) || \ - defined(__amd64) || defined(__x86_64__) || defined(__ia64__) || \ - defined(__PPC64__) || defined(__ppc64__) || defined(_M_X64) - return cdfid_getCDFid (id, NULL); -#else - return ((CDFid) id); -#endif -} - -/****************************************************************************** -* CDFidToInt32. -* On 64-bit machines (OSF/1, IRIX 6.x and Solaris in 64-bit mode), -* truncation may occur when the pointer (CDFid) is assigned to a 32-bit -* integer. -******************************************************************************/ - -STATICforIDL Int32 CDFidToInt32 (id) -CDFid id; -{ -#if defined(alphaosf) || defined(IRIX64bit) || defined(_LP64) || \ - defined(__amd64) || defined(__x86_64__) || defined(__ia64__) || \ - defined(__PPC64__) || defined(__ppc64__) || defined(_M_X64) - union { - CDFid id; - Int32 i[2]; - } u; - u.id = id; - cdfid_AllocateMemory (id, NULL); -# if defined(alphaosf) || defined(__amd64) || defined(__x86_64__) || \ - defined(__ia64__) || defined(_M_X64) - return u.i[0]; -# endif -# if defined(IRIX64bit) || (defined(_LP64) && defined(_BIG_ENDIAN)) || \ - defined(__PPC64__) || defined(__ppc64__) - return u.i[1]; -# endif -#else - return ((Int32) id); -#endif -} - -/****************************************************************************** -* VariableType. -******************************************************************************/ - -STATICforIDL CDFstatus VariableType (CDF, vdrOffset, zVar, vType) -struct CDFstruct *CDF; -Int32 vdrOffset; -Logical zVar; -int *vType; -{ - CDFstatus pStatus = CDF_OK; Int32 flags, sRecords; - if (!sX(ReadVDR(CDF,CDF->fp,vdrOffset,zVar, - VDR_FLAGS,&flags, - VDR_sRECORDS,&sRecords, - VDR_NULL),&pStatus)) return pStatus; - if (CDF->singleFile) { - if (VARcompressionBITset(flags) && SPARSEarraysBITset(flags)) { - return CORRUPTED_V2_CDF; - } - if (sRecords == NO_SPARSERECORDS) { - *vType = STANDARD_; - if (VARcompressionBITset(flags)) *vType = COMPRESSED_; - if (SPARSEarraysBITset(flags)) *vType = SPARSE_ARRAYS_; - } - else { - *vType = SPARSE_RECORDS_; - if (VARcompressionBITset(flags)) *vType = SPARSE_COMPRESSED_RECORDS_; - if (SPARSEarraysBITset(flags)) *vType = SPARSE_RECORDS_AND_ARRAYS_; - } - } - else { - *vType = IN_MULTI_; - if (VARcompressionBITset(flags)) return CORRUPTED_V2_CDF; - if (SPARSEarraysBITset(flags)) return CORRUPTED_V2_CDF; - if (sRecords != NO_SPARSERECORDS) return CORRUPTED_V2_CDF; - } - return pStatus; -} - -/****************************************************************************** -* CompressionParmsCount. -******************************************************************************/ - -STATICforIDL int CompressionParmsCount (cType) -Int32 cType; -{ - switch (cType) { - case NO_COMPRESSION: return 0; - case RLE_COMPRESSION: return NUM_RLE_PARMS; - case HUFF_COMPRESSION: return NUM_HUFF_PARMS; - case AHUFF_COMPRESSION: return NUM_AHUFF_PARMS; - case GZIP_COMPRESSION: return NUM_GZIP_PARMS; - } - return 0; /* CORRUPTED_V2_CDF or CDF_INTERNAL_ERROR? */ -} - -/****************************************************************************** -* SparsenessParmsCount. -******************************************************************************/ - -STATICforIDL int SparsenessParmsCount (sArraysType) -Int32 sArraysType; -{ - switch (sArraysType) { - case NO_SPARSEARRAYS: - return 0; - } - return 0; /* CORRUPTED_V2_CDF or CDF_INTERNAL_ERROR? */ -} - -/****************************************************************************** -* Compress. -******************************************************************************/ - -STATICforIDL CDFstatus Compress (iFp, iOffset, iSize, iError, cType, cParms, - oFp, oOffset, oSize, oError) -vFILE *iFp; -Int32 iOffset; -Int32 iSize; -CDFstatus iError; -Int32 cType; -Int32 cParms[]; -vFILE *oFp; -Int32 oOffset; -Int32 *oSize; -CDFstatus oError; -{ - CDFstatus pStatus = CDF_OK; - switch (cType) { - case RLE_COMPRESSION: { - if (cParms[0] != RLE_OF_ZEROs) return UNKNOWN_COMPRESSION; - if (!sX(CompressRLE0(iFp,iOffset,iSize,iError, - oFp,oOffset,oSize,oError),&pStatus)) return pStatus; - break; - } - case HUFF_COMPRESSION: - if (cParms[0] != OPTIMAL_ENCODING_TREES) return UNKNOWN_COMPRESSION; - if (!sX(CompressHUFF0(iFp,iOffset, - iSize,iError,oFp, - oOffset,oSize,oError),&pStatus)) return pStatus; - break; - case AHUFF_COMPRESSION: - if (cParms[0] != OPTIMAL_ENCODING_TREES) return UNKNOWN_COMPRESSION; - if (!sX(CompressAHUFF0(iFp,iOffset, - iSize,iError,oFp, - oOffset,oSize,oError),&pStatus)) return pStatus; - break; - case GZIP_COMPRESSION: - if (!INCLUSIVE(1,cParms[0],9)) return UNKNOWN_COMPRESSION; - if (!sX(CompressGZIP(iFp,iOffset,iSize,iError, - oFp,oOffset,oSize, - oError,cParms[0]),&pStatus)) return pStatus; - break; - default: - return UNKNOWN_COMPRESSION; - } - return pStatus; -} - -/****************************************************************************** -* Decompress. -******************************************************************************/ - -STATICforIDL CDFstatus Decompress (iFp, iOffset, iSize, iError, cType, cParms, - oFp, oOffset, oError) -vFILE *iFp; -Int32 iOffset; -Int32 iSize; -CDFstatus iError; -Int32 cType; -Int32 cParms[]; -vFILE *oFp; -Int32 oOffset; -CDFstatus oError; -{ - CDFstatus pStatus = CDF_OK; - switch (cType) { - case RLE_COMPRESSION: { - if (cParms[0] != RLE_OF_ZEROs) return UNKNOWN_COMPRESSION; - if (!sX(DecompressRLE0(iFp,iOffset,iSize,iError, - oFp,oOffset,oError),&pStatus)) return pStatus; - break; - } - case HUFF_COMPRESSION: - if (cParms[0] != OPTIMAL_ENCODING_TREES) return UNKNOWN_COMPRESSION; - if (!sX(DecompressHUFF0(iFp,iOffset,iError, - oFp,oOffset,oError),&pStatus)) return pStatus; - break; - case AHUFF_COMPRESSION: - if (cParms[0] != OPTIMAL_ENCODING_TREES) return UNKNOWN_COMPRESSION; - if (!sX(DecompressAHUFF0(iFp,iOffset,iError, - oFp,oOffset,oError),&pStatus)) return pStatus; - break; - case GZIP_COMPRESSION: - if (!INCLUSIVE(1,cParms[0],9)) return UNKNOWN_COMPRESSION; - if (!sX(DecompressGZIP(iFp,iOffset,iSize,iError, - oFp,oOffset,oError),&pStatus)) return pStatus; - break; - default: - return UNKNOWN_COMPRESSION; - } - return pStatus; -} - -/****************************************************************************** -* DecompressToStage. -******************************************************************************/ - -STATICforIDL CDFstatus DecompressToStage (CDF, Var, offset, uSize) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 offset; -Int32 uSize; -{ - CDFstatus pStatus = CDF_OK; Int32 irType, tOffset; - if (!sX(ReadIrType(CDF->fp,offset,&irType),&pStatus)) return pStatus; - switch (irType) { - case VVR_: { - tOffset = offset + VVR_BASE_SIZE; - if (!sX(CopyBytes(CDF->fp,tOffset, - CDF_READ_ERROR, - uSize,CDF->stage.fp, - Var->stage.areaOffset, - SCRATCH_WRITE_ERROR),&pStatus)) return pStatus; - break; - } - case CVVR_: { - struct CVVRstruct CVVR; - if (!sX(ReadCVVR(CDF->fp,offset, - CVVR_RECORDx,&CVVR, - CVVR_NULL),&pStatus)) return pStatus; - tOffset = offset + CVVR_BASE_SIZE; - if (!sX(Decompress(CDF->fp,tOffset, - CVVR.cSize,CDF_READ_ERROR, - Var->cType,Var->cParms,CDF->stage.fp, - Var->stage.areaOffset, - SCRATCH_WRITE_ERROR),&pStatus)) return pStatus; - break; - } - default: - return CORRUPTED_V2_CDF; - } - return pStatus; -} - -/****************************************************************************** -* ResetReadOnlyState. -******************************************************************************/ - -STATICforIDL void ResetReadOnlyState (CDF) -struct CDFstruct *CDF; -{ - Int32 i, j; - /************************************************************************* - * Free all allocated memory associated with the metadata READONLYon data - * structures and clear all the state variables. - *************************************************************************/ - if (CDF->fp != NULL && CDF->fp->GDR != NULL) - { - for (i = 0; i < CDF->fp->GDR->NumAttr; i++) - { - if (CDF->fp->ADRList[i] != NULL) - { - for (j = 0; j <= CDF->fp->ADRList[i]->MAXgrEntry; j++) - { - if (CDF->fp->ADRList[i]->grAEDRList[j] != NULL) - { - cdf_FreeMemory( - CDF->fp->ADRList[i]->grAEDRList[j]->Value, NULL); - CDF->fp->ADRList[i]->grAEDRList[j]->Value = NULL; - cdf_FreeMemory(CDF->fp->ADRList[i]->grAEDRList[j], - NULL); - CDF->fp->ADRList[i]->grAEDRList[j] = NULL; - }; - }; - if (CDF->fp->ADRList[i]->grAEDRList != NULL) - cdf_FreeMemory(CDF->fp->ADRList[i]->grAEDRList, NULL); - - for (j = 0; j <= CDF->fp->ADRList[i]->MAXzEntry; j++) - { - if (CDF->fp->ADRList[i]->zAEDRList[j] != NULL) - { - cdf_FreeMemory( - CDF->fp->ADRList[i]->zAEDRList[j]->Value, NULL); - CDF->fp->ADRList[i]->zAEDRList[j]->Value = NULL; - cdf_FreeMemory(CDF->fp->ADRList[i]->zAEDRList[j], NULL); - CDF->fp->ADRList[i]->zAEDRList[j] = NULL; - }; - }; - if (CDF->fp->ADRList[i]->zAEDRList != NULL) - cdf_FreeMemory(CDF->fp->ADRList[i]->zAEDRList, NULL); - }; - cdf_FreeMemory(CDF->fp->ADRList[i], NULL); - CDF->fp->ADRList[i] = NULL; - }; - if (CDF->fp->ADRList != NULL) - { - cdf_FreeMemory(CDF->fp->ADRList, NULL); - CDF->fp->ADRList = NULL; - }; - cdf_FreeMemory(CDF->fp->GDR, NULL); - CDF->fp->GDR = NULL; - CDF->fp->CurADRIndex = RESERVED_ENTRYNUM; - CDF->fp->CurAEDRIndex = RESERVED_ENTRYNUM; - CDF->CURattrOffset = RESERVED_ATTROFFSET; - CDF->CURgrEntryOffset = RESERVED_ENTRYOFFSET; - CDF->CURzEntryOffset = RESERVED_ENTRYOFFSET; - }; -} diff --git a/cdf36_3-dist/src/lib/cdfmisc2_64.c b/cdf36_3-dist/src/lib/cdfmisc2_64.c deleted file mode 100644 index 033f227..0000000 --- a/cdf36_3-dist/src/lib/cdfmisc2_64.c +++ /dev/null @@ -1,1933 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF library miscellaneous functions, part 2. -* -* Version 1.3b, 4-Mar-97, Hughes STX. -* -* Modification history: -* -* V1.0 15-Dec-94, J Love Original version. -* V1.1 6-Jan-95, J Love Encode/decode changes. More cache-residency. -* V1.1a 20-Jan-95, J Love IRIX 6.0 (64-bit). -* V1.1b 15-Mar-95, J Love Solaris 2.3 IDL i/f. Fixed `recNum' parameter -* of `LastAllocatedRecord'. Gnu C on OSF/1. -* V1.2 21-Mar-95, J Love POSIX. -* V1.2a 18-Apr-95, J Love More POSIX. -* V1.2b 13-Jun-95, J Love Linux. -* V1.2c 7-Sep-95, J Love CDFexport-related changes. Fixed possible -* memory leak. -* V1.3 5-Sep-96, J Love CDF V2.6. -* V1.3a 21-Feb-97, J Love Removed RICE. -* V1.3b 4-Mar-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V2.0 08-Apr-04, M Liu Modified LocateCurrentVar function to save -* the current selected variable's offset. -* Modified FindVarByNumber and FindVarByName -* functions to start searching for the variable -* from the current selected variable, if it's -* cwselected, instead of always from the -* beginning. Remove the calls to FindVarByNumber -* if a variable is already selected. -* V2.1 04-May-04, M Liu Corrected Int32ToCDFid and CDFidToInt32 to -* handle 64-bit on Solaris/sparc. -* V2.2 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* V3.2 20-Jun-07, D Berger Modified the "FindAttr...", "FindEntry..." -* routines, and the "SetCUR..." routines and -* added ResetReadOnlyState to handle READONLYon -* mode. -* V3.3 10-Jan-09, M Liu Modified to check used entries in LastRecord64. -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* LocateCurrentVar64. -******************************************************************************/ - -STATICforIDL CDFstatus LocateCurrentVar64 (CDF, zOp, offset, zVar, Var) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -Logical zOp; /* In: TRUE if current zVariable is to be - accessed; FALSE if current rVariable. N/A - if zMode is on (since the current zVariable - number will always be used). */ -OFF_T *offset; /* Out: Offset of the current variable's VDR. - This may be a NULL pointer. */ -Logical *zVar; /* Out: TRUE if a true zVariable; FALSE if - a true rVariable. This may be a NULL - pointer. */ -struct VarStruct **Var; /* Out: Pointer to variable. This will be NULL - if the variable has yet to be initialized. - This may be a NULL pointer. */ -{ - CDFstatus tStatus; - OFF_T tOffset; - /**************************************************************************** - * Pass back the offset of the VDR. - ****************************************************************************/ - if (zModeON(CDF)) { - if (CDF->CURzVarNum < CDF->NrVars) { - ASSIGNnotNULL(zVar, FALSE) - tStatus = FindVarByNumber64 (CDF, CDF->CURzVarNum, FALSE, &tOffset); - if (StatusOK(tStatus)) { - ASSIGNnotNULL (Var, CDF->rVars[(int)CDF->CURzVarNum]) - ASSIGNnotNULL (offset, tOffset) - CDF->CURzVarOffset64 = tOffset; - } - } - else { - ASSIGNnotNULL(zVar, TRUE) - tStatus = FindVarByNumber64 (CDF, CDF->CURzVarNum - CDF->NrVars, TRUE, - &tOffset); - if (StatusOK(tStatus)) { - ASSIGNnotNULL (Var, CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]) - ASSIGNnotNULL (offset, tOffset) - CDF->CURzVarOffset64 = tOffset; - } - } - } - else { - ASSIGNnotNULL (zVar, zOp) - tStatus = FindVarByNumber64 (CDF,BOO(zOp,CDF->CURzVarNum, - CDF->CURrVarNum),zOp,&tOffset); - if (StatusOK(tStatus)) { - ASSIGNnotNULL (Var, BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum])) - ASSIGNnotNULL (offset, tOffset) - if (zOp) - CDF->CURzVarOffset64 = tOffset; - else - CDF->CURrVarOffset64 = tOffset; - } - } - return tStatus; -} - -/****************************************************************************** -* InitCurrentVar64. -******************************************************************************/ - -STATICforIDL CDFstatus InitCurrentVar64 (CDF, zOp, Var) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -Logical zOp; /* In: TRUE if current zVariable is to be - accessed; FALSE if current rVariable. N/A - if zMode is on (since the current zVariable - number will always be used [even when a real - rVariable is being accessed]). */ -struct VarStruct **Var; /* Out: Pointer to variable. */ -{ - CDFstatus tStatus; - /**************************************************************************** - * Pass back the pointer to its variable structure. The variable will - * be initialized for access if necessary. - ****************************************************************************/ - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) { - tStatus = InitVar64 (CDF, CDF->CURzVarNum, FALSE, Var); - } - else { - tStatus = InitVar64 (CDF, CDF->CURzVarNum - CDF->NrVars, TRUE, Var); - } - else { - tStatus = InitVar64 (CDF,BOO(zOp,CDF->CURzVarNum,CDF->CURrVarNum),zOp,Var); - }; - return tStatus; -} - -/****************************************************************************** -* InitVar64. -******************************************************************************/ - -STATICforIDL CDFstatus InitVar64 (CDF, varN, zVar, VarP) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -Int32 varN; /* In: Real variable number (ignoring the - zMode). */ -Logical zVar; /* In: TRUE if a real zVariable (ignoring - the zMode). */ -struct VarStruct **VarP; /* Out: Pointer to variable. */ -{ - CDFstatus pStatus = CDF_OK; - struct VarStruct *Var = BOO(zVar,CDF->zVars[(int)varN], - CDF->rVars[(int)varN]); - /**************************************************************************** - * Check if the variable has already been initialized. If not, allocate and - * initialize its variable structure. - ****************************************************************************/ - if (Var == NULL) { - /************************************************************************** - * Allocate a variable structure. - **************************************************************************/ - Var = (struct VarStruct *) cdf_AllocateMemory ((size_t)sizeof(struct VarStruct), NULL); - if (Var == NULL) return BAD_MALLOC; - /************************************************************************** - * Determine offset of the VDR in the dotCDF file. - **************************************************************************/ - if (!sX(FindVarByNumber64(CDF,varN,zVar,&(Var->VDRoffset64)),&pStatus)) { - cdf_FreeMemory (Var, NULL); - return pStatus; - } - - /************************************************************************** - * Initialize miscellaneous fields of the variable structure. - **************************************************************************/ - Var->zVar = zVar; - Var->varN = varN; - Var->fp = NULL; - Var->varCacheSize = NUMcacheVAR; /* N/A if single-file CDF. */ - Var->accessed_at = CDF->pseudo_clock++; - Var->firstRecInVVR = NO_RECORD; - Var->lastRecInVVR = NO_RECORD; - Var->offsetOfVVR64 = (OFF_T) NO_OFFSET64; - /************************************************************************** - * Read fields to be held in memory for efficiency. - **************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_DATATYPE,&(Var->dataType), - VDR_MAXREC,&(Var->maxRec), - VDR_NULL),&pStatus)) { - cdf_FreeMemory (Var, NULL); - return pStatus; - } - /************************************************************************** - * More initialization. - **************************************************************************/ - if (!sX(InitVar2_64(CDF,Var),&pStatus)) { - cdf_FreeMemory (Var, NULL); - return pStatus; - } - /************************************************************************** - * Store pointer to variable structure. - **************************************************************************/ - if (zVar) - CDF->zVars[(int)varN] = Var; - else - CDF->rVars[(int)varN] = Var; - } - /**************************************************************************** - * Pass back pointer to variable. - ****************************************************************************/ - ASSIGNnotNULL (VarP, Var) - return pStatus; -} - -/****************************************************************************** -* InitVar2_64. -******************************************************************************/ - -STATICforIDL CDFstatus InitVar2_64 (CDF, Var) -struct CDFstruct *CDF; -struct VarStruct *Var; -{ - int dimN; CDFstatus pStatus = CDF_OK; struct CPRstruct64 CPR; int i; - Int32 flags, dataType, numElems, sRecords; - OFF_T CPRoffset; - /**************************************************************************** - * Read necessary fields from the VDR. - ****************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_FLAGS,&flags, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_sRECORDS,&sRecords, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * Determine if the variable has a known data type. - ****************************************************************************/ - if (!ValidDataType(dataType)) return BAD_DATA_TYPE; - /**************************************************************************** - * Calculate the dimensionality and variances of the variable based on the - * current zMode. - ****************************************************************************/ - if (!sX(CalcDimParms64(CDF,Var->VDRoffset64, - Var->zVar,&(Var->numDims), - Var->dimSizes,Var->dimVarys),&pStatus)) return pStatus; - Var->recVary = BOO(RECvaryBITset(flags),VARY,NOVARY); - /**************************************************************************** - * Calculate the number of values for each dimension. - ****************************************************************************/ - CalcNumDimValues (CDF, Var); - /**************************************************************************** - * Calculate the element and value sizes. - ****************************************************************************/ - Var->NvalueElems = numElems; - Var->NelemBytes = (Int32) CDFelemSize (dataType); - Var->NvalueBytes = Var->NvalueElems * Var->NelemBytes; - /**************************************************************************** - * Calculate the number of physical and virtual values per record. - ****************************************************************************/ - CalcRecValues (Var); - /**************************************************************************** - * Calculate the number of elements and the size (in bytes) of physical and - * conceptual records. - ****************************************************************************/ - Var->NphyRecElems = Var->NphyRecValues * Var->NvalueElems; - Var->NvirtRecElems = Var->NvirtRecValues * Var->NvalueElems; - Var->NphyRecBytes = Var->NphyRecValues * Var->NvalueBytes; - Var->NvirtRecBytes = Var->NvirtRecValues * Var->NvalueBytes; - /************************************************************************** - * Initialize current positioning. - **************************************************************************/ - Var->seqValueOffset64 = (OFF_T) 0; - Var->zRD.recNumber = 0; - Var->zRD.recCount = 1; - Var->zRD.recInterval = 1; - for (dimN = 0; dimN < Var->numDims; dimN++) { - Var->zRD.dimIndices[dimN] = 0; - Var->zRD.dimCounts[dimN] = Var->dimSizes[dimN]; - Var->zRD.dimIntervals[dimN] = 1; - } - /**************************************************************************** - * Determine variable type. - ****************************************************************************/ - if (!sX(VariableType64(CDF,Var->VDRoffset64, - Var->zVar,&(Var->vType)),&pStatus)) return pStatus; - /************************************************************************** - * What to do if a record is missing. - **************************************************************************/ - Var->prevIfMissing = (sRecords == PREV_SPARSERECORDS); - /************************************************************************** - * Based on the variable type... - **************************************************************************/ - switch (Var->vType) { - case STANDARD_: - case SPARSE_RECORDS_: - if (!sX(LastRecord64(CDF,Var->VDRoffset64,Var->zVar, - &(Var->maxAllocated)),&pStatus)) return pStatus; - Var->maxWritten = Var->maxAllocated; - break; - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_CPRorSPR,&CPRoffset, - VDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadCPR64(CDF->fp,CPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) return pStatus; - Var->cType = CPR.cType; - for (i = 0; i < CPR.pCount; i++) Var->cParms[i] = CPR.cParms[i]; - Var->reservePct = 0; - break; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return UNKNOWN_SPARSENESS; - case IN_MULTI_: - break; - default: - return CDF_INTERNAL_ERROR; - } - /************************************************************************** - * Initialize staging area (although n/a for most variable types). - **************************************************************************/ - Var->stage.areaOffset64 = (OFF_T) NO_OFFSET64; - Var->stage.firstRec = NO_RECORD; - Var->stage.lastRec = NO_RECORD; - Var->stage.dotOffset64 = (OFF_T) NO_OFFSET64; - Var->stage.modified = FALSE; - /**************************************************************************** - * Calculate the blocking factor based on variable type... - ****************************************************************************/ - if (!sX(CalcBF64(CDF,Var),&pStatus)) return pStatus; - /**************************************************************************** - * Determine the encoding and decoding functions to be used. - ****************************************************************************/ - if (!sX(ConversionFunction(dataType,HostEncoding(), - CDF->encoding,CDF->negToPosFp0, - &(Var->EncodeFunction)),&pStatus)) return pStatus; - if (!sX(ConversionFunction(dataType,CDF->encoding, - CDF->decoding,CDF->negToPosFp0, - &(Var->DecodeFunction)),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* CalcBF64. -******************************************************************************/ - -STATICforIDL CDFstatus CalcBF64 (CDF, Var) -struct CDFstruct *CDF; -struct VarStruct *Var; -{ - CDFstatus pStatus = CDF_OK; Int32 bF; - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64, - Var->zVar, VDR_BLOCKING,&bF, - VDR_NULL),&pStatus)) return pStatus; - switch (Var->vType) { - case STANDARD_: - if (Var->recVary) - if (bF == 0) { - Int32 min = ((MIN_BLOCKING_BYTES_standard-1)/Var->NphyRecBytes)+1; - Var->blockingFactor = MAXIMUM(min,MIN_BLOCKING_RECS_standard); - } - else - Var->blockingFactor = bF; - else - Var->blockingFactor = 1; - break; - case SPARSE_RECORDS_: - if (Var->recVary) - if (bF == 0) { - Int32 min = ((MIN_BLOCKING_BYTES_sparse-1)/Var->NphyRecBytes)+1; - Var->blockingFactor = MAXIMUM(min,MIN_BLOCKING_RECS_sparse); - } - else - Var->blockingFactor = bF; - else - Var->blockingFactor = 1; - break; - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - Var->blockingFactor = bF; - break; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return UNKNOWN_SPARSENESS; - case IN_MULTI_: - Var->blockingFactor = 1; - break; - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* UpdateConversions64. -******************************************************************************/ - -STATICforIDL CDFstatus UpdateConversions64 (CDF) -struct CDFstruct *CDF; -{ - CDFstatus pStatus = CDF_OK; Logical zVar; - for (zVar = 0; zVar <= 1; zVar++) { - int varN; Int32 nVars = BOO(zVar,CDF->NzVars,CDF->NrVars); - for (varN = 0; varN < nVars; varN++) { - struct VarStruct *Var = BOO(zVar,CDF->zVars[varN],CDF->rVars[varN]); - if (Var != NULL) { - Int32 dataType; - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64, - Var->zVar, - VDR_DATATYPE,&dataType, - VDR_NULL),&pStatus)) return pStatus; - if (!sX(ConversionFunction(dataType,HostEncoding(), - CDF->encoding,CDF->negToPosFp0, - &(Var->EncodeFunction)),&pStatus)) return - pStatus; - if (!sX(ConversionFunction(dataType,CDF->encoding, - CDF->decoding,CDF->negToPosFp0, - &(Var->DecodeFunction)),&pStatus)) return - pStatus; - } - } - } - return pStatus; -} - -/****************************************************************************** -* UpdateNEWzMode64. -******************************************************************************/ - -STATICforIDL CDFstatus UpdateNEWzMode64 (CDF) -struct CDFstruct *CDF; -{ - CDFstatus pStatus = CDF_OK; Logical zVar; - for (zVar = 0; zVar <= 1; zVar++) { - int varN; Int32 nVars = BOO(zVar,CDF->NzVars,CDF->NrVars); - for (varN = 0; varN < nVars; varN++) { - struct VarStruct *Var = BOO(zVar,CDF->zVars[varN],CDF->rVars[varN]); - if (Var != NULL) { - if (!sX(CalcDimParms64(CDF,Var->VDRoffset64, - Var->zVar,&(Var->numDims), - Var->dimSizes, - Var->dimVarys),&pStatus)) return pStatus; - CalcNumDimValues (CDF, Var); - CalcRecValues (Var); - Var->NvirtRecElems = Var->NvirtRecValues * Var->NvalueElems; - Var->NvirtRecBytes = Var->NvirtRecValues * Var->NvalueBytes; - } - } - } - return pStatus; -} - -/****************************************************************************** -* OpenVar64. -* Open a variable for read and/or write access (if this is a multi-file CDF -* and the variable file is closed). It is assumed that the variable has been -* initialized for access and that the variable is closed (and in a multi-file -* CDF). -******************************************************************************/ - -STATICforIDL CDFstatus OpenVar64 (CDF, Var) -struct CDFstruct *CDF; -struct VarStruct *Var; -{ - CDFstatus pStatus = CDF_OK; - char a_mode[MAX_aMODE_LEN+1], pathname[DU_MAX_PATH_LEN+1]; - /**************************************************************************** - * Try to open the variable file. - ****************************************************************************/ - BuildFilePath (BOO(Var->zVar,Zt,Vt), CDF->CDFname, CDF->no_append, - CDF->upper_case_ext, CDF->version_numbers, Var->varN, - pathname); - if (CDF->status == READ_WRITE) - strcpyX (a_mode, READ_PLUS_a_mode, MAX_aMODE_LEN); - else - strcpyX (a_mode, READ_ONLY_a_mode, MAX_aMODE_LEN); - Var->fp = V_open64 (pathname, a_mode); - /**************************************************************************** - * If the open failed, close a variable file and try. If that attempt fails - * return an error. - ****************************************************************************/ - if (Var->fp == NULL) { - if (!sX(CloseLRUvar(CDF),&pStatus)) return pStatus; - Var->fp = V_open64 (pathname, a_mode); - if (Var->fp == NULL) return VAR_OPEN_ERROR; - } - /**************************************************************************** - * The open was successful - try to set the proper cache size. - ****************************************************************************/ - if (!CACHEv64(Var->fp,Var->varCacheSize)) { - V_close64 (Var->fp, NULL, NULL); - Var->fp = NULL; - return BAD_CACHE_SIZE; - } - return pStatus; -} - -/****************************************************************************** -* LastRecord64. -******************************************************************************/ - -STATICforIDL CDFstatus LastRecord64 (CDF, VDRoffset, zVar, recNum) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -OFF_T VDRoffset; /* In: Offset of VDR. */ -Logical zVar; /* In: TRUE if a real zVariable; FALSE if rVariable. */ -Int32 *recNum; /* Out: Last record allocated. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 nUsedEntries, lastRecs[MAX_VXR_ENTRIES]; - OFF_T VXRoffset; - if (!sX(ReadVDR64(CDF,CDF->fp,VDRoffset,zVar, - VDR_VXRTAIL,&VXRoffset, - VDR_NULL),&pStatus)) return pStatus; - if (VXRoffset == 0) - *recNum = NO_RECORD; - else { - if (!sX(ReadVXR64(CDF->fp,VXRoffset, - VXR_NUSEDENTRIES,&nUsedEntries, - VXR_LASTREC,lastRecs, - VXR_NULL),&pStatus)) return pStatus; - if ((int)nUsedEntries > MAX_VXR_ENTRIES) return CORRUPTED_V3_CDF; - *recNum = lastRecs[(int)(nUsedEntries-1)]; - } - return pStatus; -} - -/****************************************************************************** -* RecordByteOffset64. -******************************************************************************/ - -STATICforIDL CDFstatus RecordByteOffset64 (CDF, Var, phyRecN, offsetP) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 phyRecN; -OFF_T *offsetP; -{ - CDFstatus pStatus = CDF_OK; - Int32 firstRec=-1, lastRec=-1; - OFF_T offset = (OFF_T) -1; - switch (Var->vType) { - case STANDARD_: - case SPARSE_RECORDS_: { - if (Var->firstRecInVVR <= phyRecN && phyRecN <= Var->lastRecInVVR) { - *offsetP = Var->offsetOfVVR64 + (OFF_T) (VVR_BASE_SIZE64 + ((OFF_T) - Var->NphyRecBytes) * (phyRecN - Var->firstRecInVVR)); - break; - } - else { - if (!sX(SearchForRecord64(CDF,Var->VDRoffset64,Var->zVar, - phyRecN,&firstRec,&lastRec, - &offset,NULL),&pStatus)) return pStatus; - *offsetP = offset + (OFF_T) (VVR_BASE_SIZE64 + ((OFF_T) - Var->NphyRecBytes) * (phyRecN - firstRec)); - Var->firstRecInVVR = firstRec; - Var->lastRecInVVR = lastRec; - Var->offsetOfVVR64 = offset; - break; - } - } - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return CDF_INTERNAL_ERROR; - case IN_MULTI_: - *offsetP = ((OFF_T) phyRecN) * Var->NphyRecBytes; - break; - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* ConfigureNEWzMode64. -******************************************************************************/ - -STATICforIDL CDFstatus ConfigureNEWzMode64 (CDF) -struct CDFstruct *CDF; -{ - CDFstatus pStatus = CDF_OK; - if (!sX(UpdateNEWzMode64(CDF),&pStatus)) return pStatus; - InitCURobjectsStates (CDF); - return pStatus; -} - -/****************************************************************************** -* FindAttrByName64. -******************************************************************************/ - -STATICforIDL CDFstatus FindAttrByName64 (CDF, searchName, offset) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -char *searchName; /* In: Attribute name to find. */ -OFF_T *offset; /* Out: Offset of ADR that was found. */ -{ - Int32 numAttrs; - OFF_T tOffset, nextADR, fstADR; - char attrName[CDF_ATTR_NAME_LEN256+1]; - CDFstatus pStatus = CDF_OK; - Int32 attrN; - long read_only_mode; - - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - - /************************************************************************** - * If in READONLYon mode, set CurADRIndex to the referenced attribute number. - ***************************************************************************/ - if (read_only_mode == READONLYon) - { - for (attrN = 0; attrN < CDF->fp->GDR64->NumAttr; attrN++) - { - if (!strcmpITB(CDF->fp->ADRList64[attrN]->Name,searchName)) - { - CDF->fp->CurADRIndex = attrN; - ASSIGNnotNULL (offset, DUMMY_ENTRYOFFSET); - return CDF_OK; - }; - }; - } - else - { - /************************************************************************ - * Read number of attributes and the offset of the first ADR from the GDR. - *************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_NUMATTR,&numAttrs, - GDR_ADRHEAD,&fstADR, - GDR_NULL),&pStatus)) return pStatus; - /************************************************************************ - * Read from ADRs until a matching attribute name is found. - * Note that if this is a V2.0 CDF, the last ADR will not have an - * offset of zero for the next ADR. For that reason, we will loop - * through the number of attributes read from the GDR (and then stop). - ************************************************************************/ - if (CDF->CURattrOffset64 != (OFF_T) (OFF_T) RESERVED_ATTROFFSET64) - tOffset = CDF->CURattrOffset64; - else - tOffset = fstADR; - - for (attrN = 0; attrN < numAttrs; attrN++) { - if (!sX(ReadADR64(CDF->fp,tOffset, - ADR_NAME,attrName, - ADR_ADRNEXT,&nextADR, - ADR_NULL),&pStatus)) return pStatus; - if (!strcmpITB(attrName,searchName)) { - ASSIGNnotNULL (offset, tOffset) - return CDF_OK; - } - if (nextADR != 0) - tOffset = nextADR; - else - tOffset = fstADR; - }; - }; - /**************************************************************************** - * Attribute name not found, return error. - ****************************************************************************/ - return NO_SUCH_ATTR; -} - -/****************************************************************************** -* FindAttrByNumber64. -******************************************************************************/ - -STATICforIDL CDFstatus FindAttrByNumber64 (CDF, searchNum, offset) -struct CDFstruct *CDF; /* In: Pointer to the CDF. */ -Int32 searchNum; /* In: The attribute number to be found. */ -OFF_T *offset; /* Out: The offset of the located ADR. */ -{ - Int32 numAttrs, attrNum; - OFF_T tOffset, nextADR, fstADR; - CDFstatus pStatus = CDF_OK; - Int32 attrN; - long read_only_mode; - /**************************************************************************** - * Validate. - ****************************************************************************/ - if (searchNum < 0) return BAD_ATTR_NUM; - /**************************************************************************** - * First check if the next attribute is the one being searched for. For this - * to be the case, an attribute must currently be selected, the next attribute - * must exist, and the next attribute's number must be the attribute number - * being searched for. But don't try this if a V2.0 CDF because of the bad - * terminating offset of the ADR linked list in those CDFs. - ****************************************************************************/ -/* - if (!CDF->badTerminatingOffsets) { - if (CDF->CURattrOffset64 != (OFF_T) (OFF_T) RESERVED_ATTROFFSET64) { - OFF_T nextOffset; - if (!sX(ReadADR64(CDF->fp,CDF->CURattrOffset64, - ADR_ADRNEXT,&nextOffset, - ADR_NULL),&pStatus)) return pStatus; - if (nextOffset != 0) { - Int32 nextNum; - if (!sX(ReadADR64(CDF->fp,nextOffset, - ADR_NUM,&nextNum, - ADR_NULL),&pStatus)) return pStatus; - if (nextNum == searchNum) { - *offset = nextOffset; - return pStatus; - } - } - } - } -*/ - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - /*************************************************************************** - * If in read only mode, set CurADRIndex to the searched for atribute number. - ***************************************************************************/ - if (read_only_mode == READONLYon) - { - if (CDF->fp->GDR64->NumAttr <= searchNum) return NO_SUCH_ATTR; - if (searchNum < 0 || searchNum >= CDF->fp->GDR64->NumAttr) return NO_SUCH_ATTR; - CDF->fp->CurADRIndex = searchNum; - ASSIGNnotNULL (offset, DUMMY_ENTRYOFFSET); - return CDF_OK; - } - else - { - /************************************************************************ - * The next attribute isn't the one being searched for. First read the - * number of attributes and the offset of the first ADR from the GDR. - ************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_NUMATTR,&numAttrs, - GDR_ADRHEAD,&fstADR, - GDR_NULL),&pStatus)) return pStatus; - if (numAttrs <= searchNum) return NO_SUCH_ATTR; - if (searchNum < 0 || searchNum >= numAttrs) return NO_SUCH_ATTR; - if (CDF->CURattrOffset64 != (OFF_T) RESERVED_ATTROFFSET64) - tOffset = CDF->CURattrOffset64; - else - tOffset = fstADR; - /************************************************************************* - * Read from ADRs until a matching attribute number is found. - * Note that if this is a V2.0 CDF, the last ADR will not have an - * offset of zero for the next ADR. For that reason, we will loop - * through the number of attributes read from the GDR (and then stop). - *************************************************************************/ - for (attrN = 0; attrN < numAttrs; attrN++) { - if (!sX(ReadADR64(CDF->fp,tOffset, - ADR_NUM,&attrNum, - ADR_ADRNEXT,&nextADR, - ADR_NULL),&pStatus)) return pStatus; - if (attrNum == searchNum) { - ASSIGNnotNULL (offset, tOffset) - return CDF_OK; - } - if (nextADR != 0) - tOffset = nextADR; - else - tOffset = fstADR; - } - /************************************************************************* - * Attribute number not found, internal error or corrupted CDF. - *************************************************************************/ - return CORRUPTED_V3_CDF; - }; -} - -/****************************************************************************** -* FindEntryByNumber64. -******************************************************************************/ - -STATICforIDL CDFstatus FindEntryByNumber64 (CDF, ADRoffset, zEntry, entryN, - offset) -struct CDFstruct *CDF; /* In: Pointer to the CDF. */ -OFF_T ADRoffset; /* In: Offset of attribute's ADR. */ -Logical zEntry; /* In: TRUE if AzEDR list to be searched. - FALSE if AgrEDR list to be searched. */ -Int32 entryN; /* In: The entry number being searched for. */ -OFF_T *offset; /* Out: The offset of the located AEDR. */ -{ - Int32 numEntries, entryNum; - OFF_T tOffset, nextADR; - CDFstatus pStatus = CDF_OK; - Int32 entryX; - long read_only_mode; - /**************************************************************************** - * Read number of entries and the offset of the first AEDR from the ADR. - ****************************************************************************/ - if (!sX(ReadADR64(CDF->fp,ADRoffset, - BOO(zEntry,ADR_NzENTRIES,ADR_NgrENTRIES),&numEntries, - BOO(zEntry,ADR_AzEDRHEAD,ADR_AgrEDRHEAD),&tOffset, - ADR_NULL),&pStatus)) return pStatus; - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - if (read_only_mode == READONLYon) - { - /*********************************************************************** - * If the requested entry exists, set CurAEDRIndex to the entry number and - * set CURzEntrySel to reflect if the entry is in the z list or the gr - * list. - ************************************************************************/ - if (zEntry && entryN <= CDF->fp->ADRList64[CDF->fp->CurADRIndex]-> - MAXzEntry) - { - if (CDF->fp->ADRList64[CDF->fp->CurADRIndex]->zAEDRList64[entryN] - != NULL) - { - CDF->fp->CURzEntrySel = TRUE; - CDF->fp->CurAEDRIndex = entryN; - ASSIGNnotNULL (offset, DUMMY_ENTRYOFFSET) - return pStatus; - } - else - { - return NO_SUCH_ENTRY; - } - } - else if (!zEntry && entryN <= CDF->fp->ADRList64[CDF->fp->CurADRIndex]-> - MAXgrEntry) - { - if (CDF->fp->ADRList64[CDF->fp->CurADRIndex]->grAEDRList64[entryN] - != NULL) - { - CDF->fp->CURzEntrySel = FALSE; - CDF->fp->CurAEDRIndex = entryN; - ASSIGNnotNULL (offset, DUMMY_ENTRYOFFSET) - return pStatus; - } - else - { - return NO_SUCH_ENTRY; - }; - } - else - { - return NO_SUCH_ENTRY; - }; - }; - /**************************************************************************** - * Read from AEDRs until a matching entry number is found. - * Note that if this is a V2.0 CDF, the last AEDR will not have an - * offset of zero for the next AEDR. For that reason, we will loop - * through the number of entries read from the ADR (and then stop). - ****************************************************************************/ - for (entryX = 0; entryX < numEntries; entryX++) { - if (!sX(ReadAEDR64(CDF->fp,tOffset, - AEDR_NUM,&entryNum, - AEDR_AEDRNEXT,&nextADR, - AEDR_NULL),&pStatus)) return pStatus; - if (entryNum == entryN) { - ASSIGNnotNULL (offset, tOffset) - return CDF_OK; - } - tOffset = nextADR; - } - /**************************************************************************** - * Entry number not found. - ****************************************************************************/ - return NO_SUCH_ENTRY; -} - -/****************************************************************************** -* FindLastAttr64. -******************************************************************************/ - -STATICforIDL CDFstatus FindLastAttr64 (CDF, lastOffset) -struct CDFstruct *CDF; /* In: Pointer to the CDF. */ -OFF_T *lastOffset; /* Out: Offset of last attribute's ADR. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 nAttrs; - OFF_T offset; - Int32 attrN; - long read_only_mode; - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - - /************************************************************************* - * If in READONLYon mode, set CurADRIndex to the index of the last - * attribute in menmory. - *************************************************************************/ - if (read_only_mode == READONLYon) - { - *lastOffset = DUMMY_ATTROFFSET; - CDF->fp->CurADRIndex = CDF->fp->GDR64->NumAttr - 1; - } - else - { - /************************************************************************ - * Read number of attributes and the offset of the first ADR. If there are - * no attributes, return an offset of zero. - ************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_NUMATTR,&nAttrs, - GDR_NULL),&pStatus)) return pStatus; - if (nAttrs == 0) { - *lastOffset = 0; - return pStatus; - } - /************************************************************************ - * There is at least one attribute. - * Note that if this is a V2.0 CDF, the last ADR will not have an offset of - * zero for the next ADR. For that reason, we will loop through the number - * of attributes read from the GDR (and then stop). - ************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_ADRHEAD,&offset, - GDR_NULL),&pStatus)) return pStatus; - for (attrN = 0; attrN < nAttrs - 1; attrN++) { - if (!sX(ReadADR64(CDF->fp,offset, - ADR_ADRNEXT,&offset, - ADR_NULL),&pStatus)) return pStatus; - } - *lastOffset = offset; - }; - return pStatus; -} - -/****************************************************************************** -* FindLastEntry64. -******************************************************************************/ - -STATICforIDL CDFstatus FindLastEntry64 (CDF, ADRoffset, zEntry, lastOffset) -struct CDFstruct *CDF; /* In: Pointer to the CDF. */ -OFF_T ADRoffset; /* In: Offset of attribute's ADR. */ -Logical zEntry; /* In: TRUE if (real) zEntry is being searched - for; FALSE if gEntry/rEntry. */ -OFF_T *lastOffset; /* Out: The offset of the last AEDR. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 nEntries; - OFF_T offset; - Int32 entryX; - long read_only_mode; - - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - /*********************************************************************** - * If in READONLYon mode, set CurAEDRIndex to MAXzEntry or MAXgrEntry, as - * appropriate. - ***********************************************************************/ - if (read_only_mode == READONLYon) - { - *lastOffset = DUMMY_ENTRYOFFSET; - if (zEntry == TRUE) - { - CDF->fp->CurAEDRIndex = - CDF->fp->ADRList64[CDF->fp->CurADRIndex]->MAXzEntry; - } - else - { - CDF->fp->CurAEDRIndex = - CDF->fp->ADRList64[CDF->fp->CurADRIndex]->MAXgrEntry; - }; - } - else - { - /************************************************************************ - * Read offset of first AEDR and determine if there are any entries (of the - * specified type). If there are none, pass back an offset of zero. - ************************************************************************/ - if (!sX(ReadADR64(CDF->fp,ADRoffset, - BOO(zEntry,ADR_AzEDRHEAD,ADR_AgrEDRHEAD), - &offset,ADR_NULL),&pStatus)) return pStatus; - if (offset == 0) { - *lastOffset = 0; - return pStatus; - } - /************************************************************************ - * There is at least one entry. Read the actual number of entries and then - * scan through to the last one. - * Note that if this is a V2.0 CDF, the last AEDR will not have an - * offset of zero for the next AEDR. For that reason, we will loop - * through the number of entries (minus one) read from the ADR (and then - * stop). - ************************************************************************/ - if (!sX(ReadADR64(CDF->fp,ADRoffset, - BOO(zEntry,ADR_NzENTRIES,ADR_NgrENTRIES),&nEntries, - ADR_NULL),&pStatus)) return pStatus; - for (entryX = 0; entryX < nEntries - 1; entryX++) { - if (!sX(ReadAEDR64(CDF->fp,offset, - AEDR_AEDRNEXT,&offset, - AEDR_NULL),&pStatus)) return pStatus; - } - *lastOffset = offset; - }; - return pStatus; -} - -/****************************************************************************** -* FindPrevEntry64. -******************************************************************************/ - -STATICforIDL CDFstatus FindPrevEntry64 (CDF, ADRoffset, searchOffset, zEntry, - prevOffset) -struct CDFstruct *CDF; /* Pointer to the CDF. */ -OFF_T ADRoffset; /* Offset of attribute's ADR. */ -OFF_T searchOffset; /* The entry offset being searched for. */ -Logical zEntry; /* TRUE if (real) zEntry is being searched for; - FALSE if gEntry/rEntry. */ -OFF_T *prevOffset; /* The offset of the previous AEDR. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 nEntries; - OFF_T offset, nextOffset; - int entryX; - /**************************************************************************** - * Read the offset of the first AEDR. If that offset is the same as the - * search offset, return an offset of zero. - ****************************************************************************/ - if (!sX(ReadADR64(CDF->fp,ADRoffset, - BOO(zEntry,ADR_AzEDRHEAD,ADR_AgrEDRHEAD),&offset, - ADR_NULL),&pStatus)) return pStatus; - if (offset == searchOffset) { - *prevOffset = 0; - return pStatus; - } - /**************************************************************************** - * The first AEDR is not at the search offset. Read the actual number of - * entries and then scan through them looking for the AEDR offset being - * searched for. If the search offset is not found, then either the CDF is - * corrupted or an internal logic error has occurred. - * Note that if this is a V2.0 CDF, the last AEDR will not have an - * offset of zero for the next AEDR. For that reason, we will loop - * through the number of entries read from the ADR (and then stop). - ****************************************************************************/ - if (!sX(ReadADR64(CDF->fp,ADRoffset, - BOO(zEntry,ADR_NzENTRIES,ADR_NgrENTRIES),&nEntries, - ADR_NULL),&pStatus)) return pStatus; - for (entryX = 0; entryX < nEntries; entryX++) { - if (!sX(ReadAEDR64(CDF->fp,offset, - AEDR_AEDRNEXT,&nextOffset, - AEDR_NULL),&pStatus)) return pStatus; - if (nextOffset == searchOffset) { - *prevOffset = offset; - return pStatus; - } - offset = nextOffset; - } - return CORRUPTED_V3_CDF; -} - -/****************************************************************************** -* FindVarByName64. -* Both the rVariable and zVariable lists are searched (since variable names -* are unique in a CDF). -******************************************************************************/ - -STATICforIDL CDFstatus FindVarByName64 (CDF, searchName, offset, zVar, Var) -struct CDFstruct *CDF; /* In: Pointer to the CDF. */ -char *searchName; /* In: The variable name being searched for. */ -OFF_T *offset; /* Out: Offset of the zVDR/rVDR. */ -Logical *zVar; /* Out: TRUE if a zVariable. */ -struct VarStruct **Var; /* Out: Pointer to variable structure. */ -{ - int varN; - char varName[CDF_VAR_NAME_LEN256+1]; - CDFstatus pStatus = CDF_OK; - OFF_T tOffset, nextVDR; - OFF_T headOffset; - /**************************************************************************** - * Read from rVDRs until a matching variable name is found. - * Note that if this is a V2.0 CDF, the last rVDR will not have an - * offset of zero for the next rVDR. For that reason, we will loop - * through the number of rVariables (and then stop). - ****************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_rVDRHEAD,&headOffset, - GDR_NULL),&pStatus)) return pStatus; - - if (CDF->CURrVarNum != RESERVED_VARNUM) - tOffset = CDF->CURrVarOffset64; - else - tOffset = headOffset; - - for (varN = 0; varN < CDF->NrVars; varN++) { - if (!sX(ReadVDR64(CDF,CDF->fp,tOffset,FALSE, - VDR_NAME,varName, - VDR_VDRNEXT,&nextVDR, - VDR_NULL),&pStatus)) return pStatus; - if (!strcmpITB(varName,searchName)) { - ASSIGNnotNULL (offset, tOffset) - ASSIGNnotNULL (zVar, FALSE) - ASSIGNnotNULL (Var, CDF->rVars[varN]) - return CDF_OK; - } - if (nextVDR == 0) tOffset = headOffset; - else tOffset = nextVDR; - } - /**************************************************************************** - * Read from zVDRs until a matching variable name is found. - ****************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_zVDRHEAD,&headOffset, - GDR_NULL),&pStatus)) return pStatus; -/* - if (CDF->CURzVarNum != RESERVED_VARNUM) - tOffset = CDF->CURzVarOffset64; - else -*/ - tOffset = headOffset; - - for (varN = 0; varN < CDF->NzVars; varN++) { - if (!sX(ReadVDR64(CDF,CDF->fp,tOffset,TRUE, - VDR_NAME,varName, - VDR_VDRNEXT,&nextVDR, - VDR_NULL),&pStatus)) return pStatus; - if (!strcmpITB(varName,searchName)) { - ASSIGNnotNULL (offset, tOffset) - ASSIGNnotNULL (zVar, TRUE) - ASSIGNnotNULL (Var, CDF->zVars[varN]) - return CDF_OK; - } - if (nextVDR == 0) tOffset = headOffset; - else tOffset = nextVDR; - } - /**************************************************************************** - * Variable name not found, return error. - ****************************************************************************/ - return NO_SUCH_VAR; -} - -/****************************************************************************** -* FindVarByNumber64. -******************************************************************************/ - -STATICforIDL CDFstatus FindVarByNumber64 (CDF, searchNum, zVar, offset) -struct CDFstruct *CDF; /* In: Pointer to CDF. */ -Int32 searchNum; /* In: Variable number to be searched for. */ -Logical zVar; /* In: TRUE if a (real) zVariable number should be - found. */ -OFF_T *offset; /* Out: offset of the VDR. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 nVars = BOO(zVar,CDF->NzVars,CDF->NrVars); - Int32 varNum; - OFF_T tOffset, nextVDR, fstOffset; - int varN; - /**************************************************************************** - * Read offset of first VDR. - ****************************************************************************/ - if (searchNum < 0) return BAD_VAR_NUM; - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - BOO(zVar,GDR_zVDRHEAD,GDR_rVDRHEAD),&fstOffset, - GDR_NULL),&pStatus)) return pStatus; - if (nVars <= searchNum) return NO_SUCH_VAR; - /**************************************************************************** - * Read from VDRs until a matching variable number is found. - * Note that if this is a V2.0 CDF, the last VDR will not have an - * offset of zero for the next VDR. For that reason, we will loop - * through the number of variables (and then stop). - ****************************************************************************/ - - if (zModeON(CDF)) { - tOffset = fstOffset; - if (CDF->CURzVarNum != RESERVED_VARNUM) { - long numT = BOO(zVar, CDF->CURzVarNum-CDF->NrVars, CDF->CURzVarNum); - if (numT > -1 && numT <= searchNum) tOffset = CDF->CURzVarOffset64; - } - } - else { - if (zVar) { - if (CDF->CURzVarNum != RESERVED_VARNUM && CDF->CURzVarNum < searchNum) - tOffset = CDF->CURzVarOffset64; - else - tOffset = fstOffset; - } else { - if (CDF->CURrVarNum != RESERVED_VARNUM && CDF->CURrVarNum < searchNum) - tOffset = CDF->CURrVarOffset64; - else - tOffset = fstOffset; - } - } - - /**************************************************************************** - * Search for the variable from the current selected variabale, instead of - * the top of the variable list. It will speed up the search process if the - * variables are accessed in a orderly sequence. - ****************************************************************************/ - for (varN = 0; varN < nVars; varN++) { - if (!sX(ReadVDR64(CDF,CDF->fp,tOffset,zVar, - VDR_NUM,&varNum, - VDR_VDRNEXT, &nextVDR, - VDR_NULL),&pStatus)) return pStatus; - if (varNum == searchNum) { - ASSIGNnotNULL (offset, tOffset) - return CDF_OK; - } - if (nextVDR != 0) /* Reaching the end of the list? */ - tOffset = nextVDR; /* No.... Continue. */ - else - tOffset = fstOffset; /* Yes... Go back to the top. */ - } - /**************************************************************************** - * Variable number not found, return error. - ****************************************************************************/ - return CORRUPTED_V3_CDF; -} - -/****************************************************************************** -* VerifyNoRecordsWritten64. -* Verifies that no records have been written. Both the rVariable and -* zVariable lists are searched. -******************************************************************************/ - -STATICforIDL CDFstatus VerifyNoRecordsWritten64 (CDF, no) -struct CDFstruct *CDF; /* In: Pointer to the CDF. */ -Logical *no; /* Out: If TRUE, no records written. */ -{ - CDFstatus pStatus = CDF_OK; Int32 maxRec; int varN; Logical zVar; - OFF_T tOffset; - /**************************************************************************** - * Read from r/zVDRs until a maximum record greater than NO_RECORD is found. - * Note that if this is a V2.0 CDF, the last rVDR will not have an - * offset of zero for the next rVDR. For that reason, we will loop - * through the number of variables (and then stop). - ****************************************************************************/ - for (zVar = 0; zVar <= 1; zVar++) { - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - BOO(zVar,GDR_zVDRHEAD,GDR_rVDRHEAD),&tOffset, - GDR_NULL),&pStatus)) return pStatus; - for (varN = 0; varN < BOO(zVar,CDF->NzVars,CDF->NrVars); varN++) { - if (!sX(ReadVDR64(CDF,CDF->fp,tOffset,zVar, - VDR_MAXREC,&maxRec, - VDR_VDRNEXT,&tOffset, - VDR_NULL),&pStatus)) return pStatus; - if (maxRec > NO_RECORD) { - *no = FALSE; - return pStatus; - } - } - } - /**************************************************************************** - * No records written. - ****************************************************************************/ - *no = TRUE; - return pStatus; -} - -/****************************************************************************** -* VerifyNoPadsSpecified64. -* Verifies that no pad values have been specified. Both the rVariable -* and zVariable lists are searched. -******************************************************************************/ - -STATICforIDL CDFstatus VerifyNoPadsSpecified64 (CDF, no) -struct CDFstruct *CDF; /* In: Pointer to the CDF. */ -Logical *no; /* Out: If TRUE, no pad values written. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 flags32; OFF_T tOffset; - int varN; - /**************************************************************************** - * Read from rVDRs until a pad value is found. - * Note that if this is a V2.0 CDF, the last rVDR will not have an - * offset of zero for the next rVDR. For that reason, we will loop - * through the number of rVariables (and then stop). - ****************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_rVDRHEAD,&tOffset, - GDR_NULL),&pStatus)) return pStatus; - for (varN = 0; varN < CDF->NrVars; varN++) { - if (!sX(ReadVDR64(CDF,CDF->fp,tOffset,FALSE, - VDR_FLAGS,&flags32, - VDR_NULL),&pStatus)) return pStatus; - if (PADvalueBITset(flags32)) { - *no = FALSE; - return pStatus; - } - if (!sX(ReadVDR64(CDF,CDF->fp,tOffset,FALSE, - VDR_VDRNEXT,&tOffset, - VDR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * Read from zVDRs until a pad value is found. - ****************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_zVDRHEAD,&tOffset, - GDR_NULL),&pStatus)) return pStatus; - for (varN = 0; varN < CDF->NzVars; varN++) { - if (!sX(ReadVDR64(CDF,CDF->fp,tOffset,TRUE, - VDR_FLAGS,&flags32, - VDR_NULL),&pStatus)) return pStatus; - if (PADvalueBITset(flags32)) { - *no = FALSE; - return pStatus; - } - if (!sX(ReadVDR64(CDF,CDF->fp,tOffset,TRUE, - VDR_VDRNEXT,&tOffset, - VDR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * No pad values specified. - ****************************************************************************/ - *no = TRUE; - return pStatus; -} - -/****************************************************************************** -* VerifyNoEntriesWritten64. -******************************************************************************/ - -STATICforIDL CDFstatus VerifyNoEntriesWritten64 (CDF, no) -struct CDFstruct *CDF; -Logical *no; -{ - CDFstatus pStatus = CDF_OK; - Int32 numAttrs, nEntries; OFF_T tOffset; - int attrN; - /**************************************************************************** - * Read number of attributes and the offset of the first ADR from the GDR. - ****************************************************************************/ - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_NUMATTR,&numAttrs, - GDR_ADRHEAD,&tOffset, - GDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * Read from ADRs until an entry is found. - * Note that if this is a V2.0 CDF, the last ADR will not have an - * offset of zero for the next ADR. For that reason, we will loop - * through the number of attributes read from the GDR (and then stop). - ****************************************************************************/ - for (attrN = 0; attrN < numAttrs; attrN++) { - if (!sX(ReadADR64(CDF->fp,tOffset, - ADR_NgrENTRIES,&nEntries, - ADR_NULL),&pStatus)) return pStatus; - if (nEntries > 0) { - *no = FALSE; - return pStatus; - } - if (!sX(ReadADR64(CDF->fp,tOffset, - ADR_NzENTRIES,&nEntries, - ADR_NULL),&pStatus)) return pStatus; - if (nEntries > 0) { - *no = FALSE; - return pStatus; - } - if (!sX(ReadADR64(CDF->fp,tOffset, - ADR_ADRNEXT,&tOffset, - ADR_NULL),&pStatus)) return pStatus; - } - /**************************************************************************** - * No entries detected. - ****************************************************************************/ - *no = TRUE; - return pStatus; -} - -/****************************************************************************** -* DefaultPadBuffer64. -******************************************************************************/ - -STATICforIDL CDFstatus DefaultPadBuffer64 (CDF, Var, nValues, buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -OFF_T nValues; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; - Byte1 *tBuffer = buffer; Int32 dataType, numElems; - Int32 version, release; OFF_T i; - if (!sX(ReadCDR64(CDF->fp,CDF->CDRoffset64, - CDR_VERSION,&version, - CDR_RELEASE,&release, - CDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_NULL),&pStatus)) return pStatus; - for (i = 0; i < nValues; i++, tBuffer += (size_t) Var->NvalueBytes) { - if (version*100+release < 305) - DefaultPadValuePre350 (dataType, numElems, tBuffer); - else - DefaultPadValue (dataType, numElems, tBuffer); - } - return pStatus; -} - -/****************************************************************************** -* PadBuffer64. -******************************************************************************/ - -STATICforIDL CDFstatus PadBuffer64 (CDF, Var, nValues, buffer) -struct CDFstruct *CDF; /* Pointer to CDF. */ -struct VarStruct *Var; /* Pointer to variable. */ -OFF_T nValues; /* Number of values in buffer. */ -void *buffer; /* Buffer to pad. */ -{ - CDFstatus pStatus = CDF_OK; - Int32 flags, dataType, numElems; - /**************************************************************************** - * Read the flags, data type, and number of elements fields of the VDR. - ****************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_FLAGS,&flags, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * If a pad value has been specified for the variable, read the pad value - * from the VDR and duplicate for the desired number of values. Otherwise, - * copy the desired number of default pad values into the buffer. Then - * convert the padded buffer into the desired decoding. - ****************************************************************************/ - if (PADvalueBITset(flags)) { - Byte1 *tBuffer = buffer; Int32 valueN; - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_PADVALUE,tBuffer, - VDR_NULL),&pStatus)) return pStatus; - for (valueN = 1; valueN < nValues; valueN++) { - memmove (tBuffer + ((size_t) Var->NvalueBytes), tBuffer, - (size_t) Var->NvalueBytes); - tBuffer += (size_t) Var->NvalueBytes; - } - if (!sX(ConvertBuffer(CDF->encoding,CDF->decoding, - CDF->negToPosFp0,dataType, - (nValues * numElems), - buffer,buffer),&pStatus)) return pStatus; - } - else { - if (!sX(DefaultPadBuffer64(CDF,Var,nValues,buffer),&pStatus)) return pStatus; - if (!sX(ConvertBuffer(HostEncoding(),CDF->decoding, - CDF->negToPosFp0,dataType, - (nValues * numElems), - buffer,buffer),&pStatus)) return pStatus; - } - return pStatus; -} - -/****************************************************************************** -* CheckEntryOp64. -******************************************************************************/ - -STATICforIDL CDFstatus CheckEntryOp64 (CDF, entryType) -struct CDFstruct *CDF; -int entryType; -{ - Int32 scope; CDFstatus pStatus = CDF_OK; - if (!sX(ReadADR64(CDF->fp,CDF->CURattrOffset64, - ADR_SCOPE,&scope, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (GLOBALscope(scope)) { - if (entryType != gENTRYt) return ILLEGAL_FOR_SCOPE; - } - else { - if (entryType == gENTRYt) return ILLEGAL_FOR_SCOPE; - if (BADzOP(CDF,entryType == rENTRYt)) return ILLEGAL_IN_zMODE; - } - return pStatus; -} - -/****************************************************************************** -* SetCURgrEntry64. -******************************************************************************/ - -STATICforIDL CDFstatus SetCURgrEntry64 (CDF, useCurrent, entryNum) -struct CDFstruct *CDF; -Logical useCurrent; /* TRUE if current g/rEntry offset can be used to speed - up the search. */ -Int32 entryNum; /* The new g/rEntry number. */ -{ - CDFstatus pStatus = CDF_OK, tStatus; - Int32 scope, attrNum, attrNumX, entryNumX; - OFF_T offset, nextOffset; - long read_only_mode; - /**************************************************************************** - * Check if the new g/rEntry number is the reserved entry number. - ****************************************************************************/ - if (entryNum == RESERVED_ENTRYNUM) { - CDF->CURgrEntryNum = RESERVED_ENTRYNUM; - CDF->fp->CurAEDRIndex = RESERVED_ENTRYNUM; - CDF->CURgrEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET64; - return pStatus; - } - /**************************************************************************** - * Check that a current attribute is selected. - ****************************************************************************/ - if (CDF->CURattrOffset64 == (OFF_T) RESERVED_ATTROFFSET64) { - CDF->CURgrEntryNum = entryNum; - CDF->fp->CurAEDRIndex = RESERVED_ENTRYNUM; - CDF->CURgrEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET64; - return pStatus; - } - /**************************************************************************** - * Read the scope and number of the current attribute. If READONLYon, they - * are already in memory. - ****************************************************************************/ - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - if (read_only_mode == READONLYon) - { - scope = CDF->fp->ADRList64[CDF->fp->CurADRIndex]->Scope; - attrNum = CDF->fp->CurADRIndex; - } - else - { - if (!sX(ReadADR64(CDF->fp,CDF->CURattrOffset64, - ADR_SCOPE,&scope, - ADR_NUM,&attrNum, - ADR_NULL),&pStatus)) return pStatus; - }; - /**************************************************************************** - * If the current attribute is variable-scoped and zMode is on, then the - * current g/rEntry offset is n/a. - ****************************************************************************/ - if (VARIABLEscope(scope) && zModeON(CDF)) { - CDF->CURgrEntryNum = entryNum; - CDF->fp->CurAEDRIndex = RESERVED_ENTRYNUM; - CDF->CURgrEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET64; - return pStatus; - } - /**************************************************************************** - * IF READONLYoff, check if the next entry is the one being searched for. - * For this to be the case, an entry must currently be selected and must be - * associated with the current attribute, the next entry must exist, and the - * next entry's number must be the entry number being searched for. But - * don't try this if a V2.0 CDF because of the bad terminating offset of the - * AEDR linked lists in those CDFs. - ****************************************************************************/ - if (read_only_mode == READONLYoff && useCurrent && - !CDF->badTerminatingOffsets) { - if (CDF->CURgrEntryOffset64 != (OFF_T) RESERVED_ENTRYOFFSET64) { - if (!sX(ReadAEDR64(CDF->fp,CDF->CURgrEntryOffset64, - AEDR_ATTRNUM,&attrNumX, - AEDR_AEDRNEXT,&nextOffset, - AEDR_NULL),&pStatus)) return pStatus; - if (attrNumX == attrNum && nextOffset != 0) { - if (!sX(ReadAEDR64(CDF->fp,nextOffset, - AEDR_NUM,&entryNumX, - AEDR_NULL),&pStatus)) return pStatus; - if (entryNumX == entryNum) { - CDF->CURgrEntryNum = entryNum; - CDF->CURgrEntryOffset64 = nextOffset; - return pStatus; - } - } - } - } - /**************************************************************************** - * Search the list of AEDRs for the entry. - ****************************************************************************/ - tStatus = FindEntryByNumber64 (CDF, CDF->CURattrOffset64, FALSE, entryNum, - &offset); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_ENTRY: - offset = (OFF_T) RESERVED_ENTRYOFFSET64; - break; - default: - return tStatus; - } - CDF->CURgrEntryNum = entryNum; - CDF->CURgrEntryOffset64 = offset; - return pStatus; -} - -/****************************************************************************** -* SetCURzEntry64. -******************************************************************************/ - -STATICforIDL CDFstatus SetCURzEntry64 (CDF, useCurrent, entryNum) -struct CDFstruct *CDF; -Logical useCurrent; /* TRUE if current zEntry offset can be used to speed - up the search. */ -Int32 entryNum; /* The new zEntry number. */ -{ - CDFstatus pStatus = CDF_OK, tStatus; - Int32 scope, attrNum, attrNumX, entryNumX; - OFF_T offset, nextOffset; - Logical zEntry; - Int32 entryN; - long read_only_mode; - /**************************************************************************** - * Check if the new zEntry number is the reserved entry number. - ****************************************************************************/ - if (entryNum == RESERVED_ENTRYNUM) { - CDF->CURzEntryNum = RESERVED_ENTRYNUM; - CDF->fp->CurAEDRIndex = RESERVED_ENTRYNUM; - CDF->CURzEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET64; - return pStatus; - } - /**************************************************************************** - * Check that a current attribute is selected. - ****************************************************************************/ - if (CDF->CURattrOffset64 == (OFF_T) RESERVED_ATTROFFSET64) { - CDF->CURzEntryNum = entryNum; - CDF->fp->CurAEDRIndex = RESERVED_ENTRYNUM; - CDF->CURzEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET64; - return pStatus; - } - /**************************************************************************** - * Read the scope and number of the current attribute. If READONLYon, they - * are already in memory. - ****************************************************************************/ - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - if (read_only_mode == READONLYon) - { - scope = CDF->fp->ADRList64[CDF->fp->CurADRIndex]->Scope; - attrNum = CDF->fp->CurADRIndex; - } - else - { - if (!sX(ReadADR64(CDF->fp,CDF->CURattrOffset64, - ADR_SCOPE,&scope, - ADR_NUM,&attrNum, - ADR_NULL),&pStatus)) return pStatus; - }; - /**************************************************************************** - * If the current attribute is global-scoped, then the current zEntry offset - * is n/a. - ****************************************************************************/ - if (GLOBALscope(scope)) { - CDF->CURzEntryNum = entryNum; - CDF->fp->CurAEDRIndex = RESERVED_ENTRYNUM; - CDF->CURzEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET64; - return pStatus; - } - /**************************************************************************** - * Determine if a AgrEDR or AzEDR and the true entry number. - ****************************************************************************/ - if (zModeON(CDF)) { - if (entryNum < CDF->NrVars) { - zEntry = FALSE; - entryN = entryNum; - } - else { - zEntry = TRUE; - entryN = entryNum - CDF->NrVars; - } - } - else { - zEntry = TRUE; - entryN = entryNum; - } - /**************************************************************************** - * IF READONLYoff, check if the next entry is the one being searched for. - * For this to be the case, an entry must currently be selected and must be - * associated with the current attribute, the next entry must exist, and the - * next entry's number must be the entry number being searched for. But don't - * try this if a V2.0 CDF because of the bad terminating offset of the AEDR - * linked lists in those CDFs. - ****************************************************************************/ - if (read_only_mode == READONLYoff && useCurrent && - !CDF->badTerminatingOffsets) { - if (CDF->CURzEntryOffset64 != (OFF_T) RESERVED_ENTRYOFFSET64) { - if (!sX(ReadAEDR64(CDF->fp,CDF->CURzEntryOffset64, - AEDR_ATTRNUM,&attrNumX, - AEDR_AEDRNEXT,&nextOffset, - AEDR_NULL),&pStatus)) return pStatus; - if (attrNumX == attrNum && nextOffset != 0) { - if (!sX(ReadAEDR64(CDF->fp,nextOffset, - AEDR_NUM,&entryNumX, - AEDR_NULL),&pStatus)) return pStatus; - if (entryNumX == entryN) { - CDF->CURzEntryNum = entryNum; - CDF->CURzEntryOffset64 = nextOffset; - return pStatus; - } - } - } - } - /**************************************************************************** - * Search the list of AEDRs for the entry. - ****************************************************************************/ - tStatus = FindEntryByNumber64 (CDF, CDF->CURattrOffset64, zEntry, entryN, - &offset); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_ENTRY: - offset = (OFF_T) RESERVED_ENTRYOFFSET64; - break; - default: - return tStatus; - } - CDF->CURzEntryNum = entryNum; - CDF->CURzEntryOffset64 = offset; - return pStatus; -} - -/****************************************************************************** -* VariableType64. -******************************************************************************/ - -STATICforIDL CDFstatus VariableType64 (CDF, vdrOffset, zVar, vType) -struct CDFstruct *CDF; -OFF_T vdrOffset; -Logical zVar; -int *vType; -{ - CDFstatus pStatus = CDF_OK; Int32 flags, sRecords; - if (!sX(ReadVDR64(CDF,CDF->fp,vdrOffset,zVar, - VDR_FLAGS,&flags, - VDR_sRECORDS,&sRecords, - VDR_NULL),&pStatus)) return pStatus; - if (CDF->singleFile) { - if (VARcompressionBITset(flags) && SPARSEarraysBITset(flags)) { - return CORRUPTED_V3_CDF; - } - if (sRecords == NO_SPARSERECORDS) { - *vType = STANDARD_; - if (VARcompressionBITset(flags)) *vType = COMPRESSED_; - if (SPARSEarraysBITset(flags)) *vType = SPARSE_ARRAYS_; - } - else { - *vType = SPARSE_RECORDS_; - if (VARcompressionBITset(flags)) *vType = SPARSE_COMPRESSED_RECORDS_; - if (SPARSEarraysBITset(flags)) *vType = SPARSE_RECORDS_AND_ARRAYS_; - } - } - else { - *vType = IN_MULTI_; - if (VARcompressionBITset(flags)) return CORRUPTED_V3_CDF; - if (SPARSEarraysBITset(flags)) return CORRUPTED_V3_CDF; - if (sRecords != NO_SPARSERECORDS) return CORRUPTED_V3_CDF; - } - return pStatus; -} - -/****************************************************************************** -* Compress64. -******************************************************************************/ - -STATICforIDL CDFstatus Compress64 (iFp, iOffset, iSize, iError, cType, cParms, - oFp, oOffset, oSize, oError) -vFILE *iFp; -OFF_T iOffset; -OFF_T iSize; -CDFstatus iError; -Int32 cType; -Int32 cParms[]; -vFILE *oFp; -OFF_T oOffset; -OFF_T *oSize; -CDFstatus oError; -{ - CDFstatus pStatus = CDF_OK; - switch (cType) { - case RLE_COMPRESSION: { - if (cParms[0] != RLE_OF_ZEROs) return UNKNOWN_COMPRESSION; - if (!sX(CompressRLE0_64(iFp,iOffset,iSize,iError, - oFp,oOffset,oSize,oError),&pStatus)) return pStatus; - break; - } - case HUFF_COMPRESSION: - if (cParms[0] != OPTIMAL_ENCODING_TREES) return UNKNOWN_COMPRESSION; - if (!sX(CompressHUFF0_64(iFp,iOffset, - iSize,iError,oFp, - oOffset,oSize,oError),&pStatus)) return pStatus; - break; - case AHUFF_COMPRESSION: - if (cParms[0] != OPTIMAL_ENCODING_TREES) return UNKNOWN_COMPRESSION; - if (!sX(CompressAHUFF0_64(iFp,iOffset, - iSize,iError,oFp, - oOffset,oSize,oError),&pStatus)) return pStatus; - break; - case GZIP_COMPRESSION: - if (!INCLUSIVE(1,cParms[0],9)) return UNKNOWN_COMPRESSION; - if (!sX(CompressGZIP_64(iFp,iOffset,iSize,iError, - oFp,oOffset,oSize, - oError,cParms[0]),&pStatus)) return pStatus; - break; - default: - return UNKNOWN_COMPRESSION; - } - return pStatus; -} - -/****************************************************************************** -* Decompress64. -******************************************************************************/ - -STATICforIDL CDFstatus Decompress64 (iFp, iOffset, iSize, iError, cType, cParms, - oFp, oOffset, oError) -vFILE *iFp; -OFF_T iOffset; -OFF_T iSize; -CDFstatus iError; -Int32 cType; -Int32 cParms[]; -vFILE *oFp; -OFF_T oOffset; -CDFstatus oError; -{ - CDFstatus pStatus = CDF_OK; - switch (cType) { - case RLE_COMPRESSION: { - if (cParms[0] != RLE_OF_ZEROs) return UNKNOWN_COMPRESSION; - if (!sX(DecompressRLE0_64(iFp,iOffset,iSize,iError, - oFp,oOffset,oError),&pStatus)) return pStatus; - break; - } - case HUFF_COMPRESSION: - if (cParms[0] != OPTIMAL_ENCODING_TREES) return UNKNOWN_COMPRESSION; - if (!sX(DecompressHUFF0_64(iFp,iOffset,iError, - oFp,oOffset,oError),&pStatus)) return pStatus; - break; - case AHUFF_COMPRESSION: - if (cParms[0] != OPTIMAL_ENCODING_TREES) return UNKNOWN_COMPRESSION; - if (!sX(DecompressAHUFF0_64(iFp,iOffset,iError, - oFp,oOffset,oError),&pStatus)) return pStatus; - break; - case GZIP_COMPRESSION: - if (!INCLUSIVE(1,cParms[0],9)) return UNKNOWN_COMPRESSION; - if (!sX(DecompressGZIP_64(iFp,iOffset,iSize,iError, - oFp,oOffset,oError),&pStatus)) return pStatus; - break; - default: - return UNKNOWN_COMPRESSION; - } - return pStatus; -} - -/****************************************************************************** -* DecompressToStage64. -******************************************************************************/ - -STATICforIDL CDFstatus DecompressToStage64 (CDF, Var, offset, uSize) -struct CDFstruct *CDF; -struct VarStruct *Var; -OFF_T offset; -OFF_T uSize; -{ - CDFstatus pStatus = CDF_OK; Int32 irType; - OFF_T tOffset; - if (!sX(ReadIrType64(CDF->fp,offset,&irType),&pStatus)) return pStatus; - switch (irType) { - case VVR_: { - tOffset = offset + VVR_BASE_SIZE64; - if (!sX(CopyBytes64(CDF->fp,tOffset, - CDF_READ_ERROR, - uSize,CDF->stage.fp, - Var->stage.areaOffset64, - SCRATCH_WRITE_ERROR),&pStatus)) return pStatus; - break; - } - case CVVR_: { - struct CVVRstruct64 CVVR; - if (!sX(ReadCVVR64(CDF->fp,offset, - CVVR_RECORDx,&CVVR, - CVVR_NULL),&pStatus)) return pStatus; - tOffset = offset + CVVR_BASE_SIZE64; - if (!sX(Decompress64(CDF->fp,tOffset, - CVVR.cSize,CDF_READ_ERROR, - Var->cType,Var->cParms,CDF->stage.fp, - Var->stage.areaOffset64, - SCRATCH_WRITE_ERROR),&pStatus)) return pStatus; - break; - } - default: - return CORRUPTED_V3_CDF; - } - return pStatus; -} -/****************************************************************************** -* ResetReadOnlyState64. -******************************************************************************/ - -STATICforIDL void ResetReadOnlyState64 (CDF) -struct CDFstruct *CDF; -{ - int i, j; - /************************************************************************* - * Free all allocated memory associated with the metadata READONLYon data - * structures and clear all the state variables. - *************************************************************************/ - if (CDF->fp != NULL && CDF->fp->GDR64 != NULL) - { - for (i = 0; i < CDF->fp->GDR64->NumAttr; i++) - { - if (CDF->fp->ADRList64[i] != NULL) - { - for (j = 0; j <= CDF->fp->ADRList64[i]->MAXgrEntry; j++) - { - if (CDF->fp->ADRList64[i]->grAEDRList64[j] != NULL) - { - if (CDF->fp->ADRList64[i]->grAEDRList64[j]->Value != - NULL) - { - cdf_FreeMemory( - CDF->fp->ADRList64[i]->grAEDRList64[j]->Value, - NULL); - CDF->fp->ADRList64[i]->grAEDRList64[j]->Value = - NULL; - }; - cdf_FreeMemory( - CDF->fp->ADRList64[i]->grAEDRList64[j], NULL); - CDF->fp->ADRList64[i]->grAEDRList64[j] = NULL; - }; - }; - if (CDF->fp->ADRList64[i]->grAEDRList64 != NULL) - cdf_FreeMemory(CDF->fp->ADRList64[i]->grAEDRList64, NULL); - for (j = 0; j <= CDF->fp->ADRList64[i]->MAXzEntry; j++) - { - if (CDF->fp->ADRList64[i]->zAEDRList64[j] != NULL) - { - if (CDF->fp->ADRList64[i]->zAEDRList64[j]->Value != - NULL) - { - cdf_FreeMemory( - CDF->fp->ADRList64[i]->zAEDRList64[j]->Value, - NULL); - CDF->fp->ADRList64[i]->zAEDRList64[j]->Value = NULL; - }; - cdf_FreeMemory(CDF->fp->ADRList64[i]->zAEDRList64[j], - NULL); - CDF->fp->ADRList64[i]->zAEDRList64[j] = NULL; - }; - }; - if (CDF->fp->ADRList64[i]->zAEDRList64 != NULL) - cdf_FreeMemory(CDF->fp->ADRList64[i]->zAEDRList64, NULL); - }; - cdf_FreeMemory(CDF->fp->ADRList64[i], NULL); - CDF->fp->ADRList64[i] = NULL; - }; - if (CDF->fp->ADRList64 != NULL) - { - cdf_FreeMemory(CDF->fp->ADRList64, NULL); - CDF->fp->ADRList64 = NULL; - }; - cdf_FreeMemory(CDF->fp->GDR64, NULL); - CDF->fp->GDR64 = NULL; - CDF->fp->CurADRIndex = 0; - CDF->fp->CurADRIndex = RESERVED_ENTRYNUM; - CDF->fp->CurAEDRIndex = RESERVED_ENTRYNUM; - CDF->CURattrOffset64 = RESERVED_ATTROFFSET64; - CDF->CURgrEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET64; - CDF->CURzEntryOffset64 = (OFF_T) RESERVED_ENTRYOFFSET64; - }; -} diff --git a/cdf36_3-dist/src/lib/cdfmisc3.c b/cdf36_3-dist/src/lib/cdfmisc3.c deleted file mode 100644 index 4d2cb54..0000000 --- a/cdf36_3-dist/src/lib/cdfmisc3.c +++ /dev/null @@ -1,2934 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF library miscellaneous functions, part 3. -* -* Version 1.0e, 29-Oct-97, Hughes STX. -* -* Modification history: -* -* V1.0 5-Sep-96, J Love Original version. -* V1.0a 21-Feb-97, J Love Removed RICE. -* V1.0b 4-Mar-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V1.0c 11-Sep-97, J Love Magic number are now uInt32. -* V1.0d 20-Oct-97, J Love Properly cast the uInt32 magic numbers. More -* Windows NT. -* V3.2 25-Apr-07, D Berger Changed COPYblockBYTES from 512. -* V3.3 24-Nov-10, M Liu Changed ScratchDirectory to make Windows use -* predefined env. variable "TMP" if "CDF_TMP" -* is not set. -* -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* Macros/function prototypes. -******************************************************************************/ - -#define COPYblockSIZE nCACHE_BUFFER_BYTEs - -static CDFstatus SearchForRecord_r PROTOARGs(( - vFILE *fp, Int32 vxrOffset, Int32 recNum, Int32 *firstRec, Int32 *lastRec, - Int32 *offset, Logical *found -)); -static CDFstatus IndexingStatistics_r PROTOARGs(( - vFILE *fp, Int32 vxrOffset, Int32 maxRec, int level, Int32 *nLevels, - Int32 *nVXRs, Int32 *nEntries, Int32 *nAlloc, Int32 *nRecords -)); -static CDFstatus PrevRecord_r PROTOARGs(( - vFILE *fp, Int32 vxrOffset, Int32 baseRec, Int32 *prevRec, Logical *found -)); -static CDFstatus NextRecord_r PROTOARGs(( - vFILE *fp, Int32 vxrOffset, Int32 baseRec, Int32 *nextRec, Logical *found -)); -static CDFstatus CalcCompressionPct_r PROTOARGs(( - vFILE *fp, Int32 vxrOffset, Int32 nPhyRecBytes, Int32 *uTotal, Int32 *cTotal -)); -static CDFstatus ModIndexOffset_r PROTOARGs(( - vFILE *fp, Int32 vxrOffset, Int32 firstRec, Int32 lastRec, Int32 newOffset -)); -static CDFstatus ReadSparseFull PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 firstRec, Int32 lastRec, - void *buffer -)); -static CDFstatus ReadSparsePartial PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 recNum, Int32 offset, - Int32 nValues, void *buffer -)); -static CDFstatus ReadCompressedFull PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 firstRec, Int32 lastRec, - void *buffer -)); -static CDFstatus ReadCompressedPartial PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 recNum, Int32 offset, - Int32 nValues, void *buffer -)); -static CDFstatus BringToStage PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 recNum, Logical *found -)); -static CDFstatus WriteCompressedRecords PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 firstRec, Int32 lastRec, - void *buffer, Int32 nValues, Int32 offset, Logical fullRecord -)); - -/****************************************************************************** -* DecompressCDF. -******************************************************************************/ - -STATICforIDL CDFstatus DecompressCDF (dotFp, uDotFp) -vFILE *dotFp; /* In: File pointer to dotCDF file. */ -vFILE *uDotFp; /* In: Uncompressed CDF file pointer. */ -{ - CDFstatus pStatus = CDF_OK; struct CCRstruct CCR; struct CPRstruct CPR; - uInt32 magicNumber1 = V2magicNUMBER_1, magicNumber2u = V2magicNUMBER_2u; - Int32 cSize, cOffset; - /**************************************************************************** - * Read/validate CCR. - ****************************************************************************/ - if (!sX(ReadCCR(dotFp,V2_CCR_OFFSET, - CCR_RECORD,&CCR, - CCR_NULL),&pStatus)) return pStatus; - if (CCR.uSize == 0) return EMPTY_COMPRESSED_CDF; - /**************************************************************************** - * Read CPR. - ****************************************************************************/ - if (!sX(ReadCPR(dotFp,CCR.CPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * Write magic numbers. - ****************************************************************************/ - if (!SEEKv(uDotFp,V2_MAGIC_OFFSET_1,vSEEK_SET)) return CDF_WRITE_ERROR; - if (!Write32(uDotFp,(Int32 *)&magicNumber1)) return CDF_WRITE_ERROR; - if (!Write32(uDotFp,(Int32 *)&magicNumber2u)) return CDF_WRITE_ERROR; - /**************************************************************************** - * Copy/decompress. - ****************************************************************************/ - cOffset = V2_CCR_OFFSET + CCR_BASE_SIZE; - cSize = CCR.RecordSize - CCR_BASE_SIZE; - if (!sX(Decompress(dotFp,cOffset, - cSize,CDF_READ_ERROR, - CPR.cType,CPR.cParms, - uDotFp,FIRST_IR_OFFSET, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* WriteCompressedCDF. -******************************************************************************/ - -STATICforIDL CDFstatus WriteCompressedCDF (CDF, CPR, empty) -struct CDFstruct *CDF; -struct CPRstruct *CPR; -Logical empty; /* In: If TRUE, write an empty CCR. */ -{ - uInt32 magicNumber1 = V2magicNUMBER_1; - uInt32 magicNumber2c = V2magicNUMBER_2c; - struct CCRstruct CCR; CDFstatus pStatus = CDF_OK; - /**************************************************************************** - * Write magic numbers. - ****************************************************************************/ - if (!SEEKv(CDF->dotFp,V2_MAGIC_OFFSET_1,vSEEK_SET)) return CDF_WRITE_ERROR; - if (!Write32(CDF->dotFp,(Int32 *)&magicNumber1)) return CDF_WRITE_ERROR; - if (!Write32(CDF->dotFp,(Int32 *)&magicNumber2c)) return CDF_WRITE_ERROR; - /**************************************************************************** - * Write CCR. - ****************************************************************************/ - if (empty) { - CCR.RecordSize = CCR_BASE_SIZE; - CCR.RecordType = CCR_; - CCR.CPRoffset = V2_CCR_OFFSET + CCR.RecordSize; - CCR.uSize = 0; - CCR.rfuA = 0; - if (!sX(WriteCCR(CDF->dotFp,V2_CCR_OFFSET, - CCR_RECORD,&CCR, - CCR_NULL),&pStatus)) return CDF_WRITE_ERROR; - } - else { - Int32 uSize, eof, cSize, cOffset, GDRoffset; - if (!sX(ReadCDR(CDF->uDotFp,V2_CDR_OFFSET, - CDR_GDROFFSET,&GDRoffset, - CDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadGDR(CDF->uDotFp,GDRoffset, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - uSize = eof - FIRST_IR_OFFSET; - cOffset = V2_CCR_OFFSET + CCR_BASE_SIZE; - if (!sX(Compress(CDF->uDotFp,FIRST_IR_OFFSET, - uSize,CDF_READ_ERROR,CPR->cType, - CPR->cParms,CDF->dotFp,cOffset, - &cSize,CDF_WRITE_ERROR),&pStatus)) return pStatus; - CCR.RecordSize = CCR_BASE_SIZE + cSize; - CCR.RecordType = CCR_; - CCR.CPRoffset = V2_CCR_OFFSET + CCR.RecordSize; - CCR.uSize = uSize; - CCR.rfuA = 0; - if (!sX(WriteCCR(CDF->dotFp,V2_CCR_OFFSET, - CCR_RECORD,&CCR, - CCR_NULL),&pStatus)) return CDF_WRITE_ERROR; - } - /**************************************************************************** - * Write CPR. - ****************************************************************************/ - if (!sX(WriteCPR(CDF->dotFp,CCR.CPRoffset, - CPR_RECORD,CPR, - CPR_NULL),&pStatus)) return CDF_WRITE_ERROR; - return pStatus; -} - -/****************************************************************************** -* CopyCDF. -******************************************************************************/ - -STATICforIDL CDFstatus CopyCDF (srcFp, destFp) -vFILE *srcFp; -vFILE *destFp; -{ - Int32 nBytes, offset; Byte1 buffer[nCACHE_BUFFER_BYTEs]; - CDFstatus pStatus = CDF_OK; - if (!SEEKv(srcFp,0L,vSEEK_END)) return CDF_READ_ERROR; - nBytes = V_tell (srcFp); - if (nBytes == EOF) return CDF_READ_ERROR; - if (!SEEKv(srcFp,0L,vSEEK_SET)) return CDF_READ_ERROR; - if (!SEEKv(destFp,0L,vSEEK_SET)) return CDF_WRITE_ERROR; - for (offset = 0; offset < nBytes; offset += nCACHE_BUFFER_BYTEs) { - Int32 nBytesRemaining = nBytes - offset; - size_t count = (size_t) MINIMUM (nBytesRemaining, nCACHE_BUFFER_BYTEs); - if (!READv(buffer,count,1,srcFp)) return CDF_READ_ERROR; - if (!WRITEv(buffer,count,1,destFp)) return CDF_WRITE_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* WriteVarValues. -* NOTE: If more than one record is being written, full records are assumed -* and the `offset' must be zero. -******************************************************************************/ - -STATICforIDL CDFstatus WriteVarValues (CDF, Var, startRec, offset, nValues, - buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 startRec; /* Physical record number at which to write. */ -Int32 offset; /* Byte offset within (first) record at which to - begin writing. */ -Int32 nValues; /* Number of values to write. */ -void *buffer; -{ - Int32 tOffset; Logical fullRecord; Byte1 *tBuffer = buffer; - Int32 numElems, firstRec, lastRec, lastRecInVVR, nBytes, padTo, recNum; - Int32 writeTo, recCount; CDFstatus pStatus = CDF_OK; - /**************************************************************************** - * Determine first/last record(s) being written and if full physical - * record(s). - ****************************************************************************/ - firstRec = startRec; - if (nValues < Var->NphyRecValues) { - fullRecord = FALSE; - lastRec = startRec; - } - else { - fullRecord = TRUE; - lastRec = startRec + ((nValues - 1) / Var->NphyRecValues); - } - /**************************************************************************** - * Based on variable type... - ****************************************************************************/ - switch (Var->vType) { - /************************************************************************** - * Standard variable in single-file CDF... - **************************************************************************/ - case STANDARD_: { - /************************************************************************ - * Allocate/pad records. - ************************************************************************/ - if (lastRec > Var->maxAllocated) { - struct AllocStruct alloc; - Int32 nNeeded = lastRec - Var->maxAllocated; - Int32 nRecords = MAXIMUM(nNeeded,Var->blockingFactor); - LoadAllocVVR (alloc, Var->maxAllocated + 1, - Var->maxAllocated + nRecords, FALSE) - if (!sX(AllocateRecords(CDF,Var,alloc),&pStatus)) return pStatus; - Var->maxAllocated = alloc.last; - } - padTo = BOO(fullRecord,firstRec - 1,firstRec); - if (padTo > Var->maxWritten) { - Int32 padFrom = Var->maxWritten + 1; - if (!sX(PadUnRecords(CDF,Var,padFrom,padTo),&pStatus)) return pStatus; - Var->maxWritten = padTo; - } - /************************************************************************ - * Write value(s). - ************************************************************************/ - if (fullRecord) { - recNum = firstRec; - while (recNum <= lastRec) { - if (!sX(SearchForRecord(CDF,Var->VDRoffset, - Var->zVar,recNum, - NULL,&lastRecInVVR, - NULL,NULL),&pStatus)) return pStatus; - writeTo = MINIMUM(lastRec,lastRecInVVR); - recCount = writeTo - recNum + 1; - if (!sX(RecordByteOffset(CDF,Var, - recNum, - &tOffset),&pStatus)) return pStatus; - numElems = recCount * Var->NphyRecElems; - if (!sX(WriteVarElems(Var,CDF->fp,tOffset, - numElems,tBuffer),&pStatus)) return pStatus; - recNum += recCount; - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - } - } - else { - if (!sX(RecordByteOffset(CDF,Var, - firstRec, - &tOffset),&pStatus)) return pStatus; - tOffset += (Int32) offset; - numElems = nValues * Var->NvalueElems; - if (!sX(WriteVarElems(Var,CDF->fp,tOffset, - numElems,buffer),&pStatus)) return pStatus; - } - /************************************************************************ - * Update the maximum record written. - ************************************************************************/ - Var->maxWritten = MAXIMUM(Var->maxWritten,lastRec); - break; - } - /************************************************************************** - * Sparse records... - **************************************************************************/ - case SPARSE_RECORDS_: { - Int32 maxRecInStage, recordOffsetInStage, nextRec; - int how; void *padBuffer; Logical found; - /************************************************************************ - * Pad records. - ************************************************************************/ - padTo = BOO(fullRecord,firstRec - 1,firstRec); - if (padTo > Var->maxWritten) { - Int32 padFrom = Var->maxWritten + 1; - if (!sX(PadUnRecords(CDF,Var,padFrom,padTo),&pStatus)) return pStatus; - Var->maxWritten = padTo; - } - /************************************************************************ - * Write value(s). - ************************************************************************/ - recNum = firstRec; - while (recNum <= lastRec) { - /********************************************************************** - * Check if this record already exists (is allocated). - **********************************************************************/ - if (!sX(SearchForRecord(CDF,Var->VDRoffset, - Var->zVar,recNum, - NULL,&lastRecInVVR, - NULL,&found),&pStatus)) return pStatus; - if (found) { - writeTo = MINIMUM(lastRec,lastRecInVVR); - recCount = writeTo - recNum + 1; - if (!sX(RecordByteOffset(CDF,Var, - recNum,&tOffset),&pStatus)) return pStatus; - if (fullRecord) - numElems = recCount * Var->NphyRecElems; - else { - tOffset += offset; - numElems = nValues * Var->NvalueElems; - } - if (!sX(WriteVarElems(Var,CDF->fp,tOffset, - numElems,tBuffer),&pStatus)) return pStatus; - Var->maxWritten = MAXIMUM(Var->maxWritten,writeTo); - recNum += recCount; - tBuffer += (size_t) (numElems * Var->NelemBytes); - continue; - } - /********************************************************************** - * This record doesn't exist - initialize the staging area. - **********************************************************************/ - if (Var->stage.areaOffset == NO_OFFSET) { - nBytes = Var->blockingFactor * Var->NphyRecBytes; - if (!sX(InitVarStage(CDF,Var,nBytes),&pStatus)) return pStatus; - } - /********************************************************************** - * Check if this record is in the staging area. - **********************************************************************/ - if (INCLUSIVE(Var->stage.firstRec,recNum,Var->stage.lastRec)) { - maxRecInStage = Var->stage.firstRec + Var->blockingFactor - 1; - writeTo = MINIMUM(lastRec,maxRecInStage); - if (!sX(NextRecord(CDF,Var->VDRoffset,Var->zVar, - recNum,&nextRec,&found),&pStatus)) return pStatus; - if (found) { - Int32 prevRecN = nextRec - 1; - writeTo = MINIMUM(writeTo,prevRecN); - } - recCount = writeTo - recNum + 1; - recordOffsetInStage = recNum - Var->stage.firstRec; - tOffset = Var->stage.areaOffset; - tOffset += (recordOffsetInStage * Var->NphyRecBytes); - if (fullRecord) - numElems = recCount * Var->NphyRecElems; - else { - tOffset += offset; - numElems = nValues * Var->NvalueElems; - } - if (!sX(WriteVarElems(Var,CDF->stage.fp,tOffset, - numElems,tBuffer),&pStatus)) return pStatus; - Var->stage.lastRec = MAXIMUM(Var->stage.lastRec,writeTo); - Var->stage.modified = TRUE; - recNum += recCount; - tBuffer += (size_t) (numElems * Var->NelemBytes); - continue; - } - /********************************************************************** - * This record is not in the staging area. Check if it can be added. - **********************************************************************/ - if (Var->stage.firstRec != NO_RECORD) { - if (recNum == Var->stage.lastRec + 1) { - maxRecInStage = Var->stage.firstRec + Var->blockingFactor - 1; - if (recNum <= maxRecInStage) { - writeTo = MINIMUM(lastRec,maxRecInStage); - if (!sX(NextRecord(CDF,Var->VDRoffset, - Var->zVar,recNum, - &nextRec,&found),&pStatus)) return pStatus; - if (found) { - Int32 prevRecN = nextRec - 1; - writeTo = MINIMUM(writeTo,prevRecN); - } - recCount = writeTo - recNum + 1; - recordOffsetInStage = recNum - Var->stage.firstRec; - tOffset = Var->stage.areaOffset; - tOffset += (recordOffsetInStage * Var->NphyRecBytes); - if (fullRecord) - numElems = recCount * Var->NphyRecElems; - else { - if (!sX(BuildPadBuffer(CDF,Var,recCount, - &how,&padBuffer, - TRUE),&pStatus)) return pStatus; - if (!sX(WritePadValues(Var,CDF->stage.fp,tOffset, - recCount,how,padBuffer),&pStatus)) { - cdf_FreeMemory (padBuffer, NULL); - return pStatus; - } - cdf_FreeMemory (padBuffer, NULL); - tOffset += offset; - numElems = nValues * Var->NvalueElems; - } - if (!sX(WriteVarElems(Var,CDF->stage.fp, - tOffset,numElems, - tBuffer),&pStatus)) return pStatus; - Var->stage.lastRec = MAXIMUM(Var->stage.lastRec,writeTo); - Var->stage.modified = TRUE; - recNum += recCount; - tBuffer += (size_t) (numElems * Var->NelemBytes); - continue; - } - } - } - /********************************************************************** - * This record cannot be added to the staging area. First flush the - * staging area (if necessary)... - **********************************************************************/ - if (!sX(FlushStage(CDF,Var),&pStatus)) return pStatus; - /********************************************************************** - * ...and then start a new staging area with this record. - **********************************************************************/ - maxRecInStage = recNum + Var->blockingFactor - 1; - writeTo = MINIMUM(lastRec,maxRecInStage); - if (!sX(NextRecord(CDF,Var->VDRoffset,Var->zVar, - recNum,&nextRec,&found),&pStatus)) return pStatus; - if (found) { - Int32 prevRecN = nextRec - 1; - writeTo = MINIMUM(writeTo,prevRecN); - } - recCount = writeTo - recNum + 1; - tOffset = Var->stage.areaOffset; - if (fullRecord) - numElems = recCount * Var->NphyRecElems; - else { - if (!sX(BuildPadBuffer(CDF,Var,recCount, - &how,&padBuffer, - TRUE),&pStatus)) return pStatus; - if (!sX(WritePadValues(Var,CDF->stage.fp,tOffset, - recCount,how,padBuffer),&pStatus)) { - cdf_FreeMemory (padBuffer, NULL); - return pStatus; - } - cdf_FreeMemory (padBuffer, NULL); - tOffset += offset; - numElems = nValues * Var->NvalueElems; - } - if (!sX(WriteVarElems(Var,CDF->stage.fp,tOffset, - numElems,tBuffer),&pStatus)) return pStatus; - Var->stage.firstRec = recNum; - Var->stage.lastRec = writeTo; - Var->stage.modified = TRUE; - recNum += recCount; - tBuffer += (size_t) (numElems * Var->NelemBytes); - } - break; - } - /************************************************************************** - * Compressed records... - * Sparse/compressed records... - **************************************************************************/ - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: { - Logical sparseRecords = (Var->vType == SPARSE_COMPRESSED_RECORDS_); - /************************************************************************ - * Initialize staging area. - ************************************************************************/ - if (Var->stage.areaOffset == NO_OFFSET) { - if (Var->blockingFactor == 0) { - if (Var->recVary) { - Int32 bf = ((MIN_BLOCKING_BYTES_compressed-1)/Var->NphyRecBytes)+1; - Var->blockingFactor = MAXIMUM(bf,MIN_BLOCKING_RECS_compressed); - } - else - Var->blockingFactor = 1; - if (!sX(WriteVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_BLOCKING,&(Var->blockingFactor), - VDR_NULL),&pStatus)) return pStatus; - } - nBytes = Var->blockingFactor * Var->NphyRecBytes; - if (!sX(InitVarStage(CDF,Var,nBytes),&pStatus)) return pStatus; - } - /************************************************************************ - * Pad records (if necessary). - ************************************************************************/ - if (!sparseRecords) { - padTo = firstRec - 1; - if (Var->maxRec < padTo) { - Int32 nRecords = padTo + 1, recN, valueN; void *padBuffer; int how; - if (!sX(BuildPadBuffer(CDF,Var, - nRecords,&how, - &padBuffer,FALSE),&pStatus)) return pStatus; - switch (how) { - case ALLrecordsATonce: - if (!sX(WriteCompressedRecords(CDF,Var,Var->maxRec+1, - padTo,padBuffer, - nRecords*Var->NphyRecValues, - ZERO_OFFSET, - TRUE),&pStatus)) { - cdf_FreeMemory (padBuffer, NULL); - return pStatus; - } - break; - case ONErecordATaTIME: - for (recN = Var->maxRec + 1; recN <= padTo; recN++) { - if (!sX(WriteCompressedRecords(CDF,Var,recN,recN, - padBuffer,Var->NphyRecValues, - ZERO_OFFSET,TRUE),&pStatus)) { - cdf_FreeMemory (padBuffer, NULL); - return pStatus; - } - } - break; - case ONEvalueATaTIME: - for (recN = 0; recN < nRecords; recN++) { - for (valueN = 0; valueN < Var->NphyRecValues; valueN++) { - tOffset = valueN * Var->NvalueBytes; - if (!sX(WriteCompressedRecords(CDF,Var,recN,recN, - padBuffer,INT32_ONE, - tOffset,FALSE),&pStatus)) { - cdf_FreeMemory (padBuffer, NULL); - return pStatus; - } - } - } - break; - } - cdf_FreeMemory (padBuffer, NULL); - } - } - /************************************************************************ - * Write the record(s). - ************************************************************************/ - if (!sX(WriteCompressedRecords(CDF,Var,firstRec,lastRec, - buffer,nValues,offset, - fullRecord),&pStatus)) return pStatus; - break; - } - /************************************************************************** - * Can't do sparse arrays yet... - **************************************************************************/ - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return UNKNOWN_SPARSENESS; - /************************************************************************** - * Variable in multi-file CDF... - **************************************************************************/ - case IN_MULTI_: { - padTo = BOO(fullRecord,firstRec - 1,firstRec); - /************************************************************************ - * Extend variable (if necessary). - ************************************************************************/ - if (padTo > Var->maxRec) { - Int32 padFrom = Var->maxRec + 1; - if (!sX(PadUnRecords(CDF,Var,padFrom,padTo),&pStatus)) return pStatus; - } - /************************************************************************ - * Write value(s). - ************************************************************************/ - if (!sX(RecordByteOffset(CDF,Var, - firstRec, - &tOffset),&pStatus)) return pStatus; - tOffset += (Int32) offset; - numElems = nValues * Var->NvalueElems; - if (!sX(WriteVarElems(Var,Var->fp,tOffset, - numElems,buffer),&pStatus)) return pStatus; - break; - } - /************************************************************************** - * Unknown variable type - this should never happen. - **************************************************************************/ - default: - return CDF_INTERNAL_ERROR; - } - /**************************************************************************** - * Update maximum record numbers. - ****************************************************************************/ - if (!sX(UpdateMaxRec(CDF,Var,lastRec),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* WriteVarElems. -* NOTE: On IBM PCs, it is assumed that the number of bytes being written -* will not exceed 65535. -******************************************************************************/ - -STATICforIDL CDFstatus WriteVarElems (Var, fp, offset, numElems, buffer) -struct VarStruct *Var; -vFILE *fp; -Int32 offset; -Int32 numElems; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; Int32 elemCount; - /**************************************************************************** - * Seek to the desired offset. - ****************************************************************************/ - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return VAR_WRITE_ERROR; - if (STRINGdataType(Var->dataType)) { - FillSpacesToString((char *)buffer, (int) numElems, - (int) Var->NvalueElems); - } - /**************************************************************************** - * If no encoding is necessary, simply write the buffer and return. - ****************************************************************************/ - if (Var->EncodeFunction == NULL) { - Int32 nBytes = numElems * Var->NelemBytes; - if (!WRITEv(buffer,1,(size_t)nBytes,fp)) return VAR_WRITE_ERROR; - return pStatus; - } - /**************************************************************************** - * Use as large a temporary buffer as possible for the encoding conversion. - * Start at the full number of elements and then halve that number until an - * allocation succeeds. - ****************************************************************************/ - elemCount = numElems; - for (;;) { - size_t nBytes = (size_t) (elemCount * Var->NelemBytes); - void *tBuffer; - if ((int) nBytes <= 0) return VAR_READ_ERROR; - tBuffer = cdf_AllocateMemory (nBytes, NULL); - if (tBuffer != NULL) { - Int32 elemN = 0; Byte1 *bOffset = buffer; - while (elemN < numElems) { - Int32 thisElemCount = MinInt32 (elemCount, numElems - elemN); - size_t thisByteCount = (size_t) (thisElemCount * Var->NelemBytes); - memmove (tBuffer, bOffset, thisByteCount); - if (!sX(Var->EncodeFunction(tBuffer,thisElemCount),&pStatus)) { - cdf_FreeMemory (tBuffer, NULL); - return pStatus; - } - if (!WRITEv(tBuffer,1,thisByteCount,fp)) { - cdf_FreeMemory (tBuffer, NULL); - return VAR_WRITE_ERROR; - } - elemN += thisElemCount; - bOffset += thisByteCount; - } - cdf_FreeMemory (tBuffer, NULL); - return pStatus; - } - if (elemCount == 1) break; - elemCount = (elemCount + 1) / 2; - } - return BAD_MALLOC; -} - -/****************************************************************************** -* PrevRecord. -* Determine the last record allocated AT or BEFORE `baseRec'. This routine -* should only be used for single-file CDFs. -******************************************************************************/ - -STATICforIDL CDFstatus PrevRecord (CDF, VDRoffset, zVar, baseRec, prevRec, - found) -struct CDFstruct *CDF; -Int32 VDRoffset; -Logical zVar; -Int32 baseRec; -Int32 *prevRec; -Logical *found; /* If NULL, return NO_SUCH_RECORD if the previous - record doesn't exist. Otherwise, set according to - whether or not the previous record exists and - return the pending status. */ -{ - CDFstatus pStatus = CDF_OK; Int32 VXRoffset; - /**************************************************************************** - * If multi-file... - ****************************************************************************/ - if (!CDF->singleFile) return CDF_INTERNAL_ERROR; - /**************************************************************************** - * Single-file...read the offset of the first VXR. - ****************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,VDRoffset,zVar, - VDR_VXRHEAD,&VXRoffset, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * ...and start there (unless there are no VXRs). - ****************************************************************************/ - if (VXRoffset != ZERO_OFFSET) { - if (!sX(PrevRecord_r(CDF->fp,VXRoffset, - baseRec,prevRec,found),&pStatus)) return pStatus; - } - else { - ASSIGNnotNULL (found, FALSE) - if (found == NULL) pStatus = NO_SUCH_RECORD; - } - return pStatus; -} - -static CDFstatus PrevRecord_r (fp, vxrOffset, baseRec, prevRec, found) -vFILE *fp; -Int32 vxrOffset; -Int32 baseRec; -Int32 *prevRec; -Logical *found; -{ - CDFstatus pStatus = CDF_OK; int entryN = 0; - struct VXRstruct VXR, nextVXR; Int32 irType; - /**************************************************************************** - * Read the first VXR. - ****************************************************************************/ - if (!sX(ReadVXR(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * Check if there isn't a previous allocated record. This could only be the - * case at the top level of VXRs (ie. not when this routine is recursively - * called). - ****************************************************************************/ - if (baseRec < VXR.First[0]) { - ASSIGNnotNULL (found, FALSE) - return BOO(found == NULL,NO_SUCH_RECORD,pStatus); - } - /**************************************************************************** - * Until it's time to return... - ****************************************************************************/ - for (;;) { - /************************************************************************* - * If the record is in the current entry... - *************************************************************************/ - if (INCLUSIVE(VXR.First[entryN],baseRec,VXR.Last[entryN])) { - if (!sX(ReadIrType(fp,VXR.Offset[entryN],&irType),&pStatus)) { - return pStatus; - } - switch (irType) { - case VXR_: - return PrevRecord_r(fp,VXR.Offset[entryN],baseRec,prevRec,found); - case VVR_: - case CVVR_: - *prevRec = baseRec; - ASSIGNnotNULL (found, TRUE) - return pStatus; - default: - return CORRUPTED_V2_CDF; - } - } - /************************************************************************* - * If this is the last entry in the current VXR... - *************************************************************************/ - if (entryN == VXR.NusedEntries - 1) { - if (VXR.VXRnext == ZERO_OFFSET) { - *prevRec = VXR.Last[entryN]; - ASSIGNnotNULL (found, TRUE) - return pStatus; - } - if (!sX(ReadVXR(fp,VXR.VXRnext, - VXR_RECORD,&nextVXR, - VXR_NULL),&pStatus)) return pStatus; - if (baseRec < nextVXR.First[0]) { - *prevRec = VXR.Last[entryN]; - ASSIGNnotNULL (found, TRUE) - return pStatus; - } - VXR = nextVXR; - entryN = 0; - } - else { - if (baseRec < VXR.First[entryN+1]) { - *prevRec = VXR.Last[entryN]; - ASSIGNnotNULL (found, TRUE) - return pStatus; - } - entryN++; - } - } -} - -/****************************************************************************** -* NextRecord. -* Determine the next allocated record AT or AFTER `baseRec'. I.e., if -* `baseRec' is allocated, it is returned as `nextRec'. -******************************************************************************/ - -STATICforIDL CDFstatus NextRecord (CDF, VDRoffset, zVar, baseRec, nextRec, - found) -struct CDFstruct *CDF; -Int32 VDRoffset; -Logical zVar; -Int32 baseRec; -Int32 *nextRec; -Logical *found; /* If NULL, return NO_SUCH_RECORD if the next record - doesn't exist. Otherwise, set according to whether - or not the next record exists and return the pending - status. */ -{ - CDFstatus pStatus = CDF_OK; Int32 VXRoffset, maxRec; - /**************************************************************************** - * If multi-file... - ****************************************************************************/ - if (!CDF->singleFile) { - if (!sX(ReadVDR(CDF,CDF->fp,VDRoffset,zVar, - VDR_MAXREC,&maxRec, - VDR_NULL),&pStatus)) return pStatus; - if (baseRec <= maxRec) { - *nextRec = baseRec; - ASSIGNnotNULL (found, TRUE) - } - else { - ASSIGNnotNULL (found, FALSE) - if (found == NULL) pStatus = NO_SUCH_RECORD; - } - return pStatus; - } - /**************************************************************************** - * ...single-file, read the offset of the first VXR. - ****************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,VDRoffset,zVar, - VDR_VXRHEAD,&VXRoffset, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * ...and start there. - ****************************************************************************/ - if (!sX(NextRecord_r(CDF->fp,VXRoffset, - baseRec,nextRec,found),&pStatus)) return pStatus; - return pStatus; -} - -static CDFstatus NextRecord_r (fp, vxrOffset, baseRec, nextRec, found) -vFILE *fp; -Int32 vxrOffset; -Int32 baseRec; -Int32 *nextRec; -Logical *found; -{ - CDFstatus pStatus = CDF_OK; - int entryN; struct VXRstruct VXR; Int32 irType; - /**************************************************************************** - * While more VXRs... - ****************************************************************************/ - while (vxrOffset != ZERO_OFFSET) { - /************************************************************************** - * Read the VXR. - **************************************************************************/ - if (!sX(ReadVXR(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************** - * Search entries... - **************************************************************************/ - if (baseRec <= VXR.Last[(int)(VXR.NusedEntries-1)]) { - for (entryN = 0; entryN < VXR.NusedEntries; entryN++) { - if (baseRec <= VXR.Last[entryN]) { - if (!sX(ReadIrType(fp, - VXR.Offset[entryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - return NextRecord_r(fp,VXR.Offset[entryN], - baseRec,nextRec,found); - case VVR_: - case CVVR_: - *nextRec = BOO(VXR.First[entryN] <= baseRec, - baseRec,VXR.First[entryN]); - ASSIGNnotNULL (found, TRUE) - return pStatus; - default: - return CORRUPTED_V2_CDF; - } - } - } - } - vxrOffset = VXR.VXRnext; - } - /**************************************************************************** - * No (more) VXRs. The record number was never found. - ****************************************************************************/ - ASSIGNnotNULL (found, FALSE) - return BOO(found == NULL,NO_SUCH_RECORD,pStatus); -} - -/****************************************************************************** -* SearchForRecord. -******************************************************************************/ - -STATICforIDL CDFstatus SearchForRecord (CDF, VDRoffset, zVar, recNum, - firstRec, lastRec, offset, found) -struct CDFstruct *CDF; -Int32 VDRoffset; -Logical zVar; -Int32 recNum; -Int32 *firstRec; -Int32 *lastRec; -Int32 *offset; -Logical *found; /* If NULL, return NO_SUCH_RECORD if the record is - not found. Otherwise, set according to whether - or not the record is found and return the pending - status. */ -{ - CDFstatus pStatus = CDF_OK; Int32 vxrOffset, maxRec; - /**************************************************************************** - * If multi-file... - ****************************************************************************/ - if (!CDF->singleFile) { - if (!sX(ReadVDR(CDF,CDF->fp,VDRoffset,zVar, - VDR_MAXREC,&maxRec, - VDR_NULL),&pStatus)) return pStatus; - if (recNum <= maxRec) { - ASSIGNnotNULL (firstRec, 0) - ASSIGNnotNULL (lastRec, maxRec) - ASSIGNnotNULL (offset, ZERO_OFFSET) - ASSIGNnotNULL (found, TRUE) - } - else { - ASSIGNnotNULL (found, FALSE) - if (found == NULL) pStatus = NO_SUCH_RECORD; - } - return pStatus; - } - /**************************************************************************** - * ...single-file, read the offset of the first VXR. - ****************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,VDRoffset,zVar, - VDR_VXRHEAD,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * ...and start searching there. - ****************************************************************************/ - if (!sX(SearchForRecord_r(CDF->fp,vxrOffset,recNum, - firstRec,lastRec, - offset,found),&pStatus)) return pStatus; - return pStatus; -} - -static CDFstatus SearchForRecord_r (fp, vxrOffset, recNum, firstRec, lastRec, - offset, found) -vFILE *fp; -Int32 vxrOffset; -Int32 recNum; -Int32 *firstRec; -Int32 *lastRec; -Int32 *offset; -Logical *found; -{ - CDFstatus pStatus = CDF_OK; - int entryN; struct VXRstruct VXR; Int32 irType; - /**************************************************************************** - * While more VXRs... - ****************************************************************************/ - while (vxrOffset != ZERO_OFFSET) { - /************************************************************************** - * Read the VXR. - **************************************************************************/ - if (!sX(ReadVXR(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************** - * Search entries... - **************************************************************************/ - if (recNum <= VXR.Last[(int)(VXR.NusedEntries-1)]) { - for (entryN = 0; entryN < VXR.NusedEntries; entryN++) { - if (recNum <= VXR.Last[entryN]) { - if (VXR.First[entryN] <= recNum) { - if (!sX(ReadIrType(fp, - VXR.Offset[entryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - return SearchForRecord_r(fp,VXR.Offset[entryN],recNum, - firstRec,lastRec,offset,found); - case VVR_: - case CVVR_: - ASSIGNnotNULL (firstRec, VXR.First[entryN]) - ASSIGNnotNULL (lastRec, VXR.Last[entryN]) - ASSIGNnotNULL (offset, VXR.Offset[entryN]) - ASSIGNnotNULL (found, TRUE) - return pStatus; - default: - return CORRUPTED_V2_CDF; - } - } - else { - ASSIGNnotNULL (found, FALSE) - return BOO(found == NULL,NO_SUCH_RECORD,pStatus); - } - } - } - } - vxrOffset = VXR.VXRnext; - } - /**************************************************************************** - * No (more) VXRs. The record number was never found. - ****************************************************************************/ - ASSIGNnotNULL (found, FALSE) - return BOO(found == NULL,NO_SUCH_RECORD,pStatus); -} - -/****************************************************************************** -* IndexingStatistics. -******************************************************************************/ - -STATICforIDL CDFstatus IndexingStatistics (CDF, VDRoffset, zVar, nVXRsP, - nEntriesP, nAllocP, nRecordsP, - nLevelsP) -struct CDFstruct *CDF; -Int32 VDRoffset; -Logical zVar; -Int32 *nVXRsP; -Int32 *nEntriesP; -Int32 *nAllocP; -Int32 *nRecordsP; -Int32 *nLevelsP; -{ - CDFstatus pStatus = CDF_OK; Int32 vxrOffset, maxRec; int level = 1; - Int32 nVXRs = 0, nEntries = 0, nAlloc = 0, nRecords = 0, nLevels = 0; - /**************************************************************************** - * Read the maximum record and the offset of the first VXR... - ****************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,VDRoffset,zVar, - VDR_VXRHEAD,&vxrOffset, - VDR_MAXREC,&maxRec, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * ...and start there. - ****************************************************************************/ - if (vxrOffset != ZERO_OFFSET) { - if (!sX(IndexingStatistics_r(CDF->fp,vxrOffset, - maxRec,level,&nLevels, - &nVXRs,&nEntries, - &nAlloc,&nRecords),&pStatus)) return pStatus; - } - /**************************************************************************** - * Pass back requested statistics. - ****************************************************************************/ - ASSIGNnotNULL (nVXRsP, nVXRs) - ASSIGNnotNULL (nEntriesP, nEntries) - ASSIGNnotNULL (nAllocP, nAlloc) - ASSIGNnotNULL (nRecordsP, nRecords) - ASSIGNnotNULL (nLevelsP, nLevels) - return pStatus; -} - -static CDFstatus IndexingStatistics_r (fp, vxrOffset, maxRec, level, nLevels, - nVXRs, nEntries, nAlloc, nRecords) -vFILE *fp; -Int32 vxrOffset; -Int32 maxRec; -int level; -Int32 *nLevels; -Int32 *nVXRs; -Int32 *nEntries; -Int32 *nAlloc; -Int32 *nRecords; -{ - CDFstatus pStatus = CDF_OK; - int e; Int32 irType; struct VXRstruct VXR; - /**************************************************************************** - * Check if a new level has been reached. - ****************************************************************************/ - *nLevels = MAXIMUM(*nLevels,level); - /**************************************************************************** - * While more VXRs... - ****************************************************************************/ - while (vxrOffset != ZERO_OFFSET) { - /************************************************************************** - * Read/tally the VXR. - **************************************************************************/ - if (!sX(ReadVXR(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - (*nVXRs)++; - /************************************************************************** - * Scan/count entries... - **************************************************************************/ - for (e = 0; e < VXR.NusedEntries; e++) { - (*nEntries)++; - if (!sX(ReadIrType(fp, - VXR.Offset[e], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - if (!sX(IndexingStatistics_r(fp,VXR.Offset[e], - maxRec,level+1, - nLevels,nVXRs, - nEntries,nAlloc, - nRecords),&pStatus)) return pStatus; - break; - case VVR_: - case CVVR_: - *nAlloc += (VXR.Last[e] - VXR.First[e] + 1); - if (VXR.First[e] <= maxRec) { - *nRecords += MINIMUM(maxRec,VXR.Last[e]) - VXR.First[e] + 1; - } - break; - default: - return CORRUPTED_V2_CDF; - } - } - vxrOffset = VXR.VXRnext; - } - return pStatus; -} - -/****************************************************************************** -* BuildPadBuffer. -******************************************************************************/ - -STATICforIDL CDFstatus BuildPadBuffer (CDF, Var, nRecords, how, buffer, encode) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 nRecords; -int *how; -void **buffer; -Logical encode; /* If TRUE, return values in CDF's encoding. If FALSE, - return values in host computer's encoding. */ -{ - Byte1 *ptr; Int32 nBytes, nValues, valueN; void *padValue; - Int32 VDRflags, dataType, numElems; CDFstatus pStatus = CDF_OK; - /**************************************************************************** - * Determine pad value. - ****************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_FLAGS,&VDRflags, - VDR_NULL),&pStatus)) return pStatus; - padValue = (void *) cdf_AllocateMemory ((size_t) Var->NvalueBytes, NULL); - if (padValue == NULL) return BAD_MALLOC; - if (PADvalueBITset(VDRflags)) { - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_PADVALUE,padValue, - VDR_NULL),&pStatus)) { - cdf_FreeMemory (padValue, NULL); - return pStatus; - } - if (!encode) { - if (!sX(ConvertBuffer(CDF->encoding,HostDecoding(), - CDF->negToPosFp0,dataType, - numElems,padValue,padValue),&pStatus)) { - cdf_FreeMemory (padValue, NULL); - return pStatus; - } - } - } - else { - DefaultPadValuePre350 (dataType, numElems, padValue); - if (encode) { - if (!sX(ConvertBuffer(HostEncoding(),CDF->encoding, - CDF->negToPosFp0,dataType, - numElems,padValue,padValue),&pStatus)) { - cdf_FreeMemory (padValue, NULL); - return pStatus; - } - } - } - /**************************************************************************** - * Try to allocate all of the records at once... - ****************************************************************************/ - nValues = nRecords * Var->NphyRecValues; - nBytes = nValues * Var->NvalueBytes; -#if LIMITof64K - if (nBytes < 65536L) { -#endif - *buffer = (void *) cdf_AllocateMemory ((size_t) nBytes, NULL); - if (*buffer != NULL) { - for (valueN = 0, ptr = (Byte1 *) *buffer; - valueN < nValues; valueN++, ptr += (size_t) Var->NvalueBytes) { - memmove (ptr, padValue, (size_t) Var->NvalueBytes); - } - cdf_FreeMemory (padValue, NULL); - *how = ALLrecordsATonce; - return pStatus; - } -#if LIMITof64K - } -#endif - /**************************************************************************** - * Not enough memory for that, try allocating one record... - ****************************************************************************/ -#if LIMITof64K - if (Var->NphyRecBytes < 65536L) { -#endif - *buffer = (void *) cdf_AllocateMemory ((size_t) Var->NphyRecBytes, NULL); - if (*buffer != NULL) { - for (valueN = 0, ptr = (Byte1 *) *buffer; - valueN < Var->NphyRecValues; - valueN++, ptr += (size_t) Var->NvalueBytes) { - memmove (ptr, padValue, (size_t) Var->NvalueBytes); - } - cdf_FreeMemory (padValue, NULL); - *how = ONErecordATaTIME; - return pStatus; - } -#if LIMITof64K - } -#endif - /**************************************************************************** - * Not enough memory for that either, use the one allocated value... - ****************************************************************************/ - *buffer = padValue; - *how = ONEvalueATaTIME; - return pStatus; -} - -/****************************************************************************** -* ReadVarValues. -* NOTE: If more than one record is being read, full records are assumed -* and the `offset' must be zero. -******************************************************************************/ - -STATICforIDL CDFstatus ReadVarValues (CDF, Var, startRec, offset, nValues, - buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 startRec; /* Physical record number at which to start reading. */ -Int32 offset; /* Byte offset within (first) record at which to - begin reading. */ -Int32 nValues; /* Number of values to read. */ -void *buffer; -{ - CDFstatus pStatus = CDF_OK; Int32 tOffset; Logical fullRecord; - Int32 numElems, firstRec, lastRec, lastRecInVVR, nPadValues; - Int32 readTo, recCount, nBytes; - /**************************************************************************** - * Determine first/last record(s) being read and if full physical record(s). - ****************************************************************************/ - firstRec = startRec; - if (nValues < Var->NphyRecValues) { - fullRecord = FALSE; - lastRec = startRec; - } - else { - fullRecord = TRUE; - lastRec = startRec + ((nValues - 1) / Var->NphyRecValues); - } - /**************************************************************************** - * Read value(s). - ****************************************************************************/ - switch (Var->vType) { - /************************************************************************** - * Standard variable in a single-file CDF... - **************************************************************************/ - case STANDARD_: - if (fullRecord) { - /********************************************************************** - * Full record(s) - read from contiguous groups... - **********************************************************************/ - Byte1 *tBuffer = buffer; Int32 recNum = firstRec; - while (recNum <= lastRec) { - if (recNum <= Var->maxRec) { - if (!sX(SearchForRecord(CDF,Var->VDRoffset, - Var->zVar,recNum, - NULL,&lastRecInVVR, - NULL,NULL),&pStatus)) return pStatus; - readTo = MINIMUMof3(Var->maxRec,lastRec,lastRecInVVR); - recCount = readTo - recNum + 1; - if (!sX(RecordByteOffset(CDF,Var, - recNum, - &tOffset),&pStatus)) return pStatus; - numElems = recCount * Var->NphyRecElems; - if (!sX(ReadVarElems(Var,CDF->fp,tOffset, - numElems,tBuffer),&pStatus)) return pStatus; - } - else { - recCount = lastRec - recNum + 1; - nPadValues = recCount * Var->NphyRecValues; - if (!Var->recVary) { - int ix; - for (ix = 0; ix < (int) recCount; ++ix) - memcpy (tBuffer + ix * Var->NphyRecBytes, - tBuffer - Var->NphyRecBytes, - (size_t) Var->NphyRecBytes); - } else { - if (!sX(PadBuffer(CDF,Var, - nPadValues, - tBuffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - } - } - recNum += recCount; - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - } - } - else { - /********************************************************************** - * Partial record... - **********************************************************************/ - if (firstRec <= Var->maxRec) { - if (!sX(RecordByteOffset(CDF,Var, - firstRec, - &tOffset),&pStatus)) return pStatus; - tOffset += (Int32) offset; - numElems = nValues * Var->NvalueElems; - if (!sX(ReadVarElems(Var,CDF->fp,tOffset, - numElems,buffer),&pStatus)) return pStatus; - } - else { - if (!sX(PadBuffer(CDF,Var,nValues,buffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - } - } - break; - /************************************************************************** - * Sparse records... - **************************************************************************/ - case SPARSE_RECORDS_: { - if (fullRecord) { - if (!sX(ReadSparseFull(CDF,Var,firstRec, - lastRec,buffer),&pStatus)) return pStatus; - } - else { - if (!sX(ReadSparsePartial(CDF,Var, - startRec,offset, - nValues,buffer),&pStatus)) return pStatus; - } - break; - } - /************************************************************************** - * Compressed variable... - **************************************************************************/ - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: { - /************************************************************************ - * Initialize staging area. Note that the staging area is only - * initialized if records have been written. This prevents the - * CORRUPTED_V2_CDF error code from being returned if an explicit - * blocking factor has not been specified for the variable. - ************************************************************************/ - if (Var->stage.areaOffset == NO_OFFSET && Var->maxRec > NO_RECORD) { - if (Var->blockingFactor == 0) return CORRUPTED_V2_CDF; - nBytes = Var->blockingFactor * Var->NphyRecBytes; - if (!sX(InitVarStage(CDF,Var,nBytes),&pStatus)) return pStatus; - } - /************************************************************************ - * If full record(s) or partial record... - ************************************************************************/ - if (fullRecord) { - if (!sX(ReadCompressedFull(CDF,Var,firstRec, - lastRec,buffer),&pStatus)) return pStatus; - } - else { - if (!sX(ReadCompressedPartial(CDF,Var,startRec, - offset,nValues, - buffer),&pStatus)) return pStatus; - } - break; - } - /************************************************************************** - * Can't do sparse arrays yet... - **************************************************************************/ - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return UNKNOWN_SPARSENESS; - case IN_MULTI_: - if (fullRecord) { - /******************************************************************** - * Full record(s). - ********************************************************************/ - Byte1 *tBuffer = buffer; - if (firstRec <= Var->maxRec) { - if (!sX(RecordByteOffset(CDF,Var, - firstRec, - &tOffset),&pStatus)) return pStatus; - recCount = MINIMUM(lastRec,Var->maxRec) - firstRec + 1; - numElems = recCount * Var->NphyRecElems; - if (!sX(ReadVarElems(Var,Var->fp,tOffset, - numElems,tBuffer),&pStatus)) return pStatus; - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - } - if (lastRec > Var->maxRec) { - recCount = BOO(Var->maxRec < firstRec, - lastRec - firstRec + 1, - lastRec - Var->maxRec); - nPadValues = recCount * Var->NphyRecValues; - if (!sX(PadBuffer(CDF,Var, - nPadValues, - tBuffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - } - } - else { - /******************************************************************** - * Partial record. - ********************************************************************/ - if (firstRec <= Var->maxRec) { - if (!sX(RecordByteOffset(CDF,Var, - firstRec, - &tOffset),&pStatus)) return pStatus; - tOffset += (Int32) offset; - numElems = nValues * Var->NvalueElems; - if (!sX(ReadVarElems(Var,Var->fp,tOffset, - numElems,buffer),&pStatus)) return pStatus; - } - else { - if (!sX(PadBuffer(CDF,Var,nValues,buffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - } - } - break; - } - return pStatus; -} - -/****************************************************************************** -* ReadVarElems. -* NOTE: On IBM PCs, it is assumed that the number of bytes being read -* will not exceed 65535. -******************************************************************************/ - -STATICforIDL CDFstatus ReadVarElems (Var, fp, offset, numElems, buffer) -struct VarStruct *Var; -vFILE *fp; -Int32 offset; -Int32 numElems; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; size_t nBytes; - /**************************************************************************** - * Seek to the desired offset. - ****************************************************************************/ - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return VAR_READ_ERROR; - /**************************************************************************** - * Read the value(s). - ****************************************************************************/ - nBytes = (size_t) (numElems * Var->NelemBytes); - if (!READv(buffer,nBytes,1,fp)) return VAR_READ_ERROR; - /**************************************************************************** - * Decode value(s). - ****************************************************************************/ - if (!sX(DECODE(Var->DecodeFunction,buffer,numElems),&pStatus)) { - return pStatus; - } - return pStatus; -} - -/****************************************************************************** -* ROWtoCOL. -******************************************************************************/ - -VISIBLE_PREFIX void ROWtoCOL (iBuffer, oBuffer, numDims, dimSizes, nValueBytes) -void *iBuffer; -void *oBuffer; -long numDims; -long dimSizes[]; -long nValueBytes; -{ - switch (numDims) { - case 0: - case 1: { - long nValues; int dimN; - for (dimN = 0, nValues = 1; dimN < numDims; dimN++) { - nValues *= dimSizes[dimN]; - } - memmove (oBuffer, iBuffer, (size_t) (nValues * nValueBytes)); - break; - } - default: { - long products[CDF_MAX_DIMS]; /* Products, what each dimension is - `worth'. */ - long iBoffset; /* Input buffer, byte offset. */ - long oBoffset; /* Output buffer, byte offset. */ - long oVoffset; /* Output buffer, value offset. */ - int dimN; /* Dimension number. */ - for (dimN = 1, products[0] = 1; dimN < numDims; dimN++) { - products[dimN] = products[dimN-1] * dimSizes[dimN-1]; - } - switch (numDims) { - case 2: { - int d0, d1; /* Indices... */ - for (d0 = 0, iBoffset = 0; d0 < dimSizes[0]; d0++) { - for (d1 = 0; d1 < dimSizes[1]; d1++) { - oVoffset = ((long) d0 * products[0]) + ((long) d1 * products[1]); - oBoffset = oVoffset * nValueBytes; - memmove ((Byte1 *) oBuffer + (size_t) oBoffset, - (Byte1 *) iBuffer + (size_t) iBoffset, - (size_t) nValueBytes); - iBoffset += nValueBytes; - } - } - break; - } - case 3: { - int d0, d1, d2; /* Indices... */ - for (d0 = 0, iBoffset = 0; d0 < dimSizes[0]; d0++) { - for (d1 = 0; d1 < dimSizes[1]; d1++) { - for (d2 = 0; d2 < dimSizes[2]; d2++) { - oVoffset = ((long) d0 * products[0]) + ((long) d1 * products[1]) + - ((long) d2 * products[2]); - oBoffset = oVoffset * nValueBytes; - memmove ((Byte1 *) oBuffer + (size_t) oBoffset, - (Byte1 *) iBuffer + (size_t) iBoffset, - (size_t) nValueBytes); - iBoffset += nValueBytes; - } - } - } - break; - } - default: { - long indices[CDF_MAX_DIMS]; long nValues; int i; - for (dimN = 0; dimN < numDims; dimN++) indices[dimN] = 0; - for (dimN = 0, nValues = 1; dimN < numDims; dimN++) { - nValues *= dimSizes[dimN]; - } - for (i = 0, iBoffset = 0; i < (int) nValues; i++) { - for (oVoffset = 0, dimN = 0; dimN < numDims; dimN++) { - oVoffset += indices[dimN] * products[dimN]; - } - oBoffset = oVoffset * nValueBytes; - memmove ((Byte1 *) oBuffer + (size_t) oBoffset, - (Byte1 *) iBuffer + (size_t) iBoffset, - (size_t) nValueBytes); - iBoffset += nValueBytes; - INCRindicesROW (numDims, dimSizes, indices); - } - break; - } - } - break; - } - } - return; -} - -/****************************************************************************** -* COLtoROW. -******************************************************************************/ - -VISIBLE_PREFIX void COLtoROW (iBuffer, oBuffer, numDims, dimSizes, nValueBytes) -void *iBuffer; -void *oBuffer; -long numDims; -long dimSizes[]; -long nValueBytes; -{ - switch (numDims) { - case 0: - case 1: { - long nValues; int dimN; - for (dimN = 0, nValues = 1; dimN < numDims; dimN++) { - nValues *= dimSizes[dimN]; - } - memmove (oBuffer, iBuffer, (size_t) (nValues * nValueBytes)); - break; - } - default: { - long products[CDF_MAX_DIMS]; /* Products, what each dimension is - `worth'. */ - long iBoffset; /* Input buffer, byte offset. */ - long oBoffset; /* Output buffer, byte offset. */ - long oVoffset; /* Output buffer, value offset. */ - int dimN; /* Dimension number. */ - products[(int)(numDims-1)] = 1; - for (dimN = (int) (numDims - 2); dimN >= 0; dimN--) { - products[dimN] = products[dimN+1] * dimSizes[dimN+1]; - } - switch (numDims) { - case 2: { - int d0, d1; /* Indices... */ - for (d1 = 0, iBoffset = 0; d1 < dimSizes[1]; d1++) { - for (d0 = 0; d0 < dimSizes[0]; d0++) { - oVoffset = ((long) d0 * products[0]) + ((long) d1 * products[1]); - oBoffset = oVoffset * nValueBytes; - memmove ((Byte1 *) oBuffer + (size_t) oBoffset, - (Byte1 *) iBuffer + (size_t) iBoffset, - (size_t) nValueBytes); - iBoffset += nValueBytes; - } - } - break; - } - case 3: { - int d0, d1, d2; /* Indices... */ - for (d2 = 0, iBoffset = 0; d2 < dimSizes[2]; d2++) { - for (d1 = 0; d1 < dimSizes[1]; d1++) { - for (d0 = 0; d0 < dimSizes[0]; d0++) { - oVoffset = ((long) d0 * products[0]) + ((long) d1 * products[1]) + - ((long) d2 * products[2]); - oBoffset = oVoffset * nValueBytes; - memmove ((Byte1 *) oBuffer + (size_t) oBoffset, - (Byte1 *) iBuffer + (size_t) iBoffset, - (size_t) nValueBytes); - iBoffset += nValueBytes; - } - } - } - break; - } - default: { - long indices[CDF_MAX_DIMS]; long nValues; int i; - for (dimN = 0; dimN < numDims; dimN++) indices[dimN] = 0; - for (dimN = 0, nValues = 1; dimN < numDims; dimN++) { - nValues *= dimSizes[dimN]; - } - for (i = 0, iBoffset = 0; i < (int) nValues; i++) { - for (oVoffset = 0, dimN = 0; dimN < numDims; dimN++) { - oVoffset += indices[dimN] * products[dimN]; - } - oBoffset = oVoffset * nValueBytes; - memmove ((Byte1 *) oBuffer + (size_t) oBoffset, - (Byte1 *) iBuffer + (size_t) iBoffset, - (size_t) nValueBytes); - iBoffset += nValueBytes; - INCRindicesCOL (numDims, dimSizes, indices); - } - break; - } - } - break; - } - } - return; -} - -/****************************************************************************** -* INCRindicesROW. -* Increment to next set of indices, row majority. When at the last set of -* indices, roll over to 0,0,0,... -******************************************************************************/ - -VISIBLE_PREFIX void INCRindicesROW (numDims, dimSizes, indices) -long numDims; -long dimSizes[]; -long indices[]; -{ - int dimN; - for (dimN = (int) (numDims - 1); dimN >= 0; dimN--) - if (indices[dimN] == dimSizes[dimN] - 1) - indices[dimN] = 0; - else { - indices[dimN]++; - break; - } - return; -} - -/****************************************************************************** -* INCRindicesCOL. -* Increment to next set of indices, column majority. When at the last set -* of indices, roll over to 0,0,0,... -******************************************************************************/ - -VISIBLE_PREFIX void INCRindicesCOL (numDims, dimSizes, indices) -long numDims; -long dimSizes[]; -long indices[]; -{ - int dimN; - for (dimN = 0; dimN < numDims; dimN++) - if (indices[dimN] == dimSizes[dimN] - 1) - indices[dimN] = 0; - else { - indices[dimN]++; - break; - } - return; -} - -/****************************************************************************** -* InitVarStage. -******************************************************************************/ - -STATICforIDL CDFstatus InitVarStage (CDF, Var, nBytes) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 nBytes; -{ - if (CDF->stage.fp == NULL) { - CDF->stage.fp = V_scratch (ScratchDirectory(CDF), "stg"); - if (CDF->stage.fp == NULL) return SCRATCH_CREATE_ERROR; - if (!CACHEv(CDF->stage.fp,CDF->stage.cacheSize)) { - V_delete (CDF->stage.fp, NULL); - CDF->stage.fp = NULL; - return BAD_CACHE_SIZE; - } - CDF->stage.mark = ZERO_OFFSET; - } - Var->stage.areaOffset = CDF->stage.mark; - Var->stage.firstRec = NO_RECORD; - Var->stage.lastRec = NO_RECORD; - Var->stage.dotOffset = NO_OFFSET; - Var->stage.modified = FALSE; - CDF->stage.mark += nBytes; - return CDF_OK; -} - -/****************************************************************************** -* InitScratch. -******************************************************************************/ - -STATICforIDL CDFstatus InitScratch (scratchDir, scratchFpH, cacheSize) -char *scratchDir; /* Scratch directory to be used. */ -vFILE **scratchFpH; /* Scratch file handle (pointer to pointer). */ -int cacheSize; /* Number of cache buffers to request. */ -{ - if (*scratchFpH == NULL) { - *scratchFpH = V_scratch (scratchDir, NULL); - if (*scratchFpH == NULL) return SCRATCH_CREATE_ERROR; - if (!CACHEv(*scratchFpH,cacheSize)) { - V_delete (*scratchFpH, NULL); - *scratchFpH = NULL; - return BAD_CACHE_SIZE; - } - } - else { - if (V_clear(*scratchFpH) != 0) return SCRATCH_READ_ERROR; - if (!SEEKv(*scratchFpH,0L,vSEEK_SET)) return SCRATCH_READ_ERROR; - } - return CDF_OK; -} - -/****************************************************************************** -* ScratchDirectory. -******************************************************************************/ - -STATICforIDL char *ScratchDirectory (CDF) -struct CDFstruct *CDF; /* Pointer to CDF structure. This might be NULL if a - scratch directory is needed but a CDF has not yet - been opened/created. */ -{ - char *envTmp = NULL; - if (CDF != NULL) { - if (CDF->scratchDir != NULL) return CDF->scratchDir; - } -#if defined(vms) - envTmp = getenv ("CDF$TMP"); -#else -# if defined(unix) || defined(dos) || defined(posixSHELL) || defined(win32) - envTmp = getenv ("CDF_TMP"); -# endif -#endif -#if defined(win32) - if (envTmp == NULL) envTmp = getenv ("TMP"); -#endif - return envTmp; -} - -/****************************************************************************** -* FlushStage. -******************************************************************************/ - -STATICforIDL CDFstatus FlushStage (CDF, Var) -struct CDFstruct *CDF; -struct VarStruct *Var; -{ - CDFstatus pStatus = CDF_OK; - /**************************************************************************** - * Based on the variable type... - ****************************************************************************/ - switch (Var->vType) { - case SPARSE_RECORDS_: { - Int32 nRecords, nBytes, tOffset; struct AllocStruct alloc; - /************************************************************************ - * First check if there are records to be flushed in the staging area. - ************************************************************************/ - if (!Var->stage.modified) return pStatus; - /************************************************************************ - * Allocate a new VVR. - ************************************************************************/ - LoadAllocVVR (alloc, Var->stage.firstRec, Var->stage.lastRec, FALSE) - if (!sX(AllocateRecords(CDF,Var,alloc),&pStatus)) return pStatus; - Var->maxAllocated = MAXIMUM(Var->maxAllocated,Var->stage.lastRec); - /************************************************************************ - * Copy the records to the new VVR. - ************************************************************************/ - if (!sX(RecordByteOffset(CDF,Var, - Var->stage.firstRec, - &tOffset),&pStatus)) return pStatus; - nRecords = Var->stage.lastRec - Var->stage.firstRec + 1; - nBytes = nRecords * Var->NphyRecBytes; - if (!sX(CopyBytes(CDF->stage.fp,Var->stage.areaOffset, - SCRATCH_READ_ERROR,nBytes,CDF->fp, - tOffset,CDF_WRITE_ERROR),&pStatus)) return pStatus; - Var->maxWritten = MAXIMUM(Var->maxWritten,Var->stage.lastRec); - /************************************************************************ - * Clear the staging area control. - ************************************************************************/ - Var->stage.firstRec = NO_RECORD; - Var->stage.lastRec = NO_RECORD; - Var->stage.dotOffset = NO_OFFSET; - Var->stage.modified = FALSE; - break; - } - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: { - Int32 cSize, xSize, irSize, newOffset, nRecords, uSize; - struct CVVRstruct CVVR; struct VVRstruct VVR; struct AllocStruct alloc; - /************************************************************************ - * First check if there are records to be flushed in the staging area. - ************************************************************************/ - if (!Var->stage.modified) return pStatus; - /************************************************************************ - * Check if the scratch file is created/initialized. - ************************************************************************/ - if (!sX(InitScratch(ScratchDirectory(CDF), - &(CDF->compressFp), - CDF->compressCacheSize),&pStatus)) return pStatus; - /************************************************************************ - * Compress the records in the stage. - ************************************************************************/ - nRecords = Var->stage.lastRec - Var->stage.firstRec + 1; - uSize = nRecords * Var->NphyRecBytes; - if (!sX(Compress(CDF->stage.fp,Var->stage.areaOffset, - uSize,SCRATCH_READ_ERROR,Var->cType, - Var->cParms,CDF->compressFp,ZERO_OFFSET, - &cSize,SCRATCH_WRITE_ERROR),&pStatus)) return pStatus; - /************************************************************************ - * Does a VVR/CVVR for this block of records already exist? - ************************************************************************/ - if (Var->stage.dotOffset != NO_OFFSET) { - /********************************************************************** - * Read the size of the existing VVR/CVVR. - **********************************************************************/ - if (!sX(ReadIrSize(CDF->fp, - Var->stage.dotOffset, - &irSize),&pStatus)) return pStatus; - /********************************************************************** - * Will a CVVR fit? Note that reserve space is only added to new CVVRs. - **********************************************************************/ - if (CVVR_BASE_SIZE + cSize <= irSize) { - LoadCVVRx (CVVR, irSize, cSize) - if (!sX(WriteCVVR(CDF->fp,Var->stage.dotOffset, - CVVR_RECORDx,&CVVR, - CVVR_NULL),&pStatus)) return pStatus; - if (!sX(CopyBytes(CDF->compressFp,ZERO_OFFSET, - SCRATCH_READ_ERROR,cSize,CDF->fp, - Var->stage.dotOffset + CVVR_BASE_SIZE, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - Var->stage.modified = FALSE; - return pStatus; - } - /********************************************************************** - * Will a VVR fit? - **********************************************************************/ - if (VVR_BASE_SIZE + uSize <= irSize) { - LoadVVRx (VVR, irSize) - if (!sX(WriteVVR(CDF->fp,Var->stage.dotOffset, - VVR_RECORDx,&VVR, - VVR_NULL),&pStatus)) return pStatus; - if (!sX(CopyBytes(CDF->stage.fp,Var->stage.areaOffset, - SCRATCH_READ_ERROR,uSize,CDF->fp, - Var->stage.dotOffset + VVR_BASE_SIZE, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - Var->stage.modified = FALSE; - sX (DID_NOT_COMPRESS, &pStatus); - return pStatus; - } - /********************************************************************** - * The existing VVR/CVVR will have to be resized. Will a CVVR be - * smaller than a VVR? Note that reserve space is not added to the - * size of the CVVR because a new one isn't being created. - **********************************************************************/ - if (CVVR_BASE_SIZE + cSize < VVR_BASE_SIZE + uSize) { - if (!sX(ResizeIR(CDF,Var->stage.dotOffset, - CVVR_BASE_SIZE + cSize, - &newOffset,TRUE,NULL),&pStatus)) return pStatus; - LoadCVVRx (CVVR, CVVR_BASE_SIZE + cSize, cSize) - if (!sX(WriteCVVR(CDF->fp,newOffset, - CVVR_RECORDx,&CVVR, - CVVR_NULL),&pStatus)) return pStatus; - if (!sX(CopyBytes(CDF->compressFp,ZERO_OFFSET, - SCRATCH_READ_ERROR,cSize, - CDF->fp,newOffset + CVVR_BASE_SIZE, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - } - else { - if (!sX(ResizeIR(CDF,Var->stage.dotOffset, - VVR_BASE_SIZE + uSize, - &newOffset,TRUE,NULL),&pStatus)) return pStatus; - LoadVVRx (VVR, VVR_BASE_SIZE + uSize) - if (!sX(WriteVVR(CDF->fp,newOffset, - VVR_RECORDx,&VVR, - VVR_NULL),&pStatus)) return pStatus; - if (!sX(CopyBytes(CDF->stage.fp,Var->stage.areaOffset, - SCRATCH_READ_ERROR,uSize, - CDF->fp,newOffset + VVR_BASE_SIZE, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - sX (DID_NOT_COMPRESS, &pStatus); - } - if (!sX(ModIndexOffset(CDF,Var, - Var->stage.firstRec, - Var->stage.lastRec, - newOffset),&pStatus)) return pStatus; - Var->stage.dotOffset = newOffset; - Var->stage.modified = FALSE; - return pStatus; - } - /************************************************************************ - * A new VVR/CVVR will have to be created. First calculate the reserve - * size. - ************************************************************************/ - if (Var->reservePct <= 0) - xSize = 0; - else { - if (Var->reservePct <= 100) { - Int32 tSize = (Int32) ((uSize * (Var->reservePct/100.0)) + 0.5); - xSize = MAXIMUM(cSize,tSize) - cSize; - } - else { - Int32 tSize = (Int32) ((cSize * (Var->reservePct/100.0)) + 0.5); - xSize = tSize - cSize; - } - } - /************************************************************************ - * Will a CVVR be smaller than a VVR? - ************************************************************************/ - if (CVVR_BASE_SIZE + cSize + xSize < VVR_BASE_SIZE + uSize) { - LoadAllocCVVR (alloc, Var->stage.firstRec, Var->stage.lastRec, - cSize, xSize) - if (!sX(AllocateRecords(CDF,Var,alloc),&pStatus)) return pStatus; - if (!sX(SearchForRecord(CDF,Var->VDRoffset,Var->zVar, - Var->stage.firstRec,NULL,NULL, - &newOffset,NULL),&pStatus)) return pStatus; - LoadCVVRx (CVVR, CVVR_BASE_SIZE + cSize + xSize, cSize) - if (!sX(WriteCVVR(CDF->fp,newOffset, - CVVR_RECORDx,&CVVR, - CVVR_NULL),&pStatus)) return pStatus; - if (!sX(CopyBytes(CDF->compressFp,ZERO_OFFSET, - SCRATCH_READ_ERROR,cSize, - CDF->fp,newOffset + CVVR_BASE_SIZE, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - Var->stage.dotOffset = newOffset; - Var->stage.modified = FALSE; - return pStatus; - } - /************************************************************************ - * The CVVR will be too big - create a VVR. - ************************************************************************/ - LoadAllocVVR (alloc, Var->stage.firstRec, Var->stage.lastRec, TRUE) - if (!sX(AllocateRecords(CDF,Var,alloc),&pStatus)) return pStatus; - if (!sX(SearchForRecord(CDF,Var->VDRoffset,Var->zVar, - Var->stage.firstRec,NULL,NULL, - &newOffset,NULL),&pStatus)) return pStatus; - LoadVVRx (VVR, VVR_BASE_SIZE + uSize) - if (!sX(WriteVVR(CDF->fp,newOffset, - VVR_RECORDx,&VVR, - VVR_NULL),&pStatus)) return pStatus; - if (!sX(CopyBytes(CDF->stage.fp,Var->stage.areaOffset, - SCRATCH_READ_ERROR,uSize, - CDF->fp,newOffset + VVR_BASE_SIZE, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - Var->stage.dotOffset = newOffset; - Var->stage.modified = FALSE; - sX (DID_NOT_COMPRESS, &pStatus); - return pStatus; - } - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* BringToStage. -******************************************************************************/ - -static CDFstatus BringToStage (CDF, Var, recNum, found) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 recNum; -Logical *found; -{ - CDFstatus pStatus = CDF_OK; - /**************************************************************************** - * First check if record is already in the stage. - ****************************************************************************/ - if (INCLUSIVE(Var->stage.firstRec,recNum,Var->stage.lastRec)) { - ASSIGNnotNULL (found, TRUE) - return pStatus; - } - /**************************************************************************** - * Then, based on variable type... - ****************************************************************************/ - switch (Var->vType) { - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: { - Int32 firstRec, lastRec, offset, nRecords, uSize; Logical foundX; - /************************************************************************ - * Determine if the record exists. - ************************************************************************/ - if (!sX(SearchForRecord(CDF,Var->VDRoffset,Var->zVar, - recNum,&firstRec,&lastRec, - &offset,&foundX),&pStatus)) return pStatus; - ASSIGNnotNULL (found, foundX) - if (!foundX) return BOO(found == NULL,NO_SUCH_RECORD,pStatus); - /************************************************************************ - * Flush the stage before... - ************************************************************************/ - if (!sX(FlushStage(CDF,Var),&pStatus)) return pStatus; - /************************************************************************ - * ...decompressing the CVVR (or VVR if the records did not compress) to - * the staging area. - ************************************************************************/ - nRecords = lastRec - firstRec + 1; - uSize = nRecords * Var->NphyRecBytes; - if (!sX(DecompressToStage(CDF,Var, - offset,uSize),&pStatus)) return pStatus; - /************************************************************************ - * Update staging control. - ************************************************************************/ - Var->stage.firstRec = firstRec; - Var->stage.lastRec = lastRec; - Var->stage.dotOffset = offset; - Var->stage.modified = FALSE; - break; - } - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* CopyBytes. -******************************************************************************/ - -STATICforIDL CDFstatus CopyBytes (iFp, iStart, iError, nBytes, oFp, oStart, - oError) -vFILE *iFp; -Int32 iStart; -CDFstatus iError; -Int32 nBytes; -vFILE *oFp; -Int32 oStart; -CDFstatus oError; -{ - Int32 nBlocks = nBytes / COPYblockSIZE; /* Number of full blocks that - can be copied. */ - Int32 lastCount = nBytes % COPYblockSIZE; /* Number of bytes remaining - to be copied after the full - blocks have been copied. */ - Int32 i; Byte1 buffer[COPYblockSIZE]; - /**************************************************************************** - * If the copy is within the same file... - ****************************************************************************/ - if (iFp == oFp) { - /************************************************************************** - * If the input group (of bytes) is before the output group start at the - * end in case they overlap. - **************************************************************************/ - if (iStart < oStart) { - if (nBlocks > 0) { - Int32 iOffset = iStart + nBytes - COPYblockSIZE; - Int32 oOffset = oStart + nBytes - COPYblockSIZE; - for (i = 0; i < nBlocks; i++) { - if (!SEEKv(iFp,(long)iOffset,vSEEK_SET)) return iError; - if (!READv(buffer,(size_t)COPYblockSIZE,(size_t)1,iFp)) return - iError; - if (!SEEKv(oFp,(long)oOffset,vSEEK_SET)) return oError; - if (!WRITEv(buffer,(size_t)COPYblockSIZE,(size_t)1,oFp)) return - oError; - iOffset -= COPYblockSIZE; - oOffset -= COPYblockSIZE; - } - } - if (lastCount > 0) { - if (!SEEKv(iFp,(long)iStart,vSEEK_SET)) return iError; - if (!READv(buffer,(size_t)lastCount,(size_t)1,iFp)) return iError; - if (!SEEKv(oFp,(long)oStart,vSEEK_SET)) return oError; - if (!WRITEv(buffer,(size_t)lastCount,(size_t)1,oFp)) return oError; - } - } - /************************************************************************** - * If the input group (of bytes) is after the output group start at the - * beginning in case they overlap. - **************************************************************************/ - if (iStart > oStart) { - Int32 iOffset = iStart; - Int32 oOffset = oStart; - if (nBlocks > 0) { - for (i = 0; i < nBlocks; i++) { - if (!SEEKv(iFp,(long)iOffset,vSEEK_SET)) return iError; - if (!READv(buffer,(size_t)COPYblockSIZE,(size_t)1,iFp)) return - iError; - if (!SEEKv(oFp,(long)oOffset,vSEEK_SET)) return oError; - if (!WRITEv(buffer,(size_t)COPYblockSIZE,(size_t)1,oFp)) return - oError; - iOffset += COPYblockSIZE; - oOffset += COPYblockSIZE; - } - } - if (lastCount > 0) { - if (!SEEKv(iFp,(long)iOffset,vSEEK_SET)) return iError; - if (!READv(buffer,(size_t)lastCount,(size_t)1,iFp)) return iError; - if (!SEEKv(oFp,(long)oOffset,vSEEK_SET)) return oError; - if (!WRITEv(buffer,(size_t)lastCount,(size_t)1,oFp)) return oError; - } - } - /************************************************************************** - * Offsets are the same - do nothing. - **************************************************************************/ - } - else { - /************************************************************************** - * Different files... - **************************************************************************/ - if (!SEEKv(iFp,(long)iStart,vSEEK_SET)) return iError; - if (!SEEKv(oFp,(long)oStart,vSEEK_SET)) return oError; - for (i = 0; i < nBlocks; i++) { - if (!READv(buffer,(size_t)COPYblockSIZE,(size_t)1,iFp)) return iError; - if (!WRITEv(buffer,(size_t)COPYblockSIZE,(size_t)1,oFp)) return oError; - } - if (lastCount > 0) { - if (!READv(buffer,(size_t)lastCount,(size_t)1,iFp)) return iError; - if (!WRITEv(buffer,(size_t)lastCount,(size_t)1,oFp)) return oError; - } - } - return CDF_OK; -} - -/****************************************************************************** -* ModIndexOffset. -******************************************************************************/ - -STATICforIDL CDFstatus ModIndexOffset (CDF, Var, firstRec, lastRec, newOffset) -struct CDFstruct *CDF; /* Pointer to CDF. */ -struct VarStruct *Var; /* Pointer to variable. */ -Int32 firstRec; /* First record of entry. */ -Int32 lastRec; /* Last record of entry. */ -Int32 newOffset; /* New VVR/CVVR/SVVR offset. */ -{ - CDFstatus pStatus = CDF_OK; Int32 vxrOffset; - /**************************************************************************** - * Read offset of first VXR... - ****************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_VXRHEAD,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * ...and start there. - ****************************************************************************/ - if (!sX(ModIndexOffset_r(CDF->fp,vxrOffset, - firstRec,lastRec, - newOffset),&pStatus)) return pStatus; - return pStatus; -} - -static CDFstatus ModIndexOffset_r (fp, vxrOffset, firstRec, lastRec, newOffset) -vFILE *fp; /* File pointer to dotCDF file. */ -Int32 vxrOffset; /* VXR at which to start. */ -Int32 firstRec; /* First record of entry. */ -Int32 lastRec; /* Last record of entry. */ -Int32 newOffset; /* New VVR/CVVR/SVVR offset. */ -{ - CDFstatus pStatus = CDF_OK; - struct VXRstruct VXR; int entryN; Int32 irType; - /**************************************************************************** - * While more VXRs... - ****************************************************************************/ - while (vxrOffset != ZERO_OFFSET) { - /************************************************************************** - * Read the VXR. - **************************************************************************/ - if (!sX(ReadVXR(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************** - * Search through index entries... - **************************************************************************/ - for (entryN = 0; entryN < VXR.NusedEntries; entryN++) { - if (VXR.First[entryN] <= firstRec && lastRec <= VXR.Last[entryN]) { - if (!sX(ReadIrType(fp, - VXR.Offset[entryN], - &irType),&pStatus)) return pStatus; - if (irType == VXR_) return ModIndexOffset_r(fp,VXR.Offset[entryN], - firstRec,lastRec, - newOffset); - if (VXR.First[entryN] == firstRec && lastRec == VXR.Last[entryN]) { - VXR.Offset[entryN] = newOffset; - if (!sX(WriteVXR(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - return pStatus; - } - return CDF_INTERNAL_ERROR; /* or CORRUPTED_V2_CDF? */ - } - } - /************************************************************************** - * Go to next VXR. - **************************************************************************/ - vxrOffset = VXR.VXRnext; - } - /**************************************************************************** - * No more VXRs. - ****************************************************************************/ - return CDF_INTERNAL_ERROR; -} - -/****************************************************************************** -* WriteCompressedRecords. -******************************************************************************/ - -static CDFstatus WriteCompressedRecords (CDF, Var, firstRec, lastRec, buffer, - nValues, offset, fullRecord) -struct CDFstruct *CDF; /* Pointer to CDF. */ -struct VarStruct *Var; /* Pointer to variable. */ -Int32 firstRec; /* First record being written. */ -Int32 lastRec; /* Last record being written. */ -void *buffer; /* Buffer of values. */ -Int32 nValues; /* Number of values being written. */ -Int32 offset; /* If not full record(s), byte offset in record at - which to write. */ -Logical fullRecord; /* Full record(s) being written? */ -{ - CDFstatus pStatus = CDF_OK; Logical found; - Int32 recCount, tOffset, recordOffsetInStage, maxRecThisBlock; - Int32 nextRec, writeTo, numElems; void *padBuffer; int how; - Int32 recNum = firstRec; Byte1 *tBuffer = (Byte1 *) buffer; - /**************************************************************************** - * From first to last record... - ****************************************************************************/ - while (recNum <= lastRec) { - /************************************************************************* - * Check if this record is in the staging area. - *************************************************************************/ - if (INCLUSIVE(Var->stage.firstRec,recNum,Var->stage.lastRec)) { - recordOffsetInStage = recNum - Var->stage.firstRec; - tOffset = Var->stage.areaOffset; - tOffset += (recordOffsetInStage * Var->NphyRecBytes); - if (fullRecord) { - if (Var->stage.dotOffset == NO_OFFSET) { - maxRecThisBlock = Var->stage.firstRec + Var->blockingFactor - 1; - if (!sX(NextRecord(CDF,Var->VDRoffset, - Var->zVar,recNum, - &nextRec,&found),&pStatus)) return pStatus; - if (!found) - writeTo = MINIMUM(maxRecThisBlock,lastRec); - else { - Int32 prevRecN = nextRec - 1; - writeTo = MINIMUMof3(maxRecThisBlock,prevRecN,lastRec); - } - } - else - writeTo = MINIMUM(Var->stage.lastRec,lastRec); - recCount = writeTo - recNum + 1; - numElems = recCount * Var->NphyRecElems; - } - else { - writeTo = recNum; - recCount = 1; - numElems = nValues * Var->NvalueElems; - tOffset += offset; - } - if (!sX(WriteVarElems(Var,CDF->stage.fp, - tOffset,numElems, - tBuffer),&pStatus)) return pStatus; - Var->stage.lastRec = MAXIMUM(Var->stage.lastRec,writeTo); - Var->stage.modified = TRUE; - tBuffer += (size_t) (numElems * Var->NelemBytes); - recNum += recCount; - continue; - } - /************************************************************************* - * Not in the staging area...check if this record is in an existing CVVR. - *************************************************************************/ - if (!sX(BringToStage(CDF,Var,recNum,&found),&pStatus)) return pStatus; - if (found) { - recordOffsetInStage = recNum - Var->stage.firstRec; - tOffset = Var->stage.areaOffset; - tOffset += (recordOffsetInStage * Var->NphyRecBytes); - if (fullRecord) { - writeTo = MINIMUM(Var->stage.lastRec,lastRec); - recCount = writeTo - recNum + 1; - numElems = recCount * Var->NphyRecElems; - } - else { - writeTo = recNum; - recCount = 1; - numElems = nValues * Var->NvalueElems; - tOffset += offset; - } - if (!sX(WriteVarElems(Var,CDF->stage.fp, - tOffset,numElems, - tBuffer),&pStatus)) return pStatus; - Var->stage.modified = TRUE; - tBuffer += (size_t) (numElems * Var->NelemBytes); - recNum += recCount; - continue; - } - /************************************************************************* - * Not in an existing CVVR...this record does not exist. First check - * if the record(s) can be added to the records in the stage. - *************************************************************************/ - if (Var->stage.firstRec != NO_RECORD) { - if (Var->stage.dotOffset == NO_OFFSET) { - if (recNum == Var->stage.lastRec + 1) { - maxRecThisBlock = Var->stage.firstRec + Var->blockingFactor - 1; - if (recNum <= maxRecThisBlock) { - recordOffsetInStage = recNum - Var->stage.firstRec; - tOffset = Var->stage.areaOffset; - tOffset += (recordOffsetInStage * Var->NphyRecBytes); - if (fullRecord) { - if (!sX(NextRecord(CDF,Var->VDRoffset, - Var->zVar,recNum, - &nextRec,&found),&pStatus)) return pStatus; - if (!found) - writeTo = MINIMUM(maxRecThisBlock,lastRec); - else { - Int32 prevRecN = nextRec - 1; - writeTo = MINIMUMof3(maxRecThisBlock,prevRecN,lastRec); - } - recCount = writeTo - recNum + 1; - numElems = recCount * Var->NphyRecElems; - } - else { - if (!sX(BuildPadBuffer(CDF,Var,INT32_ONE, - &how,&padBuffer, - TRUE),&pStatus)) return pStatus; - if (!sX(WritePadValues(Var,CDF->stage.fp, - tOffset,INT32_ONE,how, - padBuffer),&pStatus)) { - cdf_FreeMemory (padBuffer, NULL); - return pStatus; - } - cdf_FreeMemory (padBuffer, NULL); - writeTo = recNum; - recCount = 1; - numElems = nValues * Var->NvalueElems; - tOffset += offset; - } - if (!sX(WriteVarElems(Var,CDF->stage.fp, - tOffset,numElems, - tBuffer),&pStatus)) return pStatus; - Var->stage.lastRec = MAXIMUM(Var->stage.lastRec,writeTo); - Var->stage.modified = TRUE; - tBuffer += (size_t) (numElems * Var->NelemBytes); - recNum += recCount; - continue; - } - } - } - } - /************************************************************************* - * This record cannot be added to the block of records currently in - * the staging area. Start a new block of records. - *************************************************************************/ - if (!sX(FlushStage(CDF,Var),&pStatus)) return pStatus; - tOffset = Var->stage.areaOffset; - if (fullRecord) { - maxRecThisBlock = recNum + Var->blockingFactor - 1; - if (!sX(NextRecord(CDF,Var->VDRoffset,Var->zVar, - recNum,&nextRec,&found),&pStatus)) return pStatus; - if (!found) - writeTo = MINIMUM(maxRecThisBlock,lastRec); - else { - Int32 prevRecN = nextRec - 1; - writeTo = MINIMUMof3(maxRecThisBlock,prevRecN,lastRec); - } - recCount = writeTo - recNum + 1; - numElems = recCount * Var->NphyRecElems; - } - else { - if (!sX(BuildPadBuffer(CDF,Var,INT32_ONE, - &how,&padBuffer, - TRUE),&pStatus)) return pStatus; - if (!sX(WritePadValues(Var,CDF->stage.fp, - tOffset,INT32_ONE,how, - padBuffer),&pStatus)) { - cdf_FreeMemory (padBuffer, NULL); - return pStatus; - } - cdf_FreeMemory (padBuffer, NULL); - writeTo = recNum; - recCount = 1; - numElems = nValues * Var->NvalueElems; - tOffset += offset; - } - if (!sX(WriteVarElems(Var,CDF->stage.fp, - tOffset,numElems, - tBuffer),&pStatus)) return pStatus; - Var->stage.firstRec = recNum; - Var->stage.lastRec = writeTo; - Var->stage.dotOffset = NO_OFFSET; - Var->stage.modified = TRUE; - tBuffer += (size_t) (numElems * Var->NelemBytes); - recNum += recCount; - } - return pStatus; -} - -/****************************************************************************** -* CalcCompressionPct. -******************************************************************************/ - -STATICforIDL CDFstatus CalcCompressionPct (CDF, vdrOffset, zVar, cPct) -struct CDFstruct *CDF; -Int32 vdrOffset; -Logical zVar; -long *cPct; -{ - CDFstatus pStatus = CDF_OK; Int32 vxrOffset; - Int32 uTotal = 0, cTotal = 0; Int32 nPhyRecBytes; - /**************************************************************************** - * Calculate the number of bytes per physical record. - ****************************************************************************/ - if (!sX(CalcPhyRecBytes(CDF,vdrOffset, - zVar,&nPhyRecBytes),&pStatus)) return pStatus; - /**************************************************************************** - * Read the offset of the first VXR (return 0% if no VXRs)... - ****************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,vdrOffset,zVar, - VDR_VXRHEAD,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - if (vxrOffset == ZERO_OFFSET) { - *cPct = 0; - return pStatus; - } - /**************************************************************************** - * ...and start there. - ****************************************************************************/ - if (!sX(CalcCompressionPct_r(CDF->fp,vxrOffset, - nPhyRecBytes, - &uTotal,&cTotal),&pStatus)) return pStatus; - /**************************************************************************** - * Calculate percentage. - ****************************************************************************/ - *cPct = (long) (((100.0*cTotal) / uTotal) + 0.5); - return pStatus; -} - -static CDFstatus CalcCompressionPct_r (fp, vxrOffset, nPhyRecBytes, uTotal, - cTotal) -vFILE *fp; -Int32 vxrOffset; -Int32 nPhyRecBytes; -Int32 *uTotal; -Int32 *cTotal; -{ - CDFstatus pStatus = CDF_OK; struct VXRstruct VXR; int entryN; - Int32 nRecords, uSize, irType, irSize; - /**************************************************************************** - * While more VXRs... - ****************************************************************************/ - while (vxrOffset != ZERO_OFFSET) { - /************************************************************************** - * Read the VXR. - **************************************************************************/ - if (!sX(ReadVXR(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************** - * Scan entries... - **************************************************************************/ - for (entryN = 0; entryN < VXR.NusedEntries; entryN++) { - if (!sX(ReadIrType(fp,VXR.Offset[entryN],&irType),&pStatus)) return - pStatus; - switch (irType) { - case VXR_: - if (!sX(CalcCompressionPct_r(fp,VXR.Offset[entryN], - nPhyRecBytes,uTotal, - cTotal),&pStatus)) return pStatus; - break; - case VVR_: - case CVVR_: - /******************************************************************* - * Accumulate uncompressed size. - *******************************************************************/ - nRecords = VXR.Last[entryN] - VXR.First[entryN] + 1; - uSize = nRecords * nPhyRecBytes; - *uTotal += uSize; - /******************************************************************* - * Accumulate compressed size. - *******************************************************************/ - if (!sX(ReadIrSize(fp,VXR.Offset[entryN],&irSize),&pStatus)) return - pStatus; - *cTotal += irSize - BOO(irType == CVVR_, - CVVR_BASE_SIZE, - VVR_BASE_SIZE); - break; - default: - return CORRUPTED_V2_CDF; - } - } - vxrOffset = VXR.VXRnext; - } - return pStatus; -} - -/****************************************************************************** -* CalcPhyRecBytes. -******************************************************************************/ - -STATICforIDL CDFstatus CalcPhyRecBytes (CDF, vdrOffset, zVar, nPhyRecBytes) -struct CDFstruct *CDF; -Int32 vdrOffset; -Logical zVar; -Int32 *nPhyRecBytes; -{ - CDFstatus pStatus = CDF_OK; int dimN; Int32 dataType, numElems; - Int32 numDims, dimSizes[CDF_MAX_DIMS], dimVarys[CDF_MAX_DIMS]; - if (!sX(CalcDimParms(CDF,vdrOffset,zVar, - &numDims,dimSizes,dimVarys),&pStatus)) return pStatus; - if (!sX(ReadVDR(CDF,CDF->fp,vdrOffset,zVar, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_NULL),&pStatus)) return pStatus; - *nPhyRecBytes = (Int32) CDFelemSize((long)dataType) * numElems; - for (dimN = 0; dimN < numDims; dimN++) { - if (dimVarys[dimN]) *nPhyRecBytes *= dimSizes[dimN]; - } - return pStatus; -} - -/****************************************************************************** -* ReadSparseFull. -******************************************************************************/ - -static CDFstatus ReadSparseFull (CDF, Var, firstRec, lastRec, buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 firstRec; -Int32 lastRec; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; Logical found; - Int32 readTo, recCount, numElems, recX, prevRecN; - Int32 nextRec, padTo, tOffset, nPadValues; - Int32 recNum = firstRec; - Byte1 *tBuffer = (Byte1 *) buffer; - /**************************************************************************** - * While there are more records to be read/generated... - ****************************************************************************/ - while (recNum <= lastRec) { - /************************************************************************** - * Is the record in the staging area? - **************************************************************************/ - if (INCLUSIVE(Var->stage.firstRec,recNum,Var->stage.lastRec)) { - readTo = MINIMUM(Var->stage.lastRec,lastRec); - recCount = readTo - recNum + 1; - numElems = recCount * Var->NphyRecElems; - recX = recNum - Var->stage.firstRec; - tOffset = Var->stage.areaOffset + (recX * Var->NphyRecBytes); - if (!sX(ReadVarElems(Var,CDF->stage.fp, - tOffset,numElems,tBuffer),&pStatus)) return pStatus; - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - continue; - } - /************************************************************************** - * Does the record exist and has been written to (not just allocated)? - **************************************************************************/ - if (recNum <= Var->maxRec) { - Int32 firstRecInVVR, lastRecInVVR; - if (!sX(SearchForRecord(CDF,Var->VDRoffset, - Var->zVar,recNum, - &firstRecInVVR, - &lastRecInVVR, - &tOffset,&found),&pStatus)) return pStatus; - if (found) { - readTo = MINIMUMof3(Var->maxRec,lastRec,lastRecInVVR); - recCount = readTo - recNum + 1; - numElems = recCount * Var->NphyRecElems; - recX = recNum - firstRecInVVR; - tOffset += VVR_BASE_SIZE + (recX * Var->NphyRecBytes); - if (!sX(ReadVarElems(Var,CDF->fp,tOffset, - numElems,tBuffer),&pStatus)) return pStatus; - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - continue; - } - } - /************************************************************************** - * Determine which records need to be padded. - **************************************************************************/ - if (recNum <= Var->maxRec) { - if (!sX(NextRecord(CDF,Var->VDRoffset,Var->zVar, - recNum,&nextRec,&found),&pStatus)) return pStatus; - if (found) { - if (EXCLUSIVE(recNum, - Var->stage.firstRec, - nextRec)) nextRec = Var->stage.firstRec; - prevRecN = nextRec - 1; - padTo = MINIMUM(prevRecN,lastRec); - } - else { - prevRecN = Var->stage.firstRec - 1; - padTo = MINIMUM(prevRecN,lastRec); - } - } - else - padTo = lastRec; - recCount = padTo - recNum + 1; - /************************************************************************** - * If sRecords.PREV... - **************************************************************************/ - if (Var->prevIfMissing) { - Int32 prevRec; Byte1 *destBuffer; - if (!sX(PrevRecord(CDF,Var->VDRoffset,Var->zVar, - MINIMUM(recNum,Var->maxRec), - &prevRec,&found),&pStatus)) return pStatus; - if (found) { - if (EXCLUSIVE(prevRec,Var->stage.lastRec,recNum)) { - recX = Var->stage.lastRec - Var->stage.firstRec; - tOffset = Var->stage.areaOffset + (recX * Var->NphyRecBytes); - if (!sX(ReadVarElems(Var,CDF->stage.fp, - tOffset,Var->NphyRecElems, - tBuffer),&pStatus)) return pStatus; - } - else { - if (!sX(RecordByteOffset(CDF,Var, - prevRec, - &tOffset),&pStatus)) return pStatus; - if (!sX(ReadVarElems(Var,CDF->fp,tOffset, - Var->NphyRecElems, - tBuffer),&pStatus)) return pStatus; - } - destBuffer = tBuffer + ((size_t) Var->NphyRecBytes); - for (recX = 1; recX < recCount; recX++) { - memmove (destBuffer, tBuffer, (size_t) Var->NphyRecBytes); - destBuffer += (size_t) Var->NphyRecBytes; - } - sX (VIRTUAL_RECORD_DATA, &pStatus); - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - continue; - } - if (EXCLUSIVE(NO_RECORD,Var->stage.lastRec,recNum)) { - recX = Var->stage.lastRec - Var->stage.firstRec; - tOffset = Var->stage.areaOffset + (recX * Var->NphyRecBytes); - if (!sX(ReadVarElems(Var,CDF->stage.fp, - tOffset,Var->NphyRecElems, - tBuffer),&pStatus)) return pStatus; - destBuffer = tBuffer + ((size_t) Var->NphyRecBytes); - for (recX = 1; recX < recCount; recX++) { - memmove (destBuffer, tBuffer, (size_t) Var->NphyRecBytes); - destBuffer += (size_t) Var->NphyRecBytes; - } - sX (VIRTUAL_RECORD_DATA, &pStatus); - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - continue; - } - } - /************************************************************************** - * Pad with the variable's pad value. This occurs if the variable is - * sRecords.NO, sRecords.PAD, or if sRecords.PREV but a previous record - * does not exist (in a VVR or the staging area). - **************************************************************************/ - nPadValues = recCount * Var->NphyRecValues; - if (!sX(PadBuffer(CDF,Var,nPadValues,tBuffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - } - return pStatus; -} - -/****************************************************************************** -* ReadSparsePartial. -******************************************************************************/ - -static CDFstatus ReadSparsePartial (CDF, Var, recNum, offset, nValues, buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 recNum; -Int32 offset; -Int32 nValues; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; Logical found; - Int32 tOffset, firstRec, prevRec; - Int32 numElems = nValues * Var->NvalueElems; - /**************************************************************************** - * If the record is in the staging area... - ****************************************************************************/ - if (INCLUSIVE(Var->stage.firstRec,recNum,Var->stage.lastRec)) { - tOffset = Var->stage.areaOffset; - tOffset += Var->NphyRecBytes * (recNum - Var->stage.firstRec); - tOffset += offset; - if (!sX(ReadVarElems(Var,CDF->stage.fp, - tOffset,numElems,buffer),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * If the record exists and has been written (ie. not just allocated)... - ****************************************************************************/ - if (recNum <= Var->maxRec) { - if (!sX(SearchForRecord(CDF,Var->VDRoffset, - Var->zVar,recNum,&firstRec, - NULL,&tOffset,&found),&pStatus)) return pStatus; - if (found) { - tOffset += VVR_BASE_SIZE; - tOffset += Var->NphyRecBytes * (recNum - firstRec); - tOffset += offset; - if (!sX(ReadVarElems(Var,CDF->fp, - tOffset,numElems,buffer),&pStatus)) return pStatus; - return pStatus; - } - } - /**************************************************************************** - * If missing records are to be read from the previous record... - ****************************************************************************/ - if (Var->prevIfMissing) { - /************************************************************************** - * Check if a previous record exists in a VVR. - **************************************************************************/ - if (!sX(PrevRecord(CDF,Var->VDRoffset,Var->zVar, - MINIMUM(recNum,Var->maxRec), - &prevRec,&found),&pStatus)) return pStatus; - /************************************************************************** - * If so, also make sure that the last record in the staging area isn't - * really the previous record to use. - **************************************************************************/ - if (found) { - if (EXCLUSIVE(prevRec,Var->stage.lastRec,recNum)) { - Int32 recNumInStage = Var->stage.lastRec - Var->stage.firstRec; - tOffset = Var->stage.areaOffset; - tOffset += Var->NphyRecBytes * recNumInStage; - tOffset += offset; - if (!sX(ReadVarElems(Var,CDF->stage.fp,tOffset, - numElems,buffer),&pStatus)) return pStatus; - } - else { - if (!sX(RecordByteOffset(CDF,Var, - prevRec, - &tOffset),&pStatus)) return pStatus; - tOffset += offset; - if (!sX(ReadVarElems(Var,CDF->fp,tOffset, - numElems,buffer),&pStatus)) return pStatus; - } - sX (VIRTUAL_RECORD_DATA, &pStatus); - return pStatus; - } - /************************************************************************** - * A previous record does not exist in a VVR...check if the last record in - * the staging area is the previous record. - **************************************************************************/ - if (EXCLUSIVE(NO_RECORD,Var->stage.lastRec,recNum)) { - Int32 recNumInStage = Var->stage.lastRec - Var->stage.firstRec; - tOffset = Var->stage.areaOffset; - tOffset += Var->NphyRecBytes * recNumInStage; - tOffset += offset; - if (!sX(ReadVarElems(Var,CDF->stage.fp, - tOffset,numElems,buffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - return pStatus; - } - } - /**************************************************************************** - * Pad the buffer with the variable's pad value. Note that this is also done - * if the variable is sRecords.PREV but a previous record does not exist. - ****************************************************************************/ - if (!sX(PadBuffer(CDF,Var,nValues,buffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - return pStatus; -} - -/****************************************************************************** -* ReadCompressedFull. -******************************************************************************/ - -static CDFstatus ReadCompressedFull (CDF, Var, firstRec, lastRec, buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 firstRec; -Int32 lastRec; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; Logical found; - Int32 readTo, recCount, numElems, recX, tOffset, nextRec; - Int32 recNum = firstRec, nPadValues, prevRec, padTo; - Byte1 *tBuffer = (Byte1 *) buffer, *destBuffer; - /**************************************************************************** - * While there are more records to be read/generated... - ****************************************************************************/ - while (recNum <= lastRec) { - /************************************************************************** - * Try to bring the record to the staging area. - **************************************************************************/ - if (!sX(BringToStage(CDF,Var,recNum,&found),&pStatus)) return pStatus; - if (found) { - readTo = MINIMUM(Var->stage.lastRec,lastRec); - recCount = readTo - recNum + 1; - numElems = recCount * Var->NphyRecElems; - recX = recNum - Var->stage.firstRec; - tOffset = Var->stage.areaOffset + (recX * Var->NphyRecBytes); - if (!sX(ReadVarElems(Var,CDF->stage.fp, - tOffset,numElems,tBuffer),&pStatus)) return pStatus; - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - continue; - } - /************************************************************************** - * Determine which records need to be padded. - **************************************************************************/ - if (!sX(NextRecord(CDF,Var->VDRoffset,Var->zVar, - recNum,&nextRec,&found),&pStatus)) return pStatus; - if (found) { - if (EXCLUSIVE(recNum, - Var->stage.firstRec, - nextRec)) nextRec = Var->stage.firstRec; - prevRec = nextRec - 1; - padTo = MINIMUM(prevRec,lastRec); - } - else - padTo = BOO(Var->stage.firstRec > recNum, - Var->stage.firstRec - 1,lastRec); - recCount = padTo - recNum + 1; - /************************************************************************** - * If sRecords.PREV... - **************************************************************************/ - if (Var->prevIfMissing) { - if (!sX(PrevRecord(CDF,Var->VDRoffset,Var->zVar, - recNum,&prevRec,&found),&pStatus)) return pStatus; - if (!found) prevRec = NO_RECORD; - if (EXCLUSIVE(prevRec, - Var->stage.lastRec, - recNum)) prevRec = Var->stage.lastRec; - if (prevRec > NO_RECORD) { - if (!sX(BringToStage(CDF,Var,prevRec,NULL),&pStatus)) return pStatus; - recX = prevRec - Var->stage.firstRec; - tOffset = Var->stage.areaOffset + (recX * Var->NphyRecBytes); - if (!sX(ReadVarElems(Var,CDF->stage.fp, - tOffset,Var->NphyRecElems, - tBuffer),&pStatus)) return pStatus; - destBuffer = tBuffer + ((size_t) Var->NphyRecBytes); - for (recX = 1; recX < recCount; recX++) { - memmove (destBuffer, tBuffer, (size_t) Var->NphyRecBytes); - destBuffer += (size_t) Var->NphyRecBytes; - } - sX (VIRTUAL_RECORD_DATA, &pStatus); - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - continue; - } - } - /************************************************************************** - * Pad with the variable's pad value. This occurs if the variable is - * sRecords.NO, sRecords.PAD, or if sRecords.PREV but a previous record - * does not exist (in a CVVR/VVR or the staging area). - **************************************************************************/ - nPadValues = recCount * Var->NphyRecValues; - if (!sX(PadBuffer(CDF,Var,nPadValues,tBuffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - } - return pStatus; -} - -/****************************************************************************** -* ReadCompressedPartial. -******************************************************************************/ - -static CDFstatus ReadCompressedPartial (CDF, Var, recNum, offset, nValues, - buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 recNum; -Int32 offset; -Int32 nValues; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; - Int32 numElems = nValues * Var->NvalueElems; - Int32 tOffset, prevRec, recX; Logical found; - /**************************************************************************** - * Try to bring the record to the staging area. - ****************************************************************************/ - if (!sX(BringToStage(CDF,Var,recNum,&found),&pStatus)) return pStatus; - if (found) { - tOffset = Var->stage.areaOffset; - tOffset += Var->NphyRecBytes * (recNum - Var->stage.firstRec); - tOffset += offset; - if (!sX(ReadVarElems(Var,CDF->stage.fp, - tOffset,numElems,buffer),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * If sRecords.PREV... - ****************************************************************************/ - if (Var->prevIfMissing) { - if (!sX(PrevRecord(CDF,Var->VDRoffset, - Var->zVar,recNum, - &prevRec,&found),&pStatus)) return pStatus; - if (!found) prevRec = NO_RECORD; - if (EXCLUSIVE(prevRec, - Var->stage.lastRec, - recNum)) prevRec = Var->stage.lastRec; - if (prevRec > NO_RECORD) { - if (!sX(BringToStage(CDF,Var,prevRec,NULL),&pStatus)) return pStatus; - recX = Var->stage.lastRec - Var->stage.firstRec; - tOffset = Var->stage.areaOffset + (Var->NphyRecBytes * recX) + offset; - if (!sX(ReadVarElems(Var,CDF->stage.fp, - tOffset,numElems,buffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - return pStatus; - } - } - /**************************************************************************** - * Pad the buffer with the variable's pad value. Note that this is also done - * if the variable is sRecords.PREV but a previous record does not exist. - ****************************************************************************/ - if (!sX(PadBuffer(CDF,Var,nValues,buffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - return pStatus; -} - -#if defined(MSVC67) -/****************************************************************************** -* Replace _ftol2 with _ftol on Windows as VC 6.0 doesn't have a such function. -******************************************************************************/ - -VISIBLE_PREFIX long _ftol2(dblSource) -double dblSource; -{ - return (long) _ftol( dblSource ); -} -#endif - -/****************************************************************************** -* UTF8StrLength - Find the actual character number of an UTF-8 string. -******************************************************************************/ - -VISIBLE_PREFIX int UTF8StrLength (string) -unsigned char *string; -{ - int i = 0; - int cnt = 0; - while (string[i]) { - if ((string[i] & 0xC0) != 0x80) cnt++; - ++i; - } - return cnt; -} - - diff --git a/cdf36_3-dist/src/lib/cdfmisc3_64.c b/cdf36_3-dist/src/lib/cdfmisc3_64.c deleted file mode 100644 index cfc0e8a..0000000 --- a/cdf36_3-dist/src/lib/cdfmisc3_64.c +++ /dev/null @@ -1,3123 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF library miscellaneous functions, part 3. -* -* Version 1.0e, 29-Oct-97, Hughes STX. -* -* Modification history: -* -* V1.0 5-Sep-96, J Love Original version. -* V1.0a 21-Feb-97, J Love Removed RICE. -* V1.0b 4-Mar-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V1.0c 11-Sep-97, J Love Magic number are now uInt32. -* V1.0d 20-Oct-97, J Love Properly cast the uInt32 magic numbers. More -* Windows NT. -* V2.0 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* V3.2 25-Apr-07, D Berger Changed COPYblockSIZE from 512. -* V3.3 10-Jan-09, M Liu Added CDFsetValidate and CDFgetValidate. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" -#define REWR_MAX 2147483647 -/****************************************************************************** -* Macros/function prototypes. -******************************************************************************/ - -#define COPYblockSIZE nCACHE_BUFFER_BYTEs - -static CDFstatus SearchForRecord_r_64 PROTOARGs(( - vFILE *fp, OFF_T vxrOffset, Int32 recNum, Int32 *firstRec, Int32 *lastRec, - OFF_T *offset, Logical *found -)); -static CDFstatus IndexingStatistics_r_64 PROTOARGs(( - vFILE *fp, OFF_T vxrOffset, Int32 maxRec, int level, Int32 *nLevels, - Int32 *nVXRs, Int32 *nEntries, Int32 *nAlloc, Int32 *nRecords -)); -static CDFstatus PrevRecord_r_64 PROTOARGs(( - vFILE *fp, OFF_T vxrOffset, Int32 baseRec, Int32 *prevRec, Logical *found -)); -static CDFstatus NextRecord_r_64 PROTOARGs(( - vFILE *fp, OFF_T vxrOffset, Int32 baseRec, Int32 *nextRec, Logical *found -)); -static CDFstatus CalcCompressionPct_r_64 PROTOARGs(( - vFILE *fp, OFF_T vxrOffset, Int32 nPhyRecBytes, OFF_T *uTotal, OFF_T *cTotal -)); -static CDFstatus ModIndexOffset_r_64 PROTOARGs(( - vFILE *fp, OFF_T vxrOffset, Int32 firstRec, Int32 lastRec, OFF_T newOffset -)); -static CDFstatus ReadSparseFull PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 firstRec, Int32 lastRec, - void *buffer -)); -static CDFstatus ReadSparsePartial PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 recNum, OFF_T offset, - OFF_T nValues, void *buffer -)); -static CDFstatus ReadCompressedFull PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 firstRec, Int32 lastRec, - void *buffer -)); -static CDFstatus ReadCompressedPartial PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 recNum, OFF_T offset, - OFF_T nValues, void *buffer -)); -static CDFstatus BringToStage PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 recNum, Logical *found -)); -static CDFstatus WriteCompressedRecords PROTOARGs(( - struct CDFstruct *CDF, struct VarStruct *Var, Int32 firstRec, Int32 lastRec, - void *buffer, OFF_T nValues, OFF_T offset, Logical fullRecord -)); - -/****************************************************************************** -* DecompressCDF64. -******************************************************************************/ - -STATICforIDL CDFstatus DecompressCDF64 (dotFp, uDotFp) -vFILE *dotFp; /* In: File pointer to dotCDF file. */ -vFILE *uDotFp; /* In: Uncompressed CDF file pointer. */ -{ - CDFstatus pStatus = CDF_OK; struct CCRstruct64 CCR; struct CPRstruct64 CPR; - uInt32 magicNumber1 = V3magicNUMBER_1, magicNumber2u = V2magicNUMBER_2u; - OFF_T cSize, cOffset; - /**************************************************************************** - * Read/validate CCR. - ****************************************************************************/ - if (!sX(ReadCCR64(dotFp,V3_CCR_OFFSET64, - CCR_RECORD,&CCR, - CCR_NULL),&pStatus)) return pStatus; - if (CCR.uSize == 0) return EMPTY_COMPRESSED_CDF; - /**************************************************************************** - * Read CPR. - ****************************************************************************/ - if (!sX(ReadCPR64(dotFp,CCR.CPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * Write magic numbers. - ****************************************************************************/ - if (!SEEKv64(uDotFp,(OFF_T) V3_MAGIC_OFFSET_1,vSEEK_SET)) return CDF_WRITE_ERROR; - if (!Write32_64(uDotFp,(Int32 *)&magicNumber1)) return CDF_WRITE_ERROR; - if (!Write32_64(uDotFp,(Int32 *)&magicNumber2u)) return CDF_WRITE_ERROR; - /**************************************************************************** - * Copy/decompress. - ****************************************************************************/ - cOffset = (OFF_T) (V3_CCR_OFFSET64 + CCR_BASE_SIZE64); - cSize = CCR.RecordSize - CCR_BASE_SIZE64; - if (!sX(Decompress64(dotFp,cOffset, - cSize,CDF_READ_ERROR, - CPR.cType,CPR.cParms, - uDotFp,FIRST_IR_OFFSET, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* WriteCompressedCDF64. -******************************************************************************/ - -STATICforIDL CDFstatus WriteCompressedCDF64 (CDF, CPR, empty) -struct CDFstruct *CDF; -struct CPRstruct64 *CPR; -Logical empty; /* In: If TRUE, write an empty CCR. */ -{ - uInt32 magicNumber1 = V3magicNUMBER_1; - uInt32 magicNumber2c = V2magicNUMBER_2c; - struct CCRstruct64 CCR; CDFstatus pStatus = CDF_OK; - /**************************************************************************** - * Write magic numbers. - ****************************************************************************/ - if (!SEEKv64(CDF->dotFp,(OFF_T) V3_MAGIC_OFFSET_1,vSEEK_SET)) return CDF_WRITE_ERROR; - if (!Write32_64(CDF->dotFp,(Int32 *)&magicNumber1)) return CDF_WRITE_ERROR; - if (!Write32_64(CDF->dotFp,(Int32 *)&magicNumber2c)) return CDF_WRITE_ERROR; - /**************************************************************************** - * Write CCR. - ****************************************************************************/ - if (empty) { - CCR.RecordSize = CCR_BASE_SIZE64; - CCR.RecordType = CCR_; - CCR.CPRoffset = (OFF_T) V3_CCR_OFFSET64 + CCR.RecordSize; - CCR.uSize = 0; - CCR.rfuA = 0; - if (!sX(WriteCCR64(CDF->dotFp,V3_CCR_OFFSET64, - CCR_RECORD,&CCR, - CCR_NULL),&pStatus)) return CDF_WRITE_ERROR; - } - else { - OFF_T uSize, eof, cSize, cOffset, GDRoffset; - if (!sX(ReadCDR64(CDF->uDotFp,V3_CDR_OFFSET64, - CDR_GDROFFSET,&GDRoffset, - CDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadGDR64(CDF->uDotFp,GDRoffset, - GDR_EOF,&eof, - GDR_NULL),&pStatus)) return pStatus; - uSize = eof - FIRST_IR_OFFSET; - cOffset = (OFF_T) (V3_CCR_OFFSET64 + CCR_BASE_SIZE64); - if (!sX(Compress64(CDF->uDotFp,FIRST_IR_OFFSET, - uSize,CDF_READ_ERROR,CPR->cType, - CPR->cParms,CDF->dotFp,cOffset, - &cSize,CDF_WRITE_ERROR),&pStatus)) return pStatus; - CCR.RecordSize = (OFF_T) (CCR_BASE_SIZE64 + cSize); - CCR.RecordType = CCR_; - CCR.CPRoffset = (OFF_T) (V3_CCR_OFFSET64 + CCR.RecordSize); - CCR.uSize = uSize; - CCR.rfuA = 0; - if (!sX(WriteCCR64(CDF->dotFp,V3_CCR_OFFSET64, - CCR_RECORD,&CCR, - CCR_NULL),&pStatus)) return CDF_WRITE_ERROR; - } - /**************************************************************************** - * Write CPR. - ****************************************************************************/ - if (!sX(WriteCPR64(CDF->dotFp,CCR.CPRoffset, - CPR_RECORD,CPR, - CPR_NULL),&pStatus)) return CDF_WRITE_ERROR; - return pStatus; -} - -/****************************************************************************** -* CopyCDF64. -******************************************************************************/ - -STATICforIDL CDFstatus CopyCDF64 (srcFp, destFp) -vFILE *srcFp; -vFILE *destFp; -{ - OFF_T nBytes, offset; Byte1 buffer[nCACHE_BUFFER_BYTEs]; - CDFstatus pStatus = CDF_OK; - if (!SEEKv64(srcFp,(OFF_T)0,vSEEK_END)) return CDF_READ_ERROR; - nBytes = V_tell64 (srcFp); - if (nBytes == EOF) return CDF_READ_ERROR; - if (!SEEKv64(srcFp,(OFF_T)0,vSEEK_SET)) return CDF_READ_ERROR; - if (!SEEKv64(destFp,(OFF_T)0,vSEEK_SET)) return CDF_WRITE_ERROR; - for (offset = 0; offset < nBytes; offset += nCACHE_BUFFER_BYTEs) { - OFF_T nBytesRemaining = nBytes - offset; - size_t count = (size_t) MINIMUM (nBytesRemaining, nCACHE_BUFFER_BYTEs); - if (!READv64(buffer,count,1,srcFp)) return CDF_READ_ERROR; - if (!WRITEv64(buffer,count,1,destFp)) return CDF_WRITE_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* WriteVarValues64. -* NOTE: If more than one record is being written, full records are assumed -* and the `offset' must be zero. -******************************************************************************/ - -STATICforIDL CDFstatus WriteVarValues64 (CDF, Var, startRec, offset, nValues, - buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 startRec; /* Physical record number at which to write. */ -Int32 offset; /* Byte offset within (first) record at which to - begin writing. */ -OFF_T nValues; /* Number of values to write. */ -void *buffer; -{ - OFF_T tOffset; Logical fullRecord; Byte1 *tBuffer = buffer; - Int32 firstRec, lastRec, lastRecInVVR, nBytes, padTo, recNum; - Int32 writeTo, recCount; CDFstatus pStatus = CDF_OK; - OFF_T numElems; - /**************************************************************************** - * Determine first/last record(s) being written and if full physical - * record(s). - ****************************************************************************/ - firstRec = startRec; - if (nValues < Var->NphyRecValues) { - fullRecord = FALSE; - lastRec = startRec; - } - else { - fullRecord = TRUE; - lastRec = startRec + ((nValues - 1) / Var->NphyRecValues); - } - /**************************************************************************** - * Based on variable type... - ****************************************************************************/ - switch (Var->vType) { - /************************************************************************** - * Standard variable in single-file CDF... - **************************************************************************/ - case STANDARD_: { - /************************************************************************ - * Allocate/pad records. - ************************************************************************/ - if (lastRec > Var->maxAllocated) { - struct AllocStruct alloc; - Int32 nNeeded = lastRec - Var->maxAllocated; - Int32 nRecords = MAXIMUM(nNeeded,Var->blockingFactor); - LoadAllocVVR64 (alloc, Var->maxAllocated + 1, - Var->maxAllocated + nRecords, FALSE) - if (!sX(AllocateRecords64(CDF,Var,alloc),&pStatus)) return pStatus; - Var->maxAllocated = alloc.last; - } - padTo = BOO(fullRecord,firstRec - 1,firstRec); - if (padTo > Var->maxWritten) { - Int32 padFrom = Var->maxWritten + 1; - if (!sX(PadUnRecords64(CDF,Var,padFrom,padTo),&pStatus)) return pStatus; - Var->maxWritten = padTo; - } - /************************************************************************ - * Write value(s). - ************************************************************************/ - if (fullRecord) { - recNum = firstRec; - while (recNum <= lastRec) { - if (!sX(SearchForRecord64(CDF,Var->VDRoffset64, - Var->zVar,recNum, - NULL,&lastRecInVVR, - NULL,NULL),&pStatus)) return pStatus; - writeTo = MINIMUM(lastRec,lastRecInVVR); - recCount = writeTo - recNum + 1; - if (!sX(RecordByteOffset64(CDF,Var, - recNum, - &tOffset),&pStatus)) return pStatus; - numElems = (OFF_T) recCount * Var->NphyRecElems; - if (!sX(WriteVarElems64(Var,CDF->fp,tOffset, - numElems,tBuffer),&pStatus)) return pStatus; - recNum += recCount; - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - } - } - else { - if (!sX(RecordByteOffset64(CDF,Var, - firstRec, - &tOffset),&pStatus)) return pStatus; - tOffset += (OFF_T) offset; - numElems = nValues * Var->NvalueElems; - if (!sX(WriteVarElems64(Var,CDF->fp,tOffset, - numElems,buffer),&pStatus)) return pStatus; - } - /************************************************************************ - * Update the maximum record written. - ************************************************************************/ - Var->maxWritten = MAXIMUM(Var->maxWritten,lastRec); - break; - } - /************************************************************************** - * Sparse records... - **************************************************************************/ - case SPARSE_RECORDS_: { - Int32 maxRecInStage, recordOffsetInStage, nextRec; - int how; void *padBuffer; Logical found; - /************************************************************************ - * Pad records. - ************************************************************************/ - padTo = BOO(fullRecord,firstRec - 1,firstRec); - if (padTo > Var->maxWritten) { - Int32 padFrom = Var->maxWritten + 1; - if (!sX(PadUnRecords64(CDF,Var,padFrom,padTo),&pStatus)) return pStatus; - Var->maxWritten = padTo; - } - /************************************************************************ - * Write value(s). - ************************************************************************/ - recNum = firstRec; - while (recNum <= lastRec) { - /********************************************************************** - * Check if this record already exists (is allocated). - **********************************************************************/ - if (!sX(SearchForRecord64(CDF,Var->VDRoffset64, - Var->zVar,recNum, - NULL,&lastRecInVVR, - NULL,&found),&pStatus)) return pStatus; - if (found) { - writeTo = MINIMUM(lastRec,lastRecInVVR); - recCount = writeTo - recNum + 1; - if (!sX(RecordByteOffset64(CDF,Var, - recNum,&tOffset),&pStatus)) return pStatus; - if (fullRecord) - numElems = (OFF_T) recCount * Var->NphyRecElems; - else { - tOffset += (OFF_T) offset; - numElems = nValues * Var->NvalueElems; - } - if (!sX(WriteVarElems64(Var,CDF->fp,tOffset, - numElems,tBuffer),&pStatus)) return pStatus; - Var->maxWritten = MAXIMUM(Var->maxWritten,writeTo); - recNum += recCount; - tBuffer += (size_t) (numElems * Var->NelemBytes); - continue; - } - /********************************************************************** - * This record doesn't exist - initialize the staging area. - **********************************************************************/ - if (Var->stage.areaOffset64 == (OFF_T) NO_OFFSET64) { - nBytes = Var->blockingFactor * Var->NphyRecBytes; - if (!sX(InitVarStage64(CDF,Var,nBytes),&pStatus)) return pStatus; - } - /********************************************************************** - * Check if this record is in the staging area. - **********************************************************************/ - if (INCLUSIVE(Var->stage.firstRec,recNum,Var->stage.lastRec)) { - maxRecInStage = Var->stage.firstRec + Var->blockingFactor - 1; - writeTo = MINIMUM(lastRec,maxRecInStage); - if (!sX(NextRecord64(CDF,Var->VDRoffset64,Var->zVar, - recNum,&nextRec,&found),&pStatus)) return pStatus; - if (found) { - Int32 prevRecN = nextRec - 1; - writeTo = MINIMUM(writeTo,prevRecN); - } - recCount = writeTo - recNum + 1; - recordOffsetInStage = recNum - Var->stage.firstRec; - tOffset = Var->stage.areaOffset64; - tOffset += (recordOffsetInStage * Var->NphyRecBytes); - if (fullRecord) - numElems = (OFF_T) recCount * Var->NphyRecElems; - else { - tOffset += (OFF_T) offset; - numElems = nValues * Var->NvalueElems; - } - if (!sX(WriteVarElems64(Var,CDF->stage.fp,tOffset, - numElems,tBuffer),&pStatus)) return pStatus; - Var->stage.lastRec = MAXIMUM(Var->stage.lastRec,writeTo); - Var->stage.modified = TRUE; - recNum += recCount; - tBuffer += (size_t) (numElems * Var->NelemBytes); - continue; - } - /********************************************************************** - * This record is not in the staging area. Check if it can be added. - **********************************************************************/ - if (Var->stage.firstRec != NO_RECORD) { - if (recNum == Var->stage.lastRec + 1) { - maxRecInStage = Var->stage.firstRec + Var->blockingFactor - 1; - if (recNum <= maxRecInStage) { - writeTo = MINIMUM(lastRec,maxRecInStage); - if (!sX(NextRecord64(CDF,Var->VDRoffset64, - Var->zVar,recNum, - &nextRec,&found),&pStatus)) return pStatus; - if (found) { - Int32 prevRecN = nextRec - 1; - writeTo = MINIMUM(writeTo,prevRecN); - } - recCount = writeTo - recNum + 1; - recordOffsetInStage = recNum - Var->stage.firstRec; - tOffset = Var->stage.areaOffset64; - tOffset += (recordOffsetInStage * Var->NphyRecBytes); - if (fullRecord) - numElems = (OFF_T) recCount * Var->NphyRecElems; - else { - if (!sX(BuildPadBuffer64(CDF,Var,recCount, - &how,&padBuffer, - TRUE),&pStatus)) return pStatus; - if (!sX(WritePadValues64(Var,CDF->stage.fp,tOffset, - recCount,how,padBuffer),&pStatus)) { - cdf_FreeMemory (padBuffer, NULL); - return pStatus; - } - cdf_FreeMemory (padBuffer, NULL); - tOffset += (OFF_T) offset; - numElems = nValues * Var->NvalueElems; - } - if (!sX(WriteVarElems64(Var,CDF->stage.fp, - tOffset,numElems, - tBuffer),&pStatus)) return pStatus; - Var->stage.lastRec = MAXIMUM(Var->stage.lastRec,writeTo); - Var->stage.modified = TRUE; - recNum += recCount; - tBuffer += (size_t) (numElems * Var->NelemBytes); - continue; - } - } - } - /********************************************************************** - * This record cannot be added to the staging area. First flush the - * staging area (if necessary)... - **********************************************************************/ - if (!sX(FlushStage64(CDF,Var),&pStatus)) return pStatus; - /********************************************************************** - * ...and then start a new staging area with this record. - **********************************************************************/ - maxRecInStage = recNum + Var->blockingFactor - 1; - writeTo = MINIMUM(lastRec,maxRecInStage); - if (!sX(NextRecord64(CDF,Var->VDRoffset64,Var->zVar, - recNum,&nextRec,&found),&pStatus)) return pStatus; - if (found) { - Int32 prevRecN = nextRec - 1; - writeTo = MINIMUM(writeTo,prevRecN); - } - recCount = writeTo - recNum + 1; - tOffset = Var->stage.areaOffset64; - if (fullRecord) - numElems = (OFF_T) recCount * Var->NphyRecElems; - else { - if (!sX(BuildPadBuffer64(CDF,Var,recCount, - &how,&padBuffer, - TRUE),&pStatus)) return pStatus; - if (!sX(WritePadValues64(Var,CDF->stage.fp,tOffset, - recCount,how,padBuffer),&pStatus)) { - cdf_FreeMemory (padBuffer, NULL); - return pStatus; - } - cdf_FreeMemory (padBuffer, NULL); - tOffset += (OFF_T) offset; - numElems = nValues * Var->NvalueElems; - } - if (!sX(WriteVarElems64(Var,CDF->stage.fp,tOffset, - numElems,tBuffer),&pStatus)) return pStatus; - Var->stage.firstRec = recNum; - Var->stage.lastRec = writeTo; - Var->stage.modified = TRUE; - recNum += recCount; - tBuffer += (size_t) (numElems * Var->NelemBytes); - } - break; - } - /************************************************************************** - * Compressed records... - * Sparse/compressed records... - **************************************************************************/ - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: { - Logical sparseRecords = (Var->vType == SPARSE_COMPRESSED_RECORDS_); - /************************************************************************ - * Initialize staging area. - ************************************************************************/ - if (Var->stage.areaOffset64 == (OFF_T) NO_OFFSET64) { - if (Var->blockingFactor == 0) { - if (Var->recVary) { - Int32 bf = ((MIN_BLOCKING_BYTES_compressed-1)/Var->NphyRecBytes)+1; - Var->blockingFactor = MAXIMUM(bf,MIN_BLOCKING_RECS_compressed); - } - else - Var->blockingFactor = 1; - if (!sX(WriteVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_BLOCKING,&(Var->blockingFactor), - VDR_NULL),&pStatus)) return pStatus; - } - nBytes = Var->blockingFactor * Var->NphyRecBytes; - if (!sX(InitVarStage64(CDF,Var,nBytes),&pStatus)) return pStatus; - } - /************************************************************************ - * Pad records (if necessary). - ************************************************************************/ - if (!sparseRecords) { - padTo = firstRec - 1; - if (Var->maxRec < padTo) { - Int32 nRecords = padTo + 1, recN, valueN; void *padBuffer; int how; - if (!sX(BuildPadBuffer64(CDF,Var, - nRecords,&how, - &padBuffer,FALSE),&pStatus)) return pStatus; - switch (how) { - case ALLrecordsATonce: - if (!sX(WriteCompressedRecords(CDF,Var,Var->maxRec+1, - padTo,padBuffer, - nRecords*Var->NphyRecValues, - (OFF_T) ZERO_OFFSET64, - TRUE),&pStatus)) { - cdf_FreeMemory (padBuffer, NULL); - return pStatus; - } - break; - case ONErecordATaTIME: - for (recN = Var->maxRec + 1; recN <= padTo; recN++) { - if (!sX(WriteCompressedRecords(CDF,Var,recN,recN, - padBuffer,Var->NphyRecValues, - (OFF_T) ZERO_OFFSET64,TRUE),&pStatus)) { - cdf_FreeMemory (padBuffer, NULL); - return pStatus; - } - } - break; - case ONEvalueATaTIME: - for (recN = 0; recN < nRecords; recN++) { - for (valueN = 0; valueN < Var->NphyRecValues; valueN++) { - tOffset = valueN * Var->NvalueBytes; - if (!sX(WriteCompressedRecords(CDF,Var,recN,recN, - padBuffer,INT32_ONE, - tOffset,FALSE),&pStatus)) { - cdf_FreeMemory (padBuffer, NULL); - return pStatus; - } - } - } - break; - } - cdf_FreeMemory (padBuffer, NULL); - } - } - /************************************************************************ - * Write the record(s). - ************************************************************************/ - if (!sX(WriteCompressedRecords(CDF,Var,firstRec,lastRec, - buffer,nValues,offset, - fullRecord),&pStatus)) return pStatus; - break; - } - /************************************************************************** - * Can't do sparse arrays yet... - **************************************************************************/ - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return UNKNOWN_SPARSENESS; - /************************************************************************** - * Variable in multi-file CDF... - **************************************************************************/ - case IN_MULTI_: { - padTo = BOO(fullRecord,firstRec - 1,firstRec); - /************************************************************************ - * Extend variable (if necessary). - ************************************************************************/ - if (padTo > Var->maxRec) { - Int32 padFrom = Var->maxRec + 1; - if (!sX(PadUnRecords64(CDF,Var,padFrom,padTo),&pStatus)) return pStatus; - } - /************************************************************************ - * Write value(s). - ************************************************************************/ - if (!sX(RecordByteOffset64(CDF,Var, - firstRec, - &tOffset),&pStatus)) return pStatus; - tOffset += (OFF_T) offset; - numElems = nValues * Var->NvalueElems; - if (!sX(WriteVarElems64(Var,Var->fp,tOffset, - numElems,buffer),&pStatus)) return pStatus; - break; - } - /************************************************************************** - * Unknown variable type - this should never happen. - **************************************************************************/ - default: - return CDF_INTERNAL_ERROR; - } - /**************************************************************************** - * Update maximum record numbers. - ****************************************************************************/ - if (!sX(UpdateMaxRec64(CDF,Var,lastRec),&pStatus)) return pStatus; - return pStatus; -} - -/****************************************************************************** -* WriteVarElems64. -* NOTE: On IBM PCs, it is assumed that the number of bytes being written -* will not exceed 65535. -******************************************************************************/ - -STATICforIDL CDFstatus WriteVarElems64 (Var, fp, offset, numElems, buffer) -struct VarStruct *Var; -vFILE *fp; -OFF_T offset; -OFF_T numElems; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; OFF_T elemCount; - /**************************************************************************** - * Seek to the desired offset. - ****************************************************************************/ - if (!SEEKv64(fp,offset,vSEEK_SET)) return VAR_WRITE_ERROR; - /**************************************************************************** - * If no encoding is necessary, simply write the buffer and return. - ****************************************************************************/ - if (Var->EncodeFunction == NULL) { - OFF_T totalBytes = numElems * Var->NelemBytes; - if (totalBytes <= REWR_MAX) { - Int32 nBytes = (size_t) totalBytes; - if (STRINGdataType(Var->dataType)) { - int len = (int) strlen((char *)buffer); - if (len < (int) totalBytes) { - char *newBuffer = (char *) cdf_AllocateMemory (nBytes, NULL); - memcpy (newBuffer, (char *)buffer, totalBytes); - FillSpacesToString((char *)newBuffer, (int) totalBytes, - (int) Var->NvalueElems); - if (!WRITEv64(newBuffer,1,(size_t)nBytes,fp)) return VAR_WRITE_ERROR; - cdf_FreeMemory (newBuffer, NULL); - } else - if (!WRITEv64(buffer,1,(size_t)nBytes,fp)) return VAR_WRITE_ERROR; - } else - if (!WRITEv64(buffer,1,(size_t)nBytes,fp)) return VAR_WRITE_ERROR; - } else { - Byte1 *tBuffer = (Byte1 *) buffer; - OFF_T remaining = totalBytes; - int i = 0; - while (remaining > 0) { - if (!WRITEv64(tBuffer+i*REWR_MAX,1, - (remaining>REWR_MAX?(size_t)REWR_MAX:(size_t)remaining), - fp)) - return CDF_WRITE_ERROR; - remaining -= REWR_MAX; - ++i; - } - } - return pStatus; - } - /**************************************************************************** - * Use as large a temporary buffer as possible for the encoding conversion. - * Start at the full number of elements and then halve that number until an - * allocation succeeds. - ****************************************************************************/ - elemCount = numElems; - for (;;) { - OFF_T xBytes = (OFF_T) elemCount * Var->NelemBytes; -#if defined(win32) - if (xBytes < (OFF_T) ((1i64 << 31) - 1)) { -#else - if (xBytes < (OFF_T) ((1LL << 31) - 1)) { -#endif - size_t nBytes = (size_t) (elemCount * Var->NelemBytes); - void *tBuffer; - if ((int) nBytes <= 0) return VAR_READ_ERROR; - tBuffer = cdf_AllocateMemory (nBytes, NULL); - if (tBuffer != NULL) { - OFF_T elemN = 0; Byte1 *bOffset = buffer; - Int32 thisElemCount; size_t thisByteCount; - while (elemN < numElems) { - if ((numElems - elemN) > elemCount) thisElemCount = elemCount; - else thisElemCount = (Int32) (numElems - elemN); - thisByteCount = (size_t) (thisElemCount * Var->NelemBytes); - memmove (tBuffer, bOffset, thisByteCount); - if (!sX(Var->EncodeFunction(tBuffer,thisElemCount),&pStatus)) { - cdf_FreeMemory (tBuffer, NULL); - return pStatus; - } - if (!WRITEv64(tBuffer,1,thisByteCount,fp)) { - cdf_FreeMemory (tBuffer, NULL); - return VAR_WRITE_ERROR; - } - elemN += (OFF_T) thisElemCount; - bOffset += (OFF_T) thisByteCount; - } - cdf_FreeMemory (tBuffer, NULL); - return pStatus; - } - } - if (elemCount == 1) break; - elemCount = (elemCount + 1) / 2; - } - return BAD_MALLOC; -} - -/****************************************************************************** -* PrevRecord64. -* Determine the last record allocated AT or BEFORE `baseRec'. This routine -* should only be used for single-file CDFs. -******************************************************************************/ - -STATICforIDL CDFstatus PrevRecord64 (CDF, VDRoffset, zVar, baseRec, prevRec, - found) -struct CDFstruct *CDF; -OFF_T VDRoffset; -Logical zVar; -Int32 baseRec; -Int32 *prevRec; -Logical *found; /* If NULL, return NO_SUCH_RECORD if the previous - record doesn't exist. Otherwise, set according to - whether or not the previous record exists and - return the pending status. */ -{ - CDFstatus pStatus = CDF_OK; OFF_T VXRoffset; - /**************************************************************************** - * If multi-file... - ****************************************************************************/ - if (!CDF->singleFile) return CDF_INTERNAL_ERROR; - /**************************************************************************** - * Single-file...read the offset of the first VXR. - ****************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,VDRoffset,zVar, - VDR_VXRHEAD,&VXRoffset, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * ...and start there (unless there are no VXRs). - ****************************************************************************/ - if (VXRoffset != (OFF_T) ZERO_OFFSET64) { - if (!sX(PrevRecord_r_64(CDF->fp,VXRoffset, - baseRec,prevRec,found),&pStatus)) return pStatus; - } - else { - ASSIGNnotNULL (found, FALSE) - if (found == NULL) pStatus = NO_SUCH_RECORD; - } - return pStatus; -} - -static CDFstatus PrevRecord_r_64 (fp, vxrOffset, baseRec, prevRec, found) -vFILE *fp; -OFF_T vxrOffset; -Int32 baseRec; -Int32 *prevRec; -Logical *found; -{ - CDFstatus pStatus = CDF_OK; int entryN = 0; - struct VXRstruct64 VXR, nextVXR; Int32 irType; - /**************************************************************************** - * Read the first VXR. - ****************************************************************************/ - if (!sX(ReadVXR64(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * Check if there isn't a previous allocated record. This could only be the - * case at the top level of VXRs (ie. not when this routine is recursively - * called). - ****************************************************************************/ - if (baseRec < VXR.First[0]) { - ASSIGNnotNULL (found, FALSE) - return BOO(found == NULL,NO_SUCH_RECORD,pStatus); - } - /**************************************************************************** - * Until it's time to return... - ****************************************************************************/ - for (;;) { - /************************************************************************* - * If the record is in the current entry... - *************************************************************************/ - if (INCLUSIVE(VXR.First[entryN],baseRec,VXR.Last[entryN])) { - if (!sX(ReadIrType64(fp,VXR.Offset[entryN],&irType),&pStatus)) { - return pStatus; - } - switch (irType) { - case VXR_: - return PrevRecord_r_64(fp,VXR.Offset[entryN],baseRec,prevRec,found); - case VVR_: - case CVVR_: - *prevRec = baseRec; - ASSIGNnotNULL (found, TRUE) - return pStatus; - default: - return CORRUPTED_V3_CDF; - } - } - /************************************************************************* - * If this is the last entry in the current VXR... - *************************************************************************/ - if (entryN == VXR.NusedEntries - 1) { - if (VXR.VXRnext == (OFF_T) ZERO_OFFSET64) { - *prevRec = VXR.Last[entryN]; - ASSIGNnotNULL (found, TRUE) - return pStatus; - } - if (!sX(ReadVXR64(fp,VXR.VXRnext, - VXR_RECORD,&nextVXR, - VXR_NULL),&pStatus)) return pStatus; - if (baseRec < nextVXR.First[0]) { - *prevRec = VXR.Last[entryN]; - ASSIGNnotNULL (found, TRUE) - return pStatus; - } - VXR = nextVXR; - entryN = 0; - } - else { - if (baseRec < VXR.First[entryN+1]) { - *prevRec = VXR.Last[entryN]; - ASSIGNnotNULL (found, TRUE) - return pStatus; - } - entryN++; - } - } -} - -/****************************************************************************** -* NextRecord64. -* Determine the next allocated record AT or AFTER `baseRec'. I.e., if -* `baseRec' is allocated, it is returned as `nextRec'. -******************************************************************************/ - -STATICforIDL CDFstatus NextRecord64 (CDF, VDRoffset, zVar, baseRec, nextRec, - found) -struct CDFstruct *CDF; -OFF_T VDRoffset; -Logical zVar; -Int32 baseRec; -Int32 *nextRec; -Logical *found; /* If NULL, return NO_SUCH_RECORD if the next record - doesn't exist. Otherwise, set according to whether - or not the next record exists and return the pending - status. */ -{ - CDFstatus pStatus = CDF_OK; Int32 maxRec; - OFF_T VXRoffset; - /**************************************************************************** - * If multi-file... - ****************************************************************************/ - if (!CDF->singleFile) { - if (!sX(ReadVDR64(CDF,CDF->fp,VDRoffset,zVar, - VDR_MAXREC,&maxRec, - VDR_NULL),&pStatus)) return pStatus; - if (baseRec <= maxRec) { - *nextRec = baseRec; - ASSIGNnotNULL (found, TRUE) - } - else { - ASSIGNnotNULL (found, FALSE) - if (found == NULL) pStatus = NO_SUCH_RECORD; - } - return pStatus; - } - /**************************************************************************** - * ...single-file, read the offset of the first VXR. - ****************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,VDRoffset,zVar, - VDR_VXRHEAD,&VXRoffset, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * ...and start there. - ****************************************************************************/ - if (!sX(NextRecord_r_64(CDF->fp,VXRoffset, - baseRec,nextRec,found),&pStatus)) return pStatus; - return pStatus; -} - -static CDFstatus NextRecord_r_64 (fp, vxrOffset, baseRec, nextRec, found) -vFILE *fp; -OFF_T vxrOffset; -Int32 baseRec; -Int32 *nextRec; -Logical *found; -{ - CDFstatus pStatus = CDF_OK; - int entryN; struct VXRstruct64 VXR; Int32 irType; - /**************************************************************************** - * While more VXRs... - ****************************************************************************/ - while (vxrOffset != (OFF_T) ZERO_OFFSET64) { - /************************************************************************** - * Read the VXR. - **************************************************************************/ - if (!sX(ReadVXR64(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************** - * Search entries... - **************************************************************************/ - if (baseRec <= VXR.Last[(int)(VXR.NusedEntries-1)]) { - for (entryN = 0; entryN < VXR.NusedEntries; entryN++) { - if (baseRec <= VXR.Last[entryN]) { - if (!sX(ReadIrType64(fp, - VXR.Offset[entryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - return NextRecord_r_64(fp,VXR.Offset[entryN], - baseRec,nextRec,found); - case VVR_: - case CVVR_: - *nextRec = BOO(VXR.First[entryN] <= baseRec, - baseRec,VXR.First[entryN]); - ASSIGNnotNULL (found, TRUE) - return pStatus; - default: - return CORRUPTED_V3_CDF; - } - } - } - } - vxrOffset = VXR.VXRnext; - } - /**************************************************************************** - * No (more) VXRs. The record number was never found. - ****************************************************************************/ - ASSIGNnotNULL (found, FALSE) - return BOO(found == NULL,NO_SUCH_RECORD,pStatus); -} - -/****************************************************************************** -* SearchForRecord64. -******************************************************************************/ - -STATICforIDL CDFstatus SearchForRecord64 (CDF, VDRoffset, zVar, recNum, - firstRec, lastRec, offset, found) -struct CDFstruct *CDF; -OFF_T VDRoffset; -Logical zVar; -Int32 recNum; -Int32 *firstRec; -Int32 *lastRec; -OFF_T *offset; -Logical *found; /* If NULL, return NO_SUCH_RECORD if the record is - not found. Otherwise, set according to whether - or not the record is found and return the pending - status. */ -{ - CDFstatus pStatus = CDF_OK; Int32 maxRec; - OFF_T vxrOffset; - /**************************************************************************** - * If multi-file... - ****************************************************************************/ - if (!CDF->singleFile) { - if (!sX(ReadVDR64(CDF,CDF->fp,VDRoffset,zVar, - VDR_MAXREC,&maxRec, - VDR_NULL),&pStatus)) return pStatus; - if (recNum <= maxRec) { - ASSIGNnotNULL (firstRec, 0) - ASSIGNnotNULL (lastRec, maxRec) - ASSIGNnotNULL (offset, (OFF_T) ZERO_OFFSET64) - ASSIGNnotNULL (found, TRUE) - } - else { - ASSIGNnotNULL (found, FALSE) - if (found == NULL) pStatus = NO_SUCH_RECORD; - } - return pStatus; - } - /**************************************************************************** - * ...single-file, read the offset of the first VXR. - ****************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,VDRoffset,zVar, - VDR_VXRHEAD,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * ...and start searching there. - ****************************************************************************/ - if (!sX(SearchForRecord_r_64(CDF->fp,vxrOffset,recNum, - firstRec,lastRec, - offset,found),&pStatus)) return pStatus; - return pStatus; -} - -static CDFstatus SearchForRecord_r_64 (fp, vxrOffset, recNum, firstRec, lastRec, - offset, found) -vFILE *fp; -OFF_T vxrOffset; -Int32 recNum; -Int32 *firstRec; -Int32 *lastRec; -OFF_T *offset; -Logical *found; -{ - CDFstatus pStatus = CDF_OK; - int entryN; struct VXRstruct64 VXR; Int32 irType; - /**************************************************************************** - * While more VXRs... - ****************************************************************************/ - while (vxrOffset != (OFF_T) ZERO_OFFSET64) { - /************************************************************************** - * Read the VXR. - **************************************************************************/ - if (!sX(ReadVXR64(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************** - * Search entries... - **************************************************************************/ - if (recNum <= VXR.Last[(int)(VXR.NusedEntries-1)]) { - for (entryN = 0; entryN < VXR.NusedEntries; entryN++) { - if (recNum <= VXR.Last[entryN]) { - if (VXR.First[entryN] <= recNum) { - if (!sX(ReadIrType64(fp, - VXR.Offset[entryN], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - return SearchForRecord_r_64(fp,VXR.Offset[entryN],recNum, - firstRec,lastRec,offset,found); - case VVR_: - case CVVR_: - ASSIGNnotNULL (firstRec, VXR.First[entryN]) - ASSIGNnotNULL (lastRec, VXR.Last[entryN]) - ASSIGNnotNULL (offset, VXR.Offset[entryN]) - ASSIGNnotNULL (found, TRUE) - return pStatus; - default: - return CORRUPTED_V3_CDF; - } - } - else { - ASSIGNnotNULL (found, FALSE) - return BOO(found == NULL,NO_SUCH_RECORD,pStatus); - } - } - } - } - vxrOffset = VXR.VXRnext; - } - /**************************************************************************** - * No (more) VXRs. The record number was never found. - ****************************************************************************/ - ASSIGNnotNULL (found, FALSE) - return BOO(found == NULL,NO_SUCH_RECORD,pStatus); -} - -/****************************************************************************** -* IndexingStatistics64. -******************************************************************************/ - -STATICforIDL CDFstatus IndexingStatistics64 (CDF, VDRoffset, zVar, nVXRsP, - nEntriesP, nAllocP, nRecordsP, - nLevelsP) -struct CDFstruct *CDF; -OFF_T VDRoffset; -Logical zVar; -Int32 *nVXRsP; -Int32 *nEntriesP; -Int32 *nAllocP; -Int32 *nRecordsP; -Int32 *nLevelsP; -{ - CDFstatus pStatus = CDF_OK; Int32 maxRec; int level = 1; - Int32 nVXRs = 0, nEntries = 0, nAlloc = 0, nRecords = 0, nLevels = 0; - OFF_T vxrOffset; - /**************************************************************************** - * Read the maximum record and the offset of the first VXR... - ****************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,VDRoffset,zVar, - VDR_VXRHEAD,&vxrOffset, - VDR_MAXREC,&maxRec, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * ...and start there. - ****************************************************************************/ - if (vxrOffset != (OFF_T) ZERO_OFFSET64) { - if (!sX(IndexingStatistics_r_64(CDF->fp,vxrOffset, - maxRec,level,&nLevels, - &nVXRs,&nEntries, - &nAlloc,&nRecords),&pStatus)) return pStatus; - } - /**************************************************************************** - * Pass back requested statistics. - ****************************************************************************/ - ASSIGNnotNULL (nVXRsP, nVXRs) - ASSIGNnotNULL (nEntriesP, nEntries) - ASSIGNnotNULL (nAllocP, nAlloc) - ASSIGNnotNULL (nRecordsP, nRecords) - ASSIGNnotNULL (nLevelsP, nLevels) - return pStatus; -} - -static CDFstatus IndexingStatistics_r_64 (fp, vxrOffset, maxRec, level, nLevels, - nVXRs, nEntries, nAlloc, nRecords) -vFILE *fp; -OFF_T vxrOffset; -Int32 maxRec; -int level; -Int32 *nLevels; -Int32 *nVXRs; -Int32 *nEntries; -Int32 *nAlloc; -Int32 *nRecords; -{ - CDFstatus pStatus = CDF_OK; - int e; Int32 irType; struct VXRstruct64 VXR; - /**************************************************************************** - * Check if a new level has been reached. - ****************************************************************************/ - *nLevels = MAXIMUM(*nLevels,level); - /**************************************************************************** - * While more VXRs... - ****************************************************************************/ - while (vxrOffset != (OFF_T) ZERO_OFFSET64) { - /************************************************************************** - * Read/tally the VXR. - **************************************************************************/ - if (!sX(ReadVXR64(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - (*nVXRs)++; - /************************************************************************** - * Scan/count entries... - **************************************************************************/ - for (e = 0; e < VXR.NusedEntries; e++) { - (*nEntries)++; - if (!sX(ReadIrType64(fp, - VXR.Offset[e], - &irType),&pStatus)) return pStatus; - switch (irType) { - case VXR_: - if (!sX(IndexingStatistics_r_64(fp,VXR.Offset[e], - maxRec,level+1, - nLevels,nVXRs, - nEntries,nAlloc, - nRecords),&pStatus)) return pStatus; - break; - case VVR_: - case CVVR_: - *nAlloc += (VXR.Last[e] - VXR.First[e] + 1); - if (VXR.First[e] <= maxRec) { - *nRecords += MINIMUM(maxRec,VXR.Last[e]) - VXR.First[e] + 1; - } - break; - default: - return CORRUPTED_V3_CDF; - } - } - vxrOffset = VXR.VXRnext; - } - return pStatus; -} - -/****************************************************************************** -* BuildPadBuffer64. -******************************************************************************/ - -STATICforIDL CDFstatus BuildPadBuffer64 (CDF, Var, nRecords, how, buffer, encode) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 nRecords; -int *how; -void **buffer; -Logical encode; /* If TRUE, return values in CDF's encoding. If FALSE, - return values in host computer's encoding. */ -{ - Byte1 *ptr; Int32 nBytes, valueN; void *padValue; - Int32 VDRflags, dataType, numElems; CDFstatus pStatus = CDF_OK; - OFF_T xBytes, nValues; - /**************************************************************************** - * Determine pad value. - ****************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_FLAGS,&VDRflags, - VDR_NULL),&pStatus)) return pStatus; - padValue = (void *) cdf_AllocateMemory ((size_t) Var->NvalueBytes, NULL); - if (padValue == NULL) return BAD_MALLOC; - if (PADvalueBITset(VDRflags)) { - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_PADVALUE,padValue, - VDR_NULL),&pStatus)) { - cdf_FreeMemory (padValue, NULL); - return pStatus; - } - if (!encode) { - if (!sX(ConvertBuffer(CDF->encoding,HostDecoding(), - CDF->negToPosFp0,dataType, - numElems,padValue,padValue),&pStatus)) { - cdf_FreeMemory (padValue, NULL); - return pStatus; - } - } - } - else { - Int32 version, release; - if (!sX(ReadCDR64(CDF->fp,CDF->CDRoffset64, - CDR_VERSION,&version, - CDR_RELEASE,&release, - CDR_NULL),&pStatus)) return pStatus; - if (version*100+release < 305) - DefaultPadValuePre350 (dataType, numElems, padValue); - else - DefaultPadValue (dataType, numElems, padValue); - if (encode) { - if (!sX(ConvertBuffer(HostEncoding(),CDF->encoding, - CDF->negToPosFp0,dataType, - numElems,padValue,padValue),&pStatus)) { - cdf_FreeMemory (padValue, NULL); - return pStatus; - } - } - } - /**************************************************************************** - * Try to allocate all of the records at once... - ****************************************************************************/ - nValues = (OFF_T) nRecords * Var->NphyRecValues; - xBytes = nValues * Var->NvalueBytes; -#if defined(win32) - if (xBytes < (OFF_T) ((1i64 << 31) - 1)) { -#else - if (xBytes < (OFF_T) ((1LL << 31) - 1)) { -#endif - nBytes = (Int32) xBytes; -#if LIMITof64K - if (nBytes < 65536L) { -#endif - *buffer = (void *) cdf_AllocateMemory ((size_t) nBytes, NULL); - if (*buffer != NULL) { - for (valueN = 0, ptr = (Byte1 *) *buffer; - valueN < nValues; valueN++, ptr += (size_t) Var->NvalueBytes) { - memmove (ptr, padValue, (size_t) Var->NvalueBytes); - } - cdf_FreeMemory (padValue, NULL); - *how = ALLrecordsATonce; - return pStatus; - } -#if LIMITof64K - } -#endif - } - /**************************************************************************** - * Not enough memory for that, try allocating one record... - ****************************************************************************/ -#if LIMITof64K - if (Var->NphyRecBytes < 65536L) { -#endif - *buffer = (void *) cdf_AllocateMemory ((size_t) Var->NphyRecBytes, NULL); - if (*buffer != NULL) { - for (valueN = 0, ptr = (Byte1 *) *buffer; - valueN < Var->NphyRecValues; - valueN++, ptr += (size_t) Var->NvalueBytes) { - memmove (ptr, padValue, (size_t) Var->NvalueBytes); - } - cdf_FreeMemory (padValue, NULL); - *how = ONErecordATaTIME; - return pStatus; - } -#if LIMITof64K - } -#endif - /**************************************************************************** - * Not enough memory for that either, use the one allocated value... - ****************************************************************************/ - *buffer = padValue; - *how = ONEvalueATaTIME; - return pStatus; -} - -/****************************************************************************** -* ReadVarValues64. -* NOTE: If more than one record is being read, full records are assumed -* and the `offset' must be zero. -******************************************************************************/ - -STATICforIDL CDFstatus ReadVarValues64 (CDF, Var, startRec, offset, nValues, - buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 startRec; /* Physical record number at which to start reading. */ -Int32 offset; /* Byte offset within (first) record at which to - begin reading. */ -OFF_T nValues; /* Number of values to read. */ -void *buffer; -{ - CDFstatus pStatus = CDF_OK; OFF_T tOffset; Logical fullRecord; - Int32 numElems, firstRec, lastRec, lastRecInVVR; - Int32 readTo, recCount, nBytes; OFF_T nPadValues; - /**************************************************************************** - * Determine first/last record(s) being read and if full physical record(s). - ****************************************************************************/ - firstRec = startRec; - if (nValues < Var->NphyRecValues) { - fullRecord = FALSE; - lastRec = startRec; - } - else { - fullRecord = TRUE; - lastRec = startRec + ((nValues - 1) / Var->NphyRecValues); - } - /**************************************************************************** - * Read value(s). - ****************************************************************************/ - switch (Var->vType) { - /************************************************************************** - * Standard variable in a single-file CDF... - **************************************************************************/ - case STANDARD_: - if (fullRecord) { - /********************************************************************** - * Full record(s) - read from contiguous groups... - **********************************************************************/ - Byte1 *tBuffer = buffer; Int32 recNum = firstRec; - while (recNum <= lastRec) { - if (recNum <= Var->maxRec) { - if (!sX(SearchForRecord64(CDF,Var->VDRoffset64, - Var->zVar,recNum, - NULL,&lastRecInVVR, - NULL,NULL),&pStatus)) return pStatus; - readTo = MINIMUMof3(Var->maxRec,lastRec,lastRecInVVR); - recCount = readTo - recNum + 1; - if (!sX(RecordByteOffset64(CDF,Var, - recNum, - &tOffset),&pStatus)) return pStatus; - numElems = recCount * Var->NphyRecElems; - if (!sX(ReadVarElems64(Var,CDF->fp,tOffset, - numElems,tBuffer),&pStatus)) return pStatus; - } - else { - recCount = lastRec - recNum + 1; - nPadValues = (OFF_T) recCount * Var->NphyRecValues; - if (!sX(PadBuffer64(CDF,Var, - nPadValues, - tBuffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - } - recNum += recCount; - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - } - } - else { - /********************************************************************** - * Partial record... - **********************************************************************/ - if (firstRec <= Var->maxRec) { - if (!sX(RecordByteOffset64(CDF,Var, - firstRec, - &tOffset),&pStatus)) return pStatus; - tOffset += (OFF_T) offset; - numElems = nValues * Var->NvalueElems; - if (!sX(ReadVarElems64(Var,CDF->fp,tOffset, - numElems,buffer),&pStatus)) return pStatus; - } - else { - if (!sX(PadBuffer64(CDF,Var,nValues,buffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - } - } - break; - /************************************************************************** - * Sparse records... - **************************************************************************/ - case SPARSE_RECORDS_: { - if (fullRecord) { - if (!sX(ReadSparseFull(CDF,Var,firstRec, - lastRec,buffer),&pStatus)) return pStatus; - } - else { - if (!sX(ReadSparsePartial(CDF,Var, - startRec,offset, - nValues,buffer),&pStatus)) return pStatus; - } - break; - } - /************************************************************************** - * Compressed variable... - **************************************************************************/ - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: { - /************************************************************************ - * Initialize staging area. Note that the staging area is only - * initialized if records have been written. This prevents the - * CORRUPTED_V3_CDF error code from being returned if an explicit - * blocking factor has not been specified for the variable. - ************************************************************************/ - if (Var->stage.areaOffset64 == (OFF_T) NO_OFFSET64 && - Var->maxRec > NO_RECORD) { - if (Var->blockingFactor == 0) return CORRUPTED_V3_CDF; - nBytes = Var->blockingFactor * Var->NphyRecBytes; - if (!sX(InitVarStage64(CDF,Var,nBytes),&pStatus)) return pStatus; - } - /************************************************************************ - * If full record(s) or partial record... - ************************************************************************/ - if (fullRecord) { - if (!sX(ReadCompressedFull(CDF,Var,firstRec, - lastRec,buffer),&pStatus)) return pStatus; - } - else { - if (!sX(ReadCompressedPartial(CDF,Var,startRec, - offset,nValues, - buffer),&pStatus)) return pStatus; - } - break; - } - /************************************************************************** - * Can't do sparse arrays yet... - **************************************************************************/ - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return UNKNOWN_SPARSENESS; - case IN_MULTI_: - if (fullRecord) { - /******************************************************************** - * Full record(s). - ********************************************************************/ - Byte1 *tBuffer = buffer; - if (firstRec <= Var->maxRec) { - if (!sX(RecordByteOffset64(CDF,Var, - firstRec, - &tOffset),&pStatus)) return pStatus; - recCount = MINIMUM(lastRec,Var->maxRec) - firstRec + 1; - numElems = recCount * Var->NphyRecElems; - if (!sX(ReadVarElems64(Var,Var->fp,tOffset, - numElems,tBuffer),&pStatus)) return pStatus; - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - } - if (lastRec > Var->maxRec) { - recCount = BOO(Var->maxRec < firstRec, - lastRec - firstRec + 1, - lastRec - Var->maxRec); - nPadValues = (OFF_T) recCount * Var->NphyRecValues; - if (!sX(PadBuffer64(CDF,Var, - nPadValues, - tBuffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - } - } - else { - /******************************************************************** - * Partial record. - ********************************************************************/ - if (firstRec <= Var->maxRec) { - if (!sX(RecordByteOffset64(CDF,Var, - firstRec, - &tOffset),&pStatus)) return pStatus; - tOffset += (OFF_T) offset; - numElems = nValues * Var->NvalueElems; - if (!sX(ReadVarElems64(Var,Var->fp,tOffset, - numElems,buffer),&pStatus)) return pStatus; - } - else { - if (!sX(PadBuffer64(CDF,Var,nValues,buffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - } - } - break; - } - return pStatus; -} - -/****************************************************************************** -* ReadVarElems64. -* NOTE: On IBM PCs, it is assumed that the number of bytes being read -* will not exceed 65535. -******************************************************************************/ - -STATICforIDL CDFstatus ReadVarElems64 (Var, fp, offset, numElems, buffer) -struct VarStruct *Var; -vFILE *fp; -OFF_T offset; -OFF_T numElems; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; size_t nBytes; - OFF_T totalBytes; - /**************************************************************************** - * Seek to the desired offset. - ****************************************************************************/ - if (!SEEKv64(fp,offset,vSEEK_SET)) return VAR_READ_ERROR; - /**************************************************************************** - * Read the value(s). - ****************************************************************************/ - totalBytes = numElems * Var->NelemBytes; - if (totalBytes <= REWR_MAX) { - nBytes = (size_t) totalBytes; - if (!READv64(buffer,(size_t)totalBytes,1,fp)) return VAR_READ_ERROR; - if (STRINGdataType(Var->dataType)) { - FillSpacesToString((char *)buffer, (int) numElems, - (int) Var->NvalueElems); - } - } else { - Byte1 *tBuffer = (Byte1 *) buffer; - OFF_T remaining = totalBytes; - int i = 0; - while (remaining > 0) { - if (!READv64(tBuffer+i*REWR_MAX, - (remaining>REWR_MAX?(size_t)REWR_MAX:(size_t)remaining), - 1,fp)) - return CDF_READ_ERROR; - remaining -= (OFF_T) REWR_MAX; - ++i; - } - } - /**************************************************************************** - * Decode value(s). - ****************************************************************************/ - if (numElems < REWR_MAX) { - if (!sX(DECODE(Var->DecodeFunction,buffer,(Int32)numElems),&pStatus)) { - return pStatus; - } - } else { - Byte1 *tBuffer = (Byte1 *) buffer; - OFF_T remaining = numElems; - int i = 0; - while (remaining > 0) { - if (!sX(DECODE(Var->DecodeFunction,tBuffer+i*REWR_MAX, - (remaining>REWR_MAX?(Int32)REWR_MAX:(Int32)remaining)), - &pStatus)) - return CDF_READ_ERROR; - remaining -= REWR_MAX; - ++i; - } - } - - return pStatus; -} - -/****************************************************************************** -* InitVarStage64. -******************************************************************************/ - -STATICforIDL CDFstatus InitVarStage64 (CDF, Var, nBytes) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 nBytes; -{ - if (CDF->stage.fp == NULL) { - CDF->stage.fp = V_scratch (ScratchDirectory(CDF), "stg"); - if (CDF->stage.fp == NULL) return SCRATCH_CREATE_ERROR; - if (!CACHEv64(CDF->stage.fp,CDF->stage.cacheSize)) { - V_delete64 (CDF->stage.fp, NULL); - CDF->stage.fp = NULL; - return BAD_CACHE_SIZE; - } - CDF->stage.mark64 = (OFF_T) ZERO_OFFSET64; - } - Var->stage.areaOffset64 = CDF->stage.mark64; - Var->stage.firstRec = NO_RECORD; - Var->stage.lastRec = NO_RECORD; - Var->stage.dotOffset64 = (OFF_T) NO_OFFSET64; - Var->stage.modified = FALSE; - CDF->stage.mark64 += nBytes; - return CDF_OK; -} - -/****************************************************************************** -* InitScratch64. -******************************************************************************/ - -STATICforIDL CDFstatus InitScratch64 (scratchDir, scratchFpH, cacheSize) -char *scratchDir; /* Scratch directory to be used. */ -vFILE **scratchFpH; /* Scratch file handle (pointer to pointer). */ -int cacheSize; /* Number of cache buffers to request. */ -{ - if (*scratchFpH == NULL) { - *scratchFpH = V_scratch (scratchDir, NULL); - if (*scratchFpH == NULL) return SCRATCH_CREATE_ERROR; - if (!CACHEv64(*scratchFpH,cacheSize)) { - V_delete64 (*scratchFpH, NULL); - *scratchFpH = NULL; - return BAD_CACHE_SIZE; - } - } - else { - if (V_clear(*scratchFpH) != 0) return SCRATCH_READ_ERROR; - if (!SEEKv64(*scratchFpH,(OFF_T)0,vSEEK_SET)) return SCRATCH_READ_ERROR; - } - return CDF_OK; -} - -/****************************************************************************** -* FlushStage64. -******************************************************************************/ - -STATICforIDL CDFstatus FlushStage64 (CDF, Var) -struct CDFstruct *CDF; -struct VarStruct *Var; -{ - CDFstatus pStatus = CDF_OK; - /**************************************************************************** - * Based on the variable type... - ****************************************************************************/ - switch (Var->vType) { - case SPARSE_RECORDS_: { - Int32 nRecords, nBytes; struct AllocStruct alloc; - OFF_T tOffset; - /************************************************************************ - * First check if there are records to be flushed in the staging area. - ************************************************************************/ - if (!Var->stage.modified) return pStatus; - /************************************************************************ - * Allocate a new VVR. - ************************************************************************/ - LoadAllocVVR64 (alloc, Var->stage.firstRec, Var->stage.lastRec, FALSE) - if (!sX(AllocateRecords64(CDF,Var,alloc),&pStatus)) return pStatus; - Var->maxAllocated = MAXIMUM(Var->maxAllocated,Var->stage.lastRec); - /************************************************************************ - * Copy the records to the new VVR. - ************************************************************************/ - if (!sX(RecordByteOffset64(CDF,Var, - Var->stage.firstRec, - &tOffset),&pStatus)) return pStatus; - nRecords = Var->stage.lastRec - Var->stage.firstRec + 1; - nBytes = nRecords * Var->NphyRecBytes; - if (!sX(CopyBytes64(CDF->stage.fp,Var->stage.areaOffset64, - SCRATCH_READ_ERROR,nBytes,CDF->fp, - tOffset,CDF_WRITE_ERROR),&pStatus)) return pStatus; - Var->maxWritten = MAXIMUM(Var->maxWritten,Var->stage.lastRec); - /************************************************************************ - * Clear the staging area control. - ************************************************************************/ - Var->stage.firstRec = NO_RECORD; - Var->stage.lastRec = NO_RECORD; - Var->stage.dotOffset64 = (OFF_T) NO_OFFSET64; - Var->stage.modified = FALSE; - break; - } - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: { - Int32 nRecords; - OFF_T cSize, xSize, irSize, uSize, newOffset; - struct CVVRstruct64 CVVR; struct VVRstruct64 VVR; struct AllocStruct alloc; - /************************************************************************ - * First check if there are records to be flushed in the staging area. - ************************************************************************/ - if (!Var->stage.modified) return pStatus; - /************************************************************************ - * Check if the scratch file is created/initialized. - ************************************************************************/ - if (!sX(InitScratch64(ScratchDirectory(CDF), - &(CDF->compressFp), - CDF->compressCacheSize),&pStatus)) return pStatus; - /************************************************************************ - * Compress the records in the stage. - ************************************************************************/ - nRecords = Var->stage.lastRec - Var->stage.firstRec + 1; - uSize = nRecords * Var->NphyRecBytes; - if (!sX(Compress64(CDF->stage.fp,Var->stage.areaOffset64, - uSize,SCRATCH_READ_ERROR,Var->cType, - Var->cParms,CDF->compressFp,(OFF_T) ZERO_OFFSET64, - &cSize,SCRATCH_WRITE_ERROR),&pStatus)) return pStatus; - /************************************************************************ - * Does a VVR/CVVR for this block of records already exist? - ************************************************************************/ - if (Var->stage.dotOffset64 != (OFF_T) NO_OFFSET64) { - /********************************************************************** - * Read the size of the existing VVR/CVVR. - **********************************************************************/ - if (!sX(ReadIrSize64(CDF->fp, - Var->stage.dotOffset64, - &irSize),&pStatus)) return pStatus; - /********************************************************************** - * Will a CVVR fit? Note that reserve space is only added to new CVVRs. - **********************************************************************/ - if (CVVR_BASE_SIZE64 + cSize <= irSize) { - LoadCVVRx64 (CVVR, irSize, cSize) - if (!sX(WriteCVVR64(CDF->fp,Var->stage.dotOffset64, - CVVR_RECORDx,&CVVR, - CVVR_NULL),&pStatus)) return pStatus; - if (!sX(CopyBytes64(CDF->compressFp,(OFF_T) ZERO_OFFSET64, - SCRATCH_READ_ERROR,cSize,CDF->fp, - Var->stage.dotOffset64 + CVVR_BASE_SIZE64, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - Var->stage.modified = FALSE; - return pStatus; - } - /********************************************************************** - * Will a VVR fit? - **********************************************************************/ - if (VVR_BASE_SIZE64 + uSize <= irSize) { - LoadVVRx64 (VVR, irSize) - if (!sX(WriteVVR64(CDF->fp,Var->stage.dotOffset64, - VVR_RECORDx,&VVR, - VVR_NULL),&pStatus)) return pStatus; - if (!sX(CopyBytes64(CDF->stage.fp,Var->stage.areaOffset64, - SCRATCH_READ_ERROR,uSize,CDF->fp, - Var->stage.dotOffset64 + VVR_BASE_SIZE64, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - Var->stage.modified = FALSE; - sX (DID_NOT_COMPRESS, &pStatus); - return pStatus; - } - /********************************************************************** - * The existing VVR/CVVR will have to be resized. Will a CVVR be - * smaller than a VVR? Note that reserve space is not added to the - * size of the CVVR because a new one isn't being created. - **********************************************************************/ - if (CVVR_BASE_SIZE64 + cSize < VVR_BASE_SIZE64 + uSize) { - if (!sX(ResizeIR64(CDF,Var->stage.dotOffset64, - CVVR_BASE_SIZE64 + cSize, - &newOffset,TRUE,NULL),&pStatus)) return pStatus; - LoadCVVRx64 (CVVR, CVVR_BASE_SIZE64 + cSize, cSize) - if (!sX(WriteCVVR64(CDF->fp,newOffset, - CVVR_RECORDx,&CVVR, - CVVR_NULL),&pStatus)) return pStatus; - if (!sX(CopyBytes64(CDF->compressFp,(OFF_T) ZERO_OFFSET64, - SCRATCH_READ_ERROR,cSize, - CDF->fp,newOffset + CVVR_BASE_SIZE64, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - } - else { - if (!sX(ResizeIR64(CDF,Var->stage.dotOffset64, - VVR_BASE_SIZE64 + uSize, - &newOffset,TRUE,NULL),&pStatus)) return pStatus; - LoadVVRx64 (VVR, VVR_BASE_SIZE64 + uSize) - if (!sX(WriteVVR64(CDF->fp,newOffset, - VVR_RECORDx,&VVR, - VVR_NULL),&pStatus)) return pStatus; - if (!sX(CopyBytes64(CDF->stage.fp,Var->stage.areaOffset64, - SCRATCH_READ_ERROR,uSize, - CDF->fp,newOffset + VVR_BASE_SIZE64, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - sX (DID_NOT_COMPRESS, &pStatus); - } - if (!sX(ModIndexOffset64(CDF,Var, - Var->stage.firstRec, - Var->stage.lastRec, - newOffset),&pStatus)) return pStatus; - Var->stage.dotOffset64 = newOffset; - Var->stage.modified = FALSE; - return pStatus; - } - /************************************************************************ - * A new VVR/CVVR will have to be created. First calculate the reserve - * size. - ************************************************************************/ - if (Var->reservePct <= 0) - xSize = 0; - else { - Int32 tSize; - if (Var->reservePct <= 100) { - tSize = (Int32) ((uSize * (Var->reservePct/100.0)) + 0.5); - xSize = MAXIMUM(cSize,tSize) - cSize; - } - else { - tSize = (Int32) ((cSize * (Var->reservePct/100.0)) + 0.5); - xSize = tSize - cSize; - } - } - /************************************************************************ - * Will a CVVR be smaller than a VVR? - ************************************************************************/ - if (CVVR_BASE_SIZE64 + cSize + xSize < VVR_BASE_SIZE64 + uSize) { - LoadAllocCVVR64 (alloc, Var->stage.firstRec, Var->stage.lastRec, - cSize, xSize) - if (!sX(AllocateRecords64(CDF,Var,alloc),&pStatus)) return pStatus; - if (!sX(SearchForRecord64(CDF,Var->VDRoffset64,Var->zVar, - Var->stage.firstRec,NULL,NULL, - &newOffset,NULL),&pStatus)) return pStatus; - LoadCVVRx64 (CVVR, CVVR_BASE_SIZE64 + cSize + xSize, cSize) - if (!sX(WriteCVVR64(CDF->fp,newOffset, - CVVR_RECORDx,&CVVR, - CVVR_NULL),&pStatus)) return pStatus; - if (!sX(CopyBytes64(CDF->compressFp,(OFF_T) ZERO_OFFSET64, - SCRATCH_READ_ERROR,cSize, - CDF->fp,newOffset + CVVR_BASE_SIZE64, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - Var->stage.dotOffset64 = newOffset; - Var->stage.modified = FALSE; - return pStatus; - } - /************************************************************************ - * The CVVR will be too big - create a VVR. - ************************************************************************/ - LoadAllocVVR64 (alloc, Var->stage.firstRec, Var->stage.lastRec, TRUE) - if (!sX(AllocateRecords64(CDF,Var,alloc),&pStatus)) return pStatus; - if (!sX(SearchForRecord64(CDF,Var->VDRoffset64,Var->zVar, - Var->stage.firstRec,NULL,NULL, - &newOffset,NULL),&pStatus)) return pStatus; - LoadVVRx64 (VVR, VVR_BASE_SIZE64 + uSize) - if (!sX(WriteVVR64(CDF->fp,newOffset, - VVR_RECORDx,&VVR, - VVR_NULL),&pStatus)) return pStatus; - if (!sX(CopyBytes64(CDF->stage.fp,Var->stage.areaOffset64, - SCRATCH_READ_ERROR,uSize, - CDF->fp,newOffset + VVR_BASE_SIZE64, - CDF_WRITE_ERROR),&pStatus)) return pStatus; - Var->stage.dotOffset64 = newOffset; - Var->stage.modified = FALSE; - sX (DID_NOT_COMPRESS, &pStatus); - return pStatus; - } - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* BringToStage. -******************************************************************************/ - -static CDFstatus BringToStage (CDF, Var, recNum, found) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 recNum; -Logical *found; -{ - CDFstatus pStatus = CDF_OK; - /**************************************************************************** - * First check if record is already in the stage. - ****************************************************************************/ - if (INCLUSIVE(Var->stage.firstRec,recNum,Var->stage.lastRec)) { - ASSIGNnotNULL (found, TRUE) - return pStatus; - } - /**************************************************************************** - * Then, based on variable type... - ****************************************************************************/ - switch (Var->vType) { - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: { - Int32 firstRec, lastRec, nRecords; OFF_T uSize; Logical foundX; - OFF_T offset; - /************************************************************************ - * Determine if the record exists. - ************************************************************************/ - if (!sX(SearchForRecord64(CDF,Var->VDRoffset64,Var->zVar, - recNum,&firstRec,&lastRec, - &offset,&foundX),&pStatus)) return pStatus; - ASSIGNnotNULL (found, foundX) - if (!foundX) return BOO(found == NULL,NO_SUCH_RECORD,pStatus); - /************************************************************************ - * Flush the stage before... - ************************************************************************/ - if (!sX(FlushStage64(CDF,Var),&pStatus)) return pStatus; - /************************************************************************ - * ...decompressing the CVVR (or VVR if the records did not compress) to - * the staging area. - ************************************************************************/ - nRecords = lastRec - firstRec + 1; - uSize = nRecords * Var->NphyRecBytes; - if (!sX(DecompressToStage64(CDF,Var, - offset,uSize),&pStatus)) return pStatus; - /************************************************************************ - * Update staging control. - ************************************************************************/ - Var->stage.firstRec = firstRec; - Var->stage.lastRec = lastRec; - Var->stage.dotOffset64 = offset; - Var->stage.modified = FALSE; - break; - } - default: - return CDF_INTERNAL_ERROR; - } - return pStatus; -} - -/****************************************************************************** -* CopyBytes64. -******************************************************************************/ - -STATICforIDL CDFstatus CopyBytes64 (iFp, iStart, iError, nBytes, oFp, oStart, - oError) -vFILE *iFp; -OFF_T iStart; -CDFstatus iError; -OFF_T nBytes; -vFILE *oFp; -OFF_T oStart; -CDFstatus oError; -{ - Int32 nBlocks = (Int32) (nBytes / COPYblockSIZE); /* Number of full blocks - that can be copied. */ - Int32 lastCount = (Int32) (nBytes % COPYblockSIZE); /* Number of bytes - remaining to be copied - after the full blocks - have been copied. */ - Int32 i; Byte1 buffer[COPYblockSIZE]; - /**************************************************************************** - * If the copy is within the same file... - ****************************************************************************/ - if (iFp == oFp) { - /************************************************************************** - * If the input group (of bytes) is before the output group start at the - * end in case they overlap. - **************************************************************************/ - if (iStart < oStart) { - if (nBlocks > 0) { - OFF_T iOffset = iStart + (OFF_T) (nBytes - COPYblockSIZE); - OFF_T oOffset = oStart + (OFF_T) (nBytes - COPYblockSIZE); - for (i = 0; i < nBlocks; i++) { - if (!SEEKv64(iFp,iOffset,vSEEK_SET)) return iError; - if (!READv64(buffer,(size_t)COPYblockSIZE,(size_t)1,iFp)) return - iError; - if (!SEEKv64(oFp,oOffset,vSEEK_SET)) return oError; - if (!WRITEv64(buffer,(size_t)COPYblockSIZE,(size_t)1,oFp)) return - oError; - iOffset -= (OFF_T) COPYblockSIZE; - oOffset -= (OFF_T) COPYblockSIZE; - } - } - if (lastCount > 0) { - if (!SEEKv64(iFp,iStart,vSEEK_SET)) return iError; - if (!READv64(buffer,(size_t)lastCount,(size_t)1,iFp)) return iError; - if (!SEEKv64(oFp,oStart,vSEEK_SET)) return oError; - if (!WRITEv64(buffer,(size_t)lastCount,(size_t)1,oFp)) return oError; - } - } - /************************************************************************** - * If the input group (of bytes) is after the output group start at the - * beginning in case they overlap. - **************************************************************************/ - if (iStart > oStart) { - OFF_T iOffset = iStart; - OFF_T oOffset = oStart; - if (nBlocks > 0) { - for (i = 0; i < nBlocks; i++) { - if (!SEEKv64(iFp,iOffset,vSEEK_SET)) return iError; - if (!READv64(buffer,(size_t)COPYblockSIZE,(size_t)1,iFp)) return - iError; - if (!SEEKv64(oFp,oOffset,vSEEK_SET)) return oError; - if (!WRITEv64(buffer,(size_t)COPYblockSIZE,(size_t)1,oFp)) return - oError; - iOffset += (OFF_T) COPYblockSIZE; - oOffset += (OFF_T) COPYblockSIZE; - } - } - if (lastCount > 0) { - if (!SEEKv64(iFp,iOffset,vSEEK_SET)) return iError; - if (!READv64(buffer,(size_t)lastCount,(size_t)1,iFp)) return iError; - if (!SEEKv64(oFp,oOffset,vSEEK_SET)) return oError; - if (!WRITEv64(buffer,(size_t)lastCount,(size_t)1,oFp)) return oError; - } - } - /************************************************************************** - * Offsets are the same - do nothing. - **************************************************************************/ - } - else { - /************************************************************************** - * Different files... - **************************************************************************/ - if (!SEEKv64(iFp,iStart,vSEEK_SET)) return iError; - if (!SEEKv64(oFp,oStart,vSEEK_SET)) return oError; - for (i = 0; i < nBlocks; i++) { - if (!READv64(buffer,(size_t)COPYblockSIZE,(size_t)1,iFp)) return iError; - if (!WRITEv64(buffer,(size_t)COPYblockSIZE,(size_t)1,oFp)) return oError; - } - if (lastCount > 0) { - if (!READv64(buffer,(size_t)lastCount,(size_t)1,iFp)) return iError; - if (!WRITEv64(buffer,(size_t)lastCount,(size_t)1,oFp)) return oError; - } - } - return CDF_OK; -} - -/****************************************************************************** -* ModIndexOffset64. -******************************************************************************/ - -STATICforIDL CDFstatus ModIndexOffset64 (CDF, Var, firstRec, lastRec, newOffset) -struct CDFstruct *CDF; /* Pointer to CDF. */ -struct VarStruct *Var; /* Pointer to variable. */ -Int32 firstRec; /* First record of entry. */ -Int32 lastRec; /* Last record of entry. */ -OFF_T newOffset; /* New VVR/CVVR/SVVR offset. */ -{ - CDFstatus pStatus = CDF_OK; OFF_T vxrOffset; - /**************************************************************************** - * Read offset of first VXR... - ****************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_VXRHEAD,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - /**************************************************************************** - * ...and start there. - ****************************************************************************/ - if (!sX(ModIndexOffset_r_64(CDF->fp,vxrOffset, - firstRec,lastRec, - newOffset),&pStatus)) return pStatus; - return pStatus; -} - -static CDFstatus ModIndexOffset_r_64 (fp, vxrOffset, firstRec, lastRec, newOffset) -vFILE *fp; /* File pointer to dotCDF file. */ -OFF_T vxrOffset; /* VXR at which to start. */ -Int32 firstRec; /* First record of entry. */ -Int32 lastRec; /* Last record of entry. */ -OFF_T newOffset; /* New VVR/CVVR/SVVR offset. */ -{ - CDFstatus pStatus = CDF_OK; - struct VXRstruct64 VXR; int entryN; Int32 irType; - /**************************************************************************** - * While more VXRs... - ****************************************************************************/ - while (vxrOffset != (OFF_T) ZERO_OFFSET64) { - /************************************************************************** - * Read the VXR. - **************************************************************************/ - if (!sX(ReadVXR64(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************** - * Search through index entries... - **************************************************************************/ - for (entryN = 0; entryN < VXR.NusedEntries; entryN++) { - if (VXR.First[entryN] <= firstRec && lastRec <= VXR.Last[entryN]) { - if (!sX(ReadIrType64(fp, - VXR.Offset[entryN], - &irType),&pStatus)) return pStatus; - if (irType == VXR_) return ModIndexOffset_r_64(fp,VXR.Offset[entryN], - firstRec,lastRec, - newOffset); - if (VXR.First[entryN] == firstRec && lastRec == VXR.Last[entryN]) { - VXR.Offset[entryN] = newOffset; - if (!sX(WriteVXR64(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - return pStatus; - } - return CDF_INTERNAL_ERROR; /* or CORRUPTED_V3_CDF? */ - } - } - /************************************************************************** - * Go to next VXR. - **************************************************************************/ - vxrOffset = VXR.VXRnext; - } - /**************************************************************************** - * No more VXRs. - ****************************************************************************/ - return CDF_INTERNAL_ERROR; -} - -/****************************************************************************** -* WriteCompressedRecords. -******************************************************************************/ - -static CDFstatus WriteCompressedRecords (CDF, Var, firstRec, lastRec, buffer, - nValues, offset, fullRecord) -struct CDFstruct *CDF; /* Pointer to CDF. */ -struct VarStruct *Var; /* Pointer to variable. */ -Int32 firstRec; /* First record being written. */ -Int32 lastRec; /* Last record being written. */ -void *buffer; /* Buffer of values. */ -OFF_T nValues; /* Number of values being written. */ -OFF_T offset; /* If not full record(s), byte offset in record at - which to write. */ -Logical fullRecord; /* Full record(s) being written? */ -{ - CDFstatus pStatus = CDF_OK; Logical found; - Int32 recCount, recordOffsetInStage, maxRecThisBlock; - Int32 nextRec, writeTo; void *padBuffer; int how; - Int32 recNum = firstRec; Byte1 *tBuffer = (Byte1 *) buffer; - OFF_T tOffset, numElems; - /**************************************************************************** - * From first to last record... - ****************************************************************************/ - while (recNum <= lastRec) { - /************************************************************************* - * Check if this record is in the staging area. - *************************************************************************/ - if (INCLUSIVE(Var->stage.firstRec,recNum,Var->stage.lastRec)) { - recordOffsetInStage = recNum - Var->stage.firstRec; - tOffset = Var->stage.areaOffset64; - tOffset += (recordOffsetInStage * Var->NphyRecBytes); - if (fullRecord) { - if (Var->stage.dotOffset64 == (OFF_T) NO_OFFSET64) { - maxRecThisBlock = Var->stage.firstRec + Var->blockingFactor - 1; - if (!sX(NextRecord64(CDF,Var->VDRoffset64, - Var->zVar,recNum, - &nextRec,&found),&pStatus)) return pStatus; - if (!found) - writeTo = MINIMUM(maxRecThisBlock,lastRec); - else { - Int32 prevRecN = nextRec - 1; - writeTo = MINIMUMof3(maxRecThisBlock,prevRecN,lastRec); - } - } - else - writeTo = MINIMUM(Var->stage.lastRec,lastRec); - recCount = writeTo - recNum + 1; - numElems = (OFF_T) recCount * Var->NphyRecElems; - } - else { - writeTo = recNum; - recCount = 1; - numElems = nValues * Var->NvalueElems; - tOffset += offset; - } - if (!sX(WriteVarElems64(Var,CDF->stage.fp, - tOffset,numElems, - tBuffer),&pStatus)) return pStatus; - Var->stage.lastRec = MAXIMUM(Var->stage.lastRec,writeTo); - Var->stage.modified = TRUE; - tBuffer += (size_t) (numElems * Var->NelemBytes); - recNum += recCount; - continue; - } - /************************************************************************* - * Not in the staging area...check if this record is in an existing CVVR. - *************************************************************************/ - if (!sX(BringToStage(CDF,Var,recNum,&found),&pStatus)) return pStatus; - if (found) { - recordOffsetInStage = recNum - Var->stage.firstRec; - tOffset = Var->stage.areaOffset64; - tOffset += (recordOffsetInStage * Var->NphyRecBytes); - if (fullRecord) { - writeTo = MINIMUM(Var->stage.lastRec,lastRec); - recCount = writeTo - recNum + 1; - numElems = (OFF_T) recCount * Var->NphyRecElems; - } - else { - writeTo = recNum; - recCount = 1; - numElems = nValues * Var->NvalueElems; - tOffset += offset; - } - if (!sX(WriteVarElems64(Var,CDF->stage.fp, - tOffset,numElems, - tBuffer),&pStatus)) return pStatus; - Var->stage.modified = TRUE; - tBuffer += (size_t) (numElems * Var->NelemBytes); - recNum += recCount; - continue; - } - /************************************************************************* - * Not in an existing CVVR...this record does not exist. First check - * if the record(s) can be added to the records in the stage. - *************************************************************************/ - if (Var->stage.firstRec != NO_RECORD) { - if (Var->stage.dotOffset64 == (OFF_T) NO_OFFSET64) { - if (recNum == Var->stage.lastRec + 1) { - maxRecThisBlock = Var->stage.firstRec + Var->blockingFactor - 1; - if (recNum <= maxRecThisBlock) { - recordOffsetInStage = recNum - Var->stage.firstRec; - tOffset = Var->stage.areaOffset64; - tOffset += (recordOffsetInStage * Var->NphyRecBytes); - if (fullRecord) { - if (!sX(NextRecord64(CDF,Var->VDRoffset64, - Var->zVar,recNum, - &nextRec,&found),&pStatus)) return pStatus; - if (!found) - writeTo = MINIMUM(maxRecThisBlock,lastRec); - else { - Int32 prevRecN = nextRec - 1; - writeTo = MINIMUMof3(maxRecThisBlock,prevRecN,lastRec); - } - recCount = writeTo - recNum + 1; - numElems = (OFF_T) recCount * Var->NphyRecElems; - } - else { - if (!sX(BuildPadBuffer64(CDF,Var,INT32_ONE, - &how,&padBuffer, - TRUE),&pStatus)) return pStatus; - if (!sX(WritePadValues64(Var,CDF->stage.fp, - tOffset,INT32_ONE,how, - padBuffer),&pStatus)) { - cdf_FreeMemory (padBuffer, NULL); - return pStatus; - } - cdf_FreeMemory (padBuffer, NULL); - writeTo = recNum; - recCount = 1; - numElems = nValues * Var->NvalueElems; - tOffset += offset; - } - if (!sX(WriteVarElems64(Var,CDF->stage.fp, - tOffset,numElems, - tBuffer),&pStatus)) return pStatus; - Var->stage.lastRec = MAXIMUM(Var->stage.lastRec,writeTo); - Var->stage.modified = TRUE; - tBuffer += (size_t) (numElems * Var->NelemBytes); - recNum += recCount; - continue; - } - } - } - } - /************************************************************************* - * This record cannot be added to the block of records currently in - * the staging area. Start a new block of records. - *************************************************************************/ - if (!sX(FlushStage64(CDF,Var),&pStatus)) return pStatus; - tOffset = Var->stage.areaOffset64; - if (fullRecord) { - maxRecThisBlock = recNum + Var->blockingFactor - 1; - if (!sX(NextRecord64(CDF,Var->VDRoffset64,Var->zVar, - recNum,&nextRec,&found),&pStatus)) return pStatus; - if (!found) - writeTo = MINIMUM(maxRecThisBlock,lastRec); - else { - Int32 prevRecN = nextRec - 1; - writeTo = MINIMUMof3(maxRecThisBlock,prevRecN,lastRec); - } - recCount = writeTo - recNum + 1; - numElems = (OFF_T) recCount * Var->NphyRecElems; - } - else { - if (!sX(BuildPadBuffer64(CDF,Var,INT32_ONE, - &how,&padBuffer, - TRUE),&pStatus)) return pStatus; - if (!sX(WritePadValues64(Var,CDF->stage.fp, - tOffset,INT32_ONE,how, - padBuffer),&pStatus)) { - cdf_FreeMemory (padBuffer, NULL); - return pStatus; - } - cdf_FreeMemory (padBuffer, NULL); - writeTo = recNum; - recCount = 1; - numElems = nValues * Var->NvalueElems; - tOffset += offset; - } - if (!sX(WriteVarElems64(Var,CDF->stage.fp, - tOffset,numElems, - tBuffer),&pStatus)) return pStatus; - Var->stage.firstRec = recNum; - Var->stage.lastRec = writeTo; - Var->stage.dotOffset64 = (OFF_T) NO_OFFSET64; - Var->stage.modified = TRUE; - tBuffer += (size_t) (numElems * Var->NelemBytes); - recNum += recCount; - } - return pStatus; -} - -/****************************************************************************** -* CalcCompressionPct64. -******************************************************************************/ - -STATICforIDL CDFstatus CalcCompressionPct64 (CDF, vdrOffset, zVar, cPct) -struct CDFstruct *CDF; -OFF_T vdrOffset; -Logical zVar; -long *cPct; -{ - CDFstatus pStatus = CDF_OK; OFF_T vxrOffset; - OFF_T uTotal = 0, cTotal = 0; Int32 nPhyRecBytes; - /**************************************************************************** - * Calculate the number of bytes per physical record. - ****************************************************************************/ - if (!sX(CalcPhyRecBytes64(CDF,vdrOffset, - zVar,&nPhyRecBytes),&pStatus)) return pStatus; - /**************************************************************************** - * Read the offset of the first VXR (return 0% if no VXRs)... - ****************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,vdrOffset,zVar, - VDR_VXRHEAD,&vxrOffset, - VDR_NULL),&pStatus)) return pStatus; - if (vxrOffset == (OFF_T) ZERO_OFFSET64) { - *cPct = 0; - return pStatus; - } - /**************************************************************************** - * ...and start there. - ****************************************************************************/ - if (!sX(CalcCompressionPct_r_64(CDF->fp,vxrOffset, - nPhyRecBytes, - &uTotal,&cTotal),&pStatus)) return pStatus; - /**************************************************************************** - * Calculate percentage. - ****************************************************************************/ - *cPct = (long) (((100.0*cTotal) / uTotal) + 0.5); - return pStatus; -} - -static CDFstatus CalcCompressionPct_r_64 (fp, vxrOffset, nPhyRecBytes, uTotal, - cTotal) -vFILE *fp; -OFF_T vxrOffset; -Int32 nPhyRecBytes; -OFF_T *uTotal; -OFF_T *cTotal; -{ - CDFstatus pStatus = CDF_OK; struct VXRstruct64 VXR; int entryN; - Int32 nRecords, irType; OFF_T uSize, irSize; - /**************************************************************************** - * While more VXRs... - ****************************************************************************/ - while (vxrOffset != (OFF_T) ZERO_OFFSET64) { - /************************************************************************** - * Read the VXR. - **************************************************************************/ - if (!sX(ReadVXR64(fp,vxrOffset, - VXR_RECORD,&VXR, - VXR_NULL),&pStatus)) return pStatus; - /************************************************************************** - * Scan entries... - **************************************************************************/ - for (entryN = 0; entryN < VXR.NusedEntries; entryN++) { - if (!sX(ReadIrType64(fp,VXR.Offset[entryN],&irType),&pStatus)) return - pStatus; - switch (irType) { - case VXR_: - if (!sX(CalcCompressionPct_r_64(fp,VXR.Offset[entryN], - nPhyRecBytes,uTotal, - cTotal),&pStatus)) return pStatus; - break; - case VVR_: - case CVVR_: - /******************************************************************* - * Accumulate uncompressed size. - *******************************************************************/ - nRecords = VXR.Last[entryN] - VXR.First[entryN] + 1; - uSize = nRecords * nPhyRecBytes; - *uTotal += uSize; - /******************************************************************* - * Accumulate compressed size. - *******************************************************************/ - if (!sX(ReadIrSize64(fp,VXR.Offset[entryN],&irSize),&pStatus)) - return pStatus; - *cTotal += irSize - BOO(irType == CVVR_, - CVVR_BASE_SIZE64, - VVR_BASE_SIZE64); - break; - default: - return CORRUPTED_V3_CDF; - } - } - vxrOffset = VXR.VXRnext; - } - return pStatus; -} - -/****************************************************************************** -* CalcPhyRecBytes64. -******************************************************************************/ - -STATICforIDL CDFstatus CalcPhyRecBytes64 (CDF, vdrOffset, zVar, nPhyRecBytes) -struct CDFstruct *CDF; -OFF_T vdrOffset; -Logical zVar; -Int32 *nPhyRecBytes; -{ - CDFstatus pStatus = CDF_OK; int dimN; Int32 dataType, numElems; - Int32 numDims, dimSizes[CDF_MAX_DIMS], dimVarys[CDF_MAX_DIMS]; - if (!sX(CalcDimParms64(CDF,vdrOffset,zVar, - &numDims,dimSizes,dimVarys),&pStatus)) return pStatus; - if (!sX(ReadVDR64(CDF,CDF->fp,vdrOffset,zVar, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_NULL),&pStatus)) return pStatus; - *nPhyRecBytes = (Int32) CDFelemSize((long)dataType) * numElems; - for (dimN = 0; dimN < numDims; dimN++) { - if (dimVarys[dimN]) *nPhyRecBytes *= dimSizes[dimN]; - } - return pStatus; -} - -/****************************************************************************** -* ReadSparseFull. -******************************************************************************/ - -static CDFstatus ReadSparseFull (CDF, Var, firstRec, lastRec, buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 firstRec; -Int32 lastRec; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; Logical found; - Int32 readTo, recCount, recX, prevRecN; - Int32 nextRec, padTo; OFF_T tOffset, nPadValues, numElems; - Int32 recNum = firstRec; - Byte1 *tBuffer = (Byte1 *) buffer; - /**************************************************************************** - * While there are more records to be read/generated... - ****************************************************************************/ - while (recNum <= lastRec) { - /************************************************************************** - * Is the record in the staging area? - **************************************************************************/ - if (INCLUSIVE(Var->stage.firstRec,recNum,Var->stage.lastRec)) { - readTo = MINIMUM(Var->stage.lastRec,lastRec); - recCount = readTo - recNum + 1; - numElems = (OFF_T) recCount * Var->NphyRecElems; - recX = recNum - Var->stage.firstRec; - tOffset = Var->stage.areaOffset64 + (OFF_T) (recX * Var->NphyRecBytes); - if (!sX(ReadVarElems64(Var,CDF->stage.fp, - tOffset,numElems,tBuffer),&pStatus)) return pStatus; - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - continue; - } - /************************************************************************** - * Does the record exist and has been written to (not just allocated)? - **************************************************************************/ - if (recNum <= Var->maxRec) { - Int32 firstRecInVVR, lastRecInVVR; - if (!sX(SearchForRecord64(CDF,Var->VDRoffset64, - Var->zVar,recNum, - &firstRecInVVR, - &lastRecInVVR, - &tOffset,&found),&pStatus)) return pStatus; - if (found) { - readTo = MINIMUMof3(Var->maxRec,lastRec,lastRecInVVR); - recCount = readTo - recNum + 1; - numElems = (OFF_T) recCount * Var->NphyRecElems; - recX = recNum - firstRecInVVR; - tOffset += VVR_BASE_SIZE64 + (OFF_T) (recX * Var->NphyRecBytes); - if (!sX(ReadVarElems64(Var,CDF->fp,tOffset, - numElems,tBuffer),&pStatus)) return pStatus; - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - continue; - } - } - /************************************************************************** - * Determine which records need to be padded. - **************************************************************************/ - if (recNum <= Var->maxRec) { - if (!sX(NextRecord64(CDF,Var->VDRoffset64,Var->zVar, - recNum,&nextRec,&found),&pStatus)) return pStatus; - if (found) { - if (EXCLUSIVE(recNum, - Var->stage.firstRec, - nextRec)) nextRec = Var->stage.firstRec; - prevRecN = nextRec - 1; - padTo = MINIMUM(prevRecN,lastRec); - } - else { - prevRecN = Var->stage.firstRec - 1; - padTo = MINIMUM(prevRecN,lastRec); - } - } - else - padTo = lastRec; - recCount = padTo - recNum + 1; - /************************************************************************** - * If sRecords.PREV... - **************************************************************************/ - if (Var->prevIfMissing) { - Int32 prevRec; Byte1 *destBuffer; - if (!sX(PrevRecord64(CDF,Var->VDRoffset64,Var->zVar, - MINIMUM(recNum,Var->maxRec), - &prevRec,&found),&pStatus)) return pStatus; - if (found) { - if (EXCLUSIVE(prevRec,Var->stage.lastRec,recNum)) { - recX = Var->stage.lastRec - Var->stage.firstRec; - tOffset = Var->stage.areaOffset64 + (OFF_T) (recX * Var->NphyRecBytes); - if (!sX(ReadVarElems64(Var,CDF->stage.fp, - tOffset,Var->NphyRecElems, - tBuffer),&pStatus)) return pStatus; - } - else { - if (!sX(RecordByteOffset64(CDF,Var, - prevRec, - &tOffset),&pStatus)) return pStatus; - if (!sX(ReadVarElems64(Var,CDF->fp,tOffset, - Var->NphyRecElems, - tBuffer),&pStatus)) return pStatus; - } - destBuffer = tBuffer + ((size_t) Var->NphyRecBytes); - for (recX = 1; recX < recCount; recX++) { - memmove (destBuffer, tBuffer, (size_t) Var->NphyRecBytes); - destBuffer += (size_t) Var->NphyRecBytes; - } - sX (VIRTUAL_RECORD_DATA, &pStatus); - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - continue; - } - if (EXCLUSIVE(NO_RECORD,Var->stage.lastRec,recNum)) { - recX = Var->stage.lastRec - Var->stage.firstRec; - tOffset = Var->stage.areaOffset64 + (OFF_T) (recX * Var->NphyRecBytes); - if (!sX(ReadVarElems64(Var,CDF->stage.fp, - tOffset,Var->NphyRecElems, - tBuffer),&pStatus)) return pStatus; - destBuffer = tBuffer + ((size_t) Var->NphyRecBytes); - for (recX = 1; recX < recCount; recX++) { - memmove (destBuffer, tBuffer, (size_t) Var->NphyRecBytes); - destBuffer += (size_t) Var->NphyRecBytes; - } - sX (VIRTUAL_RECORD_DATA, &pStatus); - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - continue; - } - } - /************************************************************************** - * Pad with the variable's pad value. This occurs if the variable is - * sRecords.NO, sRecords.PAD, or if sRecords.PREV but a previous record - * does not exist (in a VVR or the staging area). - **************************************************************************/ - nPadValues = (OFF_T) recCount * Var->NphyRecValues; - if (!sX(PadBuffer64(CDF,Var,nPadValues,tBuffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - } - return pStatus; -} - -/****************************************************************************** -* ReadSparsePartial. -******************************************************************************/ - -static CDFstatus ReadSparsePartial (CDF, Var, recNum, offset, nValues, buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 recNum; -OFF_T offset; -OFF_T nValues; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; Logical found; - Int32 firstRec, prevRec; OFF_T tOffset; - OFF_T numElems = nValues * Var->NvalueElems; - /**************************************************************************** - * If the record is in the staging area... - ****************************************************************************/ - if (INCLUSIVE(Var->stage.firstRec,recNum,Var->stage.lastRec)) { - tOffset = Var->stage.areaOffset64; - tOffset += (OFF_T) (Var->NphyRecBytes * (recNum - Var->stage.firstRec)); - tOffset += offset; - if (!sX(ReadVarElems64(Var,CDF->stage.fp, - tOffset,numElems,buffer),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * If the record exists and has been written (ie. not just allocated)... - ****************************************************************************/ - if (recNum <= Var->maxRec) { - if (!sX(SearchForRecord64(CDF,Var->VDRoffset64, - Var->zVar,recNum,&firstRec, - NULL,&tOffset,&found),&pStatus)) return pStatus; - if (found) { - tOffset += (OFF_T) VVR_BASE_SIZE64; - tOffset += (OFF_T) Var->NphyRecBytes * (recNum - firstRec); - tOffset += offset; - if (!sX(ReadVarElems64(Var,CDF->fp, - tOffset,numElems,buffer),&pStatus)) return pStatus; - return pStatus; - } - } - /**************************************************************************** - * If missing records are to be read from the previous record... - ****************************************************************************/ - if (Var->prevIfMissing) { - /************************************************************************** - * Check if a previous record exists in a VVR. - **************************************************************************/ - if (!sX(PrevRecord64(CDF,Var->VDRoffset64,Var->zVar, - MINIMUM(recNum,Var->maxRec), - &prevRec,&found),&pStatus)) return pStatus; - /************************************************************************** - * If so, also make sure that the last record in the staging area isn't - * really the previous record to use. - **************************************************************************/ - if (found) { - if (EXCLUSIVE(prevRec,Var->stage.lastRec,recNum)) { - Int32 recNumInStage = Var->stage.lastRec - Var->stage.firstRec; - tOffset = Var->stage.areaOffset64; - tOffset += (OFF_T) Var->NphyRecBytes * recNumInStage; - tOffset += offset; - if (!sX(ReadVarElems64(Var,CDF->stage.fp,tOffset, - numElems,buffer),&pStatus)) return pStatus; - } - else { - if (!sX(RecordByteOffset64(CDF,Var, - prevRec, - &tOffset),&pStatus)) return pStatus; - tOffset += offset; - if (!sX(ReadVarElems64(Var,CDF->fp,tOffset, - numElems,buffer),&pStatus)) return pStatus; - } - sX (VIRTUAL_RECORD_DATA, &pStatus); - return pStatus; - } - /************************************************************************** - * A previous record does not exist in a VVR...check if the last record in - * the staging area is the previous record. - **************************************************************************/ - if (EXCLUSIVE(NO_RECORD,Var->stage.lastRec,recNum)) { - Int32 recNumInStage = Var->stage.lastRec - Var->stage.firstRec; - tOffset = Var->stage.areaOffset64; - tOffset += (OFF_T) Var->NphyRecBytes * recNumInStage; - tOffset += offset; - if (!sX(ReadVarElems64(Var,CDF->stage.fp, - tOffset,numElems,buffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - return pStatus; - } - } - /**************************************************************************** - * Pad the buffer with the variable's pad value. Note that this is also done - * if the variable is sRecords.PREV but a previous record does not exist. - ****************************************************************************/ - if (!sX(PadBuffer64(CDF,Var,nValues,buffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - return pStatus; -} - -/****************************************************************************** -* ReadCompressedFull. -******************************************************************************/ - -static CDFstatus ReadCompressedFull (CDF, Var, firstRec, lastRec, buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 firstRec; -Int32 lastRec; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; Logical found; - Int32 readTo, recCount, recX, nextRec; - Int32 recNum = firstRec, prevRec, padTo; - Byte1 *tBuffer = (Byte1 *) buffer, *destBuffer; - OFF_T tOffset, nPadValues, numElems; - /**************************************************************************** - * While there are more records to be read/generated... - ****************************************************************************/ - while (recNum <= lastRec) { - /************************************************************************** - * Try to bring the record to the staging area. - **************************************************************************/ - if (!sX(BringToStage(CDF,Var,recNum,&found),&pStatus)) return pStatus; - if (found) { - readTo = MINIMUM(Var->stage.lastRec,lastRec); - recCount = readTo - recNum + 1; - numElems = (OFF_T) recCount * Var->NphyRecElems; - recX = recNum - Var->stage.firstRec; - tOffset = Var->stage.areaOffset64 + (OFF_T) (recX * Var->NphyRecBytes); - if (!sX(ReadVarElems64(Var,CDF->stage.fp, - tOffset,numElems,tBuffer),&pStatus)) return pStatus; - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - continue; - } - /************************************************************************** - * Determine which records need to be padded. - **************************************************************************/ - if (!sX(NextRecord64(CDF,Var->VDRoffset64,Var->zVar, - recNum,&nextRec,&found),&pStatus)) return pStatus; - if (found) { - if (EXCLUSIVE(recNum, - Var->stage.firstRec, - nextRec)) nextRec = Var->stage.firstRec; - prevRec = nextRec - 1; - padTo = MINIMUM(prevRec,lastRec); - } - else - padTo = BOO(Var->stage.firstRec > recNum, - Var->stage.firstRec - 1,lastRec); - recCount = padTo - recNum + 1; - /************************************************************************** - * If sRecords.PREV... - **************************************************************************/ - if (Var->prevIfMissing) { - if (!sX(PrevRecord64(CDF,Var->VDRoffset64,Var->zVar, - recNum,&prevRec,&found),&pStatus)) return pStatus; - if (!found) prevRec = NO_RECORD; - if (EXCLUSIVE(prevRec, - Var->stage.lastRec, - recNum)) prevRec = Var->stage.lastRec; - if (prevRec > NO_RECORD) { - if (!sX(BringToStage(CDF,Var,prevRec,NULL),&pStatus)) return pStatus; - recX = prevRec - Var->stage.firstRec; - tOffset = Var->stage.areaOffset64 + (OFF_T) (recX * Var->NphyRecBytes); - if (!sX(ReadVarElems64(Var,CDF->stage.fp, - tOffset,Var->NphyRecElems, - tBuffer),&pStatus)) return pStatus; - destBuffer = tBuffer + ((size_t) Var->NphyRecBytes); - for (recX = 1; recX < recCount; recX++) { - memmove (destBuffer, tBuffer, (size_t) Var->NphyRecBytes); - destBuffer += (size_t) Var->NphyRecBytes; - } - sX (VIRTUAL_RECORD_DATA, &pStatus); - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - continue; - } - } - /************************************************************************** - * Pad with the variable's pad value. This occurs if the variable is - * sRecords.NO, sRecords.PAD, or if sRecords.PREV but a previous record - * does not exist (in a CVVR/VVR or the staging area). - **************************************************************************/ - nPadValues = (OFF_T) recCount * Var->NphyRecValues; - if (!sX(PadBuffer64(CDF,Var,nPadValues,tBuffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - tBuffer += (size_t) (recCount * Var->NphyRecBytes); - recNum += recCount; - } - return pStatus; -} - -/****************************************************************************** -* ReadCompressedPartial. -******************************************************************************/ - -static CDFstatus ReadCompressedPartial (CDF, Var, recNum, offset, nValues, - buffer) -struct CDFstruct *CDF; -struct VarStruct *Var; -Int32 recNum; -OFF_T offset; -OFF_T nValues; -void *buffer; -{ - CDFstatus pStatus = CDF_OK; - OFF_T numElems = (OFF_T) nValues * Var->NvalueElems; - Int32 prevRec, recX; Logical found; - OFF_T tOffset; - /**************************************************************************** - * Try to bring the record to the staging area. - ****************************************************************************/ - if (!sX(BringToStage(CDF,Var,recNum,&found),&pStatus)) return pStatus; - if (found) { - tOffset = Var->stage.areaOffset64; - tOffset += (OFF_T) Var->NphyRecBytes * (recNum - Var->stage.firstRec); - tOffset += offset; - if (!sX(ReadVarElems64(Var,CDF->stage.fp, - tOffset,numElems,buffer),&pStatus)) return pStatus; - return pStatus; - } - /**************************************************************************** - * If sRecords.PREV... - ****************************************************************************/ - if (Var->prevIfMissing) { - if (!sX(PrevRecord64(CDF,Var->VDRoffset64, - Var->zVar,recNum, - &prevRec,&found),&pStatus)) return pStatus; - if (!found) prevRec = NO_RECORD; - if (EXCLUSIVE(prevRec, - Var->stage.lastRec, - recNum)) prevRec = Var->stage.lastRec; - if (prevRec > NO_RECORD) { - if (!sX(BringToStage(CDF,Var,prevRec,NULL),&pStatus)) return pStatus; - recX = Var->stage.lastRec - Var->stage.firstRec; - tOffset = Var->stage.areaOffset64 + (OFF_T) (Var->NphyRecBytes * recX) + - offset; - if (!sX(ReadVarElems64(Var,CDF->stage.fp, - tOffset,numElems,buffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - return pStatus; - } - } - /**************************************************************************** - * Pad the buffer with the variable's pad value. Note that this is also done - * if the variable is sRecords.PREV but a previous record does not exist. - ****************************************************************************/ - if (!sX(PadBuffer64(CDF,Var,nValues,buffer),&pStatus)) return pStatus; - sX (VIRTUAL_RECORD_DATA, &pStatus); - return pStatus; -} - -/****************************************************************************** -* CheckLFS. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus CheckLFS (CDFname, isLFS, CDFfullName) -char *CDFname; -Logical *isLFS; -char *CDFfullName; -{ - CDFstatus pStatus = CDF_OK; -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - int fp; -#else - FILE *fp; -#endif - Int32 temp, magicNumber1; - OFF_T length64 = (OFF_T) 0; - Logical upper_case_ext, version_numbers, no_append; - char CDFpathX[DU_MAX_PATH_LEN+1], CDFpathT[DU_MAX_PATH_LEN+1]; - size_t pathLen; - - if (CDFfullName != NULL) strcpyX (CDFfullName, CDFname, DU_MAX_PATH_LEN); - /************************************************************************** - * Open CDF file. - **************************************************************************/ - if (strlen(CDFname) > (size_t) CDF_PATHNAME_LEN) { - if (!sX(CDF_NAME_TRUNC,&pStatus)) return pStatus; - } - strcpyX (CDFpathT, CDFname, DU_MAX_PATH_LEN); -#if STRIP_TRAILING_BLANKS_FROM_CDFPATH - StripTrailingBlanks (CDFpathT); -#endif -#if defined(vms) || defined(dos) - MakeUpperString (CDFpathT); -#endif -/* if (!ValidCDFname(CDFpathT)) return BAD_CDF_NAME; */ - if (!sX(FindCDF(CDFpathT,&no_append, - &upper_case_ext, - &version_numbers),&pStatus)) return pStatus; - pathLen = strlen(CDFpathT); - if (((pathLen > 4) && StrStrIgCaseX(CDFpathT+(pathLen-4), ".cdf")) || - ((pathLen > 6) && StrStrIgCaseX(CDFpathT+(pathLen-6), ".cdf;1"))) - strcpyX (CDFpathX, CDFpathT, DU_MAX_PATH_LEN); - else - BuildFilePath (CDFt, CDFpathT, no_append, upper_case_ext, version_numbers, - INT32_ZERO, CDFpathX); -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - fp = FOPEN64 (CDFpathX, _O_RDONLY); - if (fp == EOF) return CDF_OPEN_ERROR; -#else - fp = (FILE *) FOPEN64 (CDFpathX, READ_ONLY_a_mode); - if (fp == NULL) return CDF_OPEN_ERROR; -#endif - if (FSEEK64(fp,(OFF_T)0,vSEEK_END) == EOF) { - FCLOSE64 (fp); - return CDF_OPEN_ERROR; - } - length64 = FTELL64 (fp); - if (length64 == 0) /* A new one... Must be a LFS. */ - *isLFS = TRUE; - else { /* Existing one... Check its magic number at the 1st 4-byte. */ - if (FSEEK64(fp,0,vSEEK_SET) == EOF) return CDF_OPEN_ERROR; -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (FREAD64(fp,&magicNumber1,(unsigned int)4) != 4) -#else - if (FREAD64(&magicNumber1,(size_t)4,(size_t)1,fp) != 1) -#endif - return CDF_READ_ERROR; -#ifndef NETWORKbyteORDERcpu - temp = magicNumber1; - REVERSE4bIO (&temp, &magicNumber1) -#endif - if (magicNumber1 == V3magicNUMBER_1) - *isLFS = TRUE; - else if (magicNumber1 == V2magicNUMBER_1 || - magicNumber1 == V2magicNUMBER_1pre) - *isLFS = FALSE; - else { - *isLFS = TRUE; - pStatus = NOT_A_CDF_OR_NOT_SUPPORTED; - } - } - FCLOSE64 (fp); - if (CDFfullName != NULL) strcpyX (CDFfullName, CDFpathX, DU_MAX_PATH_LEN); - return pStatus; -} - -/****************************************************************************** -* StrStrIgCaseX. -******************************************************************************/ - -VISIBLE_PREFIX Logical StrStrIgCaseX (string, chkstring) -char *string; -char *chkstring; -{ - int stringL = strlen(string); - int chkstringL = strlen(chkstring); - int i; - if (stringL == 0 || chkstringL == 0) return FALSE; - if (stringL != chkstringL) return FALSE; - for (i = 0; i < stringL; i++) { - if (MakeLower(chkstring[i]) != MakeLower(string[i])) return FALSE; - } - return TRUE; -} - -/****************************************************************************** -* Check if a given string ends with the provided substring, case sensitive. -* TRUE if s1 ends with s2. Otherwise, FALSE is returned. -******************************************************************************/ - -int EndsWith (s1, s2) -char *s1; -char *s2; -{ - int i; - char *ps1, *ps2; - - if (strlen(s2) > strlen(s1)) - return FALSE; - - ps1 = s1 + strlen(s1) - strlen(s2); - ps2 = s2; - - for (i=0; i < (int) strlen(s2); i++) - if (*(ps1++) != *(ps2++)) - return FALSE; - - return TRUE; -} - -/****************************************************************************** -* Check if a given string ends with the provided substring, ignoring case. -* TRUE if s1 ends with s2. Otherwise, FALSE is returned. -******************************************************************************/ - -int EndsWithIgCase (s1, s2) -char *s1; -char *s2; -{ - int i; - char *ps1, *ps2; - - if (strlen(s2) > strlen(s1)) - return FALSE; - - ps1 = s1 + strlen(s1) - strlen(s2); - ps2 = s2; - - for (i=0; i < (int) strlen(s2); i++) { - if (MakeLower(*ps1) != MakeLower(*ps2)) - return FALSE; - ps1++; - ps2++; - } - return TRUE; -} - -/****************************************************************************** -* Find the last occurence of a substring within a given string, case -* sensitive. If the substring is found, it returns the offset where the -* substring is at in the original string. If the substring is not found, it -* returns -1. -******************************************************************************/ - -VISIBLE_PREFIX int StrLaststr (s1, s2) -char *s1; -char *s2; -{ - char *sc2, *psc1, *ps1; - - if (*s2 == '\0') - return -1; - - ps1 = s1 + strlen(s1); - - while(ps1 != s1) { - --ps1; - for (psc1 = ps1, sc2 = s2; ; ) - if (*(psc1++) != *(sc2++)) - break; - else if (*sc2 == '\0') - return (int) (ps1 - s1); - } - return -1; -} - -/****************************************************************************** -* Find the last occurence of a substring within a given string, ignoring case. -* If the substring is found, it returns the offset where the substring is at -* in the original string. If the substring is not found, it returns -1. -******************************************************************************/ - -VISIBLE_PREFIX int StrLaststrIgCase (s1, s2) -char *s1; -char *s2; -{ - char *sc2, *psc1, *ps1; - - if (*s2 == '\0') - return -1; - - ps1 = s1 + strlen(s1); - - while (ps1 != s1) { - --ps1; - for (psc1 = ps1, sc2 = s2; ; ) { - if (MakeLower(*psc1) != MakeLower(*sc2)) - break; - else if (*sc2 == '\0') - return (int) (ps1 - s1); - psc1++; - sc2++; - } - } - return -1; -} - -/****************************************************************************** -* Remove the ".cdf" file extension from the given file name if it's there. -* It ignores the case. -* Example: -* mydata.cdf => mydata -******************************************************************************/ - -VISIBLE_PREFIX void RemoveCDFFileExtension (fileName, dstPath) -char *fileName; /* CDF file name. */ -char *dstPath; /* The string holding file name without extension. */ -{ - int ptr = -1; - - strcpyX (dstPath, fileName, CDF_PATHNAME_LEN); - if (EndsWithIgCase (dstPath, ".cdf")) { - ptr = StrLaststrIgCase(dstPath, ".cdf"); - if (ptr != -1) ((char *) dstPath)[ptr] = (char) '\0'; - } - return; -} - -/****************************************************************************** -* CDFgetFileBackwardEnvVar. -******************************************************************************/ - -VISIBLE_PREFIX int CDFgetFileBackwardEnvVar () -{ - char *bk = NULL; -#if defined(vms) - bk = getenv("CDF$FILEBACKWARD"); -#else - bk = getenv("CDF_FILEBACKWARD"); -#endif - if (bk != NULL) { - if (strlen(bk) == 0) return 0; - if (StrStrIgCaseX(bk, "TRUE")) return 1; - } - return 0; -} - -/****************************************************************************** -* CDFgetChecksumEnvVar. -******************************************************************************/ - -VISIBLE_PREFIX int CDFgetChecksumEnvVar () -{ - char *bk = NULL; -#if defined(vms) - bk = getenv("CDF$CHECKSUM"); -#else - bk = getenv("CDF_CHECKSUM"); -#endif - if (bk != NULL) { - if (strlen(bk) == 0) return 0; - if (StrStrIgCaseX(bk, "none") || StrStrIgCaseX(bk, "no")) return 0; - if (StrStrIgCaseX(bk, "md5")) return 1; - } - return 0; -} - -/****************************************************************************** -* CDFChecksumMethod. -******************************************************************************/ - -VISIBLE_PREFIX long CDFChecksumMethod (Int32 flags) -{ - int md5 = 0; - int other = 0; - - if (!BITSET(flags,CDR_CHECKSUM_BIT)) return NONE_CHECKSUM; - md5 = (int) BITSET(flags,CDR_CHECKSUM_MD5_BIT); - other = (int) BITSET(flags,CDR_CHECKSUM_OTHER_BIT); - if (md5 == 1) return MD5_CHECKSUM; - else if (other == 1) return OTHER_CHECKSUM; - return NONE_CHECKSUM; -} - -/****************************************************************************** -* CDFsetValidate. -******************************************************************************/ - -VISIBLE_PREFIX void CDFsetValidate (long validate) -{ - if (validate == VALIDATEFILEon) { -#if !defined(vms) -#if !defined(sun) && (!defined(WIN32) && !defined(__MINGW32__)) && \ - !defined(sgi) - setenv ("CDF_VALIDATE", "yes", 1); -#else -# if !defined(WIN32) - putenv ("CDF_VALIDATE=yes"); -# else - _putenv ("CDF_VALIDATE=yes"); -# endif -#endif -#else - setenv ("CDF$VALIDATE", "yes", 1); -#endif - } else { -#if !defined(vms) -#if !defined(sun) && (!defined(WIN32) && !defined(__MINGW32__)) && \ - !defined(sgi) - setenv ("CDF_VALIDATE", "no", 1); -#else -# if !defined(WIN32) - putenv ("CDF_VALIDATE=no"); -# else - _putenv ("CDF_VALIDATE=no"); -# endif -#endif -#else - setenv ("CDF$VALIDATE", "no", 1); -#endif - } -} - -/****************************************************************************** -* CDFgetValidate. -* Return: 1 if not set or set to yes (the default) -* 0 if set to no or none -******************************************************************************/ - -VISIBLE_PREFIX int CDFgetValidate () -{ - char *vad = NULL; -#if defined(vms) - vad = getenv("CDF$VALIDATE"); -#else - vad = getenv("CDF_VALIDATE"); -#endif - if (vad != NULL) { - if (strlen(vad) == 0) return 0; - if (StrStrIgCaseX(vad, "none") || StrStrIgCaseX(vad, "no")) return 0; - if (StrStrIgCaseX(vad, "yes")) return 1; - } - return 1; -} - -/****************************************************************************** -* CDFgetValidateDebug. -* Return: 0 if not set or set to no or none (the default) -* 1 if set to yes -******************************************************************************/ - -VISIBLE_PREFIX int CDFgetValidateDebug () -{ - char *vad = NULL; -#if defined(vms) - vad = getenv("CDF$VALIDATE$DEBUG"); -#else - vad = getenv("CDF_VALIDATE_DEBUG"); -#endif - if (vad != NULL) { - if (strlen(vad) == 0) return 0; - if (StrStrIgCaseX(vad, "none") || StrStrIgCaseX(vad, "no")) return 0; - if (StrStrIgCaseX(vad, "yes")) return 1; - } - return 0; -} - diff --git a/cdf36_3-dist/src/lib/cdfope.c b/cdf36_3-dist/src/lib/cdfope.c deleted file mode 100644 index 5ae8439..0000000 --- a/cdf36_3-dist/src/lib/cdfope.c +++ /dev/null @@ -1,651 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `open' operations. -* -* Version 1.4a, 21-Feb-97, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 29-Sep-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 25-Jan-94, J Love CDF V2.4. -* V1.3 15-Dec-94, J Love CDF V2.5. -* V1.3a 9-Jan-95, J Love Encode/decode changes, etc. -* V1.3b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.3c 8-May-95, J Love Only check version/release for FUTURE_CDF. -* V1.3d 7-Sep-95, J Love CDFexport-related changes. Fixed clean up -* when a CDF is aborted. -* V1.4 21-Aug-96, J Love CDF V2.6. -* V1.4a 21-Feb-97, J Love Removed RICE. -* V1.5 21-Jun-04, M Liu Modified the error message for NOT_A_CDF. -* V2.0 29-Jun-04, M Liu Added support for LFS (Large File System >2G). -* V1.7 13-Oct-06, M Liu Changed to allow upper and lower case CDF -* name to be used on win32. -* V3.2 17-Jun-07, D Berger Added setting of Cur->cdf and id prior to calls -* to ReadGDR in support of READONLY perfomance -* improvement changes. -* V3.3 16-Jul-08, M Liu Added ValidateCDF/ValidateCDF64 function calls -* after GDR is read. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" -#include "cdfrev.h" - -static CDFstatus ValidateCDFTT2000 (CDFid id, int zVars, int rVars); - -/****************************************************************************** -* CDFope. -******************************************************************************/ - -STATICforIDL CDFstatus CDFope (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ -CDFstatus pStatus = CDF_OK; - -switch (Va->item) { - /**************************************************************************** - * CDF_, open an existing CDF. - ****************************************************************************/ - case CDF_: { - char CDFnameT[CDF_PATHNAME_LEN+1], CDFnameX[DU_MAX_PATH_LEN+1]; - char CDFnameTx[CDF_PATHNAME_LEN+1]; - char *CDFnameP; struct CDFstruct *CDF; - vFILE *dotFp, *uDotFp; - size_t nBytes; int varN; CDFid *id; - Logical upper_case_ext, version_numbers, no_append; - Int32 magicNumber1, magicNumber2, CDRflags, version, release, increment; - Logical largeFile; - /************************************************************************** - * Get arguments for this operation/item. - **************************************************************************/ - CDFnameP = va_arg (Va->ap, char *); - id = va_arg (Va->ap, CDFid *); - *id = (CDFid) NULL; - /************************************************************************** - * Validate arguments. - **************************************************************************/ - if (strlen(CDFnameP) > (size_t) CDF_PATHNAME_LEN) { - if (!sX(CDF_NAME_TRUNC,&pStatus)) return pStatus; - } - strcpyX (CDFnameT, CDFnameP, CDF_PATHNAME_LEN); -#if STRIP_TRAILING_BLANKS_FROM_CDFPATH - StripTrailingBlanks (CDFnameT); -#endif -#if defined(vms) || defined(dos) - MakeUpperString (CDFnameT); -#endif - RemoveCDFFileExtension(CDFnameT, CDFnameTx); -/* if (!ValidCDFname(CDFnameTx)) return BAD_CDF_NAME; */ - if (!sX(FindCDF(CDFnameTx,&no_append, - &upper_case_ext, - &version_numbers),&pStatus)) return pStatus; - /************************************************************************** - * Open CDF file. - **************************************************************************/ - BuildFilePath (CDFt, CDFnameTx, no_append, upper_case_ext, version_numbers, - INT32_ZERO, CDFnameX); - if (!sX(CheckLFS(CDFnameX, &largeFile, NULL),&pStatus)) return pStatus; - if (!largeFile) - dotFp = V_open (CDFnameX, READ_ONLY_a_mode); - else - dotFp = V_open64 (CDFnameX, READ_ONLY_a_mode); - if (dotFp == NULL) return CDF_OPEN_ERROR; - /************************************************************************** - * Read the magic numbers. - **************************************************************************/ - if (!largeFile) { /* 32-bit offset file.... */ - if (!Read32(dotFp,&magicNumber1)) { - V_close (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - if (!Read32(dotFp,&magicNumber2)) { - V_close (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - } else { /* 64-bit offset file.... */ - if (!Read32_64(dotFp,&magicNumber1)) { - V_close64 (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - if (!Read32_64(dotFp,&magicNumber2)) { - V_close64 (dotFp, NULL, NULL); - return CDF_READ_ERROR; - } - } - /************************************************************************** - * Determine what version CDF this is, if it is compressed (and if this is - * actually a CDF). - **************************************************************************/ - switch (magicNumber1) { - case V1magicNUMBER_flip: - if (!largeFile) - V_close (dotFp, NULL, NULL); - else - V_close64 (dotFp, NULL, NULL); - return ILLEGAL_ON_V1_CDF; - case V2magicNUMBER_1pre: - uDotFp = NULL; - break; - case V2magicNUMBER_1: - case V3magicNUMBER_1: - switch (magicNumber2) { - case V2magicNUMBER_2u: /* Same as V3magicNUMBER_2u */ - if (magicNumber1 == V2magicNUMBER_1) { /* 32-offset */ - if (!CACHEv(dotFp,NUMcacheUNKNOWN)) { - V_close (dotFp, NULL, NULL); - return BAD_CACHE_SIZE; - } - } else { /* 64-bit */ - if (!CACHEv64(dotFp,NUMcacheUNKNOWN)) { - V_close64 (dotFp, NULL, NULL); - return BAD_CACHE_SIZE; - } - } - uDotFp = NULL; - break; - case V2magicNUMBER_2c: - uDotFp = V_scratch (ScratchDirectory(NULL), "cdf"); - if (uDotFp == NULL) { - V_close (dotFp, NULL, NULL); - return CDF_CREATE_ERROR; - } - if (magicNumber1 == V2magicNUMBER_1) { - if (!CACHEv(uDotFp,NUMcacheUNKNOWN)) { - V_close (dotFp, NULL, NULL); - V_delete (uDotFp, NULL); - return BAD_CACHE_SIZE; - } - if (!sX(DecompressCDF(dotFp,uDotFp),&pStatus)) { - V_close (dotFp, NULL, NULL); - V_delete (uDotFp, NULL); - return pStatus; - } - } else { - if (!CACHEv64(uDotFp,NUMcacheUNKNOWN)) { - V_close64 (dotFp, NULL, NULL); - V_delete64 (uDotFp, NULL); - return BAD_CACHE_SIZE; - } - if (!sX(DecompressCDF64(dotFp,uDotFp),&pStatus)) { - V_close64 (dotFp, NULL, NULL); - V_delete64 (uDotFp, NULL); - return pStatus; - } - } - break; - default: - if (!largeFile) - V_close (dotFp, NULL, NULL); - else - V_close64 (dotFp, NULL, NULL); - return NOT_A_CDF; - } - break; - default: - if (!largeFile) - V_close (dotFp, NULL, NULL); - else - V_close64 (dotFp, NULL, NULL); - if (magicNumber1 == netCDFmagicNUMBER1 || - magicNumber1 == netCDFmagicNUMBER2) - return IS_A_NETCDF; - else - return NOT_A_CDF_OR_NOT_SUPPORTED; - } - /************************************************************************** - * Allocate and begin initializing CDF structure. - **************************************************************************/ - CDF = (struct CDFstruct *) cdf_AllocateMemory ( - (size_t)sizeof(struct CDFstruct), NULL); - if (CDF == NULL) { - if (!largeFile) { - V_close (dotFp, NULL, NULL); - if (uDotFp != NULL) V_delete (uDotFp, NULL); - } else { - V_close64 (dotFp, NULL, NULL); - if (uDotFp != NULL) V_delete64 (uDotFp, NULL); - } - return BAD_MALLOC; - } - CDF->CDFname = (char *) cdf_AllocateMemory ( - (size_t)strlen(CDFnameTx) + 1, NULL); - if (CDF->CDFname == NULL) { - if (!largeFile) { - V_close (dotFp, NULL, NULL); - if (uDotFp != NULL) V_delete (uDotFp, NULL); - } else { - V_close64 (dotFp, NULL, NULL); - if (uDotFp != NULL) V_delete64 (uDotFp, NULL); - } - cdf_FreeMemory (CDF, NULL); - return BAD_MALLOC; - } - else - strcpyX (CDF->CDFname, CDFnameTx, 0); - CDF->magic = VALIDid_MAGIC_NUMBER; - CDF->largeFile = largeFile; - CDF->dotFp = dotFp; - CDF->uDotFp = uDotFp; - CDF->fp = BOO(uDotFp == NULL,dotFp,uDotFp); - CDF->no_append = no_append; - CDF->upper_case_ext = upper_case_ext; - CDF->version_numbers = version_numbers; - CDF->decoding = HOST_DECODING; - CDF->readOnly = FALSE; - CDF->zMode = zMODEoff; - CDF->negToPosFp0 = FALSE; - CDF->status = READ_ONLY; -CDF->tt2000Updated = 0; - CDF->pseudo_clock = 0; - CDF->stage.fp = NULL; - CDF->stage.mark = ZERO_OFFSET; - CDF->stage.mark64 = (OFF_T) ZERO_OFFSET64; - CDF->stage.cacheSize = NUMcacheSTAGE; - CDF->compressCacheSize = NUMcacheCOMPRESS; - CDF->compressFp = NULL; - CDF->scratchDir = NULL; - CDF->NrVars = 0; /* Updated below if the read is OK. */ - CDF->NzVars = 0; /* Updated below if the read is OK. */ - CDF->rVars = NULL; - CDF->zVars = NULL; - CDF->CURzVarNum = RESERVED_VARNUM; - CDF->CURrVarNum = RESERVED_VARNUM; - CDF->CURzVarOffset = 0; - CDF->CURzVarOffset64 = (OFF_T) 0; - CDF->CURrVarOffset = 0; - CDF->CURrVarOffset64 = (OFF_T) 0; - /************************************************************************** - * Read necessary fields from the CDR and GDR. - **************************************************************************/ - if (!largeFile) { - CDF->CDRoffset = V2_CDR_OFFSET; - if (!sX(ReadCDR(CDF->fp,CDF->CDRoffset, - CDR_GDROFFSET,&(CDF->GDRoffset), - CDR_ENCODING,&(CDF->encoding), - CDR_FLAGS,&CDRflags, - CDR_VERSION,&version, - CDR_RELEASE,&release, - CDR_INCREMENT,&increment, - CDR_NULL),&pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - cdf_FreeMemory (CDF, NULL); - return pStatus; - } - /************************************************************************ - * Set state info for use in ReadGDR - required by changes to support - * READONLY performance enhancement. - ***********************************************************************/ - Cur->cdf = CDF; - *id = CDF; - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_EOF,&(CDF->eof), - GDR_NrVARS,&(CDF->NrVars), - GDR_NzVARS,&(CDF->NzVars), - GDR_rMAXREC,&(CDF->rMaxRec), - GDR_NULL),&pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - cdf_FreeMemory (CDF, NULL); - Cur->cdf = NULL; - *id = (CDFid) NULL; - return pStatus; - } - } else { - /************************************************************************ - * Set state info for use in ReadGDR - required by changes to support - * READONLY performance enhancement. - ***********************************************************************/ - Cur->cdf = CDF; - *id = CDF; - CDF->CDRoffset64 = (OFF_T) V3_CDR_OFFSET64; - if (!sX(ReadCDR64(CDF->fp,CDF->CDRoffset64, - CDR_GDROFFSET,&(CDF->GDRoffset64), - CDR_ENCODING,&(CDF->encoding), - CDR_FLAGS,&CDRflags, - CDR_VERSION,&version, - CDR_RELEASE,&release, - CDR_INCREMENT,&increment, - CDR_NULL),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - cdf_FreeMemory (CDF, NULL); - Cur->cdf = NULL; - *id = (CDFid) NULL; - return pStatus; - } - - /************************************************************************ - * Set state info for use in ReadGDR - required by changes to support - * READONLY performance enhancement. - ***********************************************************************/ - Cur->cdf = CDF; - *id = CDF; - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_EOF,&(CDF->eof64), - GDR_NrVARS,&(CDF->NrVars), - GDR_NzVARS,&(CDF->NzVars), - GDR_rMAXREC,&(CDF->rMaxRec), - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - cdf_FreeMemory (CDF, NULL); - Cur->cdf = NULL; - *id = (CDFid) NULL; - return pStatus; - } - } - /************************************************************************** - * Continue initializing CDF structure. - **************************************************************************/ - CDF->singleFile = SINGLEfileBITset (CDRflags); - CDF->rowMajor = ROWmajorBITset (CDRflags); - CDF->checksum = (PriorTo("3.0.0",version,release,increment) ? - NO_CHECKSUM : CDFChecksumMethod (CDRflags)); - CDF->fakeEPOCH = PriorTo("2.1.1",version,release,increment); - CDF->wastedSpace = PriorTo("2.5",version,release,increment); - CDF->badEOF = PriorTo("2.1",version,release,increment); - CDF->badTerminatingOffsets = PriorTo("2.1",version,release,increment); - CDF->assumedScopes = PriorTo("2.5",version,release,increment); - CDF->workingCacheSize = BOO(CDF->singleFile,NUMcacheSINGLE,NUMcacheMULTI); - /************************************************************************ - * Validate the CDF to make sure that certain data fields are normal by - * doing some sanity checks. - ***********************************************************************/ - if (CDFgetValidate()) { - Logical debug; - if (CDFgetValidateDebug()) - debug = TRUE; - else - debug = FALSE; - if (!largeFile) { - pStatus = ValidateCDF(CDF,CDF->fp,CDF->CDRoffset,CDF->eof, debug); - if (pStatus != CDF_OK) { - AbortAccess (CDF, noUPDATE, noDELETE); - cdf_FreeMemory (CDF, NULL); - Cur->cdf = NULL; - *id = (CDFid) NULL; - return pStatus; - } - } else { - pStatus = ValidateCDF64(CDF,CDF->fp,CDF->CDRoffset64,CDF->eof64, debug); - if (pStatus != CDF_OK) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - cdf_FreeMemory (CDF, NULL); - Cur->cdf = NULL; - *id = (CDFid) NULL; - if (pStatus == CORRUPTED_V3_CDF) { - char vri[6]; - long libver, librel, libinc; - CDFstatus status; - snprintf (vri, (size_t) 6, "%1.1d.%1.1d.%1.1d", (int) version, - (int) release, (int) increment); - status = CDFlib (GET_, LIB_VERSION_, &libver, - LIB_RELEASE_, &librel, - LIB_INCREMENT_, &libinc, - NULL_); - if (PriorTo(vri, (Int32)libver, (Int32)librel, (Int32)libinc) && - PriorTo("3.5.0", (Int32)libver, (Int32)librel, (Int32)libinc)) - return UNABLE_TO_PROCESS_CDF; - else - return pStatus; - } else - return pStatus; - } - } - } - /************************************************************************** - * Acquire some more info from the CDF. - **************************************************************************/ - if (!largeFile) { - CDF->CDRoffset = V2_CDR_OFFSET; - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_rNUMDIMS,&(CDF->rNumDims), - GDR_rDIMSIZES,CDF->rDimSizes, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - cdf_FreeMemory (CDF, NULL); - Cur->cdf = NULL; - *id = (CDFid) NULL; - return pStatus; - } - } else { - CDF->CDRoffset64 = (OFF_T) V3_CDR_OFFSET64; - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_rNUMDIMS,&(CDF->rNumDims), - GDR_rDIMSIZES,CDF->rDimSizes, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - cdf_FreeMemory (CDF, NULL); - Cur->cdf = NULL; - *id = (CDFid) NULL; - return pStatus; - } - } - /************************************************************************** - * Set the cache size for the "working" dotCDF file based on the format - * of the CDF. - **************************************************************************/ - if (!largeFile) { - if (!CACHEv(CDF->fp,CDF->workingCacheSize)) { - AbortAccess (CDF, noUPDATE, noDELETE); - cdf_FreeMemory (CDF, NULL); - return BAD_CACHE_SIZE; - } - } else { - if (!CACHEv64(CDF->fp,CDF->workingCacheSize)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - cdf_FreeMemory (CDF, NULL); - return BAD_CACHE_SIZE; - } - } - /************************************************************************** - * Allocate and initialize variable data structures kept in memory. - **************************************************************************/ - if (CDF->NrVars > 0) { - nBytes = (size_t) (CDF->NrVars * sizeof(struct VarStruct *)); - CDF->rVars = (struct VarStruct **) cdf_AllocateMemory (nBytes, NULL); - if (CDF->rVars == NULL) { - if (!largeFile) - AbortAccess (CDF, noUPDATE, noDELETE); - else - AbortAccess64 (CDF, noUPDATE, noDELETE); - cdf_FreeMemory (CDF, NULL); - return BAD_MALLOC; - } - for (varN = 0; varN < CDF->NrVars; varN++) CDF->rVars[varN] = NULL; - CDF->MAXrVars = (int) CDF->NrVars; - } - else { - CDF->rVars = NULL; - CDF->MAXrVars = 0; - } - if (CDF->NzVars > 0) { - nBytes = (size_t) (CDF->NzVars * sizeof(struct VarStruct *)); - CDF->zVars = (struct VarStruct **) cdf_AllocateMemory (nBytes, NULL); - if (CDF->zVars == NULL) { - if (!largeFile) - AbortAccess (CDF, noUPDATE, noDELETE); - else - AbortAccess64 (CDF, noUPDATE, noDELETE); - cdf_FreeMemory (CDF, NULL); - return BAD_MALLOC; - } - for (varN = 0; varN < CDF->NzVars; varN++) CDF->zVars[varN] = NULL; - CDF->MAXzVars = (int) CDF->NzVars; - } - else { - CDF->zVars = NULL; - CDF->MAXzVars = 0; - } - /************************************************************************** - * If this is a multi-file CDF and a CDF pathname that doesn't require file - * extensions to be appended was specified (ie. a weird naming convention), - * close/free the CDF and return an error. This is because the extensions - * for the variable files would be known only to the user. We'd rather not - * guess. - **************************************************************************/ - if (!CDF->singleFile && CDF->no_append) { - if (!largeFile) - AbortAccess (CDF, noUPDATE, noDELETE); - else - AbortAccess64 (CDF, noUPDATE, noDELETE); - cdf_FreeMemory (CDF, NULL); - return BAD_CDF_EXTENSION; - } - /************************************************************************** - * Initialize the current objects/states and the Vstream statistics. - **************************************************************************/ - InitCURobjectsStates (CDF); - AddTOvStats (&CDF->dotCDFvStats, NULL); - AddTOvStats (&CDF->uDotCDFvStats, NULL); - /************************************************************************** - * Select the current CDF and pass back the CDF identifier. - **************************************************************************/ - Cur->cdf = CDF; - *id = CDF; - if (CDF->singleFile && CDF->checksum != NO_CHECKSUM) { - if (!sX(CDFconfirmChecksum(*id),&pStatus)) { - if (!largeFile) - AbortAccess (CDF, noUPDATE, noDELETE); - else - AbortAccess64 (CDF, noUPDATE, noDELETE); - cdf_FreeMemory (CDF, NULL); - Cur->cdf = NULL; - *id = (CDFid) NULL; - return pStatus; - } - } - if (CDFgetValidate() && (!PriorTo ("3.5.0", version, release, increment))) { - if (!sX(ValidateCDFTT2000 (*id, (int) CDF->NzVars, (int) CDF->NrVars), - &pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - cdf_FreeMemory (CDF, NULL); - Cur->cdf = NULL; - *id = (CDFid) NULL; - return pStatus; - } - } - AddOpenCDFsCount(); - break; - } - /**************************************************************************** - * Unknown item, must be the next function. - ****************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } -} - -return pStatus; -} - -/****************************************************************************** -* ValidateCDFTT2000. -******************************************************************************/ - -static CDFstatus ValidateCDFTT2000 (CDFid id, int zVars, int rVars) -{ - long maxRec, dataType; - CDFstatus status; - int i, j, count, tt2000Sts; - long long tt2000 = DEFAULT_TT2000_PADVALUE; - void *buffer; - long year, month, day, tt2000LastUpdated, numDims, dimSizes[CDF_MAX_DIMS]; - double yy, mm, dd, hh, mn, ss, ml, ms, ns; - int once; - - status = CDFgetLeapSecondLastUpdated (id, &tt2000LastUpdated); - if (status != CDF_OK) return status; -#if defined(vms) - CDFgetLastDateinLeapSecondsTBL (&year, &month, &day); -#else - CDFgetLastDateinLeapSecondsTable (&year, &month, &day); -#endif - if (tt2000LastUpdated == 0 || - tt2000LastUpdated == (10000*year+100*month+day)) return CDF_OK; - once = 0; - for (i = 0; i < zVars; ++i) { - status = CDFlib(SELECT_, zVAR_, (long) i, - GET_, zVAR_DATATYPE_, &dataType, - NULL_); - if (status != CDF_OK) return status; - if (dataType != CDF_TIME_TT2000) continue; - status = CDFlib(GET_, zVAR_MAXREC_, &maxRec, - NULL_); - if (status != CDF_OK) return status; - if (maxRec < 0) continue; - /* If the file's last updated leap second date is later than table's, - then, the table is out-dated. */ - if ((once == 0) && (tt2000LastUpdated > (10000*year+100*month+day))) - return TT2000_USED_OUTDATED_TABLE; - else once = 1; - status = CDFlib(GET_, zVAR_NUMDIMS_, &numDims, - zVAR_DIMSIZES_, dimSizes, - NULL_); - if (status != CDF_OK) return status; - count = (int) (maxRec + 1); - if (numDims > 0) - for (j = 0; j < (int) numDims; ++j) count *= (int) dimSizes[j]; - buffer = (void *) malloc ((size_t) (count * sizeof(long long))); - if (buffer == NULL) return BAD_MALLOC; - status = CDFgetVarAllRecordsByVarID (id, 1, (long) i, buffer); - if (status < CDF_OK) { - free (buffer); - return status; - } - for (j = 0; j < count; ++j) { - if (tt2000 < *(((long long *)buffer)+j)) - tt2000 = *(((long long *)buffer)+j); - } - free (buffer); - } - status = CDFlib(GET_, rVARs_NUMDIMS_, &numDims, - rVARs_DIMSIZES_, dimSizes, - NULL_); - if (status != CDF_OK) return status; - for (i = 0; i < rVars; ++i) { - status = CDFlib(SELECT_, rVAR_, (long) i, - GET_, rVAR_DATATYPE_, &dataType, - NULL_); - if (status != CDF_OK) return status; - if (dataType != CDF_TIME_TT2000) continue; - status = CDFlib(GET_, rVAR_MAXREC_, &maxRec, - NULL_); - if (status != CDF_OK) return status; - if (maxRec < 0) continue; - if ((once == 0) && (tt2000LastUpdated > (10000*year+100*month+day))) - return TT2000_USED_OUTDATED_TABLE; - else once = 1; - count = (int) (maxRec + 1); - if (numDims > 0) - for (j = 0; j < (int) numDims; ++j) count *= (int) dimSizes[j]; - buffer = (void *) malloc ((size_t) (count * sizeof(long long))); - if (buffer == NULL) return BAD_MALLOC; - status = CDFgetVarAllRecordsByVarID (id, 0, (long) i, buffer); - if (status < CDF_OK) { - free (buffer); - return status; - } - for (j = 0; j < count; ++j) { - if (tt2000 < *(((long long *)buffer)+j)) - tt2000 = *(((long long *)buffer)+j); - } - free (buffer); - } - if (tt2000 != DEFAULT_TT2000_PADVALUE) { - breakdownTT2000 (tt2000, &yy, &mm, &dd, &hh, &mn, &ss, &ml, &ms, &ns); - tt2000Sts = ValidateTT2000((int) (10000*yy+100*mm+dd), - (int)tt2000LastUpdated); - if (tt2000Sts == -1) return TT2000_USED_OUTDATED_TABLE; - else if (tt2000Sts == 0) return TT2000_CDF_MAYNEEDUPDATE; - } - return CDF_OK; -} - - diff --git a/cdf36_3-dist/src/lib/cdfput1.c b/cdf36_3-dist/src/lib/cdfput1.c deleted file mode 100644 index ec28615..0000000 --- a/cdf36_3-dist/src/lib/cdfput1.c +++ /dev/null @@ -1,990 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `put' operations, part 1. -* -* Version 1.5, 9-Sep-96, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 16-Sep-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.1 16-Sep-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 10-Dec-93, J Love CDF V2.4. Added readonly mode and zMode. -* V1.3 15-Dec-94, J Love CDF V2.5. -* V1.3a 6-Jan-95, J Love Encode/decode changes. More cache-residency. -* V1.3b 15-Mar-95, J Love Solaris 2.3 IDL i/f. Fixed `recNum' argument -* to `LastAllocatedRecord'. -* V1.4 30-May-95, J Love Fixed bug in involving -* use of old VDR offset after the VDR was moved. -* V1.4a 4-Aug-95, J Love CDFexport-related changes. -* V1.5 9-Sep-96, J Love CDF V2.6. -* V2.0 08-Apr-04, M Liu Removed calls to LocateCurrentVar function as -* its offset becomes available when it is -* selected/created. -* V2.1 16-Nov-05, M Liu Changed code for data spec modification. -99 -* is passed as a special indicator for the -* number of elements as it can't be change. -* -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* CDFput1. -******************************************************************************/ - -STATICforIDL CDFstatus CDFput1 (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ -CDFstatus tStatus, pStatus = CDF_OK; - -switch (Va->item) { - /**************************************************************************** - * rVAR_NAME_/zVAR_NAME_, rename the current variable. A variable with the - * same name must not already exist in the CDF. - ****************************************************************************/ - case rVAR_NAME_: - case zVAR_NAME_: { - Logical zOp = (Va->item == zVAR_NAME_), zVarCur; - struct CDFstruct *CDF; - char *varName = va_arg (Va->ap, char *), tmpName[CDF_VAR_NAME_LEN+1]; - Int32 offsetCur, offsetFound; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVarCur = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVarCur) offsetCur = CDF->CURzVarOffset; - else offsetCur = CDF->CURrVarOffset; - - if (strlen(varName) > (size_t) CDF_VAR_NAME_LEN) { - if (!sX(VAR_NAME_TRUNC,&pStatus)) return pStatus; - } - strcpyX (tmpName, varName, CDF_VAR_NAME_LEN); - if (!ValidVarName(tmpName)) return BAD_VAR_NAME; - /************************************************************************** - * Check that the new variable name is not already in use. Don't flag as - * an error if the new name is the same as the old name (ignoring trailing - * blanks). Trailing blanks may be eliminated. - **************************************************************************/ - tStatus = FindVarByName (CDF, tmpName, &offsetFound, NULL, NULL); - switch (tStatus) { - case CDF_OK: - if (offsetFound != offsetCur) return VAR_EXISTS; - break; - case NO_SUCH_VAR: - break; - default: - AbortAccess (CDF, UPDATE, noDELETE); - return tStatus; - } - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - NulPad (tmpName, CDF_VAR_NAME_LEN); - if (!sX(WriteVDR(CDF,CDF->fp,offsetCur,zVarCur, - VDR_NAME,tmpName, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - - /**************************************************************************** - * rVAR_DATASPEC_/zVAR_DATASPEC_, - * If the data types are not equivalent or the number of elements are - * different, then check for the following: - * 1) if any records have been written - * 2) if a pad value has been specified - * If either is true, then the data specification cannot be changed. - ****************************************************************************/ - case rVAR_DATASPEC_: - case zVAR_DATASPEC_: { - Logical zOp = (Va->item == zVAR_DATASPEC_), zVar; - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 newDataType = (Int32) va_arg (Va->ap, long); - Int32 newNumElems = (Int32) va_arg (Va->ap, long); - Int32 offset, flags, dataType, numElems, maxRec, maxAllocated; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - - if (!ValidDataType(newDataType) || InValidDataType(newDataType)) - return BAD_DATA_TYPE; - if (newNumElems != -99 && newNumElems < 1) return BAD_NUM_ELEMS; - if (!STRINGdataType(newDataType)) { - if (newNumElems != -99 && newNumElems != 1) return BAD_NUM_ELEMS; - } - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_FLAGS,&flags, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_MAXREC,&maxRec, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * If the data specifications are not equivalent, check if any records have - * been written or allocated or if a pad value has been specified. - **************************************************************************/ - if (!EquivDataTypes(newDataType,dataType) || - (newNumElems != -99 && newNumElems != numElems)) { - if (maxRec > NO_RECORD) return CANNOT_CHANGE; - if (!sX(LastRecord(CDF,offset,zVar,&maxAllocated),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (maxAllocated > NO_RECORD) return CANNOT_CHANGE; - if (PADvalueBITset(flags)) return CANNOT_CHANGE; - } - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - if (newNumElems == -99) newNumElems = numElems; - /************************************************************************** - * Update the VDR with the new data specification. - **************************************************************************/ - if (!sX(WriteVDR(CDF,CDF->fp,offset,zVar, - VDR_DATATYPE,&newDataType, - VDR_NUMELEMS,&newNumElems, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * If this variable has been initialized, recalculate the affected - * parameters. - **************************************************************************/ - if (Var != NULL) { - Var->NvalueElems = newNumElems; - Var->NelemBytes = (Int32) CDFelemSize ((long)newDataType); - Var->NvalueBytes = Var->NvalueElems * Var->NelemBytes; - Var->NphyRecElems = Var->NphyRecValues * Var->NvalueElems; - Var->NvirtRecElems = Var->NvirtRecValues * Var->NvalueElems; - Var->NphyRecBytes = Var->NphyRecValues * Var->NvalueBytes; - Var->NvirtRecBytes = Var->NvirtRecValues * Var->NvalueBytes; - if (!sX(ConversionFunction(newDataType,HostEncoding(), - CDF->encoding,CDF->negToPosFp0, - &(Var->EncodeFunction)),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(ConversionFunction(newDataType,CDF->encoding, - CDF->decoding,CDF->negToPosFp0, - &(Var->DecodeFunction)),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - break; - } - - /**************************************************************************** - * rVAR_RECVARY_/zVAR_RECVARY_, - * Can't change if any records have been written or allocated. - ****************************************************************************/ - case rVAR_RECVARY_: - case zVAR_RECVARY_: { - Logical zOp = (Va->item == zVAR_RECVARY_), zVar; - Int32 offset, maxAllocated; - struct CDFstruct *CDF; struct VarStruct *Var; struct VDRstruct VDR; - long recVariance = va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (VDR.MaxRec > NO_RECORD) return CANNOT_CHANGE; - if (!sX(LastRecord(CDF,offset,zVar,&maxAllocated),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (maxAllocated > NO_RECORD) return CANNOT_CHANGE; - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - if (recVariance) - SetBit32 (&VDR.Flags,VDR_RECVARY_BIT); - else { - ClearBit32 (&VDR.Flags,VDR_RECVARY_BIT); - if (VDR.blockingFactor > 1) VDR.blockingFactor = 1; - } - if (!sX(WriteVDR(CDF,CDF->fp,offset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * If this variable has been initialized, recalculate the affected - * parameters. - **************************************************************************/ - if (Var != NULL) { - Var->recVary = BOO(recVariance,VARY,NOVARY); - if (!sX(CalcBF(CDF,Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - break; - } - - /**************************************************************************** - * rVAR_DIMVARYS_/zVAR_DIMVARYS_ - * Respecify dimension variances for current rVariable/zVariable. Can't - * change if any records have been written or if zMode/2 and really an - * rVariable. - ****************************************************************************/ - case rVAR_DIMVARYS_: - case zVAR_DIMVARYS_: { - Logical zOp = (Va->item == zVAR_DIMVARYS_), zVar; - long *dimVarys = va_arg (Va->ap, long *); - struct CDFstruct *CDF; struct VarStruct *Var; struct VDRstruct VDR; - Int32 offset, numDims, maxAllocated; int dimN; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset; - else offset = CDF->CURrVarOffset; - - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - - if (CDF->zMode == zMODEon2 && !zVar) return CANNOT_CHANGE; - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (VDR.MaxRec > NO_RECORD) return CANNOT_CHANGE; - if (!sX(LastRecord(CDF,offset,zVar,&maxAllocated),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (maxAllocated > NO_RECORD) return CANNOT_CHANGE; - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - numDims = BOO(zVar,VDR.zNumDims,CDF->rNumDims); - for (dimN = 0; dimN < numDims; dimN++) { - VDR.DimVarys[dimN] = BOO(dimVarys[dimN],VARY,NOVARY); - } - if (!sX(WriteVDR(CDF,CDF->fp,offset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * If this variable has been initialized, recalculate its parameters. - *************************************************************************/ - if (Var != NULL) { - if (!sX(CalcDimParms(CDF,Var->VDRoffset, - Var->zVar,&(Var->numDims), - Var->dimSizes,Var->dimVarys),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - CalcNumDimValues (CDF, Var); - CalcRecValues (Var); - Var->NphyRecElems = Var->NphyRecValues * Var->NvalueElems; - Var->NphyRecBytes = Var->NphyRecValues * Var->NvalueBytes; - if (!sX(CalcBF(CDF,Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - break; - } - - /**************************************************************************** - * rVAR_ALLOCATERECS_/zVAR_ALLOCATERECS_ - * rVAR_ALLOCATEBLOCK_/zVAR_ALLOCATEBLOCK_ - ****************************************************************************/ - case rVAR_ALLOCATERECS_: - case zVAR_ALLOCATERECS_: - case rVAR_ALLOCATEBLOCK_: - case zVAR_ALLOCATEBLOCK_: { - Logical zOp = (Va->item == zVAR_ALLOCATERECS_ || - Va->item == zVAR_ALLOCATEBLOCK_); - Logical blockOp = (Va->item == rVAR_ALLOCATEBLOCK_ || - Va->item == zVAR_ALLOCATEBLOCK_); - struct CDFstruct *CDF; struct VarStruct *Var; struct AllocStruct alloc; - long firstRecN, lastRecN; - if (blockOp) { - firstRecN = va_arg (Va->ap, long); - lastRecN = va_arg (Va->ap, long); - } - else { - firstRecN = 0; - lastRecN = va_arg(Va->ap,long) - 1; - } - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (firstRecN < 0) return BAD_ALLOCATE_RECS; - if (lastRecN < firstRecN) return BAD_ALLOCATE_RECS; - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!Var->recVary && (firstRecN != 0 || lastRecN != 0)) { - return BAD_ALLOCATE_RECS; - } - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Depending on variable type... - **************************************************************************/ - switch (Var->vType) { - case STANDARD_: - if (firstRecN > Var->maxAllocated + 1) { - firstRecN = Var->maxAllocated + 1; - sX (PRECEEDING_RECORDS_ALLOCATED, &pStatus); - } - /* No `break' is deliberate. */ - case SPARSE_RECORDS_: - LoadAllocVVR (alloc, firstRecN, lastRecN, FALSE) - if (!sX(AllocateRecords(CDF,Var,alloc),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->maxAllocated = MAXIMUM(lastRecN,Var->maxAllocated); - break; - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - return CANNOT_ALLOCATE_RECORDS; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return CANNOT_ALLOCATE_RECORDS; - case IN_MULTI_: - sX (MULTI_FILE_FORMAT, &pStatus); - break; - default: - return CDF_INTERNAL_ERROR; - } - break; - } - - /**************************************************************************** - * rVAR_INITIALRECS_/zVAR_INITIALRECS_, - * Specify (write) an initial number of records for the current variable. - * Can't set if any records have been written already. - ****************************************************************************/ - case rVAR_INITIALRECS_: - case zVAR_INITIALRECS_: { - Logical zOp = (Va->item == zVAR_INITIALRECS_); - struct CDFstruct *CDF; struct VarStruct *Var; - long recNum, nValues, valueN, offset; int how; void *buffer; - long nInitialRecs = va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (Var->maxRec > NO_RECORD) return CANNOT_CHANGE; - if (nInitialRecs < 1) return BAD_INITIAL_RECS; - if (!Var->recVary && nInitialRecs > 1) return BAD_INITIAL_RECS; - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar(CDF,Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - if (!sX(BuildPadBuffer(CDF,Var,(Int32)nInitialRecs, - &how,&buffer,FALSE),&pStatus)) return pStatus; - switch (how) { - case ALLrecordsATonce: - nValues = nInitialRecs * Var->NphyRecValues; - if (!sX(WriteVarValues(CDF,Var,INT32_ZERO,INT32_ZERO, - (Int32)nValues,buffer),&pStatus)) { - cdf_FreeMemory (buffer, NULL); - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - case ONErecordATaTIME: - for (recNum = 0; recNum < nInitialRecs; recNum++) { - if (!sX(WriteVarValues(CDF,Var,(Int32)recNum,INT32_ZERO, - Var->NphyRecValues,buffer),&pStatus)) { - cdf_FreeMemory (buffer, NULL); - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - break; - case ONEvalueATaTIME: - for (recNum = 0; recNum < nInitialRecs; recNum++) { - for (valueN = 0; valueN < Var->NphyRecValues; valueN++) { - offset = valueN * Var->NvalueBytes; - if (!sX(WriteVarValues(CDF,Var,(Int32)recNum, - (Int32)offset, - INT32_ONE,buffer),&pStatus)) { - cdf_FreeMemory (buffer, NULL); - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - } - break; - } - cdf_FreeMemory (buffer, NULL); - break; - } - - /**************************************************************************** - * rVAR_BLOCKINGFACTOR_/zVAR_BLOCKINGFACTOR_ - ****************************************************************************/ - case rVAR_BLOCKINGFACTOR_: - case zVAR_BLOCKINGFACTOR_: { - Logical zOp = (Va->item == zVAR_BLOCKINGFACTOR_); - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 blocking = (Int32) va_arg (Va->ap, long), flags; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Validate blocking factor. Zero (0) is valid meaning that the default - * is to be used. - **************************************************************************/ - switch (Var->vType) { - case STANDARD_: - break; - case SPARSE_RECORDS_: - if (Var->stage.areaOffset != NO_OFFSET) return CANNOT_CHANGE; - break; - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - if (Var->maxRec > NO_RECORD) return CANNOT_CHANGE; - break; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return UNKNOWN_SPARSENESS; - case IN_MULTI_: - break; - default: - return CDF_INTERNAL_ERROR; - } - if (blocking < 0) return BAD_BLOCKING_FACTOR; - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Update VDR with new blocking factor. - **************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_FLAGS,&flags, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!RECvaryBITset(flags) && blocking > 1) { - blocking = 1; - sX (FORCED_PARAMETER, &pStatus); - } - if (!sX(WriteVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_BLOCKING,&blocking, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Recalculate the variable parameters. - *************************************************************************/ - if (!sX(CalcBF(CDF,Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - - /**************************************************************************** - * rVAR_PADVALUE_/zVAR_PADVALUE_ - ****************************************************************************/ - case rVAR_PADVALUE_: - case zVAR_PADVALUE_: { - Logical zOp = (Va->item == zVAR_PADVALUE_); - struct CDFstruct *CDF; struct VarStruct *Var; struct VDRstruct VDR; - void *padValue = va_arg (Va->ap, void *); - Int32 newOffset; /* Offset of VDR after "possibly" being moved. */ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - /************************************************************************** - * Initialize variable. - **************************************************************************/ - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Read the variable's VDR. - **************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (PADvalueBITset(VDR.Flags)) { - /************************************************************************ - * A pad value has already been specified - simply overwrite the existing - * pad value. - ************************************************************************/ - if (!sX(WriteVDR(CDF,CDF->fp,Var->VDRoffset,Var->zVar, - VDR_PADVALUE,padValue, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - else { - /************************************************************************ - * A pad value has not yet been specified. - ************************************************************************/ - int nBytes = (int) (CDFelemSize(VDR.DataType) * VDR.NumElems); - SetBit32 (&VDR.Flags,VDR_PADVALUE_BIT); - if (!sX(ResizeIR(CDF,Var->VDRoffset, - VDR.RecordSize+nBytes, - &newOffset,TRUE,NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - VDR.RecordSize += nBytes; - if (!sX(WriteVDR(CDF,CDF->fp,newOffset,Var->zVar, - VDR_RECORD,&VDR,padValue, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (newOffset != Var->VDRoffset) { - if (VDR.Num > 0) { - Int32 prevOffset; - if (!sX(FindVarByNumber(CDF,(VDR.Num-1), - Var->zVar,&prevOffset),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteVDR(CDF,CDF->fp,prevOffset,Var->zVar, - VDR_VDRNEXT,&newOffset, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - else { - if (!sX(WriteGDR(CDF->fp,CDF->GDRoffset, - BOO(Var->zVar,GDR_zVDRHEAD,GDR_rVDRHEAD),&newOffset, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - Var->VDRoffset = newOffset; - - if (zModeON(CDF)) { - CDF->CURzVarOffset = newOffset; - } - else { - if (zOp) { - CDF->CURzVarOffset = newOffset; - } else { - CDF->CURrVarOffset = newOffset; - } - } - - } - } - /************************************************************************** - * Indicate that allocated records may have to be padded when the CDF is - * closed (if the proper type variable). - **************************************************************************/ - switch (Var->vType) { - case STANDARD_: - case SPARSE_RECORDS_: - if (Var->maxAllocated > Var->maxRec) Var->maxWritten = Var->maxRec; - break; - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - case IN_MULTI_: - break; - default: - return CDF_INTERNAL_ERROR; - } - break; - } - - /**************************************************************************** - * rVAR_DATA_/zVAR_DATA_, - ****************************************************************************/ - case rVAR_DATA_: - case zVAR_DATA_: { - /************************************************************************** - * Local variables. - **************************************************************************/ - Logical zOp = (Va->item == zVAR_DATA_); - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 phyRecNum, offset; struct rdSTRUCT *rd; - /************************************************************************** - * Get arguments. - **************************************************************************/ - void *value = va_arg (Va->ap, char *); - /************************************************************************** - * Validate current CDF/variable. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - /************************************************************************** - * Initialize variable. - **************************************************************************/ - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * If a multi-file CDF, open variable file (if closed). - **************************************************************************/ - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar(CDF,Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Write value. - **************************************************************************/ - rd = BOO(zModeON(CDF),&(Var->zRD),BOO(zOp,&(Var->zRD),&(CDF->rRD))); - phyRecNum = (Var->recVary ? rd->recNumber : 0); - offset = IndicesValueOffset(Var->numDims, - rd->dimIndices, - Var->dimVarys, - Var->nPhyDimValues) * Var->NvalueBytes; - if (!sX(WriteVarValues(CDF,Var,phyRecNum, - offset,INT32_ONE,value),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Update last access time. - **************************************************************************/ - Var->accessed_at = CDF->pseudo_clock++; - break; - } - - /**************************************************************************** - * rVAR_HYPERDATA_/zVAR_HYPERDATA_, - ****************************************************************************/ - case rVAR_HYPERDATA_: - case zVAR_HYPERDATA_: { - /************************************************************************** - * Local variables. - **************************************************************************/ - Logical zOp = (Va->item == zVAR_HYPERDATA_); - int dimN; struct CDFstruct *CDF; struct VarStruct *Var; - struct rdSTRUCT *rd; -#if LIMITof64K - long Nvalues, Nbytes; -#endif - /************************************************************************** - * Get arguments. - **************************************************************************/ - void *buffer = va_arg (Va->ap, char *); - /************************************************************************** - * Validate current CDF/variable. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - /************************************************************************** - * Initialize variable. - **************************************************************************/ - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Validate hyper parameters. - **************************************************************************/ - rd = BOO(zModeON(CDF),&(Var->zRD),BOO(zOp,&(Var->zRD),&(CDF->rRD))); - for (dimN = 0; dimN < Var->numDims; dimN++) { - long maxIndex = rd->dimIndices[dimN] + - ((rd->dimCounts[dimN] - 1) * rd->dimIntervals[dimN]); - if (maxIndex >= Var->dimSizes[dimN]) return BAD_DIM_INDEX; - } -#if LIMITof64K - Nvalues = rd->recCount; - for (dimN = 0; dimN < Var->numDims; dimN++) Nvalues *= rd->dimCounts[dimN]; - Nbytes = Nvalues * Var->NvalueBytes; - if (TOObigIBMpc(Nbytes)) return IBM_PC_OVERFLOW; -#endif - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * If a multi-file CDF, open variable file (if closed). - **************************************************************************/ - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar(CDF,Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Write values. - **************************************************************************/ - if (!sX(HyperWrite(CDF,Var,rd,buffer),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Update last access time. - **************************************************************************/ - Var->accessed_at = Cur->cdf->pseudo_clock++; - break; - } - - /**************************************************************************** - * rVAR_SEQDATA_/zVAR_SEQDATA_, - ****************************************************************************/ - case rVAR_SEQDATA_: - case zVAR_SEQDATA_: { - /************************************************************************** - * Local variables. - **************************************************************************/ - Logical zOp = (Va->item == zVAR_SEQDATA_); - struct VarStruct *Var; struct CDFstruct *CDF; Int32 phyRecNum, offset; - /************************************************************************** - * Get arguments. - **************************************************************************/ - void *value = va_arg (Va->ap, char *); - /************************************************************************** - * Validate current CDF/variable. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - /************************************************************************** - * Initialize variable. - **************************************************************************/ - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Compute physical record number and determine if this is a legal write. - **************************************************************************/ - phyRecNum = Var->seqValueOffset / Var->NphyRecValues; - if ((!Var->recVary) && (phyRecNum > 0)) return END_OF_VAR; - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * If a multi-file CDF, open variable file (if closed). - **************************************************************************/ - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar(CDF,Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Write value. - **************************************************************************/ - offset = (Var->seqValueOffset % Var->NphyRecValues) * Var->NvalueBytes; - if (!sX(WriteVarValues(CDF,Var,phyRecNum, - offset,INT32_ONE,value),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Update last access time and current sequential position. - **************************************************************************/ - Var->seqValueOffset++; - Var->accessed_at = Cur->cdf->pseudo_clock++; - break; - } - - /**************************************************************************** - * rVARs_RECDATA_/zVARs_RECDATA_, write physical data records for up to all - * of the rVariables/zVariables. - ****************************************************************************/ - case rVARs_RECDATA_: - case zVARs_RECDATA_: { - /************************************************************************** - * Local variables. - **************************************************************************/ - Logical zOp = (Va->item == zVARs_RECDATA_), zVar; - struct VarStruct *Var; struct CDFstruct *CDF; - Int32 recNum, varNt; Byte1 *tBuffer; int varX; -#if LIMITof64K - long nBytes; -#endif - /************************************************************************** - * Get arguments. - **************************************************************************/ - long nVars = va_arg (Va->ap, long); - long *varNs = va_arg (Va->ap, long *); - void *buffer = va_arg (Va->ap, char *); - /************************************************************************** - * Validate... - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (nVars < 1) return BAD_NUM_VARS; - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Initialize variables and check that each can be accessed. - **************************************************************************/ - for (varX = 0; varX < nVars; varX++) { - if (!sX(VarIdentity(CDF,(Int32)varNs[varX], - zOp,&varNt,&zVar,NULL),&pStatus)) return pStatus; - if (!sX(InitVar(CDF,varNt,zVar,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Check for too large a write under DOS (64K limit). - **************************************************************************/ -#if LIMITof64K - for (varX = 0, nBytes = 0; varX < nVars; varX++) { - if (!sX(VarIdentity(CDF,(Int32)varNs[varX], - zOp,NULL,NULL,&Var),&pStatus)) return pStatus; - nBytes += Var->NphyRecBytes; - } - if (TOObigIBMpc(nBytes)) return IBM_PC_OVERFLOW; -#endif - /************************************************************************** - * Write to each selected variable... - **************************************************************************/ - for (varX = 0, tBuffer = buffer; varX < nVars; varX++) { - /*********************************************************************** - * Get variable... - ***********************************************************************/ - if (!sX(VarIdentity(CDF,(Int32)varNs[varX], - zOp,NULL,NULL,&Var),&pStatus)) return pStatus; - /*********************************************************************** - * If a multi-file CDF, open variable file (if closed). - ***********************************************************************/ - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar(CDF,Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /*********************************************************************** - * Write variable value(s). - ***********************************************************************/ - recNum = BOO(Var->recVary,BOO(zOp,Var->zRD.recNumber, - CDF->rRD.recNumber),0); - if (!sX(WriteVarValues(CDF,Var,recNum,INT32_ZERO, - Var->NphyRecValues,tBuffer),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /*********************************************************************** - * Increment buffer pointer and update time of last access for variable. - ***********************************************************************/ - tBuffer += (size_t) Var->NphyRecBytes; - Var->accessed_at = CDF->pseudo_clock++; - } - - break; - } - /**************************************************************************** - * Look in `cdfput2.c' for these items. - ****************************************************************************/ - case CDF_ENCODING_: - case CDF_MAJORITY_: - case CDF_FORMAT_: - case CDF_COMPRESSION_: - case CDF_LEAPSECONDLASTUPDATED_: - case ATTR_NAME_: - case ATTR_SCOPE_: - case gENTRY_DATA_: - case rENTRY_DATA_: - case zENTRY_DATA_: - case gENTRY_DATASPEC_: - case rENTRY_DATASPEC_: - case zENTRY_DATASPEC_: - case rVAR_COMPRESSION_: - case zVAR_COMPRESSION_: - case rVAR_SPARSERECORDS_: - case zVAR_SPARSERECORDS_: - case rVAR_SPARSEARRAYS_: - case zVAR_SPARSEARRAYS_: - case CDF_CHECKSUM_: - return CDFput2 (Va, Cur); - /**************************************************************************** - * Unknown item, must be the next function. - ****************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } -} -return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfput1_64.c b/cdf36_3-dist/src/lib/cdfput1_64.c deleted file mode 100644 index 6a32f3d..0000000 --- a/cdf36_3-dist/src/lib/cdfput1_64.c +++ /dev/null @@ -1,1019 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `put' operations, part 1. -* -* Version 1.5, 9-Sep-96, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 16-Sep-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.1 16-Sep-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 10-Dec-93, J Love CDF V2.4. Added readonly mode and zMode. -* V1.3 15-Dec-94, J Love CDF V2.5. -* V1.3a 6-Jan-95, J Love Encode/decode changes. More cache-residency. -* V1.3b 15-Mar-95, J Love Solaris 2.3 IDL i/f. Fixed `recNum' argument -* to `LastAllocatedRecord'. -* V1.4 30-May-95, J Love Fixed bug in involving -* use of old VDR offset after the VDR was moved. -* V1.4a 4-Aug-95, J Love CDFexport-related changes. -* V1.5 9-Sep-96, J Love CDF V2.6. -* V2.0 08-Apr-04, M Liu Removed calls to LocateCurrentVar function as -* its offset becomes available when it is -* selected/created. -* V2.1 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* V2.2 16-Nov-05, M Liu Changed code for data spec modification. -99 -* is passed as a special indicator for the -* number of elements as it can't be change. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* CDFput1_64. -******************************************************************************/ - -STATICforIDL CDFstatus CDFput1_64 (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ -CDFstatus tStatus, pStatus = CDF_OK; -switch (Va->item) { - /**************************************************************************** - * rVAR_NAME_/zVAR_NAME_, rename the current variable. A variable with the - * same name must not already exist in the CDF. - ****************************************************************************/ - case rVAR_NAME_: - case zVAR_NAME_: { - Logical zOp = (Va->item == zVAR_NAME_), zVarCur; - struct CDFstruct *CDF; - char *varName = va_arg (Va->ap, char *), tmpName[CDF_VAR_NAME_LEN256+1]; - OFF_T offsetCur, offsetFound; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVarCur = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVarCur) offsetCur = CDF->CURzVarOffset64; - else offsetCur = CDF->CURrVarOffset64; - - if (strlen(varName) > (size_t) CDF_VAR_NAME_LEN256) { - if (!sX(VAR_NAME_TRUNC,&pStatus)) return pStatus; - } - strcpyX (tmpName, varName, CDF_VAR_NAME_LEN256); - if (!ValidVarName(tmpName)) return BAD_VAR_NAME; - /************************************************************************** - * Check that the new variable name is not already in use. Don't flag as - * an error if the new name is the same as the old name (ignoring trailing - * blanks). Trailing blanks may be eliminated. - **************************************************************************/ - tStatus = FindVarByName64 (CDF, tmpName, &offsetFound, NULL, NULL); - switch (tStatus) { - case CDF_OK: - if (offsetFound != offsetCur) return VAR_EXISTS; - break; - case NO_SUCH_VAR: - break; - default: - AbortAccess64 (CDF, UPDATE, noDELETE); - return tStatus; - } - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - NulPad (tmpName, CDF_VAR_NAME_LEN256); - if (!sX(WriteVDR64(CDF,CDF->fp,offsetCur,zVarCur, - VDR_NAME,tmpName, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - - /**************************************************************************** - * rVAR_DATASPEC_/zVAR_DATASPEC_, - * If the data types are not equivalent or the number of elements are - * different, then check for the following: - * 1) if any records have been written - * 2) if a pad value has been specified - * If either is true, then the data specification cannot be changed. - ****************************************************************************/ - case rVAR_DATASPEC_: - case zVAR_DATASPEC_: { - Logical zOp = (Va->item == zVAR_DATASPEC_), zVar; - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 newDataType = (Int32) va_arg (Va->ap, long); - Int32 newNumElems = (Int32) va_arg (Va->ap, long); - Int32 flags, dataType, numElems, maxRec, maxAllocated; OFF_T offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - - if (!ValidDataType(newDataType)) return BAD_DATA_TYPE; - if (newNumElems != -99 && newNumElems < 1) return BAD_NUM_ELEMS; - if (!STRINGdataType(newDataType)) { - if (newNumElems != -99 && newNumElems != 1) return BAD_NUM_ELEMS; - } - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_FLAGS,&flags, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_MAXREC,&maxRec, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * If the data specifications are not equivalent, check if any records have - * been written or allocated or if a pad value has been specified. - **************************************************************************/ - if (!EquivDataTypes(newDataType,dataType) || - (newNumElems != -99 && newNumElems != numElems)) { - if (maxRec > NO_RECORD) return CANNOT_CHANGE; - if (!sX(LastRecord64(CDF,offset,zVar,&maxAllocated),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (maxAllocated > NO_RECORD) return CANNOT_CHANGE; - if (PADvalueBITset(flags)) return CANNOT_CHANGE; - } - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - if (newNumElems == -99) newNumElems = numElems; - /************************************************************************** - * Update the VDR with the new data specification. - **************************************************************************/ - if (!sX(WriteVDR64(CDF,CDF->fp,offset,zVar, - VDR_DATATYPE,&newDataType, - VDR_NUMELEMS,&newNumElems, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * If this variable has been initialized, recalculate the affected - * parameters. - **************************************************************************/ - if (Var != NULL) { - Var->NvalueElems = newNumElems; - Var->NelemBytes = (Int32) CDFelemSize ((long)newDataType); - Var->NvalueBytes = Var->NvalueElems * Var->NelemBytes; - Var->NphyRecElems = Var->NphyRecValues * Var->NvalueElems; - Var->NvirtRecElems = Var->NvirtRecValues * Var->NvalueElems; - Var->NphyRecBytes = Var->NphyRecValues * Var->NvalueBytes; - Var->NvirtRecBytes = Var->NvirtRecValues * Var->NvalueBytes; - if (!sX(ConversionFunction(newDataType,HostEncoding(), - CDF->encoding,CDF->negToPosFp0, - &(Var->EncodeFunction)),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(ConversionFunction(newDataType,CDF->encoding, - CDF->decoding,CDF->negToPosFp0, - &(Var->DecodeFunction)),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - break; - } - - /**************************************************************************** - * rVAR_RECVARY_/zVAR_RECVARY_, - * Can't change if any records have been written or allocated. - ****************************************************************************/ - case rVAR_RECVARY_: - case zVAR_RECVARY_: { - Logical zOp = (Va->item == zVAR_RECVARY_), zVar; - Int32 maxAllocated; OFF_T offset; - struct CDFstruct *CDF; struct VarStruct *Var; struct VDRstruct64 VDR; - long recVariance = va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (VDR.MaxRec > NO_RECORD) return CANNOT_CHANGE; - if (!sX(LastRecord64(CDF,offset,zVar,&maxAllocated),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (maxAllocated > NO_RECORD) return CANNOT_CHANGE; - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - if (recVariance) - SetBit32 (&VDR.Flags,VDR_RECVARY_BIT); - else { - ClearBit32 (&VDR.Flags,VDR_RECVARY_BIT); - if (VDR.blockingFactor > 1) VDR.blockingFactor = 1; - } - if (!sX(WriteVDR64(CDF,CDF->fp,offset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * If this variable has been initialized, recalculate the affected - * parameters. - **************************************************************************/ - if (Var != NULL) { - Var->recVary = BOO(recVariance,VARY,NOVARY); - if (!sX(CalcBF64(CDF,Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - break; - } - - /**************************************************************************** - * rVAR_DIMVARYS_/zVAR_DIMVARYS_ - * Respecify dimension variances for current rVariable/zVariable. Can't - * change if any records have been written or if zMode/2 and really an - * rVariable. - ****************************************************************************/ - case rVAR_DIMVARYS_: - case zVAR_DIMVARYS_: { - Logical zOp = (Va->item == zVAR_DIMVARYS_), zVar; - long *dimVarys = va_arg (Va->ap, long *); - struct CDFstruct *CDF; struct VarStruct *Var; struct VDRstruct64 VDR; - Int32 numDims, maxAllocated; int dimN; OFF_T offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) offset = CDF->CURzVarOffset64; - else offset = CDF->CURrVarOffset64; - - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - - if (CDF->zMode == zMODEon2 && !zVar) return CANNOT_CHANGE; - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (VDR.MaxRec > NO_RECORD) return CANNOT_CHANGE; - if (!sX(LastRecord64(CDF,offset,zVar,&maxAllocated),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (maxAllocated > NO_RECORD) return CANNOT_CHANGE; - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - numDims = BOO(zVar,VDR.zNumDims,CDF->rNumDims); - for (dimN = 0; dimN < numDims; dimN++) { - VDR.DimVarys[dimN] = BOO(dimVarys[dimN],VARY,NOVARY); - } - if (!sX(WriteVDR64(CDF,CDF->fp,offset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * If this variable has been initialized, recalculate its parameters. - *************************************************************************/ - if (Var != NULL) { - if (!sX(CalcDimParms64(CDF,Var->VDRoffset64, - Var->zVar,&(Var->numDims), - Var->dimSizes,Var->dimVarys),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - CalcNumDimValues (CDF, Var); - CalcRecValues (Var); - Var->NphyRecElems = Var->NphyRecValues * Var->NvalueElems; - Var->NphyRecBytes = Var->NphyRecValues * Var->NvalueBytes; - if (!sX(CalcBF64(CDF,Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - break; - } - - /**************************************************************************** - * rVAR_ALLOCATERECS_/zVAR_ALLOCATERECS_ - * rVAR_ALLOCATEBLOCK_/zVAR_ALLOCATEBLOCK_ - ****************************************************************************/ - case rVAR_ALLOCATERECS_: - case zVAR_ALLOCATERECS_: - case rVAR_ALLOCATEBLOCK_: - case zVAR_ALLOCATEBLOCK_: { - Logical zOp = (Va->item == zVAR_ALLOCATERECS_ || - Va->item == zVAR_ALLOCATEBLOCK_); - Logical blockOp = (Va->item == rVAR_ALLOCATEBLOCK_ || - Va->item == zVAR_ALLOCATEBLOCK_); - struct CDFstruct *CDF; struct VarStruct *Var; struct AllocStruct alloc; - long firstRecN, lastRecN; - if (blockOp) { - firstRecN = va_arg (Va->ap, long); - lastRecN = va_arg (Va->ap, long); - } - else { - firstRecN = 0; - lastRecN = va_arg(Va->ap,long) - 1; - } - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (firstRecN < 0) return BAD_ALLOCATE_RECS; - if (lastRecN < firstRecN) return BAD_ALLOCATE_RECS; - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!Var->recVary && (firstRecN != 0 || lastRecN != 0)) { - return BAD_ALLOCATE_RECS; - } - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Depending on variable type... - **************************************************************************/ - switch (Var->vType) { - case STANDARD_: - if (firstRecN > Var->maxAllocated + 1) { - firstRecN = Var->maxAllocated + 1; - sX (PRECEEDING_RECORDS_ALLOCATED, &pStatus); - } - /* No `break' is deliberate. */ - case SPARSE_RECORDS_: - LoadAllocVVR64 (alloc, firstRecN, lastRecN, FALSE) - if (!sX(AllocateRecords64(CDF,Var,alloc),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->maxAllocated = MAXIMUM(lastRecN,Var->maxAllocated); - break; - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - return CANNOT_ALLOCATE_RECORDS; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return CANNOT_ALLOCATE_RECORDS; - case IN_MULTI_: - sX (MULTI_FILE_FORMAT, &pStatus); - break; - default: - return CDF_INTERNAL_ERROR; - } - break; - } - - /**************************************************************************** - * rVAR_INITIALRECS_/zVAR_INITIALRECS_, - * Specify (write) an initial number of records for the current variable. - * Can't set if any records have been written already. - ****************************************************************************/ - case rVAR_INITIALRECS_: - case zVAR_INITIALRECS_: { - Logical zOp = (Va->item == zVAR_INITIALRECS_); - struct CDFstruct *CDF; struct VarStruct *Var; - long recNum, valueN; int how; void *buffer; long offset; - long nInitialRecs = va_arg (Va->ap, long); OFF_T nValues; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (Var->maxRec > NO_RECORD) return CANNOT_CHANGE; - if (nInitialRecs < 1) return BAD_INITIAL_RECS; - if (!Var->recVary && nInitialRecs > 1) return BAD_INITIAL_RECS; - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar64(CDF,Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - if (!sX(BuildPadBuffer64(CDF,Var,(Int32)nInitialRecs, - &how,&buffer,FALSE),&pStatus)) return pStatus; - switch (how) { - case ALLrecordsATonce: - nValues = (OFF_T) nInitialRecs * Var->NphyRecValues; - if (!sX(WriteVarValues64(CDF,Var,INT32_ZERO,INT32_ZERO, - nValues,buffer),&pStatus)) { - cdf_FreeMemory (buffer, NULL); - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - case ONErecordATaTIME: - for (recNum = 0; recNum < nInitialRecs; recNum++) { - if (!sX(WriteVarValues64(CDF,Var,(Int32)recNum,INT32_ZERO, - (OFF_T) Var->NphyRecValues,buffer),&pStatus)) { - cdf_FreeMemory (buffer, NULL); - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - break; - case ONEvalueATaTIME: - for (recNum = 0; recNum < nInitialRecs; recNum++) { - for (valueN = 0; valueN < Var->NphyRecValues; valueN++) { - offset = valueN * Var->NvalueBytes; - if (!sX(WriteVarValues64(CDF,Var,(Int32)recNum, - (Int32)offset, - (OFF_T) 1,buffer),&pStatus)) { - cdf_FreeMemory (buffer, NULL); - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - } - break; - } - cdf_FreeMemory (buffer, NULL); - break; - } - - /**************************************************************************** - * rVAR_BLOCKINGFACTOR_/zVAR_BLOCKINGFACTOR_ - ****************************************************************************/ - case rVAR_BLOCKINGFACTOR_: - case zVAR_BLOCKINGFACTOR_: { - Logical zOp = (Va->item == zVAR_BLOCKINGFACTOR_); - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 blocking = (Int32) va_arg (Va->ap, long), flags; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Validate blocking factor. Zero (0) is valid meaning that the default - * is to be used. - **************************************************************************/ - switch (Var->vType) { - case STANDARD_: - break; - case SPARSE_RECORDS_: - if (Var->stage.areaOffset64 != (OFF_T) NO_OFFSET64) return CANNOT_CHANGE; - break; - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - if (Var->maxRec > NO_RECORD) return CANNOT_CHANGE; - break; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return UNKNOWN_SPARSENESS; - case IN_MULTI_: - break; - default: - return CDF_INTERNAL_ERROR; - } - if (blocking < 0) return BAD_BLOCKING_FACTOR; - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Update VDR with new blocking factor. - **************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_FLAGS,&flags, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!RECvaryBITset(flags) && blocking > 1) { - blocking = 1; - sX (FORCED_PARAMETER, &pStatus); - } - if (!sX(WriteVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_BLOCKING,&blocking, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Recalculate the variable parameters. - *************************************************************************/ - if (!sX(CalcBF64(CDF,Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - - /**************************************************************************** - * rVAR_PADVALUE_/zVAR_PADVALUE_ - ****************************************************************************/ - case rVAR_PADVALUE_: - case zVAR_PADVALUE_: { - Logical zOp = (Va->item == zVAR_PADVALUE_); - struct CDFstruct *CDF; struct VarStruct *Var; struct VDRstruct64 VDR; - void *padValue = va_arg (Va->ap, void *); - OFF_T newOffset; /* Offset of VDR after "possibly" being moved. */ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - /************************************************************************** - * Initialize variable. - **************************************************************************/ - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - if (Var->dataType == CDF_TIME_TT2000) { - if (!UpdateTT2000header(CDF,&pStatus)) return pStatus; - } - /************************************************************************** - * Read the variable's VDR. - **************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (PADvalueBITset(VDR.Flags)) { - /************************************************************************ - * A pad value has already been specified - simply overwrite the existing - * pad value. - ************************************************************************/ - if (!sX(WriteVDR64(CDF,CDF->fp,Var->VDRoffset64,Var->zVar, - VDR_PADVALUE,padValue, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - else { - /************************************************************************ - * A pad value has not yet been specified. - ************************************************************************/ - int nBytes = (int) (CDFelemSize(VDR.DataType) * VDR.NumElems); - SetBit32 (&VDR.Flags,VDR_PADVALUE_BIT); - if (!sX(ResizeIR64(CDF,Var->VDRoffset64, - VDR.RecordSize+nBytes, - &newOffset,TRUE,NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - VDR.RecordSize += nBytes; - if (!sX(WriteVDR64(CDF,CDF->fp,newOffset,Var->zVar, - VDR_RECORD,&VDR,padValue, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (newOffset != Var->VDRoffset64) { - if (VDR.Num > 0) { - OFF_T prevOffset; - if (!sX(FindVarByNumber64(CDF,(VDR.Num-1), - Var->zVar,&prevOffset),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteVDR64(CDF,CDF->fp,prevOffset,Var->zVar, - VDR_VDRNEXT,&newOffset, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - else { - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - BOO(Var->zVar,GDR_zVDRHEAD,GDR_rVDRHEAD),&newOffset, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - Var->VDRoffset64 = newOffset; - - if (zModeON(CDF)) { - CDF->CURzVarOffset64 = newOffset; - } - else { - if (zOp) { - CDF->CURzVarOffset64 = newOffset; - } else { - CDF->CURrVarOffset64 = newOffset; - } - } - - } - } - /************************************************************************** - * Indicate that allocated records may have to be padded when the CDF is - * closed (if the proper type variable). - **************************************************************************/ - switch (Var->vType) { - case STANDARD_: - case SPARSE_RECORDS_: - if (Var->maxAllocated > Var->maxRec) Var->maxWritten = Var->maxRec; - break; - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - case IN_MULTI_: - break; - default: - return CDF_INTERNAL_ERROR; - } - break; - } - - /**************************************************************************** - * rVAR_DATA_/zVAR_DATA_, - ****************************************************************************/ - case rVAR_DATA_: - case zVAR_DATA_: { - /************************************************************************** - * Local variables. - **************************************************************************/ - Logical zOp = (Va->item == zVAR_DATA_); - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 phyRecNum; struct rdSTRUCT *rd; Int32 offset; - /************************************************************************** - * Get arguments. - **************************************************************************/ - void *value = va_arg (Va->ap, char *); - /************************************************************************** - * Validate current CDF/variable. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - /************************************************************************** - * Initialize variable. - **************************************************************************/ - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - if (Var->dataType == CDF_TIME_TT2000) { - if (!UpdateTT2000header(CDF,&pStatus)) return pStatus; - } - /************************************************************************** - * If a multi-file CDF, open variable file (if closed). - **************************************************************************/ - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar64(CDF,Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Write value. - **************************************************************************/ - rd = BOO(zModeON(CDF),&(Var->zRD),BOO(zOp,&(Var->zRD),&(CDF->rRD))); - phyRecNum = (Var->recVary ? rd->recNumber : 0); - offset = IndicesValueOffset(Var->numDims, - rd->dimIndices, - Var->dimVarys, - Var->nPhyDimValues) * Var->NvalueBytes; - if (!sX(WriteVarValues64(CDF,Var,phyRecNum, - offset,(OFF_T) 1,value),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Update last access time. - **************************************************************************/ - Var->accessed_at = CDF->pseudo_clock++; - if (!sX(SetLeapSecondLastUpdate (CDF, Var, zOp), &pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - - /**************************************************************************** - * rVAR_HYPERDATA_/zVAR_HYPERDATA_, - ****************************************************************************/ - case rVAR_HYPERDATA_: - case zVAR_HYPERDATA_: { - /************************************************************************** - * Local variables. - **************************************************************************/ - Logical zOp = (Va->item == zVAR_HYPERDATA_); - int dimN; struct CDFstruct *CDF; struct VarStruct *Var; - struct rdSTRUCT *rd; -#if LIMITof64K - long Nvalues, Nbytes; -#endif - /************************************************************************** - * Get arguments. - **************************************************************************/ - void *buffer = va_arg (Va->ap, char *); - /************************************************************************** - * Validate current CDF/variable. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - /************************************************************************** - * Initialize variable. - **************************************************************************/ - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Validate hyper parameters. - **************************************************************************/ - rd = BOO(zModeON(CDF),&(Var->zRD),BOO(zOp,&(Var->zRD),&(CDF->rRD))); - for (dimN = 0; dimN < Var->numDims; dimN++) { - long maxIndex = rd->dimIndices[dimN] + - ((rd->dimCounts[dimN] - 1) * rd->dimIntervals[dimN]); - if (maxIndex >= Var->dimSizes[dimN]) return BAD_DIM_INDEX; - } -#if LIMITof64K - Nvalues = rd->recCount; - for (dimN = 0; dimN < Var->numDims; dimN++) Nvalues *= rd->dimCounts[dimN]; - Nbytes = Nvalues * Var->NvalueBytes; - if (TOObigIBMpc(Nbytes)) return IBM_PC_OVERFLOW; -#endif - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - if (Var->dataType == CDF_TIME_TT2000) { - if (!UpdateTT2000header(CDF,&pStatus)) return pStatus; - } - /************************************************************************** - * If a multi-file CDF, open variable file (if closed). - **************************************************************************/ - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar64(CDF,Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Write values. - **************************************************************************/ - if (!sX(HyperWrite64(CDF,Var,rd,buffer),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Update last access time. - **************************************************************************/ - Var->accessed_at = Cur->cdf->pseudo_clock++; - if (!sX(SetLeapSecondLastUpdate (CDF, Var, zOp), &pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - - /**************************************************************************** - * rVAR_SEQDATA_/zVAR_SEQDATA_, - ****************************************************************************/ - case rVAR_SEQDATA_: - case zVAR_SEQDATA_: { - /************************************************************************** - * Local variables. - **************************************************************************/ - Logical zOp = (Va->item == zVAR_SEQDATA_); - struct VarStruct *Var; struct CDFstruct *CDF; Int32 phyRecNum; - Int32 offset; - /************************************************************************** - * Get arguments. - **************************************************************************/ - void *value = va_arg (Va->ap, char *); - /************************************************************************** - * Validate current CDF/variable. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - /************************************************************************** - * Initialize variable. - **************************************************************************/ - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Compute physical record number and determine if this is a legal write. - **************************************************************************/ - phyRecNum = (Int32) (Var->seqValueOffset64 / (OFF_T) Var->NphyRecValues); - if ((!Var->recVary) && (phyRecNum > 0)) return END_OF_VAR; - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - if (Var->dataType == CDF_TIME_TT2000) { - if (!UpdateTT2000header(CDF,&pStatus)) return pStatus; - } - /************************************************************************** - * If a multi-file CDF, open variable file (if closed). - **************************************************************************/ - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar64(CDF,Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Write value. - **************************************************************************/ - offset = (Int32) (Var->seqValueOffset64 % (OFF_T) Var->NphyRecValues) * - Var->NvalueBytes; - if (!sX(WriteVarValues64(CDF,Var,phyRecNum, - offset,(OFF_T) 1,value),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Update last access time and current sequential position. - **************************************************************************/ - Var->seqValueOffset64++; - Var->accessed_at = Cur->cdf->pseudo_clock++; - if (!sX(SetLeapSecondLastUpdate (CDF, Var, zOp), &pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - - /**************************************************************************** - * rVARs_RECDATA_/zVARs_RECDATA_, write physical data records for up to all - * of the rVariables/zVariables. - ****************************************************************************/ - case rVARs_RECDATA_: - case zVARs_RECDATA_: { - /************************************************************************** - * Local variables. - **************************************************************************/ - Logical zOp = (Va->item == zVARs_RECDATA_), zVar; - struct VarStruct *Var; struct CDFstruct *CDF; - Int32 recNum, varNt; Byte1 *tBuffer; int varX; -#if LIMITof64K - long nBytes; -#endif - /************************************************************************** - * Get arguments. - **************************************************************************/ - long nVars = va_arg (Va->ap, long); - long *varNs = va_arg (Va->ap, long *); - void *buffer = va_arg (Va->ap, char *); - /************************************************************************** - * Validate... - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (nVars < 1) return BAD_NUM_VARS; - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Initialize variables and check that each can be accessed. - **************************************************************************/ - for (varX = 0; varX < nVars; varX++) { - if (!sX(VarIdentity(CDF,(Int32)varNs[varX], - zOp,&varNt,&zVar,NULL),&pStatus)) return pStatus; - if (!sX(InitVar64(CDF,varNt,zVar,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /************************************************************************** - * Check for too large a write under DOS (64K limit). - **************************************************************************/ -#if LIMITof64K - for (varX = 0, nBytes = 0; varX < nVars; varX++) { - if (!sX(VarIdentity(CDF,(Int32)varNs[varX], - zOp,NULL,NULL,&Var),&pStatus)) return pStatus; - nBytes += Var->NphyRecBytes; - } - if (TOObigIBMpc(nBytes)) return IBM_PC_OVERFLOW; -#endif - /************************************************************************** - * Write to each selected variable... - **************************************************************************/ - for (varX = 0, tBuffer = buffer; varX < nVars; varX++) { - /*********************************************************************** - * Get variable... - ***********************************************************************/ - if (!sX(VarIdentity(CDF,(Int32)varNs[varX], - zOp,NULL,NULL,&Var),&pStatus)) return pStatus; - /*********************************************************************** - * If a multi-file CDF, open variable file (if closed). - ***********************************************************************/ - if (!CDF->singleFile && Var->fp == NULL) { - if (!sX(OpenVar64(CDF,Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - /*********************************************************************** - * Write variable value(s). - ***********************************************************************/ - recNum = BOO(Var->recVary,BOO(zOp,Var->zRD.recNumber, - CDF->rRD.recNumber),0); - if (!sX(WriteVarValues64(CDF,Var,recNum,INT32_ZERO, - (OFF_T) Var->NphyRecValues,tBuffer),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /*********************************************************************** - * Increment buffer pointer and update time of last access for variable. - ***********************************************************************/ - tBuffer += (size_t) Var->NphyRecBytes; - Var->accessed_at = CDF->pseudo_clock++; - } - if (!sX(SetLeapSecondLastUpdate (CDF, Var, zOp), &pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * Look in `cdfput2.c' for these items. - ****************************************************************************/ - case CDF_ENCODING_: - case CDF_MAJORITY_: - case CDF_FORMAT_: - case CDF_COMPRESSION_: - case ATTR_NAME_: - case ATTR_SCOPE_: - case gENTRY_DATA_: - case rENTRY_DATA_: - case zENTRY_DATA_: - case gENTRY_DATASPEC_: - case rENTRY_DATASPEC_: - case zENTRY_DATASPEC_: - case rVAR_COMPRESSION_: - case zVAR_COMPRESSION_: - case rVAR_SPARSERECORDS_: - case zVAR_SPARSERECORDS_: - case rVAR_SPARSEARRAYS_: - case zVAR_SPARSEARRAYS_: - case CDF_CHECKSUM_: - case CDF_LEAPSECONDLASTUPDATED_: - return CDFput2_64 (Va, Cur); - /**************************************************************************** - * Unknown item, must be the next function. - ****************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } -} -return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfput2.c b/cdf36_3-dist/src/lib/cdfput2.c deleted file mode 100644 index 17cd578..0000000 --- a/cdf36_3-dist/src/lib/cdfput2.c +++ /dev/null @@ -1,1039 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `put' operations, part 2. -* -* Version 1.4a, 21-Feb-97, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 16-Sep-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 24-Jan-94, J Love CDF V2.4. -* V1.3 5-Dec-94, J Love CDF V2.5. -* V1.3a 6-Jan-95, J Love Encode/decode changes. More cache-residency. -* V1.3b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.3c 4-Aug-95, J Love CDFexport-related changes. -* V1.4 3-Oct-96, J Love CDF V2.6. -* V1.4a 21-Feb-97, J Love Removed RICE. -* V2.0 08-Apr-04, M Liu Removed calls to LocateCurrentVar function as -* its offset becomes available when it is -* selected/created. -* V2.1 16-Nov-05, M Liu Changed code for data spec modification. -99 -* is passed as a special indicator for the -* number of elements as it can't be change. -* -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* CDFput2. -******************************************************************************/ - -STATICforIDL CDFstatus CDFput2 (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ -CDFstatus tStatus, pStatus = CDF_OK; - -switch (Va->item) { - /**************************************************************************** - * CDF_ENCODING_, - * Can't change if any variables have been written to (including pad - * values). Can't change if any attribute entries have been written. - ****************************************************************************/ - case CDF_ENCODING_: { - struct CDFstruct *CDF; - Int32 actualEncoding; - Int32 encoding = (Int32) va_arg (Va->ap, long); - Logical no; - SelectCDF (Cur->cdf, CDF) - if (!ValidEncoding(encoding,&actualEncoding)) return BAD_ENCODING; - if (!sX(VerifyNoRecordsWritten(CDF,&no),&pStatus)) return pStatus; - if (!no) return CANNOT_CHANGE; - if (!sX(VerifyNoPadsSpecified(CDF,&no),&pStatus)) return pStatus; - if (!no) return CANNOT_CHANGE; - if (!sX(VerifyNoEntriesWritten(CDF,&no),&pStatus)) return pStatus; - if (!no) return CANNOT_CHANGE; - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - CDF->encoding = actualEncoding; - /************************************************************************** - * Update the `encoding' field in the CDR. - **************************************************************************/ - if (!sX(WriteCDR(CDF->fp,V2_CDR_OFFSET, - CDR_ENCODING,&(CDF->encoding), - CDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Update the initialized variables for the new encoding. - **************************************************************************/ - if (!sX(UpdateConversions(CDF),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * CDF_MAJORITY_, - * Can't change if any variable values have been written. - ****************************************************************************/ - case CDF_MAJORITY_: { - struct CDFstruct *CDF; - long majority = va_arg (Va->ap,long); - Logical no, zVar; Int32 CDRflags; - SelectCDF (Cur->cdf, CDF) - if (majority != ROW_MAJOR && majority != COLUMN_MAJOR) return BAD_MAJORITY; - if (!sX(VerifyNoRecordsWritten(CDF,&no),&pStatus)) return pStatus; - if (!no) return CANNOT_CHANGE; - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - CDF->rowMajor = ROWmajor(majority); - /************************************************************************** - * Update the `flags' field in the CDR. - **************************************************************************/ - if (!sX(ReadCDR(CDF->fp,CDF->CDRoffset, - CDR_FLAGS,&CDRflags, - CDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (CDF->rowMajor) - SetBit32 (&CDRflags, CDR_MAJORITY_BIT); - else - ClearBit32 (&CDRflags, CDR_MAJORITY_BIT); - if (!sX(WriteCDR(CDF->fp,V2_CDR_OFFSET, - CDR_FLAGS,&CDRflags, - CDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Update the initialized variables for the new majority. - **************************************************************************/ - for (zVar = 0; zVar <= 1; zVar++) { - int varN; Int32 nVars = BOO(zVar,CDF->NzVars,CDF->NrVars); - for (varN = 0; varN < nVars; varN++) { - struct VarStruct *Var = BOO(zVar,CDF->zVars[varN],CDF->rVars[varN]); - if (Var != NULL) CalcNumDimValues (CDF, Var); - } - } - break; - } - /**************************************************************************** - * CDF_FORMAT_, - * Can't change if any variables have been created or if a compressed - * single-file CDF. - ****************************************************************************/ - case CDF_FORMAT_: { - long format = va_arg (Va->ap,long); - struct CDFstruct *CDF; Int32 CDRflags; - SelectCDF (Cur->cdf, CDF) - if (format != SINGLE_FILE && format != MULTI_FILE) return BAD_FORMAT; - if (CDF->NrVars > 0) return CANNOT_CHANGE; - if (CDF->NzVars > 0) return CANNOT_CHANGE; - if (CDF->uDotFp != NULL) return CANNOT_CHANGE; - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - if (format == MULTI_FILE && CDF->checksum != NO_CHECKSUM) - return CANNOT_CHANGE; - CDF->singleFile = (format == SINGLE_FILE); - /************************************************************************** - * Update the `flags' field in the CDR. - **************************************************************************/ - if (!sX(ReadCDR(CDF->fp,CDF->CDRoffset, - CDR_FLAGS,&CDRflags, - CDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - - if (CDF->singleFile) - SetBit32 (&CDRflags, CDR_FORMAT_BIT); - else - ClearBit32 (&CDRflags, CDR_FORMAT_BIT); - if (!sX(WriteCDR(CDF->fp,V2_CDR_OFFSET, - CDR_FLAGS,&CDRflags, - CDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Reset cache size for "working" dotCDF file to the default for the CDF's - * format. - **************************************************************************/ - CDF->workingCacheSize = BOO(CDF->singleFile,NUMcacheSINGLE,NUMcacheMULTI); - if (!CACHEv(CDF->fp,CDF->workingCacheSize)) { - AbortAccess (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - break; - } - /**************************************************************************** - * CDF_LEAPSECONDLASTUPDATED, - ****************************************************************************/ - case CDF_LEAPSECONDLASTUPDATED_: { - long lastUpdated = va_arg (Va->ap, long); /* Last updated day. */ - break; - } - /**************************************************************************** - * CDF_COMPRESSION_ - ****************************************************************************/ - case CDF_COMPRESSION_: { - long cType = va_arg (Va->ap, long); /* Compression type. */ - long *cParms = va_arg (Va->ap, long *); /* Compression parameters. */ - struct CDFstruct *CDF; int parmN; vSTATS vStats; - SelectCDF (Cur->cdf, CDF) - /************************************************************************** - * Validate compression type/parameters. - **************************************************************************/ - if (!sX(ValidateCompression(cType,cParms),&pStatus)) return pStatus; - /************************************************************************** - * Verify that compression is not being attempted on a multi-file CDF. (It - * is allowed to specify no compression.) - **************************************************************************/ - if (!CDF->singleFile) { - if (cType != NO_COMPRESSION) return CANNOT_COMPRESS; - break; - } - /************************************************************************** - * Depending on the type of compression... - **************************************************************************/ - switch (cType) { - /************************************************************************ - * Turning off compression. - ************************************************************************/ - case NO_COMPRESSION: - /********************************************************************** - * If the CDF is currently compressed... - **********************************************************************/ - if (CDF->uDotFp != NULL) { - char pathName[DU_MAX_PATH_LEN+1]; - /******************************************************************** - * First get write access. - ********************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /******************************************************************** - * Delete the compressed dotCDF file. - ********************************************************************/ - if (!DELETEv(CDF->dotFp,&vStats)) { - CDF->dotFp = NULL; - AbortAccess (CDF, UPDATE, noDELETE); - return CDF_CLOSE_ERROR; - } - CDF->dotFp = NULL; - AddTOvStats (&CDF->dotCDFvStats, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "DotCDF..", &vStats); -#endif - /******************************************************************** - * Recreate the dotCDF file (now uncompressed) and set its cache size - * to that of the "working" dotCDF file (which it now has become). - ********************************************************************/ - BuildFilePath (CDFt, CDF->CDFname, CDF->no_append, - CDF->upper_case_ext, CDF->version_numbers, - INT32_ZERO, pathName); - CDF->dotFp = V_open (pathName, WRITE_PLUS_a_mode); - if (CDF->dotFp == NULL) { - AbortAccess (CDF, UPDATE, noDELETE); - return CDF_CREATE_ERROR; - } - if (!CACHEv(CDF->dotFp,CDF->workingCacheSize)) { - AbortAccess (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - /******************************************************************** - * Copy the uncompressed dotCDF file to the recreated dotCDF file. - ********************************************************************/ - if (!sX(CopyCDF(CDF->uDotFp,CDF->dotFp),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /******************************************************************** - * Flush the recreated dotCDF file. - ********************************************************************/ - if (!FLUSHv(CDF->dotFp)) { - AbortAccess (CDF, UPDATE, noDELETE); - return CDF_WRITE_ERROR; - } - /******************************************************************** - * Delete the uncompressed dotCDF file. - ********************************************************************/ - if (!DELETEv(CDF->uDotFp,&vStats)) { - CDF->uDotFp = NULL; - AbortAccess (CDF, UPDATE, noDELETE); - return SCRATCH_DELETE_ERROR; - } - CDF->uDotFp = NULL; - AddTOvStats (&CDF->uDotCDFvStats, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "uDotCDF.", &vStats); -#endif - /******************************************************************** - * Reset the "working" dotCDF file. - ********************************************************************/ - CDF->fp = CDF->dotFp; - } - break; - /************************************************************************ - * Turning on/changing compression. - ************************************************************************/ - case RLE_COMPRESSION: - case HUFF_COMPRESSION: - case AHUFF_COMPRESSION: - case GZIP_COMPRESSION: { - char pathName[DU_MAX_PATH_LEN+1]; struct CPRstruct CPR; Int32 pCount; - /********************************************************************** - * Get read/write access. - **********************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /********************************************************************** - * If the CDF is not currently compressed, create an uncompressed dotCDF - * file and copy the current contents into it. - **********************************************************************/ - if (CDF->uDotFp == NULL) { - CDF->uDotFp = V_scratch (ScratchDirectory(CDF), "cdf"); - if (CDF->uDotFp == NULL) { - AbortAccess (CDF, UPDATE, noDELETE); - return CDF_CREATE_ERROR; - } - if (!CACHEv(CDF->uDotFp,CDF->workingCacheSize)) { - AbortAccess (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - if (!sX(CopyCDF(CDF->dotFp,CDF->uDotFp),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!FLUSHv(CDF->uDotFp)) { - AbortAccess (CDF, UPDATE, noDELETE); - return CDF_WRITE_ERROR; - } - CDF->fp = CDF->uDotFp; - } - /********************************************************************** - * Delete/recreate the dotCDF file and write a CCR and CPR. - **********************************************************************/ - if (!DELETEv(CDF->dotFp,&vStats)) { - CDF->dotFp = NULL; - AbortAccess (CDF, UPDATE, noDELETE); - return CDF_DELETE_ERROR; - } - CDF->dotFp = NULL; - AddTOvStats (&CDF->dotCDFvStats, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "DotCDF..", &vStats); -#endif - BuildFilePath (CDFt, CDF->CDFname, CDF->no_append, - CDF->upper_case_ext, CDF->version_numbers, - INT32_ZERO, pathName); - CDF->dotFp = V_open (pathName, WRITE_PLUS_a_mode); - if (CDF->dotFp == NULL) { - AbortAccess (CDF, UPDATE, noDELETE); - return CDF_CREATE_ERROR; - } - pCount = CompressionParmsCount ((Int32) cType); - CPR.RecordSize = CPR_BASE_SIZE + (pCount * sizeof(Int32)); - CPR.RecordType = CPR_; - CPR.rfuA = 0; - CPR.cType = (Int32) cType; - CPR.pCount = pCount; - for (parmN = 0; parmN < pCount; parmN++) { - CPR.cParms[parmN] = (Int32) cParms[parmN]; - } - if (!sX(WriteCompressedCDF(CDF,&CPR,EMPTY),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!FLUSHv(CDF->dotFp)) { - AbortAccess (CDF, UPDATE, noDELETE); - return CDF_WRITE_ERROR; - } - break; - } - } - break; - } - /**************************************************************************** - * r/zVAR_COMPRESSION_ - ****************************************************************************/ - case rVAR_COMPRESSION_: - case zVAR_COMPRESSION_: { - Logical zOp = (Va->item == zVAR_COMPRESSION_), zVar; - Int32 VDRoffset, maxAllocated, pCount; int p; - struct CDFstruct *CDF; struct VarStruct *Var; - struct VDRstruct VDR; struct CPRstruct CPR; - long cType = va_arg (Va->ap, long); /* Compression type. */ - long *cParms = va_arg (Va->ap, long *); /* Compression parameters. */ - /************************************************************************** - * Verify the current CDF and variable and that this operation is legal for - * the current zMode. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - /************************************************************************** - * Validate compression type/parameters. - **************************************************************************/ - if (!sX(ValidateCompression(cType,cParms),&pStatus)) return pStatus; - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Verify that compression isn't being attempted on a multi-file CDF. (It - * is allowed to specify no compression.) After this point a single-file - * CDF can be assumed. - **************************************************************************/ - if (!CDF->singleFile) { - if (cType != NO_COMPRESSION) return CANNOT_COMPRESS; - break; - } - /************************************************************************** - * Locate the current variable. - **************************************************************************/ - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) VDRoffset = CDF->CURzVarOffset; - else VDRoffset = CDF->CURrVarOffset; - - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - /************************************************************************** - * Read VDR. - **************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,VDRoffset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Verify that no records have been written or allocated. If so, the - * compression cannot be changed. - **************************************************************************/ - if (!sX(LastRecord(CDF,VDRoffset,zVar,&maxAllocated),&pStatus)){ - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (maxAllocated > NO_RECORD) return CANNOT_COMPRESS; - if (VDR.MaxRec > NO_RECORD) return CANNOT_COMPRESS; - /************************************************************************** - * If array sparseness is selected, then the variable cannot be compressed. - **************************************************************************/ - if (SPARSEarraysBITset(VDR.Flags)) { - if (cType != NO_COMPRESSION) return CANNOT_COMPRESS; - } - /************************************************************************** - * Disable current compression (if any). - **************************************************************************/ - if (VARcompressionBITset(VDR.Flags)) { - ClearBit32 (&VDR.Flags, VDR_COMPRESSION_BIT); - if (!sX(ReadCPR(CDF->fp,VDR.CPRorSPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WasteIR(CDF,VDR.CPRorSPRoffset,CPR.RecordSize),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - VDR.CPRorSPRoffset = NO_OFFSET; - } - /************************************************************************** - * Set up new compression. - **************************************************************************/ - switch (cType) { - case NO_COMPRESSION: - break; - case RLE_COMPRESSION: - case HUFF_COMPRESSION: - case AHUFF_COMPRESSION: - case GZIP_COMPRESSION: - pCount = CompressionParmsCount ((Int32) cType); - SetBit32 (&VDR.Flags, VDR_COMPRESSION_BIT); - CPR.RecordSize = CPR_BASE_SIZE + (pCount * sizeof(Int32)); - CPR.RecordType = CPR_; - CPR.cType = (Int32) cType; - CPR.rfuA = 0; - CPR.pCount = pCount; - for (p = 0; p < pCount; p++) CPR.cParms[p] = (Int32) cParms[p]; - if (!sX(AllocateIR(CDF,CPR.RecordSize,&VDR.CPRorSPRoffset),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteCPR(CDF->fp,VDR.CPRorSPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /************************************************************************** - * Update VDR. - **************************************************************************/ - if (!sX(WriteVDR(CDF,CDF->fp,VDRoffset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * If this variable has been initialized, recalculate the affected - * parameters. - **************************************************************************/ - if (Var != NULL) { - if (!sX(VariableType(CDF,VDRoffset,zVar,&(Var->vType)),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (cType != NO_COMPRESSION) { - Var->cType = (Int32) cType; - for (p = 0; p < pCount; p++) Var->cParms[p] = (Int32) cParms[p]; - Var->reservePct = 0; - } - if (!sX(CalcBF(CDF,Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - break; - } - /**************************************************************************** - * CDF_CHECKSUM_, - ****************************************************************************/ - case CDF_CHECKSUM_: { - long checksumValue = va_arg (Va->ap,long); - Int32 version, release; - struct CDFstruct *CDF; Int32 CDRflags; - SelectCDF (Cur->cdf, CDF) - - if (!CDF->singleFile) return CANNOT_CHANGE; - if (checksumValue != NONE_CHECKSUM && - checksumValue != MD5_CHECKSUM && - checksumValue != OTHER_CHECKSUM) return BAD_CHECKSUM; - /************************************************************************** - * Update the `flags' field in the CDR. - **************************************************************************/ - if (!sX(ReadCDR(CDF->fp,V2_CDR_OFFSET, - CDR_VERSION,&version, - CDR_RELEASE,&release, - CDR_FLAGS,&CDRflags, - CDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Only apply to Version 2.6 and later CDFs. - **************************************************************************/ - if ((version*100+release) < 206) return CHECKSUM_NOT_ALLOWED; - - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - - if (checksumValue == NONE_CHECKSUM) { - ClearBit32 (&CDRflags, CDR_CHECKSUM_BIT); - ClearBit32 (&CDRflags, CDR_CHECKSUM_MD5_BIT); - ClearBit32 (&CDRflags, CDR_CHECKSUM_OTHER_BIT); - } else { - SetBit32 (&CDRflags, CDR_CHECKSUM_BIT); - if (checksumValue == MD5_CHECKSUM) { - SetBit32 (&CDRflags, CDR_CHECKSUM_MD5_BIT); - ClearBit32 (&CDRflags, CDR_CHECKSUM_OTHER_BIT); - } else { - ClearBit32 (&CDRflags, CDR_CHECKSUM_MD5_BIT); - SetBit32 (&CDRflags, CDR_CHECKSUM_OTHER_BIT); - } - } - if (!sX(WriteCDR(CDF->fp,V2_CDR_OFFSET, - CDR_FLAGS,&CDRflags, - CDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - CDF->checksum = checksumValue; - break; - } - /**************************************************************************** - * r/zVAR_SPARSERECORDS_ - ****************************************************************************/ - case rVAR_SPARSERECORDS_: - case zVAR_SPARSERECORDS_: { - Logical zOp = (Va->item == zVAR_SPARSERECORDS_), zVar; - Int32 VDRoffset, maxAllocated, maxRec, flags; - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 sRecordsType = (Int32) va_arg (Va->ap, long); - /************************************************************************** - * Verify the current CDF and variable and that this operation is legal for - * the current zMode. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Verify that sparseness isn't being attempted on a multi-file CDF. (It - * is allowed to specify sRecords.NO.) After this point a single-file CDF - * can be assumed. - **************************************************************************/ - if (!CDF->singleFile) { - if (sRecordsType != NO_SPARSERECORDS) return CANNOT_SPARSERECORDS; - break; - } - /************************************************************************** - * Locate the current variable. - **************************************************************************/ - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) VDRoffset = CDF->CURzVarOffset; - else VDRoffset = CDF->CURrVarOffset; - - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - /************************************************************************** - * Verify that no records have been written or allocated. If so, the - * sparseness cannot be changed. - **************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,VDRoffset,zVar, - VDR_MAXREC,&maxRec, - VDR_FLAGS,&flags, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (maxRec > NO_RECORD) return CANNOT_SPARSERECORDS; - if (!sX(LastRecord(CDF,VDRoffset,zVar,&maxAllocated),&pStatus)){ - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (maxAllocated > NO_RECORD) return CANNOT_SPARSERECORDS; - if (!RECvaryBITset(flags) && sRecordsType != NO_SPARSERECORDS) - return CANNOT_SPARSERECORDS; - /************************************************************************** - * Based on type of sparseness... - **************************************************************************/ - switch (sRecordsType) { - case NO_SPARSERECORDS: - case PAD_SPARSERECORDS: - case PREV_SPARSERECORDS: - if (!sX(WriteVDR(CDF,CDF->fp,VDRoffset,zVar, - VDR_sRECORDS,&sRecordsType, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - default: - return UNKNOWN_SPARSENESS; - } - /************************************************************************** - * If this variable has been initialized, recalculate the affected - * parameters. - **************************************************************************/ - if (Var != NULL) { - if (!sX(VariableType(CDF,VDRoffset,zVar,&(Var->vType)),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->prevIfMissing = (sRecordsType == PREV_SPARSERECORDS); - } - break; - } - /**************************************************************************** - * r/zVAR_SPARSEARRAYS_ - ****************************************************************************/ - case rVAR_SPARSEARRAYS_: - case zVAR_SPARSEARRAYS_: { - Logical zOp = (Va->item == zVAR_SPARSEARRAYS_); - struct CDFstruct *CDF; - long sArraysType = va_arg (Va->ap, long); /* Sparseness type. */ - (void) va_arg (Va->ap, long *); /* Doing it this way quiets - the Borland C compiler. */ - /************************************************************************** - * Verify the current CDF and variable and that this operation is legal for - * the current zMode. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - /************************************************************************** - * Verify that sparse arrays aren't being attempted on a multi-file CDF. - * (It is allowed to specify no sparse arrays.) - **************************************************************************/ - if (!CDF->singleFile) { - if (sArraysType != NO_SPARSEARRAYS) return CANNOT_SPARSEARRAYS; - break; - } - /************************************************************************** - * Sparse arrays are not yet supported. - **************************************************************************/ - switch (sArraysType) { - case NO_SPARSEARRAYS: - /* Nothing needs to be done until sparse arrays are supported. */ - break; - default: - return UNKNOWN_SPARSENESS; - } - break; - } - /**************************************************************************** - * ATTR_NAME_, - ****************************************************************************/ - case ATTR_NAME_: { - struct CDFstruct *CDF; - char tmpname[CDF_ATTR_NAME_LEN+1]; - char *attrname = va_arg (Va->ap, char *); - Int32 offsetFound; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED(CDF)) return NO_ATTR_SELECTED; - if (strlen(attrname) > (size_t) CDF_ATTR_NAME_LEN) { - if (!sX(ATTR_NAME_TRUNC,&pStatus)) return pStatus; - } - strcpyX (tmpname, attrname, CDF_ATTR_NAME_LEN); - if (!ValidAttrName(tmpname)) return BAD_ATTR_NAME; - /************************************************************************** - * Check that the new attribute name is not already in use. Don't flag as - * an error if the new name is the same as the old name (ignoring trailing - * blanks). Trailing blanks may be being eliminated. - **************************************************************************/ - tStatus = FindAttrByName (CDF, tmpname, &offsetFound); - switch (tStatus) { - case CDF_OK: - if (offsetFound != CDF->CURattrOffset) return ATTR_EXISTS; - break; - case NO_SUCH_ATTR: - break; - default: - AbortAccess (CDF, UPDATE, noDELETE); - return tStatus; - } - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - NulPad (tmpname, CDF_ATTR_NAME_LEN); - if (!sX(WriteADR(CDF->fp,CDF->CURattrOffset, - ADR_NAME,tmpname, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * ATTR_SCOPE_ - ****************************************************************************/ - case ATTR_SCOPE_: { - struct CDFstruct *CDF; - Int32 scope = (Int32) va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED(CDF)) return NO_ATTR_SELECTED; - if (!ValidAttrScope(scope)) return BAD_SCOPE; - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - if (!sX(WriteADR(CDF->fp,CDF->CURattrOffset, - ADR_SCOPE,&scope, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Reset current entry offsets. - **************************************************************************/ - if (!sX(SetCURgrEntry(CDF,FALSE,CDF->CURgrEntryNum),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(SetCURzEntry(CDF,FALSE,CDF->CURzEntryNum),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * gENTRY_DATASPEC_/rENTRY_DATASPEC_/zENTRY_DATASPEC_, change the data - * specification of an existing entry. Currently, only the data type can - * be changed (and must be equivalent). The number of elements must remain - * the same. - ****************************************************************************/ - case rENTRY_DATASPEC_: - case gENTRY_DATASPEC_: - case zENTRY_DATASPEC_: { - int entryType = E3p(Va->item,gENTRY_DATASPEC_, - rENTRY_DATASPEC_, - zENTRY_DATASPEC_); - struct CDFstruct *CDF; - Int32 newDataType = (Int32) va_arg (Va->ap, long); - Int32 newNumElems = (Int32) va_arg (Va->ap, long); - Int32 oldDataType, oldNumElems, eOffset; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED(CDF)) return NO_ATTR_SELECTED; - if (E3(entryType, - CDF->CURgrEntryNum, - CDF->CURgrEntryNum, - CDF->CURzEntryNum) == RESERVED_ENTRYNUM) return NO_ENTRY_SELECTED; - if (!ValidDataType(newDataType) || InValidDataType(newDataType)) - return BAD_DATA_TYPE; - if (newNumElems != -99 && newNumElems < 1) return BAD_NUM_ELEMS; - if (!sX(CheckEntryOp(CDF,entryType),&pStatus)) return pStatus; - eOffset = E3(entryType,CDF->CURgrEntryOffset, - CDF->CURgrEntryOffset, - CDF->CURzEntryOffset); - if (eOffset == RESERVED_ENTRYOFFSET) return NO_SUCH_ENTRY; - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - if (!sX(ReadAEDR(CDF->fp,eOffset, - AEDR_DATATYPE,&oldDataType, - AEDR_NUMELEMS,&oldNumElems, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if ((!EquivDataTypes(newDataType,oldDataType)) || - (newNumElems != -99 && newNumElems != oldNumElems)) - return CANNOT_CHANGE; - if (!sX(WriteAEDR(CDF,CDF->fp,eOffset, - AEDR_DATATYPE,&newDataType, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * gENTRY_DATA_/rENTRY_DATA_/zENTRY_DATA_, - ****************************************************************************/ - case rENTRY_DATA_: - case gENTRY_DATA_: - case zENTRY_DATA_: { - int entryType = E3p(Va->item,gENTRY_DATA_,rENTRY_DATA_,zENTRY_DATA_); - struct CDFstruct *CDF; - struct ADRstruct ADR; - long entryN; /* True entry number. */ - Logical zEntry; /* If true, a AzEDR. If FALSE, a AgrEDR. */ - int nBytesNew; /* Size of new entry value. */ - Int32 eOffset; /* Offset of AEDR. */ - long dataType = va_arg (Va->ap, long); - long numElems = va_arg (Va->ap, long); - void *value = va_arg (Va->ap, void *); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED(CDF)) return NO_ATTR_SELECTED; - if (E3(entryType, - CDF->CURgrEntryNum, - CDF->CURgrEntryNum, - CDF->CURzEntryNum) == RESERVED_ENTRYNUM) return NO_ENTRY_SELECTED; - if (!ValidDataType((Int32)dataType) || InValidDataType((Int32)dataType)) - return BAD_DATA_TYPE; - if (numElems < 1) return BAD_NUM_ELEMS; - if (!sX(ReadADR(CDF->fp,CDF->CURattrOffset, - ADR_RECORD,&ADR, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(CheckEntryOp(CDF,entryType),&pStatus)) return pStatus; - if (!WriteAccess(CDF,FALSE,&pStatus)) return pStatus; - nBytesNew = (int) (CDFelemSize(dataType) * numElems); - eOffset = E3(entryType,CDF->CURgrEntryOffset, - CDF->CURgrEntryOffset, - CDF->CURzEntryOffset); - if (eOffset != RESERVED_ENTRYOFFSET) { - /************************************************************************ - * The entry already exists. - ************************************************************************/ - struct AEDRstruct AEDR; int nBytesCur; - if (!sX(ReadAEDR(CDF->fp,eOffset, - AEDR_RECORD,&AEDR,NULL, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - nBytesCur = (int) (CDFelemSize(AEDR.DataType) * AEDR.NumElems); - zEntry = (AEDR.RecordType == AzEDR_); - if (nBytesNew != nBytesCur) { - /******************************************************************** - * The size of the new entry value is different than the size of the - * old entry value. The AEDR is changing size. - ********************************************************************/ - Int32 prevOffset, newOffset; - if (!sX(FindPrevEntry(CDF,CDF->CURattrOffset,eOffset, - zEntry,&prevOffset),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(ResizeIR(CDF,eOffset, - AEDR_BASE_SIZE+nBytesNew, - &newOffset,TRUE,NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - AEDR.RecordSize = AEDR_BASE_SIZE + nBytesNew; - AEDR.DataType = dataType; - AEDR.NumElems = numElems; - if (!sX(WriteAEDR(CDF,CDF->fp,newOffset, - AEDR_RECORD,&AEDR,value, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (entryType) { - case gENTRYt: - case rENTRYt: - CDF->CURgrEntryOffset = newOffset; - break; - case zENTRYt: - CDF->CURzEntryOffset = newOffset; - break; - } - if (prevOffset == 0) { - if (!sX(WriteADR(CDF->fp,CDF->CURattrOffset, - BOO(zEntry,ADR_AzEDRHEAD,ADR_AgrEDRHEAD),&newOffset, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - else { - if (!sX(WriteAEDR(CDF,CDF->fp,prevOffset, - AEDR_AEDRNEXT,&newOffset, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - } - else { - /******************************************************************** - * The AEDR is not changing size. - ********************************************************************/ - AEDR.DataType = dataType; - AEDR.NumElems = numElems; - if (!sX(WriteAEDR(CDF,CDF->fp,eOffset, - AEDR_RECORD,&AEDR,value, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - } - else { - /************************************************************************ - * The entry does not exist. - ************************************************************************/ - struct AEDRstruct AEDR; - Int32 lastOffset; - zEntry = E3(entryType,FALSE,FALSE, - BOO(zModeON(CDF), - BOO(CDF->CURzEntryNum < CDF->NrVars,FALSE,TRUE),TRUE)); - entryN = E3(entryType,CDF->CURgrEntryNum,CDF->CURgrEntryNum, - BOO(zModeON(CDF), - BOO(CDF->CURzEntryNum < CDF->NrVars, - CDF->CURzEntryNum,CDF->CURzEntryNum - CDF->NrVars), - CDF->CURzEntryNum)); - AEDR.RecordSize = AEDR_BASE_SIZE + nBytesNew; - AEDR.RecordType = BOO(zEntry,AzEDR_,AgrEDR_); - AEDR.AEDRnext = 0; - AEDR.AttrNum = ADR.Num; - AEDR.DataType = dataType; - AEDR.Num = entryN; - AEDR.NumElems = numElems; - AEDR.rfuA = 0; - AEDR.rfuB = 0; - AEDR.rfuC = 0; - AEDR.rfuD = -1; - AEDR.rfuE = -1; - if (!sX(AllocateIR(CDF,AEDR.RecordSize,&eOffset),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteAEDR(CDF,CDF->fp,eOffset, - AEDR_RECORD,&AEDR,value, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (entryType) { - case gENTRYt: - case rENTRYt: - CDF->CURgrEntryOffset = eOffset; - break; - case zENTRYt: - CDF->CURzEntryOffset = eOffset; - break; - } - if (!sX(FindLastEntry(CDF,CDF->CURattrOffset, - zEntry,&lastOffset),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (lastOffset == 0) { - /******************************************************************** - * This is the first entry (of this type). The ADR will point to - * this entry. - ********************************************************************/ - if (zEntry) { - ADR.NzEntries = 1; - ADR.MAXzEntry = entryN; - ADR.AzEDRhead = eOffset; - } - else { - ADR.NgrEntries = 1; - ADR.MAXgrEntry = entryN; - ADR.AgrEDRhead = eOffset; - } - if (!sX(WriteADR(CDF->fp,CDF->CURattrOffset, - ADR_RECORD,&ADR, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - else { - /******************************************************************** - * Entries already exist (of this type). The currently last entry - * will point to this entry. - ********************************************************************/ - if (zEntry) { - ADR.NzEntries++; - ADR.MAXzEntry = MAXIMUM(ADR.MAXzEntry,entryN); - } - else { - ADR.NgrEntries++; - ADR.MAXgrEntry = MAXIMUM(ADR.MAXgrEntry,entryN); - } - if (!sX(WriteADR(CDF->fp,CDF->CURattrOffset, - ADR_RECORD,&ADR, - ADR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteAEDR(CDF,CDF->fp,lastOffset, - AEDR_AEDRNEXT,&eOffset, - AEDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - } - } - break; - } -} -return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfput2_64.c b/cdf36_3-dist/src/lib/cdfput2_64.c deleted file mode 100644 index e5c3e86..0000000 --- a/cdf36_3-dist/src/lib/cdfput2_64.c +++ /dev/null @@ -1,1057 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `put' operations, part 2. -* -* Version 1.4a, 21-Feb-97, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 16-Sep-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 24-Jan-94, J Love CDF V2.4. -* V1.3 5-Dec-94, J Love CDF V2.5. -* V1.3a 6-Jan-95, J Love Encode/decode changes. More cache-residency. -* V1.3b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.3c 4-Aug-95, J Love CDFexport-related changes. -* V1.4 3-Oct-96, J Love CDF V2.6. -* V1.4a 21-Feb-97, J Love Removed RICE. -* V2.0 08-Apr-04, M Liu Removed calls to LocateCurrentVar function as -* its offset becomes available when it is -* selected/created. -* V2.1 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* V2.2 16-Nov-05, M Liu Changed code for data spec modification. -99 -* is passed as a special indicator for the -* number of elements as it can't be changed. -* V2.3 17-Oct-12, M Liu Not allowed to set SPARSEREC if a variable -* is non-record varying. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* CDFput2_64. -******************************************************************************/ - -STATICforIDL CDFstatus CDFput2_64 (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ -CDFstatus tStatus, pStatus = CDF_OK; - -switch (Va->item) { - /**************************************************************************** - * CDF_ENCODING_, - * Can't change if any variables have been written to (including pad - * values). Can't change if any attribute entries have been written. - ****************************************************************************/ - case CDF_ENCODING_: { - struct CDFstruct *CDF; - Int32 actualEncoding; - Int32 encoding = (Int32) va_arg (Va->ap, long); - Logical no; - SelectCDF (Cur->cdf, CDF) - if (!ValidEncoding(encoding,&actualEncoding)) return BAD_ENCODING; - if (!sX(VerifyNoRecordsWritten64(CDF,&no),&pStatus)) return pStatus; - if (!no) return CANNOT_CHANGE; - if (!sX(VerifyNoPadsSpecified64(CDF,&no),&pStatus)) return pStatus; - if (!no) return CANNOT_CHANGE; - if (!sX(VerifyNoEntriesWritten64(CDF,&no),&pStatus)) return pStatus; - if (!no) return CANNOT_CHANGE; - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - CDF->encoding = actualEncoding; - /************************************************************************** - * Update the `encoding' field in the CDR. - **************************************************************************/ - if (!sX(WriteCDR64(CDF->fp,V3_CDR_OFFSET64, - CDR_ENCODING,&(CDF->encoding), - CDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Update the initialized variables for the new encoding. - **************************************************************************/ - if (!sX(UpdateConversions64(CDF),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * CDF_MAJORITY_, - * Can't change if any variable values have been written. - ****************************************************************************/ - case CDF_MAJORITY_: { - struct CDFstruct *CDF; - long majority = va_arg (Va->ap,long); - Logical no, zVar; Int32 CDRflags; - SelectCDF (Cur->cdf, CDF) - if (majority != ROW_MAJOR && majority != COLUMN_MAJOR) return BAD_MAJORITY; - if (!sX(VerifyNoRecordsWritten64(CDF,&no),&pStatus)) return pStatus; - if (!no) return CANNOT_CHANGE; - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - CDF->rowMajor = ROWmajor(majority); - /************************************************************************** - * Update the `flags' field in the CDR. - **************************************************************************/ - if (!sX(ReadCDR64(CDF->fp,CDF->CDRoffset64, - CDR_FLAGS,&CDRflags, - CDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (CDF->rowMajor) - SetBit32 (&CDRflags, CDR_MAJORITY_BIT); - else - ClearBit32 (&CDRflags, CDR_MAJORITY_BIT); - if (!sX(WriteCDR64(CDF->fp,V3_CDR_OFFSET64, - CDR_FLAGS,&CDRflags, - CDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Update the initialized variables for the new majority. - **************************************************************************/ - for (zVar = 0; zVar <= 1; zVar++) { - int varN; Int32 nVars = BOO(zVar,CDF->NzVars,CDF->NrVars); - for (varN = 0; varN < nVars; varN++) { - struct VarStruct *Var = BOO(zVar,CDF->zVars[varN],CDF->rVars[varN]); - if (Var != NULL) CalcNumDimValues (CDF, Var); - } - } - break; - } - /**************************************************************************** - * CDF_FORMAT_, - * Can't change if any variables have been created or if a compressed - * single-file CDF. - ****************************************************************************/ - case CDF_FORMAT_: { - long format = va_arg (Va->ap,long); - struct CDFstruct *CDF; Int32 CDRflags; - SelectCDF (Cur->cdf, CDF) - if (format != SINGLE_FILE && format != MULTI_FILE) return BAD_FORMAT; - if (CDF->NrVars > 0) return CANNOT_CHANGE; - if (CDF->NzVars > 0) return CANNOT_CHANGE; - if (CDF->uDotFp != NULL) return CANNOT_CHANGE; - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - if (format == MULTI_FILE && CDF->checksum != NO_CHECKSUM) - return CANNOT_CHANGE; - CDF->singleFile = (format == SINGLE_FILE); - /************************************************************************** - * Update the `flags' field in the CDR. - **************************************************************************/ - if (!sX(ReadCDR64(CDF->fp,CDF->CDRoffset64, - CDR_FLAGS,&CDRflags, - CDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (CDF->singleFile) - SetBit32 (&CDRflags, CDR_FORMAT_BIT); - else - ClearBit32 (&CDRflags, CDR_FORMAT_BIT); - if (!sX(WriteCDR64(CDF->fp,V3_CDR_OFFSET64, - CDR_FLAGS,&CDRflags, - CDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Reset cache size for "working" dotCDF file to the default for the CDF's - * format. - **************************************************************************/ - CDF->workingCacheSize = BOO(CDF->singleFile,NUMcacheSINGLE,NUMcacheMULTI); - if (!CACHEv64(CDF->fp,CDF->workingCacheSize)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - break; - } - /**************************************************************************** - * CDF_COMPRESSION_ - ****************************************************************************/ - case CDF_COMPRESSION_: { - long cType = va_arg (Va->ap, long); /* Compression type. */ - long *cParms = va_arg (Va->ap, long *); /* Compression parameters. */ - struct CDFstruct *CDF; int parmN; vSTATS vStats; - SelectCDF (Cur->cdf, CDF) - /************************************************************************** - * Validate compression type/parameters. - **************************************************************************/ - if (!sX(ValidateCompression64(cType,cParms),&pStatus)) return pStatus; - /************************************************************************** - * Verify that compression is not being attempted on a multi-file CDF. (It - * is allowed to specify no compression.) - **************************************************************************/ - if (!CDF->singleFile) { - if (cType != NO_COMPRESSION) return CANNOT_COMPRESS; - break; - } - /************************************************************************** - * Depending on the type of compression... - **************************************************************************/ - switch (cType) { - /************************************************************************ - * Turning off compression. - ************************************************************************/ - case NO_COMPRESSION: - /********************************************************************** - * If the CDF is currently compressed... - **********************************************************************/ - if (CDF->uDotFp != NULL) { - char pathName[DU_MAX_PATH_LEN+1]; - /******************************************************************** - * First get write access. - ********************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - /******************************************************************** - * Delete the compressed dotCDF file. - ********************************************************************/ - if (!DELETEv64(CDF->dotFp,&vStats)) { - CDF->dotFp = NULL; - AbortAccess64 (CDF, UPDATE, noDELETE); - return CDF_CLOSE_ERROR; - } - CDF->dotFp = NULL; - AddTOvStats (&CDF->dotCDFvStats, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "DotCDF..", &vStats); -#endif - /******************************************************************** - * Recreate the dotCDF file (now uncompressed) and set its cache size - * to that of the "working" dotCDF file (which it now has become). - ********************************************************************/ - BuildFilePath (CDFt, CDF->CDFname, CDF->no_append, - CDF->upper_case_ext, CDF->version_numbers, - INT32_ZERO, pathName); - CDF->dotFp = V_open64 (pathName, WRITE_PLUS_a_mode); - if (CDF->dotFp == NULL) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return CDF_CREATE_ERROR; - } - if (!CACHEv64(CDF->dotFp,CDF->workingCacheSize)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - /******************************************************************** - * Copy the uncompressed dotCDF file to the recreated dotCDF file. - ********************************************************************/ - if (!sX(CopyCDF64(CDF->uDotFp,CDF->dotFp),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /******************************************************************** - * Flush the recreated dotCDF file. - ********************************************************************/ - if (!FLUSHv64(CDF->dotFp)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return CDF_WRITE_ERROR; - } - /******************************************************************** - * Delete the uncompressed dotCDF file. - ********************************************************************/ - if (!DELETEv64(CDF->uDotFp,&vStats)) { - CDF->uDotFp = NULL; - AbortAccess64 (CDF, UPDATE, noDELETE); - return SCRATCH_DELETE_ERROR; - } - CDF->uDotFp = NULL; - AddTOvStats (&CDF->uDotCDFvStats, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "uDotCDF.", &vStats); -#endif - /******************************************************************** - * Reset the "working" dotCDF file. - ********************************************************************/ - CDF->fp = CDF->dotFp; - } - break; - /************************************************************************ - * Turning on/changing compression. - ************************************************************************/ - case RLE_COMPRESSION: - case HUFF_COMPRESSION: - case AHUFF_COMPRESSION: - case GZIP_COMPRESSION: { - char pathName[DU_MAX_PATH_LEN+1]; struct CPRstruct64 CPR; Int32 pCount; - /********************************************************************** - * Get read/write access. - **********************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - /********************************************************************** - * If the CDF is not currently compressed, create an uncompressed dotCDF - * file and copy the current contents into it. - **********************************************************************/ - if (CDF->uDotFp == NULL) { - CDF->uDotFp = V_scratch (ScratchDirectory(CDF), "cdf"); - if (CDF->uDotFp == NULL) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return CDF_CREATE_ERROR; - } - if (!CACHEv64(CDF->uDotFp,CDF->workingCacheSize)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - if (!sX(CopyCDF64(CDF->dotFp,CDF->uDotFp),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!FLUSHv64(CDF->uDotFp)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return CDF_WRITE_ERROR; - } - CDF->fp = CDF->uDotFp; - } - /********************************************************************** - * Delete/recreate the dotCDF file and write a CCR and CPR. - **********************************************************************/ - if (!DELETEv64(CDF->dotFp,&vStats)) { - CDF->dotFp = NULL; - AbortAccess64 (CDF, UPDATE, noDELETE); - return CDF_DELETE_ERROR; - } - CDF->dotFp = NULL; - AddTOvStats (&CDF->dotCDFvStats, &vStats); -#if defined(DEBUG) - DisplayVs (getenv("VSTREAM_STATS"), "DotCDF..", &vStats); -#endif - BuildFilePath (CDFt, CDF->CDFname, CDF->no_append, - CDF->upper_case_ext, CDF->version_numbers, - INT32_ZERO, pathName); - CDF->dotFp = V_open64 (pathName, WRITE_PLUS_a_mode); - if (CDF->dotFp == NULL) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return CDF_CREATE_ERROR; - } - pCount = CompressionParmsCount ((Int32) cType); - CPR.RecordSize = CPR_BASE_SIZE64 + (pCount * sizeof(Int32)); - CPR.RecordType = CPR_; - CPR.rfuA = 0; - CPR.cType = (Int32) cType; - CPR.pCount = pCount; - for (parmN = 0; parmN < pCount; parmN++) { - CPR.cParms[parmN] = (Int32) cParms[parmN]; - } - if (!sX(WriteCompressedCDF64(CDF,&CPR,EMPTY),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!FLUSHv64(CDF->dotFp)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return CDF_WRITE_ERROR; - } - break; - } - } - break; - } - /**************************************************************************** - * r/zVAR_COMPRESSION_ - ****************************************************************************/ - case rVAR_COMPRESSION_: - case zVAR_COMPRESSION_: { - Logical zOp = (Va->item == zVAR_COMPRESSION_), zVar; - Int32 maxAllocated, pCount; int p; OFF_T VDRoffset; - struct CDFstruct *CDF; struct VarStruct *Var; - struct VDRstruct64 VDR; struct CPRstruct64 CPR; - long cType = va_arg (Va->ap, long); /* Compression type. */ - long *cParms = va_arg (Va->ap, long *); /* Compression parameters. */ - /************************************************************************** - * Verify the current CDF and variable and that this operation is legal for - * the current zMode. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - /************************************************************************** - * Validate compression type/parameters. - **************************************************************************/ - if (!sX(ValidateCompression64(cType,cParms),&pStatus)) return pStatus; - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Verify that compression isn't being attempted on a multi-file CDF. (It - * is allowed to specify no compression.) After this point a single-file - * CDF can be assumed. - **************************************************************************/ - if (!CDF->singleFile) { - if (cType != NO_COMPRESSION) return CANNOT_COMPRESS; - break; - } - /************************************************************************** - * Locate the current variable. - **************************************************************************/ - - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) VDRoffset = CDF->CURzVarOffset64; - else VDRoffset = CDF->CURrVarOffset64; - - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - - /************************************************************************** - * Read VDR. - **************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,VDRoffset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Verify that no records have been written or allocated. If so, the - * compression cannot be changed. - **************************************************************************/ - if (!sX(LastRecord64(CDF,VDRoffset,zVar,&maxAllocated),&pStatus)){ - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (maxAllocated > NO_RECORD) return CANNOT_COMPRESS; - if (VDR.MaxRec > NO_RECORD) return CANNOT_COMPRESS; - /************************************************************************** - * If array sparseness is selected, then the variable cannot be compressed. - **************************************************************************/ - if (SPARSEarraysBITset(VDR.Flags)) { - if (cType != NO_COMPRESSION) return CANNOT_COMPRESS; - } - /************************************************************************** - * Disable current compression (if any). - **************************************************************************/ - if (VARcompressionBITset(VDR.Flags)) { - ClearBit32 (&VDR.Flags, VDR_COMPRESSION_BIT); - if (!sX(ReadCPR64(CDF->fp,VDR.CPRorSPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WasteIR64(CDF,VDR.CPRorSPRoffset,CPR.RecordSize),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - VDR.CPRorSPRoffset = (OFF_T) NO_OFFSET64; - } - /************************************************************************** - * Set up new compression. - **************************************************************************/ - switch (cType) { - case NO_COMPRESSION: - break; - case RLE_COMPRESSION: - case HUFF_COMPRESSION: - case AHUFF_COMPRESSION: - case GZIP_COMPRESSION: - pCount = CompressionParmsCount ((Int32) cType); - SetBit32 (&VDR.Flags, VDR_COMPRESSION_BIT); - CPR.RecordSize = CPR_BASE_SIZE64 + (pCount * sizeof(Int32)); - CPR.RecordType = CPR_; - CPR.cType = (Int32) cType; - CPR.rfuA = 0; - CPR.pCount = pCount; - for (p = 0; p < pCount; p++) CPR.cParms[p] = (Int32) cParms[p]; - if (!sX(AllocateIR64(CDF,CPR.RecordSize,&VDR.CPRorSPRoffset),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteCPR64(CDF->fp,VDR.CPRorSPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /************************************************************************** - * Update VDR. - **************************************************************************/ - if (!sX(WriteVDR64(CDF,CDF->fp,VDRoffset,zVar, - VDR_RECORD,&VDR,NULL, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * If this variable has been initialized, recalculate the affected - * parameters. - **************************************************************************/ - if (Var != NULL) { - if (!sX(VariableType64(CDF,VDRoffset,zVar,&(Var->vType)),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (cType != NO_COMPRESSION) { - Var->cType = (Int32) cType; - for (p = 0; p < pCount; p++) Var->cParms[p] = (Int32) cParms[p]; - Var->reservePct = 0; - } - if (!sX(CalcBF64(CDF,Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - break; - } - /**************************************************************************** - * CDF_CHECKSUM_, - ****************************************************************************/ - case CDF_CHECKSUM_: { - long checksumValue = va_arg (Va->ap, long); - Int32 version, release; - struct CDFstruct *CDF; Int32 CDRflags; - SelectCDF (Cur->cdf, CDF) - if (!CDF->singleFile) return CANNOT_CHANGE; - if (checksumValue != NONE_CHECKSUM && - checksumValue != MD5_CHECKSUM && - checksumValue != OTHER_CHECKSUM) return BAD_CHECKSUM; - /************************************************************************** - * Update the `flags' field in the CDR. - **************************************************************************/ - if (!sX(ReadCDR64(CDF->fp,CDF->CDRoffset64, - CDR_VERSION,&version, - CDR_RELEASE,&release, - CDR_FLAGS,&CDRflags, - CDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Only apply to Version 2.6 and later CDFs. - **************************************************************************/ - if ((version*100+release) < 206) return CHECKSUM_NOT_ALLOWED; - - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - if (checksumValue == NONE_CHECKSUM) { - ClearBit32 (&CDRflags, CDR_CHECKSUM_BIT); - ClearBit32 (&CDRflags, CDR_CHECKSUM_MD5_BIT); - ClearBit32 (&CDRflags, CDR_CHECKSUM_OTHER_BIT); - } else { - SetBit32 (&CDRflags, CDR_CHECKSUM_BIT); - if (checksumValue == MD5_CHECKSUM) { - SetBit32 (&CDRflags, CDR_CHECKSUM_MD5_BIT); - ClearBit32 (&CDRflags, CDR_CHECKSUM_OTHER_BIT); - } else { - ClearBit32 (&CDRflags, CDR_CHECKSUM_MD5_BIT); - SetBit32 (&CDRflags, CDR_CHECKSUM_OTHER_BIT); - } - } - if (!sX(WriteCDR64(CDF->fp,CDF->CDRoffset64, - CDR_FLAGS,&CDRflags, - CDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - CDF->checksum = checksumValue; - break; - } - /**************************************************************************** - * r/zVAR_SPARSERECORDS_ - ****************************************************************************/ - case rVAR_SPARSERECORDS_: - case zVAR_SPARSERECORDS_: { - Logical zOp = (Va->item == zVAR_SPARSERECORDS_), zVar; - Int32 maxAllocated, maxRec, flags; OFF_T VDRoffset; - struct CDFstruct *CDF; struct VarStruct *Var; - Int32 sRecordsType = (Int32) va_arg (Va->ap, long); - /************************************************************************** - * Verify the current CDF and variable and that this operation is legal for - * the current zMode. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - /************************************************************************** - * Get write access. - **************************************************************************/ - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - /************************************************************************** - * Verify that sparseness isn't being attempted on a multi-file CDF. (It - * is allowed to specify sRecords.NO.) After this point a single-file CDF - * can be assumed. - **************************************************************************/ - if (!CDF->singleFile) { - if (sRecordsType != NO_SPARSERECORDS) return CANNOT_SPARSERECORDS; - break; - } - /************************************************************************** - * Locate the current variable. - **************************************************************************/ - zVar = CurrentVarMode(CDF,zOp); - if (zModeON(CDF) || zVar) VDRoffset = CDF->CURzVarOffset64; - else VDRoffset = CDF->CURrVarOffset64; - - if (zModeON(CDF)) - if (CDF->CURzVarNum < CDF->NrVars) - Var = CDF->rVars[(int)CDF->CURzVarNum]; - else - Var = CDF->zVars[(int)(CDF->CURzVarNum - CDF->NrVars)]; - else - Var = BOO(zOp,CDF->zVars[(int)CDF->CURzVarNum], - CDF->rVars[(int)CDF->CURrVarNum]); - /************************************************************************** - * Verify that no records have been written or allocated. If so, the - * sparseness cannot be changed. - **************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,VDRoffset,zVar, - VDR_MAXREC,&maxRec, - VDR_FLAGS,&flags, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (maxRec > NO_RECORD) return CANNOT_SPARSERECORDS; - if (!sX(LastRecord64(CDF,VDRoffset,zVar,&maxAllocated),&pStatus)){ - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (maxAllocated > NO_RECORD) return CANNOT_SPARSERECORDS; - if (!RECvaryBITset(flags) && sRecordsType != NO_SPARSERECORDS) - return CANNOT_SPARSERECORDS; - /************************************************************************** - * Based on type of sparseness... - **************************************************************************/ - switch (sRecordsType) { - case NO_SPARSERECORDS: - case PAD_SPARSERECORDS: - case PREV_SPARSERECORDS: - if (!sX(WriteVDR64(CDF,CDF->fp,VDRoffset,zVar, - VDR_sRECORDS,&sRecordsType, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - default: - return UNKNOWN_SPARSENESS; - } - /************************************************************************** - * If this variable has been initialized, recalculate the affected - * parameters. - **************************************************************************/ - if (Var != NULL) { - if (!sX(VariableType64(CDF,VDRoffset,zVar,&(Var->vType)),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->prevIfMissing = (sRecordsType == PREV_SPARSERECORDS); - } - break; - } - /**************************************************************************** - * r/zVAR_SPARSEARRAYS_ - ****************************************************************************/ - case rVAR_SPARSEARRAYS_: - case zVAR_SPARSEARRAYS_: { - Logical zOp = (Va->item == zVAR_SPARSEARRAYS_); - struct CDFstruct *CDF; - long sArraysType = va_arg (Va->ap, long); /* Sparseness type. */ - (void) va_arg (Va->ap, long *); /* Doing it this way quiets - the Borland C compiler. */ - /************************************************************************** - * Verify the current CDF and variable and that this operation is legal for - * the current zMode. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - /************************************************************************** - * Verify that sparse arrays aren't being attempted on a multi-file CDF. - * (It is allowed to specify no sparse arrays.) - **************************************************************************/ - if (!CDF->singleFile) { - if (sArraysType != NO_SPARSEARRAYS) return CANNOT_SPARSEARRAYS; - break; - } - /************************************************************************** - * Sparse arrays are not yet supported. - **************************************************************************/ - switch (sArraysType) { - case NO_SPARSEARRAYS: - /* Nothing needs to be done until sparse arrays are supported. */ - break; - default: - return UNKNOWN_SPARSENESS; - } - break; - } - /**************************************************************************** - * ATTR_NAME_, - ****************************************************************************/ - case ATTR_NAME_: { - struct CDFstruct *CDF; - char tmpname[CDF_ATTR_NAME_LEN256+1]; - char *attrname = va_arg (Va->ap, char *); - OFF_T offsetFound; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED64(CDF)) return NO_ATTR_SELECTED; - if (strlen(attrname) > (size_t) CDF_ATTR_NAME_LEN256) { - if (!sX(ATTR_NAME_TRUNC,&pStatus)) return pStatus; - } - strcpyX (tmpname, attrname, CDF_ATTR_NAME_LEN256); - if (!ValidAttrName(tmpname)) return BAD_ATTR_NAME; - /************************************************************************** - * Check that the new attribute name is not already in use. Don't flag as - * an error if the new name is the same as the old name (ignoring trailing - * blanks). Trailing blanks may be being eliminated. - **************************************************************************/ - tStatus = FindAttrByName64 (CDF, tmpname, &offsetFound); - switch (tStatus) { - case CDF_OK: - if (offsetFound != CDF->CURattrOffset64) return ATTR_EXISTS; - break; - case NO_SUCH_ATTR: - break; - default: - AbortAccess64 (CDF, UPDATE, noDELETE); - return tStatus; - } - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - NulPad (tmpname, CDF_ATTR_NAME_LEN256); - if (!sX(WriteADR64(CDF->fp,CDF->CURattrOffset64, - ADR_NAME,tmpname, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * ATTR_SCOPE_ - ****************************************************************************/ - case ATTR_SCOPE_: { - struct CDFstruct *CDF; - Int32 scope = (Int32) va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED64(CDF)) return NO_ATTR_SELECTED; - if (!ValidAttrScope(scope)) return BAD_SCOPE; - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - if (!sX(WriteADR64(CDF->fp,CDF->CURattrOffset64, - ADR_SCOPE,&scope, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Reset current entry offsets. - **************************************************************************/ - if (!sX(SetCURgrEntry64(CDF,FALSE,CDF->CURgrEntryNum),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(SetCURzEntry64(CDF,FALSE,CDF->CURzEntryNum),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * CDF_LEAPSECONDLASTUPDATED_, - ****************************************************************************/ - case CDF_LEAPSECONDLASTUPDATED_: { - struct CDFstruct *CDF; - long lastUpdated = va_arg (Va->ap, long); - Int32 lastUpdatedT; - SelectCDF (Cur->cdf, CDF) - if (lastUpdated != 0) { - if (ValidateLeapSecondLastUpdated((int)lastUpdated) != 1) - return BADDATE_LEAPSECOND_UPDATED; - } - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - lastUpdatedT = (Int32) lastUpdated; - if (!sX(WriteGDR64(CDF->fp,CDF->GDRoffset64, - GDR_LEAPSECONDLASTUPDATED,&lastUpdatedT, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * gENTRY_DATASPEC_/rENTRY_DATASPEC_/zENTRY_DATASPEC_, change the data - * specification of an existing entry. Currently, only the data type can - * be changed (and must be equivalent). The number of elements must remain - * the same. - ****************************************************************************/ - case rENTRY_DATASPEC_: - case gENTRY_DATASPEC_: - case zENTRY_DATASPEC_: { - int entryType = E3p(Va->item,gENTRY_DATASPEC_, - rENTRY_DATASPEC_, - zENTRY_DATASPEC_); - struct CDFstruct *CDF; - Int32 newDataType = (Int32) va_arg (Va->ap, long); - Int32 newNumElems = (Int32) va_arg (Va->ap, long); - Int32 oldDataType, oldNumElems; OFF_T eOffset; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED64(CDF)) return NO_ATTR_SELECTED; - if (E3(entryType, - CDF->CURgrEntryNum, - CDF->CURgrEntryNum, - CDF->CURzEntryNum) == RESERVED_ENTRYNUM) return NO_ENTRY_SELECTED; - if (!ValidDataType(newDataType)) return BAD_DATA_TYPE; - if (newNumElems != -99 && newNumElems < 1) return BAD_NUM_ELEMS; - if (!sX(CheckEntryOp64(CDF,entryType),&pStatus)) return pStatus; - eOffset = E3(entryType,CDF->CURgrEntryOffset64, - CDF->CURgrEntryOffset64, - CDF->CURzEntryOffset64); - if (eOffset == (OFF_T) RESERVED_ENTRYOFFSET64) return NO_SUCH_ENTRY; - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - if (!sX(ReadAEDR64(CDF->fp,eOffset, - AEDR_DATATYPE,&oldDataType, - AEDR_NUMELEMS,&oldNumElems, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if ((!EquivDataTypes(newDataType,oldDataType)) || - (newNumElems != -99 && newNumElems != oldNumElems)) - return CANNOT_CHANGE; - if (!sX(WriteAEDR64(CDF,CDF->fp,eOffset, - AEDR_DATATYPE,&newDataType, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * gENTRY_DATA_/rENTRY_DATA_/zENTRY_DATA_, - ****************************************************************************/ - case rENTRY_DATA_: - case gENTRY_DATA_: - case zENTRY_DATA_: { - int entryType = E3p(Va->item,gENTRY_DATA_,rENTRY_DATA_,zENTRY_DATA_); - struct CDFstruct *CDF; - struct ADRstruct64 ADR; - long entryN; /* True entry number. */ - Logical zEntry; /* If true, a AzEDR. If FALSE, a AgrEDR. */ - int nBytesNew; /* Size of new entry value. */ - OFF_T eOffset; /* Offset of AEDR. */ - long dataType = va_arg (Va->ap, long); - long numElems = va_arg (Va->ap, long); - void *value = va_arg (Va->ap, void *); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTattrSELECTED64(CDF)) return NO_ATTR_SELECTED; - if (E3(entryType, - CDF->CURgrEntryNum, - CDF->CURgrEntryNum, - CDF->CURzEntryNum) == RESERVED_ENTRYNUM) return NO_ENTRY_SELECTED; - if (!ValidDataType((Int32)dataType)) return BAD_DATA_TYPE; - if (numElems < 1L) return BAD_NUM_ELEMS; - if (!sX(ReadADR64(CDF->fp,CDF->CURattrOffset64, - ADR_RECORD,&ADR, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(CheckEntryOp64(CDF,entryType),&pStatus)) return pStatus; - if (!WriteAccess64(CDF,FALSE,&pStatus)) return pStatus; - if (dataType == CDF_TIME_TT2000) { - if (!UpdateTT2000header(CDF,&pStatus)) return pStatus; - } - nBytesNew = (int) (CDFelemSize(dataType) * numElems); - eOffset = E3(entryType,CDF->CURgrEntryOffset64, - CDF->CURgrEntryOffset64, - CDF->CURzEntryOffset64); - if (eOffset != (OFF_T) RESERVED_ENTRYOFFSET64) { - /************************************************************************ - * The entry already exists. - ************************************************************************/ - struct AEDRstruct64 AEDR; int nBytesCur; - if (!sX(ReadAEDR64(CDF->fp,eOffset, - AEDR_RECORD,&AEDR,NULL, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - nBytesCur = (int) (CDFelemSize(AEDR.DataType) * AEDR.NumElems); - zEntry = (AEDR.RecordType == AzEDR_); - if (nBytesNew != nBytesCur) { - /******************************************************************** - * The size of the new entry value is different than the size of the - * old entry value. The AEDR is changing size. - ********************************************************************/ - OFF_T prevOffset, newOffset; - if (!sX(FindPrevEntry64(CDF,CDF->CURattrOffset64,eOffset, - zEntry,&prevOffset),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(ResizeIR64(CDF,eOffset, - AEDR_BASE_SIZE64+nBytesNew, - &newOffset,TRUE,NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - AEDR.RecordSize = AEDR_BASE_SIZE64 + nBytesNew; - AEDR.DataType = dataType; - AEDR.NumElems = numElems; - if (!sX(WriteAEDR64(CDF,CDF->fp,newOffset, - AEDR_RECORD,&AEDR,value, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (entryType) { - case gENTRYt: - case rENTRYt: - CDF->CURgrEntryOffset64 = newOffset; - break; - case zENTRYt: - CDF->CURzEntryOffset64 = newOffset; - break; - } - if (prevOffset == 0) { - if (!sX(WriteADR64(CDF->fp,CDF->CURattrOffset64, - BOO(zEntry,ADR_AzEDRHEAD,ADR_AgrEDRHEAD),&newOffset, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - else { - if (!sX(WriteAEDR64(CDF,CDF->fp,prevOffset, - AEDR_AEDRNEXT,&newOffset, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - } - else { - /******************************************************************** - * The AEDR is not changing size. - ********************************************************************/ - AEDR.DataType = dataType; - AEDR.NumElems = numElems; - if (!sX(WriteAEDR64(CDF,CDF->fp,eOffset, - AEDR_RECORD,&AEDR,value, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - } - else { - /************************************************************************ - * The entry does not exist. - ************************************************************************/ - struct AEDRstruct64 AEDR; - OFF_T lastOffset; - zEntry = E3(entryType,FALSE,FALSE, - BOO(zModeON(CDF), - BOO(CDF->CURzEntryNum < CDF->NrVars,FALSE,TRUE),TRUE)); - entryN = E3(entryType,CDF->CURgrEntryNum,CDF->CURgrEntryNum, - BOO(zModeON(CDF), - BOO(CDF->CURzEntryNum < CDF->NrVars, - CDF->CURzEntryNum,CDF->CURzEntryNum - CDF->NrVars), - CDF->CURzEntryNum)); - AEDR.RecordSize = AEDR_BASE_SIZE64 + nBytesNew; - AEDR.RecordType = BOO(zEntry,AzEDR_,AgrEDR_); - AEDR.AEDRnext = (OFF_T) 0; - AEDR.AttrNum = ADR.Num; - AEDR.DataType = dataType; - AEDR.Num = entryN; - AEDR.NumElems = numElems; - AEDR.rfuA = 0; - AEDR.rfuB = 0; - AEDR.rfuC = 0; - AEDR.rfuD = -1; - AEDR.rfuE = -1; - if (!sX(AllocateIR64(CDF,AEDR.RecordSize,&eOffset),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteAEDR64(CDF,CDF->fp,eOffset, - AEDR_RECORD,&AEDR,value, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (entryType) { - case gENTRYt: - case rENTRYt: - CDF->CURgrEntryOffset64 = eOffset; - break; - case zENTRYt: - CDF->CURzEntryOffset64 = eOffset; - break; - } - if (!sX(FindLastEntry64(CDF,CDF->CURattrOffset64, - zEntry,&lastOffset),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (lastOffset == (OFF_T) 0) { - /******************************************************************** - * This is the first entry (of this type). The ADR will point to - * this entry. - ********************************************************************/ - if (zEntry) { - ADR.NzEntries = 1; - ADR.MAXzEntry = entryN; - ADR.AzEDRhead = eOffset; - } - else { - ADR.NgrEntries = 1; - ADR.MAXgrEntry = entryN; - ADR.AgrEDRhead = eOffset; - } - if (!sX(WriteADR64(CDF->fp,CDF->CURattrOffset64, - ADR_RECORD,&ADR, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - else { - /******************************************************************** - * Entries already exist (of this type). The currently last entry - * will point to this entry. - ********************************************************************/ - if (zEntry) { - ADR.NzEntries++; - ADR.MAXzEntry = MAXIMUM(ADR.MAXzEntry,entryN); - } - else { - ADR.NgrEntries++; - ADR.MAXgrEntry = MAXIMUM(ADR.MAXgrEntry,entryN); - } - if (!sX(WriteADR64(CDF->fp,CDF->CURattrOffset64, - ADR_RECORD,&ADR, - ADR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(WriteAEDR64(CDF,CDF->fp,lastOffset, - AEDR_AEDRNEXT,&eOffset, - AEDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - } - } - break; - } -} -return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfread.c b/cdf36_3-dist/src/lib/cdfread.c deleted file mode 100644 index 57f410f..0000000 --- a/cdf36_3-dist/src/lib/cdfread.c +++ /dev/null @@ -1,1762 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Read from internal record. -* -* Version 1.4a, 28-Feb-97, Hughes STX. -* -* Modification history: -* -* V1.0 30-Nov-94, J Love Original version. -* V1.1 30-Jan-95, J Love `Read32s' now checks count. -* V1.1a 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.2 26-May-95, J Love CDF V2.4 compatibility mode. What? -* V1.3 14-Jun-95, J Love Recursion! -* V1.3a 4-Aug-95, J Love More efficient `Read32' and `Read32s'. -* CDFexport-related changes. -* V1.4 3-Apr-96, J Love CDF V2.6. -* V1.4a 28-Feb-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V3.2 21-Jun-07, D Berger Modified ReadGDR, ReadADR, and ReadAEDR, and -* added ReadADRList and ReadAEDRList to support -* perfomance enhancements for accessing metadata -* in READONLYon mode. -* V3.2a 11-Apr-08, M Liu Modified Read32s to eliminate the potential -* buffer overflow. -* V3.3 28-Jul-08, M Liu Modified to work with CDF file validation. -* V3.3a 15-Sep-08, M Liu Modified ReadAEDRList to pass in the number of -* entries to set up the list, not just the last -* entry number. -* V3.4 12-Aug-10, M Liu Replaced strcpy by strcpyX in ReadVDR. -* -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* Local macro definitions. -******************************************************************************/ - -#define CRE CDF_READ_ERROR -#define CV2C CORRUPTED_V2_CDF - -/****************************************************************************** -* Read32. -******************************************************************************/ - -VISIBLE_PREFIX Logical Read32 (fp, value) -vFILE *fp; -Int32 *value; -{ -#if defined(NETWORKbyteORDERcpu) - if (!READv(value,(size_t)4,(size_t)1,fp)) return FALSE; -#else - Int32 temp; - if (!READv(&temp,(size_t)4,(size_t)1,fp)) return FALSE; - REVERSE4bIO (&temp, value) -#endif - return TRUE; -} - -/****************************************************************************** -* Read32s. -******************************************************************************/ - -STATICforIDL Logical Read32s (fp, buffer, count) -vFILE *fp; -Int32 *buffer; -int count; -{ -#define MAX_READ32s CDF_MAX_DIMS /* This must be the maximum of - CDF_MAX_DIMS and MAX_VXR_ENTRIES - (and for any other uses of - `Read32s'). */ -#if defined(NETWORKbyteORDERcpu) - if (count == 0) return TRUE; - if (count < 0 || count > MAX_READ32s) return FALSE; - if (!READv(buffer,(size_t)4,(size_t)count,fp)) return FALSE; -#else - int i; Int32 temp[MAX_READ32s]; - if (count == 0) return TRUE; - if (count < 0 || count > MAX_READ32s) return FALSE; - if (!READv(temp,(size_t)4,(size_t)count,fp)) return FALSE; - for (i = 0; i < count; i++) { - REVERSE4bIO (&temp[i], &buffer[i]) - } -#endif - return TRUE; -} - -/****************************************************************************** -* ReadIrSize. -* The size is always in the first 4-byte field. -******************************************************************************/ - -STATICforIDL CDFstatus ReadIrSize (fp, offset, irSize) -vFILE *fp; -Int32 offset; -Int32 *irSize; -{ - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CRE; - if (!Read32(fp,irSize)) return CRE; - return CDF_OK; -} - -/****************************************************************************** -* ReadIrType. -* The type is always in the second 4-byte field. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus ReadIrType (fp, offset, irType) -vFILE *fp; -Int32 offset; -Int32 *irType; -{ - long irTypeOffset = offset + sizeof(Int32); - if (!SEEKv(fp,irTypeOffset,vSEEK_SET)) return CRE; - if (!Read32(fp,irType)) return CRE; - return CDF_OK; -} - -/****************************************************************************** -* ReadCDR. -* Note that the length of the CDF copyright was decreased in CDF V2.5 (there -* were way too many characters allowed for). When reading the copyright, only -* CDF_COPYRIGHT_LEN characters will be read. This will be less than the -* actual number in CDFs prior to CDF V2.4 but is enough to include all of the -* characters that were used. (The value of CDF_COPYRIGHT_LEN was decreased -* from CDF V2.4 to CDF V2.5.) -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadCDR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus ReadCDR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CDR_NULL: - va_end (ap); - return pStatus; - case CDR_RECORD: { - struct CDRstruct *CDR = va_arg (ap, struct CDRstruct *); - void *copyRight = va_arg (ap, char *); - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CRE; - if (!Read32(fp,&(CDR->RecordSize))) return CRE; - if (!Read32(fp,&(CDR->RecordType))) return CRE; - if (!Read32(fp,&(CDR->GDRoffset))) return CRE; - if (!Read32(fp,&(CDR->Version))) return CRE; - if (!Read32(fp,&(CDR->Release))) return CRE; - if (!Read32(fp,&(CDR->Encoding))) return CRE; - if (!Read32(fp,&(CDR->Flags))) return CRE; - if (!Read32(fp,&(CDR->rfuA))) return CRE; - if (!Read32(fp,&(CDR->rfuB))) return CRE; - if (!Read32(fp,&(CDR->Increment))) return CRE; - if (!Read32(fp,&(CDR->rfuD))) return CRE; - if (!Read32(fp,&(CDR->rfuE))) return CRE; - if (copyRight != NULL) { - if (!READv(copyRight,CDF_COPYRIGHT_LEN,1,fp)) return CRE; - NulPad (copyRight, CDF_COPYRIGHT_LEN); - } - break; - } - case CDR_COPYRIGHT: { - void *copyRight = va_arg (ap, char *); - long tOffset = offset + CDR_COPYRIGHT_OFFSET; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!READv(copyRight,CDF_COPYRIGHT_LEN,1,fp)) return CRE; - NulPad (copyRight, CDF_COPYRIGHT_LEN); - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); - long tOffset = offset; - switch (field) { - case CDR_RECORDSIZE: tOffset += CDR_RECORDSIZE_OFFSET; break; - case CDR_RECORDTYPE: tOffset += CDR_RECORDTYPE_OFFSET; break; - case CDR_GDROFFSET: tOffset += CDR_GDROFFSET_OFFSET; break; - case CDR_VERSION: tOffset += CDR_VERSION_OFFSET; break; - case CDR_RELEASE: tOffset += CDR_RELEASE_OFFSET; break; - case CDR_ENCODING: tOffset += CDR_ENCODING_OFFSET; break; - case CDR_FLAGS: tOffset += CDR_FLAGS_OFFSET; break; - case CDR_INCREMENT: tOffset += CDR_INCREMENT_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadGDR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadGDR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus ReadGDR (va_alist) -va_dcl -#endif -{ - long i; - long read_only_mode; - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - /*************************************************************************** - * Check read only mode. If it is invalid, it may have not been initialized - - * set it to off. - ***************************************************************************/ - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - if (read_only_mode != READONLYon && read_only_mode != READONLYoff) - { - read_only_mode = READONLYoff; - }; - /*************************************************************************** - * If READONLYon, read the GDR into memory for future reference. - ***************************************************************************/ - if (read_only_mode == READONLYon && fp->GDR == NULL) - { - fp->GDR = cdf_AllocateMemory((size_t)sizeof(struct GDRstruct), NULL); - if (fp->GDR == NULL) return CRE; - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CRE; - if (!Read32(fp,&(fp->GDR->RecordSize))) return CRE; - if (!Read32(fp,&(fp->GDR->RecordType))) return CRE; - if (!Read32(fp,&(fp->GDR->rVDRhead))) return CRE; - if (!Read32(fp,&(fp->GDR->zVDRhead))) return CRE; - if (!Read32(fp,&(fp->GDR->ADRhead))) return CRE; - if (!Read32(fp,&(fp->GDR->eof))) return CRE; - if (!Read32(fp,&(fp->GDR->NrVars))) return CRE; - if (!Read32(fp,&(fp->GDR->NumAttr))) return CRE; - if (!Read32(fp,&(fp->GDR->rMaxRec))) return CRE; - if (!Read32(fp,&(fp->GDR->rNumDims))) return CRE; - if (!Read32(fp,&(fp->GDR->NzVars))) return CRE; - if (!Read32(fp,&(fp->GDR->UIRhead))) return CRE; - if (!Read32(fp,&(fp->GDR->rfuC))) return CRE; - if (!Read32(fp,&(fp->GDR->rfuD))) return CRE; - if (!Read32(fp,&(fp->GDR->rfuE))) return CRE; - if (fp->GDR->rNumDims < 0 || fp->GDR->rNumDims > CDF_MAX_DIMS) - return CV2C; - if (!Read32s(fp,fp->GDR->rDimSizes, - (int)fp->GDR->rNumDims)) return CRE; - pStatus = ReadADRList(fp); - if (pStatus != CDF_OK) return pStatus; - }; - /************************************************************************** - * For whatever data is requested from the GDR, if READONLYon, get the data - * from the GDR in memory, otherwise read from the file/cache. - ***************************************************************************/ - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case GDR_NULL: - va_end (ap); - return pStatus; - case GDR_RECORD: { - struct GDRstruct *GDR = va_arg (ap, struct GDRstruct *); - if (read_only_mode == READONLYoff) - { - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CRE; - if (!Read32(fp,&(GDR->RecordSize))) return CRE; - if (!Read32(fp,&(GDR->RecordType))) return CRE; - if (!Read32(fp,&(GDR->rVDRhead))) return CRE; - if (!Read32(fp,&(GDR->zVDRhead))) return CRE; - if (!Read32(fp,&(GDR->ADRhead))) return CRE; - if (!Read32(fp,&(GDR->eof))) return CRE; - if (!Read32(fp,&(GDR->NrVars))) return CRE; - if (!Read32(fp,&(GDR->NumAttr))) return CRE; - if (!Read32(fp,&(GDR->rMaxRec))) return CRE; - if (!Read32(fp,&(GDR->rNumDims))) return CRE; - if (!Read32(fp,&(GDR->NzVars))) return CRE; - if (!Read32(fp,&(GDR->UIRhead))) return CRE; - if (!Read32(fp,&(GDR->rfuC))) return CRE; - if (!Read32(fp,&(GDR->rfuD))) return CRE; - if (!Read32(fp,&(GDR->rfuE))) return CRE; - if (GDR->rNumDims < 0 || GDR->rNumDims > CDF_MAX_DIMS) - break; /* return CV2C; */ - if (!Read32s(fp,GDR->rDimSizes,(int)GDR->rNumDims)) return CRE; - } - else - { - GDR->RecordSize = fp->GDR->RecordSize; - GDR->RecordType = fp->GDR->RecordType; - GDR->rVDRhead = fp->GDR->rVDRhead; - GDR->zVDRhead = fp->GDR->zVDRhead; - GDR->ADRhead = fp->GDR->ADRhead; - GDR->eof = fp->GDR->eof; - GDR->NrVars = fp->GDR->NrVars; - GDR->NumAttr = fp->GDR->NumAttr; - GDR->rMaxRec = fp->GDR->rMaxRec; - GDR->rNumDims = fp->GDR->rNumDims; - GDR->NzVars = fp->GDR->NzVars; - GDR->UIRhead = fp->GDR->UIRhead; - GDR->rfuC = fp->GDR->rfuC; - GDR->rfuD = fp->GDR->rfuD; - GDR->rfuE = fp->GDR->rfuE; - for (i = 0; i < GDR->rNumDims; i++) - { - GDR->rDimSizes[i] = fp->GDR->rDimSizes[i]; - }; - } - break; - } - case GDR_rDIMSIZES: { - Int32 *rDimSizes = va_arg (ap, Int32 *); Int32 rNumDims; long tOffset; - if (read_only_mode == READONLYoff) - { - if (!sX(ReadGDR(fp,offset, - GDR_rNUMDIMS,&rNumDims, - GDR_NULL),&pStatus)) return pStatus; - tOffset = offset + GDR_rDIMSIZES_OFFSET; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (rNumDims < 0 || rNumDims > CDF_MAX_DIMS) - return CV2C; - if (!Read32s(fp,rDimSizes,(int)rNumDims)) return CRE; - } - else - { - for (i = 0; i < fp->GDR->rNumDims; i++) - { - rDimSizes[i] = fp->GDR->rDimSizes[i]; - }; - } - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case GDR_RECORDSIZE: { - if (read_only_mode == READONLYoff) - { - tOffset += GDR_RECORDSIZE_OFFSET; - } - else - { - *buffer = fp->GDR->RecordSize; - }; - break; - } - case GDR_RECORDTYPE: { - if (read_only_mode == READONLYoff) - { - tOffset += GDR_RECORDTYPE_OFFSET; - } - else - { - *buffer = fp->GDR->RecordType; - } - break; - } - case GDR_rVDRHEAD: { - if (read_only_mode == READONLYoff) - { - tOffset += GDR_rVDRHEAD_OFFSET; - } - else - { - *buffer = fp->GDR->rVDRhead; - } - break; - } - case GDR_zVDRHEAD: { - if (read_only_mode == READONLYoff) - { - tOffset += GDR_zVDRHEAD_OFFSET; - } - else - { - *buffer = fp->GDR->zVDRhead; - } - break; - } - case GDR_ADRHEAD: { - if (read_only_mode == READONLYoff) - { - tOffset += GDR_ADRHEAD_OFFSET; - } - else - { - *buffer = fp->GDR->ADRhead; - } - break; - } - case GDR_EOF: { - if (read_only_mode == READONLYoff) - { - tOffset += GDR_EOF_OFFSET; - } - else - { - *buffer = fp->GDR->eof; - } - break; - } - case GDR_NrVARS: { - if (read_only_mode == READONLYoff) - { - tOffset += GDR_NrVARS_OFFSET; - } - else - { - *buffer = fp->GDR->NrVars; - } - break; - } - case GDR_NUMATTR: { - if (read_only_mode == READONLYoff) - { - tOffset += GDR_NUMATTR_OFFSET; - } - else - { - *buffer = fp->GDR->NumAttr; - } - break; - } - case GDR_rMAXREC: { - if (read_only_mode == READONLYoff) - { - tOffset += GDR_rMAXREC_OFFSET; - } - else - { - *buffer = fp->GDR->rMaxRec; - } - break; - } - case GDR_rNUMDIMS: { - if (read_only_mode == READONLYoff) - { - tOffset += GDR_rNUMDIMS_OFFSET; - } - else - { - *buffer = fp->GDR->rNumDims; - } - break; - } - case GDR_NzVARS: { - if (read_only_mode == READONLYoff) - { - tOffset += GDR_NzVARS_OFFSET; - } - else - { - *buffer = fp->GDR->NzVars; - } - break; - } - case GDR_UIRHEAD: { - if (read_only_mode == READONLYoff) - { - tOffset += GDR_UIRHEAD_OFFSET; - } - else - { - *buffer = fp->GDR->UIRhead; - } - break; - } - default: return CDF_INTERNAL_ERROR; - } - if (read_only_mode == READONLYoff) - { - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32(fp,buffer)) return CRE; - } - break; - } - } - } -} - -/****************************************************************************** -* ReadADR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadADR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus ReadADR (va_alist) -va_dcl -#endif -{ - long read_only_mode; - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - /*************************************************************************** - * IF READONLYon, and there are no ADRs in memory or no attribute has been - * selected, return NO_ATTR_SELECTED. Note that reading of ADRs into memory - * is triggered the 1st time an ADR is selected. - ***************************************************************************/ - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - if (read_only_mode == READONLYon && fp->CurADRIndex == RESERVED_ENTRYNUM) - { - return NO_ATTR_SELECTED; - }; - /*************************************************************************** - * For whatever ADR data is selected, if READONLYon, read the data from memory - * using CurADRIndex to select the correct ADR from the ADRList. Otherwise, - * read the data from the file/cache using the file offset. - ***************************************************************************/ - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case ADR_NULL: - va_end (ap); - return pStatus; - case ADR_RECORD: { - struct ADRstruct *ADR = va_arg (ap, struct ADRstruct *); - if (read_only_mode == READONLYoff) - { - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CRE; - if (!Read32(fp,&(ADR->RecordSize))) return CRE; - if (!Read32(fp,&(ADR->RecordType))) return CRE; - if (!Read32(fp,&(ADR->ADRnext))) return CRE; - if (!Read32(fp,&(ADR->AgrEDRhead))) return CRE; - if (!Read32(fp,&(ADR->Scope))) return CRE; - if (!Read32(fp,&(ADR->Num))) return CRE; - if (!Read32(fp,&(ADR->NgrEntries))) return CRE; - if (!Read32(fp,&(ADR->MAXgrEntry))) return CRE; - if (!Read32(fp,&(ADR->rfuA))) return CRE; - if (!Read32(fp,&(ADR->AzEDRhead))) return CRE; - if (!Read32(fp,&(ADR->NzEntries))) return CRE; - if (!Read32(fp,&(ADR->MAXzEntry))) return CRE; - if (!Read32(fp,&(ADR->rfuE))) return CRE; - if (!READv(ADR->Name,CDF_ATTR_NAME_LEN,1,fp)) return CRE; - NulPad (ADR->Name, CDF_ATTR_NAME_LEN); - } - else - { - ADR->RecordSize = fp->ADRList[fp->CurADRIndex]->RecordSize; - ADR->RecordType = fp->ADRList[fp->CurADRIndex]->RecordType; - ADR->ADRnext = fp->ADRList[fp->CurADRIndex]->ADRnext; - ADR->AgrEDRhead = fp->ADRList[fp->CurADRIndex]->AgrEDRhead; - ADR->Scope = fp->ADRList[fp->CurADRIndex]->Scope; - ADR->Num = fp->ADRList[fp->CurADRIndex]->Num; - ADR->NgrEntries = fp->ADRList[fp->CurADRIndex]->NgrEntries; - ADR->MAXgrEntry = fp->ADRList[fp->CurADRIndex]->MAXgrEntry; - ADR->rfuA = fp->ADRList[fp->CurADRIndex]->rfuA; - ADR->AzEDRhead = fp->ADRList[fp->CurADRIndex]->AzEDRhead; - ADR->NzEntries = fp->ADRList[fp->CurADRIndex]->NzEntries; - ADR->MAXzEntry = fp->ADRList[fp->CurADRIndex]->MAXzEntry; - ADR->rfuE = fp->ADRList[fp->CurADRIndex]->rfuE; - strcpyX (ADR->Name, fp->ADRList[fp->CurADRIndex]->Name, - CDF_ATTR_NAME_LEN); - } - break; - } - case ADR_NAME: { - char *aName = va_arg (ap, char *); - if (read_only_mode == READONLYoff) - { - long tOffset = offset + ADR_NAME_OFFSET; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!READv(aName,CDF_ATTR_NAME_LEN,1,fp)) return CRE; - NulPad (aName, CDF_ATTR_NAME_LEN); - } - else - { - strcpyX (aName, fp->ADRList[fp->CurADRIndex]->Name, - CDF_ATTR_NAME_LEN); - } - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case ADR_RECORDSIZE: { - if (read_only_mode == READONLYoff) - { - tOffset += ADR_RECORDSIZE_OFFSET; - } - else - { - *buffer = fp->ADRList[fp->CurADRIndex]->RecordSize; - }; - break; - } - case ADR_RECORDTYPE: { - if (read_only_mode == READONLYoff) - { - tOffset += ADR_RECORDTYPE_OFFSET; - } - else - { - *buffer = fp->ADRList[fp->CurADRIndex]->RecordType; - }; - break; - } - case ADR_ADRNEXT: { - if (read_only_mode == READONLYoff) - { - tOffset += ADR_ADRNEXT_OFFSET; - } - else - { - *buffer = fp->ADRList[fp->CurADRIndex]->ADRnext; - }; - break; - } - case ADR_AgrEDRHEAD: { - if (read_only_mode == READONLYoff) - { - tOffset += ADR_AgrEDRHEAD_OFFSET; - } - else - { - *buffer = fp->ADRList[fp->CurADRIndex]->AgrEDRhead; - }; - break; - } - case ADR_SCOPE: { - if (read_only_mode == READONLYoff) - { - tOffset += ADR_SCOPE_OFFSET; - } - else - { - *buffer = fp->ADRList[fp->CurADRIndex]->Scope; - }; - break; - } - case ADR_NUM: { - if (read_only_mode == READONLYoff) - { - tOffset += ADR_NUM_OFFSET; - } - else - { - *buffer = fp->ADRList[fp->CurADRIndex]->Num; - }; - break; - } - case ADR_NgrENTRIES: { - if (read_only_mode == READONLYoff) - { - tOffset += ADR_NgrENTRIES_OFFSET; - } - else - { - *buffer = fp->ADRList[fp->CurADRIndex]->NgrEntries; - }; - break; - } - case ADR_MAXgrENTRY: { - if (read_only_mode == READONLYoff) - { - tOffset += ADR_MAXgrENTRY_OFFSET; - } - else - { - *buffer = fp->ADRList[fp->CurADRIndex]->MAXgrEntry; - }; - break; - } - case ADR_AzEDRHEAD: { - if (read_only_mode == READONLYoff) - { - tOffset += ADR_AzEDRHEAD_OFFSET; - } - else - { - *buffer = fp->ADRList[fp->CurADRIndex]->AzEDRhead; - }; - break; - } - case ADR_NzENTRIES: { - if (read_only_mode == READONLYoff) - { - tOffset += ADR_NzENTRIES_OFFSET; - } - else - { - *buffer = fp->ADRList[fp->CurADRIndex]->NzEntries; - }; - break; - } - case ADR_MAXzENTRY: { - if (read_only_mode == READONLYoff) - { - tOffset += ADR_MAXzENTRY_OFFSET; - } - else - { - *buffer = fp->ADRList[fp->CurADRIndex]->MAXzEntry; - }; - break; - } - default: return CDF_INTERNAL_ERROR; - } - if (read_only_mode == READONLYoff) { - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32(fp,buffer)) return CRE; - }; - break; - } - } - } -} - -/****************************************************************************** -* ReadAEDR/AzEDR. -* If the entry value is being read, it is passed back in the encoding of the -* CDF (no decoding is performed). The caller must decode the value (if that -* is necessary). -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadAEDR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus ReadAEDR (va_alist) -va_dcl -#endif -{ - long read_only_mode; - struct AEDRstructExt *CurAEDR; - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - /*************************************************************************** - * If READONLYon and either an attribute or an entry have not been selected, - * return the appropriate status. If they have been selected but there is no - * entry for the selected attribute, return NO_SUCH_ENTRY. Note that for each - * attribute, entries are stored in an array which is indexed by the entry's - * number and if the selected entry number does not exist for the seleceted - * attribute, the entry list has a NULL pointer for that entry. Note also that - * the reading of ADRs and AEDRs into memory is triggered by the 1st time an - * ADR (or AEDR) is selected. - ***************************************************************************/ - if (read_only_mode == READONLYon) - { - if (fp->CurADRIndex == RESERVED_ENTRYNUM) - { - return NO_ATTR_SELECTED; - } - else if (fp->CurAEDRIndex == RESERVED_ENTRYNUM) - { - return NO_ENTRY_SELECTED; - } - else if (fp->CURzEntrySel) - { - if (fp->ADRList[fp->CurADRIndex]->zAEDRList[fp->CurAEDRIndex] != NULL) - { - CurAEDR = - fp->ADRList[fp->CurADRIndex]->zAEDRList[fp->CurAEDRIndex]; - } - else - { - return NO_SUCH_ENTRY; - }; - } - else - { - if (fp->ADRList[fp->CurADRIndex]->grAEDRList[fp->CurAEDRIndex] != - NULL) - { - CurAEDR = - fp->ADRList[fp->CurADRIndex]->grAEDRList[fp->CurAEDRIndex]; - } - else - { - return NO_SUCH_ENTRY; - }; - }; - }; - /*************************************************************************** - * For whatever AEDR data is selected, if READONLYon, read the data from memory - * using CurADRIndex and CurAEDRIndex to select the correct AEDR from the - * AEDRList. Otherwise, read the data from the file/cache using the file - * offset. - ***************************************************************************/ - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case AEDR_NULL: - va_end (ap); - return pStatus; - case AEDR_RECORD: { - struct AEDRstruct *AEDR = va_arg (ap, struct AEDRstruct *); - void *value = va_arg (ap, void *); size_t nBytes; - if (read_only_mode == READONLYoff) - { - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CRE; - if (!Read32(fp,&(AEDR->RecordSize))) return CRE; - if (!Read32(fp,&(AEDR->RecordType))) return CRE; - if (!Read32(fp,&(AEDR->AEDRnext))) return CRE; - if (!Read32(fp,&(AEDR->AttrNum))) return CRE; - if (!Read32(fp,&(AEDR->DataType))) return CRE; - if (!Read32(fp,&(AEDR->Num))) return CRE; - if (!Read32(fp,&(AEDR->NumElems))) return CRE; - if (!Read32(fp,&(AEDR->rfuA))) return CRE; - if (!Read32(fp,&(AEDR->rfuB))) return CRE; - if (!Read32(fp,&(AEDR->rfuC))) return CRE; - if (!Read32(fp,&(AEDR->rfuD))) return CRE; - if (!Read32(fp,&(AEDR->rfuE))) return CRE; - if (value != NULL) { - nBytes = (size_t) (CDFelemSize(AEDR->DataType) * - AEDR->NumElems); - if (!READv(value,nBytes,1,fp)) return CRE; - if (STRINGdataType(AEDR->DataType)) { - FillSpacesToString((char *)value, (int)AEDR->NumElems, - (int)AEDR->NumElems); - } - - }; - } - else - { - AEDR->RecordSize = CurAEDR->AEDR.RecordSize; - AEDR->RecordType = CurAEDR->AEDR.RecordType; - AEDR->AEDRnext = CurAEDR->AEDR.AEDRnext; - AEDR->AttrNum = CurAEDR->AEDR.AttrNum; - AEDR->DataType = CurAEDR->AEDR.DataType; - AEDR->Num = CurAEDR->AEDR.Num; - AEDR->NumElems = CurAEDR->AEDR.NumElems; - AEDR->rfuA = CurAEDR->AEDR.rfuA; - AEDR->rfuB = CurAEDR->AEDR.rfuB; - AEDR->rfuC = CurAEDR->AEDR.rfuC; - AEDR->rfuD = CurAEDR->AEDR.rfuD; - AEDR->rfuE = CurAEDR->AEDR.rfuE; - if (value != NULL) { - memcpy(value, CurAEDR->Value, CurAEDR->ValueSize); - }; - }; - break; - } - case AEDR_VALUE: { - void *value = va_arg (ap, void *); - if (read_only_mode == READONLYoff) - { - size_t nBytes; Int32 dataType, numElems; long tOffset; - if (!sX(ReadAEDR(fp,offset, - AEDR_DATATYPE,&dataType, - AEDR_NUMELEMS,&numElems, - AEDR_NULL),&pStatus)) return pStatus; - tOffset = offset + AEDR_VALUE_OFFSET; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - nBytes = (size_t) (CDFelemSize(dataType) * numElems); - if (!READv(value,nBytes,1,fp)) return CRE; - if (STRINGdataType(dataType)) { - FillSpacesToString((char *)value, (int)numElems, (int)numElems); - } - } - else - { - memcpy(value, CurAEDR->Value, CurAEDR->ValueSize); - }; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case AEDR_RECORDSIZE: { - if (read_only_mode == READONLYoff) - { - tOffset += AEDR_RECORDSIZE_OFFSET; - } - else - { - *buffer = CurAEDR->AEDR.RecordSize; - }; - break; - } - case AEDR_RECORDTYPE: { - if (read_only_mode == READONLYoff) - { - tOffset += AEDR_RECORDTYPE_OFFSET; - } - else - { - *buffer = CurAEDR->AEDR.RecordType; - }; - break; - } - case AEDR_AEDRNEXT: { - if (read_only_mode == READONLYoff) - { - tOffset += AEDR_AEDRNEXT_OFFSET; - } - else - { - *buffer = CurAEDR->AEDR.AEDRnext; - }; - break; - } - case AEDR_ATTRNUM: { - if (read_only_mode == READONLYoff) - { - tOffset += AEDR_ATTRNUM_OFFSET; - } - else - { - *buffer = CurAEDR->AEDR.AttrNum; - }; - break; - } - case AEDR_DATATYPE: { - if (read_only_mode == READONLYoff) - { - tOffset += AEDR_DATATYPE_OFFSET; - } - else - { - *buffer = CurAEDR->AEDR.DataType; - }; - break; - } - case AEDR_NUM: { - if (read_only_mode == READONLYoff) - { - tOffset += AEDR_NUM_OFFSET; - } - else - { - *buffer = CurAEDR->AEDR.Num; - }; - break; - } - case AEDR_NUMELEMS: { - if (read_only_mode == READONLYoff) - { - tOffset += AEDR_NUMELEMS_OFFSET; - } - else - { - *buffer = CurAEDR->AEDR.NumElems; - }; - break; - } - default: return CDF_INTERNAL_ERROR; - } - if (read_only_mode == READONLYoff) - { - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32(fp,buffer)) return CRE; - }; - break; - } - } - } -} - -/****************************************************************************** -* ReadVDR/zVDR. -* If the pad value is being read, it is passed back in the encoding of the -* CDF (no decoding is performed). The caller must decode the value (if that -* is necessary). -* If this CDF contains wasted space in its VDRs, note that the offset for -* those fields after the wasted space is adjusted. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadVDR (struct CDFstruct *CDF, vFILE *fp, - Int32 offset, Logical zVar, ...) -#else -STATICforIDL CDFstatus ReadVDR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, zVar); -#else - struct CDFstruct *CDF; vFILE *fp; Int32 offset; Logical zVar; - VA_START (ap); - CDF = va_arg (ap, struct CDFstruct *); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); - zVar = va_arg (ap, Logical); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case VDR_NULL: - va_end (ap); - return pStatus; - case VDR_RECORD: { - struct VDRstruct *VDR = va_arg (ap, struct VDRstruct *); - void *padValue = va_arg (ap, void *); Int32 nDims; - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CRE; - if (!Read32(fp,&(VDR->RecordSize))) return CRE; - if (!Read32(fp,&(VDR->RecordType))) return CRE; - if (!Read32(fp,&(VDR->VDRnext))) return CRE; - if (!Read32(fp,&(VDR->DataType))) return CRE; - if (!Read32(fp,&(VDR->MaxRec))) return CRE; - if (!Read32(fp,&(VDR->VXRhead))) return CRE; - if (!Read32(fp,&(VDR->VXRtail))) return CRE; - if (!Read32(fp,&(VDR->Flags))) return CRE; - if (!Read32(fp,&(VDR->sRecords))) return CRE; - if (!Read32(fp,&(VDR->rfuB))) return CRE; - if (!Read32(fp,&(VDR->rfuC))) return CRE; - if (!Read32(fp,&(VDR->rfuF))) return CRE; - if (CDF->wastedSpace) { - if (!SEEKv(fp,(long)VDR_WASTED_SIZE,vSEEK_CUR)) return CRE; - } - if (!Read32(fp,&(VDR->NumElems))) return CRE; - if (!Read32(fp,&(VDR->Num))) return CRE; - if (!Read32(fp,&(VDR->CPRorSPRoffset))) return CRE; - if (!Read32(fp,&(VDR->blockingFactor))) return CRE; - if (!READv(VDR->Name,CDF_VAR_NAME_LEN,1,fp)) return CRE; - NulPad (VDR->Name, CDF_VAR_NAME_LEN); - if (zVar) { - if (!Read32(fp,&(VDR->zNumDims))) return CRE; - if (VDR->zNumDims < 0 || VDR->zNumDims > CDF_MAX_DIMS) - return CV2C; - if (!Read32s(fp,VDR->zDimSizes,(int)VDR->zNumDims)) return CRE; - } - if (zVar) - nDims = VDR->zNumDims; - else { - long tOffset = V_tell (fp); Int32 GDRoffset; - if (!sX(ReadCDR(fp,V2_CDR_OFFSET, - CDR_GDROFFSET,&GDRoffset, - CDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadGDR(fp,GDRoffset, - GDR_rNUMDIMS,&nDims, - GDR_NULL),&pStatus)) return pStatus; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - } - if (nDims < 0 || nDims > CDF_MAX_DIMS) - return CV2C; - if (!Read32s(fp,VDR->DimVarys,(int)nDims)) return CRE; - if (PADvalueBITset(VDR->Flags) && padValue != NULL) { - size_t nBytes = (size_t) (CDFelemSize(VDR->DataType)*VDR->NumElems); - if (!READv(padValue,nBytes,1,fp)) return CRE; - if (STRINGdataType(VDR->DataType)) { - FillSpacesToString((char *)padValue, (int)VDR->NumElems, - (int)VDR->NumElems); - } - } - break; - } - case VDR_NAME: { - char *vName = va_arg (ap, char *); - long tOffset = offset + VDR_NAME_OFFSET; - if (CDF->wastedSpace) tOffset += VDR_WASTED_SIZE; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!READv(vName,CDF_VAR_NAME_LEN,1,fp)) return CRE; - NulPad (vName, CDF_VAR_NAME_LEN); - break; - } - case VDR_zNUMDIMS: { - Int32 *numDims = va_arg (ap, Int32 *); - long tOffset = offset + zVDR_zNUMDIMS_OFFSET + - BOO(CDF->wastedSpace,VDR_WASTED_SIZE,0); - if (!zVar) return CDF_INTERNAL_ERROR; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32(fp,numDims)) return CRE; - break; - } - case VDR_zDIMSIZES: { - Int32 *zDimSizes = va_arg (ap, Int32 *); - Int32 zNumDims; long tOffset; - if (!zVar) return CDF_INTERNAL_ERROR; - if (!sX(ReadVDR(CDF,fp,offset,zVar, - VDR_zNUMDIMS,&zNumDims, - VDR_NULL),&pStatus)) return pStatus; - tOffset = offset + zVDR_zDIMSIZES_OFFSET + - BOO(CDF->wastedSpace,VDR_WASTED_SIZE,0); - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (zNumDims < 0 || zNumDims > CDF_MAX_DIMS) - return CV2C; - if (!Read32s(fp,zDimSizes,(int)zNumDims)) return CRE; - break; - } - case VDR_DIMVARYS: { - Int32 *dimVarys = va_arg (ap, Int32 *); - Int32 nDims; long tOffset; - if (zVar) { - if (!sX(ReadVDR(CDF,fp,offset,zVar, - VDR_zNUMDIMS,&nDims, - VDR_NULL),&pStatus)) return pStatus; - tOffset = offset + zVDR_DIMVARYS_OFFSETb + (nDims*sizeof(Int32)) + - BOO(CDF->wastedSpace,VDR_WASTED_SIZE,0); - } - else { - Int32 GDRoffset; - if (!sX(ReadCDR(fp,V2_CDR_OFFSET, - CDR_GDROFFSET,&GDRoffset, - CDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadGDR(fp,GDRoffset, - GDR_rNUMDIMS,&nDims, - GDR_NULL),&pStatus)) return pStatus; - tOffset = offset + rVDR_DIMVARYS_OFFSET + - BOO(CDF->wastedSpace,VDR_WASTED_SIZE,0); - } - if (nDims < 0 || nDims > CDF_MAX_DIMS) - return CV2C; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32s(fp,dimVarys,(int)nDims)) return CRE; - break; - } - case VDR_PADVALUE: { - void *padValue = va_arg (ap, void *); - Int32 dataType, numElems; size_t nBytes; long tOffset; - if (!sX(ReadVDR(CDF,fp,offset,zVar, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_NULL),&pStatus)) return pStatus; - if (zVar) { - Int32 zNumDims; - if (!sX(ReadVDR(CDF,fp,offset,zVar, - VDR_zNUMDIMS,&zNumDims, - VDR_NULL),&pStatus)) return pStatus; - tOffset = offset + zVDR_PADVALUE_OFFSETb + - (zNumDims*sizeof(Int32)) + - (zNumDims*sizeof(Int32)) + - BOO(CDF->wastedSpace,VDR_WASTED_SIZE,0); - } - else { - Int32 rNumDims, GDRoffset; - if (!sX(ReadCDR(fp,V2_CDR_OFFSET, - CDR_GDROFFSET,&GDRoffset, - CDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadGDR(fp,GDRoffset, - GDR_rNUMDIMS,&rNumDims, - GDR_NULL),&pStatus)) return pStatus; - tOffset = offset + rVDR_PADVALUE_OFFSETb + - (rNumDims*sizeof(Int32)) + - BOO(CDF->wastedSpace,VDR_WASTED_SIZE,0); - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - nBytes = (size_t) (CDFelemSize(dataType) * numElems); - if (!READv(padValue,nBytes,1,fp)) return CRE; - if (STRINGdataType(dataType)) { - FillSpacesToString((char *)padValue, (int)numElems, - (int)numElems); - } - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case VDR_RECORDSIZE: tOffset += VDR_RECORDSIZE_OFFSET; break; - case VDR_RECORDTYPE: tOffset += VDR_RECORDTYPE_OFFSET; break; - case VDR_VDRNEXT: tOffset += VDR_VDRNEXT_OFFSET; break; - case VDR_DATATYPE: tOffset += VDR_DATATYPE_OFFSET; break; - case VDR_MAXREC: tOffset += VDR_MAXREC_OFFSET; break; - case VDR_VXRHEAD: tOffset += VDR_VXRHEAD_OFFSET; break; - case VDR_VXRTAIL: tOffset += VDR_VXRTAIL_OFFSET; break; - case VDR_FLAGS: tOffset += VDR_FLAGS_OFFSET; break; - case VDR_sRECORDS: tOffset += VDR_sRECORDS_OFFSET; break; - case VDR_NUMELEMS: - tOffset += (VDR_NUMELEMS_OFFSET + - BOO(CDF->wastedSpace,VDR_WASTED_SIZE,0)); - break; - case VDR_NUM: - tOffset += (VDR_NUM_OFFSET + - BOO(CDF->wastedSpace,VDR_WASTED_SIZE,0)); - break; - case VDR_CPRorSPR: - tOffset += (VDR_CPRorSPR_OFFSET + - BOO(CDF->wastedSpace,VDR_WASTED_SIZE,0)); - break; - case VDR_BLOCKING: - tOffset += (VDR_BLOCKING_OFFSET + - BOO(CDF->wastedSpace,VDR_WASTED_SIZE,0)); - break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadVXR. -******************************************************************************/ - -#if defined(STDARG) -VISIBLE_PREFIX CDFstatus ReadVXR (vFILE *fp, Int32 offset, ...) -#else -VISIBLE_PREFIX CDFstatus ReadVXR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case VXR_NULL: - va_end (ap); - return pStatus; - case VXR_RECORD: { - struct VXRstruct *VXR = va_arg (ap, struct VXRstruct *); - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CRE; - if (!Read32(fp,&(VXR->RecordSize))) return CRE; - if (!Read32(fp,&(VXR->RecordType))) return CRE; - if (!Read32(fp,&(VXR->VXRnext))) return CRE; - if (!Read32(fp,&(VXR->Nentries))) return CRE; - if (!Read32(fp,&(VXR->NusedEntries))) return CRE; - if (VXR->Nentries < 0 || VXR->Nentries > MAX_VXR_ENTRIES) - return CV2C; - if (!Read32s(fp,VXR->First,(int)VXR->Nentries)) return CRE; - if (!Read32s(fp,VXR->Last,(int)VXR->Nentries)) return CRE; - if (!Read32s(fp,VXR->Offset,(int)VXR->Nentries)) return CRE; - break; - } - case VXR_FIRSTREC: - case VXR_LASTREC: - case VXR_OFFSET: { - Int32 *buffer = va_arg (ap, Int32 *), nEntries; - long tOffset = offset + VXR_FIRSTREC_OFFSET; - if (!sX(ReadVXR(fp,offset, - VXR_NENTRIES,&nEntries, - VXR_NULL),&pStatus)) return pStatus; - switch (field) { - case VXR_FIRSTREC: break; - case VXR_LASTREC: tOffset += nEntries * sizeof(Int32); break; - case VXR_OFFSET: tOffset += 2 * nEntries * sizeof(Int32); break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (nEntries < 0 || nEntries > MAX_VXR_ENTRIES) - return CV2C; - if (!Read32s(fp,buffer,(int)nEntries)) return CRE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case VXR_RECORDSIZE: tOffset += VXR_RECORDSIZE_OFFSET; break; - case VXR_RECORDTYPE: tOffset += VXR_RECORDTYPE_OFFSET; break; - case VXR_VXRNEXT: tOffset += VXR_VXRNEXT_OFFSET; break; - case VXR_NENTRIES: tOffset += VXR_NENTRIES_OFFSET; break; - case VXR_NUSEDENTRIES: tOffset += VXR_NUSEDENTRIES_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadVVR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadVVR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus ReadVVR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case VVR_NULL: - va_end (ap); - return pStatus; - case VVR_RECORDx: { - struct VVRstruct *VVR = va_arg (ap, struct VVRstruct *); - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CRE; - if (!Read32(fp,&(VVR->RecordSize))) return CRE; - if (!Read32(fp,&(VVR->RecordType))) return CRE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case VVR_RECORDSIZE: tOffset += VVR_RECORDSIZE_OFFSET; break; - case VVR_RECORDTYPE: tOffset += VVR_RECORDTYPE_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadUIR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadUIR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus ReadUIR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case UIR_NULL: - va_end (ap); - return pStatus; - case UIR_RECORD: { - struct UIRstruct *UIR = va_arg (ap, struct UIRstruct *); - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CRE; - if (!Read32(fp,&(UIR->RecordSize))) return CRE; - if (!Read32(fp,&(UIR->RecordType))) return CRE; - if (!Read32(fp,&(UIR->NextUIR))) return CRE; - if (!Read32(fp,&(UIR->PrevUIR))) return CRE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case UIR_RECORDSIZE: tOffset += UIR_RECORDSIZE_OFFSET; break; - case UIR_RECORDTYPE: tOffset += UIR_RECORDTYPE_OFFSET; break; - case UIR_NEXTUIR: tOffset += UIR_NEXTUIR_OFFSET; break; - case UIR_PREVUIR: tOffset += UIR_PREVUIR_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadCCR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadCCR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus ReadCCR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CCR_NULL: - va_end (ap); - return pStatus; - case CCR_RECORD: { - struct CCRstruct *CCR = va_arg (ap, struct CCRstruct *); - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CRE; - if (!Read32(fp,&(CCR->RecordSize))) return CRE; - if (!Read32(fp,&(CCR->RecordType))) return CRE; - if (!Read32(fp,&(CCR->CPRoffset))) return CRE; - if (!Read32(fp,&(CCR->uSize))) return CRE; - if (!Read32(fp,&(CCR->rfuA))) return CRE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case CCR_RECORDSIZE: tOffset += CCR_RECORDSIZE_OFFSET; break; - case CCR_RECORDTYPE: tOffset += CCR_RECORDTYPE_OFFSET; break; - case CCR_CPROFFSET: tOffset += CCR_CPROFFSET_OFFSET; break; - case CCR_USIZE: tOffset += CCR_USIZE_OFFSET; break; - case CCR_RFUa: tOffset += CCR_RFUa_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadCPR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadCPR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus ReadCPR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CPR_NULL: - va_end (ap); - return pStatus; - case CPR_RECORD: { - struct CPRstruct *CPR = va_arg (ap, struct CPRstruct *); int i; - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CRE; - if (!Read32(fp,&(CPR->RecordSize))) return CRE; - if (!Read32(fp,&(CPR->RecordType))) return CRE; - if (!Read32(fp,&(CPR->cType))) return CRE; - if (!Read32(fp,&(CPR->rfuA))) return CRE; - if (!Read32(fp,&(CPR->pCount))) return CRE; - if (CPR->pCount > CDF_MAX_PARMS) return TOO_MANY_PARMS; - for (i = 0; i < CPR->pCount; i++) { - if (!Read32(fp,&(CPR->cParms[i]))) return CRE; - } - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case CPR_RECORDSIZE: tOffset += CPR_RECORDSIZE_OFFSET; break; - case CPR_RECORDTYPE: tOffset += CPR_RECORDTYPE_OFFSET; break; - case CPR_CTYPE: tOffset += CPR_CTYPE_OFFSET; break; - case CPR_RFUa: tOffset += CPR_RFUa_OFFSET; break; - case CPR_PCOUNT: tOffset += CPR_PCOUNT_OFFSET; break; - case CPR_CPARM1: tOffset += CPR_CPARM1_OFFSET; break; - case CPR_CPARM2: tOffset += CPR_CPARM2_OFFSET; break; - case CPR_CPARM3: tOffset += CPR_CPARM3_OFFSET; break; - case CPR_CPARM4: tOffset += CPR_CPARM4_OFFSET; break; - case CPR_CPARM5: tOffset += CPR_CPARM5_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadSPR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadSPR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus ReadSPR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case SPR_NULL: - va_end (ap); - return pStatus; - case SPR_RECORD: { - struct SPRstruct *SPR = va_arg (ap, struct SPRstruct *); int i; - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CRE; - if (!Read32(fp,&(SPR->RecordSize))) return CRE; - if (!Read32(fp,&(SPR->RecordType))) return CRE; - if (!Read32(fp,&(SPR->sArraysType))) return CRE; - if (!Read32(fp,&(SPR->rfuA))) return CRE; - if (!Read32(fp,&(SPR->pCount))) return CRE; - if (SPR->pCount > CDF_MAX_PARMS) return TOO_MANY_PARMS; - for (i = 0; i < SPR->pCount; i++) { - if (!Read32(fp,&(SPR->sArraysParms[i]))) return CRE; - } - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case SPR_RECORDSIZE: tOffset += SPR_RECORDSIZE_OFFSET; break; - case SPR_RECORDTYPE: tOffset += SPR_RECORDTYPE_OFFSET; break; - case SPR_STYPE: tOffset += SPR_STYPE_OFFSET; break; - case SPR_RFUa: tOffset += SPR_RFUa_OFFSET; break; - case SPR_PCOUNT: tOffset += SPR_PCOUNT_OFFSET; break; - case SPR_SPARM1: tOffset += SPR_SPARM1_OFFSET; break; - case SPR_SPARM2: tOffset += SPR_SPARM2_OFFSET; break; - case SPR_SPARM3: tOffset += SPR_SPARM3_OFFSET; break; - case SPR_SPARM4: tOffset += SPR_SPARM4_OFFSET; break; - case SPR_SPARM5: tOffset += SPR_SPARM5_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadCVVR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadCVVR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus ReadCVVR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CVVR_NULL: - va_end (ap); - return pStatus; - case CVVR_RECORDx: { - struct CVVRstruct *CVVR = va_arg (ap, struct CVVRstruct *); - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CRE; - if (!Read32(fp,&(CVVR->RecordSize))) return CRE; - if (!Read32(fp,&(CVVR->RecordType))) return CRE; - if (!Read32(fp,&(CVVR->rfuA))) return CRE; - if (!Read32(fp,&(CVVR->cSize))) return CRE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case CVVR_RECORDSIZE: tOffset += CVVR_RECORDSIZE_OFFSET; break; - case CVVR_RECORDTYPE: tOffset += CVVR_RECORDTYPE_OFFSET; break; - case CVVR_RFUa: tOffset += CVVR_RFUa_OFFSET; break; - case CVVR_CSIZE: tOffset += CVVR_CSIZE_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadADRList. -* Reads metadata into memory for future reference in READONLYon mode. -******************************************************************************/ - -STATICforIDL CDFstatus ReadADRList (vFILE *fp) -{ - Int32 nxtADR = fp->GDR->ADRhead; - CDFstatus pStatus = CDF_OK; - Int32 i; - - /************************************************************************** - * Allocate memory for the list of ADRs - ***************************************************************************/ - if (fp->GDR->NumAttr > 0) - fp->ADRList = cdf_AllocateMemory((size_t)fp->GDR->NumAttr * - sizeof(struct ADRstruct**), NULL); - if (fp->GDR->NumAttr > 0 && fp->ADRList == NULL) return BAD_MALLOC; - for (i = 0; i < fp->GDR->NumAttr; i++) - { - fp->ADRList[i] = cdf_AllocateMemory((size_t)sizeof(struct ADRstruct), NULL); - if (fp->ADRList[i] == NULL) return BAD_MALLOC; - }; - /*************************************************************************** - * Read the ADRs into the list - ****************************************************************************/ - for (i = 0; i < fp->GDR->NumAttr; i++) - { - if (!SEEKv(fp,nxtADR,vSEEK_SET)) return CRE; - if (!Read32(fp, &(fp->ADRList[i]->RecordSize))) return CRE; - if (!Read32(fp,&(fp->ADRList[i]->RecordType))) return CRE; - if (!Read32(fp,&nxtADR)) return CRE; - fp->ADRList[i]->ADRnext = 0; - if (!Read32(fp,&(fp->ADRList[i]->AgrEDRhead))) return CRE; - if (!Read32(fp,&(fp->ADRList[i]->Scope))) return CRE; - if (!Read32(fp,&(fp->ADRList[i]->Num))) return CRE; - if (!Read32(fp,&(fp->ADRList[i]->NgrEntries))) return CRE; - if (!Read32(fp,&(fp->ADRList[i]->MAXgrEntry))) return CRE; - if (!Read32(fp,&(fp->ADRList[i]->rfuA))) return CRE; - if (!Read32(fp,&(fp->ADRList[i]->AzEDRhead))) return CRE; - if (!Read32(fp,&(fp->ADRList[i]->NzEntries))) return CRE; - if (!Read32(fp,&(fp->ADRList[i]->MAXzEntry))) return CRE; - if (!Read32(fp,&(fp->ADRList[i]->rfuE))) return CRE; - if (!READv(fp->ADRList[i]->Name,CDF_ATTR_NAME_LEN,1,fp)) - return CRE; - NulPad (fp->ADRList[i]->Name, CDF_ATTR_NAME_LEN); - /*********************************************************************** - * Allocate memory for the lists of gAEDRs and zAEDRS associated with - * this ADR and read the AEDRs into the lists. - ***********************************************************************/ - pStatus = ReadAEDRList(fp, &(fp->ADRList[i]->grAEDRList), - fp->ADRList[i]->AgrEDRhead, - fp->ADRList[i]->NgrEntries, - fp->ADRList[i]->MAXgrEntry); - if (pStatus != CDF_OK) return pStatus; - pStatus = ReadAEDRList(fp, &(fp->ADRList[i]->zAEDRList), - fp->ADRList[i]->AzEDRhead, - fp->ADRList[i]->NzEntries, - fp->ADRList[i]->MAXzEntry); - if (pStatus != CDF_OK) return pStatus; - }; - return pStatus; -} - -/****************************************************************************** -* ReadAEDRList. -* Reads the set of entrys (zENTRYs or grENTRYs) associated with an attribute -* into a list indexed by the entry number. If there is no entry for a particular -* index (i.e., there is no entry for the associated variable/attribute -* pair), the list entry is NULL. -******************************************************************************/ -STATICforIDL CDFstatus ReadAEDRList (vFILE *fp, - struct AEDRstructExt ***AEDRList, - Int32 AEDRHead, - Int32 NumEntries, - Int32 MaxEntry) -{ - CDFstatus pStatus = CDF_OK; - Int32 NxtAEDR = AEDRHead; - struct AEDRstructExt *TempAEDR; - int iEntries; - int i; - /************************************************************************** - * Allocate memory for the list and initialize each entry to NULL. - **************************************************************************/ - if (MaxEntry >= 0) { - *AEDRList = cdf_AllocateMemory((size_t)(MaxEntry + 1) * - sizeof(struct AEDRstructExt**), NULL); - if (*AEDRList == NULL) return BAD_MALLOC; - } - else - { - *AEDRList = NULL; - return pStatus; - }; - - for (i = 0; i <= MaxEntry; i++) - { - (*AEDRList)[i] = NULL; - }; - iEntries = 0; - /*************************************************************************** - * Allocate memory for each AEDR, read each AEDR, and assign them to the list - * by entry number. - ***************************************************************************/ - while (NxtAEDR != 0 && iEntries != NumEntries) - { - TempAEDR = cdf_AllocateMemory((size_t)sizeof(struct AEDRstructExt), NULL); - if (TempAEDR == NULL) return BAD_MALLOC; - if (!SEEKv(fp,NxtAEDR,vSEEK_SET)) return CRE; - if (!Read32(fp,&(TempAEDR->AEDR.RecordSize))) return CRE; - if (!Read32(fp,&(TempAEDR->AEDR.RecordType))) return CRE; - if (!Read32(fp,&NxtAEDR)) return CRE; - TempAEDR->AEDR.AEDRnext = 0; - if (!Read32(fp,&(TempAEDR->AEDR.AttrNum))) return CRE; - if (!Read32(fp,&(TempAEDR->AEDR.DataType))) return CRE; - if (!Read32(fp,&(TempAEDR->AEDR.Num))) return CRE; - if (!Read32(fp,&(TempAEDR->AEDR.NumElems))) return CRE; - if (!Read32(fp,&(TempAEDR->AEDR.rfuA))) return CRE; - if (!Read32(fp,&(TempAEDR->AEDR.rfuB))) return CRE; - if (!Read32(fp,&(TempAEDR->AEDR.rfuC))) return CRE; - if (!Read32(fp,&(TempAEDR->AEDR.rfuD))) return CRE; - if (!Read32(fp,&(TempAEDR->AEDR.rfuE))) return CRE; - TempAEDR->ValueSize = (CDFelemSize(TempAEDR->AEDR.DataType) * - TempAEDR->AEDR.NumElems); - if (TempAEDR->ValueSize < 1) return CV2C; - TempAEDR->Value = cdf_AllocateMemory((size_t)TempAEDR->ValueSize, NULL); - if (TempAEDR->Value == NULL) return BAD_MALLOC; - if (!READv(TempAEDR->Value,TempAEDR->ValueSize,1,fp)) return CRE; - if (STRINGdataType(TempAEDR->AEDR.DataType)) { - FillSpacesToString((char *)(TempAEDR->Value), - (int)TempAEDR->AEDR.NumElems, - (int)TempAEDR->AEDR.NumElems); - } - ++iEntries; - if (TempAEDR->AEDR.Num < 0 || TempAEDR->AEDR.Num > MaxEntry) - return CV2C; - (*AEDRList)[TempAEDR->AEDR.Num] = TempAEDR; - }; - return pStatus; -} - diff --git a/cdf36_3-dist/src/lib/cdfread64.c b/cdf36_3-dist/src/lib/cdfread64.c deleted file mode 100644 index 01fec8b..0000000 --- a/cdf36_3-dist/src/lib/cdfread64.c +++ /dev/null @@ -1,2012 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Read from internal records for V3 CDF. -* -* Version 1.4a, 28-Feb-97, Hughes STX. -* -* Modification history: -* -* V1.0 30-Nov-94, J Love Original version. -* V1.1 30-Jan-95, J Love `Read32s' now checks count. -* V1.1a 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.2 26-May-95, J Love CDF V2.4 compatibility mode. What? -* V1.3 14-Jun-95, J Love Recursion! -* V1.3a 4-Aug-95, J Love More efficient `Read32' and `Read32s'. -* CDFexport-related changes. -* V1.4 3-Apr-96, J Love CDF V2.6. -* V1.4a 28-Feb-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V2.0 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* V3.2 21-Jun-07, D Berger Modified ReadGDR64, ReadADR64, and ReadAEDR64, -* and added ReadADRList64 and ReadAEDRList64 to -* support perfomance enhancements for accessing -* metadata in READONLYon mode. -* V3.2a 11-Apr-08, M Liu Modified Read32s_64 and Read64s_64 to -* eliminate the potential buffer overflow. -* V3.3 28-Jul-08, M Liu Modified to remove checks for wasted space as -* it is handled by cdfread.c for V2 CDF. -* V3.3a 15-Sep-08, M Liu Modified ReadAEDRList64 to pass in the number of -* entries to set up the list, not just the last -* entry number. -* V3.4 12-Aug-10, M Liu Replaced strcpy by strcpyX in ReadVDR. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* Local macro definitions. -******************************************************************************/ - -#define CRE CDF_READ_ERROR -#define CV3C CORRUPTED_V3_CDF - -/****************************************************************************** -* Read32_64. -******************************************************************************/ - -VISIBLE_PREFIX Logical Read32_64 (fp, value) -vFILE *fp; -Int32 *value; -{ -#if defined(NETWORKbyteORDERcpu) - if (!READv64(value,(size_t)4,(size_t)1,fp)) return FALSE; -#else - Int32 temp; - if (!READv64(&temp,(size_t)4,(size_t)1,fp)) return FALSE; - REVERSE4bIO (&temp, value) -#endif - return TRUE; -} - -/****************************************************************************** -* Read32s_64. -******************************************************************************/ - -STATICforIDL Logical Read32s_64 (fp, buffer, count) -vFILE *fp; -Int32 *buffer; -int count; -{ -#define MAX_READ32s CDF_MAX_DIMS /* This must be the maximum of - CDF_MAX_DIMS and MAX_VXR_ENTRIES - (and for any other uses of - `Read32s'). */ -#if defined(NETWORKbyteORDERcpu) - if (count == 0) return TRUE; - if (count < 0 || count > MAX_READ32s) return FALSE; - if (!READv64(buffer,(size_t)4,(size_t)count,fp)) return FALSE; -#else - int i; Int32 temp[MAX_READ32s]; - if (count == 0) return TRUE; - if (count < 0 || count > MAX_READ32s) return FALSE; - if (!READv64(temp,(size_t)4,(size_t)count,fp)) return FALSE; - for (i = 0; i < count; i++) { - REVERSE4bIO (&temp[i], &buffer[i]) - } -#endif - return TRUE; -} - -/****************************************************************************** -* Read64_64. -******************************************************************************/ - -VISIBLE_PREFIX Logical Read64_64 (fp, value) -vFILE *fp; -OFF_T *value; -{ -#if defined(NETWORKbyteORDERcpu) - if (!READv64(value,(size_t)8,(size_t)1,fp)) return FALSE; -#else - OFF_T temp; - if (!READv64(&temp,(size_t)8,(size_t)1,fp)) return FALSE; - REVERSE8bIO (&temp, value) -#endif - return TRUE; -} - -/****************************************************************************** -* Read64s_64. -******************************************************************************/ - -STATICforIDL Logical Read64s_64 (fp, buffer, count) -vFILE *fp; -OFF_T *buffer; -int count; -{ -#define MAX_READ64s CDF_MAX_DIMS /* This must be the maximum of - CDF_MAX_DIMS and MAX_VXR_ENTRIES - (and for any other uses of - `Read64s'). */ -#if defined(NETWORKbyteORDERcpu) - if (count == 0) return TRUE; - if (count < 0 || count > MAX_READ64s) return FALSE; - if (!READv64(buffer,(size_t)8,(size_t)count,fp)) return FALSE; -#else - int i; OFF_T temp[MAX_READ64s]; - if (count == 0) return TRUE; - if (count < 0 || count > MAX_READ64s) return FALSE; - if (!READv64(temp,(size_t)8,(size_t)count,fp)) return FALSE; - for (i = 0; i < count; i++) { - REVERSE8bIO (&temp[i], &buffer[i]) - } -#endif - return TRUE; -} - -/****************************************************************************** -* ReadIrSize64. -* The size is always in the first 4-byte field. -******************************************************************************/ - -STATICforIDL CDFstatus ReadIrSize64 (fp, offset, irSize) -vFILE *fp; -OFF_T offset; -OFF_T *irSize; -{ - if (!SEEKv64(fp,offset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,irSize)) return CRE; - return CDF_OK; -} - -/****************************************************************************** -* ReadIrType64. -* The type is always in the second field (4-byte) after the size. -******************************************************************************/ - -VISIBLE_PREFIX CDFstatus ReadIrType64 (fp, offset, irType) -vFILE *fp; -OFF_T offset; -Int32 *irType; -{ - OFF_T irTypeOffset = offset + sizeof(OFF_T); - if (!SEEKv64(fp,irTypeOffset,vSEEK_SET)) return CRE; - if (!Read32_64(fp,irType)) return CRE; - return CDF_OK; -} - -/****************************************************************************** -* ReadCDR64. -* Note that the length of the CDF copyright was decreased in CDF V2.5 (there -* were way too many characters allowed for). When reading the copyright, only -* CDF_COPYRIGHT_LEN characters will be read. This will be less than the -* actual number in CDFs prior to CDF V2.4 but is enough to include all of the -* characters that were used. (The value of CDF_COPYRIGHT_LEN was decreased -* from CDF V2.4 to CDF V2.5.) -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadCDR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus ReadCDR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CDR_NULL: - va_end (ap); - return pStatus; - case CDR_RECORD: { - struct CDRstruct64 *CDR = va_arg (ap, struct CDRstruct64 *); - void *copyRight = va_arg (ap, char *); - if (!SEEKv64(fp,offset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,&(CDR->RecordSize))) return CRE; - if (!Read32_64(fp,&(CDR->RecordType))) return CRE; - if (!Read64_64(fp,&(CDR->GDRoffset))) return CRE; - /* group read for Version, Release, Encoding, Flags, rfuA, rfuB, - Increment, rfuD, rfuE -- all 4-byte big-endian. */ - if (!Read32s_64(fp,&(CDR->Version),9)) return CRE; - /* - if (!Read32_64(fp,&(CDR->Version))) return CRE; - if (!Read32_64(fp,&(CDR->Release))) return CRE; - if (!Read32_64(fp,&(CDR->Encoding))) return CRE; - if (!Read32_64(fp,&(CDR->Flags))) return CRE; - if (!Read32_64(fp,&(CDR->rfuA))) return CRE; - if (!Read32_64(fp,&(CDR->rfuB))) return CRE; - if (!Read32_64(fp,&(CDR->Increment))) return CRE; - if (!Read32_64(fp,&(CDR->rfuD))) return CRE; - if (!Read32_64(fp,&(CDR->rfuE))) return CRE; - */ - if (copyRight != NULL) { - if (!READv64(copyRight,CDF_COPYRIGHT_LEN,1,fp)) return CRE; - NulPad (copyRight, CDF_COPYRIGHT_LEN); - } - break; - } - case CDR_COPYRIGHT: { - void *copyRight = va_arg (ap, char *); - OFF_T tOffset = offset + (OFF_T) CDR_COPYRIGHT_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!READv64(copyRight,CDF_COPYRIGHT_LEN,1,fp)) return CRE; - NulPad (copyRight, CDF_COPYRIGHT_LEN); - break; - } - case CDR_RECORDSIZE: - case CDR_GDROFFSET: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case CDR_RECORDSIZE: tOffset += (OFF_T) CDR_RECORDSIZE_OFFSET64; break; - case CDR_GDROFFSET: tOffset += (OFF_T) CDR_GDROFFSET_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,buffer)) return CRE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); - OFF_T tOffset = offset; - switch (field) { - case CDR_RECORDTYPE: tOffset += (OFF_T) CDR_RECORDTYPE_OFFSET64; break; - case CDR_VERSION: tOffset += (OFF_T) CDR_VERSION_OFFSET64; break; - case CDR_RELEASE: tOffset += (OFF_T) CDR_RELEASE_OFFSET64; break; - case CDR_ENCODING: tOffset += (OFF_T) CDR_ENCODING_OFFSET64; break; - case CDR_FLAGS: tOffset += (OFF_T) CDR_FLAGS_OFFSET64; break; - case CDR_INCREMENT: tOffset += (OFF_T) CDR_INCREMENT_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32_64(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadGDR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadGDR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus ReadGDR64 (va_alist) -va_dcl -#endif -{ - long read_only_mode; - int i; - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - /*************************************************************************** - * Check read only mode. If it is invalid, it may have not been initialized - - * set it to off. - ***************************************************************************/ - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - if (read_only_mode != READONLYon && read_only_mode != READONLYoff) - { - read_only_mode = READONLYoff; - }; - /*************************************************************************** - * If READONLYon, read the GDR into memory for future reference. - ***************************************************************************/ - if (read_only_mode == READONLYon && fp->GDR64 == NULL) - { - fp->GDR64 = cdf_AllocateMemory((size_t)sizeof(struct GDRstruct64), NULL); - if (fp->GDR64 == NULL) return CRE; - if (!SEEKv64(fp,offset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,&(fp->GDR64->RecordSize))) return CRE; - if (!Read32_64(fp,&(fp->GDR64->RecordType))) return CRE; - /* group read for rVDRhead, zVDRhead, ADRhead, eof -- all 8-byte - big-endian */ - if (!Read64s_64(fp,&(fp->GDR64->rVDRhead),4)) return CRE; - /* - if (!Read64_64(fp,&(fp->GDR64->rVDRhead))) return CRE; - if (!Read64_64(fp,&(fp->GDR64->zVDRhead))) return CRE; - if (!Read64_64(fp,&(fp->GDR64->ADRhead))) return CRE; - if (!Read64_64(fp,&(fp->GDR64->eof))) return CRE; - */ - /* group read for NrVars, NumAttr, rMaxRec, rNumDims, NzVars -- all - 4-byte big-endian */ - if (!Read32s_64(fp,&(fp->GDR64->NrVars),5)) return CRE; - /* - if (!Read32_64(fp,&(fp->GDR64->NrVars))) return CRE; - if (!Read32_64(fp,&(fp->GDR64->NumAttr))) return CRE; - if (!Read32_64(fp,&(fp->GDR64->rMaxRec))) return CRE; - if (!Read32_64(fp,&(fp->GDR64->rNumDims))) return CRE; - if (!Read32_64(fp,&(fp->GDR64->NzVars))) return CRE; - */ - if (!Read64_64(fp,&(fp->GDR64->UIRhead))) return CRE; - /* group read for rfuC, LeapSecondLastUpdated, rfuE -- all 4-byte - big-endian */ - if (!Read32s_64(fp,&(fp->GDR64->rfuC),3)) return CRE; - /* - if (!Read32_64(fp,&(fp->GDR64->rfuC))) return CRE; - if (!Read32_64(fp,&(fp->GDR64->LeapSecondLastUpdated))) return CRE; - if (!Read32_64(fp,&(fp->GDR64->rfuE))) return CRE; - */ - if (fp->GDR64->rNumDims < 0 || - fp->GDR64->rNumDims > CDF_MAX_DIMS) return CV3C; - if (!Read32s_64(fp,fp->GDR64->rDimSizes, - (int)fp->GDR64->rNumDims)) return CRE; - pStatus = ReadADRList64(fp); - if (pStatus != CDF_OK) return pStatus; - }; - /************************************************************************** - * For whatever data is requested from the GDR, if READONLYon, get the data - * from the GDR in memory, otherwise read from the file/cache. - ***************************************************************************/ - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case GDR_NULL: - va_end (ap); - return pStatus; - case GDR_RECORD: { - struct GDRstruct64 *GDR = va_arg (ap, struct GDRstruct64 *); - if (read_only_mode == READONLYoff) - { - if (!SEEKv64(fp,offset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,&(GDR->RecordSize))) return CRE; - if (!Read32_64(fp,&(GDR->RecordType))) return CRE; - if (!Read64s_64(fp,&(GDR->rVDRhead),4)) return CRE; - /* - if (!Read64_64(fp,&(GDR->rVDRhead))) return CRE; - if (!Read64_64(fp,&(GDR->zVDRhead))) return CRE; - if (!Read64_64(fp,&(GDR->ADRhead))) return CRE; - if (!Read64_64(fp,&(GDR->eof))) return CRE; - */ - if (!Read32s_64(fp,&(GDR->NrVars),5)) return CRE; - /* - if (!Read32_64(fp,&(GDR->NrVars))) return CRE; - if (!Read32_64(fp,&(GDR->NumAttr))) return CRE; - if (!Read32_64(fp,&(GDR->rMaxRec))) return CRE; - if (!Read32_64(fp,&(GDR->rNumDims))) return CRE; - if (!Read32_64(fp,&(GDR->NzVars))) return CRE; - */ - if (!Read64_64(fp,&(GDR->UIRhead))) return CRE; - if (!Read32s_64(fp,&(GDR->rfuC),3)) return CRE; - /* - if (!Read32_64(fp,&(GDR->rfuC))) return CRE; - if (!Read32_64(fp,&(GDR->LeapSecondLastUpdated))) return CRE; - if (!Read32_64(fp,&(GDR->rfuE))) return CRE; - */ - if (GDR->rNumDims < 0 || - GDR->rNumDims > CDF_MAX_DIMS) break; /* return CV3C; */ - if (!Read32s_64(fp,GDR->rDimSizes,(int)GDR->rNumDims)) return CRE; - } - else - { - GDR->RecordSize = fp->GDR64->RecordSize; - GDR->RecordType = fp->GDR64->RecordType; - GDR->rVDRhead = fp->GDR64->rVDRhead; - GDR->zVDRhead = fp->GDR64->zVDRhead; - GDR->ADRhead = fp->GDR64->ADRhead; - GDR->eof = fp->GDR64->eof; - GDR->NrVars = fp->GDR64->NrVars; - GDR->NumAttr = fp->GDR64->NumAttr; - GDR->rMaxRec = fp->GDR64->rMaxRec; - GDR->rNumDims = fp->GDR64->rNumDims; - GDR->NzVars = fp->GDR64->NzVars; - GDR->UIRhead = fp->GDR64->UIRhead; - GDR->rfuC = fp->GDR64->rfuC; - GDR->LeapSecondLastUpdated = fp->GDR64->LeapSecondLastUpdated; - GDR->rfuE = fp->GDR64->rfuE; - for (i = 0; i < GDR->rNumDims; i++) - { - GDR->rDimSizes[i] = fp->GDR64->rDimSizes[i]; - }; - }; - break; - } - case GDR_rDIMSIZES: { - Int32 *rDimSizes = va_arg (ap, Int32 *); - if (read_only_mode == READONLYoff) - { - Int32 rNumDims; - OFF_T tOffset; - if (!sX(ReadGDR64(fp,offset, - GDR_rNUMDIMS,&rNumDims, - GDR_NULL),&pStatus)) return pStatus; - tOffset = offset + (OFF_T) GDR_rDIMSIZES_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (rNumDims < 0 || rNumDims > CDF_MAX_DIMS) - return CV3C; - if (!Read32s_64(fp,rDimSizes,(int)rNumDims)) return CRE; - } - else - { - for (i = 0; i < fp->GDR64->rNumDims; i++) - { - rDimSizes[i] = fp->GDR64->rDimSizes[i]; - }; - } - break; - } - case GDR_RECORDSIZE: - case GDR_rVDRHEAD: - case GDR_zVDRHEAD: - case GDR_ADRHEAD: - case GDR_EOF: - case GDR_UIRHEAD: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case GDR_RECORDSIZE: { - if (read_only_mode == READONLYoff) - { - tOffset += (OFF_T) GDR_RECORDSIZE_OFFSET64; break; - } - else - { - *buffer = fp->GDR64->RecordSize; - }; - break; - }; - case GDR_rVDRHEAD: { - if (read_only_mode == READONLYoff) - { - tOffset += (OFF_T) GDR_rVDRHEAD_OFFSET64; - } - else - { - *buffer = fp->GDR64->rVDRhead; - }; - break; - }; - case GDR_zVDRHEAD: { - if (read_only_mode == READONLYoff) - { - tOffset += (OFF_T) GDR_zVDRHEAD_OFFSET64; - } - else - { - *buffer = fp->GDR64->zVDRhead; - }; - break; - }; - case GDR_ADRHEAD: { - if (read_only_mode == READONLYoff) - { - tOffset += (OFF_T) GDR_ADRHEAD_OFFSET64; - } - else - { - *buffer = fp->GDR64->ADRhead; - }; - break; - }; - case GDR_EOF: { - if (read_only_mode == READONLYoff) - { - tOffset += (OFF_T) GDR_EOF_OFFSET64; - } - else - { - *buffer = fp->GDR64->eof; - }; - break; - }; - case GDR_UIRHEAD: { - if (read_only_mode == READONLYoff) - { - tOffset += (OFF_T) GDR_UIRHEAD_OFFSET64; break; - } - else - { - *buffer = fp->GDR64->UIRhead; - }; - break; - }; - default: return CDF_INTERNAL_ERROR; - } - if (read_only_mode == READONLYoff) - { - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,buffer)) return CRE; - } - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { - case GDR_RECORDTYPE: { - if (read_only_mode == READONLYoff) - { - tOffset += (OFF_T) GDR_RECORDTYPE_OFFSET64; - } - else - { - *buffer = fp->GDR64->RecordType; - }; - break; - }; - case GDR_NrVARS: { - if (read_only_mode == READONLYoff) - { - tOffset += (OFF_T) GDR_NrVARS_OFFSET64; - } - else - { - *buffer = fp->GDR64->NrVars; - }; - break; - }; - case GDR_NUMATTR: { - if (read_only_mode == READONLYoff) - { - tOffset +=(OFF_T) GDR_NUMATTR_OFFSET64; - } - else - { - *buffer = fp->GDR64->NumAttr; - }; - break; - }; - case GDR_rMAXREC: { - if (read_only_mode == READONLYoff) - { - tOffset +=(OFF_T) GDR_rMAXREC_OFFSET64; - } - else - { - *buffer = fp->GDR64->rMaxRec; - }; - break; - }; - case GDR_rNUMDIMS: { - if (read_only_mode == READONLYoff) - { - tOffset +=(OFF_T) GDR_rNUMDIMS_OFFSET64; - } - else - { - *buffer = fp->GDR64->rNumDims; - }; - break; - }; - case GDR_NzVARS: { - if (read_only_mode == READONLYoff) - { - tOffset +=(OFF_T) GDR_NzVARS_OFFSET64; break; - } - else - { - *buffer = fp->GDR64->NzVars; - }; - break; - }; - case GDR_LEAPSECONDLASTUPDATED: { - if (read_only_mode == READONLYoff) - { - tOffset +=(OFF_T) GDR_LEAPSECONDLASTUPDATED_OFFSET64; break; - } - else - { - *buffer = fp->GDR64->LeapSecondLastUpdated; - }; - break; - }; - default: return CDF_INTERNAL_ERROR; - } - if (read_only_mode == READONLYoff) - { - if (!SEEKv64(fp,tOffset,vSEEK_SET)) { - return CRE; - }; - if (!Read32_64(fp,buffer)) { - return CRE; - }; - } - break; - } - } - } -} - -/****************************************************************************** -* ReadADR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadADR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus ReadADR64 (va_alist) -va_dcl -#endif -{ - long read_only_mode; - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - /*************************************************************************** - * IF READONLYon, and there are no ADRs in memory or no attribute has been - * selected, return NO_ATTR_SELECTED. Note that reading of ADRs into memory - * is triggered the 1st time an ADR is selected. - ***************************************************************************/ - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - if (read_only_mode == READONLYon && fp->CurADRIndex == RESERVED_ENTRYNUM) - { - return NO_ATTR_SELECTED; - }; - /*************************************************************************** - * For whatever ADR data is selected, if READONLYon, read the data from memory - * using CurADRIndex to select the correct ADR from the ADRList. Otherwise, - * read the data from the file/cache using the file offset. - ***************************************************************************/ - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case ADR_NULL: - va_end (ap); - return pStatus; - case ADR_RECORD: { - struct ADRstruct64 *ADR = va_arg (ap, struct ADRstruct64 *); - if (read_only_mode == READONLYoff) - { - if (!SEEKv64(fp,offset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,&(ADR->RecordSize))) return CRE; - if (!Read32_64(fp,&(ADR->RecordType))) return CRE; - if (!Read64s_64(fp,&(ADR->ADRnext),2)) return CRE; - /* - if (!Read64_64(fp,&(ADR->ADRnext))) return CRE; - if (!Read64_64(fp,&(ADR->AgrEDRhead))) return CRE; - */ - if (!Read32s_64(fp,&(ADR->Scope),5)) return CRE; - /* - if (!Read32_64(fp,&(ADR->Scope))) return CRE; - if (!Read32_64(fp,&(ADR->Num))) return CRE; - if (!Read32_64(fp,&(ADR->NgrEntries))) return CRE; - if (!Read32_64(fp,&(ADR->MAXgrEntry))) return CRE; - if (!Read32_64(fp,&(ADR->rfuA))) return CRE; - */ - if (!Read64_64(fp,&(ADR->AzEDRhead))) return CRE; - if (!Read32s_64(fp,&(ADR->NzEntries),3)) return CRE; - /* - if (!Read32_64(fp,&(ADR->NzEntries))) return CRE; - if (!Read32_64(fp,&(ADR->MAXzEntry))) return CRE; - if (!Read32_64(fp,&(ADR->rfuE))) return CRE; - */ - if (!READv64(ADR->Name,CDF_ATTR_NAME_LEN256,1,fp)) return CRE; - NulPad (ADR->Name, CDF_ATTR_NAME_LEN256); - } - else - { - ADR->RecordSize = fp->ADRList64[fp->CurADRIndex]->RecordSize; - ADR->RecordType = fp->ADRList64[fp->CurADRIndex]->RecordType; - ADR->ADRnext = fp->ADRList64[fp->CurADRIndex]->ADRnext; - ADR->AgrEDRhead = fp->ADRList64[fp->CurADRIndex]->AgrEDRhead; - ADR->Scope = fp->ADRList64[fp->CurADRIndex]->Scope; - ADR->Num = fp->ADRList64[fp->CurADRIndex]->Num; - ADR->NgrEntries = fp->ADRList64[fp->CurADRIndex]->NgrEntries; - ADR->MAXgrEntry = fp->ADRList64[fp->CurADRIndex]->MAXgrEntry; - ADR->rfuA = fp->ADRList64[fp->CurADRIndex]->rfuA; - ADR->AzEDRhead = fp->ADRList64[fp->CurADRIndex]->AzEDRhead; - ADR->NzEntries = fp->ADRList64[fp->CurADRIndex]->NzEntries; - ADR->MAXzEntry = fp->ADRList64[fp->CurADRIndex]->MAXzEntry; - ADR->rfuE = fp->ADRList64[fp->CurADRIndex]->rfuE; - strcpyX (ADR->Name, fp->ADRList64[fp->CurADRIndex]->Name, - CDF_ATTR_NAME_LEN256); - }; - break; - }; - case ADR_NAME: { - char *aName = va_arg (ap, char *); - if (read_only_mode == READONLYoff) { - OFF_T tOffset = offset + ADR_NAME_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!READv64(aName,CDF_ATTR_NAME_LEN256,1,fp)) return CRE; - NulPad (aName, CDF_ATTR_NAME_LEN256); - } - else { - strcpyX (aName, fp->ADRList64[fp->CurADRIndex]->Name, - CDF_ATTR_NAME_LEN256); - } - break; - } - case ADR_RECORDSIZE: - case ADR_ADRNEXT: - case ADR_AgrEDRHEAD: - case ADR_AzEDRHEAD: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case ADR_RECORDSIZE: { - if (read_only_mode == READONLYoff) { - tOffset += (OFF_T) ADR_RECORDSIZE_OFFSET64; - } - else { - *buffer = fp->ADRList64[fp->CurADRIndex]->RecordSize; - } - break; - } - case ADR_ADRNEXT: { - if (read_only_mode == READONLYoff) { - tOffset += (OFF_T) ADR_ADRNEXT_OFFSET64; - } - else { - *buffer = fp->ADRList64[fp->CurADRIndex]->ADRnext; - } - break; - } - case ADR_AgrEDRHEAD: { - if (read_only_mode == READONLYoff) { - tOffset += (OFF_T) ADR_AgrEDRHEAD_OFFSET64; - } - else { - *buffer = fp->ADRList64[fp->CurADRIndex]->AgrEDRhead; - }; - break; - } - case ADR_AzEDRHEAD: { - if (read_only_mode == READONLYoff) { - tOffset += (OFF_T) ADR_AzEDRHEAD_OFFSET64; - } - else { - *buffer = fp->ADRList64[fp->CurADRIndex]->AzEDRhead; - } - break; - } - default: return CDF_INTERNAL_ERROR; - } - if (read_only_mode == READONLYoff) { - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,buffer)) return CRE; - }; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { - case ADR_RECORDTYPE: { - if (read_only_mode == READONLYoff) { - tOffset += (OFF_T) ADR_RECORDTYPE_OFFSET64; - } - else { - *buffer = fp->ADRList64[fp->CurADRIndex]->RecordType; - } - break; - } - case ADR_SCOPE: { - if (read_only_mode == READONLYoff) { - tOffset += (OFF_T) ADR_SCOPE_OFFSET64; - } - else { - *buffer = fp->ADRList64[fp->CurADRIndex]->Scope; - } - break; - } - case ADR_NUM: { - if (read_only_mode == READONLYoff) { - tOffset += (OFF_T) ADR_NUM_OFFSET64; - } - else { - *buffer = fp->ADRList64[fp->CurADRIndex]->Num; - } - break; - } - case ADR_NgrENTRIES: { - if (read_only_mode == READONLYoff) { - tOffset += (OFF_T) ADR_NgrENTRIES_OFFSET64; - } - else { - *buffer = fp->ADRList64[fp->CurADRIndex]->NgrEntries; - } - break; - } - case ADR_MAXgrENTRY: { - if (read_only_mode == READONLYoff) { - tOffset += (OFF_T) ADR_MAXgrENTRY_OFFSET64; - } - else { - *buffer = fp->ADRList64[fp->CurADRIndex]->MAXgrEntry; - } - break; - } - case ADR_NzENTRIES: { - if (read_only_mode == READONLYoff) { - tOffset += (OFF_T) ADR_NzENTRIES_OFFSET64; - } - else { - *buffer = fp->ADRList64[fp->CurADRIndex]->NzEntries; - } - break; - } - case ADR_MAXzENTRY: { - if (read_only_mode == READONLYoff) { - tOffset += (OFF_T) ADR_MAXzENTRY_OFFSET64; - } - else { - *buffer = fp->ADRList64[fp->CurADRIndex]->MAXzEntry; - } - break; - } - default: return CDF_INTERNAL_ERROR; - } - if (read_only_mode == READONLYoff) { - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32_64(fp,buffer)) return CRE; - } - break; - } - } - } -} - -/****************************************************************************** -* ReadAEDR64/AzEDR64. -* If the entry value is being read, it is passed back in the encoding of the -* CDF (no decoding is performed). The caller must decode the value (if that -* is necessary). -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadAEDR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus ReadAEDR64 (va_alist) -va_dcl -#endif -{ - long read_only_mode; - struct AEDRstructExt64 *CurAEDR; - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - pStatus = CDFlib(CONFIRM_, CDF_READONLY_MODE_, &read_only_mode, NULL_); - if (pStatus != CDF_OK) return pStatus; - /*************************************************************************** - * If READONLYon and either an attribute or an entry have not been selected, - * return the appropriate status. If they have been selected but there is no - * entry for the selected attribute, return BAD_ENTRY_NUM. Note that for each - * attribute, entries are stored in an array which is indexed by the entry's - * number and if the selected entry number does not exist for the seleceted - * attribute, the entry list has a NULL pointer for that entry. Note also that - * the reading of ADRs and AEDRs into memory is triggered by the 1st time an - * ADR (or AEDR) is selected. - ***************************************************************************/ - if (read_only_mode == READONLYon) - { - if (fp->CurADRIndex == RESERVED_ENTRYNUM) - { - return NO_ATTR_SELECTED; - } - else if (fp->CurAEDRIndex == RESERVED_ENTRYNUM) - { - return NO_ENTRY_SELECTED; - } - else if (fp->CURzEntrySel) - { - if (fp->ADRList64[fp->CurADRIndex]->zAEDRList64[fp->CurAEDRIndex] - != NULL) - { - CurAEDR = - fp->ADRList64[fp->CurADRIndex]->zAEDRList64[fp->CurAEDRIndex]; - } - else - { - return NO_SUCH_ENTRY; - }; - } - else - { - if (fp->ADRList64[fp->CurADRIndex]->grAEDRList64[fp->CurAEDRIndex] != - NULL) - { - CurAEDR = - fp->ADRList64[fp->CurADRIndex]->grAEDRList64[fp->CurAEDRIndex]; - } - else - { - return NO_SUCH_ENTRY; - }; - }; - }; - /*************************************************************************** - * For whatever AEDR data is selected, if READONLYon, read the data from memory - * using CurADRIndex and CurAEDRIndex to select the correct AEDR from the - * AEDRList. Otherwise, read the data from the file/cache using the file - * offset. - ***************************************************************************/ - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case AEDR_NULL: - va_end (ap); - return pStatus; - case AEDR_RECORD: { - struct AEDRstruct64 *AEDR = va_arg (ap, struct AEDRstruct64 *); - void *value = va_arg (ap, void *); size_t nBytes; - if (read_only_mode == READONLYoff) - { - if (!SEEKv64(fp,offset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,&(AEDR->RecordSize))) return CRE; - if (!Read32_64(fp,&(AEDR->RecordType))) return CRE; - if (!Read64_64(fp,&(AEDR->AEDRnext))) return CRE; - if (!Read32s_64(fp,&(AEDR->AttrNum),9)) return CRE; - /* - if (!Read32_64(fp,&(AEDR->AttrNum))) return CRE; - if (!Read32_64(fp,&(AEDR->DataType))) return CRE; - if (!Read32_64(fp,&(AEDR->Num))) return CRE; - if (!Read32_64(fp,&(AEDR->NumElems))) return CRE; - if (!Read32_64(fp,&(AEDR->rfuA))) return CRE; - if (!Read32_64(fp,&(AEDR->rfuB))) return CRE; - if (!Read32_64(fp,&(AEDR->rfuC))) return CRE; - if (!Read32_64(fp,&(AEDR->rfuD))) return CRE; - if (!Read32_64(fp,&(AEDR->rfuE))) return CRE; - */ - if (value != NULL) { - nBytes = (size_t) (CDFelemSize(AEDR->DataType) * - AEDR->NumElems); - if (!READv64(value,nBytes,1,fp)) return CRE; - if (STRINGdataType(AEDR->DataType)) { - FillSpacesToString((char *)value, (int)AEDR->NumElems, - (int)AEDR->NumElems); - } - }; - } - else - { - AEDR->RecordSize = CurAEDR->AEDR.RecordSize; - AEDR->RecordType = CurAEDR->AEDR.RecordType; - AEDR->AEDRnext = CurAEDR->AEDR.AEDRnext; - AEDR->AttrNum = CurAEDR->AEDR.AttrNum; - AEDR->DataType = CurAEDR->AEDR.DataType; - AEDR->Num = CurAEDR->AEDR.Num; - AEDR->NumElems = CurAEDR->AEDR.NumElems; - AEDR->rfuA = CurAEDR->AEDR.rfuA; - AEDR->rfuB = CurAEDR->AEDR.rfuB; - AEDR->rfuC = CurAEDR->AEDR.rfuC; - AEDR->rfuD = CurAEDR->AEDR.rfuD; - AEDR->rfuE = CurAEDR->AEDR.rfuE; - if (value != NULL) { - memcpy(value, CurAEDR->Value, CurAEDR->ValueSize); - }; - }; - break; - } - case AEDR_VALUE: { - void *value = va_arg (ap, void *); - if (read_only_mode == READONLYoff) - { - size_t nBytes; Int32 dataType, numElems; OFF_T tOffset; - if (!sX(ReadAEDR64(fp,offset, - AEDR_DATATYPE,&dataType, - AEDR_NUMELEMS,&numElems, - AEDR_NULL),&pStatus)) return pStatus; - tOffset = offset + (OFF_T) AEDR_VALUE_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - nBytes = (size_t) (CDFelemSize(dataType) * numElems); - if (!READv64(value,nBytes,1,fp)) return CRE; - if (STRINGdataType(dataType)) { - FillSpacesToString((char *)value, (int)numElems, (int)numElems); - } - } - else - { - memcpy(value, CurAEDR->Value, CurAEDR->ValueSize); - } - break; - } - case AEDR_RECORDSIZE: - case AEDR_AEDRNEXT: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case AEDR_RECORDSIZE: { - if (read_only_mode == READONLYoff) - { - tOffset += (OFF_T) AEDR_RECORDSIZE_OFFSET64; - } - else - { - *buffer = CurAEDR->AEDR.RecordSize; - }; - break; - }; - case AEDR_AEDRNEXT: { - if (read_only_mode == READONLYoff) - { - tOffset += (OFF_T) AEDR_AEDRNEXT_OFFSET64; - } - else - { - *buffer = CurAEDR->AEDR.AEDRnext; - } - break; - } - default: return CDF_INTERNAL_ERROR; - } - if (read_only_mode == READONLYoff) - { - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,buffer)) return CRE; - }; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { - case AEDR_RECORDTYPE: { - if (read_only_mode == READONLYoff) - { - tOffset += (OFF_T) AEDR_RECORDTYPE_OFFSET64; - } - else - { - *buffer = CurAEDR->AEDR.RecordType; - } - break; - } - case AEDR_ATTRNUM: { - if (read_only_mode == READONLYoff) - { - tOffset += (OFF_T) AEDR_ATTRNUM_OFFSET64; - } - else - { - *buffer = CurAEDR->AEDR.AttrNum; - } - break; - } - case AEDR_DATATYPE: { - if (read_only_mode == READONLYoff) - { - tOffset += (OFF_T) AEDR_DATATYPE_OFFSET64; - } - else - { - *buffer = CurAEDR->AEDR.DataType; - } - break; - } - case AEDR_NUM: { - if (read_only_mode == READONLYoff) - { - tOffset += (OFF_T) AEDR_NUM_OFFSET64; - } - else - { - *buffer = CurAEDR->AEDR.Num; - } - break; - } - case AEDR_NUMELEMS: { - if (read_only_mode == READONLYoff) - { - tOffset += (OFF_T) AEDR_NUMELEMS_OFFSET64; break; - } - else - { - *buffer = CurAEDR->AEDR.NumElems; - } - break; - } - default: return CDF_INTERNAL_ERROR; - } - if (read_only_mode == READONLYoff) - { - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32_64(fp,buffer)) return CRE; - }; - break; - } - } - } -} - -/****************************************************************************** -* ReadVDR/zVDR64. -* If the pad value is being read, it is passed back in the encoding of the -* CDF (no decoding is performed). The caller must decode the value (if that -* is necessary). -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadVDR64 (struct CDFstruct *CDF, vFILE *fp, - OFF_T offset, Logical zVar, ...) -#else -STATICforIDL CDFstatus ReadVDR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, zVar); -#else - struct CDFstruct *CDF; vFILE *fp; OFF_T offset; Logical zVar; - VA_START (ap); - CDF = va_arg (ap, struct CDFstruct *); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); - zVar = va_arg (ap, Logical); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case VDR_NULL: - va_end (ap); - return pStatus; - case VDR_RECORD: { - struct VDRstruct64 *VDR = va_arg (ap, struct VDRstruct64 *); - void *padValue = va_arg (ap, void *); Int32 nDims; - if (!SEEKv64(fp,offset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,&(VDR->RecordSize))) return CRE; - if (!Read32_64(fp,&(VDR->RecordType))) return CRE; - if (!Read64_64(fp,&(VDR->VDRnext))) return CRE; - if (!Read32s_64(fp,&(VDR->DataType),2)) return CRE; - /* - if (!Read32_64(fp,&(VDR->DataType))) return CRE; - if (!Read32_64(fp,&(VDR->MaxRec))) return CRE; - */ - if (!Read64s_64(fp,&(VDR->VXRhead),2)) return CRE; - /* - if (!Read64_64(fp,&(VDR->VXRhead))) return CRE; - if (!Read64_64(fp,&(VDR->VXRtail))) return CRE; - */ - if (!Read32s_64(fp,&(VDR->Flags),7)) return CRE; - /* - if (!Read32_64(fp,&(VDR->Flags))) return CRE; - if (!Read32_64(fp,&(VDR->sRecords))) return CRE; - if (!Read32_64(fp,&(VDR->rfuB))) return CRE; - if (!Read32_64(fp,&(VDR->rfuC))) return CRE; - if (!Read32_64(fp,&(VDR->rfuF))) return CRE; - if (!Read32_64(fp,&(VDR->NumElems))) return CRE; - if (!Read32_64(fp,&(VDR->Num))) return CRE; - */ - if (!Read64_64(fp,&(VDR->CPRorSPRoffset))) return CRE; - if (!Read32_64(fp,&(VDR->blockingFactor))) return CRE; - if (!READv64(VDR->Name,CDF_VAR_NAME_LEN256,1,fp)) return CRE; - NulPad (VDR->Name, CDF_VAR_NAME_LEN256); - if (zVar) { - if (!Read32_64(fp,&(VDR->zNumDims))) return CRE; - if (VDR->zNumDims < 0 || VDR->zNumDims > CDF_MAX_DIMS) - return CV3C; - if (!Read32s_64(fp,VDR->zDimSizes,(int)VDR->zNumDims)) return CRE; - } - if (zVar) - nDims = VDR->zNumDims; - else { - OFF_T tOffset = V_tell64 (fp); OFF_T GDRoffset; - if (!sX(ReadCDR64(fp,V3_CDR_OFFSET64, - CDR_GDROFFSET,&GDRoffset, - CDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadGDR64(fp,GDRoffset, - GDR_rNUMDIMS,&nDims, - GDR_NULL),&pStatus)) return pStatus; - if (nDims < 0 || nDims > CDF_MAX_DIMS) - return CV3C; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - } - if (!Read32s_64(fp,VDR->DimVarys,(int)nDims)) return CRE; - if (PADvalueBITset(VDR->Flags) && padValue != NULL) { - size_t nBytes = (size_t) (CDFelemSize(VDR->DataType)*VDR->NumElems); - if (!READv64(padValue,nBytes,1,fp)) return CRE; - if (STRINGdataType(VDR->DataType)) { - FillSpacesToString((char *)padValue, (int)VDR->NumElems, - (int)VDR->NumElems); - } - } - break; - } - case VDR_NAME: { - char *vName = va_arg (ap, char *); - OFF_T tOffset = offset + VDR_NAME_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!READv64(vName,CDF_VAR_NAME_LEN256,1,fp)) return CRE; - NulPad (vName, CDF_VAR_NAME_LEN256); - break; - } - case VDR_zNUMDIMS: { - Int32 *numDims = va_arg (ap, Int32 *); - OFF_T tOffset = offset + zVDR_zNUMDIMS_OFFSET64; - if (!zVar) return CDF_INTERNAL_ERROR; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32_64(fp,numDims)) return CRE; - break; - } - case VDR_zDIMSIZES: { - Int32 *zDimSizes = va_arg (ap, Int32 *); - Int32 zNumDims; OFF_T tOffset; - if (!zVar) return CDF_INTERNAL_ERROR; - if (!sX(ReadVDR64(CDF,fp,offset,zVar, - VDR_zNUMDIMS,&zNumDims, - VDR_NULL),&pStatus)) return pStatus; - tOffset = offset + (OFF_T) zVDR_zDIMSIZES_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (zNumDims < 0 || zNumDims > CDF_MAX_DIMS) - return CV3C; - if (!Read32s_64(fp,zDimSizes,(int)zNumDims)) return CRE; - break; - } - case VDR_DIMVARYS: { - Int32 *dimVarys = va_arg (ap, Int32 *); - Int32 nDims; OFF_T tOffset; - if (zVar) { - if (!sX(ReadVDR64(CDF,fp,offset,zVar, - VDR_zNUMDIMS,&nDims, - VDR_NULL),&pStatus)) return pStatus; - tOffset = offset + (OFF_T) (zVDR_DIMVARYS_OFFSETb64 + - (nDims*sizeof(Int32))); - } - else { - OFF_T GDRoffset; - if (!sX(ReadCDR64(fp,V3_CDR_OFFSET64, - CDR_GDROFFSET,&GDRoffset, - CDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadGDR64(fp,GDRoffset, - GDR_rNUMDIMS,&nDims, - GDR_NULL),&pStatus)) return pStatus; - tOffset = offset + (OFF_T) rVDR_DIMVARYS_OFFSET64; - } - if (nDims < 0 || nDims > CDF_MAX_DIMS) - return CV3C; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32s_64(fp,dimVarys,(int)nDims)) return CRE; - break; - } - case VDR_PADVALUE: { - void *padValue = va_arg (ap, void *); - Int32 dataType, numElems; size_t nBytes; OFF_T tOffset; - if (!sX(ReadVDR64(CDF,fp,offset,zVar, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_NULL),&pStatus)) return pStatus; - if (zVar) { - Int32 zNumDims; - if (!sX(ReadVDR64(CDF,fp,offset,zVar, - VDR_zNUMDIMS,&zNumDims, - VDR_NULL),&pStatus)) return pStatus; - tOffset = offset + (OFF_T) (zVDR_PADVALUE_OFFSETb64 + - (zNumDims*sizeof(Int32)) + - (zNumDims*sizeof(Int32))); - } - else { - Int32 rNumDims; - OFF_T GDRoffset; - if (!sX(ReadCDR64(fp,V3_CDR_OFFSET64, - CDR_GDROFFSET,&GDRoffset, - CDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadGDR64(fp,GDRoffset, - GDR_rNUMDIMS,&rNumDims, - GDR_NULL),&pStatus)) return pStatus; - tOffset = offset + (OFF_T) (rVDR_PADVALUE_OFFSETb64 + - (rNumDims*sizeof(Int32))); - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - nBytes = (size_t) (CDFelemSize(dataType) * numElems); - if (!READv64(padValue,nBytes,1,fp)) return CRE; - if (STRINGdataType(dataType)) { - FillSpacesToString((char *)padValue, (int)numElems, - (int)numElems); - } - break; - } - case VDR_RECORDSIZE: - case VDR_VDRNEXT: - case VDR_VXRHEAD: - case VDR_VXRTAIL: - case VDR_CPRorSPR: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case VDR_RECORDSIZE: tOffset += (OFF_T) VDR_RECORDSIZE_OFFSET64; break; - case VDR_VDRNEXT: tOffset += (OFF_T) VDR_VDRNEXT_OFFSET64; break; - case VDR_VXRHEAD: tOffset += (OFF_T) VDR_VXRHEAD_OFFSET64; break; - case VDR_VXRTAIL: tOffset += (OFF_T) VDR_VXRTAIL_OFFSET64; break; - case VDR_CPRorSPR: - tOffset += (OFF_T) VDR_CPRorSPR_OFFSET64; - break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,buffer)) return CRE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { - case VDR_RECORDTYPE: tOffset += (OFF_T) VDR_RECORDTYPE_OFFSET64; break; - case VDR_DATATYPE: tOffset += (OFF_T) VDR_DATATYPE_OFFSET64; break; - case VDR_MAXREC: tOffset += (OFF_T) VDR_MAXREC_OFFSET64; break; - case VDR_FLAGS: tOffset += (OFF_T) VDR_FLAGS_OFFSET64; break; - case VDR_sRECORDS: tOffset += (OFF_T) VDR_sRECORDS_OFFSET64; break; - case VDR_NUMELEMS: - tOffset += (OFF_T) VDR_NUMELEMS_OFFSET64; - break; - case VDR_NUM: - tOffset += (OFF_T) VDR_NUM_OFFSET64; - break; - case VDR_BLOCKING: - tOffset += (OFF_T) VDR_BLOCKING_OFFSET64; - break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32_64(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadVXR64. -******************************************************************************/ - -#if defined(STDARG) -VISIBLE_PREFIX CDFstatus ReadVXR64 (vFILE *fp, OFF_T offset, ...) -#else -VISIBLE_PREFIX CDFstatus ReadVXR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case VXR_NULL: - va_end (ap); - return pStatus; - case VXR_RECORD: { - struct VXRstruct64 *VXR = va_arg (ap, struct VXRstruct64 *); - if (!SEEKv64(fp,offset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,&(VXR->RecordSize))) return CRE; - if (!Read32_64(fp,&(VXR->RecordType))) return CRE; - if (!Read64_64(fp,&(VXR->VXRnext))) return CRE; - if (!Read32s_64(fp,&(VXR->Nentries),2)) return CRE; - /* - if (!Read32_64(fp,&(VXR->Nentries))) return CRE; - if (!Read32_64(fp,&(VXR->NusedEntries))) return CRE; - */ - if ((int)VXR->Nentries < 0 || (int)VXR->Nentries > MAX_VXR_ENTRIES) - return CV3C; - if (!Read32s_64(fp,VXR->First,(int)VXR->Nentries)) return CRE; - if (!Read32s_64(fp,VXR->Last,(int)VXR->Nentries)) return CRE; - if (!Read64s_64(fp,VXR->Offset,(int)VXR->Nentries)) return CRE; - break; - } - case VXR_FIRSTREC: - case VXR_LASTREC: { - Int32 *buffer = va_arg (ap, Int32 *), nEntries; - OFF_T tOffset = offset + VXR_FIRSTREC_OFFSET64; - if (!sX(ReadVXR64(fp,offset, - VXR_NENTRIES,&nEntries, - VXR_NULL),&pStatus)) return pStatus; - switch (field) { - case VXR_FIRSTREC: break; - case VXR_LASTREC: tOffset += (OFF_T) nEntries * sizeof(Int32); break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if ((int)nEntries < 0 || nEntries > MAX_VXR_ENTRIES) - return CV3C; - if (!Read32s_64(fp,buffer,(int)nEntries)) return CRE; - break; - } - case VXR_OFFSET: { - OFF_T *buffer = va_arg (ap, OFF_T *); Int32 nEntries; - OFF_T tOffset = offset + (OFF_T) VXR_FIRSTREC_OFFSET64; - if (!sX(ReadVXR64(fp,offset, - VXR_NENTRIES,&nEntries, - VXR_NULL),&pStatus)) return pStatus; - tOffset += (OFF_T) (2 * nEntries * sizeof(Int32)); - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if ((int)nEntries < 0 || nEntries > MAX_VXR_ENTRIES) - return CV3C; - if (!Read64s_64(fp,buffer,(int)nEntries)) return CRE; - break; - } - case VXR_RECORDSIZE: - case VXR_VXRNEXT: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case VXR_RECORDSIZE: tOffset += (OFF_T) VXR_RECORDSIZE_OFFSET64; break; - case VXR_VXRNEXT: tOffset += (OFF_T) VXR_VXRNEXT_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,buffer)) return CRE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { - case VXR_RECORDTYPE: tOffset += (OFF_T) VXR_RECORDTYPE_OFFSET64; break; - case VXR_NENTRIES: tOffset += (OFF_T) VXR_NENTRIES_OFFSET64; break; - case VXR_NUSEDENTRIES: tOffset += (OFF_T) VXR_NUSEDENTRIES_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32_64(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadVVR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadVVR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus ReadVVR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case VVR_NULL: - va_end (ap); - return pStatus; - case VVR_RECORDx: { - struct VVRstruct64 *VVR = va_arg (ap, struct VVRstruct64 *); - if (!SEEKv64(fp,offset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,&(VVR->RecordSize))) return CRE; - if (!Read32_64(fp,&(VVR->RecordType))) return CRE; - break; - } - case VVR_RECORDSIZE: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - tOffset += (OFF_T) VVR_RECORDSIZE_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,buffer)) return CRE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { - case VVR_RECORDTYPE: tOffset += (OFF_T) VVR_RECORDTYPE_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32_64(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadUIR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadUIR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus ReadUIR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case UIR_NULL: - va_end (ap); - return pStatus; - case UIR_RECORD: { - struct UIRstruct64 *UIR = va_arg (ap, struct UIRstruct64 *); - if (!SEEKv64(fp,offset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,&(UIR->RecordSize))) return CRE; - if (!Read32_64(fp,&(UIR->RecordType))) return CRE; - if (!Read64s_64(fp,&(UIR->NextUIR),2)) return CRE; - /* - if (!Read64_64(fp,&(UIR->NextUIR))) return CRE; - if (!Read64_64(fp,&(UIR->PrevUIR))) return CRE; - */ - break; - } - case UIR_RECORDTYPE: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - tOffset += (OFF_T) UIR_RECORDTYPE_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32_64(fp,buffer)) return CRE; - break; - } - default: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case UIR_RECORDSIZE: tOffset += (OFF_T) UIR_RECORDSIZE_OFFSET64; break; - case UIR_NEXTUIR: tOffset += (OFF_T) UIR_NEXTUIR_OFFSET64; break; - case UIR_PREVUIR: tOffset += (OFF_T) UIR_PREVUIR_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadCCR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadCCR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus ReadCCR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CCR_NULL: - va_end (ap); - return pStatus; - case CCR_RECORD: { - struct CCRstruct64 *CCR = va_arg (ap, struct CCRstruct64 *); - if (!SEEKv64(fp,offset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,&(CCR->RecordSize))) return CRE; - if (!Read32_64(fp,&(CCR->RecordType))) return CRE; - if (!Read64s_64(fp,&(CCR->CPRoffset),2)) return CRE; - /* - if (!Read64_64(fp,&(CCR->CPRoffset))) return CRE; - if (!Read64_64(fp,&(CCR->uSize))) return CRE; - */ - if (!Read32_64(fp,&(CCR->rfuA))) return CRE; - break; - } - case CCR_RECORDTYPE: - case CCR_RFUa: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { - case CCR_RECORDTYPE: tOffset += (OFF_T) CCR_RECORDTYPE_OFFSET64; break; - case CCR_RFUa: tOffset += (OFF_T) CCR_RFUa_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,offset,vSEEK_SET)) return CRE; - if (!Read32_64(fp,buffer)) return CRE; - break; - } - default: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case CCR_RECORDSIZE: tOffset += (OFF_T) CCR_RECORDSIZE_OFFSET64; break; - case CCR_CPROFFSET: tOffset += (OFF_T) CCR_CPROFFSET_OFFSET64; break; - case CCR_USIZE: tOffset += (OFF_T) CCR_USIZE_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadCPR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadCPR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus ReadCPR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CPR_NULL: - va_end (ap); - return pStatus; - case CPR_RECORD: { - struct CPRstruct64 *CPR = va_arg (ap, struct CPRstruct64 *); int i; - if (!SEEKv64(fp,offset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,&(CPR->RecordSize))) return CRE; - if (!Read32s_64(fp,&(CPR->RecordType),4)) return CRE; - /* - if (!Read32_64(fp,&(CPR->RecordType))) return CRE; - if (!Read32_64(fp,&(CPR->cType))) return CRE; - if (!Read32_64(fp,&(CPR->rfuA))) return CRE; - if (!Read32_64(fp,&(CPR->pCount))) return CRE; - */ - if (CPR->pCount > CDF_MAX_PARMS) return TOO_MANY_PARMS; - for (i = 0; i < CPR->pCount; i++) { - if (!Read32_64(fp,&(CPR->cParms[i]))) return CRE; - } - break; - } - case CPR_RECORDSIZE: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - tOffset += (OFF_T) CPR_RECORDSIZE_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,buffer)) return CRE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { - case CPR_RECORDTYPE: tOffset += (OFF_T) CPR_RECORDTYPE_OFFSET64; break; - case CPR_CTYPE: tOffset += (OFF_T) CPR_CTYPE_OFFSET64; break; - case CPR_RFUa: tOffset += (OFF_T) CPR_RFUa_OFFSET64; break; - case CPR_PCOUNT: tOffset += (OFF_T) CPR_PCOUNT_OFFSET64; break; - case CPR_CPARM1: tOffset += (OFF_T) CPR_CPARM1_OFFSET64; break; - case CPR_CPARM2: tOffset += (OFF_T) CPR_CPARM2_OFFSET64; break; - case CPR_CPARM3: tOffset += (OFF_T) CPR_CPARM3_OFFSET64; break; - case CPR_CPARM4: tOffset += (OFF_T) CPR_CPARM4_OFFSET64; break; - case CPR_CPARM5: tOffset += (OFF_T) CPR_CPARM5_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32_64(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadSPR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadSPR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus ReadSPR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case SPR_NULL: - va_end (ap); - return pStatus; - case SPR_RECORD: { - struct SPRstruct64 *SPR = va_arg (ap, struct SPRstruct64 *); int i; - if (!SEEKv64(fp,offset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,&(SPR->RecordSize))) return CRE; - if (!Read32s_64(fp,&(SPR->RecordType),4)) return CRE; - /* - if (!Read32_64(fp,&(SPR->RecordType))) return CRE; - if (!Read32_64(fp,&(SPR->sArraysType))) return CRE; - if (!Read32_64(fp,&(SPR->rfuA))) return CRE; - if (!Read32_64(fp,&(SPR->pCount))) return CRE; - */ - if (SPR->pCount > CDF_MAX_PARMS) return TOO_MANY_PARMS; - for (i = 0; i < SPR->pCount; i++) { - if (!Read32_64(fp,&(SPR->sArraysParms[i]))) return CRE; - } - break; - } - case SPR_RECORDSIZE: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - tOffset += (OFF_T) SPR_RECORDSIZE_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,buffer)) return CRE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { - case SPR_RECORDTYPE: tOffset += (OFF_T) SPR_RECORDTYPE_OFFSET64; break; - case SPR_STYPE: tOffset += (OFF_T) SPR_STYPE_OFFSET64; break; - case SPR_RFUa: tOffset += (OFF_T) SPR_RFUa_OFFSET64; break; - case SPR_PCOUNT: tOffset += (OFF_T) SPR_PCOUNT_OFFSET64; break; - case SPR_SPARM1: tOffset += (OFF_T) SPR_SPARM1_OFFSET64; break; - case SPR_SPARM2: tOffset += (OFF_T) SPR_SPARM2_OFFSET64; break; - case SPR_SPARM3: tOffset += (OFF_T) SPR_SPARM3_OFFSET64; break; - case SPR_SPARM4: tOffset += (OFF_T) SPR_SPARM4_OFFSET64; break; - case SPR_SPARM5: tOffset += (OFF_T) SPR_SPARM5_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32_64(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadCVVR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus ReadCVVR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus ReadCVVR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CVVR_NULL: - va_end (ap); - return pStatus; - case CVVR_RECORDx: { - struct CVVRstruct64 *CVVR = va_arg (ap, struct CVVRstruct64 *); - if (!SEEKv64(fp,offset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,&(CVVR->RecordSize))) return CRE; - if (!Read32s_64(fp,&(CVVR->RecordType),2)) return CRE; - /* - if (!Read32_64(fp,&(CVVR->RecordType))) return CRE; - if (!Read32_64(fp,&(CVVR->rfuA))) return CRE; - */ - if (!Read64_64(fp,&(CVVR->cSize))) return CRE; - break; - } - case CVVR_RECORDSIZE: - case CVVR_CSIZE: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case CVVR_RECORDSIZE: tOffset += (OFF_T) CVVR_RECORDSIZE_OFFSET64; break; - case CVVR_CSIZE: tOffset += (OFF_T) CVVR_CSIZE_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read64_64(fp,buffer)) return CRE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { - /* case CVVR_RECORDSIZE: tOffset += (OFF_T) CVVR_RECORDSIZE_OFFSET64; break; */ - case CVVR_RECORDTYPE: tOffset += (OFF_T) CVVR_RECORDTYPE_OFFSET64; break; - case CVVR_RFUa: tOffset += (OFF_T) CVVR_RFUa_OFFSET64; break; - /* case CVVR_CSIZE: tOffset += (OFF_T) CVVR_CSIZE_OFFSET64; break; */ - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CRE; - if (!Read32_64(fp,buffer)) return CRE; - break; - } - } - } -} - -/****************************************************************************** -* ReadADRList64. -******************************************************************************/ - -STATICforIDL CDFstatus ReadADRList64 (vFILE *fp) -{ - OFF_T nxtADR = fp->GDR64->ADRhead; - CDFstatus pStatus = CDF_OK; - Int32 i; - OFF_T temp; - - /************************************************************************** - * Allocate memory for the list of ADRs - ***************************************************************************/ - if (fp->GDR64->NumAttr > 0) - fp->ADRList64 = cdf_AllocateMemory((size_t)fp->GDR64->NumAttr * - sizeof(struct ADRstruct64**), NULL); - if (fp->GDR64->NumAttr > 0 && fp->ADRList64 == NULL) return BAD_MALLOC; - for (i = 0; i < fp->GDR64->NumAttr; i++) - { - fp->ADRList64[i] = cdf_AllocateMemory((size_t)sizeof(struct ADRstruct64), NULL); - if (fp->ADRList64[i] == NULL) return BAD_MALLOC; - }; - /*************************************************************************** - * Read the ADRs into the list - ****************************************************************************/ - for (i = 0; i < fp->GDR64->NumAttr; i++) - { - if (!SEEKv64(fp,nxtADR,vSEEK_SET)) return CRE; - if (!Read64_64(fp, &temp)) return CRE; - fp->ADRList64[i]->RecordSize = temp; - if (!Read32_64(fp,&(fp->ADRList64[i]->RecordType))) return CRE; - if (!Read64_64(fp,&temp)) return CRE; - nxtADR = temp; - fp->ADRList64[i]->ADRnext = 0; - if (!Read64_64(fp,&temp)) return CRE; - fp->ADRList64[i]->AgrEDRhead = temp; - if (!Read32s_64(fp,&(fp->ADRList64[i]->Scope),5)) return CRE; - /* - if (!Read32_64(fp,&(fp->ADRList64[i]->Scope))) return CRE; - if (!Read32_64(fp,&(fp->ADRList64[i]->Num))) return CRE; - if (!Read32_64(fp,&(fp->ADRList64[i]->NgrEntries))) return CRE; - if (!Read32_64(fp,&(fp->ADRList64[i]->MAXgrEntry))) return CRE; - if (!Read32_64(fp,&(fp->ADRList64[i]->rfuA))) return CRE; - */ - if (!Read64_64(fp,&temp)) return CRE; - fp->ADRList64[i]->AzEDRhead = temp; - if (!Read32s_64(fp,&(fp->ADRList64[i]->NzEntries),3)) return CRE; - /* - if (!Read32_64(fp,&(fp->ADRList64[i]->NzEntries))) return CRE; - if (!Read32_64(fp,&(fp->ADRList64[i]->MAXzEntry))) return CRE; - if (!Read32_64(fp,&(fp->ADRList64[i]->rfuE))) return CRE; - */ - if (!READv64(fp->ADRList64[i]->Name,CDF_ATTR_NAME_LEN256,1,fp)) - return CRE; - NulPad (fp->ADRList64[i]->Name, CDF_ATTR_NAME_LEN256); - /*********************************************************************** - * Allocate memory for the lists of gAEDRs and zAEDRS associated with - * this ADR and read the AEDRs into the lists. - ***********************************************************************/ - pStatus = ReadAEDRList64(fp, &(fp->ADRList64[i]->grAEDRList64), - fp->ADRList64[i]->AgrEDRhead, - fp->ADRList64[i]->NgrEntries, - fp->ADRList64[i]->MAXgrEntry); - if (pStatus != CDF_OK) return pStatus; - pStatus = ReadAEDRList64(fp, &(fp->ADRList64[i]->zAEDRList64), - fp->ADRList64[i]->AzEDRhead, - fp->ADRList64[i]->NzEntries, - fp->ADRList64[i]->MAXzEntry); - if (pStatus != CDF_OK) return pStatus; - }; - return pStatus; -} - -/****************************************************************************** -* ReadAEDRList64. -* Reads the set of entrys (zENTRYs or grENTRYs) associated with an attribute -* into a list indexed by the entry number. If there is no entry for a particular -* index (i.e., there is no entry for the associated variable/attribute -* pair), the list entry is NULL. -******************************************************************************/ -STATICforIDL CDFstatus ReadAEDRList64 (vFILE *fp, - struct AEDRstructExt64 ***AEDRList, - OFF_T AEDRHead, - Int32 NumEntries, - Int32 MaxEntry) -{ - CDFstatus pStatus = CDF_OK; - OFF_T NxtAEDR = AEDRHead; - struct AEDRstructExt64 *TempAEDR; - Int32 iEntries; - Int32 i; - OFF_T temp; - /************************************************************************** - * Allocate memory for the list and initialize each entry to NULL. - **************************************************************************/ - if (MaxEntry >= 0) { - *AEDRList = cdf_AllocateMemory((size_t)(MaxEntry + 1) * - sizeof(struct AEDRstructExt64**), NULL); - if (*AEDRList == NULL) return BAD_MALLOC; - } - else - { - *AEDRList = NULL; - return pStatus; - }; - - for (i = 0; i <= MaxEntry; i++) - { - (*AEDRList)[i] = NULL; - }; - iEntries = 0; - /*************************************************************************** - * Allocate memory for each AEDR, read each AEDR, and assign them to the list - * by entry number. - ***************************************************************************/ - while (NxtAEDR != 0 && iEntries != NumEntries) - { - TempAEDR = cdf_AllocateMemory((size_t)sizeof(struct AEDRstructExt64), NULL); - if (TempAEDR == NULL) return BAD_MALLOC; - if (!SEEKv64(fp,NxtAEDR,vSEEK_SET)) return CRE; - if (!Read64_64(fp,&temp)) return CRE; - TempAEDR->AEDR.RecordSize = temp; - if (!Read32_64(fp,&(TempAEDR->AEDR.RecordType))) return CRE; - if (!Read64_64(fp,&temp)) return CRE; - NxtAEDR = temp; - TempAEDR->AEDR.AEDRnext = 0; - if (!Read32s_64(fp,&(TempAEDR->AEDR.AttrNum),9)) return CRE; - /* - if (!Read32_64(fp,&(TempAEDR->AEDR.AttrNum))) return CRE; - if (!Read32_64(fp,&(TempAEDR->AEDR.DataType))) return CRE; - if (!Read32_64(fp,&(TempAEDR->AEDR.Num))) return CRE; - if (!Read32_64(fp,&(TempAEDR->AEDR.NumElems))) return CRE; - if (!Read32_64(fp,&(TempAEDR->AEDR.rfuA))) return CRE; - if (!Read32_64(fp,&(TempAEDR->AEDR.rfuB))) return CRE; - if (!Read32_64(fp,&(TempAEDR->AEDR.rfuC))) return CRE; - if (!Read32_64(fp,&(TempAEDR->AEDR.rfuD))) return CRE; - if (!Read32_64(fp,&(TempAEDR->AEDR.rfuE))) return CRE; - */ - TempAEDR->ValueSize = (CDFelemSize(TempAEDR->AEDR.DataType) * - TempAEDR->AEDR.NumElems); - if (TempAEDR->ValueSize < 1) { - return CV3C; - } - TempAEDR->Value = cdf_AllocateMemory((size_t)TempAEDR->ValueSize, NULL); - if (TempAEDR->Value == NULL) return BAD_MALLOC; - if (!READv64(TempAEDR->Value,TempAEDR->ValueSize,1,fp)) return CRE; - if (STRINGdataType(TempAEDR->AEDR.DataType)) { - FillSpacesToString((char *)(TempAEDR->Value), - (int)TempAEDR->AEDR.NumElems, - (int)TempAEDR->AEDR.NumElems); - } - ++iEntries; - if (TempAEDR->AEDR.Num < 0 || TempAEDR->AEDR.Num > MaxEntry) { - return CV3C; - } - (*AEDRList)[TempAEDR->AEDR.Num] = TempAEDR; - }; - return pStatus; -} - diff --git a/cdf36_3-dist/src/lib/cdfrle.c b/cdf36_3-dist/src/lib/cdfrle.c deleted file mode 100644 index de9f3e4..0000000 --- a/cdf36_3-dist/src/lib/cdfrle.c +++ /dev/null @@ -1,179 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Run-length encoding compression/decompression. -* -* Version 1.0, 15-May-96, Hughes STX. -* -* Modification history: -* -* V1.0 15-May-96, J Love Original version. -* -******************************************************************************/ - -#include "cdflib.h" - -#if !SUPPORT_RLE && defined(BORLANDC) -#pragma warn -par -#endif - -/****************************************************************************** -* CompressRLE0. -******************************************************************************/ - -STATICforIDL CDFstatus CompressRLE0 (srcFp, srcOffset, srcSize, srcError, - destFp, destOffset, destSize, destError) -vFILE *srcFp; -Int32 srcOffset; -Int32 srcSize; -CDFstatus srcError; -vFILE *destFp; -Int32 destOffset; -Int32 *destSize; -CDFstatus destError; -{ -#if SUPPORT_RLE - CDFstatus pStatus = CDF_OK; Int32 byteN = 0, count; - uByte byte, zero = 0, max255 = (uByte) 255, zCount; - /**************************************************************************** - * Seek to starting offsets. - ****************************************************************************/ - if (!SEEKv(srcFp,(long)srcOffset,vSEEK_SET)) return srcError; - if (!SEEKv(destFp,(long)destOffset,vSEEK_SET)) return destError; - /**************************************************************************** - * Initialize destination count and begin... - ****************************************************************************/ - *destSize = 0; - for (;;) { - /************************************************************************* - * Return if past the last source byte. - *************************************************************************/ - if (byteN == srcSize) return pStatus; - /************************************************************************* - * Read the next source byte. - *************************************************************************/ - if (!READv(&byte,1,1,srcFp)) return srcError; - byteN++; - /************************************************************************* - * If the source byte is zero, set the counter and begin... - *************************************************************************/ - if (byte == 0) { - count = 1; - for (;;) { - /******************************************************************** - * If past the last source byte, write a zero/count to the - * destination file and return. In this case the final `count' - * bytes of the source file are zeroes. - ********************************************************************/ - if (byteN == srcSize) { - if (!WRITEv(&zero,1,1,destFp)) return destError; - (*destSize)++; - zCount = (uByte) (count - 1); - if (!WRITEv(&zCount,1,1,destFp)) return destError; - (*destSize)++; - return pStatus; - } - /******************************************************************** - * Read the next source byte. - ********************************************************************/ - if (!READv(&byte,1,1,srcFp)) return srcError; - byteN++; - /******************************************************************** - * If the byte is not a zero, write a zero/count and the non-zero - * byte to the destination file and break out of this loop. - ********************************************************************/ - if (byte != 0) { - if (!WRITEv(&zero,1,1,destFp)) return destError; - (*destSize)++; - zCount = (Byte1) (count - 1); - if (!WRITEv(&zCount,1,1,destFp)) return destError; - (*destSize)++; - if (!WRITEv(&byte,1,1,destFp)) return destError; - (*destSize)++; - break; - } - /******************************************************************** - * Increment for another zero and check if at the limit. If so, - * write a zero/count to the destination and break out of this loop. - ********************************************************************/ - count++; - if (count == 256) { - if (!WRITEv(&zero,1,1,destFp)) return destError; - (*destSize)++; - if (!WRITEv(&max255,1,1,destFp)) return destError; - (*destSize)++; - break; - } - } - } - else { - /*********************************************************************** - * A non-zero source byte - write it to the destination file. - ***********************************************************************/ - if (!WRITEv(&byte,1,1,destFp)) return destError; - (*destSize)++; - } - } -#else - return UNKNOWN_COMPRESSION; -#endif -} - -/****************************************************************************** -* DecompressRLE0. -******************************************************************************/ - -STATICforIDL CDFstatus DecompressRLE0 (srcFp, srcOffset, srcSize, srcError, - destFp, destOffset, destError) -vFILE *srcFp; -Int32 srcOffset; -Int32 srcSize; -CDFstatus srcError; -vFILE *destFp; -Int32 destOffset; -CDFstatus destError; -{ -#if SUPPORT_RLE - CDFstatus pStatus = CDF_OK; Int32 byteN = 0, count, i; - uByte byte, zero = 0, zCount; - /**************************************************************************** - * Seek to starting offsets. - ****************************************************************************/ - if (!SEEKv(srcFp,(long)srcOffset,vSEEK_SET)) return srcError; - if (!SEEKv(destFp,(long)destOffset,vSEEK_SET)) return destError; - /**************************************************************************** - * Begin... - ****************************************************************************/ - for (;;) { - /************************************************************************* - * Return if past the last source byte - *************************************************************************/ - if (byteN == srcSize) return pStatus; - /************************************************************************* - * Read a source byte. If it is a zero, read the following count byte - * and write the specified number of zeroes to the destination file. - * Otherwise, just write the non-zero byte. Note that the count byte is - * one less than the number of zeroes. - *************************************************************************/ - if (!READv(&byte,1,1,srcFp)) return srcError; - byteN++; - if (byte == 0) { - if (byteN == srcSize) return DECOMPRESSION_ERROR; - if (!READv(&zCount,1,1,srcFp)) return srcError; - byteN++; - count = ((Int32) zCount) + 1; - for (i = 0; i < count; i++) { - if (!WRITEv(&zero,1,1,destFp)) return destError; - } - } - else - if (!WRITEv(&byte,1,1,destFp)) return destError; - } -#else - return UNKNOWN_COMPRESSION; -#endif -} diff --git a/cdf36_3-dist/src/lib/cdfrle64.c b/cdf36_3-dist/src/lib/cdfrle64.c deleted file mode 100644 index c586aff..0000000 --- a/cdf36_3-dist/src/lib/cdfrle64.c +++ /dev/null @@ -1,180 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Run-length encoding compression/decompression. -* -* Version 1.0, 15-May-96, Hughes STX. -* -* Modification history: -* -* V1.0 15-May-96, J Love Original version. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -#if !SUPPORT_RLE64 && defined(BORLANDC) -#pragma warn -par -#endif - -/****************************************************************************** -* CompressRLE0_64. -******************************************************************************/ - -STATICforIDL CDFstatus CompressRLE0_64 (srcFp, srcOffset, srcSize, srcError, - destFp, destOffset, destSize, destError) -vFILE *srcFp; -OFF_T srcOffset; -OFF_T srcSize; -CDFstatus srcError; -vFILE *destFp; -OFF_T destOffset; -OFF_T *destSize; -CDFstatus destError; -{ -#if SUPPORT_RLE64 - CDFstatus pStatus = CDF_OK; Int32 byteN = 0, count; - uByte byte, zero = 0, max255 = (uByte) 255, zCount; - /**************************************************************************** - * Seek to starting offsets. - ****************************************************************************/ - if (!SEEKv64(srcFp,srcOffset,vSEEK_SET)) return srcError; - if (!SEEKv64(destFp,destOffset,vSEEK_SET)) return destError; - /**************************************************************************** - * Initialize destination count and begin... - ****************************************************************************/ - *destSize = 0; - for (;;) { - /************************************************************************* - * Return if past the last source byte. - *************************************************************************/ - if (byteN == srcSize) return pStatus; - /************************************************************************* - * Read the next source byte. - *************************************************************************/ - if (!READv64(&byte,1,1,srcFp)) return srcError; - byteN++; - /************************************************************************* - * If the source byte is zero, set the counter and begin... - *************************************************************************/ - if (byte == 0) { - count = 1; - for (;;) { - /******************************************************************** - * If past the last source byte, write a zero/count to the - * destination file and return. In this case the final `count' - * bytes of the source file are zeroes. - ********************************************************************/ - if (byteN == srcSize) { - if (!WRITEv64(&zero,1,1,destFp)) return destError; - (*destSize)++; - zCount = (uByte) (count - 1); - if (!WRITEv64(&zCount,1,1,destFp)) return destError; - (*destSize)++; - return pStatus; - } - /******************************************************************** - * Read the next source byte. - ********************************************************************/ - if (!READv64(&byte,1,1,srcFp)) return srcError; - byteN++; - /******************************************************************** - * If the byte is not a zero, write a zero/count and the non-zero - * byte to the destination file and break out of this loop. - ********************************************************************/ - if (byte != 0) { - if (!WRITEv64(&zero,1,1,destFp)) return destError; - (*destSize)++; - zCount = (Byte1) (count - 1); - if (!WRITEv64(&zCount,1,1,destFp)) return destError; - (*destSize)++; - if (!WRITEv64(&byte,1,1,destFp)) return destError; - (*destSize)++; - break; - } - /******************************************************************** - * Increment for another zero and check if at the limit. If so, - * write a zero/count to the destination and break out of this loop. - ********************************************************************/ - count++; - if (count == 256) { - if (!WRITEv64(&zero,1,1,destFp)) return destError; - (*destSize)++; - if (!WRITEv64(&max255,1,1,destFp)) return destError; - (*destSize)++; - break; - } - } - } - else { - /*********************************************************************** - * A non-zero source byte - write it to the destination file. - ***********************************************************************/ - if (!WRITEv64(&byte,1,1,destFp)) return destError; - (*destSize)++; - } - } -#else - return UNKNOWN_COMPRESSION; -#endif -} - -/****************************************************************************** -* DecompressRLE0_64. -******************************************************************************/ - -STATICforIDL CDFstatus DecompressRLE0_64 (srcFp, srcOffset, srcSize, srcError, - destFp, destOffset, destError) -vFILE *srcFp; -OFF_T srcOffset; -OFF_T srcSize; -CDFstatus srcError; -vFILE *destFp; -OFF_T destOffset; -CDFstatus destError; -{ -#if SUPPORT_RLE64 - CDFstatus pStatus = CDF_OK; Int32 byteN = 0, count, i; - uByte byte, zero = 0, zCount; - /**************************************************************************** - * Seek to starting offsets. - ****************************************************************************/ - if (!SEEKv64(srcFp,srcOffset,vSEEK_SET)) return srcError; - if (!SEEKv64(destFp,destOffset,vSEEK_SET)) return destError; - /**************************************************************************** - * Begin... - ****************************************************************************/ - for (;;) { - /************************************************************************* - * Return if past the last source byte - *************************************************************************/ - if (byteN == srcSize) return pStatus; - /************************************************************************* - * Read a source byte. If it is a zero, read the following count byte - * and write the specified number of zeroes to the destination file. - * Otherwise, just write the non-zero byte. Note that the count byte is - * one less than the number of zeroes. - *************************************************************************/ - if (!READv64(&byte,1,1,srcFp)) return srcError; - byteN++; - if (byte == 0) { - if (byteN == srcSize) return DECOMPRESSION_ERROR; - if (!READv64(&zCount,1,1,srcFp)) return srcError; - byteN++; - count = ((Int32) zCount) + 1; - for (i = 0; i < count; i++) { - if (!WRITEv64(&zero,1,1,destFp)) return destError; - } - } - else - if (!WRITEv64(&byte,1,1,destFp)) return destError; - } -#else - return UNKNOWN_COMPRESSION; -#endif -} diff --git a/cdf36_3-dist/src/lib/cdfsav.c b/cdf36_3-dist/src/lib/cdfsav.c deleted file mode 100644 index 00d1751..0000000 --- a/cdf36_3-dist/src/lib/cdfsav.c +++ /dev/null @@ -1,301 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `save' operations. -* -* Version 1.0, 31-Jan-06, Hughes STX. -* -* Modification history: -* -* V1.0 31-Jan-06, M Liu Original version -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* CDFsav. -******************************************************************************/ - -STATICforIDL CDFstatus CDFsav (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ - CDFstatus pStatus = CDF_OK; - int ix; - - switch (Va->item) { - /************************************************************************** - * CDF_ - * Save a CDF for the dotCDF file. - **************************************************************************/ - case CDF_: { - struct CDFstruct *CDF; - struct VarStruct *Var; - /************************************************************************ - * Validate the current CDF. Don't use `SelectCDF' here because we don't - * want to return NO_MORE_ACCESS if that is the case. - ************************************************************************/ - if (Cur->cdf == NULL) - return NO_CDF_SELECTED; - else - CDF = Cur->cdf; - /************************************************************************ - * If this is a CDF for which access was aborted, simply free the CDF's - * memory. - ************************************************************************/ - if (CDF->magic == ABORTEDid_MAGIC_NUMBER) { - KillAbortedCDF (CDF, Cur); - break; - } - - /************************************************************************ - * If the CDF is open read/write, update the dotCDF file. - ************************************************************************/ - if (CDF->status == READ_WRITE) { - if (!CDF->largeFile) { - if (!sX(UpdateDotCDF(CDF),&pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - } else { - if (!sX(UpdateDotCDF64(CDF),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - } - } - /************************************************************************ - * If the CDF is compressed... - ************************************************************************/ - if (CDF->uDotFp != NULL) { - /********************************************************************** - * If the CDF is open read/write... - **********************************************************************/ - if (CDF->status == READ_WRITE) { - char pathName[DU_MAX_PATH_LEN+1]; - Int32 CPRoffset; struct CPRstruct CPR; - OFF_T CPRoffset64; struct CPRstruct64 CPR64; - - /******************************************************************** - * Write cache buffers. - ********************************************************************/ - if (!CDF->largeFile) { - if (!FlushCache(CDF->uDotFp,CDF->uDotFp->cacheHead)) - return CDF_WRITE_ERROR; - } else { - if (!FlushCache64(CDF->uDotFp,CDF->uDotFp->cacheHead)) - return CDF_WRITE_ERROR; - } - /******************************************************************** - * Flush the uncompressed dotCDF file. - ********************************************************************/ - if (!CDF->largeFile) { - if (!FLUSHv(CDF->uDotFp)) { - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_WRITE_ERROR; - } - } else { - if (!FLUSHv64(CDF->uDotFp)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_WRITE_ERROR; - } - } - /******************************************************************** - * Read the compression parameters from the compressed dotCDF file. - ********************************************************************/ - if (!CDF->largeFile) { - if (!sX(ReadCCR(CDF->dotFp,V2_CCR_OFFSET, - CCR_CPROFFSET,&CPRoffset, - CCR_NULL),&pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - if (!sX(ReadCPR(CDF->dotFp,CPRoffset, - CPR_RECORD,&CPR, - CPR_NULL),&pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - } else { - if (!sX(ReadCCR64(CDF->dotFp,V3_CCR_OFFSET64, - CCR_CPROFFSET,&CPRoffset64, - CCR_NULL),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - if (!sX(ReadCPR64(CDF->dotFp,CPRoffset64, - CPR_RECORD,&CPR64, - CPR_NULL),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - } - /******************************************************************** - * Delete the compressed dotCDF file. - ********************************************************************/ - if (!CDF->largeFile) { - if (!DELETEv(CDF->dotFp,NULL)) { - CDF->dotFp = NULL; - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CLOSE_ERROR; - } - } else { - if (!DELETEv64(CDF->dotFp,NULL)) { - CDF->dotFp = NULL; - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CLOSE_ERROR; - } - } - CDF->dotFp = NULL; - /******************************************************************** - * Recreate the compressed dotCDF file. - ********************************************************************/ - BuildFilePath (CDFt, CDF->CDFname, CDF->no_append, - CDF->upper_case_ext, CDF->version_numbers, - INT32_ZERO, pathName); - if (!CDF->largeFile) { - CDF->dotFp = V_open (pathName, WRITE_PLUS_a_mode); - if (CDF->dotFp == NULL) { - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CREATE_ERROR; - } - } else { - CDF->dotFp = V_open64 (pathName, WRITE_PLUS_a_mode); - if (CDF->dotFp == NULL) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_CREATE_ERROR; - } - } - /******************************************************************** - * Write the compressed dotCDF file. - ********************************************************************/ - if (!CDF->largeFile) { - if (!sX(WriteCompressedCDF(CDF,&CPR,notEMPTY),&pStatus)) { - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - if (!FlushCache(CDF->dotFp,CDF->dotFp->cacheHead)) - return CDF_WRITE_ERROR; - if (!FLUSHv(CDF->dotFp)) { - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_WRITE_ERROR; - } - } else { - if (!sX(WriteCompressedCDF64(CDF,&CPR64,notEMPTY),&pStatus)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return pStatus; - } - if (!FlushCache64(CDF->dotFp,CDF->dotFp->cacheHead)) - return CDF_WRITE_ERROR; - if (!FLUSHv64(CDF->dotFp)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_WRITE_ERROR; - } - } - } - } - else { - /********************************************************************** - * CDF - Not compressed. - **********************************************************************/ - if (CDF->status == READ_WRITE) { - /********************************************************************** - * Write cache buffers. - **********************************************************************/ - if (!CDF->largeFile) { - if (!FlushCache(CDF->dotFp,CDF->dotFp->cacheHead)) - return CDF_WRITE_ERROR; - if (!FLUSHv(CDF->dotFp)) { - AbortAccess (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_WRITE_ERROR; - } - } else { - if (!FlushCache64(CDF->dotFp,CDF->dotFp->cacheHead)) - return CDF_WRITE_ERROR; - if (!FLUSHv64(CDF->dotFp)) { - AbortAccess64 (CDF, noUPDATE, noDELETE); - KillAbortedCDF (CDF, Cur); - return CDF_WRITE_ERROR; - } - } - } - /********************************************************************** - * Multi-format file.... - * If the CDF is open read/write, update the dotCDF file. - **********************************************************************/ - if (!CDF->singleFile) { - if (CDF->status == READ_WRITE) { - for (ix = 0; ix < CDF->NrVars; ix++) { - Var = CDF->rVars[ix]; - if (Var != NULL) { - if (Var->fp != NULL) { - if (!CDF->largeFile) { - if (!FLUSHv(Var->fp)) { - AbortAccess (CDF, UPDATE, noDELETE); - return VAR_WRITE_ERROR; - } - } else { - if (!FLUSHv64(Var->fp)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return VAR_WRITE_ERROR; - } - } - } - } - } - for (ix = 0; ix < CDF->NzVars; ix++) { - Var = CDF->zVars[ix]; - if (Var != NULL) { - if (Var->fp != NULL) { - if (!CDF->largeFile) { - if (!FLUSHv(Var->fp)) { - AbortAccess (CDF, UPDATE, noDELETE); - return VAR_WRITE_ERROR; - } - } else { - if (!FLUSHv64(Var->fp)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return VAR_WRITE_ERROR; - } - } - } - } - } - } - } - } - break; - } - /************************************************************************** - * Unknown item, must be the next function. - **************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } - } - return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfsel.c b/cdf36_3-dist/src/lib/cdfsel.c deleted file mode 100644 index 240bd22..0000000 --- a/cdf36_3-dist/src/lib/cdfsel.c +++ /dev/null @@ -1,907 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `select' operations. -* -* Version 1.4a, 21-Feb-97, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 21-Aug-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 4-Jan-94, J Love CDF V2.4. -* V1.3 15-Dec-94, J Love CDF V2.5. -* V1.3a 4-Jan-95, J Love Encode/decode changes. -* V1.3b 19-Jan-95, J Love IRIX 6.0 (64-bit). -* V1.3c 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.4 5-Sep-96, J Love CDF V2.6. -* V1.4a 21-Feb-97, J Love Removed RICE. -* V2.0 08-Apr-04, M Liu Modified selection for r/zVAR_ to see if -* its the same as the current. if not, get and -* save its offset from the file. This offset -* is used for any succeeding reference to this -* variable for GET/PUT/DELETE/CLOSE operation. -* V3.2 20-Jun-07, D Berger Added clearing of READONLY mode metadata state -* info when READONLYon selected. -* V3.2a 29-AUG-07, D Berger Removed clearing of READONLY mode metadata state -* info when zMODE selected. -* -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* CDFsel. -******************************************************************************/ - -STATICforIDL CDFstatus CDFsel (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ -CDFstatus tStatus, pStatus = CDF_OK; -switch (Va->item) { - /**************************************************************************** - * CDF_, select the current CDF. - ****************************************************************************/ - case CDF_: { - CDFid id = va_arg (Va->ap, CDFid); - /************************************************************************** - * Check if the reserved CDFid (used by IDL interface and Windows DLL). - **************************************************************************/ - if (id == RESERVED_CDFID) { - Cur->cdf = (struct CDFstruct *) RESERVED_CDFID; - break; - } - /************************************************************************** - * Check what the CDFid points to. - **************************************************************************/ - switch (((struct CDFstruct *)id)->magic) { - case VALIDid_MAGIC_NUMBER: - case ABORTEDid_MAGIC_NUMBER: - break; - case KILLEDid_MAGIC_NUMBER: - return BAD_CDF_ID; - default: - return BAD_CDF_ID; - } - /************************************************************************** - * Set the current CDF. - **************************************************************************/ - Cur->cdf = (struct CDFstruct *) id; - break; - } - /**************************************************************************** - * CDF_STATUS_, select the current CDFstatus. - ****************************************************************************/ - case CDF_STATUS_: { - Cur->status = va_arg (Va->ap, CDFstatus); - break; - } - /**************************************************************************** - * CDF_READONLY_MODE_, select a readonly mode for the current CDF. - ****************************************************************************/ - case CDF_READONLY_MODE_: { - struct CDFstruct *CDF; - Logical Change = FALSE; - long mode = va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - switch (mode) { - case READONLYon: - if (CDF->status == READ_ONLY) - { - if (CDF->readOnly != TRUE) Change = TRUE; - CDF->readOnly = TRUE; - }; - break; - case READONLYoff: - if (CDF->readOnly != FALSE) Change = TRUE; - CDF->readOnly = FALSE; - break; - default: - return BAD_READONLY_MODE; - } - /************************************************************************* - * Clear the READONLY metadata state info. - *************************************************************************/ - if (Change) - { - ResetReadOnlyState(CDF); - if (CDF->readOnly == TRUE && CDF->fp != NULL) - { - if (!sX(ReadGDR(CDF->fp,CDF->GDRoffset, - GDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - }; - }; - break; - } - /**************************************************************************** - * CDF_zMODE_, select a zMode for the current CDF. Changing the zMode causes - * all "current" objects/states to be reset (sort of like - * reopening the CDF). - ****************************************************************************/ - case CDF_zMODE_: { - long mode; - struct CDFstruct *CDF; - mode = va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - switch (mode) { - /************************************************************************ - * zMODEoff, turn off zMode. - ************************************************************************/ - case zMODEoff: - CDF->zMode = (int) zMODEoff; - break; - /************************************************************************ - * zMODEon1, turn on zMode/1. The rVariables become a zGroup (ie. they - * all have the same dimensionality [that of the rVariables] with their - * original record/dimension variances). - ************************************************************************/ - case zMODEon1: - CDF->zMode = (int) zMODEon1; - break; - /************************************************************************ - * zMODEon2, turn on zMode/2. The dimensionality of each rVariable is - * determined based on their dimension variances (dimensions with a - * NOVARY variance are eliminated). - ************************************************************************/ - case zMODEon2: - CDF->zMode = (int) zMODEon2; - break; - /************************************************************************ - * Unknown zMode. - ************************************************************************/ - default: - return BAD_zMODE; - }; - if (!sX(ConfigureNEWzMode(CDF),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - }; - break; - } - /**************************************************************************** - * CDF_DECODING_, selects the decoding for attribute entry and variable data - * values read from the current CDF. - ****************************************************************************/ - case CDF_DECODING_: { - struct CDFstruct *CDF; - long decoding = va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (!ValidDecoding((Int32)decoding)) return BAD_DECODING; - CDF->decoding = decoding; - if (!sX(UpdateConversions(CDF),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * CDF_NEGtoPOSfp0_MODE_, select a negative to positive floating point zero - * mode for the current CDF. - ****************************************************************************/ - case CDF_NEGtoPOSfp0_MODE_: { - struct CDFstruct *CDF; - long mode = va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - switch (mode) { - case NEGtoPOSfp0on: - CDF->negToPosFp0 = TRUE; - break; - case NEGtoPOSfp0off: - CDF->negToPosFp0 = FALSE; - break; - default: - return BAD_NEGtoPOSfp0_MODE; - } - if (!sX(UpdateConversions(CDF),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * CDF_SCRATCHDIR_ - ****************************************************************************/ - case CDF_SCRATCHDIR_: { - struct CDFstruct *CDF; size_t length; - char *scratchDir = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - if (CDF->scratchDir != NULL) { - cdf_FreeMemory (CDF->scratchDir, NULL); - CDF->scratchDir = NULL; - } - if (scratchDir == NULL) return BAD_SCRATCH_DIR; - length = strlen (scratchDir); - if (length > DU_MAX_DIR_LEN) return BAD_SCRATCH_DIR; - CDF->scratchDir = (char *) cdf_AllocateMemory ((size_t) (length + 1), NULL); - if (CDF->scratchDir == NULL) { - AbortAccess (CDF, UPDATE, noDELETE); - return BAD_MALLOC; - } - strcpyX (CDF->scratchDir, scratchDir, 0); - break; - } - /**************************************************************************** - * CDF_CACHESIZE_ - * Select a new cache size for the "working" dotCDF file. A cache size of - * zero causes a reset to the default. - ****************************************************************************/ - case CDF_CACHESIZE_: { - struct CDFstruct *CDF; - int nBuffers = (int) va_arg (Va->ap, long); - if (nBuffers < 0) return BAD_CACHE_SIZE; - SelectCDF (Cur->cdf, CDF) - CDF->workingCacheSize = BOO(nBuffers > 0,nBuffers,BOO(CDF->singleFile, - NUMcacheSINGLE, - NUMcacheMULTI)); - if (!CACHEv(CDF->fp,CDF->workingCacheSize)) { - AbortAccess (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - break; - } - /**************************************************************************** - * STAGE_CACHESIZE_ - * Select a new cache size for the staging file. A cache size of zero causes - * a reset to the default. - ****************************************************************************/ - case STAGE_CACHESIZE_: { - struct CDFstruct *CDF; - int nBuffers = (int) va_arg (Va->ap, long); - if (nBuffers < 0) return BAD_CACHE_SIZE; - SelectCDF (Cur->cdf, CDF) - CDF->stage.cacheSize = BOO(nBuffers > 0,nBuffers,NUMcacheSTAGE); - if (CDF->stage.fp != NULL) { - if (!CACHEv(CDF->stage.fp,CDF->stage.cacheSize)) { - AbortAccess (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - } - break; - } - /**************************************************************************** - * COMPRESS_CACHESIZE_ - * Select a new cache size for the compression scratch file. A cache size of - * zero causes a reset to the default. Note that the vFILE is first cleared - * so that cache buffers are not written to disk. This assumes that the - * compression scratch file is always cleared before being used. - ****************************************************************************/ - case COMPRESS_CACHESIZE_: { - struct CDFstruct *CDF; - int nBuffers = (int) va_arg (Va->ap, long); - if (nBuffers < 0) return BAD_CACHE_SIZE; - SelectCDF (Cur->cdf, CDF) - CDF->compressCacheSize = BOO(nBuffers > 0,nBuffers,NUMcacheCOMPRESS); - if (CDF->compressFp != NULL) { - if (!CLEARv(CDF->compressFp)) { - AbortAccess (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - if (!CACHEv(CDF->compressFp,CDF->compressCacheSize)) { - AbortAccess (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - } - break; - } - /**************************************************************************** - * rVARs_CACHESIZE_/zVARs_CACHESIZE_ - * Selects a new cache size for all of the r/zVariable files. N/A if a - * single-file CDF. A cache size of zero causes a reset to the default. - ****************************************************************************/ - case rVARs_CACHESIZE_: - case zVARs_CACHESIZE_: { - Logical zOp = (Va->item == zVARs_CACHESIZE_); - struct CDFstruct *CDF; struct VarStruct *Var; - int nBuffers = (int) va_arg (Va->ap, long), varN; - if (nBuffers < 0) return BAD_CACHE_SIZE; - if (nBuffers < 1) nBuffers = NUMcacheVAR; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (CDF->singleFile) { - sX (SINGLE_FILE_FORMAT, &pStatus); - break; - } - if (zModeON(CDF)) { - for (varN = 0; varN < CDF->NrVars; varN++) { - if (!sX(InitVar(CDF,varN,FALSE,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->varCacheSize = nBuffers; - if (Var->fp != NULL) { - if (!CACHEv(Var->fp,Var->varCacheSize)) { - AbortAccess (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - } - } - for (varN = 0; varN < CDF->NzVars; varN++) { - if (!sX(InitVar(CDF,varN,TRUE,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->varCacheSize = nBuffers; - if (Var->fp != NULL) { - if (!CACHEv(Var->fp,Var->varCacheSize)) { - AbortAccess (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - } - } - } - else { - long nVars = BOO(zOp,CDF->NzVars,CDF->NrVars); - for (varN = 0; varN < nVars; varN++) { - if (!sX(InitVar(CDF,varN,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->varCacheSize = nBuffers; - if (Var->fp != NULL) { - if (!CACHEv(Var->fp,Var->varCacheSize)) { - AbortAccess (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - } - } - } - break; - } - /**************************************************************************** - * rVAR_CACHESIZE_/zVAR_CACHESIZE_, selects a new cache size for the current - * r/zVariable's file. N/a if a single-file CDF. A cache size of zero causes - * a reset to the default. - ****************************************************************************/ - case rVAR_CACHESIZE_: - case zVAR_CACHESIZE_: { - Logical zOp = (Va->item == zVAR_CACHESIZE_); - struct CDFstruct *CDF; struct VarStruct *Var; - int nBuffers = (int) va_arg (Va->ap, long); - if (nBuffers < 0) return BAD_CACHE_SIZE; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (CDF->singleFile) { - sX (SINGLE_FILE_FORMAT, &pStatus); - break; - } - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->varCacheSize = BOO(nBuffers < 1,NUMcacheVAR,nBuffers); - if (Var->fp != NULL) { - if (!CACHEv(Var->fp,Var->varCacheSize)) { - AbortAccess (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - } - break; - } - /**************************************************************************** - * rVAR_/zVAR_ - * Select (by number) the current rVariable/zVariable for the current CDF. - ****************************************************************************/ - case rVAR_: - case zVAR_: { - Logical zOp = (Va->item == zVAR_); - struct CDFstruct *CDF; - Int32 offset; - Int32 varNum = (Int32) va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (varNum < 0) return BAD_VAR_NUM; - if (zModeON(CDF)) - if (varNum < CDF->NrVars) { - if (CDF->CURzVarNum == varNum) { - offset = CDF->CURzVarOffset; - return CDF_OK; - } else { - if (!sX(FindVarByNumber(CDF,varNum,FALSE,&offset),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - CDF->CURzVarNum = varNum; - CDF->CURzVarOffset = offset; - return pStatus; - } - } - else { - long varNumT = varNum - CDF->NrVars; - if (varNumT < CDF->NzVars) { - if (CDF->CURzVarNum == varNum) { - offset = CDF->CURzVarOffset; - return CDF_OK; - } else { - if (!sX(FindVarByNumber(CDF,varNumT,TRUE,&offset),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - CDF->CURzVarNum = varNum; - CDF->CURzVarOffset = offset; - return pStatus; - } - } - else - return NO_SUCH_VAR; - } - else - if (varNum < BOO(zOp,CDF->NzVars,CDF->NrVars)) { - if (zOp) { - if (CDF->CURzVarNum == varNum) { - offset = CDF->CURzVarOffset; - return CDF_OK; - } else { - if (!sX(FindVarByNumber(CDF,varNum,TRUE,&offset),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - CDF->CURzVarNum = varNum; - CDF->CURzVarOffset = offset; - return pStatus; - } - } - else { - if (CDF->CURrVarNum == varNum) { - offset = CDF->CURrVarOffset; - return CDF_OK; - } else { - if (!sX(FindVarByNumber(CDF,varNum,FALSE,&offset),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - CDF->CURrVarNum = varNum; - CDF->CURrVarOffset = offset; - return pStatus; - } - } - } else - return NO_SUCH_VAR; - break; - } - /**************************************************************************** - * rVAR_NAME_/zVAR_NAME_ - * Select (by name) the current rVariable/zVariable for the current CDF. - ****************************************************************************/ - case rVAR_NAME_: - case zVAR_NAME_: { - Logical zOp = (Va->item == zVAR_NAME_), zVar; - struct CDFstruct *CDF; - char *varName = va_arg (Va->ap, char *); - Int32 varN, offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - tStatus = FindVarByName (CDF, varName, &offset, &zVar, NULL); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_VAR: - return tStatus; - default: - AbortAccess (CDF, UPDATE, noDELETE); - return tStatus; - } - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_NUM,&varN, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (zModeON(CDF)) { - CDF->CURzVarNum = (zVar ? CDF->NrVars + varN : varN); - CDF->CURzVarOffset = offset; - } else { - if (zOp) - if (zVar) { - CDF->CURzVarNum = varN; - CDF->CURzVarOffset = offset; - } else - return NO_SUCH_VAR; /* Wrong type of variable. */ - else - if (zVar) - return NO_SUCH_VAR; /* Wrong type of variable. */ - else { - CDF->CURrVarNum = varN; - CDF->CURrVarOffset = offset; - } - } - break; - } - /**************************************************************************** - * rVARs_RECNUMBER_/rVARs_RECCOUNT_/rVARs_RECINTERVAL_ - ****************************************************************************/ - case rVARs_RECNUMBER_: - case rVARs_RECCOUNT_: - case rVARs_RECINTERVAL_: { - struct CDFstruct *CDF; - Int32 value = (Int32) va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,TRUE)) return ILLEGAL_IN_zMODE; - if (CDF->NrVars == 0) { - if (!sX(NO_VARS_IN_CDF,&pStatus)) return pStatus; - } - switch (Va->item) { - case rVARs_RECNUMBER_: - if (value < 0) return BAD_REC_NUM; - CDF->rRD.recNumber = value; - break; - case rVARs_RECCOUNT_: - if (value < 0) return BAD_REC_COUNT; - CDF->rRD.recCount = value; - break; - case rVARs_RECINTERVAL_: - if (value < 1) return BAD_REC_INTERVAL; - CDF->rRD.recInterval = value; - break; - } - break; - } - /**************************************************************************** - * zVAR_RECNUMBER_/zVAR_RECCOUNT_/zVAR_RECINTERVAL_ - ****************************************************************************/ - case zVAR_RECNUMBER_: - case zVAR_RECCOUNT_: - case zVAR_RECINTERVAL_: { - struct CDFstruct *CDF; - struct VarStruct *Var; - Int32 value = (Int32) va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTvarSELECTED(CDF,TRUE)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar(CDF,TRUE,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (Va->item) { - case zVAR_RECNUMBER_: - if (value < 0) return BAD_REC_NUM; - Var->zRD.recNumber = value; - break; - case zVAR_RECCOUNT_: - if (value < 1) return BAD_REC_COUNT; - Var->zRD.recCount = value; - break; - case zVAR_RECINTERVAL_: - if (value < 1) return BAD_REC_INTERVAL; - Var->zRD.recInterval = value; - break; - } - break; - } - /**************************************************************************** - * zVARs_RECNUMBER_ - ****************************************************************************/ - case zVARs_RECNUMBER_: { - struct CDFstruct *CDF; - struct VarStruct *Var; - Int32 recNumber = (Int32) va_arg (Va->ap, long); Int32 varN; - SelectCDF (Cur->cdf, CDF) - if (zModeON(CDF)) { - if (CDF->NrVars + CDF->NzVars == 0) { - if (!sX(NO_VARS_IN_CDF,&pStatus)) return pStatus; - } - for (varN = 0; varN < CDF->NrVars; varN++) { - if (!sX(InitVar(CDF,varN,FALSE,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->zRD.recNumber = recNumber; - } - for (varN = 0; varN < CDF->NzVars; varN++) { - if (!sX(InitVar(CDF,varN,TRUE,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->zRD.recNumber = recNumber; - } - } - else { - if (CDF->NzVars == 0) { - if (!sX(NO_VARS_IN_CDF,&pStatus)) return pStatus; - } - for (varN = 0; varN < CDF->NzVars; varN++) { - if (!sX(InitVar(CDF,varN,TRUE,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->zRD.recNumber = recNumber; - } - } - break; - } - /**************************************************************************** - * rVARs_DIMINDICES_/rVARs_DIMCOUNTS_/rVARs_DIMINTERVALS_ - ****************************************************************************/ - case rVARs_DIMINDICES_: - case rVARs_DIMCOUNTS_: - case rVARs_DIMINTERVALS_: { - struct CDFstruct *CDF; - long *values = va_arg (Va->ap, long *); - int dimN; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,TRUE)) return ILLEGAL_IN_zMODE; - if (CDF->NrVars == 0) { - if (!sX(NO_VARS_IN_CDF,&pStatus)) return pStatus; - } - switch (Va->item) { - case rVARs_DIMINDICES_: { - for (dimN = 0; dimN < CDF->rNumDims; dimN++) - if (values[dimN] < 0 || CDF->rDimSizes[dimN] <= values[dimN]) - return BAD_DIM_INDEX; - else - CDF->rRD.dimIndices[dimN] = (Int32) values[dimN]; - break; - } - case rVARs_DIMCOUNTS_: - for (dimN = 0; dimN < CDF->rNumDims; dimN++) - if (values[dimN] < 1) - return BAD_DIM_COUNT; - else - CDF->rRD.dimCounts[dimN] = (Int32) values[dimN]; - break; - case rVARs_DIMINTERVALS_: - for (dimN = 0; dimN < CDF->rNumDims; dimN++) - if (values[dimN] < 1) - return BAD_DIM_INTERVAL; - else - CDF->rRD.dimIntervals[dimN] = (Int32) values[dimN]; - break; - } - break; - } - /**************************************************************************** - * zVAR_DIMINDICES_/zVAR_DIMCOUNTS_/zVAR_DIMINTERVALS_ - ****************************************************************************/ - case zVAR_DIMINDICES_: - case zVAR_DIMCOUNTS_: - case zVAR_DIMINTERVALS_: { - struct CDFstruct *CDF; - struct VarStruct *Var; - long *values = va_arg (Va->ap, long *); - int dimN; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTvarSELECTED(CDF,TRUE)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar(CDF,TRUE,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (Va->item) { - case zVAR_DIMINDICES_: - for (dimN = 0; dimN < Var->numDims; dimN++) - if (values[dimN] < 0 || Var->dimSizes[dimN] <= values[dimN]) - return BAD_DIM_INDEX; - else - Var->zRD.dimIndices[dimN] = (Int32) values[dimN]; - break; - case zVAR_DIMCOUNTS_: - for (dimN = 0; dimN < Var->numDims; dimN++) - if (values[dimN] < 1) - return BAD_DIM_COUNT; - else - Var->zRD.dimCounts[dimN] = (Int32) values[dimN]; - break; - case zVAR_DIMINTERVALS_: - for (dimN = 0; dimN < Var->numDims; dimN++) - if (values[dimN] < 1) - return BAD_DIM_INTERVAL; - else - Var->zRD.dimIntervals[dimN] = (Int32) values[dimN]; - break; - } - break; - } - /**************************************************************************** - * rVAR_SEQPOS_/zVAR_SEQPOS_, - ****************************************************************************/ - case rVAR_SEQPOS_: - case zVAR_SEQPOS_: { - Logical zOp = (Va->item == zVAR_SEQPOS_); - struct CDFstruct *CDF; struct VarStruct *Var; - int dimN; Int32 indices[CDF_MAX_DIMS]; - Int32 recNumber = (Int32) va_arg (Va->ap, long); - long *dimIndices = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (recNumber < 0) return BAD_REC_NUM; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - for (dimN = 0; dimN < Var->numDims; dimN++) { - if (dimIndices[dimN] < 0 || dimIndices[dimN] >= Var->dimSizes[dimN]) - return BAD_DIM_INDEX; - else - indices[dimN] = (Int32) dimIndices[dimN]; - } - Var->seqValueOffset = BOO(Var->recVary,recNumber*Var->NphyRecValues,0); - Var->seqValueOffset += IndicesValueOffset (Var->numDims, indices, - Var->dimVarys, - Var->nPhyDimValues); - break; - } - /**************************************************************************** - * rVAR_RESERVEPERCENT_/zVAR_RESERVEPERCENT_ - ****************************************************************************/ - case rVAR_RESERVEPERCENT_: - case zVAR_RESERVEPERCENT_: { - Logical zOp = (Va->item == zVAR_RESERVEPERCENT_); - struct CDFstruct *CDF; struct VarStruct *Var; - int pct = (int) va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (pct < 0) return BAD_COMPRESSION_PARM; - if (!sX(InitCurrentVar(CDF,zOp,&Var),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (Var->vType) { - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - Var->reservePct = pct; - break; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return CDF_INTERNAL_ERROR; - case STANDARD_: - case SPARSE_RECORDS_: - sX (NA_FOR_VARIABLE, &pStatus); - break; - case IN_MULTI_: - sX (MULTI_FILE_FORMAT, &pStatus); - break; - } - break; - } - /**************************************************************************** - * ATTR_/ATTR_NAME_ - * Select the current attribute by number/name. - ****************************************************************************/ - case ATTR_: - case ATTR_NAME_: { - Logical nameOp = (Va->item == ATTR_NAME_); - long attrNum; char *attrName; struct CDFstruct *CDF; Int32 offset; - if (nameOp) - attrName = va_arg (Va->ap, char *); - else { - attrNum = va_arg (Va->ap, long); - if (attrNum < 0) return BAD_ATTR_NUM; - } - /************************************************************************** - * Determine current attribute offset. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - tStatus = BOO(nameOp,FindAttrByName(CDF,attrName,&offset), - FindAttrByNumber(CDF,(Int32)attrNum,&offset)); - switch (tStatus) { - case CDF_OK: - CDF->CURattrOffset = offset; - break; - case NO_SUCH_ATTR: - return tStatus; - default: - AbortAccess (CDF, UPDATE, noDELETE); - return tStatus; - } - /************************************************************************** - * Reset current entry offsets. - **************************************************************************/ - if (!sX(SetCURgrEntry(CDF,FALSE,CDF->CURgrEntryNum),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(SetCURzEntry(CDF,FALSE,CDF->CURzEntryNum),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * gENTRY_/rENTRY_/zENTRY_, select the current g/r/zEntry by number. - ****************************************************************************/ - case gENTRY_: - case rENTRY_: - case zENTRY_: { - struct CDFstruct *CDF; Logical zOp = (Va->item == zENTRY_); - long entryNum = va_arg (Va->ap, long); - /************************************************************************** - * Setup/validate operation. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,Va->item==rENTRY_)) return ILLEGAL_IN_zMODE; - if (entryNum < 0) return BAD_ENTRY_NUM; - /************************************************************************** - * Set current entry number and offset. - **************************************************************************/ - if (!sX(BOO(zOp,SetCURzEntry(CDF,TRUE,(Int32)entryNum), - SetCURgrEntry(CDF,TRUE,(Int32)entryNum)),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * rENTRY_NAME_/zENTRY_NAME_, select the current r/zEntry number by variable - * name. - ****************************************************************************/ - case rENTRY_NAME_: - case zENTRY_NAME_: { - void *varName = va_arg (Va->ap, void *); - Logical zOp = (Va->item == zENTRY_NAME_), zVar; - struct CDFstruct *CDF; - Int32 offset, varN; - long entryNum; - /************************************************************************** - * Setup/validate operation. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,Va->item == rENTRY_NAME_)) return ILLEGAL_IN_zMODE; - /************************************************************************** - * Locate the VDR. - **************************************************************************/ - tStatus = FindVarByName (CDF, varName, &offset, &zVar, NULL); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_VAR: - return tStatus; - default: - AbortAccess (CDF, UPDATE, noDELETE); - return tStatus; - } - /************************************************************************** - * Read the variable number. - **************************************************************************/ - if (!sX(ReadVDR(CDF,CDF->fp,offset,zVar, - VDR_NUM,&varN, - VDR_NULL),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Determine the new entry number. - **************************************************************************/ - if (zModeON(CDF)) - if (zVar) - entryNum = CDF->NrVars + varN; - else - entryNum = varN; - else - if (zVar) - if (zOp) - entryNum = varN; - else - return NO_SUCH_VAR; /* Wrong type of variable. */ - else - if (zOp) - return NO_SUCH_VAR; /* Wrong type of variable. */ - else - entryNum = varN; - /************************************************************************** - * Set the current entry number and offset. - **************************************************************************/ - if (!sX(BOO(zOp,SetCURzEntry(CDF,FALSE,(Int32)entryNum), - SetCURgrEntry(CDF,FALSE,(Int32)entryNum)),&pStatus)) { - AbortAccess (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * Unknown item, must be the next function. - ****************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } -} -return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfsel64.c b/cdf36_3-dist/src/lib/cdfsel64.c deleted file mode 100644 index 77b15c9..0000000 --- a/cdf36_3-dist/src/lib/cdfsel64.c +++ /dev/null @@ -1,912 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF `select' operations. -* -* Version 1.4a, 21-Feb-97, Hughes STX. -* -* Modification history: -* -* V1.0 20-May-92, J Love Original version (was part of `cdflib.c'). -* V1.1 21-Aug-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 4-Jan-94, J Love CDF V2.4. -* V1.3 15-Dec-94, J Love CDF V2.5. -* V1.3a 4-Jan-95, J Love Encode/decode changes. -* V1.3b 19-Jan-95, J Love IRIX 6.0 (64-bit). -* V1.3c 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.4 5-Sep-96, J Love CDF V2.6. -* V1.4a 21-Feb-97, J Love Removed RICE. -* V2.0 08-Apr-04, M Liu Modified selection for r/zVAR_ to see if -* its the same as the current. if not, get and -* save its offset from the file. This offset -* is used for any succeeding reference to this -* variable for GET/PUT/DELETE/CLOSE operation. -* V2.1 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* V3.2 20-Jun-07, D Berger Added clearing of READONLY mode metadata state -* info when READONLYon selected. -* V3.2a 29-Aug-07, D Berger Removed clearing of READONLY mode metadata state -* info when zMODE selected. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* CDFsel64. -******************************************************************************/ - -STATICforIDL CDFstatus CDFsel64 (Va, Cur) -struct VAstruct *Va; -struct CurStruct *Cur; -{ -CDFstatus tStatus, pStatus = CDF_OK; -switch (Va->item) { - /**************************************************************************** - * CDF_, select the current CDF. - ****************************************************************************/ - case CDF_: { - CDFid id = va_arg (Va->ap, CDFid); - /************************************************************************** - * Check if the reserved CDFid (used by IDL interface and Windows DLL). - **************************************************************************/ - if (id == RESERVED_CDFID) { - Cur->cdf = (struct CDFstruct *) RESERVED_CDFID; - break; - } - /************************************************************************** - * Check what the CDFid points to. - **************************************************************************/ - switch (((struct CDFstruct *)id)->magic) { - case VALIDid_MAGIC_NUMBER: - case ABORTEDid_MAGIC_NUMBER: - break; - case KILLEDid_MAGIC_NUMBER: - return BAD_CDF_ID; - default: - return BAD_CDF_ID; - } - /************************************************************************** - * Set the current CDF. - **************************************************************************/ - Cur->cdf = (struct CDFstruct *) id; - break; - } - /**************************************************************************** - * CDF_STATUS_, select the current CDFstatus. - ****************************************************************************/ - case CDF_STATUS_: { - Cur->status = va_arg (Va->ap, CDFstatus); - break; - } - /**************************************************************************** - * CDF_READONLY_MODE_, select a readonly mode for the current CDF. - ****************************************************************************/ - case CDF_READONLY_MODE_: { - struct CDFstruct *CDF; - Logical Change = FALSE; - long mode = va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - switch (mode) { - case READONLYon: - if (CDF->status == READ_ONLY) - { - if (CDF->readOnly != TRUE) Change = TRUE; - CDF->readOnly = TRUE; - }; - break; - case READONLYoff: - if (CDF->readOnly != FALSE) Change = TRUE; - CDF->readOnly = FALSE; - break; - default: - return BAD_READONLY_MODE; - } - /************************************************************************* - * Clear the READONLY metadata state info and read in metatdata if - * READONLYon. - *************************************************************************/ - if (Change) - { - ResetReadOnlyState64(CDF); - if (CDF->readOnly == TRUE && CDF->fp != NULL) - { - if (!sX(ReadGDR64(CDF->fp,CDF->GDRoffset64, - GDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - }; - }; - break; - } - /**************************************************************************** - * CDF_zMODE_, select a zMode for the current CDF. Changing the zMode causes - * all "current" objects/states to be reset (sort of like - * reopening the CDF). - ****************************************************************************/ - case CDF_zMODE_: { - long mode; - struct CDFstruct *CDF; - mode = va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - switch (mode) { - /************************************************************************ - * zMODEoff, turn off zMode. - ************************************************************************/ - case zMODEoff: - CDF->zMode = (int) zMODEoff; - break; - /************************************************************************ - * zMODEon1, turn on zMode/1. The rVariables become a zGroup (ie. they - * all have the same dimensionality [that of the rVariables] with their - * original record/dimension variances). - ************************************************************************/ - case zMODEon1: - CDF->zMode = (int) zMODEon1; - break; - /************************************************************************ - * zMODEon2, turn on zMode/2. The dimensionality of each rVariable is - * determined based on their dimension variances (dimensions with a - * NOVARY variance are eliminated). - ************************************************************************/ - case zMODEon2: - CDF->zMode = (int) zMODEon2; - break; - /************************************************************************ - * Unknown zMode. - ************************************************************************/ - default: - return BAD_zMODE; - } - if (!sX(ConfigureNEWzMode64(CDF),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - }; - break; - } - /**************************************************************************** - * CDF_DECODING_, selects the decoding for attribute entry and variable data - * values read from the current CDF. - ****************************************************************************/ - case CDF_DECODING_: { - struct CDFstruct *CDF; - long decoding = va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (!ValidDecoding((Int32)decoding)) return BAD_DECODING; - CDF->decoding = decoding; - if (!sX(UpdateConversions64(CDF),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * CDF_NEGtoPOSfp0_MODE_, select a negative to positive floating point zero - * mode for the current CDF. - ****************************************************************************/ - case CDF_NEGtoPOSfp0_MODE_: { - struct CDFstruct *CDF; - long mode = va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - switch (mode) { - case NEGtoPOSfp0on: - CDF->negToPosFp0 = TRUE; - break; - case NEGtoPOSfp0off: - CDF->negToPosFp0 = FALSE; - break; - default: - return BAD_NEGtoPOSfp0_MODE; - } - if (!sX(UpdateConversions64(CDF),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * CDF_SCRATCHDIR_ - ****************************************************************************/ - case CDF_SCRATCHDIR_: { - struct CDFstruct *CDF; size_t length; - char *scratchDir = va_arg (Va->ap, char *); - SelectCDF (Cur->cdf, CDF) - if (CDF->scratchDir != NULL) { - cdf_FreeMemory (CDF->scratchDir, NULL); - CDF->scratchDir = NULL; - } - if (scratchDir == NULL) return BAD_SCRATCH_DIR; - length = strlen (scratchDir); - if (length > DU_MAX_DIR_LEN) return BAD_SCRATCH_DIR; - CDF->scratchDir = (char *) cdf_AllocateMemory ((size_t) (length + 1), NULL); - if (CDF->scratchDir == NULL) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return BAD_MALLOC; - } - strcpyX (CDF->scratchDir, scratchDir, 0); - break; - } - /**************************************************************************** - * CDF_CACHESIZE_ - * Select a new cache size for the "working" dotCDF file. A cache size of - * zero causes a reset to the default. - ****************************************************************************/ - case CDF_CACHESIZE_: { - struct CDFstruct *CDF; - int nBuffers = (int) va_arg (Va->ap, long); - if (nBuffers < 0) return BAD_CACHE_SIZE; - SelectCDF (Cur->cdf, CDF) - CDF->workingCacheSize = BOO(nBuffers > 0,nBuffers,BOO(CDF->singleFile, - NUMcacheSINGLE, - NUMcacheMULTI)); - if (!CACHEv64(CDF->fp,CDF->workingCacheSize)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - break; - } - /**************************************************************************** - * STAGE_CACHESIZE_ - * Select a new cache size for the staging file. A cache size of zero causes - * a reset to the default. - ****************************************************************************/ - case STAGE_CACHESIZE_: { - struct CDFstruct *CDF; - int nBuffers = (int) va_arg (Va->ap, long); - if (nBuffers < 0) return BAD_CACHE_SIZE; - SelectCDF (Cur->cdf, CDF) - CDF->stage.cacheSize = BOO(nBuffers > 0,nBuffers,NUMcacheSTAGE); - if (CDF->stage.fp != NULL) { - if (!CACHEv64(CDF->stage.fp,CDF->stage.cacheSize)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - } - break; - } - /**************************************************************************** - * COMPRESS_CACHESIZE_ - * Select a new cache size for the compression scratch file. A cache size of - * zero causes a reset to the default. Note that the vFILE is first cleared - * so that cache buffers are not written to disk. This assumes that the - * compression scratch file is always cleared before being used. - ****************************************************************************/ - case COMPRESS_CACHESIZE_: { - struct CDFstruct *CDF; - int nBuffers = (int) va_arg (Va->ap, long); - if (nBuffers < 0) return BAD_CACHE_SIZE; - SelectCDF (Cur->cdf, CDF) - CDF->compressCacheSize = BOO(nBuffers > 0,nBuffers,NUMcacheCOMPRESS); - if (CDF->compressFp != NULL) { - if (!CLEARv(CDF->compressFp)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - if (!CACHEv64(CDF->compressFp,CDF->compressCacheSize)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - } - break; - } - /**************************************************************************** - * rVARs_CACHESIZE_/zVARs_CACHESIZE_ - * Selects a new cache size for all of the r/zVariable files. N/A if a - * single-file CDF. A cache size of zero causes a reset to the default. - ****************************************************************************/ - case rVARs_CACHESIZE_: - case zVARs_CACHESIZE_: { - Logical zOp = (Va->item == zVARs_CACHESIZE_); - struct CDFstruct *CDF; struct VarStruct *Var; - int nBuffers = (int) va_arg (Va->ap, long), varN; - if (nBuffers < 0) return BAD_CACHE_SIZE; - if (nBuffers < 1) nBuffers = NUMcacheVAR; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (CDF->singleFile) { - sX (SINGLE_FILE_FORMAT, &pStatus); - break; - } - if (zModeON(CDF)) { - for (varN = 0; varN < CDF->NrVars; varN++) { - if (!sX(InitVar64(CDF,varN,FALSE,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->varCacheSize = nBuffers; - if (Var->fp != NULL) { - if (!CACHEv64(Var->fp,Var->varCacheSize)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - } - } - for (varN = 0; varN < CDF->NzVars; varN++) { - if (!sX(InitVar64(CDF,varN,TRUE,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->varCacheSize = nBuffers; - if (Var->fp != NULL) { - if (!CACHEv64(Var->fp,Var->varCacheSize)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - } - } - } - else { - long nVars = BOO(zOp,CDF->NzVars,CDF->NrVars); - for (varN = 0; varN < nVars; varN++) { - if (!sX(InitVar64(CDF,varN,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->varCacheSize = nBuffers; - if (Var->fp != NULL) { - if (!CACHEv64(Var->fp,Var->varCacheSize)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - } - } - } - break; - } - /**************************************************************************** - * rVAR_CACHESIZE_/zVAR_CACHESIZE_, selects a new cache size for the current - * r/zVariable's file. N/a if a single-file CDF. A cache size of zero causes - * a reset to the default. - ****************************************************************************/ - case rVAR_CACHESIZE_: - case zVAR_CACHESIZE_: { - Logical zOp = (Va->item == zVAR_CACHESIZE_); - struct CDFstruct *CDF; struct VarStruct *Var; - int nBuffers = (int) va_arg (Va->ap, long); - if (nBuffers < 0) return BAD_CACHE_SIZE; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (CDF->singleFile) { - sX (SINGLE_FILE_FORMAT, &pStatus); - break; - } - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->varCacheSize = BOO(nBuffers < 1,NUMcacheVAR,nBuffers); - if (Var->fp != NULL) { - if (!CACHEv64(Var->fp,Var->varCacheSize)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return BAD_CACHE_SIZE; - } - } - break; - } - /**************************************************************************** - * rVAR_/zVAR_ - * Select (by number) the current rVariable/zVariable for the current CDF. - ****************************************************************************/ - case rVAR_: - case zVAR_: { - Logical zOp = (Va->item == zVAR_); - struct CDFstruct *CDF; - OFF_T offset; - Int32 varNum = (Int32) va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (varNum < 0) return BAD_VAR_NUM; - if (zModeON(CDF)) - if (varNum < CDF->NrVars) { - if (CDF->CURzVarNum == varNum) { - offset = CDF->CURzVarOffset64; - return CDF_OK; - } else { - if (!sX(FindVarByNumber64(CDF,varNum,FALSE,&offset),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - CDF->CURzVarNum = varNum; - CDF->CURzVarOffset64 = offset; - return pStatus; - } - } - else { - long varNumT = varNum - CDF->NrVars; - if (varNumT < CDF->NzVars) { - if (CDF->CURzVarNum == varNum) { - offset = CDF->CURzVarOffset64; - return CDF_OK; - } else { - if (!sX(FindVarByNumber64(CDF,varNumT,TRUE,&offset),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - CDF->CURzVarNum = varNum; - CDF->CURzVarOffset64 = offset; - return pStatus; - } - } - else - return NO_SUCH_VAR; - } - else - if (varNum < BOO(zOp,CDF->NzVars,CDF->NrVars)) { - if (zOp) { - if (CDF->CURzVarNum == varNum) { - offset = CDF->CURzVarOffset64; - return CDF_OK; - } else { - if (!sX(FindVarByNumber64(CDF,varNum,TRUE,&offset),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - CDF->CURzVarNum = varNum; - CDF->CURzVarOffset64 = offset; - return pStatus; - } - } - else { - if (CDF->CURrVarNum == varNum) { - offset = CDF->CURrVarOffset64; - return CDF_OK; - } else { - if (!sX(FindVarByNumber64(CDF,varNum,FALSE,&offset),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - CDF->CURrVarNum = varNum; - CDF->CURrVarOffset64 = offset; - return pStatus; - } - } - } else - return NO_SUCH_VAR; - break; - } - /**************************************************************************** - * rVAR_NAME_/zVAR_NAME_ - * Select (by name) the current rVariable/zVariable for the current CDF. - ****************************************************************************/ - case rVAR_NAME_: - case zVAR_NAME_: { - Logical zOp = (Va->item == zVAR_NAME_), zVar; - struct CDFstruct *CDF; - char *varName = va_arg (Va->ap, char *); - Int32 varN; - OFF_T offset; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - tStatus = FindVarByName64 (CDF, varName, &offset, &zVar, NULL); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_VAR: - return tStatus; - default: - AbortAccess64 (CDF, UPDATE, noDELETE); - return tStatus; - } - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_NUM,&varN, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (zModeON(CDF)) { - CDF->CURzVarNum = (zVar ? CDF->NrVars + varN : varN); - CDF->CURzVarOffset64 = offset; - } else { - if (zOp) - if (zVar) { - CDF->CURzVarNum = varN; - CDF->CURzVarOffset64 = offset; - } else - return NO_SUCH_VAR; /* Wrong type of variable. */ - else - if (zVar) - return NO_SUCH_VAR; /* Wrong type of variable. */ - else { - CDF->CURrVarNum = varN; - CDF->CURrVarOffset64 = offset; - } - } - break; - } - /**************************************************************************** - * rVARs_RECNUMBER_/rVARs_RECCOUNT_/rVARs_RECINTERVAL_ - ****************************************************************************/ - case rVARs_RECNUMBER_: - case rVARs_RECCOUNT_: - case rVARs_RECINTERVAL_: { - struct CDFstruct *CDF; - Int32 value = (Int32) va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,TRUE)) return ILLEGAL_IN_zMODE; - if (CDF->NrVars == 0) { - if (!sX(NO_VARS_IN_CDF,&pStatus)) return pStatus; - } - switch (Va->item) { - case rVARs_RECNUMBER_: - if (value < 0) return BAD_REC_NUM; - CDF->rRD.recNumber = value; - break; - case rVARs_RECCOUNT_: - if (value < 0) return BAD_REC_COUNT; - CDF->rRD.recCount = value; - break; - case rVARs_RECINTERVAL_: - if (value < 1) return BAD_REC_INTERVAL; - CDF->rRD.recInterval = value; - break; - } - break; - } - /**************************************************************************** - * zVAR_RECNUMBER_/zVAR_RECCOUNT_/zVAR_RECINTERVAL_ - ****************************************************************************/ - case zVAR_RECNUMBER_: - case zVAR_RECCOUNT_: - case zVAR_RECINTERVAL_: { - struct CDFstruct *CDF; - struct VarStruct *Var; - Int32 value = (Int32) va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (!CURRENTvarSELECTED(CDF,TRUE)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar64(CDF,TRUE,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (Va->item) { - case zVAR_RECNUMBER_: - if (value < 0) return BAD_REC_NUM; - Var->zRD.recNumber = value; - break; - case zVAR_RECCOUNT_: - if (value < 1) return BAD_REC_COUNT; - Var->zRD.recCount = value; - break; - case zVAR_RECINTERVAL_: - if (value < 1) return BAD_REC_INTERVAL; - Var->zRD.recInterval = value; - break; - } - break; - } - /**************************************************************************** - * zVARs_RECNUMBER_ - ****************************************************************************/ - case zVARs_RECNUMBER_: { - struct CDFstruct *CDF; - struct VarStruct *Var; - Int32 recNumber = (Int32) va_arg (Va->ap, long); Int32 varN; - SelectCDF (Cur->cdf, CDF) - if (zModeON(CDF)) { - if (CDF->NrVars + CDF->NzVars == 0) { - if (!sX(NO_VARS_IN_CDF,&pStatus)) return pStatus; - } - for (varN = 0; varN < CDF->NrVars; varN++) { - if (!sX(InitVar64(CDF,varN,FALSE,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->zRD.recNumber = recNumber; - } - for (varN = 0; varN < CDF->NzVars; varN++) { - if (!sX(InitVar64(CDF,varN,TRUE,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->zRD.recNumber = recNumber; - } - } - else { - if (CDF->NzVars == 0) { - if (!sX(NO_VARS_IN_CDF,&pStatus)) return pStatus; - } - for (varN = 0; varN < CDF->NzVars; varN++) { - if (!sX(InitVar64(CDF,varN,TRUE,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - Var->zRD.recNumber = recNumber; - } - } - break; - } - /**************************************************************************** - * rVARs_DIMINDICES_/rVARs_DIMCOUNTS_/rVARs_DIMINTERVALS_ - ****************************************************************************/ - case rVARs_DIMINDICES_: - case rVARs_DIMCOUNTS_: - case rVARs_DIMINTERVALS_: { - struct CDFstruct *CDF; - long *values = va_arg (Va->ap, long *); - int dimN; - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,TRUE)) return ILLEGAL_IN_zMODE; - if (CDF->NrVars == 0) { - if (!sX(NO_VARS_IN_CDF,&pStatus)) return pStatus; - } - switch (Va->item) { - case rVARs_DIMINDICES_: { - for (dimN = 0; dimN < CDF->rNumDims; dimN++) - if (values[dimN] < 0 || CDF->rDimSizes[dimN] <= values[dimN]) - return BAD_DIM_INDEX; - else - CDF->rRD.dimIndices[dimN] = (Int32) values[dimN]; - break; - } - case rVARs_DIMCOUNTS_: - for (dimN = 0; dimN < CDF->rNumDims; dimN++) - if (values[dimN] < 1) - return BAD_DIM_COUNT; - else - CDF->rRD.dimCounts[dimN] = (Int32) values[dimN]; - break; - case rVARs_DIMINTERVALS_: - for (dimN = 0; dimN < CDF->rNumDims; dimN++) - if (values[dimN] < 1) - return BAD_DIM_INTERVAL; - else - CDF->rRD.dimIntervals[dimN] = (Int32) values[dimN]; - break; - } - break; - } - /**************************************************************************** - * zVAR_DIMINDICES_/zVAR_DIMCOUNTS_/zVAR_DIMINTERVALS_ - ****************************************************************************/ - case zVAR_DIMINDICES_: - case zVAR_DIMCOUNTS_: - case zVAR_DIMINTERVALS_: { - struct CDFstruct *CDF; - struct VarStruct *Var; - long *values = va_arg (Va->ap, long *); - int dimN; - SelectCDF (Cur->cdf, CDF) - if (!CURRENTvarSELECTED(CDF,TRUE)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar64(CDF,TRUE,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (Va->item) { - case zVAR_DIMINDICES_: - for (dimN = 0; dimN < Var->numDims; dimN++) - if (values[dimN] < 0 || Var->dimSizes[dimN] <= values[dimN]) - return BAD_DIM_INDEX; - else - Var->zRD.dimIndices[dimN] = (Int32) values[dimN]; - break; - case zVAR_DIMCOUNTS_: - for (dimN = 0; dimN < Var->numDims; dimN++) - if (values[dimN] < 1) - return BAD_DIM_COUNT; - else - Var->zRD.dimCounts[dimN] = (Int32) values[dimN]; - break; - case zVAR_DIMINTERVALS_: - for (dimN = 0; dimN < Var->numDims; dimN++) - if (values[dimN] < 1) - return BAD_DIM_INTERVAL; - else - Var->zRD.dimIntervals[dimN] = (Int32) values[dimN]; - break; - } - break; - } - /**************************************************************************** - * rVAR_SEQPOS_/zVAR_SEQPOS_, - ****************************************************************************/ - case rVAR_SEQPOS_: - case zVAR_SEQPOS_: { - Logical zOp = (Va->item == zVAR_SEQPOS_); - struct CDFstruct *CDF; struct VarStruct *Var; - int dimN; Int32 indices[CDF_MAX_DIMS]; - Int32 recNumber = (Int32) va_arg (Va->ap, long); - long *dimIndices = va_arg (Va->ap, long *); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (recNumber < 0) return BAD_REC_NUM; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - for (dimN = 0; dimN < Var->numDims; dimN++) { - if (dimIndices[dimN] < 0 || dimIndices[dimN] >= Var->dimSizes[dimN]) - return BAD_DIM_INDEX; - else - indices[dimN] = (Int32) dimIndices[dimN]; - } - Var->seqValueOffset64 = BOO(Var->recVary,recNumber*Var->NphyRecValues,0); - Var->seqValueOffset64 += IndicesValueOffset (Var->numDims, indices, - Var->dimVarys, - Var->nPhyDimValues); - break; - } - /**************************************************************************** - * rVAR_RESERVEPERCENT_/zVAR_RESERVEPERCENT_ - ****************************************************************************/ - case rVAR_RESERVEPERCENT_: - case zVAR_RESERVEPERCENT_: { - Logical zOp = (Va->item == zVAR_RESERVEPERCENT_); - struct CDFstruct *CDF; struct VarStruct *Var; - int pct = (int) va_arg (Va->ap, long); - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,!zOp)) return ILLEGAL_IN_zMODE; - if (!CURRENTvarSELECTED(CDF,zOp)) return NO_VAR_SELECTED; - if (pct < 0) return BAD_COMPRESSION_PARM; - if (!sX(InitCurrentVar64(CDF,zOp,&Var),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - switch (Var->vType) { - case COMPRESSED_: - case SPARSE_COMPRESSED_RECORDS_: - Var->reservePct = pct; - break; - case SPARSE_ARRAYS_: - case SPARSE_RECORDS_AND_ARRAYS_: - return CDF_INTERNAL_ERROR; - case STANDARD_: - case SPARSE_RECORDS_: - sX (NA_FOR_VARIABLE, &pStatus); - break; - case IN_MULTI_: - sX (MULTI_FILE_FORMAT, &pStatus); - break; - } - break; - } - /**************************************************************************** - * ATTR_/ATTR_NAME_ - * Select the current attribute by number/name. - ****************************************************************************/ - case ATTR_: - case ATTR_NAME_: { - Logical nameOp = (Va->item == ATTR_NAME_); - long attrNum; char *attrName; struct CDFstruct *CDF; OFF_T offset; - if (nameOp) - attrName = va_arg (Va->ap, char *); - else { - attrNum = va_arg (Va->ap, long); - if (attrNum < 0) return BAD_ATTR_NUM; - } - /************************************************************************** - * Determine current attribute offset. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - tStatus = BOO(nameOp,FindAttrByName64(CDF,attrName,&offset), - FindAttrByNumber64(CDF,(Int32)attrNum,&offset)); - switch (tStatus) { - case CDF_OK: - CDF->CURattrOffset64 = offset; - break; - case NO_SUCH_ATTR: - return tStatus; - default: - AbortAccess64 (CDF, UPDATE, noDELETE); - return tStatus; - } - /************************************************************************** - * Reset current entry offsets. - **************************************************************************/ - if (!sX(SetCURgrEntry64(CDF,FALSE,CDF->CURgrEntryNum),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - if (!sX(SetCURzEntry64(CDF,FALSE,CDF->CURzEntryNum),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * gENTRY_/rENTRY_/zENTRY_, select the current g/r/zEntry by number. - ****************************************************************************/ - case gENTRY_: - case rENTRY_: - case zENTRY_: { - struct CDFstruct *CDF; Logical zOp = (Va->item == zENTRY_); - long entryNum = va_arg (Va->ap, long); - /************************************************************************** - * Setup/validate operation. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,Va->item==rENTRY_)) return ILLEGAL_IN_zMODE; - if (entryNum < 0) return BAD_ENTRY_NUM; - /************************************************************************** - * Set current entry number and offset. - **************************************************************************/ - if (!sX(BOO(zOp,SetCURzEntry64(CDF,TRUE,(Int32)entryNum), - SetCURgrEntry64(CDF,TRUE,(Int32)entryNum)),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * rENTRY_NAME_/zENTRY_NAME_, select the current r/zEntry number by variable - * name. - ****************************************************************************/ - case rENTRY_NAME_: - case zENTRY_NAME_: { - void *varName = va_arg (Va->ap, void *); - Logical zOp = (Va->item == zENTRY_NAME_), zVar; - struct CDFstruct *CDF; - Int32 varN; - OFF_T offset; - long entryNum; - /************************************************************************** - * Setup/validate operation. - **************************************************************************/ - SelectCDF (Cur->cdf, CDF) - if (BADzOP(CDF,Va->item == rENTRY_NAME_)) return ILLEGAL_IN_zMODE; - /************************************************************************** - * Locate the VDR. - **************************************************************************/ - tStatus = FindVarByName64 (CDF, varName, &offset, &zVar, NULL); - switch (tStatus) { - case CDF_OK: - break; - case NO_SUCH_VAR: - return tStatus; - default: - AbortAccess64 (CDF, UPDATE, noDELETE); - return tStatus; - } - /************************************************************************** - * Read the variable number. - **************************************************************************/ - if (!sX(ReadVDR64(CDF,CDF->fp,offset,zVar, - VDR_NUM,&varN, - VDR_NULL),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - /************************************************************************** - * Determine the new entry number. - **************************************************************************/ - if (zModeON(CDF)) - if (zVar) - entryNum = CDF->NrVars + varN; - else - entryNum = varN; - else - if (zVar) - if (zOp) - entryNum = varN; - else - return NO_SUCH_VAR; /* Wrong type of variable. */ - else - if (zOp) - return NO_SUCH_VAR; /* Wrong type of variable. */ - else - entryNum = varN; - /************************************************************************** - * Set the current entry number and offset. - **************************************************************************/ - if (!sX(BOO(zOp,SetCURzEntry64(CDF,FALSE,(Int32)entryNum), - SetCURgrEntry64(CDF,FALSE,(Int32)entryNum)),&pStatus)) { - AbortAccess64 (CDF, UPDATE, noDELETE); - return pStatus; - } - break; - } - /**************************************************************************** - * Unknown item, must be the next function. - ****************************************************************************/ - default: { - Va->fnc = Va->item; - break; - } -} -return pStatus; -} diff --git a/cdf36_3-dist/src/lib/cdfstr.c b/cdf36_3-dist/src/lib/cdfstr.c deleted file mode 100644 index 351e979..0000000 --- a/cdf36_3-dist/src/lib/cdfstr.c +++ /dev/null @@ -1,628 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF CDF character string handling. -* -* Version 1.7a, 28-Feb-97, Hughes STX. -* -* Modification history: -* -* V1.0 16-May-91, J Love Original version (for CDF V2.1). This is a -* combination of nulterminate.c, isdescr.c, -* descrtoref.c, and descrtorefnul.c. -* V1.1 31-Jul-91, J Love Added 'array' class to checking for a -* descriptor (DSC$K_CLASS_A). -* V1.2 23-Sep-91, J Love Modified for IBM-PC port. -* V1.3 5-Apr-92, J Love CDF V2.2. -* V1.4 7-Jul-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.5 1-Mar-93, J Love CDF V2.4. -* V1.5a 5-Feb-94, J Love DEC Alpha/OpenVMS port. -* V1.6 13-Dec-94, J Love CDF V2.5. -* V1.6a 10-Jan-95, J Love Added `Trailer'. -* V1.6b 6-Mar-95, J Love Added `IsGraphChr'. Solaris 2.3 IDL i/f. -* `strstr' moved here (for SunOS before 4.1). -* V1.7 22-Aug-96, J Love CDF V2.6. -* V1.7a 28-Feb-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V1.8 12-Aug-10, M Liu Nothing is performed if negative max length -* is passed in in strcpyX, strcatX, catchrX, -* PstrcatX and PstrcpyX. -* -******************************************************************************/ - -/****************************************************************************** -* NOTE: -* Never assume that a string may be NUL-terminated already. If it is, -* it might be accidental and the NUL might go away. -******************************************************************************/ - -#include "cdflib.h" - -#if defined(Fif_DESCR) -#if defined(vms) -#include -#endif -#if defined(MPW_C) -#define MPW_FORTRAN_STRING 18 -struct DESCRstruct { - void *ptr; - short length; - Byte1 filler; - Byte1 type; -}; -#endif -#endif - -#define IsASCII(c) (0 <= c && c <= 127) - -/****************************************************************************** -* NULterminate. NUL-terminate a character string. -******************************************************************************/ - -STATICforIDL char *NULterminate (string, length, ssh) -char *string; /* String to NUL-terminate. */ -size_t length; /* Length of string (not including - the NUL terminator. */ -struct STRINGstruct **ssh; /* Pointer to head of STRINGstruct - linked list. */ -{ - struct STRINGstruct *ss; - - if (*ssh == NULL) { /* First string. */ - *ssh = (struct STRINGstruct *) cdf_AllocateMemory ((size_t)sizeof(struct STRINGstruct), - NULL); - if (*ssh == NULL) return NULL; - ss = *ssh; - } - else { - ss = *ssh; - while (ss->next != NULL) ss = ss->next; - ss->next = (struct STRINGstruct *) - cdf_AllocateMemory ((size_t)sizeof(struct STRINGstruct), NULL); - if (ss->next == NULL) return NULL; - ss = ss->next; - } - - ss->next = NULL; - - ss->string = (char *) cdf_AllocateMemory ((size_t)length + 1, NULL); - if (ss->string == NULL) return NULL; - - memmove (ss->string, string, length); - ss->string[length] = NUL; - - return ss->string; -} - -/****************************************************************************** -* FreeStrings. Free all strings (and control structures) used during the call. -******************************************************************************/ - -STATICforIDL void FreeStrings (ssh) -struct STRINGstruct *ssh; /* Head of STRINGstruct chain. */ -{ - struct STRINGstruct *ss, *sst; - ss = ssh; - while (ss != NULL) { - cdf_FreeMemory (ss->string, NULL); - sst = ss; - ss = ss->next; - cdf_FreeMemory (sst, NULL); - } - return; -} - -#if defined(Fif_DESCR) -/****************************************************************************** -* isDESCR. Is a descriptor being pointed to? -* -* NOTE: -* There is no checking on the length of the string because all lengths -* are valid to VMS and to CDF (for attributes with character data types). It -* is assumed that all lengths will also be valid on the Macintosh using MPW -* Fortran. -* -******************************************************************************/ - -STATICforIDL Logical isDESCR (ptr, aptr, len) -void *ptr; /* could point to a descriptor or to the - string (if already passed by reference) */ -char **aptr; /* pointer to string */ -size_t *len; /* length of string */ -{ -#if defined(vms) - struct dsc$descriptor *tPtr = (struct dsc$descriptor *) ptr; - if (tPtr->dsc$b_dtype == DSC$K_DTYPE_T && - (tPtr->dsc$b_class == DSC$K_CLASS_S || - tPtr->dsc$b_class == DSC$K_CLASS_A || - tPtr->dsc$b_class == DSC$K_CLASS_NCA)) { - *len = tPtr->dsc$w_length; - *aptr = tPtr->dsc$a_pointer; - return TRUE; - } - else - return FALSE; -#endif -#if defined(MPW_C) - struct DESCRstruct *tPtr = (struct DESCRstruct *) ptr; - if (tPtr->type == MPW_FORTRAN_STRING && 0 <= tPtr->length) { - *len = (size_t) tPtr->length; - *aptr = (char *) tPtr->ptr; - return TRUE; - } - else - return FALSE; -#endif -} -#endif - -#if defined(Fif_DESCR) -/****************************************************************************** -* DESCRtoREF. Convert from passing by descriptor to passing by reference. -******************************************************************************/ - -STATICforIDL char *DESCRtoREF (ptr) -void *ptr; /* could point to a descriptor or to the string (if - already passed by reference) */ -{ - char *aptr; /* pointer to string */ - size_t len; /* length of string */ - - if (isDESCR (ptr, &aptr, &len)) - return aptr; - else - return (char *) ptr; /* already passed by reference */ -} -#endif - -#if defined(Fif_DESCR) -/****************************************************************************** -* DESCRtoREFnul. Convert from passing by descriptor to passing by reference -* and NUL-terminate. -* NOTE: -* If a descriptor is being pointed to, always use a temporary string to pass -* by reference - never assume that the string may already be NUL-terminated -* (in case its NUL-terminated by chance and the NUL might go away). -* -******************************************************************************/ - -STATICforIDL char *DESCRtoREFnul (ptr, maxREFlen, ssh) -void *ptr; /* Could point to a descriptor or to - the string (if already passed by - reference). */ -size_t maxREFlen; /* Maximum length of the string if - passed by reference. */ -struct STRINGstruct **ssh; /* Pointer to head of STRINGstruct - linked list. */ -{ - char *aptr; /* pointer to string */ - size_t len; /* length of string */ - if (isDESCR (ptr, &aptr, &len)) - return NULterminate (aptr, len, ssh); - else - return NULterminate (ptr, maxREFlen, ssh); -} -#endif - -#if defined(Fif_NOLEN) -/****************************************************************************** -* FindEndNUL. Find the end of the string and NUL-terminate. -* -* NOTE: -* Never assume that the string may already be NUL-terminated (in case its -* NUL-terminated by chance and the NUL might go away). -* -******************************************************************************/ - -STATICforIDL char *FindEndNUL (ptr, maxREFlen, ssh) -char *ptr; /* Character string. */ -size_t maxREFlen; /* Maximum length of the string. */ -struct STRINGstruct **ssh; /* Pointer to head of STRINGstruct - linked list. */ -{ - size_t i; - for (i = 0; i < maxREFlen; i++) - if (!Printable(ptr[i])) return NULterminate (ptr, i, ssh); - return NULterminate (ptr, maxREFlen, ssh); -} -#endif - -/****************************************************************************** -* Trailer. -* Note that if the trailer is a null-string (length of zero), TRUE will be -* returned. -******************************************************************************/ - -VISIBLE_PREFIX Logical Trailer (string, trailer) -char *string; -char *trailer; -{ - size_t stringL = strlen (string); - size_t trailerL = strlen (trailer); - if (trailerL > stringL) return FALSE; - if (strcmp(&string[stringL-trailerL],trailer)) return FALSE; - return TRUE; -} - -/****************************************************************************** -* strcpyX. -* Copies from the source to the destination but only up to the maximum -* number of characters specified. Then NUL-terminates the destination -* either at the actual end of the copied source string or after the maximum -* number of characters. If the maximum number of characters is zero, then -* a normal `strcpy' is done. If the maximum number of characters is less than -* zero, nothing is copied. 'max', if not zero, could be the destination's -* actual size, or the maximum allowed size for the destination item defined -* in CDF (when the actual size is not available in the calling function), not -* including the terminating NUL character. -******************************************************************************/ - -VISIBLE_PREFIX char *strcpyX (dst, src, max) -char *dst; -char *src; -size_t max; -{ - if (max > 0 && src[0] != NUL) { - size_t j; - j = MINIMUM(strlen(src), max); - strncpy (dst, src, j); - dst[(int)j] = NUL; -/* - int i; - for (i = 0; src[i] != NUL && i < (int) max; i++) dst[i] = src[i]; - dst[i] = NUL; -*/ - } else if (max == 0) { - strcpy (dst, src); - } else if (src[0] == NUL) { - dst[0] = NUL; - } - return dst; -} - -/****************************************************************************** -* strcatX. -* Concatenates from the source to the destination but only up to the -* maximum number of characters, 'max', specified. In other words, 'max' is -* used as a mechanism for controlling how many characters are allowed/stored -* in the destination. Then NUL-terminates the destination either at the actual -* end of the concatenated source string or after the maximum number of -* characters. If the maximum number of characters is zero, then a normal -* `strcat' is done. If the maximum number of characters is less than zero, -* nothing is concatenated. 'max', if not zero, could be the destination's -* actual size, or the maximum allowed size for the destination item defined -* in CDF (when the actual size is not available in the calling function), not -* including the terminating NUL character. -******************************************************************************/ - -VISIBLE_PREFIX char *strcatX (dst, src, max) -char *dst; -char *src; -size_t max; -{ - if (max > 0 && src[0] != NUL) { - size_t i, j; - i = strlen(dst); - j = strlen(src); - if (max > i) { - size_t k = MINIMUM(max - i, j); - if (k > 0) - strncat (dst, src, k); - } -/* - for (i = strlen(dst), j = 0; src[j] != NUL && i < (int) max; i++, j++) { - dst[i] = src[j]; - - } - dst[i] = NUL; -*/ - } else if (max == 0) { - strcat (dst, src); - } - return dst; -} - -/****************************************************************************** -* catchrX. -* Concatenates one character (the source) to the destination string but -* only up to the maximum number of characters specified. If the maximum -* number of characters is zero, the character is always concatenated. -* If the maximum number of characters is less than zero, nothing is -* concatenated. -******************************************************************************/ - -VISIBLE_PREFIX char *catchrX (dst, src, max) -char *dst; -int src; -size_t max; -{ - size_t l = strlen(dst); - if (max > 0) { - if (l < max) { - dst[l] = (char) src; - dst[l+1] = NUL; - } - } else if (max == 0) { - dst[l] = (char) src; - dst[l+1] = NUL; - } - return dst; -} - -/****************************************************************************** -* prependX. -* Place a string at the beginning of another string but don't let the -* destination string exceed a maximum length. -******************************************************************************/ - -VISIBLE_PREFIX char *prependX (dst, src, max) -char *dst; -char *src; -size_t max; -{ - size_t lenDst = strlen(dst); - size_t maxLen = max - lenDst; - size_t lenSrc = MINIMUM (maxLen, strlen(src)); - memmove (&dst[lenSrc], dst, lenDst + 1); - memmove (dst, src, lenSrc); - return dst; -} - -/****************************************************************************** -* PstrcpyX. -* Copy a Pascal-style string to a C-style string. -******************************************************************************/ - -#if defined(mac) -STATICforIDL char *PstrcpyX (dst, src, max) -char *dst; -char *src; -size_t max; -{ - if (max < 0) return dst; - int len = (int) BOO(max > 0,MINIMUM(max,(int)src[0]),src[0]); - strncpy (dst, &src[1], len); - dst[len] = NUL; - return dst; -} -#endif - -/****************************************************************************** -* PstrcatX. -* Concatinate a Pascal-style string to a C-style string. -******************************************************************************/ - -#if defined(mac) -STATICforIDL char *PstrcatX (dst, src, max) -char *dst; -char *src; -size_t max; -{ - if (max > 0) { - int i, j; - for (i = strlen(dst), j = 1; j <= src[0] && i < max; i++, j++) { - dst[i] = src[j]; - } - dst[i] = NUL; - } else if (max == 0) { - strncat (dst, &src[1], (size_t) src[0]); - } - return dst; -} -#endif - -/****************************************************************************** -* PprependX. -* Place a Pascal-style string at the beginning of a C-style string but -* don't let the C-style string exceed a maximum length. -******************************************************************************/ - -#if defined(mac) -STATICforIDL char *PprependX (dst, src, max) -char *dst; -char *src; -size_t max; -{ - size_t lenDst = strlen(dst); - size_t maxLen = max - lenDst; - size_t lenSrc = MINIMUM (maxLen, src[0]); - memmove (&dst[lenSrc], dst, lenDst + 1); - memmove (dst, &src[1], lenSrc); - return dst; -} -#endif - -/****************************************************************************** -* CtoFORTstring. -* Copies a NUL-terminated string (C-style) to a FORTRAN-style string. -******************************************************************************/ - -STATICforIDL void CtoFORTstring (Cstring, FORTstring, length) -char *Cstring; -void *FORTstring; -int length; -{ -#if defined(Fif_DESCR) - char *ptr; size_t lenT; int i; - if (!isDESCR(FORTstring,&ptr,&lenT)) { - ptr = FORTstring; - lenT = (size_t) length; - } -/*memmove (ptr, Cstring, lenT);*/ - strncpy (ptr, Cstring, lenT); - for (i = strlen(Cstring); i < lenT; i++) ptr[i] = ' '; - return; -#else - int i; -/*memmove (FORTstring, Cstring, (size_t) length);*/ - strncpy (FORTstring, Cstring, (size_t) length); - for (i = strlen(Cstring); i < length; i++) ((char *) FORTstring)[i] = ' '; - return; -#endif -} - -/****************************************************************************** -* Printable. -******************************************************************************/ - -VISIBLE_PREFIX int Printable (c) -int c; -{ - return BOO(IsASCII(c),isprint(c),FALSE); -} - -/****************************************************************************** -* UpperCase. -******************************************************************************/ - -VISIBLE_PREFIX int UpperCase (c) -int c; -{ - return BOO(IsASCII(c),isupper(c),FALSE); -} - -/****************************************************************************** -* LowerCase. -******************************************************************************/ - -VISIBLE_PREFIX int LowerCase (c) -int c; -{ - return BOO(IsASCII(c),islower(c),FALSE); -} - -/****************************************************************************** -* Alphabetic. -******************************************************************************/ - -VISIBLE_PREFIX int Alphabetic (c) -int c; -{ - return BOO(IsASCII(c),isalpha(c),FALSE); -} - -/****************************************************************************** -* Decimal. -******************************************************************************/ - -VISIBLE_PREFIX int Decimal (c) -int c; -{ - return BOO(IsASCII(c),isdigit(c),FALSE); -} - -/****************************************************************************** -* Spacing. -******************************************************************************/ - -VISIBLE_PREFIX int Spacing (c) -int c; -{ - return BOO(IsASCII(c),isspace(c),FALSE); -} - -/****************************************************************************** -* Visible. -******************************************************************************/ - -VISIBLE_PREFIX int Visible (c) -int c; -{ - return BOO(IsASCII(c),isgraph(c),FALSE); -} - -/****************************************************************************** -* MakeLower. -******************************************************************************/ - -VISIBLE_PREFIX int MakeLower (c) -int c; -{ - return BOO(UpperCase(c),(c | 0x20),c); -} - -/****************************************************************************** -* MakeUpper. -******************************************************************************/ - -VISIBLE_PREFIX int MakeUpper (c) -int c; -{ - return BOO(LowerCase(c),(c & 0x5F),c); -} - -/****************************************************************************** -* CDFstrcmpIgCase. -* It returns 1 if compared strings are identical with the same length -* 0 if compared strings are not same or there is a NULL string -******************************************************************************/ - -int CDFstrcmpIgCase (string1, string2) -char *string1; -char *string2; -{ - size_t string1L, string2L; - int i; - - if (string1 == NULL || string2 == NULL) return 0; - string1L = strlen(string1); - string2L = strlen(string2); - if (string1L != string2L) return 0; - for (i = 0; i < (int) string1L; i++) { - if (MakeLower(string1[i]) != MakeLower(string2[i])) - return 0; - } - return 1; -} - -/****************************************************************************** -* CDFstrstrIgCase. -******************************************************************************/ - -char *CDFstrstrIgCase (string, substring) -char *string; -char *substring; -{ - size_t stringL, substringL; - int i, j; - - if (string == NULL || substring == NULL) return NULL; - stringL = strlen(string); - substringL = strlen(substring); - if (stringL == 0 || substringL == 0) return NULL; - if (stringL < substringL) return NULL; - for (i = 0; i < (int) stringL; i++) { - for (j = 0; j < (int) substringL; j++) { - if (MakeLower(substring[j]) != MakeLower(string[i+j])) break; - } - if (j == substringL) return &string[i]; - } - return NULL; -} - -/****************************************************************************** -* `strstr' (for SunOS before 4.1). This should no longer be needed. If it -* is, STATICforIDL may or may not need to be present. -******************************************************************************/ - -#if defined(SunOSpre41) -/*STATICforIDL*/ char *strstr (string, substring) -char *string; -char *substring; -{ - int stringL = strlen(string); - int substringL = strlen(substring); - int i, j; - if (stringL == 0 || substringL == 0) return NULL; - if (stringL < substringL) return NULL; - for (i = 0; i < stringL; i++) { - for (j = 0; j < substringL; j++) - if (substring[j] != string[i+j]) break; - if (j == substringL) return &string[i]; - } - return NULL; -} -#endif diff --git a/cdf36_3-dist/src/lib/cdftext.c b/cdf36_3-dist/src/lib/cdftext.c deleted file mode 100644 index 03b8a8b..0000000 --- a/cdf36_3-dist/src/lib/cdftext.c +++ /dev/null @@ -1,817 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Get CDF status code explanation text. -* -* Version 1.3a, 2-Sep-97, Hughes STX. -* -* Modification history: -* -* V1.0 21-Sep-92, J Love Original version. -* V1.1 12-Jan-94, J Love CDF V2.4. -* V1.1a 4-Feb-94, J Love DEC Alpha/OpenVMS port. -* V1.2 24-Oct-94, J Love CDF V2.5. -* V1.2a 10-Jan-95, J Love Incremental release in 1995. -* V1.2b 23-Jan-95, J Love NSI/DECnet -> DECnet. -* V1.2c 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.3 9-Sep-96, J Love CDF V2.6. -* V1.3a 2-Sep-97, J Love Incremental release in 1997. -* V1.4 21-Jun-04, M Liu Added a new error, NOT_A_CDF_OR_NOT_SUPPORTED. -* V1.5 24-Apr-08, M Liu Modified the copyright. -* V1.6 24-Apr-09, M Liu Modified the copyright. -* -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* CDFcopyRight. -* `\012' is used to indicate a newline character because MPW C seems to map -* newline characters to carriage returns (`\015'). -******************************************************************************/ - -STATICforIDL void CDFcopyRight (copyRight) -char *copyRight; -{ - strcpyX (copyRight, -"\012\ -Common Data Format (CDF)\012\ -(C) Copyright 1990-2016 NASA/GSFC\012\ -Space Physics Data Facility\012\ -NASA/Goddard Space Flight Center\012\ -Greenbelt, Maryland 20771 USA\012\ -(Internet -- GSFC-CDF-SUPPORT@LISTS.NASA.GOV)\012", CDF_COPYRIGHT_LEN); - return; -} - -/****************************************************************************** -* CDFstatusText. -******************************************************************************/ - -STATICforIDL CDFstatus CDFstatusText (status, textPtr) -CDFstatus status; -char *textPtr; -{ -#if INCLUDE_STATUS_TEXT - switch (status) { - -case ATTR_EXISTS: -strcpyX (textPtr, -"ATTR_EXISTS: Named attribute already exists.", -CDF_STATUSTEXT_LEN); -break; - -case ATTR_NAME_TRUNC: -strcpyX (textPtr, -"ATTR_NAME_TRUNC: Attribute name truncated.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_ALLOCATE_RECS: -strcpyX (textPtr, -"BAD_ALLOCATE_RECS: Illegal number of records to allocate specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_ARGUMENT: -strcpyX (textPtr, -"BAD_ARGUMENT: Illegal/undefined argument specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_ATTR_NAME: -strcpyX (textPtr, -"BAD_ATTR_NAME: Illegal attribute name specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_ATTR_NUM: -strcpyX (textPtr, -"BAD_ATTR_NUM: Illegal attribute number specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_CACHE_SIZE: -strcpyX (textPtr, -"BAD_CACHE_SIZE: Illegal number of cache buffers specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_CDF_EXTENSION: -strcpyX (textPtr, -"BAD_CDF_EXTENSION: Illegal/missing extension for multi-file CDF.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_CDF_ID: -strcpyX (textPtr, -"BAD_CDF_ID: CDF identifier is unknown or invalid.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_CDF_NAME: -strcpyX (textPtr, -"BAD_CDF_NAME: Illegal CDF name specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_CDFSTATUS: -strcpyX (textPtr, -"BAD_CDFSTATUS: Unknown CDF status code specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_COMPRESSION_PARM: -strcpyX (textPtr, -"BAD_COMPRESSION_PARM: An illegal compression parameter was specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_DATA_TYPE: -strcpyX (textPtr, -"BAD_DATA_TYPE: Unknown data type specified or encountered.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_DECODING: -strcpyX (textPtr, -"BAD_DECODING: Unknown or unsupported data decoding specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_DIM_COUNT: -strcpyX (textPtr, -"BAD_DIM_COUNT: Illegal dimension count specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_DIM_INDEX: -strcpyX (textPtr, -"BAD_DIM_INDEX: Dimension index out of range.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_DIM_INTERVAL: -strcpyX (textPtr, -"BAD_DIM_INTERVAL: Illegal dimension interval specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_DIM_SIZE: -strcpyX (textPtr, -"BAD_DIM_SIZE: Dimension size specified as zero or less.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_ENCODING: -strcpyX (textPtr, -"BAD_ENCODING: Unknown or unsupported data encoding.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_ENTRY_NUM: -strcpyX (textPtr, -"BAD_ENTRY_NUM: Illegal attribute entry number specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_BLOCKING_FACTOR: -strcpyX (textPtr, -"BAD_BLOCKING_FACTOR: Illegal blocking factor specified (less than zero).", -CDF_STATUSTEXT_LEN); -break; - -case BAD_FNC_OR_ITEM: -strcpyX (textPtr, -"BAD_FNC_OR_ITEM: The specified function or item is illegal.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_FORMAT: -strcpyX (textPtr, -"BAD_FORMAT: Unknown CDF format specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_INITIAL_RECS: -strcpyX (textPtr, -"BAD_INITIAL_RECS: Illegal number of initial records.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_MAJORITY: -strcpyX (textPtr, -"BAD_MAJORITY: Unknown variable majority specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_MALLOC: -strcpyX (textPtr, -"BAD_MALLOC: Unable to allocate dynamic memory.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_NEGtoPOSfp0_MODE: -strcpyX (textPtr, -"BAD_NEGtoPOSfp0_MODE: Illegal negative to positive floating point zero mode.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_NUM_DIMS: -strcpyX (textPtr, -"BAD_NUM_DIMS: Illegal number of dimensions.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_NUM_ELEMS: -strcpyX (textPtr, -"BAD_NUM_ELEMS: Illegal number of elements (for data type).", -CDF_STATUSTEXT_LEN); -break; - -case BAD_NUM_VARS: -strcpyX (textPtr, -"BAD_NUM_VARS: Illegal number of variables specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_READONLY_MODE: -strcpyX (textPtr, -"BAD_READONLY_MODE: Illegal read-only mode specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_REC_COUNT: -strcpyX (textPtr, -"BAD_REC_COUNT: Illegal record count specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_REC_INTERVAL: -strcpyX (textPtr, -"BAD_REC_INTERVAL: Illegal record interval specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_REC_NUM: -strcpyX (textPtr, -"BAD_REC_NUM: Record number is out of range.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_SCOPE: -strcpyX (textPtr, -"BAD_SCOPE: Unrecognized attribute scope.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_SPARSEARRAYS_PARM: -strcpyX (textPtr, -"BAD_SPARSEARRAYS_PARM: An illegal sparse arrays parameter was specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_SCRATCH_DIR: -strcpyX (textPtr, -"BAD_SCRATCH_DIR: An illegal scratch directory was specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_VAR_NAME: -strcpyX (textPtr, -"BAD_VAR_NAME: Illegal variable name specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_VAR_NUM: -strcpyX (textPtr, -"BAD_VAR_NUM: Illegal variable number specified.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_zMODE: -strcpyX (textPtr, -"BAD_zMODE: Illegal zMode specified.", -CDF_STATUSTEXT_LEN); -break; - -case CANNOT_ALLOCATE_RECORDS: -strcpyX (textPtr, -"CANNOT_ALLOCATE_RECORDS: Records can't be allocated at this time.", -CDF_STATUSTEXT_LEN); -break; - -case CANNOT_CHANGE: -strcpyX (textPtr, -"CANNOT_CHANGE: The parameter/value can't be set/changed.", -CDF_STATUSTEXT_LEN); -break; - -case CANNOT_COMPRESS: -strcpyX (textPtr, -"CANNOT_COMPRESS: The compression for the CDF/variable can't be set/modified.", -CDF_STATUSTEXT_LEN); -break; - -case CANNOT_SPARSEARRAYS: -strcpyX (textPtr, -"CANNOT_SPARSEARRAYS: Sparse arrays can't be set/modified for the variable.", -CDF_STATUSTEXT_LEN); -break; - -case CANNOT_SPARSERECORDS: -strcpyX (textPtr, -"CANNOT_SPARSERECORDS: Sparse records can't be set/modified for the variable.", -CDF_STATUSTEXT_LEN); -break; - -case CDF_CLOSE_ERROR: -strcpyX (textPtr, -"CDF_CLOSE_ERROR: Close failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case CDF_CREATE_ERROR: -strcpyX (textPtr, -"CDF_CREATE_ERROR: Creation failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case CDF_DELETE_ERROR: -strcpyX (textPtr, -"CDF_DELETE_ERROR: Deletion failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case CDF_EXISTS: -strcpyX (textPtr, -"CDF_EXISTS: The CDF named already exists.", -CDF_STATUSTEXT_LEN); -break; - -case CDF_INTERNAL_ERROR: -strcpyX (textPtr, -"CDF_INTERNAL_ERROR: An internal error has occurred in the CDF library.", -CDF_STATUSTEXT_LEN); -break; - -case CDF_NAME_TRUNC: -strcpyX (textPtr, -"CDF_NAME_TRUNC: CDF pathname truncated.", -CDF_STATUSTEXT_LEN); -break; - -case CDF_OK: -strcpyX (textPtr, -"CDF_OK: Function completed successfully.", -CDF_STATUSTEXT_LEN); -break; - -case CDF_OPEN_ERROR: -strcpyX (textPtr, -"CDF_OPEN_ERROR: Open failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case CDF_READ_ERROR: -strcpyX (textPtr, -"CDF_READ_ERROR: Read failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case CDF_WRITE_ERROR: -strcpyX (textPtr, -"CDF_WRITE_ERROR: Write failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case CORRUPTED_V2_CDF: -strcpyX (textPtr, -"CORRUPTED_V2_CDF: Version 2 CDF is corrupted.", -CDF_STATUSTEXT_LEN); -break; - -case CORRUPTED_V3_CDF: -strcpyX (textPtr, -"CORRUPTED_V3_CDF: Version 3 CDF is corrupted.", -CDF_STATUSTEXT_LEN); -break; - -case DECOMPRESSION_ERROR: -strcpyX (textPtr, -"DECOMPRESSION_ERROR: An error was detected in the compressed data.", -CDF_STATUSTEXT_LEN); -break; - -case DID_NOT_COMPRESS: -strcpyX (textPtr, -"DID_NOT_COMPRESS: The CDF or variable values did not compress.", -CDF_STATUSTEXT_LEN); -break; - -case EMPTY_COMPRESSED_CDF: -strcpyX (textPtr, -"EMPTY_COMPRESSED_CDF: No internal records in a compressed CDF.", -CDF_STATUSTEXT_LEN); -break; - -case END_OF_VAR: -strcpyX (textPtr, -"END_OF_VAR: Current position is at the end of the variable.", -CDF_STATUSTEXT_LEN); -break; - -case FORCED_PARAMETER: -strcpyX (textPtr, -"FORCED_PARAMETER: A specified parameter was changed to a different value.", -CDF_STATUSTEXT_LEN); -break; - -case IBM_PC_OVERFLOW: -strcpyX (textPtr, -"PC_OVERFLOW: Greater than 64Kb of memory required.", -CDF_STATUSTEXT_LEN); -break; - -case ILLEGAL_FOR_SCOPE: -strcpyX (textPtr, -"ILLEGAL_FOR_SCOPE: The operation is illegal for the attribute's scope.", -CDF_STATUSTEXT_LEN); -break; - -case ILLEGAL_IN_zMODE: -strcpyX (textPtr, -"ILLEGAL_IN_zMODE: Operation is illegal while in zMode.", -CDF_STATUSTEXT_LEN); -break; - -case ILLEGAL_ON_V1_CDF: -strcpyX (textPtr, -"ILLEGAL_ON_V1_CDF: Operation not allowed on Version 1 CDFs.", -CDF_STATUSTEXT_LEN); -break; - -case MULTI_FILE_FORMAT: -strcpyX (textPtr, -"MULTI_FILE_FORMAT: Operation n/a when multi-file format.", -CDF_STATUSTEXT_LEN); -break; - -case NA_FOR_VARIABLE: -strcpyX (textPtr, -"NA_FOR_VARIABLE: Operation n/a for the type of variable.", -CDF_STATUSTEXT_LEN); -break; - -case NEGATIVE_FP_ZERO: -strcpyX (textPtr, -"NEGATIVE_FP_ZERO: A negative floating point zero (-0.0) was detected.", -CDF_STATUSTEXT_LEN); -break; - -case NO_ATTR_SELECTED: -strcpyX (textPtr, -"NO_ATTR_SELECTED: An attribute has not been selected.", -CDF_STATUSTEXT_LEN); -break; - -case NO_CDF_SELECTED: -strcpyX (textPtr, -"NO_CDF_SELECTED: A CDF has not been selected.", -CDF_STATUSTEXT_LEN); -break; - -case NO_DELETE_ACCESS: -strcpyX (textPtr, -"NO_DELETE_ACCESS: Deleting is not allowed (read only).", -CDF_STATUSTEXT_LEN); -break; - -case NO_ENTRY_SELECTED: -strcpyX (textPtr, -"NO_ENTRY_SELECTED: An attribute entry has not been selected.", -CDF_STATUSTEXT_LEN); -break; - -case NO_MORE_ACCESS: -strcpyX (textPtr, -"NO_MORE_ACCESS: No more access to the CDF due to a severe error.", -CDF_STATUSTEXT_LEN); -break; - -case NO_PADVALUE_SPECIFIED: -strcpyX (textPtr, -"NO_PADVALUE_SPECIFIED: A pad value has not been specified.", -CDF_STATUSTEXT_LEN); -break; - -case NO_STATUS_SELECTED: -strcpyX (textPtr, -"NO_STATUS_SELECTED: A CDF status code has not been selected.", -CDF_STATUSTEXT_LEN); -break; - -case NO_SUCH_ATTR: -strcpyX (textPtr, -"NO_SUCH_ATTR: Named attribute not found in this CDF.", -CDF_STATUSTEXT_LEN); -break; - -case NO_SUCH_CDF: -strcpyX (textPtr, -"NO_SUCH_CDF: The specified CDF does not exist.", -CDF_STATUSTEXT_LEN); -break; - -case NO_SUCH_ENTRY: -strcpyX (textPtr, -"NO_SUCH_ENTRY: No such entry for specified attribute.", -CDF_STATUSTEXT_LEN); -break; - -case NO_SUCH_RECORD: -strcpyX (textPtr, -"NO_SUCH_RECORD: The specified record does not exist.", -CDF_STATUSTEXT_LEN); -break; - -case NO_SUCH_VAR: -strcpyX (textPtr, -"NO_SUCH_VAR: Named variable not found in this CDF.", -CDF_STATUSTEXT_LEN); -break; - -case NO_VAR_SELECTED: -strcpyX (textPtr, -"NO_VAR_SELECTED: A variable has not been selected.", -CDF_STATUSTEXT_LEN); -break; - -case NO_VARS_IN_CDF: -strcpyX (textPtr, -"NO_VARS_IN_CDF: CDF contains no rVariables.", -CDF_STATUSTEXT_LEN); -break; - -case NO_WRITE_ACCESS: -strcpyX (textPtr, -"NO_WRITE_ACCESS: Write access is not allowed on the CDF file(s).", -CDF_STATUSTEXT_LEN); -break; - -case NOT_A_CDF: -strcpyX (textPtr, -"NOT_A_CDF: Named CDF is corrupted or not actually a CDF.", -CDF_STATUSTEXT_LEN); -break; - -case NOT_A_CDF_OR_NOT_SUPPORTED: -strcpyX (textPtr, -"NOT_A_CDF_OR_NOT_SUPPORTED: Named CDF is corrupted or not supported by the current library version.", -CDF_STATUSTEXT_LEN); -break; - -case PRECEEDING_RECORDS_ALLOCATED: -strcpyX (textPtr, -"PRECEEDING_RECORDS_ALLOCATED: The preceeding records were also allocated.", -CDF_STATUSTEXT_LEN); -break; - -case READ_ONLY_DISTRIBUTION: -strcpyX (textPtr, -"READ_ONLY_DISTRIBUTION: Writing/deleting is illegal.", -CDF_STATUSTEXT_LEN); -break; - -case READ_ONLY_MODE: -strcpyX (textPtr, -"READ_ONLY_MODE: CDF is in read-only mode.", -CDF_STATUSTEXT_LEN); -break; - -case SCRATCH_CREATE_ERROR: -strcpyX (textPtr, -"SCRATCH_CREATE_ERROR: Scratch file creation failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case SCRATCH_DELETE_ERROR: -strcpyX (textPtr, -"SCRATCH_DELETE_ERROR: Scratch file deletion failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case SCRATCH_READ_ERROR: -strcpyX (textPtr, -"SCRATCH_READ_ERROR: Scratch file read failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case SCRATCH_WRITE_ERROR: -strcpyX (textPtr, -"SCRATCH_WRITE_ERROR: Scratch file write failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case SINGLE_FILE_FORMAT: -strcpyX (textPtr, -"SINGLE_FILE_FORMAT: Operation n/a when single-file format.", -CDF_STATUSTEXT_LEN); -break; - -case SOME_ALREADY_ALLOCATED: -strcpyX (textPtr, -"SOME_ALREADY_ALLOCATED: One or more of the records were already allocated.", -CDF_STATUSTEXT_LEN); -break; - -case TOO_MANY_PARMS: -strcpyX (textPtr, -"TOO_MANY_PARMS: Too many parameters were encountered.", -CDF_STATUSTEXT_LEN); -break; - -case TOO_MANY_VARS: -strcpyX (textPtr, -"TOO_MANY_VARS: Only a limited number of variables may exist in this CDF.", -CDF_STATUSTEXT_LEN); -break; - -case UNKNOWN_COMPRESSION: -strcpyX (textPtr, -"UNKNOWN_COMPRESSION: An unknown type of compression was encountered.", -CDF_STATUSTEXT_LEN); -break; - -case UNKNOWN_SPARSENESS: -strcpyX (textPtr, -"UNKNOWN_SPARSENESS: An unknown sparseness was encountered.", -CDF_STATUSTEXT_LEN); -break; - -case UNSUPPORTED_OPERATION: -strcpyX (textPtr, -"UNSUPPORTED_OPERATION: The attempted operation isn't supported at this time.", -CDF_STATUSTEXT_LEN); -break; - -case VAR_ALREADY_CLOSED: -strcpyX (textPtr, -"VAR_ALREADY_CLOSED: Variable is already closed.", -CDF_STATUSTEXT_LEN); -break; - -case VAR_CLOSE_ERROR: -strcpyX (textPtr, -"VAR_CLOSE_ERROR: Close failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case VAR_CREATE_ERROR: -strcpyX (textPtr, -"VAR_CREATE_ERROR: Creation failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case VAR_DELETE_ERROR: -strcpyX (textPtr, -"VAR_DELETE_ERROR: Deletion failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case VAR_EXISTS: -strcpyX (textPtr, -"VAR_EXISTS: Named variable already exists.", -CDF_STATUSTEXT_LEN); -break; - -case VAR_NAME_TRUNC: -strcpyX (textPtr, -"VAR_NAME_TRUNC: Variable name truncated.", -CDF_STATUSTEXT_LEN); -break; - -case VAR_OPEN_ERROR: -strcpyX (textPtr, -"VAR_OPEN_ERROR: Open failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case VAR_READ_ERROR: -strcpyX (textPtr, -"VAR_READ_ERROR: Read failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case VAR_WRITE_ERROR: -strcpyX (textPtr, -"VAR_WRITE_ERROR: Write failed - error from file system.", -CDF_STATUSTEXT_LEN); -break; - -case VIRTUAL_RECORD_DATA: -strcpyX (textPtr, -"VIRTUAL_RECORD_DATA: One or more of the records are virtual.", -CDF_STATUSTEXT_LEN); -break; - -case BAD_CHECKSUM: -strcpyX (textPtr, -"BAD_CHECKSUM: The specified checksum method is not currently supported.", -CDF_STATUSTEXT_LEN); -break; - -case CHECKSUM_ERROR: -strcpyX (textPtr, -"CHECKSUM_ERROR: The data integrity verification through the checksum failed.", -CDF_STATUSTEXT_LEN); -break; - -case CHECKSUM_NOT_ALLOWED: -strcpyX (textPtr, -"CHECKSUM_NOT_ALLOWED: The checksum is not allowed for old versioned files.", -CDF_STATUSTEXT_LEN); -break; - -case IS_A_NETCDF: -strcpyX (textPtr, -"IS_A_NETCDF: Named CDF file is actually a netCDF file.", -CDF_STATUSTEXT_LEN); -break; - -case TT2000_TIME_ERROR: -strcpyX (textPtr, -"TT2000_TIME_ERROR: Error handling the date/time for TT2000 or a TT2000 epoch.", -CDF_STATUSTEXT_LEN); -break; - -case UNABLE_TO_PROCESS_CDF: -strcpyX (textPtr, -"UNABLE_TO_PROCESS_CDF: One of data fields is invalid... Upgrade the library might fix the problem.", -CDF_STATUSTEXT_LEN); -break; - -case ZLIB_COMPRESS_ERROR: -strcpyX (textPtr, -"ZLIB_ERROR: Error during ZLIB compression.", -CDF_STATUSTEXT_LEN); -break; - -case ZLIB_UNCOMPRESS_ERROR: -strcpyX (textPtr, -"ZLIB_ERROR: Error during ZLIB decompression.", -CDF_STATUSTEXT_LEN); -break; - -case ILLEGAL_EPOCH_FIELD: -strcpyX (textPtr, -"ILLEGAL_EPOCH_FIELD: One or more of the date/time fields is out of valid range.", -CDF_STATUSTEXT_LEN); -break; - -case CANNOT_INSERT_RECORDS: -strcpyX (textPtr, -"CANNOT_INSERT_RECORDS: Cannot insert records to a variable with sparserecords.", -CDF_STATUSTEXT_LEN); -break; - -case TT2000_CDF_MAYNEEDUPDATE: -strcpyX (textPtr, -"TT2000_CDF_MAYNEEDUPDATE: CDF version or its file-based template may need to upgrade to handle TT2000 data properly (even its value may be valid).", -CDF_STATUSTEXT_LEN); -break; - -case TT2000_USED_OUTDATED_TABLE: -strcpyX (textPtr, -"TT2000_USED_OUTDATED_TABLE: A TT2000 data is either invalid (made with an oudated leap second table) or trying to use an outdated leap second table.", -CDF_STATUSTEXT_LEN); -break; - -case BADDATE_LEAPSECOND_UPDATED: -strcpyX (textPtr, -"BADDATE_LEAPSECOND_UPDATED: The last leap second updated date is not valid (not in the leap second table).", -CDF_STATUSTEXT_LEN); -break; - -case FUNCTION_NOT_SUPPORTED: -strcpyX (textPtr, -"FUNCTION_NOT_SUPPORTED: This function is not supported. Likely, it is trying to access an rVariable.", -CDF_STATUSTEXT_LEN); -break; - -default: -snprintf (textPtr, (size_t) CDF_STATUSTEXT_LEN+1, - "Text not found - unknown CDF status code (%ld).", status); -return BAD_CDFSTATUS; - - } -#else - snprintf (textPtr, (size_t) CDF_STATUSTEXT_LEN+1, - "Explanation text not available (%ld).", (long) status); -#endif - return CDF_OK; -} diff --git a/cdf36_3-dist/src/lib/cdftt2000.c b/cdf36_3-dist/src/lib/cdftt2000.c deleted file mode 100644 index f823726..0000000 --- a/cdf36_3-dist/src/lib/cdftt2000.c +++ /dev/null @@ -1,1536 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* SPDF/CDF CDF_TIME_TT2000 utility routines for C. -* -* Version 1.0, 15-Mar-11, ADNET systems -* -* Modification history: -* -* V1.0 15-Mar-11, M Liu Initial version (for CDF V3.3.2) -* V2.0 15-Feb-12, M Liu Initial version (for CDF V3.4.0) -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -#define YearWithin(a) ((a >= 1708) && (a <= 2291)) -#define JulianDateJ2000_12h 2451545 -#define J2000Since0AD12h 730485 /* 2000-1-1 since 0-1-1 */ -#define J2000Since0AD12hSec 63113904000.0 -#define J2000Since0AD12hMilsec 63113904000000.0 - /* 86400000.0 * 730485 */ -#define J2000LeapSeconds 32.0 -#define dT 32.184 -#define dTinNanoSecs 32184000000LL -#define MJDbase 2400000.5 -#define SECinNanoSecs 1000000000LL -#define SECinNanoSecsD 1000000000.0 -#define DAYinNanoSecs 86400000000000LL -#define HOURinNanoSecs 3600000000000LL -#define MINUTEinNanoSecs 60000000000LL -#define T12hinNanoSecs 43200000000000LL -/* Julian days for 1707-09-22 and 2292-04-11, the valid TT2000 range. */ -#define JDY17070922 2344793 -#define JDY22920411 2558297 - -/* Number of Delta(dAT) expressions before leap seconds were introduced */ -#define NERA1 14 - -#define LASTLEAPSECONDDAY 20170101 -/* Dates, Delta(AT)s and drift rates */ -static double LTS [][6]= { -/* year month day delta drift drift */ - { 1960, 1, 1, 1.4178180, 37300.0, 0.0012960 }, - { 1961, 1, 1, 1.4228180, 37300.0, 0.0012960 }, - { 1961, 8, 1, 1.3728180, 37300.0, 0.0012960 }, - { 1962, 1, 1, 1.8458580, 37665.0, 0.0011232 }, - { 1963, 11, 1, 1.9458580, 37665.0, 0.0011232 }, - { 1964, 1, 1, 3.2401300, 38761.0, 0.0012960 }, - { 1964, 4, 1, 3.3401300, 38761.0, 0.0012960 }, - { 1964, 9, 1, 3.4401300, 38761.0, 0.0012960 }, - { 1965, 1, 1, 3.5401300, 38761.0, 0.0012960 }, - { 1965, 3, 1, 3.6401300, 38761.0, 0.0012960 }, - { 1965, 7, 1, 3.7401300, 38761.0, 0.0012960 }, - { 1965, 9, 1, 3.8401300, 38761.0, 0.0012960 }, - { 1966, 1, 1, 4.3131700, 39126.0, 0.0025920 }, - { 1968, 2, 1, 4.2131700, 39126.0, 0.0025920 }, - { 1972, 1, 1, 10.0, 0.0, 0.0 }, - { 1972, 7, 1, 11.0, 0.0, 0.0 }, - { 1973, 1, 1, 12.0, 0.0, 0.0 }, - { 1974, 1, 1, 13.0, 0.0, 0.0 }, - { 1975, 1, 1, 14.0, 0.0, 0.0 }, - { 1976, 1, 1, 15.0, 0.0, 0.0 }, - { 1977, 1, 1, 16.0, 0.0, 0.0 }, - { 1978, 1, 1, 17.0, 0.0, 0.0 }, - { 1979, 1, 1, 18.0, 0.0, 0.0 }, - { 1980, 1, 1, 19.0, 0.0, 0.0 }, - { 1981, 7, 1, 20.0, 0.0, 0.0 }, - { 1982, 7, 1, 21.0, 0.0, 0.0 }, - { 1983, 7, 1, 22.0, 0.0, 0.0 }, - { 1985, 7, 1, 23.0, 0.0, 0.0 }, - { 1988, 1, 1, 24.0, 0.0, 0.0 }, - { 1990, 1, 1, 25.0, 0.0, 0.0 }, - { 1991, 1, 1, 26.0, 0.0, 0.0 }, - { 1992, 7, 1, 27.0, 0.0, 0.0 }, - { 1993, 7, 1, 28.0, 0.0, 0.0 }, - { 1994, 7, 1, 29.0, 0.0, 0.0 }, - { 1996, 1, 1, 30.0, 0.0, 0.0 }, - { 1997, 7, 1, 31.0, 0.0, 0.0 }, - { 1999, 1, 1, 32.0, 0.0, 0.0 }, - { 2006, 1, 1, 33.0, 0.0, 0.0 }, - { 2009, 1, 1, 34.0, 0.0, 0.0 }, - { 2012, 7, 1, 35.0, 0.0, 0.0 }, - { 2015, 7, 1, 36.0, 0.0, 0.0 }, - { 2017, 1, 1, 37.0, 0.0, 0.0 } - }; - -/* Number of Delta(AT) in static table */ -static const int NDAT = sizeof (LTS) / sizeof (LTS[0]); -static double **LTD = NULL; -static long long *NST = NULL; -static int entryCnt; - -static long doys1[] = {31,59,90,120,151,181,212,243,273,304,334,365}; -static long doys2[] = {31,60,91,121,152,182,213,244,274,305,335,366}; -static long daym1[] = {31,28,31,30,31,30,31,31,30,31,30,31}; -static long daym2[] = {31,29,31,30,31,30,31,31,30,31,30,31}; - -static int tableChecked = 0; -static int openCDF64s = 0; -static int toPlus = 0; -static long currentDay = -1; -static double currentLeapSeconds; -static double currentJDay; -static int fromFile = 0; - -static double JulianDay12h (long, long, long); -static void DatefromJulianDay (double, long *, long *, long *); -static int ValidateYMD (long, long , long); -static char *MonthToken (long); -static int MonthNumber (char *); -static int ScanUTCstring (char *); -static double LeapSecondsfromYMD (long, long, long); -static double LeapSecondsfromJ2000 (long long, int *); -static void LoadLeapSecondsTable (); -static void LoadLeapNanoSecondsTable (); -static void EPOCHbreakdownTT2000 (double, long *, long *, long *, long *, - long *, long *); -static int LeapSecondLastUpdatedinTable (int); -static void FromUTCISO8601string (char *string, long *ly, long *lm, long *ld, - long *lh, long *ln, long *ls, - long *ll, long *lu, long *la); - -static char *MonthToken (long month) -{ - switch (month) { - case 1: return "Jan"; - case 2: return "Feb"; - case 3: return "Mar"; - case 4: return "Apr"; - case 5: return "May"; - case 6: return "Jun"; - case 7: return "Jul"; - case 8: return "Aug"; - case 9: return "Sep"; - case 10: return "Oct"; - case 11: return "Nov"; - case 12: return "Dec"; - } - return "???"; -} - -static int MonthNumber (char *month) -{ - if (StrStrIgCaseX (month, "jan")) return 1; - else if (StrStrIgCaseX (month, "feb")) return 2; - else if (StrStrIgCaseX (month, "mar")) return 3; - else if (StrStrIgCaseX (month, "apr")) return 4; - else if (StrStrIgCaseX (month, "may")) return 5; - else if (StrStrIgCaseX (month, "jun")) return 6; - else if (StrStrIgCaseX (month, "jul")) return 7; - else if (StrStrIgCaseX (month, "aug")) return 8; - else if (StrStrIgCaseX (month, "sep")) return 9; - else if (StrStrIgCaseX (month, "oct")) return 10; - else if (StrStrIgCaseX (month, "nov")) return 11; - else if (StrStrIgCaseX (month, "dec")) return 12; - else return 0; -} - - -static double JulianDay12h (long y, long m, long d) -{ - if (m == 0) m = 1; - return (double) (367*y-7*(y+(m+9)/12)/4-3*((y+(m-9)/7)/100+1)/4+275*m/9+d+1721029); -} - -static void DatefromJulianDay (double julday, long *y, long *m, long *d) -{ - long i, j, k, l, n; - l=(long) (julday+68569); - n=4*l/146097; - l=l-(146097*n+3)/4; - i=4000*(l+1)/1461001; - l=l-1461*i/4+31; - j=80*l/2447; - k=l-2447*j/80; - l=j/11; - j=j+2-12*l; - i=100*(n-49)+i+l; - *y = i; - *m = j; - *d = k; - return; -} - -static int ScanUTCstring (char *string) -{ - int len; - len = (int) strlen (string); - if ((len == TT2000_3_STRING_LEN) || - (len > 20 && string[10] == 'T')) return 3; - else if ((len == TT2000_0_STRING_LEN) || - (len > 20 && string[11] == ' ')) return 0; - else if ((len == TT2000_1_STRING_LEN) || - (len > 9 && string[8] == '.')) return 1; - else if ((len == TT2000_2_STRING_LEN) || (len > 7)) return 2; - return -1; -} - -static int ValidateYMD (long yy, long mm, long dd) -{ - double jday; - if (yy <= 0 || mm < 0 || dd < 0) return 0; - /* Y-M-D should be in the 1707-09-22 and 2292-04-11 range. */ - jday = JulianDay12h(yy, mm, dd); - if (jday < JDY17070922 || jday > JDY22920411) return 0; - return 1; -} - -void EPOCHbreakdownTT2000 (double epoch, long *year, long *month, long *day, - long *hour, long *minute, long *second) -{ - long jd,i,j,k,l,n; - double second_AD, minute_AD, hour_AD, day_AD; - second_AD = epoch; - minute_AD = second_AD / 60.0; - hour_AD = minute_AD / 60.0; - day_AD = hour_AD / 24.0; - - jd = (long) (1721060 + day_AD); - l=jd+68569; - n=4*l/146097; - l=l-(146097*n+3)/4; - i=4000*(l+1)/1461001; - l=l-1461*i/4+31; - j=80*l/2447; - k=l-2447*j/80; - l=j/11; - j=j+2-12*l; - i=100*(n-49)+i+l; - - *year = i; - *month = j; - *day = k; - - *hour = (long) fmod (hour_AD, (double) 24.0); - *minute = (long) fmod (minute_AD, (double) 60.0); - *second = (long) fmod (second_AD, (double) 60.0); - - return; -} - -static void LoadLeapSecondsTable () -{ - if (!tableChecked) { - char *table; - FILE *leaptable = NULL; - int im, ix; - tableChecked = 1; - table = CDFgetLeapSecondsTableEnvVar(); - if (table != NULL) { - leaptable = fopen (table, "r"); - if (leaptable != NULL) { - int togo = 1; - char line[81]; - int count = 0; - long yy, mm, dd; - while (fgets(line, 80, leaptable)) { - if (line[0] == ';') continue; - ++count; - } - rewind(leaptable); - LTD = (double **) cdf_AllocateMemory (count * sizeof (double *), NULL); - ix = 0; - while (fgets(line, 80, leaptable)) { - if (line[0] == ';') continue; - LTD[ix] = (double *) cdf_AllocateMemory(6 * sizeof(double), NULL); - im = sscanf (line, "%ld %ld %ld %lf %lf %lf", &yy, &mm, &dd, - &(LTD[ix][3]), &(LTD[ix][4]), &(LTD[ix][5])); - if (im != 6) { - int iz; - for (iz = 0; iz < ix; ++iz) - cdf_FreeMemory (LTD[iz], NULL); - cdf_FreeMemory (LTD, NULL); - togo = 0; - break; - } - LTD[ix][0] = (double) yy; - LTD[ix][1] = (double) mm; - LTD[ix][2] = (double) dd; - ++ix; - } - fclose (leaptable); - if (togo == 1) { - entryCnt = count; - fromFile = 1; - } - } - } - if (fromFile == 0) { - LTD = (double **) cdf_AllocateMemory (NDAT * sizeof (double *), NULL); - for (ix = 0; ix < NDAT; ++ix) { - LTD[ix] = (double *) cdf_AllocateMemory(6 * sizeof(double), NULL); - LTD[ix][0] = LTS[ix][0]; - LTD[ix][1] = LTS[ix][1]; - LTD[ix][2] = LTS[ix][2]; - LTD[ix][3] = LTS[ix][3]; - LTD[ix][4] = LTS[ix][4]; - LTD[ix][5] = LTS[ix][5]; - } - entryCnt = NDAT; - } - } -} - -static void LoadLeapNanoSecondsTable () -{ - int ix; - if (LTD == NULL) LoadLeapSecondsTable (); - NST = (long long *) cdf_AllocateMemory (entryCnt * sizeof (long long), NULL); - for (ix = NERA1; ix < entryCnt; ++ix) - NST[ix] = CDF_TT2000_from_UTC_parts(LTD[ix][0], LTD[ix][1], - LTD[ix][2], 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0); -} - -static double LeapSecondsfromYMD (long iy, long im, long id) -{ - int i, j; - long m, n; - double da; - if (LTD == NULL) LoadLeapSecondsTable(); - j = -1; - m = 12 * iy + im; - for (i = entryCnt-1; i >=0; --i) { - n = (long) (12 * LTD[i][0] + LTD[i][1]); - if (m >= n) { - j = i; - break; - } - } - if (j == -1) return 0.0; - da = LTD[j][3]; - /* If pre-1972, adjust for drift. */ - if (j < NERA1) { - double jda; - jda = JulianDay12h (iy, im, id); - da += ((jda - MJDbase) - LTD[j][4]) * LTD[j][5]; - } - return da; -} - -static double LeapSecondsfromJ2000 (long long nanosecs, int *leapSecond) -{ - int i, j; - double da; - *leapSecond = 0; - if (NST == NULL) LoadLeapNanoSecondsTable(); - j = -1; - for (i = entryCnt-1; i >=NERA1; --i) { - if (nanosecs >= NST[i]) { - j = i; - if (i < (entryCnt - 1)) { - /* Check for time following on leap second (second = 60). */ - if ((nanosecs + 1000000000L) >= NST[i+1]) { - *leapSecond = 1; - } - } - break; - } - } - if (j == -1) return 0.0; /* Pre 1972 .... do it later.... */ - da = LTD[j][3]; - return da; -} - -/****************************************************************************** -* CDFgetLeapSecondsTableEnvVar. -******************************************************************************/ - -VISIBLE_PREFIX char *CDFgetLeapSecondsTableEnvVar () -{ - char *table = NULL; -#if defined(vms) - table = getenv("CDF$LEAPSECONDSTABLE"); -#else - table = getenv("CDF_LEAPSECONDSTABLE"); -#endif - return table; -} - -/****************************************************************************** -* CDFClearLeapSecondsTable. -******************************************************************************/ - -VISIBLE_PREFIX void CDFClearLeapSecondsTable () -{ - int ix; - if (LTD != NULL) { - for (ix = 0; ix < entryCnt; ++ix) - cdf_FreeMemory (LTD[ix], NULL); - cdf_FreeMemory (LTD, NULL); - if (NST != NULL) cdf_FreeMemory (NST, NULL); - LTD = NULL; - NST = NULL; - } - tableChecked = 0; -} - -/****************************************************************************** -* CDFfillLeapSecondsTable. -******************************************************************************/ - -VISIBLE_PREFIX void CDFfillLeapSecondsTable (double **table) -{ - int ix; - if (LTD == NULL) LoadLeapSecondsTable(); - for (ix = 0; ix < entryCnt; ++ix) { - table[ix][0] = LTD[ix][0]; - table[ix][1] = LTD[ix][1]; - table[ix][2] = LTD[ix][2]; - table[ix][3] = LTD[ix][3]; - table[ix][4] = LTD[ix][4]; - table[ix][5] = LTD[ix][5]; - } -} - -/****************************************************************************** -* CDFgetRowsinLeapSecondsTable. -******************************************************************************/ - -VISIBLE_PREFIX int CDFgetRowsinLeapSecondsTable () -{ - if (LTD == NULL) LoadLeapSecondsTable(); - return entryCnt; -} - -/****************************************************************************** -* CDFgetLastDateinLeapSecondsTable. -******************************************************************************/ -#if defined(vms) -VISIBLE_PREFIX void CDFgetLastDateinLeapSecondsTBL (long *year, long *month, - long *day) -#else -VISIBLE_PREFIX void CDFgetLastDateinLeapSecondsTable (long *year, long *month, - long *day) -#endif -{ - if (LTD == NULL) LoadLeapSecondsTable(); - *year = (long) LTD[entryCnt-1][0]; - *month = (long) LTD[entryCnt-1][1]; - *day = (long) LTD[entryCnt-1][2]; -} - -/****************************************************************************** -* CDFgetLeapSecondsTableStatus. -******************************************************************************/ - -VISIBLE_PREFIX int CDFgetLeapSecondsTableStatus () -{ - if (LTD == NULL) LoadLeapSecondsTable(); - return fromFile; -} - -/****************************************************************************** -* CDF_TT2000_to_UTC_parts. -******************************************************************************/ - -#if defined(STDARG) -VISIBLE_PREFIX void CDF_TT2000_to_UTC_parts (long long nanoSecSinceJ2000, - double *ly, double *lm, - double *ld, ...) -#else -VISIBLE_PREFIX void CDF_TT2000_to_UTC_parts (long long nanoSecSinceJ2000, - double *ly, double *lm, - double *ld, va_alist) -va_dcl -#endif -{ - double epoch, *tmp, tmp1, dat0; - long long t2, t3, secSinceJ2000; - long nansec; - double *ye, *ym, *da, *opt[6]; - long ye1, mo1, da1, ho1, mi1, se1, ml1, ma1, na1; - int ix, leapSec; - va_list Va; - ye = ly; - ym = lm; - da = ld; -#if defined(STDARG) - va_start (Va, ld); -#else - VA_START (Va); -#endif - ix = 0; - tmp = va_arg (Va, double *); - while (tmp != TT2000NULL) { - opt[ix] = tmp; - ++ix; - if (ix == 6) break; - tmp = va_arg (Va, double *); - } - va_end (Va); - if (nanoSecSinceJ2000 == FILLED_TT2000_VALUE) { - *ly = 9999.0; - *lm = 12.0; - *ld = 31.0; - if (ix > 0) *opt[0] = 23.0; - if (ix > 1) *opt[1] = 59.0; - if (ix > 2) *opt[2] = 59.0; - if (ix > 3) *opt[3] = 999.0; - if (ix > 4) *opt[4] = 999.0; - if (ix > 5) *opt[5] = 999.0; - return; - } else if (nanoSecSinceJ2000 == DEFAULT_TT2000_PADVALUE) { - *ly = 0.0; - *lm = 1.0; - *ld = 1.0; - if (ix > 0) *opt[0] = 0.0; - if (ix > 1) *opt[1] = 0.0; - if (ix > 2) *opt[2] = 0.0; - if (ix > 3) *opt[3] = 0.0; - if (ix > 4) *opt[4] = 0.0; - if (ix > 5) *opt[5] = 0.0; - return; - } - toPlus = 0; - t3 = nanoSecSinceJ2000; - dat0 = LeapSecondsfromJ2000 (nanoSecSinceJ2000, &leapSec); - if (nanoSecSinceJ2000 > 0) { /* try to avoid overflow (substraction first) */ - secSinceJ2000 = (long long) ((double)nanoSecSinceJ2000/SECinNanoSecsD); - nansec = (long) (nanoSecSinceJ2000 - secSinceJ2000 * SECinNanoSecs); - secSinceJ2000 -= 32; /* secs portion in dT */ - secSinceJ2000 += 43200; /* secs in 12h */ - nansec -= 184000000L; /* nanosecs portion in dT */ - } else { /* try to avoid underflow (addition first) */ - nanoSecSinceJ2000 += T12hinNanoSecs; /* 12h in nanosecs */ - nanoSecSinceJ2000 -= dTinNanoSecs /* dT in nanosecs */; - secSinceJ2000 = (long long) ((double)nanoSecSinceJ2000/SECinNanoSecsD); - nansec = (long) (nanoSecSinceJ2000 - secSinceJ2000 * SECinNanoSecs); - } - if (nansec < 0) { - nansec = SECinNanoSecs + nansec; - --secSinceJ2000; - } - t2 = secSinceJ2000 * SECinNanoSecs + nansec; - if (dat0 > 0.0) { /* Post-1972.... */ - secSinceJ2000 -= (long long) dat0; - epoch = (double) J2000Since0AD12hSec + secSinceJ2000; - if (leapSec == 0) - EPOCHbreakdownTT2000 (epoch, &ye1, &mo1, &da1, &ho1, &mi1, &se1); - else { - /* second is at 60.... bearkdown function can't handle 60 so make it - 59 first and then add 1 second back. */ - epoch -= 1.0; - EPOCHbreakdownTT2000 (epoch, &ye1, &mo1, &da1, &ho1, &mi1, &se1); - se1 += 1; - } - } else { /* Pre-1972.... */ - long long tmpNanosecs; - epoch = (double) secSinceJ2000 + J2000Since0AD12hSec; - /* First guess */ - EPOCHbreakdownTT2000 (epoch, &ye1, &mo1, &da1, &ho1, &mi1, &se1); - tmpNanosecs = CDF_TT2000_from_UTC_parts ((double) ye1, (double) mo1, - (double) da1, (double) ho1, - (double) mi1, (double) se1, - 0.0, 0.0, (double) nansec); - if (tmpNanosecs != t3) { - long long tmpx, tmpy; - dat0 = LeapSecondsfromYMD (ye1, mo1, da1); - tmpx = t2 - (long long) (dat0 * SECinNanoSecs); - tmpy = (long long) ((double)tmpx/SECinNanoSecsD); - nansec = (long) (tmpx - tmpy * SECinNanoSecs); - if (nansec < 0) { - nansec = SECinNanoSecs + nansec; - --tmpy; - } - epoch = (double) tmpy + J2000Since0AD12hSec; - /* Second guess */ - EPOCHbreakdownTT2000 (epoch, &ye1, &mo1, &da1, &ho1, &mi1, &se1); - tmpNanosecs = CDF_TT2000_from_UTC_parts ((double) ye1, (double) mo1, - (double) da1, (double) ho1, - (double) mi1, (double) se1, - 0.0, 0.0, (double) nansec); - if (tmpNanosecs != t3) { - dat0 = LeapSecondsfromYMD (ye1, mo1, da1); - tmpx = t2 - (long long) (dat0 * SECinNanoSecs); - tmpy = (long long) ((double)tmpx/SECinNanoSecsD); - nansec = (long) (tmpx - tmpy * SECinNanoSecs); - if (nansec < 0) { - nansec = SECinNanoSecs + nansec; - --tmpy; - } - epoch = (double) tmpy + J2000Since0AD12hSec; - /* One more determination */ - EPOCHbreakdownTT2000 (epoch, &ye1, &mo1, &da1, &ho1, &mi1, &se1); - } - } - } - if (se1 == 60) toPlus = 1; - ml1 = (long) (nansec / 1000000); - tmp1 = nansec - 1000000 * ml1; - if (ml1 > 1000) { - ml1 -= 1000; - se1 += 1; - } - ma1 = (long) (tmp1 / 1000); - na1 = (long) (tmp1 - 1000 * ma1); - *ly = (double) ye1; - *lm = (double) mo1; - if (ix == 6) { - *ld = (double) da1; - *(opt[0]) = (double) ho1; - *(opt[1]) = (double) mi1; - *(opt[2]) = (double) se1; - *(opt[3]) = (double) ml1; - *(opt[4]) = (double) ma1; - *(opt[5]) = (double) na1; - } else if (ix == 5) { - *ld = (double) da1; - *(opt[0]) = (double) ho1; - *(opt[1]) = (double) mi1; - *(opt[2]) = (double) se1; - *(opt[3]) = (double) ml1; - *(opt[4]) = (double) ma1 + (na1 / 1000.0); - } else if (ix == 4) { - *ld = (double) da1; - *(opt[0]) = (double) ho1; - *(opt[1]) = (double) mi1; - *(opt[2]) = (double) se1; - *(opt[3]) = (double) ml1 + (ma1*1000.0 + na1) / 1000000.0; - } else if (ix == 3) { - *ld = (double) da1; - *(opt[0]) = (double) ho1; - *(opt[1]) = (double) mi1; - tmp1 = ml1*1000000.0 + ma1*1000.0 + na1; - *(opt[2]) = (double) se1 + tmp1 / 1000000000.0; - } else if (ix == 2) { - *ld = (double) da1; - *(opt[0]) = (double) ho1; - tmp1 = se1*1000000000.0 + ml1*1000000.0 + ma1*1000.0 + na1; - *(opt[1]) = (double) mi1 + tmp1 / (60000000000.0+1000000000*toPlus); - } else if (ix == 1) { - *ld = (double) da1; - tmp1 = mi1*60000000000.0 + se1*1000000000.0 + ml1*1000000.0 + - ma1*1000.0 + na1; - *(opt[0]) = (double) ho1 + tmp1 / (3600000000000.0+1000000000*toPlus); - } else if (ix == 0) { - tmp1 = ho1*3600000000000.0 + mi1*60000000000.0 + se1*1000000000.0 + - ml1*1000000.0 + ma1*1000.0 + na1; - *ld = (double) da1 + tmp1 / (86400000000000.0 + 1000000000*toPlus); - } -} - -/****************************************************************************** -* computeTT2000withBasedLeapDay. -* This function is similar to CDF_TT2000_from_UTC_parts (aka computeTT2000), -* with an adjustment if necessary. It returns the TT2000 from UTC date/time -* based on the passed last leap second day, while CDF_TT2000_from_UTC_parts -* function is based on the last leap second updated day in the current leap -* second table (LST). -* If the based leap second day is not a zero (0) or if the UTC date/time is -* extended over the next leap second day in the LST, one second(s) will be -* adjusted (deduction), due to the newly added leap second(s) in the LST. -* Otherwise, it returns the same value as CDF_TT2000_from_UTC_parts. -******************************************************************************/ - -VISIBLE_PREFIX long long computeTT2000withBasedLeapDay (long yy, long mm, - long dd, long hh, - long mn, long ss, - long ms, long us, - long ns, int yymmdd) -{ - long long nanoSecSinceJ2000; - if (yy < 0 || mm < 0 || dd < 0 || hh < 0 || mn < 0 || - ss < 0 || ms < 0 || us < 0 || ns < 0) - return ILLEGAL_TT2000_VALUE; - nanoSecSinceJ2000 = computeTT2000 ((double)yy, (double)mm, (double)dd, - (double)hh, (double)mn, (double)ss, - (double)ms, (double)us, (double)ns); - if (yymmdd <= 0 || (yy*10000+mm*100+dd) < (long)yymmdd || - ((yy*10000+mm*100+dd) == (long)yymmdd && (hh*10000+mn*100+ss) < 235960)) - return nanoSecSinceJ2000; - else { - int ix, iy; - ix = LeapSecondLastUpdatedinTable (yymmdd); - iy = LeapSecondLastUpdatedinTable ((int)yy*10000+(int)mm*100+(int)dd); - return (nanoSecSinceJ2000 - (long long)(iy-ix)*1000000000LL); - } -} - -/****************************************************************************** -* breakdownTT2000withBasedLeapDay. -* This function is similar to CDF_TT2000_to_UTC_parts (aka breakdownTT2000), -* with an adjustment if necessary. It returns UTC date/time from TT2000 value, -* based on the passed last leap second day, while CDF_TT2000_to_UTC_parts -* function is based on the last leap second updated day in the current leap -* second table (LST). -* If the based leap second day is zero (0), this routine functions just like -* CDF_TT2000_to_UTC_parts. If the TT2000 value was computed based on the -* LST that was not up-to-date, one second(s) adjustment (addition) might be -* necessay if its value crosses over the next new leap second day in the LST. -******************************************************************************/ - -VISIBLE_PREFIX void breakdownTT2000withBasedLeapDay (long long tt2000, - int yymmdd, long *yy, - long *mm, long *dd, - long *hh, long *mn, - long *ss, long *ms, - long *us, long *ns) -{ - long long *tmpTT2000s; - double yyy, mmm, ddd, hhh, mmn, sss, mms, mus, mns; - int off, ix, iy, found; - - if (yymmdd <= 0) - breakdownTT2000 (tt2000, &yyy, &mmm, &ddd, &hhh, &mmn, &sss, &mms, &mus, - &mns); - else { - ix = LeapSecondLastUpdatedinTable (yymmdd); - off = entryCnt - ix - 1; - if (off == 0) - breakdownTT2000 (tt2000, &yyy, &mmm, &ddd, &hhh, &mmn, &sss, &mms, - &mus, &mns); - else { - found = 0; - tmpTT2000s = (long long *) malloc (sizeof (long long) * off); - for (iy = 0; iy < off; ++iy) - tmpTT2000s[iy] = computeTT2000withBasedLeapDay (LTD[ix+1+iy][0], - LTD[ix+1+iy][1], - LTD[ix+1+iy][2], - 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, yymmdd); - for (iy = off; iy > 0; --iy) { - if (tt2000 >= tmpTT2000s[iy-1]) { - breakdownTT2000 (tt2000+(long long)iy*1000000000LL, &yyy, &mmm, - &ddd, &hhh, &mmn, &sss, &mms, &mus, &mns); - found = 1; - break; - } - } - if (found == 0) - breakdownTT2000 (tt2000, &yyy, &mmm, &ddd, &hhh, &mmn, &sss, &mms, - &mus, &mns); - free (tmpTT2000s); - } - } - *yy = (long) yyy; - *mm = (long) mmm; - *dd = (long) ddd; - *hh = (long) hhh; - *mn = (long) mmn; - *ss = (long) sss; - *ms = (long) mms; - *us = (long) mus; - *ns = (long) mns; -} - -/****************************************************************************** -* encodeTT2000withBasedLeapDay. -* This function is similar to CDF_TT2000_to_UTC_string (aka encodeTT2000), -* with an adjustment if necessary. It encodes TT2000 to UTC string in ISO 8601 -* form based on the passed last leap second day, while CDF_TT2000_to_UTC_string -* function is based on the last leap second updated day in the current leap -* second table (LST). -* If the based leap second day is zero (0), this routine functions just like -* CDF_TT2000_to_UTC_string. If the TT2000 value was computed based on the -* LST that was not up-to-date, one second(s) adjustment (addition) might be -* necessay if its value crosses over the next new leap second day in the LST. -******************************************************************************/ - -VISIBLE_PREFIX void encodeTT2000withBasedLeapDay (long long tt2000, - int yymmdd, char *string) -{ - long long *tmpTT2000s; - int off, ix, iy, found; - if (yymmdd <= 0) { - CDF_TT2000_to_UTC_string (tt2000, string); - return; - } - ix = LeapSecondLastUpdatedinTable (yymmdd); - off = entryCnt - ix - 1; - if (off == 0) { - CDF_TT2000_to_UTC_string (tt2000, string); - return; - } else { - found = 0; - tmpTT2000s = (long long *) malloc (sizeof (long long) * off); - for (iy = 0; iy < off; ++iy) - tmpTT2000s[iy] = computeTT2000withBasedLeapDay (LTD[ix+1+iy][0], - LTD[ix+1+iy][1], - LTD[ix+1+iy][2], - 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, yymmdd); - for (iy = off; iy > 0; --iy) { - if (tt2000 >= tmpTT2000s[iy-1]) { - CDF_TT2000_to_UTC_string (tt2000+(long long)iy*1000000000LL, string); - found = 1; - break; - } - } - if (found == 0) - CDF_TT2000_to_UTC_string (tt2000, string); - free (tmpTT2000s); - } - return; -} - -/****************************************************************************** -* parseTT2000withBasedLeapDay. -* This function is similar to CDF_TT2000_from_UTC_string (aka parseTT2000), -* with an adjustment if necessary. It returns a TT2000 value from the UTC -* string in ISO 8601 form based on the passed last leap second day, while -* CDF_TT2000_from_UTC_string function is based on the last leap second updated -* day in the current leap second table (LST). -* If the based leap second day is zero (0), this routine functions just like -* CDF_TT2000_from_UTC_string. If the UTC string was encoded based on the -* LST that was not up-to-date, one second(s) adjustment (addition) might be -* necessay if its day crosses over the next new leap second day in the LST. -******************************************************************************/ - -VISIBLE_PREFIX long long parseTT2000withBasedLeapDay (char *tt2000, int yymmdd) -{ - long yy, mm, dd, hh, mn, ss, ms, us, ns; - FromUTCISO8601string (tt2000, &yy, &mm, &dd, &hh, &mn, &ss, &ms, &us, &ns); - return computeTT2000withBasedLeapDay ((double)yy, (double)mm, (double)dd, - (double)hh, (double)mn, (double)ss, - (double)ms, (double)us, (double)ns, - yymmdd); -} - -/****************************************************************************** -* CDF_TT2000_from_UTC_parts. -******************************************************************************/ - -#if defined(STDARG) -VISIBLE_PREFIX long long CDF_TT2000_from_UTC_parts (double yy, double mm, - double dd, ...) -#else -VISIBLE_PREFIX long long CDF_TT2000_from_UTC_parts (double yy, double mm, - double dd, va_alist) -va_dcl -#endif -{ - double jd; - long long subDayinNanoSecs, nanoSecSinceJ2000; - long long t2, iy; - double tmp, opt[6]; - va_list Va; - int ix; - double ly, lm, ld, lh, ln, ls, ll, lu, la; - long lyl, lml, ldl, lhl, lnl, lsl, lll, lul, lal; - long xy, xm, xd; - int lyear; - -#if defined(STDARG) - va_start (Va, dd); -#else - VA_START (Va); -#endif - ix = 0; - tmp = va_arg (Va, double); - while (tmp != TT2000END) { - opt[ix] = tmp; - ++ix; - if (ix == 6) break; - tmp = va_arg (Va, double); - } - va_end (Va); - ly = floor(yy); - lm = floor(mm); - ld = floor(dd); - if (ix == 6) { - if (opt[0] < 0.0 || opt[1] < 0.0 || opt[2] < 0.0 || opt[3] < 0.0 || - opt[4] < 0.0 || opt[5] < 0.0) return ILLEGAL_TT2000_VALUE; - lh = opt[0]; - ln = opt[1]; - ls = opt[2]; - ll = opt[3]; - lu = opt[4]; - if ((dd-ld) != 0.0 || (lh-floor(lh)) != 0.0 || (ln-floor(ln)) != 0.0 || - (ls-floor(ls)) != 0.0 || (ll-floor(ll)) != 0.0 || - (lu-floor(lu)) != 0.0) return ILLEGAL_TT2000_VALUE; - la = opt[5]; - } else if (ix == 5) { - if (opt[0] < 0.0 || opt[1] < 0.0 || opt[2] < 0.0 || opt[3] < 0.0 || - opt[4] < 0.0) return ILLEGAL_TT2000_VALUE; - lh = opt[0]; - ln = opt[1]; - ls = opt[2]; - ll = opt[3]; - if ((dd-ld) != 0.0 || (lh-floor(lh)) != 0.0 || (ln-floor(ln)) != 0.0 || - (ls-floor(ls)) != 0.0 || (ll-floor(ll)) != 0.0) - return ILLEGAL_TT2000_VALUE; - lu = floor(opt[4]); - la = (opt[4] - lu) * 1000.0; - } else if (ix == 4) { - if (opt[0] < 0.0 || opt[1] < 0.0 || opt[2] < 0.0 || opt[3] < 0.0) - return ILLEGAL_TT2000_VALUE; - lh = opt[0]; - ln = opt[1]; - ls = opt[2]; - if ((dd-ld) != 0.0 || (lh-floor(lh)) != 0.0 || (ln-floor(ln)) != 0.0 || - (ls-floor(ls)) != 0.0) return ILLEGAL_TT2000_VALUE; - ll = floor(opt[3]); - tmp = (opt[3] - ll) * 1000.0; - lu = floor(tmp); - la = (tmp - lu) * 1000.0; - } else if (ix == 3) { - if (opt[0] < 0.0 || opt[1] < 0.0 || opt[2] < 0.0) - return ILLEGAL_TT2000_VALUE; - lh = opt[0]; - ln = opt[1]; - if ((dd-ld) != 0.0 || (lh-floor(lh)) != 0.0 || (ln-floor(ln)) != 0.0) - return ILLEGAL_TT2000_VALUE; - ls = floor(opt[2]); - tmp = (opt[2] - ls) * 1000.0; - ll = floor(tmp); - tmp = (tmp - ll) * 1000.0; - lu = floor(tmp); - la = (tmp - lu) * 1000.0; - } else if (ix == 2) { - if (opt[0] < 0.0 || opt[1] < 0.0) return ILLEGAL_TT2000_VALUE; - lh = opt[0]; - if ((dd-ld) != 0.0 || (lh-floor(lh)) != 0.0) return ILLEGAL_TT2000_VALUE; - ln = floor(opt[1]); - tmp = opt[1] - ln; - if (tmp > 0.0) { - tmp *= 60.0; - ls = floor(tmp); - tmp = (tmp - ls) * 1000.0; - ll = floor(tmp); - tmp = (tmp - ll) * 1000.0; - lu = floor(tmp); - la = (tmp - lu) * 1000.0; - } else { - ls = ll = lu = la = 0.0; - } - } else if (ix == 1) { - if ((dd-ld) != 0.0) return ILLEGAL_TT2000_VALUE; - if (opt[0] < 0.0) return ILLEGAL_TT2000_VALUE; - tmp = opt[0]; - if (tmp > 0.0) { - lh = floor(tmp); - tmp = (tmp - lh) * 60.0; - ln = floor(tmp); - tmp = (tmp - ln) * 60.0; - ls = floor(tmp); - tmp = (tmp - ls) * 1000.0; - ll = floor(tmp); - tmp = (tmp - ll) * 1000.0; - lu = floor(tmp); - la = (tmp - lu) * 1000.0; - } else { - lh = ln = ls = ll = lu = la = 0.0; - } - } else { /* ix == 0 */ - tmp = dd - ld; - if (tmp > 0.0) { - tmp *= 24.0; - lh = floor(tmp); - tmp = (tmp - lh) * 60.0; - ln = floor(tmp); - tmp = (tmp - ln) * 60.0; - ls = floor(tmp); - tmp = (tmp - ls) * 1000.0; - ll = floor(tmp); - tmp = (tmp - ll) * 1000.0; - lu = floor(tmp); - la = (tmp - lu) * 1000.0; - } else { - lh = ln = ls = ll = lu = la = 0.0; - } - } - lyl = lml = -999; - if (la >= 1000.0) { - double ad, ah, am, as, al, au; - ad = floor(la / 86400000000000.0); - la = la - ad * 86400000000000.0; - ah = floor(la /3600000000000.0); - la = la - ah * 3600000000000.0; - am = floor(la / 60000000000.0); - la = la - am * 60000000000.0; - as = floor(la / 1000000000.0); - la = la - as * 1000000000.0; - al = floor(la /1000000.0); - la = la - al * 1000000.0; - au = floor(la /1000.0); - la = la - au * 1000.0; - ld += ad; - lh += ah; - ln += am; - ls += as; - ll += al; - lu += au; - tmp = JulianDay12h ((long) ly, (long) lm, (long) ld); - DatefromJulianDay (tmp, &lyl, &lml, &ldl); - } - if (lu >= 1000.0) { - double ad, ah, am, as, al; - ad = floor(lu / 86400000000.0); - lu = lu - ad * 86400000000.0; - ah = floor(lu /3600000000.0); - lu = lu - ah * 3600000000.0; - am = floor(lu / 60000000); - lu = lu - am * 60000000; - as = floor(lu / 1000000); - lu = lu - as * 1000000; - al = floor(lu /1000); - lu = lu - al * 1000; - ld += ad; - lh += ah; - ln += am; - ls += as; - ll += al; - tmp = JulianDay12h ((long) ly, (long) lm, (long) ld); - DatefromJulianDay (tmp, &lyl, &lml, &ldl); - } - if (ll >= 1000.0) { - double ad, ah, am, as; - ad = floor(ll / 86400000); - ll = ll - ad * 86400000; - ah = floor(ll /3600000); - ll = ll - ah * 3600000; - am = floor(ll / 60000); - ll = ll - am * 60000; - as = floor(ll / 1000); - ll = ll - as * 1000; - ld += ad; - lh += ah; - ln += am; - ls += as; - tmp = JulianDay12h ((long) ly, (long) lm, (long) ld); - DatefromJulianDay (tmp, &lyl, &lml, &ldl); - } - if (ls >= 60.0) { - tmp = JulianDay12h ((long) ly, (long) lm, (long) ld); - DatefromJulianDay (tmp+1, &xy, &xm, &xd); - toPlus = LeapSecondsfromYMD(xy,xm,xd) - LeapSecondsfromYMD(ly,lm,ld); - toPlus = floor(toPlus); - if (ls >= (60.0+toPlus)) { - double ad, ah, am; - ad = floor(ls / (86400+toPlus)); - ls = ls - ad * (86400+toPlus); - ah = floor(ls /(3600+toPlus)); - ls = ls - ah * (3600+toPlus); - am = floor(ls / (60+toPlus)); - ls = ls - am * (60+toPlus); - ld += ad; - lh += ah; - ln += am; - tmp = JulianDay12h ((long) ly, (long) lm, (long) ld); - DatefromJulianDay (tmp, &lyl, &lml, &ldl); - } - } - if (ln >= 60.0) { - double ad, ah; - ad = floor(ln / 1440); - ln = ln - (ad * 1440); - ah = floor(ln / 60); - ln = ln - ah * 60; - ld += ad; - lh += ah; - tmp = JulianDay12h ((long) ly, (long) lm, (long) ld); - DatefromJulianDay (tmp, &lyl, &lml, &ldl); - } - if (lh >= 24.0) { - double ad; - ad = floor(lh / 24.0); - lh = lh - ad * 24.0; - ld += ad; - tmp = JulianDay12h ((long) ly, (long) lm, (long) ld); - DatefromJulianDay (tmp, &lyl, &lml, &ldl); - } - if (lyl == -999 && lml == -999) { - lyl = (long) ly; - lml = (long) lm; - ldl = (long) ld; - } - lhl = (long) lh; - lnl = (long) ln; - lsl = (long) ls; - lll = (long) ll; - lul = (long) lu; - lal = (long) la; - if (lyl == 9999 && lml == 12 && ldl == 31 && lhl == 23 && lnl == 59 && - lsl == 59 && lll == 999 && lul == 999 && lal == 999) - return FILLED_TT2000_VALUE; - else if (lyl == 0 && lml == 1 && ldl == 1 && lhl == 0 && lnl == 0 && - lsl == 0 && lll == 0 && lul == 0 && lal == 0) - return DEFAULT_TT2000_PADVALUE; - if (!YearWithin(lyl) && !ValidateYMD(lyl,lml,ldl)) - return ILLEGAL_TT2000_VALUE; - lyear = (lyl & 3) == 0 && ((lyl % 25) != 0 || (lyl & 15) == 0); - if ((!lyear && ldl > 365) || (lyear && ldl > 366)) - return ILLEGAL_TT2000_VALUE; - if ((!lyear && lml > 1 && ldl > daym1[(int)lml-1]) || - (lyear && lml > 1 && ldl > daym2[(int)lml-1])) - return ILLEGAL_TT2000_VALUE; - if (lml <= 1 && ldl > 31) { - /* DOY is passed in. */ - int ix; - if (lml == 0) lml = 1; - for (ix = 0; ix < 12; ++ix) { - if ((!lyear && ldl <= doys1[ix]) || (lyear && ldl <= doys2[ix])) { - if (ix == 0) break; - else { - lml = ix + 1; - if (!lyear) ldl = ldl - doys1[ix-1]; - else ldl = ldl - doys2[ix-1]; - break; - } - } - } - } - iy = 10000000 * lml + 10000 * ldl + lyl; - if (iy != currentDay) { - currentDay = iy; - currentLeapSeconds = LeapSecondsfromYMD(lyl, lml, ldl); - currentJDay = JulianDay12h(lyl,lml,ldl); - } - jd = currentJDay; - jd = jd - JulianDateJ2000_12h; - subDayinNanoSecs = lhl * HOURinNanoSecs + lnl * MINUTEinNanoSecs + - lsl * SECinNanoSecs + lll * 1000000 + lul * 1000 + lal; - nanoSecSinceJ2000 = (long long) jd * DAYinNanoSecs + subDayinNanoSecs; - t2 = (long long) (currentLeapSeconds * SECinNanoSecs); - if (nanoSecSinceJ2000 < 0) { - nanoSecSinceJ2000 += t2; - nanoSecSinceJ2000 += dTinNanoSecs; - nanoSecSinceJ2000 -= T12hinNanoSecs; - } else { - nanoSecSinceJ2000 -= T12hinNanoSecs; - nanoSecSinceJ2000 += t2; - nanoSecSinceJ2000 += dTinNanoSecs; - } - return nanoSecSinceJ2000; -} - -/****************************************************************************** -* CDF_TT2000_to_UTC_EPOCH. -******************************************************************************/ - -VISIBLE_PREFIX double CDF_TT2000_to_UTC_EPOCH (long long nanoSecSinceJ2000) -{ - double yy, mm, dd, hh, nn, ss, ll, uu, aa; - double epoch; - if (nanoSecSinceJ2000 == FILLED_TT2000_VALUE) return -1.0E31; - else if (nanoSecSinceJ2000 == DEFAULT_TT2000_PADVALUE || - nanoSecSinceJ2000 == ILLEGAL_TT2000_VALUE) return 0.0; - CDF_TT2000_to_UTC_parts (nanoSecSinceJ2000, &yy, &mm, &dd, &hh, &nn, &ss, - &ll, &uu, &aa); - epoch = computeEPOCH ((long)yy, (long)mm, (long)dd, (long)hh, (long)nn, - (long)ss, (long)ll); - return epoch; -} - -/****************************************************************************** -* CDF_TT2000_from_UTC_EPOCH. -******************************************************************************/ - -VISIBLE_PREFIX long long CDF_TT2000_from_UTC_EPOCH (double epoch) -{ - long yy, mm, dd, hh, nn, ss, ll; - if (epoch == -1.0E31 || epoch == -1.0E-31) - return FILLED_TT2000_VALUE; - if (epoch == 0.0 || NegativeZeroReal8 (&epoch)) - return DEFAULT_TT2000_PADVALUE; - EPOCHbreakdown (epoch, &yy, &mm, &dd, &hh, &nn, &ss, &ll); - if (!YearWithin(yy) && !ValidateYMD(yy,mm,dd)) return ILLEGAL_TT2000_VALUE; - return CDF_TT2000_from_UTC_parts ((double)yy, (double)mm, (double)dd, - (double)hh, (double)nn, (double)ss, - (double)ll, 0.0, 0.0); -} - -/****************************************************************************** -* CDF_TT2000_to_UTC_EPOCH16. -******************************************************************************/ - -VISIBLE_PREFIX double CDF_TT2000_to_UTC_EPOCH16 (long long nanoSecSinceJ2000, - double *epoch) -{ - double yy, mm, dd, hh, nn, ss, ll, uu, aa; - double tmp; - if (nanoSecSinceJ2000 == FILLED_TT2000_VALUE) { - *epoch = -1.0E31; - *(epoch+1) = -1.0E31; - return 0.0; - } - else if (nanoSecSinceJ2000 == DEFAULT_TT2000_PADVALUE || - nanoSecSinceJ2000 == ILLEGAL_TT2000_VALUE) { - *epoch = 0.0; - *(epoch+1) = 0.0; - return 0.0; - } - CDF_TT2000_to_UTC_parts (nanoSecSinceJ2000, &yy, &mm, &dd, &hh, &nn, &ss, - &ll, &uu, &aa); - tmp = computeEPOCH16 ((long)yy, (long)mm, (long)dd, (long)hh, (long)nn, - (long)ss, (long)ll, (long)uu, (long)aa, 0, epoch); - return tmp; -} - -/****************************************************************************** -* CDF_TT2000_from_UTC_EPOCH16. -******************************************************************************/ - -VISIBLE_PREFIX long long CDF_TT2000_from_UTC_EPOCH16 (double *epoch) -{ - long yy, mm, dd, hh, nn, ss, ll, uu, aa, pp; - if (epoch[0] == 0.0 && epoch[1] == 0.0) return DEFAULT_TT2000_PADVALUE; - if (NegativeZeroReal8 (&(epoch[0])) && NegativeZeroReal8 (&(epoch[1]))) - return DEFAULT_TT2000_PADVALUE; - if (epoch[0] == -1.0E31 && epoch[1] == -1.0E31) return FILLED_TT2000_VALUE; - if (epoch[0] == -1.0E-31 && epoch[1] == -1.0E-31) return FILLED_TT2000_VALUE; - EPOCH16breakdown (epoch, &yy, &mm, &dd, &hh, &nn, &ss, &ll, &uu, &aa, &pp); - if (!YearWithin(yy) && !ValidateYMD(yy,mm,dd)) return ILLEGAL_TT2000_VALUE; - return CDF_TT2000_from_UTC_parts ((double)yy, (double)mm, (double)dd, - (double)hh, (double)nn, (double)ss, - (double)ll, (double)uu, (double)aa); -} - -/****************************************************************************** -* CDF_TT2000_to_UTC_string. -******************************************************************************/ - -#if defined(STDARG) -VISIBLE_PREFIX void CDF_TT2000_to_UTC_string (long long nanoSecSinceJ2000, - char *string, ...) -#else -VISIBLE_PREFIX void CDF_TT2000_to_UTC_string (long long nanoSecSinceJ2000, - char *string, va_alist) -va_dcl -#endif -{ - long ly, lm, ld, lh, ln, ls, ll, lu, la; - double lyd, lmd, ldd, lhd, lnd, lsd, lld, lud, lad; - int format; - va_list Va; -#if defined(STDARG) - va_start (Va, string); -#else - VA_START (Va); -#endif - format = va_arg (Va, int); - if (format < 0 || format > 3) format = 3; - va_end (Va); - if (nanoSecSinceJ2000 == FILLED_TT2000_VALUE) { - if (format == 0) { - strncpy(string, "31-DEC-9999 23:59:59.999999999", 30); - string[30] = '\0'; - } else if (format == 1) { - strncpy(string, "99991231.9999999999", 19); - string[19] = '\0'; - } else if (format == 2) { - strncpy(string, "99991231235959", 14); - string[14] = '\0'; - } else { - strncpy(string, "9999-12-31T23:59:59.999999999", 29); - string[29] = '\0'; - } - return; - } else if (nanoSecSinceJ2000 == DEFAULT_TT2000_PADVALUE) { - if (format == 0) { - strncpy(string, "01-JAN-0000 00:00:00.000000000", 30); - string[30] = '\0'; - } else if (format == 1) { - strncpy(string, "00000101.0000000000", 19); - string[19] = '\0'; - } else if (format == 2) { - strncpy(string, "00000101000000", 14); - string[14] = '\0'; - } else { - strncpy(string, "0000-01-01T00:00:00.000000000", 29); - string[29] = '\0'; - } - return; - } - CDF_TT2000_to_UTC_parts(nanoSecSinceJ2000, &lyd, &lmd, &ldd, &lhd, &lnd, - &lsd, &lld, &lud, &lad); - ly = (long) lyd; - lm = (long) lmd; - ld = (long) ldd; - lh = (long) lhd; - ln = (long) lnd; - ls = (long) lsd; - ll = (long) lld; - lu = (long) lud; - la = (long) lad; - if (format == 0) { - snprintf(string, (size_t) TT2000_0_STRING_LEN+1, - "%2.2ld-%s-%4.4ld %2.2ld:%2.2ld:%2.2ld.%3.3ld%3.3ld%3.3ld", - ld,MonthToken(lm),ly,lh,ln,ls,ll,lu,la); - } else if (format == 1) { - long milsecs, nansecs; - double subday; - long long subdayll; - milsecs = 3600000 * lh + 60000 * ln + 1000 * ls + ll; - nansecs = 1000 * lu + la; - subday = (1000000.0 * (double) milsecs + nansecs) - / (86400.0 * SECinNanoSecsD); - subdayll = (long long) (subday * pow (10.0, 10)); - snprintf(string, (size_t) TT2000_1_STRING_LEN+1, - "%4.4ld%2.2ld%2.2ld.%10.10lld", ly,lm,ld,subdayll); - } else if (format == 2) { - snprintf(string, (size_t) TT2000_2_STRING_LEN+1, - "%4.4ld%2.2ld%2.2ld%2.2ld%2.2ld%2.2ld",ly,lm,ld,lh,ln,ls); - } else if (format == 3) { - snprintf(string, (size_t) TT2000_3_STRING_LEN+1, - "%4.4ld-%2.2ld-%2.2ldT%2.2ld:%2.2ld:%2.2ld.%3.3ld%3.3ld%3.3ld", - ly,lm,ld,lh,ln,ls,ll,lu,la); - } -} - -/****************************************************************************** -* CDF_TT2000_from_UTC_string. -******************************************************************************/ - -VISIBLE_PREFIX long long CDF_TT2000_from_UTC_string (char *string) -{ - double fraction; - long ly, lm, ld, lh, ln, ls, ll, lu, la; - int len, format; - - while (string[0] == ' ') memmove (string, &string[1], strlen(string)); - format = ScanUTCstring(string); - if (format == 0) { - char moString[4]; - long tmp; - if (sscanf(string,"%2ld-%c%c%c-%4ld %2ld:%2ld:%2ld.%9ld", - &ld, &(moString[0]), &(moString[1]), &(moString[2]), &ly, - &lh, &ln, &ls, &tmp) != 9) return ILLEGAL_TT2000_VALUE; - moString[3] = '\0'; - lm = (long) MonthNumber(moString); - if (ly == 9999 && lm == 12 && ld == 31 && lh == 23 && ln == 59 && - ls == 59 && tmp == 999999999) - return FILLED_TT2000_VALUE; - else if (ly == 0 && lm == 1 && ld == 1 && lh == 0 && ln == 0 && - ls == 0 && tmp == 0) - return DEFAULT_TT2000_PADVALUE; - if (tmp == 0) { - ll = lu = la = 0; - } else { - char *dot = strrchr (string, '.'); - if (dot == NULL) { - ll = lu = la = 0; - } else { - len = (int) strlen (dot + 1); - if (len < 9) tmp = tmp * pow (10.0, 9-len); - ll = (long) (tmp / 1000000); - tmp = tmp - ll * 1000000; - lu = (long) (tmp / 1000); - la = (long) (tmp - lu * 1000); - } - } - if (!YearWithin(ly) && !ValidateYMD(ly,lm,ld)) return ILLEGAL_TT2000_VALUE; - return CDF_TT2000_from_UTC_parts ((double) ly, (double) lm, (double) ld, - (double) lh, (double) ln, (double) ls, - (double) ll, (double) lu, (double) la); - } else if (format == 1) { - long long tmp; - if (sscanf(string,"%4ld%2ld%2ld.%lld", - &ly, &lm, &ld, &tmp) != 4) return ILLEGAL_TT2000_VALUE; - if (tmp == 0) - fraction = 0.0; - else { - char *dot = strrchr (string, '.'); - len = (int) strlen (dot + 1); - fraction = tmp / pow(10.0, len); - } - if (ly == 9999 && lm == 12 && ld == 31 && tmp == 9999999999LL) - return FILLED_TT2000_VALUE; - else if (ly == 0 && lm == 1 && ld == 1 && tmp == 0) - return DEFAULT_TT2000_PADVALUE; - if (!YearWithin(ly) && !ValidateYMD(ly,lm,ld)) return ILLEGAL_TT2000_VALUE; - return CDF_TT2000_from_UTC_parts ((double) ly, (double) lm, (double) ld, - fraction, TT2000END); - } else if (format == 2) { - if (sscanf(string,"%4ld%2ld%2ld%2ld%2ld%2ld", - &ly, &lm, &ld, &lh, &ln, &ls) != 6) return ILLEGAL_TT2000_VALUE; - if (ly == 9999 && lm == 12 && ld == 31 && lh == 23 && ln == 59 && - ls == 59) return FILLED_TT2000_VALUE; - else if (ly == 0 && lm == 1 && ld == 1 && lh == 0 && ln == 0 && - ls == 0) return DEFAULT_TT2000_PADVALUE; - if (!YearWithin(ly) && !ValidateYMD(ly,lm,ld)) return ILLEGAL_TT2000_VALUE; - return CDF_TT2000_from_UTC_parts ((double) ly, (double) lm, (double) ld, - (double) lh, (double) ln, (double) ls, - 0.0, 0.0, 0.0); - } else if (format == 3) { - long tmp; - if (sscanf(string,"%4ld-%2ld-%2ldT%2ld:%2ld:%2ld.%9ld", - &ly, &lm, &ld, &lh, &ln, &ls, &tmp) != 7) return ILLEGAL_TT2000_VALUE; - if (ly == 9999 && lm == 12 && ld == 31 && lh == 23 && ln == 59 && - ls == 59 && tmp == 999999999) - return FILLED_TT2000_VALUE; - else if (ly == 0 && lm == 1 && ld == 1 && lh == 0 && ln == 0 && - ls == 0 && tmp == 0) - return DEFAULT_TT2000_PADVALUE; - if (tmp == 0) { - ll = lu = la = 0; - } else { - char *dot = strrchr (string, '.'); - len = (int) strlen (dot+1); - if (len < 9) tmp = tmp * pow (10.0, 9-len); - ll = (long) (tmp / 1000000); - tmp = tmp - ll * 1000000; - lu = (long) (tmp / 1000); - la = (long) (tmp - lu * 1000); - } - if (!YearWithin(ly) && !ValidateYMD(ly,lm,ld)) return ILLEGAL_TT2000_VALUE; - return CDF_TT2000_from_UTC_parts ((double) ly, (double) lm, (double) ld, - (double) lh, (double) ln, (double) ls, - (double) ll, (double) lu, (double) la); - } else - return ILLEGAL_TT2000_VALUE; -} - -/****************************************************************************** -* AddOpenCDFCount. -******************************************************************************/ - -VISIBLE_PREFIX void AddOpenCDFsCount () -{ - ++openCDF64s; -} - -/****************************************************************************** -* ReduceOpenCDFCount. -******************************************************************************/ - -VISIBLE_PREFIX void ReduceOpenCDFsCount () -{ - --openCDF64s; - if (openCDF64s == 0) CDFClearLeapSecondsTable(); -} - -/****************************************************************************** -* ValidateTT2000. -* Returns 1 if the TT2000 data is determined to be created properly based on -* the info from the currently used leap second table, e.g., prior-to 2015/07/01 -* or leap second last updated being equal to the last entry in the table, or -* the TT2000 time is within the next new leap second date. -* It returns -1 if TT2000 time (based on an older leap second table) is after -* a date that a new leap second was added. Or, the leap second table used by -* the TT2000 time is even newer than the one currently being used. This is -* considered a bad data or case. -* It returns 0 as we can't tell if the time is good. It's using pre-3.6.0 code -* with the latest leap second table, which is good. But -* using the older table, which can be bad after 2017-01-01). -******************************************************************************/ - -VISIBLE_PREFIX int ValidateTT2000 (int yyyymmdd, - int leapSecondLastUpdated) -{ - int i, last, lastDate; - if (yyyymmdd < LASTLEAPSECONDDAY) return 1; - if (LTD == NULL) LoadLeapSecondsTable (); - last = entryCnt - 1; - lastDate = (int) (10000*LTD[last][0] + 100*LTD[last][1] + LTD[last][2]); - if (leapSecondLastUpdated == lastDate) return 1; - if (leapSecondLastUpdated > 0) { - if (yyyymmdd < leapSecondLastUpdated) return 1; - if (lastDate > leapSecondLastUpdated) { - for (i = last-1; i >= 0; --i) { - if (leapSecondLastUpdated == (int) (10000*LTD[i][0] + 100*LTD[i][1] + - LTD[i][2])) { - if (yyyymmdd < (int) (10000*LTD[i+1][0] + 100*LTD[i+1][1] + - LTD[i+1][2])) return 1; - else return -1; - } - } - return -1; - } else - return -1; - } - return 0; -} - -/****************************************************************************** -* ValidateLeapSecondLastUpdated. -* Returns 1 if the passed date, in YYYYMMDD, is in the leap second table. -* Otherwise, 0. -******************************************************************************/ - -VISIBLE_PREFIX int ValidateLeapSecondLastUpdated (int leapSecondLastUpdated) -{ - int i, last; - if (LTD == NULL) LoadLeapSecondsTable (); - last = entryCnt - 1; - for (i = last; i >= 0; --i) { - if (leapSecondLastUpdated == (int) (10000*LTD[i][0] + 100*LTD[i][1] + - LTD[i][2])) return 1; - if ((i < (last - 1)) && - (leapSecondLastUpdated > (int) (10000*LTD[i+1][0] + 100*LTD[i+1][1] + - LTD[i+1][2]))) return 0; - } - return 0; -} - -/****************************************************************************** -* LeapSecondLastUpdatedinTable. -* Returns the index in the leap second table (LST) for the passed leap second -* last updated day (in YYYYMMDD). If the day is not in the LST, the nearest -* index from the table is returned, which has the day less than the passed -* day. -******************************************************************************/ - -static int LeapSecondLastUpdatedinTable (int leapSecondLastUpdated) -{ - int i, last; - if (LTD == NULL) LoadLeapSecondsTable (); - last = entryCnt - 1; - for (i = last; i >= 0; --i) { - if (leapSecondLastUpdated >= (int) (10000*LTD[i][0] + 100*LTD[i][1] + - LTD[i][2])) return i; - } - return 0; -} - -static void FromUTCISO8601string (char *string, long *ly, long *lm, long *ld, - long *lh, long *ln, long *ls, - long *ll, long *lu, long *la) -{ - int format, len; - char *dot; - - format = ScanUTCstring(string); - if (format == 3) { /* %4ld-%2ld-%2ldT%2ld:%2ld:%2ld.%9ld */ - long tmp; - *ly = *lm = *ld = *lh = *ln = *ls = *ll = *lu = *la = 0L; - if (sscanf(string,"%4ld-%2ld-%2ldT%2ld:%2ld:%2ld.%9ld", - ly, lm, ld, lh, ln, ls, &tmp) != 7) return; - dot = strrchr (string, '.'); - len = (int) strlen (dot+1); - if (len < 9) tmp = tmp * (long) pow (10.0, 9-len); - *ll = (long) (tmp / 1000000L); - tmp = tmp - *ll * 1000000L; - *lu = (long) (tmp / 1000L); - *la = (long) (tmp - *lu * 1000L); - } -} - - diff --git a/cdf36_3-dist/src/lib/cdftt2000f.c b/cdf36_3-dist/src/lib/cdftt2000f.c deleted file mode 100644 index 741ff9f..0000000 --- a/cdf36_3-dist/src/lib/cdftt2000f.c +++ /dev/null @@ -1,627 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* SPDF/CDF CDF_TIME_TT2000 utility routines for C. -* -* Version 1.0, 15-Mar-11, ADNET systems -* -* Modification history: -* -* V1.0 15-Mar-11, M Liu Initial version (for CDF V3.3.2) -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* breakdown_TT2000 (FORTRAN equivalent of CDF_TT2000_to_UTC_parts). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(breakdown_tt2000__, - breakdown_tt2000_, - breakdown_tt2000, - BREAKDOWN_TT2000) -(nanoSecSinceJ2000, ly, lm, ld, lh, ln, ls, ll, lu, lx) -long long *nanoSecSinceJ2000; -int *ly; -int *lm; -int *ld; -int *lh; -int *ln; -int *ls; -int *ll; -int *lu; -int *lx; -{ - double ly1, lm1, ld1, lh1, ln1, ls1, ll1, lu1, lx1; - CDF_TT2000_to_UTC_parts (*nanoSecSinceJ2000, &ly1, &lm1, &ld1, - &lh1, &ln1, &ls1, &ll1, &lu1, &lx1); - *ly = (int) ly1; - *lm = (int) lm1; - *ld = (int) ld1; - *lh = (int) lh1; - *ln = (int) ln1; - *ls = (int) ls1; - *ll = (int) ll1; - *lu = (int) lu1; - *lx = (int) lx1; -} - -/****************************************************************************** -* breakdown_TT2000 (FORTRAN equivalent of CDF_TT2000_to_UTC_parts). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(tt2000_breakdown__, - tt2000_breakdown_, - tt2000_breakdown, - TT2000_BREAKDOWN) -(nanoSecSinceJ2000, ly, lm, ld, lh, ln, ls, ll, lu, lx) -long long *nanoSecSinceJ2000; -int *ly; -int *lm; -int *ld; -int *lh; -int *ln; -int *ls; -int *ll; -int *lu; -int *lx; -{ - double ly1, lm1, ld1, lh1, ln1, ls1, ll1, lu1, lx1; - CDF_TT2000_to_UTC_parts (*nanoSecSinceJ2000, &ly1, &lm1, &ld1, - &lh1, &ln1, &ls1, &ll1, &lu1, &lx1); - *ly = (int) ly1; - *lm = (int) lm1; - *ld = (int) ld1; - *lh = (int) lh1; - *ln = (int) ln1; - *ls = (int) ls1; - *ll = (int) ll1; - *lu = (int) lu1; - *lx = (int) lx1; -} - -/****************************************************************************** -* CDF_TT2000_to_UTC_parts_f (FORTRAN equivalent of CDF_TT2000_to_UTC_parts). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_tt2000_to_utc_parts_f__, - cdf_tt2000_to_utc_parts_f_, - cdf_tt2000_to_utc_parts_f, - CDF_TT2000_TO_UTC_PARTS_F) -(nanoSecSinceJ2000, ly, lm, ld, lh, ln, ls, ll, lu, lx) -long long *nanoSecSinceJ2000; -int *ly; -int *lm; -int *ld; -int *lh; -int *ln; -int *ls; -int *ll; -int *lu; -int *lx; -{ - double ly1, lm1, ld1, lh1, ln1, ls1, ll1, lu1, lx1; - CDF_TT2000_to_UTC_parts (*nanoSecSinceJ2000, &ly1, &lm1, &ld1, - &lh1, &ln1, &ls1, &ll1, &lu1, &lx1); - *ly = (int) ly1; - *lm = (int) lm1; - *ld = (int) ld1; - *lh = (int) lh1; - *ln = (int) ln1; - *ls = (int) ls1; - *ll = (int) ll1; - *lu = (int) lu1; - *lx = (int) lx1; -} - -/****************************************************************************** -* compute_TT2000 (FORTRAN equivalent of CDF_TT2000_from_UTC_parts). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(compute_tt2000__, - compute_tt2000_, - compute_tt2000, - COMPUTE_TT2000) -(ly, lm, ld, lh, ln, ls, ll, lu, la, nanoSecSinceJ2000) -int *ly; -int *lm; -int *ld; -int *lh; -int *ln; -int *ls; -int *ll; -int *lu; -int *la; -long long *nanoSecSinceJ2000; -{ - *nanoSecSinceJ2000 = CDF_TT2000_from_UTC_parts ((double)*ly, (double)*lm, - (double)*ld, (double)*lh, - (double)*ln, (double)*ls, - (double)*ll, (double)*lu, - (double)*la); -} - -/****************************************************************************** -* CDF_TT2000_from_UTC_parts_f (FORTRAN equivalent of -* CDF_TT2000_from_UTC_parts). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_tt2000_from_utc_parts_f__, - cdf_tt2000_from_utc_parts_f_, - cdf_tt2000_from_utc_parts_f, - CDF_TT2000_FROM_UTC_PARTS_F) -(ly, lm, ld, lh, ln, ls, ll, lu, la, nanoSecSinceJ2000) -int *ly; -int *lm; -int *ld; -int *lh; -int *ln; -int *ls; -int *ll; -int *lu; -int *la; -long long *nanoSecSinceJ2000; -{ - *nanoSecSinceJ2000 = CDF_TT2000_from_UTC_parts ((double)*ly, (double)*lm, - (double)*ld, (double)*lh, - (double)*ln, (double)*ls, - (double)*ll, (double)*lu, - (double)*la); -} - -/****************************************************************************** -* TT2000_to_EPOCH (FORTRAN equivalent of CDF_TT2000_to_UTC_EPOCH). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(tt2000_to_epoch__, - tt2000_to_epoch_, - tt2000_to_epoch, - TT2000_TO_EPOCH) -(nanoSecSinceJ2000, epoch) -long long *nanoSecSinceJ2000; -double *epoch; -{ - *epoch = CDF_TT2000_to_UTC_EPOCH (*nanoSecSinceJ2000); -} - -/****************************************************************************** -* CDF_TT2000_to_UTC_EPOCH_f (FORTRAN equivalent of CDF_TT2000_to_UTC_EPOCH). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_tt2000_to_utc_epoch_f__, - cdf_tt2000_to_utc_epoch_f_, - cdf_tt2000_to_utc_epoch_f, - CDF_TT2000_TO_UTC_EPOCH_F) -(nanoSecSinceJ2000, epoch) -long long *nanoSecSinceJ2000; -double *epoch; -{ - *epoch = CDF_TT2000_to_UTC_EPOCH (*nanoSecSinceJ2000); -} - -/****************************************************************************** -* TT2000_from_EPOCH (FORTRAN equivalent of CDF_TT2000_from_UTC_EPOCH). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(tt2000_from_epoch__, - tt2000_from_epoch_, - tt2000_from_epoch, - TT2000_FROM_EPOCH) -(epoch, nanoSecSinceJ2000) -double *epoch; -long long *nanoSecSinceJ2000; -{ - *nanoSecSinceJ2000 = CDF_TT2000_from_UTC_EPOCH (*epoch); -} - -/****************************************************************************** -* CDF_TT2000_from_UTC_EPOCH_f (FORTRAN equivalent of CDF_TT2000_from_UTC_EPOCH). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_tt2000_from_utc_epoch_f__, - cdf_tt2000_from_utc_epoch_f_, - cdf_tt2000_from_utc_epoch_f, - CDF_TT2000_FROM_UTC_EPOCH_F) -(epoch, nanoSecSinceJ2000) -double *epoch; -long long *nanoSecSinceJ2000; -{ - *nanoSecSinceJ2000 = CDF_TT2000_from_UTC_EPOCH (*epoch); -} - -/****************************************************************************** -* TT2000_to_EPOCH16 (FORTRAN equivalent of CDF_TT2000_to_UTC_EPOCH16). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(tt2000_to_epoch16__, - tt2000_to_epoch16_, - tt2000_to_epoch16, - TT2000_TO_EPOCH16) -(nanoSecSinceJ2000, epoch16) -long long *nanoSecSinceJ2000; -double *epoch16; -{ - CDF_TT2000_to_UTC_EPOCH16 (*nanoSecSinceJ2000, epoch16); -} - -/****************************************************************************** -* CDF_TT2000_to_UTC_EPOCH16_f (FORTRAN equivalent of -* CDF_TT2000_to_UTC_EPOCH16). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_tt2000_to_utc_epoch16_f__, - cdf_tt2000_to_utc_epoch16_f_, - cdf_tt2000_to_utc_epoch16_f, - CDF_TT2000_TO_UTC_EPOCH16_F) -(nanoSecSinceJ2000, epoch16) -long long *nanoSecSinceJ2000; -double *epoch16; -{ - CDF_TT2000_to_UTC_EPOCH16 (*nanoSecSinceJ2000, epoch16); -} - -/****************************************************************************** -* TT2000_from_EPOCH16 (FORTRAN equivalent of CDF_TT2000_from_UTC_EPOCH16). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(tt2000_from_epoch16__, - tt2000_from_epoch16_, - tt2000_from_epoch16, - TT2000_FROM_EPOCH16) -(epoch16, nanoSecSinceJ2000) -double *epoch16; -long long *nanoSecSinceJ2000; -{ - *nanoSecSinceJ2000 = CDF_TT2000_from_UTC_EPOCH16 (epoch16); -} - -/****************************************************************************** -* CDF_TT2000_from_UTC_EPOCH16_f (FORTRAN equivalent of -* CDF_TT2000_from_UTC_EPOCH16). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_tt2000_from_utc_epoch16_f__, - cdf_tt2000_from_utc_epoch16_f_, - cdf_tt2000_from_utc_epoch16_f, - CDF_TT2000_FROM_UTC_EPOCH16_F) -(epoch16, nanoSecSinceJ2000) -double *epoch16; -long long *nanoSecSinceJ2000; -{ - *nanoSecSinceJ2000 = CDF_TT2000_from_UTC_EPOCH16 (epoch16); -} - - -/****************************************************************************** -* encode_TT2000 (FORTRAN equivalent of CDF_TT2000_to_UTC_string). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(encode_tt2000__, - encode_tt2000_, - encode_tt2000, - ENCODE_TT2000) -(nanoSecSinceJ2000, format, string Fif_GHOSTARG(string_len)) -long long *nanoSecSinceJ2000; -int *format; -void *string; -Fif_GHOSTDEF(string_len) -{ - char tString[TT2000_0_STRING_LEN+1]; - int len = -1; - if (*format == 3) len = TT2000_3_STRING_LEN; - else if (*format == 0) len = TT2000_0_STRING_LEN; - else if (*format == 1) len = TT2000_1_STRING_LEN; - else if (*format == 2) len = TT2000_2_STRING_LEN; - if (len != -1) { - CDF_TT2000_to_UTC_string (*nanoSecSinceJ2000, tString, *format); -#if defined(Fif_GHOSTLEN) - CtoFORTstring (tString, string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (tString, string, len); -#endif - } else { -#if defined(Fif_GHOSTLEN) - CtoFORTstring (" ", string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (" ", string, 1); -#endif - } -} - -/****************************************************************************** -* CDF_TT2000_to_UTC_string_f (FORTRAN equivalent of CDF_TT2000_to_UTC_string). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_tt2000_to_utc_string_f__, - cdf_tt2000_to_utc_string_f_, - cdf_tt2000_to_utc_string_f, - CDF_TT2000_TO_UTC_STRING_F) -(nanoSecSinceJ2000, format, string Fif_GHOSTARG(string_len)) -long long *nanoSecSinceJ2000; -int *format; -void *string; -Fif_GHOSTDEF(string_len) -{ - char tString[TT2000_0_STRING_LEN+1]; - int len = -1; - if (*format == 3) len = TT2000_3_STRING_LEN; - else if (*format == 0) len = TT2000_0_STRING_LEN; - else if (*format == 1) len = TT2000_1_STRING_LEN; - else if (*format == 2) len = TT2000_2_STRING_LEN; - if (len != -1) { - CDF_TT2000_to_UTC_string (*nanoSecSinceJ2000, tString, *format); -#if defined(Fif_GHOSTLEN) - CtoFORTstring (tString, string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (tString, string, len); -#endif - } else { -#if defined(Fif_GHOSTLEN) - CtoFORTstring (" ", string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (" ", string, 1); -#endif - } -} - -/****************************************************************************** -* parse_TT2000 (FORTRAN equivalent of CDF_TT2000_from_UTC_string). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(parse_tt2000__, - parse_tt2000_, - parse_tt2000, - PARSE_TT2000) -(string, tt2000 Fif_GHOSTARG(string_len)) -char *string; -long long *tt2000; -Fif_GHOSTDEF(string_len) -{ - struct STRINGstruct *ssh = NULL; - size_t len = strlen(string)+1; -#if defined(Fif_DESCR) - *tt2000 = CDF_TT2000_from_UTC_string (DESCRtoREFnul(string,len,&ssh)); -#endif -#if defined(Fif_GHOSTLEN) - *tt2000 = CDF_TT2000_from_UTC_string (NULterminate(string,Fif_GHOSTUSE(string_len),&ssh)); -#endif -#if defined(Fif_NOLEN) - *tt2000 = CDF_TT2000_from_UTC_string (FindEndNUL(string,len,&ssh)); -#endif - FreeStrings (ssh); -} - -/****************************************************************************** -* CDF_TT2000_from_UTC_string_f (FORTRAN equivalent of -* CDF_TT2000_from_UTC_string). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_tt2000_from_utc_string_f__, - cdf_tt2000_from_utc_string_f_, - cdf_tt2000_from_utc_string_f, - CDF_TT2000_FROM_UTC_STRING_F) -(string, tt2000 Fif_GHOSTARG(string_len)) -char *string; -long long *tt2000; -Fif_GHOSTDEF(string_len) -{ - struct STRINGstruct *ssh = NULL; - size_t len = strlen(string)+1; -#if defined(Fif_DESCR) - *tt2000 = CDF_TT2000_from_UTC_string (DESCRtoREFnul(string,len,&ssh)); -#endif -#if defined(Fif_GHOSTLEN) - *tt2000 = CDF_TT2000_from_UTC_string (NULterminate(string,Fif_GHOSTUSE(string_len),&ssh)); -#endif -#if defined(Fif_NOLEN) - *tt2000 = CDF_TT2000_from_UTC_string (FindEndNUL(string,len,&ssh)); -#endif - FreeStrings (ssh); -} - -/****************************************************************************** -* CDF_getLeapSecondsTableEnvVar (FORTRAN equivalent of -* CDFgetLeapSecondsTableEnvVar). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_getleapsecondstableenvvar__, - cdf_getleapsecondstableenvvar_, - cdf_getleapsecondstableenvvar, - CDF_GETLEAPSECONDSTABLEENVVAR) -(string Fif_GHOSTARG(string_len)) -char *string; -Fif_GHOSTDEF(string_len) -{ - char *table = CDFgetLeapSecondsTableEnvVar(); - if (table != NULL) { -#if defined(Fif_GHOSTLEN) - CtoFORTstring (table, string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (table, string, CDF_PATHNAME_LEN); -#endif - } else - string[0] = (char) '\0'; -} - -/****************************************************************************** -* CDF_getLastDateinLeapSecondsTable (FORTRAN equivalent of -* CDFgetLastDateinLeapSecondsTable). -******************************************************************************/ -#if defined(vms) -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_getlastdateinleapsectable__, - cdf_getlastdateinleapsectable_, - cdf_getlastdateinleapsectable, - CDF_GETLASTDATEINLEAPSECTABLE) -#else -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_getlastdateinleapsecondstable__, - cdf_getlastdateinleapsecondstable_, - cdf_getlastdateinleapsecondstable, - CDF_GETLASTDATEINLEAPSECONDSTABLE) -#endif -(year, month, day) -Int32 *year; -Int32 *month; -Int32 *day; -{ - long yy, mm, dd; -#if defined(vms) - CDFgetLastDateinLeapSecondsTBL (&yy, &mm, &dd); -#else - CDFgetLastDateinLeapSecondsTable (&yy, &mm, &dd); -#endif - *year = (Int32) yy; - *month = (Int32) mm; - *day = (Int32) dd; -} - -/****************************************************************************** -* CDF_getLeapSecondsTableStatus (FORTRAN equivalent of -* CDFgetLeapSecondsTableStatus). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_getleapsecondstablestatus__, - cdf_getleapsecondstablestatus_, - cdf_getleapsecondstablestatus, - CDF_GETLEAPSECONDSTABLESTATUS) -() -{ - return (Int32) CDFgetLeapSecondsTableStatus (); -} - -/****************************************************************************** -* CDF_getRowsinLeapSecondsTable (FORTRAN equivalent of -* CDFgetRowsinLeapSecondsTable). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -Int32 -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_getrowsinleapsecondstable__, - cdf_getrowsinleapsecondstable_, - cdf_getrowsinleapsecondstable, - CDF_GETROWSINLEAPSECONDSTABLE) -() -{ - return (Int32) CDFgetRowsinLeapSecondsTable (); -} - -/****************************************************************************** -* CDF_fillLeapSecondsTable (FORTRAN equivalent of -* CDFfillLeapSecondsTable). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(cdf_fillleapsecondstable__, - cdf_fillleapsecondstable_, - cdf_fillleapsecondstable, - CDF_FILLLEAPSECONDSTABLE) -(tableo) -double *tableo; -{ - int ix, iy; - int rows = CDFgetRowsinLeapSecondsTable (); - double **table; - table = (double **) cdf_AllocateMemory (sizeof (double *) * rows, NULL); - for (ix = 0; ix < rows; ++ix) - table[ix] = cdf_AllocateMemory (sizeof (double) * 6, NULL); - CDFfillLeapSecondsTable (table); - for (ix = 0; ix < rows; ++ix) - for (iy = 0; iy < 6; ++iy) - *(((double *)tableo)+6*ix+iy) = table[ix][iy]; - for (ix = 0; ix < rows; ++ix) cdf_FreeMemory (table[ix], NULL); - cdf_FreeMemory (table, NULL); -} - - diff --git a/cdf36_3-dist/src/lib/cdfvalid.c b/cdf36_3-dist/src/lib/cdfvalid.c deleted file mode 100644 index d75a119..0000000 --- a/cdf36_3-dist/src/lib/cdfvalid.c +++ /dev/null @@ -1,326 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Validate CDF things. -* -* Version 1.9c, 14-Dec-97, Hughes STX. -* -* Modification history: -* -* V1.0 3-Jun-91, J Love Original version (for CDF V2.1). This is a -* combination of validcdfname.c, validvarname.c, -* validattrname.c, validdatatype.c, -* validattrscope.c, and validencoding. -* V1.1 10-Jun-91, J Love Don't allow blanks in VMS CDF names. Check -* all characters in CDF, attr., and var. names. -* V1.2 28-Jun-91, J Love Housekeeping. -* V1.3 15-Sep-91, J Love Changed for IBM-PC port. -* V1.4 4-Oct-91, J Love Changed for IBM-RS6000 port (and IBM-PC). -* V1.5 23-Mar-92, J Love HP port/CDF V2.2. -* V1.6 5-Oct-92, J Love Added NeXT to `validEncoding' (better late -* than never). -* V1.7 25-Jan-94, J Love CDF V2.4. -* V1.7a 4-Feb-94, J Love DEC Alpha/OpenVMS port. -* V1.8 13-Dec-94, J Love CDF V2.5. -* V1.8a 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.9 27-Aug-96, J Love CDF V2.6. -* V1.9a 21-Feb-97, J Love Removed RICE. -* V1.9b 28-Feb-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V1.9c 14-Dec-97, J Love Added ALPHAVMSi encoding. -* V1.10 18-Feb-10, M Liu Modified ValidAttrScope to allow the assumed -* global/variable attribute in the older file. -* V1.11 10-Feb-12, M Liu Added InValidDataType function. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* Validate CDF name. -******************************************************************************/ - -VISIBLE_PREFIX Logical ValidCDFname (name) -char *name; -{ - size_t len = strlen(name); - int i; - /**************************************************************************** - * Length must be at least one. - ****************************************************************************/ - if (len < 1) return FALSE; - /**************************************************************************** - * All characters must be printable. - ****************************************************************************/ - for (i = 0; i < (int) len; i++) { - if (!Printable((int)name[i])) return FALSE; - } - /**************************************************************************** - * Passed all tests - return TRUE. - ****************************************************************************/ - return TRUE; -} - -/****************************************************************************** -* Validate variable name. -******************************************************************************/ - -VISIBLE_PREFIX Logical ValidVarName (name) -char *name; -{ - size_t len; /* length of name */ - size_t i; - /**************************************************************************** - * Length must be at least one. - ****************************************************************************/ - len = strlen(name); - if (len < 1) return FALSE; /* length must be at least one */ - /**************************************************************************** - * All characters must be printable. - ****************************************************************************/ - for (i = 0; i < len; i++) { - if (!Printable((int)name[i])) return FALSE; - } - /**************************************************************************** - * Passed all tests - return TRUE. - ****************************************************************************/ - return TRUE; -} - -/****************************************************************************** -* Validate attribute name. -******************************************************************************/ - -VISIBLE_PREFIX Logical ValidAttrName (name) -char *name; -{ - size_t len; /* length of name */ - size_t i; - /**************************************************************************** - * Length must be at least one. - ****************************************************************************/ - len = strlen(name); - if (len < 1) return FALSE; /* length must be at least one */ - /**************************************************************************** - * All characters must be printable. - ****************************************************************************/ - for (i = 0; i < len; i++) { - if (!Printable((int)name[i])) return FALSE; - } - /**************************************************************************** - * Passed all tests - return TRUE. - ****************************************************************************/ - return TRUE; -} - -/****************************************************************************** -* Validate data type. -******************************************************************************/ - -VISIBLE_PREFIX Logical ValidDataType (dataType) -Int32 dataType; -{ - switch (dataType) { - case CDF_INT1: return TRUE; - case CDF_INT2: return TRUE; - case CDF_INT4: return TRUE; - case CDF_INT8: return TRUE; - case CDF_UINT1: return TRUE; - case CDF_UINT2: return TRUE; - case CDF_UINT4: return TRUE; - case CDF_REAL4: return TRUE; - case CDF_REAL8: return TRUE; - case CDF_CHAR: return TRUE; - case CDF_UCHAR: return TRUE; - case CDF_BYTE: return TRUE; - case CDF_FLOAT: return TRUE; - case CDF_DOUBLE: return TRUE; - case CDF_EPOCH: return TRUE; - case CDF_EPOCH16: return TRUE; - case CDF_TIME_TT2000: return TRUE; - } - return FALSE; -} - -/****************************************************************************** -* InValidate data type. -* Data types added in V3.* are invalid for V2.* file. -******************************************************************************/ - -VISIBLE_PREFIX Logical InValidDataType (dataType) -Int32 dataType; -{ - switch (dataType) { - case CDF_INT8: return TRUE; - case CDF_EPOCH16: return TRUE; - case CDF_TIME_TT2000: return TRUE; - } - return FALSE; -} - -/****************************************************************************** -* Validate attribute scope. -******************************************************************************/ - -VISIBLE_PREFIX Logical ValidAttrScope (scope) -Int32 scope; -{ - switch (scope) { - case GLOBAL_SCOPE: return TRUE; - case VARIABLE_SCOPE: return TRUE; - case GLOBALscopeASSUMED: return TRUE; - case VARIABLEscopeASSUMED: return TRUE; - } - return FALSE; -} - -/****************************************************************************** -* Validate encoding. -******************************************************************************/ - -VISIBLE_PREFIX Logical ValidEncoding (encoding, actualEncoding) -Int32 encoding; -Int32 *actualEncoding; -{ - switch (encoding) { - case HOST_ENCODING: - *actualEncoding = HostEncoding(); - break; - case NETWORK_ENCODING: - case SUN_ENCODING: - case VAX_ENCODING: - case DECSTATION_ENCODING: - case SGi_ENCODING: - case IBMPC_ENCODING: - case IBMRS_ENCODING: - case HP_ENCODING: - case NeXT_ENCODING: - case ALPHAOSF1_ENCODING: - case ALPHAVMSd_ENCODING: - case ALPHAVMSg_ENCODING: - case ALPHAVMSi_ENCODING: - case PPC_ENCODING: - *actualEncoding = encoding; - break; - default: - return FALSE; - } - return TRUE; -} - -/****************************************************************************** -* Validate decoding. -******************************************************************************/ - -VISIBLE_PREFIX Logical ValidDecoding (decoding) -Int32 decoding; -{ - switch (decoding) { - case HOST_DECODING: - case NETWORK_DECODING: - case SUN_DECODING: - case VAX_DECODING: - case DECSTATION_DECODING: - case SGi_DECODING: - case IBMPC_DECODING: - case IBMRS_DECODING: - case HP_DECODING: - case NeXT_DECODING: - case ALPHAOSF1_DECODING: - case ALPHAVMSd_DECODING: - case ALPHAVMSg_DECODING: - case ALPHAVMSi_DECODING: - case PPC_DECODING: - return TRUE; - default: - return FALSE; - } -} - -/****************************************************************************** -* ValidateCompression. -******************************************************************************/ - -#if defined(BORLANDC) -#pragma warn -par -#endif - -VISIBLE_PREFIX CDFstatus ValidateCompression (cType, cParms) -long cType; -long *cParms; -{ - switch (cType) { - case NO_COMPRESSION: - break; -#if SUPPORT_RLE - case RLE_COMPRESSION: - if (cParms[0] != RLE_OF_ZEROs) return BAD_COMPRESSION_PARM; - break; -#endif -#if SUPPORT_HUFF - case HUFF_COMPRESSION: - if (cParms[0] != OPTIMAL_ENCODING_TREES) return BAD_COMPRESSION_PARM; - break; -#endif -#if SUPPORT_AHUFF - case AHUFF_COMPRESSION: - if (cParms[0] != OPTIMAL_ENCODING_TREES) return BAD_COMPRESSION_PARM; - break; -#endif -#if SUPPORT_GZIP - case GZIP_COMPRESSION: - if (!INCLUSIVE(1,cParms[0],9)) return BAD_COMPRESSION_PARM; - break; -#endif - default: - return UNKNOWN_COMPRESSION; - } - return CDF_OK; -} - -/****************************************************************************** -* ValidateCompression64. -******************************************************************************/ - -#if defined(BORLANDC) -#pragma warn -par -#endif - -VISIBLE_PREFIX CDFstatus ValidateCompression64 (cType, cParms) -long cType; -long *cParms; -{ - switch (cType) { - case NO_COMPRESSION: - break; -#if SUPPORT_RLE64 - case RLE_COMPRESSION: - if (cParms[0] != RLE_OF_ZEROs) return BAD_COMPRESSION_PARM; - break; -#endif -#if SUPPORT_HUFF64 - case HUFF_COMPRESSION: - if (cParms[0] != OPTIMAL_ENCODING_TREES) return BAD_COMPRESSION_PARM; - break; -#endif -#if SUPPORT_AHUFF64 - case AHUFF_COMPRESSION: - if (cParms[0] != OPTIMAL_ENCODING_TREES) return BAD_COMPRESSION_PARM; - break; -#endif -#if SUPPORT_GZIP64 - case GZIP_COMPRESSION: - if (!INCLUSIVE(1,cParms[0],9)) return BAD_COMPRESSION_PARM; - break; -#endif - default: - return UNKNOWN_COMPRESSION; - } - return CDF_OK; -} - - diff --git a/cdf36_3-dist/src/lib/cdfvalidator.c b/cdf36_3-dist/src/lib/cdfvalidator.c deleted file mode 100644 index bf4640e..0000000 --- a/cdf36_3-dist/src/lib/cdfvalidator.c +++ /dev/null @@ -1,1085 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Validate internal records in a CDF V2.* file -* -* Version 1.0, 15-Jul-08, Peort Systems. -* -* Modification history: -* -* V1.0 15-Jul-08, M Liu Original version. -* V1.1 20-Aug-09, M Liu Modified ValidateCDF to handle V2.0 files that -* have no filesize field. Also, don't look for -* any VDRs when the last one is read. -* V1.2 12-Aug-10, M Liu Ensured the debugging message will not overrun -* the defined string in QuitCDF. -* -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* Local macro definitions. -******************************************************************************/ - -#define CRE CDF_READ_ERROR -#define CV2C CORRUPTED_V2_CDF - -/****************************************************************************** -* Local function prototypes. -******************************************************************************/ - -static CDFstatus QuitCDF PROTOARGs((char *why, Int32 offset, int size, int num, -void *value1, void *value2, Logical debug)); -static CDFstatus ValidateCCR PROTOARGs((vFILE *fp, Int32 offset, Logical debug)); -static CDFstatus ValidateCDR PROTOARGs((vFILE *fp, Int32 offset, Logical debug)); -static CDFstatus ValidateGDR PROTOARGs((vFILE *fp, Int32 offset, Logical debug)); -static CDFstatus ValidateVDR PROTOARGs((struct CDFstruct *CDF, vFILE *fp, Int32 offset, Logical zVar, Logical debug)); -static CDFstatus ValidateVXR PROTOARGs((vFILE *fp, Int32 offset, Int32 lastRec, Logical debug)); -static CDFstatus ValidateVVR PROTOARGs((vFILE *fp, Int32 offset, Logical debug)); -static CDFstatus ValidateADR PROTOARGs((struct CDFstruct *CDF, vFILE *fp, Int32 offset, Logical debug)); -static CDFstatus ValidateAEDR PROTOARGs((struct CDFstruct *CDF, vFILE *fp, Int32 offset, Int32 num, Int32 maxEntry, Logical zEntry, Logical debug)); -static CDFstatus ValidateCPR PROTOARGs((vFILE *fp, Int32 offset, Logical debug)); -static CDFstatus ValidateSPR PROTOARGs((vFILE *fp, Int32 offset, Logical debug)); -static CDFstatus ValidateCVVR PROTOARGs((vFILE *fp, Int32 offset, Logical debug)); -static CDFstatus ValidateUIR PROTOARGs((vFILE *fp, Int32 offset, Logical debug)); -static CDFstatus ValidateAttributeLinks PROTOARGs((struct CDFstruct *CDF, vFILE *fp, Logical debug)); -static CDFstatus ValidateAttributeEntryLink PROTOARGs((struct CDFstruct *CDF, vFILE *fp, Int32 num, Logical zEntry, Int32 AEDRhead, Int32 numEntries, Int32 maxEntry, Logical debug)); -static CDFstatus ValidateVariableLinks PROTOARGs((struct CDFstruct *CDF, vFILE *fp, Logical zVar, Logical debug)); -static CDFstatus ValidateVariableValueLinks PROTOARGs((struct CDFstruct *CDF, vFILE *fp, Int32 lastRec, Int32 headVXR, Logical debug)); -static struct CDRstruct CDR; -static struct GDRstruct GDR; -static int rVars, zVars; -static int numAttrs; - -/****************************************************************************** -* QuitCDF. -******************************************************************************/ - -static CDFstatus QuitCDF (char *why, Int32 offset, int size, int num, - void *value1, void *value2, Logical debug) -{ - - if (debug) { - char text[151], texta[41]; - text[0] = NUL; - strcpyX (text, why, 150); - if (offset >= 0) { - snprintf (texta, (size_t) sizeof(texta), - " (@%ld) ", (long) offset); - strcatX (text, texta, 150); - } - if (strlen(why) < 150) { - if (num == 2) { /* Two argument values to show. */ - if (size == 4) { /* Each one is a 4-byte int type. */ - /* Each int is up to 10 digits + sign. */ - char text2[2 * 11 + 6 + 1]; - text2[0] = NUL; - snprintf (text2, (size_t) sizeof(text2), - "(%ld vs %ld)", (long) *(int *)value1, - (long) *(int *)value2); - strcatX (text, text2, 150); - } else { /* Both are strings. */ - char *text2; - size_t len = strlen ((char *) value1) + strlen ((char *) value2) + - 6 + 1; - text2 = (char *) cdf_AllocateMemory (len, NULL); - if (text2 != NULL) { - text2[0] = NUL; - snprintf (text2, len, "(%s vs %s)", (char *)value1, (char *)value2); - strcatX (text, text2, 150); - cdf_FreeMemory (text2, NULL); - } - } - } else { /* Only one argument value to show. */ - if (size == 4) { /* Each int is up to 10 digits + sign. */ - char text2[11 + 2 + 1]; - text2[0] = NUL; - snprintf (text2, (size_t) sizeof(text2), - "(%ld)", (long) *(int *)value1); - strcatX (text, text2, 150); - } else { - char *text2; - size_t len = strlen ((char *) value1) + 2 + 1; - text2 = (char *) cdf_AllocateMemory (len, NULL); - if (text2 != NULL) { - text2[0] = NUL; - snprintf (text2, len, "(%s)", (char *)value1); - strcatX (text, text2, 150); - cdf_FreeMemory (text2, NULL); - } - } - } - } - printf ("ERROR...%s\n", text); - } - return CV2C; -} - -/****************************************************************************** -* ValidateCDF. -* Start to validate each internal record in a CDF file. -******************************************************************************/ - -STATICforIDL CDFstatus ValidateCDF (struct CDFstruct *CDF, vFILE *CDFfp, - Int32 offset, Int32 fileSize, - Logical debug) -{ - Int32 recordSize; - Int32 recordType; - CDFstatus status; - - status = CDF_OK; - /**************************************************************************** - * Read internal records from the beginning of the file until EOF (or illegal - * record) reached. - ****************************************************************************/ - if (!SEEKv(CDFfp,offset,vSEEK_SET)) return CRE; - for (;;) { - /************************************************************************* - * Read record size. - *************************************************************************/ - offset = V_tell (CDFfp); - if (!CDF->badEOF && offset == fileSize) break; - if (!Read32(CDFfp,&recordSize)) { - if (!CDF->badEOF) return CRE; - else break; - } - if (recordSize < 1 || (!CDF->badEOF && recordSize > fileSize)) - return QuitCDF ("CDF: an invalid internal record size ", offset, - 4, 1, &recordSize, 0, debug); - /************************************************************************* - * Read record type. - *************************************************************************/ - if (!Read32(CDFfp,&recordType)) return CRE; - /************************************************************************* - * Based on the record type... - *************************************************************************/ - switch ((int)recordType) { - /********************************************************************** - * Compressed CDF Record (CCR). - **********************************************************************/ - case CCR_: { -/* - status = ValidateCCR (CDFfp, offset, debug); - if (status != CDF_OK) return status; -*/ - offset = offset + recordSize; - if (!SEEKv(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * CDF Descriptor Record (CDR). - **********************************************************************/ - case CDR_: { - numAttrs = rVars = zVars = 0; - status = ValidateCDR (CDFfp, offset, debug); - if (status != CDF_OK) return status; - status = ValidateGDR (CDFfp, CDR.GDRoffset, debug); - if (status != CDF_OK) return status; - offset = offset + recordSize; - if (!SEEKv(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Global Descriptor Record (GDR). - **********************************************************************/ - case GDR_: { - offset = offset + recordSize; - if (!SEEKv(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Attribute Descriptor Record (ADR). - **********************************************************************/ - case ADR_: { - ++numAttrs; - offset = offset + recordSize; - if (!SEEKv(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Attribute Entry Descriptor Record (AgrEDR or AzEDR). - **********************************************************************/ - case AgrEDR_: - case AzEDR_: { - offset = offset + recordSize; - if (!SEEKv(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Variable Descriptor Record (rVDR or zVDR). - **********************************************************************/ - case rVDR_: - case zVDR_: { - Logical zVar = (recordType == zVDR_); - if (zVar) - ++zVars; - else - ++rVars; - offset = offset + recordSize; - if (!SEEKv(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Variable indeX Record (VXR). - **********************************************************************/ - case VXR_: { - offset = offset + recordSize; - if (!SEEKv(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Variable Values Record (VVR). - **********************************************************************/ - case VVR_: { - status = ValidateVVR (CDFfp, offset, debug); - if (recordSize < VVR_BASE_SIZE) - return QuitCDF ("CDF(VVR): record size is invalid ", offset, - 4, 1, &recordSize, 0, debug); - offset = offset + recordSize; - if (!SEEKv(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Compressed Variable Values Record (CVVR). - **********************************************************************/ - case CVVR_: { - status = ValidateCVVR (CDFfp, offset, debug); - if (status != CDF_OK) return status; - offset = offset + recordSize; - if (!SEEKv(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Compressed Parameters Record (CPR). - **********************************************************************/ - case CPR_: { - offset = offset + recordSize; - if (!SEEKv(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Sparseness Parameters Record (SPR). - **********************************************************************/ - case SPR_: { -/* - status = ValidateSPR (CDFfp, offset, debug); - if (status != CDF_OK) return status; -*/ - offset = offset + recordSize; - if (!SEEKv(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Unused internal record - **********************************************************************/ - case UIR_: { - offset = offset + recordSize; - if (!SEEKv(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Illegal record type. - **********************************************************************/ - default: { - return QuitCDF ("CDF: an invalid internal record type", offset, - 4, 1, &recordType, 0, debug); - } - } - } - /**************************************************************************** - * Check attribute links and their attribute entries. - ****************************************************************************/ - if (GDR.NumAttr != numAttrs) - return QuitCDF ("CDF: number of attributes does not match: ", (Int32) -1, - 4, 2, &GDR.NumAttr, &numAttrs, debug); - if (numAttrs > 0) { - status = ValidateAttributeLinks(CDF, CDFfp, debug); - if (status != CDF_OK) return status; - } - /**************************************************************************** - * Check rVariable links and their data. - ****************************************************************************/ - if (GDR.NrVars != rVars) - return QuitCDF ("CDF: number of rVariables does not match: ", (Int32) -1, - 4, 2, &GDR.NrVars, &rVars, debug); - if (rVars > 0) { - status = ValidateVariableLinks(CDF, CDFfp, FALSE, debug); - if (status != CDF_OK) return status; - } - /**************************************************************************** - * Check zVariable links and their data. - ****************************************************************************/ - if (GDR.NzVars != zVars) - return QuitCDF ("CDF: number of zVariables does not match: ", (Int32) -1, - 4, 2, &GDR.NzVars, &zVars, debug); - if (zVars > 0) { - status = ValidateVariableLinks(CDF, CDFfp, TRUE, debug); - if (status != CDF_OK) return status; - } - return CDF_OK; -} - -/****************************************************************************** -* ValidateCDR. -******************************************************************************/ - -static CDFstatus ValidateCDR (vFILE *fp, Int32 offset, Logical debug) -{ - Int32 actualEncoding; -/* - char copyRight[CDF_COPYRIGHT_LEN+1]; -*/ - CDFstatus status; - - if (debug) - printf(" Checking CDR...@%d\n", (int) offset); - status = ReadCDR (fp, offset, - CDR_RECORD, &CDR, NULL, - CDR_NULL); - if (status != CDF_OK) return status; - if (CDR.RecordType != CDR_) - return QuitCDF ("CDF(CDR): record type is invalid ", offset, - 4, 1, &(CDR.RecordType), 0, debug); - if (CDR.RecordSize < CDR_BASE_SIZE || - (!PriorTo("2.5",CDR.Version,CDR.Release,CDR.Increment) && - CDR.RecordSize > CDR_MAX_SIZE)) - return QuitCDF ("CDF(CDR): record size is invalid ", offset, - 4, 1, &(CDR.RecordSize), 0, debug); - if (CDR.GDRoffset < 1) - return QuitCDF ("CDF(CDR): offset to GDR is invalid ", offset, - 4, 1, &(CDR.GDRoffset), 0, debug); - if (CDR.Version != 2) - return QuitCDF ("CDF: version number is invalid ", offset, - 4, 1, &(CDR.Version), 0, debug); - if (CDR.Release < 0) - return QuitCDF ("CDF: release number is invalid ", offset, - 4, 1, &(CDR.Release), 0, debug); - if (CDR.Increment < 0) - return QuitCDF ("CDF: increment number is invalid ", offset, - 4, 1, &(CDR.Increment), 0, debug); - if (!ValidEncoding(CDR.Encoding,&actualEncoding)) - return QuitCDF ("CDF(CDR): encoding is invalid ", offset, - 4, 1, &(CDR.Encoding), 0, debug); -/* - for (i = 0; i < strlen(copyRight); ++i) - if (!Printable(copyRight[i])) - return QuitCDF ("CDF(CDR): copyright is invalid ", offset, - 0, copyRight), 0, debug); -*/ - return CDF_OK; -} - -/****************************************************************************** -* ValidateGDR. -******************************************************************************/ - -static CDFstatus ValidateGDR (vFILE *fp, Int32 offset, Logical debug) -{ - int i; - CDFstatus status; - - if (debug) - printf(" Checking GDR...@%d\n", (int) offset); - status = ReadGDR (fp, offset, - GDR_RECORD, &GDR, - GDR_NULL); - if (status != CDF_OK) return status; - if (GDR.RecordType != GDR_) - return QuitCDF ("CDF(GDR): record type is invalid ", offset, - 4, 1, &(GDR.RecordType), 0, debug); - if (GDR.RecordSize < GDR_BASE_SIZE || - GDR.RecordSize > GDR_MAX_SIZE) - return QuitCDF ("CDF(GDR): record size is invalid ", offset, - 4, 1, &(GDR.RecordSize), 0, debug); - if (GDR.NrVars < 0 || (GDR.NrVars > 0 && GDR.rVDRhead < 1)) - return QuitCDF ("CDF(GDR): NrVars or their link is invalid ", offset, - 4, 1, &(GDR.NrVars), 0, debug); - if (GDR.NumAttr < 0 || (GDR.NumAttr > 0 && GDR.ADRhead < 1)) - return QuitCDF ("CDF(GDR): attribute numbers or their link is invalid ", offset, - 4, 1, &(GDR.NumAttr), 0, debug); - if (GDR.rMaxRec < -1) - return QuitCDF ("CDF(GDR): max rVars record is invalid ", offset, - 4, 1, &(GDR.rMaxRec), 0, debug); - if (GDR.rNumDims < 0 || - GDR.rNumDims > CDF_MAX_DIMS) - return QuitCDF ("CDF(GDR): number of dimensions for rVars is invalid ", offset, - 4, 1, &(GDR.rNumDims), 0, debug); - if (GDR.NzVars < 0 || (GDR.NzVars > 0 && GDR.zVDRhead < 1)) - return QuitCDF ("CDF(GDR): NzVars or their link is invalid ", offset, - 4, 1, &(GDR.NzVars), 0, debug); - if (GDR.UIRhead < 0) - return QuitCDF ("CDF(GDR): offset to UIR is invalid ", offset, - 4, 1, &(GDR.UIRhead), 0, debug); - for (i = 0; i < (int)GDR.rNumDims; ++i) - if (GDR.rDimSizes[i] < 1) - return QuitCDF ("CDF(GDR): dimensional size is invalid ", offset, - 4, 1, &(GDR.rDimSizes[i]), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateADR. -******************************************************************************/ - -static CDFstatus ValidateADR (struct CDFstruct *CDF, vFILE *fp, Int32 offset, - Logical debug) -{ - struct ADRstruct ADR; - CDFstatus status; - - if (debug) - printf(" Checking ADR...@%d\n", (int) offset); - status = ReadADR (fp, offset, - ADR_RECORD, &ADR, - ADR_NULL); - if (status != CDF_OK) return status; - if (ADR.RecordType != ADR_) - return QuitCDF ("CDF(ADR): record type is invalid ", offset, - 4, 1, &(ADR.RecordType), 0, debug); - - if (ADR.RecordSize < ADR_BASE_SIZE || - ADR.RecordSize > ADR_MAX_SIZE) - return QuitCDF ("CDF(ADR): record size is invalid ", offset, - 4, 1, &(ADR.RecordSize), 0, debug); - if (ADR.ADRnext < 0 || ((ADR.Num < (GDR.NumAttr-1)) && ADR.ADRnext == 0)) - return QuitCDF ("CDF(ADR): offset to next ADR is invalid ", offset, - 4, 1, &(ADR.ADRnext), 0, debug); - if (ADR.AgrEDRhead < 0 || (ADR.NgrEntries > 0 && ADR.AgrEDRhead == 0)) - return QuitCDF ("CDF(ADR): record size is invalid ", offset, - 4, 1, &(ADR.AgrEDRhead), 0, debug); -/* - if ((ADR.Scope == GLOBAL_SCOPE) && (ADR.NzEntries > 0)) - return QuitCDF ("CDF(ADR): attribute zEntries exist for a global attribute ", offset, - 4, 1, &(ADR.NzEntries), 0, debug); -*/ - if (!ValidAttrScope(ADR.Scope)) - return QuitCDF ("CDF(ADR): scope is invalid ", offset, - 4, 1, &(ADR.Scope), 0, debug); - if (ADR.Num < 0 || ADR.Num > GDR.NumAttr) - return QuitCDF ("CDF(ADR): attribute number is invalid ", offset, - 4, 2, &(ADR.Num), &(GDR.NumAttr), debug); - if (ADR.NgrEntries < 0) - return QuitCDF ("CDF(ADR): number of g/rEntries is invalid ", offset, - 4, 1, &(ADR.NgrEntries), 0, debug); -/* - if ((ADR.Scope == VARIABLE_SCOPE) && (ADR.NgrEntries > CDF->NrVars)) - return QuitCDF ("CDF(ADR): number of rEntries is invalid ", offset, - 4, 1, &(ADR.NgrEntries), 0, debug); -*/ - if (ADR.MAXgrEntry < -1) - return QuitCDF ("CDF(ADR): max g/rEntry is invalid ", offset, - 4, 1, &(ADR.MAXgrEntry), 0, debug); - if ((ADR.Scope == VARIABLE_SCOPE) && (ADR.MAXgrEntry < (ADR.NgrEntries-1))) - return QuitCDF ("CDF(ADR): max rEntry is invalid ", offset, - 4, 2, &(ADR.MAXgrEntry), &(ADR.NgrEntries), debug); - if (ADR.AzEDRhead < 0 || (ADR.NzEntries > 0 && ADR.AzEDRhead == 0)) - return QuitCDF ("CDF(ADR): offset to next AzEDR is invalid ", offset, - 4, 1, &(ADR.AzEDRhead), 0, debug); -/* - if (ADR.NzEntries < 0 || ((ADR.Scope == VARIABLE_SCOPE) && - (ADR.NzEntries > CDF->NzVars))) - return QuitCDF ("CDF(ADR): number of zEntries is invalid ", offset, - 4, 2, &(ADR.NzEntries), &(CDF->NzVars), debug); - if (ADR.MAXzEntry < -1 || ((ADR.Scope == VARIABLE_SCOPE) && - (ADR.MAXzEntry > CDF->NzVars))) - return QuitCDF ("CDF(ADR): max zEntry is invalid ", offset, - 4, 2, &(ADR.MAXzEntry), &(CDF->NzVars), debug); -*/ - if ((ADR.Scope == VARIABLE_SCOPE) && (ADR.MAXzEntry < (ADR.NzEntries-1))) - return QuitCDF ("CDF(ADR): max zEntry is invalid ", offset, - 4, 2, &(ADR.MAXzEntry), &(ADR.NzEntries), debug); - if (!ValidAttrName(ADR.Name)) - return QuitCDF ("CDF(ADR): attribute name is invalid ", offset, - 0, 1, ADR.Name, 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateAEDR/AzEDR. -******************************************************************************/ - -static 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(AEDR): record type is invalid ", offset, - 4, 1, &(AEDR.RecordType), 0, debug); - if (AEDR.RecordSize < AEDR_BASE_SIZE) - return QuitCDF ("CDF(AEDR): record size is invalid ", offset, - 4, 1, &(AEDR.RecordSize), 0, debug); - if (AEDR.AEDRnext < 0) - return QuitCDF ("CDF(AEDR): offset to next AEDR is invalid ", offset, - 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(AEDR): attribute number is invalid ", offset, - 4, 2, &(AEDR.AttrNum), &(GDR.NumAttr), debug); -*/ - if (!ValidDataType(AEDR.DataType) || InValidDataType(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, - 4, 1, &(AEDR.AEDRnext), 0, debug); -/* - if (zEntry && AEDR.EntryNum > GDR->NzVars) - return QuitCDF ("CDF(AEDR): entry number is invalid ", offset, - 4, 2, &(AEDR.Num), &(GDR->NzVars), debug); -*/ - if (AEDR.NumElems < 1 || - (STRINGdataType(AEDR.DataType) && - AEDR.NumElems > (AEDR.RecordSize - AEDR_VALUE_OFFSET))) - 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_OFFSET)) - return QuitCDF ("CDF(AEDR): entry value size is invalid ", offset, - 4, 1, &nBytes, 0, debug); - if (AEDR.RecordSize > (AEDR_MAX_SIZE + nBytes)) - return QuitCDF ("CDF(AEDR): record size is invalid ", offset, - 4, 1, &(AEDR.RecordSize), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateVDR/zVDR. -******************************************************************************/ - -static CDFstatus ValidateVDR (struct CDFstruct *CDF, vFILE *fp, Int32 offset, - Logical zVar, Logical debug) -{ - struct VDRstruct VDR; - Int32 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(VDR): record type is invalid ", offset, - 4, 1, &(VDR.RecordType), 0, debug); - if (VDR.RecordSize < (zVar ? zVDR_BASE_SIZE : rVDR_BASE_SIZE)) - return QuitCDF ("CDF(VDR): record size is invalid ", offset, - 4, 1, &(VDR.RecordSize), 0, debug); - if (!ValidDataType(VDR.DataType) || InValidDataType(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, - 4, 1, &(VDR.VDRnext), 0, debug); - if (VARcompressionBITset(VDR.Flags) && VDR.CPRorSPRoffset <= (int) NO_OFFSET) - return QuitCDF ("CDF(VDR): offset to CPRorSPR is invalid ", offset, - 4, 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_SIZE : rVDR_MAX_SIZE) + nBytes + - (CDF->wastedSpace ? VDR_WASTED_SIZE : 0))) - return QuitCDF ("CDF(VDR): record size is invalid ", offset, - 4, 1, &(VDR.RecordSize), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateVXR. -******************************************************************************/ - -static CDFstatus ValidateVXR (vFILE *fp, Int32 offset, Int32 lastRec, - Logical debug) -{ - struct VXRstruct VXR; - int i; - Int32 irType; - CDFstatus status; - - if (debug) - printf(" Checking VXR...@%d\n", (int) offset); - status = ReadVXR (fp, offset, - VXR_RECORD, &VXR, - VXR_NULL); - if (status != CDF_OK) return status; - if (VXR.RecordType != VXR_) - return QuitCDF ("CDF(VXR): record type is invalid ", offset, - 4, 1, &(VXR.RecordType), 0, debug); - if (VXR.RecordSize != (VXR_FIRSTREC_OFFSET + 12 * VXR.Nentries)) - return QuitCDF ("CDF(VXR): record size is invalid ", offset, - 4, 1, &(VXR.RecordSize), 0, debug); - if (VXR.Nentries < 0 || VXR.Nentries > MAX_VXR_ENTRIES) - return QuitCDF ("CDF(VXR): number of entries is invalid ", offset, - 4, 1, &(VXR.Nentries), 0, debug); - if (VXR.NusedEntries < 0 || VXR.NusedEntries > VXR.Nentries) - return QuitCDF ("CDF(VXR): number of used entries is invalid ", offset, - 4, 2, &(VXR.NusedEntries), &(VXR.Nentries), debug); - if (VXR.VXRnext > 0) { - if (VXR.Last[VXR.NusedEntries-1] > lastRec) - return QuitCDF ("CDF(VXR): a variable last record does not match in a Variable Index Record: ", offset, - 4, 2, &(VXR.Last[VXR.NusedEntries-1]), &lastRec, debug); - status = ValidateVXR (fp, VXR.VXRnext, lastRec, debug); - if (status != CDF_OK) return status; - } else if (VXR.VXRnext < 0) { - return QuitCDF ("CDF(VXR): a link offset to next record is negative in a Variable Index Record: ", offset, - 4, 1, &(VXR.VXRnext), 0, debug); - } - - for (i = 0; i < VXR.NusedEntries; ++i) { - if (VXR.First[i] < 0 || VXR.Last[i] < 0 || VXR.First[i] > VXR.Last[i]) - return QuitCDF ("CDF(VXR): entry value for first/last is invalid ", offset, - 4, 2, &(VXR.First[i]), &(VXR.Last[i]), debug); - if (VXR.Offset[i] < 1) - return QuitCDF ("CDF(VXR): entry value for offset is invalid ", offset, - 4, 1, &(VXR.Offset[i]), 0, debug); - - status = ReadIrType (fp, VXR.Offset[i], &irType); - if (status != CDF_OK) return status; - if (irType != VXR_ && irType != VVR_ && irType != CVVR_) - return QuitCDF ("CDF(VXR): entry value for offset is invalid ", offset, - 4, 1, &(VXR.Offset[i]), 0, debug); - if (irType == VXR_ && VXR.Offset[i] != offset) { - status = ValidateVXR (fp, VXR.Offset[i], lastRec, debug); - if (status != CDF_OK) return status; - } - } - return CDF_OK; -} - -/****************************************************************************** -* ValidateVVR. -******************************************************************************/ - -static CDFstatus ValidateVVR (vFILE *fp, Int32 offset, Logical debug) -{ - struct VVRstruct VVR; - CDFstatus status; - - if (debug) - printf(" Checking VVR...@%d\n", (int) offset); - status = ReadVVR (fp, offset, - VVR_RECORDx, &VVR, - VVR_NULL); - if (status != CDF_OK) return status; - if (VVR.RecordType != VVR_) - return QuitCDF ("CDF(VVR): record type is invalid ", offset, - 4, 1, &(VVR.RecordType), 0, debug); - if (VVR.RecordSize < VVR_BASE_SIZE) - return QuitCDF ("CDF(VVR): record size is invalid for Variable Value Record", offset, - 4, 1, &(VVR.RecordSize), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateUIR. -******************************************************************************/ - -static CDFstatus ValidateUIR (vFILE *fp, Int32 offset, Logical debug) -{ - struct UIRstruct UIR; - CDFstatus status; - - if (debug) - printf(" Checking UIR...@%d\n", (int) offset); - status = ReadUIR (fp, offset, - UIR_RECORD, &UIR, - UIR_NULL); - if (status != CDF_OK) return status; - if (UIR.RecordType != UIR_) - return QuitCDF ("CDF(UIR): record type is invalid ", offset, - 4, 1, &(UIR.RecordType), 0, debug); - if (UIR.RecordSize < UIR_BASE_SIZE) - return QuitCDF ("CDF(UIR): record size is invalid for Unused Internal Record", offset, - 4, 1, &(UIR.RecordSize), 0, debug); - if (UIR.NextUIR < 0) - return QuitCDF ("CDF(UIR): offset to next UIR is invalid for Unused Internal Record", offset, - 4, 1, &(UIR.NextUIR), 0, debug); - if (UIR.PrevUIR < 0) - return QuitCDF ("CDF(UIR): offset to previous UIR is invalid for Unused Internal Record", offset, - 4, 1, &(UIR.PrevUIR), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateCCR. -******************************************************************************/ - -static CDFstatus ValidateCCR (vFILE *fp, Int32 offset, Logical debug) -{ - struct CCRstruct CCR; - CDFstatus status; - - if (debug) - printf(" Checking CCR...@%d\n", (int) offset); - status = ReadCCR (fp, offset, - CCR_RECORD, &CCR, - CCR_NULL); - if (status != CDF_OK) return status; - if (CCR.RecordType != CCR_) - return QuitCDF ("CDF(CCR): record type is invalid ", offset, - 4, 1, &(CCR.RecordType), 0, debug); - if (CCR.RecordSize < CCR_BASE_SIZE) - return QuitCDF ("CDF(CCR): record size is invalid ", offset, - 4, 1, &(CCR.RecordSize), 0, debug); - if (CCR.uSize < 0) - return QuitCDF ("CDF(CCR): uncompressed file size is invalid ", offset, - 4, 1, &(CCR.uSize), 0, debug); - if (CCR.CPRoffset < 0) - return QuitCDF ("CDF(CCR): offset to CPR is invalid ", offset, - 4, 1, &(CCR.CPRoffset), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateCPR. -******************************************************************************/ - -static CDFstatus ValidateCPR (vFILE *fp, Int32 offset, Logical debug) -{ - struct CPRstruct CPR; - CDFstatus status; - long cType, cParms[1]; - - if (debug) - printf(" Checking CPR...@%d\n", (int) offset); - status = ReadCPR (fp, offset, - CPR_RECORD, &CPR, - CPR_NULL); - if (status != CDF_OK) return status; - if (CPR.RecordType != CPR_) - return QuitCDF ("CDF(CPR): record type is invalid ", offset, - 4, 1, &(CPR.RecordType), 0, debug); - if (CPR.RecordSize != (CPR_BASE_SIZE + CPR.pCount * sizeof(Int32))) - return QuitCDF ("CDF(CPR): reocrd size is invalid ", offset, - 4, 1, &(CPR.RecordSize), 0, debug); - if (CPR.pCount != 1) - return QuitCDF ("CDF(CPR): compression parameter count is invalid ", offset, - 4, 1, &(CPR.pCount), 0, debug); - cType = (long) CPR.cType; - cParms[0] = (long) CPR.cParms[0]; - if (ValidateCompression(cType, cParms) != CDF_OK) - return QuitCDF ("CDF(CPR): compression parameter is invalid ", offset, - 4, 1, &(CPR.cType), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateSPR. -******************************************************************************/ - -static CDFstatus ValidateSPR (vFILE *fp, Int32 offset, Logical debug) -{ - struct SPRstruct SPR; - CDFstatus status; - - if (debug) - printf(" Checking SPR...@%d\n", (int) offset); - status = ReadSPR (fp, offset, - SPR_RECORD, &SPR, - SPR_NULL); - if (status != CDF_OK) return status; - if (SPR.RecordType != SPR_) - return QuitCDF ("CDF(SPR): record type is invalid ", offset, - 4, 1, &(SPR.RecordType), 0, debug); - if (SPR.RecordSize != (SPR_BASE_SIZE + SPR.pCount * sizeof(Int32))) - return QuitCDF ("CDF(SPR): record size is invalid ", offset, - 4, 1, &(SPR.RecordSize), 0, debug); - if (SPR.pCount < 1 || SPR.pCount > CDF_MAX_PARMS) - return QuitCDF ("CDF(SPR): sparseness parameter count is invalid ", offset, - 4, 1, &(SPR.pCount), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateCVVR. -******************************************************************************/ - -static CDFstatus ValidateCVVR (vFILE *fp, Int32 offset, Logical debug) -{ - struct CVVRstruct CVVR; - CDFstatus status; - - if (debug) - printf(" Checking CVVR...@%d\n", (int) offset); - status = ReadCVVR (fp, offset, - CVVR_RECORDx, &CVVR, - CVVR_NULL); - if (status != CDF_OK) return status; - if (CVVR.RecordSize < CVVR_BASE_SIZE) - return QuitCDF ("CDF(CVVR): record size is invalid ", offset, - 4, 1, &(CVVR.RecordSize), 0, debug); - if (CVVR.cSize < 0) - return QuitCDF ("CDF(CVVR): uncompressed records size is invalid ", offset, - 4, 1, &(CVVR.cSize), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateAttributeLinks. -******************************************************************************/ - -static CDFstatus ValidateAttributeLinks (struct CDFstruct *CDF, vFILE *fp, - Logical debug) -{ - CDFstatus status; - Int32 offset, nextADR, AgrEDRhead, AzEDRhead; - Int32 num, numgrEntries, maxgrEntry, numzEntries, maxzEntry; - int ix, *visit; - - visit = (int *) cdf_AllocateMemory(GDR.NumAttr * sizeof(Int32), NULL); - for (ix = 0; ix < GDR.NumAttr; ++ix) visit[ix] = 0; - offset = GDR.ADRhead; - for (ix = 0; ix < GDR.NumAttr; ++ix) { - status = ValidateADR (CDF, fp, offset, debug); - if (status != CDF_OK) { - cdf_FreeMemory (visit, NULL); - return status; - } - status = ReadADR (fp, offset, - ADR_NUM, &num, - ADR_ADRNEXT, &nextADR, - ADR_AgrEDRHEAD, &AgrEDRhead, - ADR_NgrENTRIES, &numgrEntries, - ADR_MAXgrENTRY, &maxgrEntry, - ADR_AzEDRHEAD, &AzEDRhead, - ADR_NzENTRIES, &numzEntries, - ADR_MAXzENTRY, &maxzEntry, - ADR_NULL); - if (numgrEntries > 0) - status = ValidateAttributeEntryLink (CDF, fp, num, FALSE, AgrEDRhead, - numgrEntries, maxgrEntry, debug); - if (status != CDF_OK) { - cdf_FreeMemory (visit, NULL); - return status; - } - if (numzEntries > 0) - status = ValidateAttributeEntryLink (CDF, fp, num, TRUE, AzEDRhead, - numzEntries, maxzEntry, debug); - if (status != CDF_OK) { - cdf_FreeMemory (visit, NULL); - return status; - } - visit[num] = 1; - offset = nextADR; - } - for (ix = 0; ix < GDR.NumAttr; ++ix) { - if (visit[ix] == 0) { - cdf_FreeMemory (visit, NULL); - return QuitCDF ("CDF: an attribute unreachable in the attribute link: ", (Int32) -1, - 4, 1, &ix, 0, debug); - } - } - cdf_FreeMemory (visit, NULL); - return CDF_OK; -} - -/****************************************************************************** -* ValidateAttributeEntryLink. -******************************************************************************/ - -static CDFstatus ValidateAttributeEntryLink (struct CDFstruct *CDF, vFILE *fp, - Int32 num, Logical zEntry, Int32 EDRhead, - Int32 numEntries, Int32 maxEntry, - Logical debug) -{ - CDFstatus status; - Int32 offset, nextAEDR; - Int32 entryNum, lastNum, *visits; - int ix, iy; - - offset = EDRhead; - lastNum = 0; - visits = (Int32 *) cdf_AllocateMemory ((size_t)numEntries * sizeof(Int32), NULL); - if (visits == NULL) return BAD_MALLOC; - for (ix = 0; ix < numEntries; ++ix) visits[ix] = 0; - ix = 0; - while (offset != 0) { - status = ValidateAEDR (CDF, fp, offset, num, maxEntry, zEntry, debug); - if (status != CDF_OK) { - cdf_FreeMemory (visits, NULL); - return status; - } - status = ReadAEDR (fp, offset, - AEDR_NUM, &entryNum, - AEDR_AEDRNEXT, &nextAEDR, - AEDR_NULL); - if (ix > 0) { - for (iy = 0; iy < ix; ++iy) { - if (visits[iy] == entryNum) { - cdf_FreeMemory (visits, NULL); - return QuitCDF ("CDF: entry number is repeating in an attribute entry link: ", (Int32) -1, - 4, 1, &entryNum, 0, debug); - } - } - } - if (ix == (int) numEntries) { - cdf_FreeMemory (visits, NULL); - return QuitCDF ("CDF: number of entries is more than maximum in an attribute entry link: ", (Int32) -1, - 4, 1, &ix, 0, debug); - } - visits[ix] = entryNum; - ++ix; - if (lastNum < entryNum) lastNum = entryNum; - offset = nextAEDR; - } - if (lastNum != maxEntry) { - cdf_FreeMemory (visits, NULL); - return QuitCDF ("CDF: last entry number is not the maximum entry number in an attribute entry link: ", (Int32) -1, - 4, 2, &lastNum, &maxEntry, debug); - } - cdf_FreeMemory (visits, NULL); - return CDF_OK; -} - -/****************************************************************************** -* ValidateVariableLinks. -******************************************************************************/ - -static CDFstatus ValidateVariableLinks (struct CDFstruct *CDF, vFILE *fp, - Logical zVar, Logical debug) -{ - CDFstatus status; - Int32 offset, headVXR, tailVXR, nextVDR, cprOffset; - Int32 num, lastRec, flags; - int ix, numVars, *visit; - - numVars = (zVar ? GDR.NzVars : GDR.NrVars); - visit = (int *) cdf_AllocateMemory ((size_t)numVars * sizeof(Int32), NULL); - if (visit == NULL) return BAD_MALLOC; - for (ix = 0; ix < numVars; ++ix) visit[ix] = 0; - offset = (zVar ? GDR.zVDRhead : GDR.rVDRhead); - for (ix = 0; ix < numVars; ++ix) { - status = ValidateVDR (CDF, fp, offset, zVar, debug); - if (status != CDF_OK) { - cdf_FreeMemory (visit, NULL); - return status; - } - status = ReadVDR (CDF, fp, offset, zVar, - VDR_NUM, &num, - VDR_FLAGS, &flags, - VDR_MAXREC, &lastRec, - VDR_VDRNEXT, &nextVDR, - VDR_CPRorSPR, &cprOffset, - VDR_VXRHEAD, &headVXR, - VDR_VXRTAIL, &tailVXR, - VDR_NULL); - if (CDF->singleFile && lastRec > -1) { - status = ValidateVariableValueLinks (CDF, fp, lastRec, headVXR, debug); - if (status != CDF_OK) { - cdf_FreeMemory (visit, NULL); - return status; - } - } -/* - if (CDF->singleFile && (headVXR != tailVXR) && tailVXR > 0) { - status = ValidateVariableValueLinks (CDF, fp, lastRec, tailVXR, debug); - if (status != CDF_OK) { - cdf_FreeMemory (visit, NULL); - return status; - } - } -*/ - if (VARcompressionBITset(flags)) { - status = ValidateCPR (fp, cprOffset, debug); - if (status != CDF_OK) { - cdf_FreeMemory (visit, NULL); - return status; - } - } - visit[num] = 1; - offset = nextVDR; - } - for (ix = 0; ix < numVars; ++ix) { - if (visit[ix] == 0) { - cdf_FreeMemory (visit, NULL); - return QuitCDF ("CDF: a variable unreachable in variable link: ", (Int32) -1, - 4, 1, &ix, 0, debug); - } - } - cdf_FreeMemory (visit, NULL); - if (!CDF->badEOF && offset != 0) { - status = ReadVDR (CDF, fp, offset, zVar, - VDR_NUM, &num, - VDR_VDRNEXT, &nextVDR, - VDR_NULL); - if (status == CDF_OK) { - if (num >= numVars) - return QuitCDF ("CDF(VDR): a variable unreachable in variable link: ", offset, - 4, 2, &num, &numVars, debug); - else - return QuitCDF ("CDF(VDR): a variable is repeated in variable link: ", offset, - 4, 2, &num, &numVars, debug); - } - } - return CDF_OK; -} - -/****************************************************************************** -* ValidateVariableValueLinks. -******************************************************************************/ - -static CDFstatus ValidateVariableValueLinks (struct CDFstruct *CDF, vFILE *fp, - Int32 lastRec, Int32 headVXR, - Logical debug) -{ - CDFstatus status; - - status = ValidateVXR (fp, headVXR, lastRec, debug); - if (status != CDF_OK) return status; - - return CDF_OK; -} - diff --git a/cdf36_3-dist/src/lib/cdfvalidator64.c b/cdf36_3-dist/src/lib/cdfvalidator64.c deleted file mode 100644 index e2d6015..0000000 --- a/cdf36_3-dist/src/lib/cdfvalidator64.c +++ /dev/null @@ -1,1117 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Validate internal records in a CDF V3.* file. -* -* Version 1.0, 15-Jul-08, Peort Systems. -* -* Modification history: -* -* V1.0 15-Jul-08, M Liu Original version. -* V1.1 12-Aug-10, M Liu Ensured the debugging message will not overrun -* the defined string in QuitCDF. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* Local macro definitions. -******************************************************************************/ - -#define CRE CDF_READ_ERROR -#define CV3C CORRUPTED_V3_CDF - -/****************************************************************************** -* Local function prototypes. -******************************************************************************/ - -static CDFstatus QuitCDF PROTOARGs((char *why, OFF_T offset, int size, int num, -void *value1, void *value2, Logical debug)); -static CDFstatus ValidateCCR PROTOARGs((vFILE *fp, OFF_T offset, Logical debug)); -static CDFstatus ValidateCDR PROTOARGs((vFILE *fp, OFF_T offset, Logical debug)); -static CDFstatus ValidateGDR PROTOARGs((vFILE *fp, OFF_T offset, Logical debug)); -static CDFstatus ValidateVDR PROTOARGs((struct CDFstruct *CDF, vFILE *fp, OFF_T offset, Logical zVar, Logical debug)); -static CDFstatus ValidateVXR PROTOARGs((vFILE *fp, OFF_T offset, Int32 lastRec, Logical debug)); -static CDFstatus ValidateVVR PROTOARGs((vFILE *fp, OFF_T offset, Logical debug)); -static CDFstatus ValidateADR PROTOARGs((struct CDFstruct *CDF, vFILE *fp, OFF_T offset, Logical debug)); -static CDFstatus ValidateAEDR PROTOARGs((struct CDFstruct *CDF, vFILE *fp, OFF_T offset, Int32 num, Int32 maxEntry, Logical zEntry, Logical debug)); -static CDFstatus ValidateCPR PROTOARGs((vFILE *fp, OFF_T offset, Logical debug)); -static CDFstatus ValidateSPR PROTOARGs((vFILE *fp, OFF_T offset, Logical debug)); -static CDFstatus ValidateCVVR PROTOARGs((vFILE *fp, OFF_T offset, Logical debug)); -static CDFstatus ValidateUIR PROTOARGs((vFILE *fp, OFF_T offset, Logical debug)); -static CDFstatus ValidateAttributeLinks PROTOARGs((struct CDFstruct *CDF, vFILE *fp, Logical debug)); -static CDFstatus ValidateAttributeEntryLink PROTOARGs((struct CDFstruct *CDF, vFILE *fp, Int32 num, Logical zEntry, OFF_T AEDRhead, Int32 numEntries, Int32 maxEntry, Logical debug)); -static CDFstatus ValidateVariableLinks PROTOARGs((struct CDFstruct *CDF, vFILE *fp, Logical zVar, Logical debug)); -static CDFstatus ValidateVariableValueLinks PROTOARGs((struct CDFstruct *CDF, vFILE *fp, Int32 lastRec, OFF_T headVXR, Logical debug)); -static struct CDRstruct64 CDR; -static struct GDRstruct64 GDR; -static int rVars, zVars; -static int numAttrs; - -/****************************************************************************** -* QuitCDF. -******************************************************************************/ - -static CDFstatus QuitCDF (char *why, OFF_T offset, int isize, int num, - void *value1,void *value2, Logical debug) -{ - - if (debug) { - char text[151], texta[41]; - text[0] = NUL; - strcpyX (text, why, 150); - if (offset >= 0) { -#if !defined(win32) && !defined(__MINGW32__) - snprintf (texta, (size_t) sizeof(texta), - " (@%lld) ", (long long) offset); -#else - snprintf (texta, (size_t) sizeof(texta), - " (@%I64d) ", (long long) offset); -#endif - strcatX (text, texta, 150); - } - if (strlen(why) < 150) { - if (num == 2) { /* Two argument values to show. */ - if (isize == 4) { /* Each one is a 4-byte int type. */ - /* Each int is up to 10 digits + sign. */ - char text2[2 * 11 + 6 + 1]; - text2[0] = (char) NUL; - snprintf (text2, (size_t) sizeof(text2), - "(%ld vs %ld)", (long) *(int *)value1, - (long) *(int *)value2); - strcatX (text, text2, 150); - } else if (isize == 8) { /* Each one is a 8-byte long long type. */ - /* Each long long is up to 19 digits + sign. */ - char text2[2 * 20 + 6 + 1]; - text2[0] = (char) NUL; -#if !defined(win32) && !defined(__MINGW32__) - snprintf (text2, (size_t) sizeof(text2), - "(%lld vs %lld)", *(long long *)value1, *(long long *)value2); -#else - snprintf (text2, (size_t) sizeof(text2), - "(%I64d vs %I64d)", *(long long *)value1, *(long long *)value2); -#endif - strcatX (text, text2, 150); - } else { /* Each one is a string. */ - char *text2; - size_t len = strlen ((char *) value1) + strlen ((char *) value2) + 6 - + 1; - text2 = (char *) cdf_AllocateMemory (len, NULL); - if (text2 != NULL) { - text2[0] = (char) NUL; - snprintf (text2, len, "(%s vs %s)", (char *)value1, (char *)value2); - strcatX (text, text2, 150); - cdf_FreeMemory (text2, NULL); - } - } - } else { /* Only one argument value to show. */ - if (isize == 4) { /* 4 extra chars are for 2 " ", "(", and ")". */ - char text2[11 + 2 + 1]; - text2[0] = (char) NUL; - snprintf (text2, (size_t) sizeof(text2), - "(%ld)", (long) *(int *)value1); - strcatX (text, text2, 150); - } else if (isize == 8) { - char text2[20 + 2 + 1]; - text2[0] = (char) NUL; -#if !defined(win32) && !defined(__MINGW32__) - snprintf (text2, (size_t) sizeof(text2), - "(%lld)", *(long long *)value1); -#else - snprintf (text2, (size_t) sizeof(text2), - "(%I64d)", *(long long *)value1); -#endif - strcatX (text, text2, 150); - } else { - char *text2; - size_t len = strlen ((char *) value1) + 2 + 1; - text2 = (char *) cdf_AllocateMemory (len, NULL); - if (text2 != NULL) { - text2[0] = (char) NUL; - snprintf (text2, len, "(%s)", (char *)value1); - strcatX (text, text2, 150); - cdf_FreeMemory (text2, NULL); - } - } - } - } - printf ("ERROR...%s\n", text); - } - return CV3C; -} - -/****************************************************************************** -* ValidateCDF64. -* Start to validate each internal record in a CDF file. -******************************************************************************/ - -STATICforIDL CDFstatus ValidateCDF64 (struct CDFstruct *CDF, vFILE *CDFfp, - OFF_T offset, OFF_T fileSize64, - Logical debug) -{ - OFF_T recordSize; - Int32 recordType; - CDFstatus status; - - /**************************************************************************** - * Read internal records from beginning of the file until EOF (or illegal - * record) reached. - ****************************************************************************/ - if (!SEEKv64(CDFfp,offset,vSEEK_SET)) return CRE; - for (;;) { - /************************************************************************* - * Read record size. - *************************************************************************/ - offset = V_tell64 (CDFfp); - if (offset == fileSize64) break; - if (!Read64_64(CDFfp,&recordSize)) return CRE; - if (recordSize < 1 || recordSize > fileSize64) - return QuitCDF ("CDF: an invalid internal record size ", offset, - 8, 1, &recordSize, 0, debug); - /************************************************************************* - * Read record type. - *************************************************************************/ - if (!Read32_64(CDFfp,&recordType)) return CRE; - /************************************************************************* - * Based on the record type... - *************************************************************************/ - switch ((int)recordType) { - /********************************************************************** - * Compressed CDF Record (CCR). - **********************************************************************/ - case CCR_: { - offset = offset + recordSize; - if (!SEEKv64(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * CDF Descriptor Record (CDR). - **********************************************************************/ - case CDR_: { - numAttrs = rVars = zVars = 0; - status = ValidateCDR (CDFfp, offset, debug); - if (status != CDF_OK) return status; - status = ValidateGDR (CDFfp, CDR.GDRoffset, debug); - if (status != CDF_OK) return status; - offset = offset + recordSize; - if (!SEEKv64(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Global Descriptor Record (GDR). - **********************************************************************/ - case GDR_: { - offset = offset + recordSize; - if (!SEEKv64(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Attribute Descriptor Record (ADR). - **********************************************************************/ - case ADR_: { - ++numAttrs; - offset = offset + recordSize; - if (!SEEKv64(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Attribute Entry Descriptor Record (AgrEDR or AzEDR). - **********************************************************************/ - case AgrEDR_: - case AzEDR_: { - offset = offset + recordSize; - if (!SEEKv64(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Variable Descriptor Record (rVDR or zVDR). - **********************************************************************/ - case rVDR_: - case zVDR_: { - Logical zVar = (recordType == zVDR_); - if (zVar) { - ++zVars; - } else { - ++rVars; - } - offset = offset + recordSize; - if (!SEEKv64(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Variable indeX Record (VXR). - **********************************************************************/ - case VXR_: { - offset = offset + recordSize; - if (!SEEKv64(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Variable Values Record (VVR). - **********************************************************************/ - case VVR_: { - status = ValidateVVR (CDFfp, offset, debug); - if (status != CDF_OK) return status; - if (recordSize < VVR_BASE_SIZE64) - return QuitCDF ("CDF(VVR): record size is invalid ", offset, - 8, 1, &recordSize, 0, debug); - offset = offset + recordSize; - if (!SEEKv64(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Compressed Variable Values Record (CVVR). - **********************************************************************/ - case CVVR_: { - status = ValidateCVVR (CDFfp, offset, debug); - if (status != CDF_OK) return status; - offset = offset + recordSize; - if (!SEEKv64(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Compressed Parameters Record (CPR). - **********************************************************************/ - case CPR_: { - offset = offset + recordSize; - if (!SEEKv64(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Sparseness Parameters Record (SPR). - **********************************************************************/ - case SPR_: { - offset = offset + recordSize; - if (!SEEKv64(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Unused internal record - **********************************************************************/ - case UIR_: { - offset = offset + recordSize; - if (!SEEKv64(CDFfp,offset,vSEEK_SET)) return CRE; - break; - } - /********************************************************************** - * Illegal record type. - **********************************************************************/ - default: { - return QuitCDF ("CDF: an invalid internal record type", offset, - 4, 1, &recordType, 0, debug); - } - } - } - /**************************************************************************** - * Check attribute links and their attribute entries. - ****************************************************************************/ - if (GDR.NumAttr != numAttrs) - return QuitCDF ("CDF: number of attributes does not match: ", (OFF_T) -1, - 4, 2, &GDR.NumAttr, &numAttrs, debug); - if (numAttrs > 0) { - status = ValidateAttributeLinks(CDF, CDFfp, debug); - if (status != CDF_OK) return status; - } - /**************************************************************************** - * Check rVariable links and their data. - ****************************************************************************/ - if (GDR.NrVars != rVars) - return QuitCDF ("CDF: number of rVariables does not match: ", (OFF_T) -1, - 4, 2, &GDR.NrVars, &rVars, debug); - if (rVars > 0) { - status = ValidateVariableLinks(CDF, CDFfp, FALSE, debug); - if (status != CDF_OK) return status; - } - /**************************************************************************** - * Check zVariable links and their data. - ****************************************************************************/ - if (GDR.NzVars != zVars) - return QuitCDF ("CDF: number of zVariables does not match: ", (OFF_T) -1, - 4, 2, &GDR.NzVars, &zVars, debug); - if (zVars > 0) { - status = ValidateVariableLinks(CDF, CDFfp, TRUE, debug); - if (status != CDF_OK) return status; - } - return CDF_OK; -} - -/****************************************************************************** -* ValidateCDR. -******************************************************************************/ - -static CDFstatus ValidateCDR (vFILE *fp, OFF_T offset, Logical debug) -{ - Int32 actualEncoding; - CDFstatus status; - - if (debug) -#if defined(win32) || defined(__MINGW32__) - printf(" Checking CDR...@%I64d\n", (long long) offset); -#else - printf(" Checking CDR...@%lld\n", (long long) offset); -#endif - status = ReadCDR64 (fp, offset, - CDR_RECORD, &CDR, NULL, - CDR_NULL); - if (status != CDF_OK) return status; - if (CDR.RecordType != CDR_) - return QuitCDF ("CDF: record type is invalid ", offset, - 4, 1, &(CDR.RecordType), 0, debug); - if (CDR.RecordSize < CDR_BASE_SIZE64 || - CDR.RecordSize > CDR_MAX_SIZE64) - return QuitCDF ("CDF: record size is invalid ", offset, - 8, 1, &(CDR.RecordSize), 0, debug); - if (CDR.GDRoffset < 1) - return QuitCDF ("CDF: offset to GDR is invalid ", offset, - 8, 1, &(CDR.GDRoffset), 0, debug); - if (CDR.Version != 3) - return QuitCDF ("CDF: version number is invalid ", offset, - 4, 1, &(CDR.Version), 0, debug); - if (CDR.Release < 0) - return QuitCDF ("CDF: release number is invalid ", offset, - 4, 1, &(CDR.Release), 0, debug); - if (CDR.Increment < 0) - return QuitCDF ("CDF: increment number is invalid ", offset, - 4, 1, &(CDR.Increment), 0, debug); - if (!ValidEncoding(CDR.Encoding,&actualEncoding)) - return QuitCDF ("CDF: encoding is invalid ", offset, - 4, 1, &(CDR.Encoding), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateGDR. -******************************************************************************/ - -static CDFstatus ValidateGDR (vFILE *fp, OFF_T offset, Logical debug) -{ - int i; - CDFstatus status; - - if (debug) -#if defined(win32) || defined(__MINGW32__) - printf(" Checking GDR...@%I64d\n", (long long) offset); -#else - printf(" Checking GDR...@%lld\n", (long long) offset); -#endif - status = ReadGDR64 (fp, offset, - GDR_RECORD, &GDR, - GDR_NULL); - if (status != CDF_OK) return status; - if (GDR.RecordType != GDR_) - return QuitCDF ("CDF(GDR): record type is invalid ", offset, - 4, 1, &(GDR.RecordType), 0, debug); - if (GDR.RecordSize < GDR_BASE_SIZE64 || - GDR.RecordSize > GDR_MAX_SIZE64) - return QuitCDF ("CDF(GDR): record size is invalid ", offset, - 8, 1, &(GDR.RecordSize), 0, debug); - if (GDR.NrVars < 0 || (GDR.NrVars > 0 && GDR.rVDRhead < 1)) - return QuitCDF ("CDF(GDR): NrVars or their link is invalid ", offset, - 4, 1, &(GDR.NrVars), 0, debug); - if (GDR.NumAttr < 0 || (GDR.NumAttr > 0 && GDR.ADRhead < 1)) - return QuitCDF ("CDF(GDR): number of attributes or their link is invalid ", offset, - 4, 1, &(GDR.NumAttr), 0, debug); - if (GDR.rMaxRec < -1) - return QuitCDF ("CDF(GDR): max rVars record is invalid ", offset, - 4, 1, &(GDR.rMaxRec), 0, debug); - if (GDR.rNumDims < 0 || GDR.rNumDims > CDF_MAX_DIMS) - return QuitCDF ("CDF(GDR): number of dimensions for rVars is invalid ", offset, - 4, 1, &(GDR.rNumDims), 0, debug); - if (GDR.NzVars < 0 || (GDR.NzVars > 0 && GDR.zVDRhead < 1)) - return QuitCDF ("CDF(GDR): NzVars or their link is invalid ", offset, - 4, 1, &(GDR.NzVars), 0, debug); - if (GDR.UIRhead < 0) - return QuitCDF ("CDF(GDR): offset to UIR is invalid ", offset, - 8, 1, &(GDR.UIRhead), 0, debug); - for (i = 0; i < (int)GDR.rNumDims; ++i) - if (GDR.rDimSizes[i] < 1) - return QuitCDF ("CDF(GDR): dimensional size is invalid ", offset, - 4, 1, &(GDR.rDimSizes[i]), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateADR. -******************************************************************************/ - -static CDFstatus ValidateADR (struct CDFstruct *CDF, vFILE *fp, OFF_T offset, - Logical debug) -{ - struct ADRstruct64 ADR; - CDFstatus status; - - if (debug) -#if defined(win32) || defined(__MINGW32__) - printf(" Checking ADR...@%I64d\n", (long long) offset); -#else - printf(" Checking ADR...@%lld\n", (long long) offset); -#endif - status = ReadADR64 (fp, offset, - ADR_RECORD, &ADR, - ADR_NULL); - if (status != CDF_OK) return status; - if (ADR.RecordType != ADR_) - return QuitCDF ("CDF(ADR): record type is invalid ", offset, - 4, 1, &(ADR.RecordType), 0, debug); - if (ADR.RecordSize < ADR_BASE_SIZE64 || - ADR.RecordSize > ADR_MAX_SIZE64) - return QuitCDF ("CDF(ADR): record size is invalid ", offset, - 8, 1, &(ADR.RecordSize), 0, debug); - if (ADR.ADRnext < 0 || ((ADR.Num < (GDR.NumAttr-1)) && ADR.ADRnext == 0)) - return QuitCDF ("CDF(ADR): offset to next ADR is invalid ", offset, - 8, 1, &(ADR.ADRnext), 0, debug); - if (ADR.AgrEDRhead < 0 || (ADR.NgrEntries > 0 && ADR.AgrEDRhead == 0)) - return QuitCDF ("CDF(ADR): offset to AgrEDR is invalid ", offset, - 8, 1, &(ADR.AgrEDRhead), 0, debug); - if (!ValidAttrScope(ADR.Scope)) - return QuitCDF ("CDF(ADR): scope is invalid ", offset, - 4, 1, &(ADR.Scope), 0, debug); - if (ADR.Num < 0 || ADR.Num > GDR.NumAttr) - return QuitCDF ("CDF(ADR): attribute number is invalid ", offset, - 4, 2, &(ADR.Num), &(GDR.NumAttr), debug); - if (ADR.NgrEntries < 0) - return QuitCDF ("CDF(ADR): number of g/rEntries is invalid ", offset, - 4, 1, &(ADR.NgrEntries), 0, debug); - if (ADR.MAXgrEntry < -1) - return QuitCDF ("CDF(ADR): max g/rEntry is invalid ", offset, - 4, 1, &(ADR.MAXgrEntry), 0, debug); - if ((ADR.Scope == VARIABLE_SCOPE) && (ADR.MAXgrEntry < (ADR.NgrEntries-1))) - return QuitCDF ("CDF(ADR): max rEntry is invalid ", offset, - 4, 2, &(ADR.MAXgrEntry), &(ADR.NgrEntries), debug); - if (ADR.AzEDRhead < 0 || (ADR.NzEntries > 0 && ADR.AzEDRhead == 0)) - return QuitCDF ("CDF(ADR): offset to next AzEDR is invalid ", offset, - 8, 1, &(ADR.AzEDRhead), 0, debug); - if ((ADR.Scope == VARIABLE_SCOPE) && (ADR.MAXzEntry < (ADR.NzEntries-1))) - return QuitCDF ("CDF(ADR): max zEntry is invalid ", offset, - 4, 2, &(ADR.MAXzEntry), &(ADR.NzEntries), debug); - if (!ValidAttrName(ADR.Name)) - return QuitCDF ("CDF(ADR): attribute name is invalid ", offset, - 0, 1, ADR.Name, 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateAgrEDR/AzEDR. -******************************************************************************/ - -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", (long long) offset); -#else - printf(" Checking AEDR...@%lld\n", (long long) 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; -} - -/****************************************************************************** -* ValidateVDR/zVDR. -******************************************************************************/ - -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", (long long) offset); -#else - printf(" Checking VDR...@%lld\n", (long long) 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; -} - -/****************************************************************************** -* ValidateVXR. -******************************************************************************/ - -static CDFstatus ValidateVXR (vFILE *fp, OFF_T offset, Int32 lastRec, Logical debug) -{ - struct VXRstruct64 VXR; - int i; - Int32 irType; - CDFstatus status; - - if (debug) -#if defined(win32) || defined(__MINGW32__) - printf(" Checking VXR...@%I64d\n", (long long) offset); -#else - printf(" Checking VXR...@%lld\n", (long long) offset); -#endif - status = ReadVXR64 (fp, offset, - VXR_RECORD, &VXR, - VXR_NULL); - if (status != CDF_OK) return status; - if (VXR.RecordType != VXR_) - return QuitCDF ("CDF(VXR): record type is invalid ", offset, - 4, 1, &(VXR.RecordType), 0, debug); - if (VXR.RecordSize != (VXR_FIRSTREC_OFFSET64 + 16 * VXR.Nentries)) - return QuitCDF ("CDF(VXR): record size is invalid ", offset, - 8, 1, &(VXR.RecordSize), 0, debug); - if (VXR.Nentries < 0 || VXR.Nentries > MAX_VXR_ENTRIES) - return QuitCDF ("CDF(VXR): number of entries is invalid ", offset, - 4, 1, &(VXR.Nentries), 0, debug); - if (VXR.NusedEntries < 0 || VXR.NusedEntries > VXR.Nentries) - return QuitCDF ("CDF(VXR): number of used entries is invalid ", offset, - 4, 2, &(VXR.NusedEntries), &(VXR.Nentries), debug); - if (VXR.VXRnext > 0) { - if (VXR.Last[VXR.NusedEntries-1] > lastRec) - return QuitCDF ("CDF(VXR): a variable last record does not match in a Variable Index Record: ", offset, - 4, 2, &(VXR.Last[VXR.NusedEntries-1]), &lastRec, debug); - status = ValidateVXR (fp, VXR.VXRnext, lastRec, debug); - if (status != CDF_OK) return status; - } else if (VXR.VXRnext < 0) { - return QuitCDF ("CDF(VXR): a link offset to next record is negative in a Variable Index Record: ", offset, - 8, 1, &(VXR.VXRnext), 0, debug); - } - - for (i = 0; i < VXR.NusedEntries; ++i) { - if (VXR.First[i] < 0 || VXR.Last[i] < 0 || VXR.First[i] > VXR.Last[i]) - return QuitCDF ("CDF(VXR): entry value for first/last is invalid ", offset, - 4, 2, &(VXR.First[i]), &(VXR.Last[i]), debug); - if (VXR.Offset[i] < 1) - return QuitCDF ("CDF(VXR): entry offset is invalid ", offset, - 8, 1, &(VXR.Offset[i]), 0, debug); - status = ReadIrType64 (fp, VXR.Offset[i], &irType); - if (status != CDF_OK) return status; - if (irType != VXR_ && irType != VVR_ && irType != CVVR_) - return QuitCDF ("CDF(VXR): entry value for offset is invalid ", offset, - 8, 1, &(VXR.Offset[i]), 0, debug); - if (irType == VXR_ && VXR.Offset[i] != offset) { - status = ValidateVXR (fp, VXR.Offset[i], lastRec, debug); - if (status != CDF_OK) return status; - } - } - return CDF_OK; -} - -/****************************************************************************** -* ValidateVVR. -******************************************************************************/ - -static CDFstatus ValidateVVR (vFILE *fp, OFF_T offset, Logical debug) -{ - struct VVRstruct64 VVR; - CDFstatus status; - - if (debug) -#if defined(win32) || defined(__MINGW32__) - printf(" Checking VVR...@%I64d\n", (long long) offset); -#else - printf(" Checking VVR...@%lld\n", (long long) offset); -#endif - status = ReadVVR64 (fp, offset, - VVR_RECORDx, &VVR, - VVR_NULL); - if (status != CDF_OK) return status; - if (VVR.RecordType != VVR_) - return QuitCDF ("CDF(VVR): record type is invalid ", offset, - 4, 1, &(VVR.RecordType), 0, debug); - if (VVR.RecordSize < VVR_BASE_SIZE64) - return QuitCDF ("CDF(VVR): record size is invalid ", offset, - 8, 1, &(VVR.RecordSize), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateUIR. -******************************************************************************/ - -static CDFstatus ValidateUIR (vFILE *fp, OFF_T offset, Logical debug) -{ - struct UIRstruct64 UIR; - CDFstatus status; - - if (debug) -#if defined(win32) || defined(__MINGW32__) - printf(" Checking UIR...@%I64d\n", (long long) offset); -#else - printf(" Checking UIR...@%lld\n", (long long) offset); -#endif - status = ReadUIR64 (fp, offset, - UIR_RECORD, &UIR, - UIR_NULL); - if (status != CDF_OK) return status; - if (UIR.RecordType != UIR_) - return QuitCDF ("CDF(UIR): record type is invalid ", offset, - 4, 1, &(UIR.RecordType), 0, debug); - if (UIR.RecordSize < UIR_BASE_SIZE64) - return QuitCDF ("CDF(UIR): record size is invalid ", offset, - 8, 1, &(UIR.RecordSize), 0, debug); - if (UIR.NextUIR < 0) - return QuitCDF ("CDF(UIR): offset to next UIR is invalid ", offset, - 8, 1, &(UIR.NextUIR), 0, debug); - if (UIR.PrevUIR < 0) - return QuitCDF ("CDF(UIR): offset to previous UIR is invalid ", offset, - 8, 1, &(UIR.PrevUIR), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateCCR. -******************************************************************************/ - -static CDFstatus ValidateCCR (vFILE *fp, OFF_T offset, Logical debug) -{ - struct CCRstruct64 CCR; - CDFstatus status; - - if (debug) -#if defined(win32) || defined(__MINGW32__) - printf(" Checking CCR...@%I64d\n", (long long) offset); -#else - printf(" Checking CCR...@%lld\n", (long long) offset); -#endif - status = ReadCCR64 (fp, offset, - CCR_RECORD, &CCR, - CCR_NULL); - if (status != CDF_OK) return status; - if (CCR.RecordType != CCR_) - return QuitCDF ("CDF(CCR): record type is invalid ", offset, - 4, 1, &(CCR.RecordType), 0, debug); - if (CCR.RecordSize < CCR_BASE_SIZE64) - return QuitCDF ("CDF(CCR): record size is invalid ", offset, - 8, 1, &(CCR.RecordSize), 0, debug); - if (CCR.uSize < 0) - return QuitCDF ("CDF(CCR): uncompressed file size is invalid ", offset, - 8, 1, &(CCR.uSize), 0, debug); - if (CCR.CPRoffset < 0) - return QuitCDF ("CDF(CCR): offset to CPR is invalid ", offset, - 8, 1, &(CCR.CPRoffset), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateCPR. -******************************************************************************/ - -static CDFstatus ValidateCPR (vFILE *fp, OFF_T offset, Logical debug) -{ - struct CPRstruct64 CPR; - int i; - CDFstatus status; - long cType, cParms[1]; - - if (debug) -#if defined(win32) || defined(__MINGW32__) - printf(" Checking CPR...@%I64d\n", (long long) offset); -#else - printf(" Checking CPR...@%lld\n", (long long) offset); -#endif - status = ReadCPR64 (fp, offset, - CPR_RECORD, &CPR, - CPR_NULL); - if (status != CDF_OK) return status; - if (CPR.RecordType != CPR_) - return QuitCDF ("CDF(CPR): record type is invalid ", offset, - 4, 1, &(CPR.RecordType), 0, debug); - if (CPR.RecordSize != (CPR_BASE_SIZE64 + CPR.pCount * sizeof(Int32))) - return QuitCDF ("CDF(CPR): reocrd size is invalid ", offset, - 8, 1, &(CPR.RecordSize), 0, debug); - if (CPR.pCount != 1) - return QuitCDF ("CDF(CPR): compression parameter count is invalid ", offset, - 4, 1, &(CPR.pCount), 0, debug); - cType = (long) CPR.cType; - cParms[0] = (long) CPR.cParms[0]; - if (ValidateCompression64(cType, cParms) != CDF_OK) - return QuitCDF ("CDF(CPR): compression parameter is invalid ", offset, - 4, 1, &(CPR.cType), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateSPR. -******************************************************************************/ - -static CDFstatus ValidateSPR (vFILE *fp, OFF_T offset, Logical debug) -{ - struct SPRstruct64 SPR; - int i; - CDFstatus status; - - if (debug) -#if defined(win32) || defined(__MINGW32__) - printf(" Checking SPR...@%I64d\n", (long long) offset); -#else - printf(" Checking SPR...@%lld\n", (long long) offset); -#endif - status = ReadSPR64 (fp, offset, - SPR_RECORD, &SPR, - SPR_NULL); - if (status != CDF_OK) return status; - if (SPR.RecordType != SPR_) - return QuitCDF ("CDF(SPR): record type is invalid ", offset, - 4, 1, &(SPR.RecordType), 0, debug); - if (SPR.RecordSize != (SPR_BASE_SIZE64 + SPR.pCount * sizeof(Int32))) - return QuitCDF ("CDF(SPR): record size is invalid ", offset, - 8, 1, &(SPR.RecordSize), 0, debug); - if (SPR.pCount < 1 || SPR.pCount > CDF_MAX_PARMS) - return QuitCDF ("CDF(SPR): sparseness parameter count is invalid ", offset, - 4, 1, &(SPR.pCount), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateCVVR. -******************************************************************************/ - -static CDFstatus ValidateCVVR (vFILE *fp, OFF_T offset, Logical debug) -{ - struct CVVRstruct64 CVVR; - CDFstatus status; - - if (debug) -#if defined(win32) || defined(__MINGW32__) - printf(" Checking CVVR...@%I64d\n", (long long) offset); -#else - printf(" Checking CVVR...@%lld\n", (long long) offset); -#endif - status = ReadCVVR64 (fp, offset, - CVVR_RECORDx, &CVVR, - CVVR_NULL); - if (status != CDF_OK) return status; - if (CVVR.RecordSize < CVVR_BASE_SIZE64) - return QuitCDF ("CDF(CVVR): record size is invalid ", offset, - 8, 1, &(CVVR.RecordSize), 0, debug); - if (CVVR.cSize < 0) - return QuitCDF ("CDF(CVVR): uncompressed records size is invalid ", offset, - 8, 1, &(CVVR.cSize), 0, debug); - return CDF_OK; -} - -/****************************************************************************** -* ValidateAttributeLinks. -******************************************************************************/ - -static CDFstatus ValidateAttributeLinks (struct CDFstruct *CDF, vFILE *fp, - Logical debug) -{ - CDFstatus status; - OFF_T offset, nextADR, AgrEDRhead, AzEDRhead; - Int32 num, numgrEntries, maxgrEntry, numzEntries, maxzEntry; - int ix, *visit; - - visit = (int *) cdf_AllocateMemory ((size_t)GDR.NumAttr * sizeof(Int32), NULL); - if (visit == NULL) return BAD_MALLOC; - for (ix = 0; ix < GDR.NumAttr; ++ix) visit[ix] = 0; - offset = GDR.ADRhead; - for (ix = 0; ix < GDR.NumAttr; ++ix) { - status = ValidateADR (CDF, fp, offset, debug); - if (status != CDF_OK) { - cdf_FreeMemory (visit, NULL); - return status; - } - status = ReadADR64 (fp, offset, - ADR_NUM, &num, - ADR_ADRNEXT, &nextADR, - ADR_AgrEDRHEAD, &AgrEDRhead, - ADR_NgrENTRIES, &numgrEntries, - ADR_MAXgrENTRY, &maxgrEntry, - ADR_AzEDRHEAD, &AzEDRhead, - ADR_NzENTRIES, &numzEntries, - ADR_MAXzENTRY, &maxzEntry, - ADR_NULL); - if (numgrEntries > 0) { - status = ValidateAttributeEntryLink (CDF, fp, num, FALSE, AgrEDRhead, - numgrEntries, maxgrEntry, debug); - if (status != CDF_OK) { - cdf_FreeMemory (visit, NULL); - return status; - } - } - if (numzEntries > 0) { - status = ValidateAttributeEntryLink (CDF, fp, num, TRUE, AzEDRhead, - numzEntries, maxzEntry, debug); - if (status != CDF_OK) { - cdf_FreeMemory (visit, NULL); - return status; - } - } - visit[num] = 1; - offset = nextADR; - } - for (ix = 0; ix < GDR.NumAttr; ++ix) { - if (visit[ix] == 0) { - cdf_FreeMemory (visit, NULL); - return QuitCDF ("CDF: an attribute unreachable in attribute link: ", (OFF_T) -1, - 4, 1, &ix, 0, debug); - } - } - cdf_FreeMemory (visit, NULL); - return CDF_OK; -} - -/****************************************************************************** -* ValidateAttributeEntryLink. -******************************************************************************/ - -static CDFstatus ValidateAttributeEntryLink (struct CDFstruct *CDF, vFILE *fp, - Int32 num, Logical zEntry, OFF_T EDRhead, - Int32 numEntries, Int32 maxEntry, - Logical debug) -{ - CDFstatus status; - OFF_T offset, nextAEDR; - Int32 entryNum, lastNum, *visits; - int ix, iy; - - offset = EDRhead; - lastNum = 0; - visits = (Int32 *) cdf_AllocateMemory ((size_t)numEntries * sizeof(Int32), NULL); - if (visits == NULL) return BAD_MALLOC; - for (ix = 0; ix < numEntries; ++ix) visits[ix] = 0; - ix = 0; - while (offset != 0) { - status = ValidateAEDR (CDF, fp, offset, num, maxEntry, zEntry, debug); - if (status != CDF_OK) { - cdf_FreeMemory (visits, NULL); - return status; - } - status = ReadAEDR64 (fp, offset, - AEDR_NUM, &entryNum, - AEDR_AEDRNEXT, &nextAEDR, - AEDR_NULL); - if (ix > 0) { - for (iy = 0; iy < ix; ++iy) { - if (visits[iy] == entryNum) { - cdf_FreeMemory (visits, NULL); - return QuitCDF ("CDF: entry number is repeating in an attribute entry link: ", (OFF_T) -1, - 4, 1, &entryNum, 0, debug); - } - } - } - if (ix == (int) numEntries) { - cdf_FreeMemory (visits, NULL); - return QuitCDF ("CDF: number of entries is more than maximum in an attribute entry link: ", (OFF_T) -1, - 4, 1, &ix, 0, debug); - } - visits[ix] = entryNum; - ++ix; - if (lastNum < entryNum) lastNum = entryNum; - offset = nextAEDR; - } - if (lastNum != maxEntry) { - cdf_FreeMemory (visits, NULL); - return QuitCDF ("CDF: last entry number is not the maximum entry number in an attribute entry link: ", (OFF_T) -1, - 4, 2, &lastNum, &maxEntry, debug); - } - cdf_FreeMemory (visits, NULL); - return CDF_OK; -} - -/****************************************************************************** -* ValidateVariableLinks. -******************************************************************************/ - -static CDFstatus ValidateVariableLinks (struct CDFstruct *CDF, vFILE *fp, - Logical zVar, Logical debug) -{ - CDFstatus status; - OFF_T offset, headVXR, tailVXR, nextVXR, nextVDR, cprOffset; - Int32 num, lastRec, flags; - int ix, numVars, *visit; - - numVars = (zVar ? GDR.NzVars : GDR.NrVars); - visit = (int *) cdf_AllocateMemory(numVars * sizeof(Int32), NULL); - for (ix = 0; ix < numVars; ++ix) visit[ix] = 0; - offset = (zVar ? GDR.zVDRhead : GDR.rVDRhead); - for (ix = 0; ix < numVars; ++ix) { - status = ValidateVDR (CDF, fp, offset, zVar, debug); - if (status != CDF_OK) { - cdf_FreeMemory (visit, NULL); - return status; - } - status = ReadVDR64 (CDF, fp, offset, zVar, - VDR_NUM, &num, - VDR_FLAGS, &flags, - VDR_MAXREC, &lastRec, - VDR_VDRNEXT, &nextVDR, - VDR_CPRorSPR, &cprOffset, - VDR_VXRHEAD, &headVXR, - VDR_VXRTAIL, &tailVXR, - VDR_NULL); - if (CDF->singleFile && lastRec > -1) { - status = ValidateVariableValueLinks (CDF, fp, lastRec, headVXR, debug); - if (status != CDF_OK) { - cdf_FreeMemory (visit, NULL); - return status; - } - } - if (VARcompressionBITset(flags)) { - status = ValidateCPR (fp, cprOffset, debug); - if (status != CDF_OK) { - cdf_FreeMemory (visit, NULL); - return status; - } - } - visit[num] = 1; - offset = nextVDR; - } - - for (ix = 0; ix < numVars; ++ix) { - if (visit[ix] == 0) { - cdf_FreeMemory (visit, NULL); - if (zVar) - return QuitCDF ("CDF: a zVariable unreachable in the variable chain: ", (OFF_T) -1, - 4, 1, &ix, 0, debug); - else - return QuitCDF ("CDF: a rVariable unreachable in the variable chain: ", (OFF_T) -1, - 4, 1, &ix, 0, debug); - } - } - cdf_FreeMemory (visit, NULL); - if (offset != 0) { - status = ReadVDR64 (CDF, fp, offset, zVar, - VDR_NUM, &num, - VDR_VDRNEXT, &nextVDR, - VDR_NULL); - if (status == CDF_OK) { - if (num >= numVars) { - if (zVar) - return QuitCDF ("CDF(VDR): a zVariable unreachable in the variable chain: ", offset, - 4, 1, &num, 0, debug); - else - return QuitCDF ("CDF(VDR): a rVariable unreachable in the variable chain: ", offset, - 4, 1, &num, 0, debug); - } else { - if (zVar) - return QuitCDF ("CDF(VDR): a zVariable is repeated in the variable chain: ", offset, - 4, 1, &num, 0, debug); - else - return QuitCDF ("CDF(VDR): a rVariable unreachable in the variable chain: ", offset, - 4, 1, &num, 0, debug); - } - } - } - return CDF_OK; -} - -/****************************************************************************** -* ValidateVariableValueLinks. -******************************************************************************/ - -static CDFstatus ValidateVariableValueLinks (struct CDFstruct *CDF, vFILE *fp, - Int32 lastRec, OFF_T headVXR, - Logical debug) -{ - CDFstatus status; - - status = ValidateVXR (fp, headVXR, lastRec, debug); - if (status != CDF_OK) return status; - return CDF_OK; -} - diff --git a/cdf36_3-dist/src/lib/cdfwrite.c b/cdf36_3-dist/src/lib/cdfwrite.c deleted file mode 100644 index ed42122..0000000 --- a/cdf36_3-dist/src/lib/cdfwrite.c +++ /dev/null @@ -1,1090 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Write to internal record. -* -* Version 1.5a, 28-Feb-97, Hughes STX. -* -* Modification history: -* -* V1.0 4-Nov-93, J Love Original version. -* V1.1 15-Nov-94, J Love CDF V2.5. -* V1.2 5-Jan-95, J Love Encode/decode changes. -* V1.2a 30-Jan-95, J Love `Write32s' now checks count. -* V1.2b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.3 26-May-95, J Love CDF V2.4 compatibility mode. What? -* V1.4 14-Jun-95, J Love Use `ReadXYZ' routines. -* V1.4a 6-Sep-95, J Love CDFexport-related changes. -* V1.5 3-Apr-96, J Love CDF V2.6. -* V1.5a 28-Feb-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V3.2a 11-Apr-08, M Liu Modified Write32s to eliminate the potential -* buffer overflow. -* -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* Local macro definitions. -******************************************************************************/ - -#define CWE CDF_WRITE_ERROR - -/****************************************************************************** -* Write32. -******************************************************************************/ - -STATICforIDL Logical Write32 (fp, value) -vFILE *fp; -Int32 *value; -{ -#if defined(NETWORKbyteORDERcpu) - if (!WRITEv(value,(size_t)4,(size_t)1,fp)) return FALSE; -#else - Int32 tValue; - REVERSE4bIO (value, &tValue) - if (!WRITEv(&tValue,(size_t)4,(size_t)1,fp)) return FALSE; -#endif - return TRUE; -} - -/****************************************************************************** -* Write32s. -******************************************************************************/ - -STATICforIDL Logical Write32s (fp, buffer, count) -vFILE *fp; -Int32 *buffer; -int count; -{ -#define MAX_tBUFFER_SIZE 10 /* This must be set to the maximum - value that `count' may ever be. - Currently, that is either the - maximum number of dimensions or - the number of entries in a VXR. */ -#if defined(NETWORKbyteORDERcpu) - if (count == 0) return TRUE; - if (count < 0 || count > MAX_tBUFFER_SIZE) return FALSE; - if (!WRITEv(buffer,(size_t)4,(size_t)count,fp)) return FALSE; -#else - Int32 tBuffer[MAX_tBUFFER_SIZE]; int i; - if (count == 0) return TRUE; - if (count < 0 || count > MAX_tBUFFER_SIZE) return FALSE; - for (i = 0; i < count; i++) { - REVERSE4bIO (&buffer[i], &tBuffer[i]) - } - if (!WRITEv(tBuffer,(size_t)4,(size_t)count,fp)) return FALSE; -#endif - return TRUE; -} - -/****************************************************************************** -* WriteIrSize. -* The size is always in the first 4-byte field. -******************************************************************************/ - -STATICforIDL CDFstatus WriteIrSize (fp, offset, irSize) -vFILE *fp; -Int32 offset; -Int32 *irSize; -{ - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CWE; - if (!Write32(fp,irSize)) return CWE; - return CDF_OK; -} - -/****************************************************************************** -* WriteIrType. -* The type is always in the second 4-byte field. -******************************************************************************/ - -STATICforIDL CDFstatus WriteIrType (fp, offset, irType) -vFILE *fp; -Int32 offset; -Int32 *irType; -{ - long irTypeOffset = offset + sizeof(Int32); - if (!SEEKv(fp,irTypeOffset,vSEEK_SET)) return CWE; - if (!Write32(fp,irType)) return CWE; - return CDF_OK; -} - -/****************************************************************************** -* WriteCDR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteCDR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus WriteCDR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CDR_NULL: - va_end (ap); - return pStatus; - case CDR_RECORD: { - struct CDRstruct *CDR = va_arg (ap, struct CDRstruct *); - char *copyRight = va_arg (ap, char *); - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CWE; - if (!Write32(fp,&(CDR->RecordSize))) return CWE; - if (!Write32(fp,&(CDR->RecordType))) return CWE; - if (!Write32(fp,&(CDR->GDRoffset))) return CWE; - if (!Write32(fp,&(CDR->Version))) return CWE; - if (!Write32(fp,&(CDR->Release))) return CWE; - if (!Write32(fp,&(CDR->Encoding))) return CWE; - if (!Write32(fp,&(CDR->Flags))) return CWE; - if (!Write32(fp,&(CDR->rfuA))) return CWE; - if (!Write32(fp,&(CDR->rfuB))) return CWE; - if (!Write32(fp,&(CDR->Increment))) return CWE; - if (!Write32(fp,&(CDR->rfuD))) return CWE; - if (!Write32(fp,&(CDR->rfuE))) return CWE; - if (copyRight != NULL) { - if (!WRITEv(copyRight,CDF_COPYRIGHT_LEN,1,fp)) return CWE; - } - break; - } - case CDR_COPYRIGHT: { - char *copyRight = va_arg (ap, char *); - long tOffset = offset + CDR_COPYRIGHT_OFFSET; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!WRITEv(copyRight,CDF_COPYRIGHT_LEN,1,fp)) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); - long tOffset = offset; - switch (field) { - case CDR_RECORDSIZE: tOffset += CDR_RECORDSIZE_OFFSET; break; - case CDR_RECORDTYPE: tOffset += CDR_RECORDTYPE_OFFSET; break; - case CDR_GDROFFSET: tOffset += CDR_GDROFFSET_OFFSET; break; - case CDR_VERSION: tOffset += CDR_VERSION_OFFSET; break; - case CDR_RELEASE: tOffset += CDR_RELEASE_OFFSET; break; - case CDR_ENCODING: tOffset += CDR_ENCODING_OFFSET; break; - case CDR_FLAGS: tOffset += CDR_FLAGS_OFFSET; break; - case CDR_INCREMENT: tOffset += CDR_INCREMENT_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteGDR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteGDR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus WriteGDR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case GDR_NULL: - va_end (ap); - return pStatus; - case GDR_RECORD: { - struct GDRstruct *GDR = va_arg (ap, struct GDRstruct *); - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CWE; - if (!Write32(fp,&(GDR->RecordSize))) return CWE; - if (!Write32(fp,&(GDR->RecordType))) return CWE; - if (!Write32(fp,&(GDR->rVDRhead))) return CWE; - if (!Write32(fp,&(GDR->zVDRhead))) return CWE; - if (!Write32(fp,&(GDR->ADRhead))) return CWE; - if (!Write32(fp,&(GDR->eof))) return CWE; - if (!Write32(fp,&(GDR->NrVars))) return CWE; - if (!Write32(fp,&(GDR->NumAttr))) return CWE; - if (!Write32(fp,&(GDR->rMaxRec))) return CWE; - if (!Write32(fp,&(GDR->rNumDims))) return CWE; - if (!Write32(fp,&(GDR->NzVars))) return CWE; - if (!Write32(fp,&(GDR->UIRhead))) return CWE; - if (!Write32(fp,&(GDR->rfuC))) return CWE; - if (!Write32(fp,&(GDR->rfuD))) return CWE; - if (!Write32(fp,&(GDR->rfuE))) return CWE; - if (!Write32s(fp,GDR->rDimSizes,(int)GDR->rNumDims)) return CWE; - break; - } - case GDR_rDIMSIZES: { - Int32 *rDimSizes = va_arg (ap, Int32 *), rNumDims; long tOffset; - if (!sX(ReadGDR(fp,offset, - GDR_rNUMDIMS,&rNumDims, - GDR_NULL),&pStatus)) return pStatus; - tOffset = offset + GDR_rDIMSIZES_OFFSET; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32s(fp,rDimSizes,(int)rNumDims)) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); - Int32 tOffset = offset; - switch (field) { - case GDR_RECORDSIZE: tOffset += GDR_RECORDSIZE_OFFSET; break; - case GDR_RECORDTYPE: tOffset += GDR_RECORDTYPE_OFFSET; break; - case GDR_rVDRHEAD: tOffset += GDR_rVDRHEAD_OFFSET; break; - case GDR_zVDRHEAD: tOffset += GDR_zVDRHEAD_OFFSET; break; - case GDR_ADRHEAD: tOffset += GDR_ADRHEAD_OFFSET; break; - case GDR_EOF: tOffset += GDR_EOF_OFFSET; break; - case GDR_NrVARS: tOffset += GDR_NrVARS_OFFSET; break; - case GDR_NUMATTR: tOffset += GDR_NUMATTR_OFFSET; break; - case GDR_rMAXREC: tOffset += GDR_rMAXREC_OFFSET; break; - case GDR_rNUMDIMS: tOffset += GDR_rNUMDIMS_OFFSET; break; - case GDR_NzVARS: tOffset += GDR_NzVARS_OFFSET; break; - case GDR_UIRHEAD: tOffset += GDR_UIRHEAD_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteADR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteADR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus WriteADR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case ADR_NULL: - va_end (ap); - return pStatus; - case ADR_RECORD: { - struct ADRstruct *ADR = va_arg (ap, struct ADRstruct *); - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CWE; - if (!Write32(fp,&(ADR->RecordSize))) return CWE; - if (!Write32(fp,&(ADR->RecordType))) return CWE; - if (!Write32(fp,&(ADR->ADRnext))) return CWE; - if (!Write32(fp,&(ADR->AgrEDRhead))) return CWE; - if (!Write32(fp,&(ADR->Scope))) return CWE; - if (!Write32(fp,&(ADR->Num))) return CWE; - if (!Write32(fp,&(ADR->NgrEntries))) return CWE; - if (!Write32(fp,&(ADR->MAXgrEntry))) return CWE; - if (!Write32(fp,&(ADR->rfuA))) return CWE; - if (!Write32(fp,&(ADR->AzEDRhead))) return CWE; - if (!Write32(fp,&(ADR->NzEntries))) return CWE; - if (!Write32(fp,&(ADR->MAXzEntry))) return CWE; - if (!Write32(fp,&(ADR->rfuE))) return CWE; - if (!WRITEv(ADR->Name,CDF_ATTR_NAME_LEN,1,fp)) return CWE; - break; - } - case ADR_NAME: { - char *aName = va_arg (ap, char *); - long tOffset = offset + ADR_NAME_OFFSET; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!WRITEv(aName,CDF_ATTR_NAME_LEN,1,fp)) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case ADR_RECORDSIZE: tOffset += ADR_RECORDSIZE_OFFSET; break; - case ADR_RECORDTYPE: tOffset += ADR_RECORDTYPE_OFFSET; break; - case ADR_ADRNEXT: tOffset += ADR_ADRNEXT_OFFSET; break; - case ADR_AgrEDRHEAD: tOffset += ADR_AgrEDRHEAD_OFFSET; break; - case ADR_SCOPE: tOffset += ADR_SCOPE_OFFSET; break; - case ADR_NUM: tOffset += ADR_NUM_OFFSET; break; - case ADR_NgrENTRIES: tOffset += ADR_NgrENTRIES_OFFSET; break; - case ADR_MAXgrENTRY: tOffset += ADR_MAXgrENTRY_OFFSET; break; - case ADR_AzEDRHEAD: tOffset += ADR_AzEDRHEAD_OFFSET; break; - case ADR_NzENTRIES: tOffset += ADR_NzENTRIES_OFFSET; break; - case ADR_MAXzENTRY: tOffset += ADR_MAXzENTRY_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteAgrEDR/AzEDR. -* If the entry value is being written, it is assumed that the value passed -* in is in the host machine's encoding. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteAEDR (struct CDFstruct *CDF, vFILE *fp, - Int32 offset, ...) -#else -STATICforIDL CDFstatus WriteAEDR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - struct CDFstruct *CDF; vFILE *fp; Int32 offset; - VA_START (ap); - CDF = va_arg (ap, struct CDFstruct *); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case AEDR_NULL: - va_end (ap); - return pStatus; - case AEDR_RECORD: { - struct AEDRstruct *AEDR = va_arg (ap, struct AEDRstruct *); - void *value = va_arg (ap, void *); - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CWE; - if (!Write32(fp,&(AEDR->RecordSize))) return CWE; - if (!Write32(fp,&(AEDR->RecordType))) return CWE; - if (!Write32(fp,&(AEDR->AEDRnext))) return CWE; - if (!Write32(fp,&(AEDR->AttrNum))) return CWE; - if (!Write32(fp,&(AEDR->DataType))) return CWE; - if (!Write32(fp,&(AEDR->Num))) return CWE; - if (!Write32(fp,&(AEDR->NumElems))) return CWE; - if (!Write32(fp,&(AEDR->rfuA))) return CWE; - if (!Write32(fp,&(AEDR->rfuB))) return CWE; - if (!Write32(fp,&(AEDR->rfuC))) return CWE; - if (!Write32(fp,&(AEDR->rfuD))) return CWE; - if (!Write32(fp,&(AEDR->rfuE))) return CWE; - if (value != NULL) { - if (STRINGdataType(AEDR->DataType)) { - size_t len; char *newValue = NULL; - len = strlen ((char *)value); - if ((int)len < (int) AEDR->NumElems) { - int ix; - newValue = (char *) cdf_AllocateMemory ((size_t) AEDR->NumElems, - NULL); - memcpy (newValue, (char *)value, len); - for (ix = (int) len; ix < (int) AEDR->NumElems; ++ix) - *(newValue+ix) = (char) ' '; - } - if (!sX(WriteBuffer(CDF,fp,AEDR->DataType,AEDR->NumElems, - (newValue==NULL?value:(void *)newValue)), - &pStatus)) - return pStatus; - if (newValue != NULL) cdf_FreeMemory (newValue, NULL); - } else - if (!sX(WriteBuffer(CDF,fp,AEDR->DataType, - AEDR->NumElems,value),&pStatus)) return pStatus; - } - break; - } - case AEDR_VALUE: { - void *value = va_arg (ap, void *); - Int32 dataType, numElems; long tOffset; - if (!sX(ReadAEDR(fp,offset, - AEDR_DATATYPE,&dataType, - AEDR_NUMELEMS,&numElems, - AEDR_NULL),&pStatus)) return pStatus; - tOffset = offset + AEDR_VALUE_OFFSET; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (STRINGdataType(dataType)) { - size_t len; char *newValue = NULL; - len = strlen ((char *)value); - if ((int)len < (int) numElems) { - int ix; - newValue = (char *) cdf_AllocateMemory ((size_t) numElems, NULL); - memcpy (newValue, (char *)value, len); - for (ix = (int) len; ix < (int) numElems; ++ix) - *(newValue+ix) = (char) ' '; - } - if (!sX(WriteBuffer(CDF,fp,dataType,numElems, - (newValue==NULL?value:(void *)newValue)), - &pStatus)) - return pStatus; - if (newValue != NULL) cdf_FreeMemory (newValue, NULL); - } else - if (!sX(WriteBuffer(CDF,fp,dataType, - numElems,value),&pStatus)) return pStatus; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case AEDR_RECORDSIZE: tOffset += AEDR_RECORDSIZE_OFFSET; break; - case AEDR_RECORDTYPE: tOffset += AEDR_RECORDTYPE_OFFSET; break; - case AEDR_AEDRNEXT: tOffset += AEDR_AEDRNEXT_OFFSET; break; - case AEDR_ATTRNUM: tOffset += AEDR_ATTRNUM_OFFSET; break; - case AEDR_DATATYPE: tOffset += AEDR_DATATYPE_OFFSET; break; - case AEDR_NUM: tOffset += AEDR_NUM_OFFSET; break; - case AEDR_NUMELEMS: tOffset += AEDR_NUMELEMS_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriterVDR/zVDR. -* If the pad value is being written, it is assumed that the value passed -* in is in the host machine's encoding. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteVDR (struct CDFstruct *CDF, vFILE *fp, - Int32 offset, Logical zVar, ...) -#else -STATICforIDL CDFstatus WriteVDR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, zVar); -#else - struct CDFstruct *CDF; vFILE *fp; Int32 offset; Logical zVar; - VA_START (ap); - CDF = va_arg (ap, struct CDFstruct *); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); - zVar = va_arg (ap, Logical); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case VDR_NULL: - va_end (ap); - return pStatus; - case VDR_RECORD: { - struct VDRstruct *VDR = va_arg (ap, struct VDRstruct *); - void *padValue = va_arg (ap, void *); - Int32 nDims; - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CWE; - if (!Write32(fp,&(VDR->RecordSize))) return CWE; - if (!Write32(fp,&(VDR->RecordType))) return CWE; - if (!Write32(fp,&(VDR->VDRnext))) return CWE; - if (!Write32(fp,&(VDR->DataType))) return CWE; - if (!Write32(fp,&(VDR->MaxRec))) return CWE; - if (!Write32(fp,&(VDR->VXRhead))) return CWE; - if (!Write32(fp,&(VDR->VXRtail))) return CWE; - if (!Write32(fp,&(VDR->Flags))) return CWE; - if (!Write32(fp,&(VDR->sRecords))) return CWE; - if (!Write32(fp,&(VDR->rfuB))) return CWE; - if (!Write32(fp,&(VDR->rfuC))) return CWE; - if (!Write32(fp,&(VDR->rfuF))) return CWE; - if (!Write32(fp,&(VDR->NumElems))) return CWE; - if (!Write32(fp,&(VDR->Num))) return CWE; - if (!Write32(fp,&(VDR->CPRorSPRoffset))) return CWE; - if (!Write32(fp,&(VDR->blockingFactor))) return CWE; - if (!WRITEv(VDR->Name,CDF_VAR_NAME_LEN,1,fp)) return CWE; - if (zVar) { - if (!Write32(fp,&(VDR->zNumDims))) return CWE; - if (!Write32s(fp,VDR->zDimSizes, - (int)VDR->zNumDims)) return CWE; - } - if (zVar) - nDims = VDR->zNumDims; - else { - long tOffset = V_tell (fp); Int32 GDRoffset; - if (!sX(ReadCDR(fp,V2_CDR_OFFSET, - CDR_GDROFFSET,&GDRoffset, - CDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadGDR(fp,GDRoffset, - GDR_rNUMDIMS,&nDims, - GDR_NULL),&pStatus)) return pStatus; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - } - if (!Write32s(fp,VDR->DimVarys,(int)nDims)) return CWE; - if (PADvalueBITset(VDR->Flags) && padValue != NULL) { - if (STRINGdataType(VDR->DataType)) { - size_t len; char *newPad = NULL; - len = strlen ((char *)padValue); - if ((int)len < (int) VDR->NumElems) { - int ix; - newPad = (char *) cdf_AllocateMemory ((size_t) VDR->NumElems, - NULL); - memcpy (newPad, (char *)padValue, len); - for (ix = (int) len; ix < (int) VDR->NumElems; ++ix) - *(newPad+ix) = (char) ' '; - } - if (!sX(WriteBuffer(CDF,fp,VDR->DataType,VDR->NumElems, - (newPad==NULL?padValue:(void *)newPad)), - &pStatus)) - return pStatus; - if (newPad != NULL) cdf_FreeMemory (newPad, NULL); - } else - if (!sX(WriteBuffer(CDF,fp,VDR->DataType, - VDR->NumElems, - padValue),&pStatus)) return pStatus; - } - break; - } - case VDR_NAME: { - char *vName = va_arg (ap, char *); - long tOffset = offset + VDR_NAME_OFFSET; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!WRITEv(vName,CDF_VAR_NAME_LEN,1,fp)) return CWE; - break; - } - case VDR_zNUMDIMS: { - Int32 *numDims = va_arg (ap, Int32 *); - long tOffset = offset + zVDR_zNUMDIMS_OFFSET; - if (!zVar) return CDF_INTERNAL_ERROR; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32(fp,numDims)) return CWE; - break; - } - case VDR_zDIMSIZES: { - Int32 *zDimSizes = va_arg (ap, Int32 *), zNumDims; - int dimN; long tOffset; - if (!zVar) return CDF_INTERNAL_ERROR; - if (!sX(ReadVDR(CDF,fp,offset,zVar, - VDR_zNUMDIMS,&zNumDims, - VDR_NULL),&pStatus)) return pStatus; - tOffset = offset + zVDR_zDIMSIZES_OFFSET; - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - for (dimN = 0; dimN < zNumDims; dimN++) { - if (!Write32(fp,&(zDimSizes[dimN]))) return CWE; - } - break; - } - case VDR_DIMVARYS: { - Int32 *dimVarys = va_arg (ap, Int32 *), nDims; long tOffset; - if (zVar) { - if (!sX(ReadVDR(CDF,fp,offset,zVar, - VDR_zNUMDIMS,&nDims, - VDR_NULL),&pStatus)) return pStatus; - tOffset = offset + zVDR_DIMVARYS_OFFSETb + (nDims * sizeof(Int32)); - } - else { - Int32 GDRoffset; - if (!sX(ReadCDR(fp,V2_CDR_OFFSET, - CDR_GDROFFSET,&GDRoffset, - CDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadGDR(fp,GDRoffset, - GDR_rNUMDIMS,&nDims, - GDR_NULL),&pStatus)) return pStatus; - tOffset = offset + rVDR_DIMVARYS_OFFSET; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32s(fp,dimVarys,(int)nDims)) return CWE; - break; - } - case VDR_PADVALUE: { - void *padValue = va_arg (ap, void *); - Int32 dataType, numElems; long tOffset; - if (!sX(ReadVDR(CDF,fp,offset,zVar, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_NULL),&pStatus)) return pStatus; - if (zVar) { - Int32 zNumDims; - if (!sX(ReadVDR(CDF,fp,offset,zVar, - VDR_zNUMDIMS,&zNumDims, - VDR_NULL),&pStatus)) return pStatus; - tOffset = offset + zVDR_PADVALUE_OFFSETb + - (zNumDims * sizeof(Int32)) + (zNumDims * sizeof(Int32)); - } - else { - Int32 rNumDims, GDRoffset; - if (!sX(ReadCDR(fp,V2_CDR_OFFSET, - CDR_GDROFFSET,&GDRoffset, - CDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadGDR(fp,GDRoffset, - GDR_rNUMDIMS,&rNumDims, - GDR_NULL),&pStatus)) return pStatus; - tOffset = offset + rVDR_PADVALUE_OFFSETb + (rNumDims*sizeof(Int32)); - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (STRINGdataType(dataType)) { - size_t len; char *newPad = NULL; - len = strlen ((char *)padValue); - if ((int)len < (int) numElems) { - int ix; - newPad = (char *) cdf_AllocateMemory ((size_t) numElems, NULL); - memcpy (newPad, (char *)padValue, len); - for (ix = (int) len; ix < (int) numElems; ++ix) - *(newPad+ix) = (char) ' '; - } - if (!sX(WriteBuffer(CDF,fp,dataType,numElems, - (newPad==NULL?padValue:(void *)newPad)), - &pStatus)) - return pStatus; - if (newPad != NULL) cdf_FreeMemory (newPad, NULL); - } else - if (!sX(WriteBuffer(CDF,fp,dataType, - numElems,padValue),&pStatus)) return pStatus; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case VDR_RECORDSIZE: tOffset += VDR_RECORDSIZE_OFFSET; break; - case VDR_RECORDTYPE: tOffset += VDR_RECORDTYPE_OFFSET; break; - case VDR_VDRNEXT: tOffset += VDR_VDRNEXT_OFFSET; break; - case VDR_DATATYPE: tOffset += VDR_DATATYPE_OFFSET; break; - case VDR_MAXREC: tOffset += VDR_MAXREC_OFFSET; break; - case VDR_VXRHEAD: tOffset += VDR_VXRHEAD_OFFSET; break; - case VDR_VXRTAIL: tOffset += VDR_VXRTAIL_OFFSET; break; - case VDR_FLAGS: tOffset += VDR_FLAGS_OFFSET; break; - case VDR_sRECORDS: tOffset += VDR_sRECORDS_OFFSET; break; - case VDR_NUMELEMS: tOffset += VDR_NUMELEMS_OFFSET; break; - case VDR_NUM: tOffset += VDR_NUM_OFFSET; break; - case VDR_CPRorSPR: tOffset += VDR_CPRorSPR_OFFSET; break; - case VDR_BLOCKING: tOffset += VDR_BLOCKING_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteVXR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteVXR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus WriteVXR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case VXR_NULL: - va_end (ap); - return pStatus; - case VXR_RECORD: { - struct VXRstruct *VXR = va_arg (ap, struct VXRstruct *); - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CWE; - if (!Write32(fp,&(VXR->RecordSize))) return CWE; - if (!Write32(fp,&(VXR->RecordType))) return CWE; - if (!Write32(fp,&(VXR->VXRnext))) return CWE; - if (!Write32(fp,&(VXR->Nentries))) return CWE; - if (!Write32(fp,&(VXR->NusedEntries))) return CWE; - if (!Write32s(fp,VXR->First,(int)VXR->Nentries)) return CWE; - if (!Write32s(fp,VXR->Last,(int)VXR->Nentries)) return CWE; - if (!Write32s(fp,VXR->Offset,(int)VXR->Nentries)) return CWE; - break; - } - case VXR_FIRSTREC: - case VXR_LASTREC: - case VXR_OFFSET: { - Int32 *buffer = va_arg (ap, Int32 *), nEntries; - long tOffset = offset + VXR_FIRSTREC_OFFSET; - if (!sX(ReadVXR(fp,offset, - VXR_NENTRIES,&nEntries, - VXR_NULL),&pStatus)) return pStatus; - switch (field) { - case VXR_FIRSTREC: break; - case VXR_LASTREC: tOffset += nEntries * sizeof(Int32); break; - case VXR_OFFSET: tOffset += 2 * nEntries * sizeof(Int32); break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32s(fp,buffer,(int)nEntries)) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case VXR_RECORDSIZE: tOffset += VXR_RECORDSIZE_OFFSET; break; - case VXR_RECORDTYPE: tOffset += VXR_RECORDTYPE_OFFSET; break; - case VXR_VXRNEXT: tOffset += VXR_VXRNEXT_OFFSET; break; - case VXR_NENTRIES: tOffset += VXR_NENTRIES_OFFSET; break; - case VXR_NUSEDENTRIES: tOffset += VXR_NUSEDENTRIES_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteVVR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteVVR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus WriteVVR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case VVR_NULL: - va_end (ap); - return pStatus; - case VVR_RECORDx: { - struct VVRstruct *VVR = va_arg (ap, struct VVRstruct *); - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CWE; - if (!Write32(fp,&(VVR->RecordSize))) return CWE; - if (!Write32(fp,&(VVR->RecordType))) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case VVR_RECORDSIZE: tOffset += VVR_RECORDSIZE_OFFSET; break; - case VVR_RECORDTYPE: tOffset += VVR_RECORDTYPE_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteUIR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteUIR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus WriteUIR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case UIR_NULL: - va_end (ap); - return pStatus; - case UIR_RECORD: { - struct UIRstruct *UIR = va_arg (ap, struct UIRstruct *); - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CWE; - if (!Write32(fp,&(UIR->RecordSize))) return CWE; - if (!Write32(fp,&(UIR->RecordType))) return CWE; - if (!Write32(fp,&(UIR->NextUIR))) return CWE; - if (!Write32(fp,&(UIR->PrevUIR))) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case UIR_RECORDSIZE: tOffset += UIR_RECORDSIZE_OFFSET; break; - case UIR_RECORDTYPE: tOffset += UIR_RECORDTYPE_OFFSET; break; - case UIR_NEXTUIR: tOffset += UIR_NEXTUIR_OFFSET; break; - case UIR_PREVUIR: tOffset += UIR_PREVUIR_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteCCR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteCCR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus WriteCCR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CCR_NULL: - va_end (ap); - return pStatus; - case CCR_RECORD: { - struct CCRstruct *CCR = va_arg (ap, struct CCRstruct *); - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CWE; - if (!Write32(fp,&(CCR->RecordSize))) return CWE; - if (!Write32(fp,&(CCR->RecordType))) return CWE; - if (!Write32(fp,&(CCR->CPRoffset))) return CWE; - if (!Write32(fp,&(CCR->uSize))) return CWE; - if (!Write32(fp,&(CCR->rfuA))) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case CCR_RECORDSIZE: tOffset += CCR_RECORDSIZE_OFFSET; break; - case CCR_RECORDTYPE: tOffset += CCR_RECORDTYPE_OFFSET; break; - case CCR_CPROFFSET: tOffset += CCR_CPROFFSET_OFFSET; break; - case CCR_USIZE: tOffset += CCR_USIZE_OFFSET; break; - case CCR_RFUa: tOffset += CCR_RFUa_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteCPR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteCPR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus WriteCPR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CPR_NULL: - va_end (ap); - return pStatus; - case CPR_RECORD: { - struct CPRstruct *CPR = va_arg (ap, struct CPRstruct *); int i; - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CWE; - if (!Write32(fp,&(CPR->RecordSize))) return CWE; - if (!Write32(fp,&(CPR->RecordType))) return CWE; - if (!Write32(fp,&(CPR->cType))) return CWE; - if (!Write32(fp,&(CPR->rfuA))) return CWE; - if (!Write32(fp,&(CPR->pCount))) return CWE; - for (i = 0; i < CPR->pCount; i++) { - if (!Write32(fp,&(CPR->cParms[i]))) return CWE; - } - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case CPR_RECORDSIZE: tOffset += CPR_RECORDSIZE_OFFSET; break; - case CPR_RECORDTYPE: tOffset += CPR_RECORDTYPE_OFFSET; break; - case CPR_CTYPE: tOffset += CPR_CTYPE_OFFSET; break; - case CPR_RFUa: tOffset += CPR_RFUa_OFFSET; break; - case CPR_PCOUNT: tOffset += CPR_PCOUNT_OFFSET; break; - case CPR_CPARM1: tOffset += CPR_CPARM1_OFFSET; break; - case CPR_CPARM2: tOffset += CPR_CPARM2_OFFSET; break; - case CPR_CPARM3: tOffset += CPR_CPARM3_OFFSET; break; - case CPR_CPARM4: tOffset += CPR_CPARM4_OFFSET; break; - case CPR_CPARM5: tOffset += CPR_CPARM5_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteSPR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteSPR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus WriteSPR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case SPR_NULL: - va_end (ap); - return pStatus; - case SPR_RECORD: { - struct SPRstruct *SPR = va_arg (ap, struct SPRstruct *); int i; - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CWE; - if (!Write32(fp,&(SPR->RecordSize))) return CWE; - if (!Write32(fp,&(SPR->RecordType))) return CWE; - if (!Write32(fp,&(SPR->sArraysType))) return CWE; - if (!Write32(fp,&(SPR->rfuA))) return CWE; - if (!Write32(fp,&(SPR->pCount))) return CWE; - for (i = 0; i < SPR->pCount; i++) { - if (!Write32(fp,&(SPR->sArraysParms[i]))) return CWE; - } - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case SPR_RECORDSIZE: tOffset += SPR_RECORDSIZE_OFFSET; break; - case SPR_RECORDTYPE: tOffset += SPR_RECORDTYPE_OFFSET; break; - case SPR_STYPE: tOffset += SPR_STYPE_OFFSET; break; - case SPR_RFUa: tOffset += SPR_RFUa_OFFSET; break; - case SPR_PCOUNT: tOffset += SPR_PCOUNT_OFFSET; break; - case SPR_SPARM1: tOffset += SPR_SPARM1_OFFSET; break; - case SPR_SPARM2: tOffset += SPR_SPARM2_OFFSET; break; - case SPR_SPARM3: tOffset += SPR_SPARM3_OFFSET; break; - case SPR_SPARM4: tOffset += SPR_SPARM4_OFFSET; break; - case SPR_SPARM5: tOffset += SPR_SPARM5_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteCVVR. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteCVVR (vFILE *fp, Int32 offset, ...) -#else -STATICforIDL CDFstatus WriteCVVR (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; Int32 offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, Int32); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CVVR_NULL: - va_end (ap); - return pStatus; - case CVVR_RECORDx: { - struct CVVRstruct *CVVR = va_arg (ap, struct CVVRstruct *); - if (!SEEKv(fp,(long)offset,vSEEK_SET)) return CWE; - if (!Write32(fp,&(CVVR->RecordSize))) return CWE; - if (!Write32(fp,&(CVVR->RecordType))) return CWE; - if (!Write32(fp,&(CVVR->rfuA))) return CWE; - if (!Write32(fp,&(CVVR->cSize))) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); long tOffset = offset; - switch (field) { - case CVVR_RECORDSIZE: tOffset += CVVR_RECORDSIZE_OFFSET; break; - case CVVR_RECORDTYPE: tOffset += CVVR_RECORDTYPE_OFFSET; break; - case CVVR_RFUa: tOffset += CVVR_RFUa_OFFSET; break; - case CVVR_CSIZE: tOffset += CVVR_CSIZE_OFFSET; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32(fp,buffer)) return CWE; - break; - } - } - } -} diff --git a/cdf36_3-dist/src/lib/cdfwrite64.c b/cdf36_3-dist/src/lib/cdfwrite64.c deleted file mode 100644 index 4e95654..0000000 --- a/cdf36_3-dist/src/lib/cdfwrite64.c +++ /dev/null @@ -1,1346 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Write to internal record. -* -* Version 1.5a, 28-Feb-97, Hughes STX. -* -* Modification history: -* -* V1.0 4-Nov-93, J Love Original version. -* V1.1 15-Nov-94, J Love CDF V2.5. -* V1.2 5-Jan-95, J Love Encode/decode changes. -* V1.2a 30-Jan-95, J Love `Write32s' now checks count. -* V1.2b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.3 26-May-95, J Love CDF V2.4 compatibility mode. What? -* V1.4 14-Jun-95, J Love Use `ReadXYZ' routines. -* V1.4a 6-Sep-95, J Love CDFexport-related changes. -* V1.5 3-Apr-96, J Love CDF V2.6. -* V1.5a 28-Feb-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V2.0 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* V3.2a 11-Apr-08, M Liu Modified Write32s_64 and Write64s_64 to -* eliminate the potential buffer overflow. -* -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* Local macro definitions. -******************************************************************************/ - -#define CWE CDF_WRITE_ERROR - -/****************************************************************************** -* Write32_64. -******************************************************************************/ - -STATICforIDL Logical Write32_64 (fp, value) -vFILE *fp; -Int32 *value; -{ -#if defined(NETWORKbyteORDERcpu) - if (!WRITEv64(value,(size_t)4,(size_t)1,fp)) return FALSE; -#else - Int32 tValue; - REVERSE4bIO (value, &tValue) - if (!WRITEv64(&tValue,(size_t)4,(size_t)1,fp)) return FALSE; -#endif - return TRUE; -} - -/****************************************************************************** -* Write32s_64. -******************************************************************************/ - -STATICforIDL Logical Write32s_64 (fp, buffer, count) -vFILE *fp; -Int32 *buffer; -int count; -{ -#define MAX_tBUFFER_SIZE 10 /* This must be set to the maximum - value that `count' may ever be. - Currently, that is either the - maximum number of dimensions or - the number of entries in a VXR. */ -#if defined(NETWORKbyteORDERcpu) - if (count == 0) return TRUE; - if (count < 0 || count > MAX_tBUFFER_SIZE) return FALSE; - if (!WRITEv64(buffer,(size_t)4,(size_t)count,fp)) return FALSE; -#else - Int32 tBuffer[MAX_tBUFFER_SIZE]; int i; - if (count == 0) return TRUE; - if (count < 0 || count > MAX_tBUFFER_SIZE) return FALSE; - for (i = 0; i < count; i++) { - REVERSE4bIO (&buffer[i], &tBuffer[i]) - } - if (!WRITEv64(tBuffer,(size_t)4,(size_t)count,fp)) return FALSE; -#endif - return TRUE; -} - -/****************************************************************************** -* Write64_64. -******************************************************************************/ - -STATICforIDL Logical Write64_64 (fp, value) -vFILE *fp; -OFF_T *value; -{ -#if defined(NETWORKbyteORDERcpu) - if (!WRITEv64(value,(size_t)8,(size_t)1,fp)) return FALSE; -#else - OFF_T tValue; - REVERSE8bIO (value, &tValue) - if (!WRITEv64(&tValue,(size_t)8,(size_t)1,fp)) return FALSE; -#endif - return TRUE; -} - -/****************************************************************************** -* Write64s_64. -******************************************************************************/ - -STATICforIDL Logical Write64s_64 (fp, buffer, count) -vFILE *fp; -OFF_T *buffer; -int count; -{ -#define MAX_tBUFFER_SIZE 10 /* This must be set to the maximum - value that `count' may ever be. - Currently, that is either the - maximum number of dimensions or - the number of entries in a VXR. */ -#if defined(NETWORKbyteORDERcpu) - if (count == 0) return TRUE; - if (count < 0 || count > MAX_tBUFFER_SIZE) return FALSE; - if (!WRITEv64(buffer,(size_t)8,(size_t)count,fp)) return FALSE; -#else - OFF_T tBuffer[MAX_tBUFFER_SIZE]; int i; - if (count == 0) return TRUE; - if (count < 0 || count > MAX_tBUFFER_SIZE) return FALSE; - for (i = 0; i < count; i++) { - REVERSE8bIO (&buffer[i], &tBuffer[i]) - } - if (!WRITEv64(tBuffer,(size_t)8,(size_t)count,fp)) return FALSE; -#endif - return TRUE; -} - -/****************************************************************************** -* WriteIrSize64. -* The size is always in the first 8-byte field. -******************************************************************************/ - -STATICforIDL CDFstatus WriteIrSize64 (fp, offset, irSize) -vFILE *fp; -OFF_T offset; -OFF_T *irSize; -{ - if (!SEEKv64(fp,offset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,irSize)) return CWE; - return CDF_OK; -} - -/****************************************************************************** -* WriteIrType64. -* The type is always in the second field (4-byte). -******************************************************************************/ - -STATICforIDL CDFstatus WriteIrType64 (fp, offset, irType) -vFILE *fp; -OFF_T offset; -Int32 *irType; -{ - OFF_T irTypeOffset = offset + sizeof(OFF_T); - if (!SEEKv64(fp,irTypeOffset,vSEEK_SET)) return CWE; - if (!Write32_64(fp,irType)) return CWE; - return CDF_OK; -} - -/****************************************************************************** -* WriteCDR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteCDR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus WriteCDR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CDR_NULL: - va_end (ap); - return pStatus; - case CDR_RECORD: { - struct CDRstruct64 *CDR = va_arg (ap, struct CDRstruct64 *); - char *copyRight = va_arg (ap, char *); - if (!SEEKv64(fp,offset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,&(CDR->RecordSize))) return CWE; - if (!Write32_64(fp,&(CDR->RecordType))) return CWE; - if (!Write64_64(fp,&(CDR->GDRoffset))) return CWE; - if (!Write32s_64(fp,&(CDR->Version),9)) return CWE; -/* - if (!Write32_64(fp,&(CDR->Version))) return CWE; - if (!Write32_64(fp,&(CDR->Release))) return CWE; - if (!Write32_64(fp,&(CDR->Encoding))) return CWE; - if (!Write32_64(fp,&(CDR->Flags))) return CWE; - if (!Write32_64(fp,&(CDR->rfuA))) return CWE; - if (!Write32_64(fp,&(CDR->rfuB))) return CWE; - if (!Write32_64(fp,&(CDR->Increment))) return CWE; - if (!Write32_64(fp,&(CDR->rfuD))) return CWE; - if (!Write32_64(fp,&(CDR->rfuE))) return CWE; -*/ - if (copyRight != NULL) { - if (!WRITEv64(copyRight,CDF_COPYRIGHT_LEN,1,fp)) return CWE; - } - break; - } - case CDR_COPYRIGHT: { - char *copyRight = va_arg (ap, char *); - OFF_T tOffset = offset + CDR_COPYRIGHT_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!WRITEv64(copyRight,CDF_COPYRIGHT_LEN,1,fp)) return CWE; - break; - } - case CDR_RECORDSIZE: - case CDR_GDROFFSET: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case CDR_RECORDSIZE: tOffset += (OFF_T) CDR_RECORDSIZE_OFFSET64; break; - case CDR_GDROFFSET: tOffset += (OFF_T) CDR_GDROFFSET_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,buffer)) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { -/* case CDR_RECORDSIZE: tOffset += (OFF_T) CDR_RECORDSIZE_OFFSET64; break; */ - case CDR_RECORDTYPE: tOffset += (OFF_T) CDR_RECORDTYPE_OFFSET64; break; -/* case CDR_GDROFFSET: tOffset += (OFF_T) CDR_GDROFFSET_OFFSET64; break; */ - case CDR_VERSION: tOffset += (OFF_T) CDR_VERSION_OFFSET64; break; - case CDR_RELEASE: tOffset += (OFF_T) CDR_RELEASE_OFFSET64; break; - case CDR_ENCODING: tOffset += (OFF_T) CDR_ENCODING_OFFSET64; break; - case CDR_FLAGS: tOffset += (OFF_T) CDR_FLAGS_OFFSET64; break; - case CDR_INCREMENT: tOffset += (OFF_T) CDR_INCREMENT_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32_64(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteGDR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteGDR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus WriteGDR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case GDR_NULL: - va_end (ap); - return pStatus; - case GDR_RECORD: { - struct GDRstruct64 *GDR = va_arg (ap, struct GDRstruct64 *); - if (!SEEKv64(fp,offset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,&(GDR->RecordSize))) return CWE; - if (!Write32_64(fp,&(GDR->RecordType))) return CWE; - if (!Write64s_64(fp,&(GDR->rVDRhead),4)) return CWE; -/* - if (!Write64_64(fp,&(GDR->rVDRhead))) return CWE; - if (!Write64_64(fp,&(GDR->zVDRhead))) return CWE; - if (!Write64_64(fp,&(GDR->ADRhead))) return CWE; - if (!Write64_64(fp,&(GDR->eof))) return CWE; -*/ - if (!Write32s_64(fp,&(GDR->NrVars),5)) return CWE; -/* - if (!Write32_64(fp,&(GDR->NrVars))) return CWE; - if (!Write32_64(fp,&(GDR->NumAttr))) return CWE; - if (!Write32_64(fp,&(GDR->rMaxRec))) return CWE; - if (!Write32_64(fp,&(GDR->rNumDims))) return CWE; - if (!Write32_64(fp,&(GDR->NzVars))) return CWE; -*/ - if (!Write64_64(fp,&(GDR->UIRhead))) return CWE; - if (!Write32s_64(fp,&(GDR->rfuC),3)) return CWE; -/* - if (!Write32_64(fp,&(GDR->rfuC))) return CWE; - if (!Write32_64(fp,&(GDR->LeapSecondLastUpdated))) return CWE; - if (!Write32_64(fp,&(GDR->rfuE))) return CWE; -*/ - if (!Write32s_64(fp,GDR->rDimSizes,(int)GDR->rNumDims)) return CWE; - break; - } - case GDR_rDIMSIZES: { - Int32 *rDimSizes = va_arg (ap, Int32 *), rNumDims; OFF_T tOffset; - if (!sX(ReadGDR64(fp,offset, - GDR_rNUMDIMS,&rNumDims, - GDR_NULL),&pStatus)) return pStatus; - tOffset = offset + GDR_rDIMSIZES_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32s_64(fp,rDimSizes,(int)rNumDims)) return CWE; - break; - } - case GDR_RECORDSIZE: - case GDR_rVDRHEAD: - case GDR_zVDRHEAD: - case GDR_ADRHEAD: - case GDR_EOF: - case GDR_UIRHEAD: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case GDR_RECORDSIZE: tOffset += (OFF_T) GDR_RECORDSIZE_OFFSET64; break; - case GDR_rVDRHEAD: tOffset += (OFF_T) GDR_rVDRHEAD_OFFSET64; break; - case GDR_zVDRHEAD: tOffset += (OFF_T) GDR_zVDRHEAD_OFFSET64; break; - case GDR_ADRHEAD: tOffset += (OFF_T) GDR_ADRHEAD_OFFSET64; break; - case GDR_EOF: tOffset += (OFF_T) GDR_EOF_OFFSET64; break; - case GDR_UIRHEAD: tOffset += (OFF_T) GDR_UIRHEAD_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,buffer)) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { -/* case GDR_RECORDSIZE: tOffset += (OFF_T) GDR_RECORDSIZE_OFFSET64; break; */ - case GDR_RECORDTYPE: tOffset += (OFF_T) GDR_RECORDTYPE_OFFSET64; break; -/* case GDR_rVDRHEAD: tOffset += (OFF_T) GDR_rVDRHEAD_OFFSET64; break; */ -/* case GDR_zVDRHEAD: tOffset += (OFF_T) GDR_zVDRHEAD_OFFSET64; break; */ -/* case GDR_ADRHEAD: tOffset += (OFF_T) GDR_ADRHEAD_OFFSET64; break; */ -/* case GDR_EOF: tOffset += (OFF_T) GDR_EOF_OFFSET64; break; */ - case GDR_NrVARS: tOffset += (OFF_T) GDR_NrVARS_OFFSET64; break; - case GDR_NUMATTR: tOffset += (OFF_T) GDR_NUMATTR_OFFSET64; break; - case GDR_rMAXREC: tOffset += (OFF_T) GDR_rMAXREC_OFFSET64; break; - case GDR_rNUMDIMS: tOffset += (OFF_T) GDR_rNUMDIMS_OFFSET64; break; - case GDR_NzVARS: tOffset += (OFF_T) GDR_NzVARS_OFFSET64; break; - case GDR_LEAPSECONDLASTUPDATED: tOffset += (OFF_T) GDR_LEAPSECONDLASTUPDATED_OFFSET64; break; -/* case GDR_UIRHEAD: tOffset += (OFF_T) GDR_UIRHEAD_OFFSET64; break; */ - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32_64(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteADR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteADR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus WriteADR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case ADR_NULL: - va_end (ap); - return pStatus; - case ADR_RECORD: { - struct ADRstruct64 *ADR = va_arg (ap, struct ADRstruct64 *); - if (!SEEKv64(fp,offset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,&(ADR->RecordSize))) return CWE; - if (!Write32_64(fp,&(ADR->RecordType))) return CWE; - if (!Write64s_64(fp,&(ADR->ADRnext),2)) return CWE; -/* - if (!Write64_64(fp,&(ADR->ADRnext))) return CWE; - if (!Write64_64(fp,&(ADR->AgrEDRhead))) return CWE; -*/ - if (!Write32s_64(fp,&(ADR->Scope),5)) return CWE; -/* - if (!Write32_64(fp,&(ADR->Scope))) return CWE; - if (!Write32_64(fp,&(ADR->Num))) return CWE; - if (!Write32_64(fp,&(ADR->NgrEntries))) return CWE; - if (!Write32_64(fp,&(ADR->MAXgrEntry))) return CWE; - if (!Write32_64(fp,&(ADR->rfuA))) return CWE; -*/ - if (!Write64_64(fp,&(ADR->AzEDRhead))) return CWE; - if (!Write32s_64(fp,&(ADR->NzEntries),3)) return CWE; -/* - if (!Write32_64(fp,&(ADR->NzEntries))) return CWE; - if (!Write32_64(fp,&(ADR->MAXzEntry))) return CWE; - if (!Write32_64(fp,&(ADR->rfuE))) return CWE; -*/ - if (!WRITEv64(ADR->Name,CDF_ATTR_NAME_LEN256,1,fp)) return CWE; - break; - } - case ADR_NAME: { - char *aName = va_arg (ap, char *); - OFF_T tOffset = offset + ADR_NAME_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!WRITEv64(aName,CDF_ATTR_NAME_LEN256,1,fp)) return CWE; - break; - } - case ADR_RECORDSIZE: - case ADR_ADRNEXT: - case ADR_AgrEDRHEAD: - case ADR_AzEDRHEAD: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case ADR_RECORDSIZE: tOffset += (OFF_T) ADR_RECORDSIZE_OFFSET64; break; - case ADR_ADRNEXT: tOffset += (OFF_T) ADR_ADRNEXT_OFFSET64; break; - case ADR_AgrEDRHEAD: tOffset += (OFF_T) ADR_AgrEDRHEAD_OFFSET64; break; - case ADR_AzEDRHEAD: tOffset += (OFF_T) ADR_AzEDRHEAD_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,buffer)) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { -/* case ADR_RECORDSIZE: tOffset += (OFF_T) ADR_RECORDSIZE_OFFSET64; break; */ - case ADR_RECORDTYPE: tOffset += (OFF_T) ADR_RECORDTYPE_OFFSET64; break; -/* case ADR_ADRNEXT: tOffset += (OFF_T) ADR_ADRNEXT_OFFSET64; break; */ -/* case ADR_AgrEDRHEAD: tOffset += (OFF_T) ADR_AgrEDRHEAD_OFFSET64; break; */ - case ADR_SCOPE: tOffset += (OFF_T) ADR_SCOPE_OFFSET64; break; - case ADR_NUM: tOffset += (OFF_T) ADR_NUM_OFFSET64; break; - case ADR_NgrENTRIES: tOffset += (OFF_T) ADR_NgrENTRIES_OFFSET64; break; - case ADR_MAXgrENTRY: tOffset += (OFF_T) ADR_MAXgrENTRY_OFFSET64; break; -/* case ADR_AzEDRHEAD: tOffset += (OFF_T) ADR_AzEDRHEAD_OFFSET64; break; */ - case ADR_NzENTRIES: tOffset += (OFF_T) ADR_NzENTRIES_OFFSET64; break; - case ADR_MAXzENTRY: tOffset += (OFF_T) ADR_MAXzENTRY_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32_64(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteAgrEDR64/AzEDR64. -* If the entry value is being written, it is assumed that the value passed -* in is in the host machine's encoding. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteAEDR64 (struct CDFstruct *CDF, vFILE *fp, - OFF_T offset, ...) -#else -STATICforIDL CDFstatus WriteAEDR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - struct CDFstruct *CDF; vFILE *fp; OFF_T offset; - VA_START (ap); - CDF = va_arg (ap, struct CDFstruct *); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case AEDR_NULL: - va_end (ap); - return pStatus; - case AEDR_RECORD: { - struct AEDRstruct64 *AEDR = va_arg (ap, struct AEDRstruct64 *); - void *value = va_arg (ap, void *); - if (!SEEKv64(fp,offset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,&(AEDR->RecordSize))) return CWE; - if (!Write32_64(fp,&(AEDR->RecordType))) return CWE; - if (!Write64_64(fp,&(AEDR->AEDRnext))) return CWE; - if (!Write32s_64(fp,&(AEDR->AttrNum),9)) return CWE; -/* - - if (!Write32_64(fp,&(AEDR->AttrNum))) return CWE; - if (!Write32_64(fp,&(AEDR->DataType))) return CWE; - if (!Write32_64(fp,&(AEDR->Num))) return CWE; - if (!Write32_64(fp,&(AEDR->NumElems))) return CWE; - if (!Write32_64(fp,&(AEDR->rfuA))) return CWE; - if (!Write32_64(fp,&(AEDR->rfuB))) return CWE; - if (!Write32_64(fp,&(AEDR->rfuC))) return CWE; - if (!Write32_64(fp,&(AEDR->rfuD))) return CWE; - if (!Write32_64(fp,&(AEDR->rfuE))) return CWE; -*/ - if (value != NULL) { - if (STRINGdataType(AEDR->DataType)) { - size_t len; char *newValue = NULL; - len = strlen ((char *)value); - if ((int)len < AEDR->NumElems) { - int ix; - newValue = (char *) cdf_AllocateMemory ((size_t) AEDR->NumElems, - NULL); - memcpy (newValue, (char *)value, len); - for (ix = (int) len; ix < AEDR->NumElems; ++ix) - *(newValue+ix) = (char) ' '; - } - if (!sX(WriteBuffer64(CDF,fp,AEDR->DataType,AEDR->NumElems, - (newValue==NULL?value:(void *)newValue)), - &pStatus)) - return pStatus; - if (newValue != NULL) cdf_FreeMemory (newValue, NULL); - } else - if (!sX(WriteBuffer64(CDF,fp,AEDR->DataType, - AEDR->NumElems,value),&pStatus)) - return pStatus; - } - break; - } - case AEDR_VALUE: { - void *value = va_arg (ap, void *); - Int32 dataType, numElems; OFF_T tOffset; - if (!sX(ReadAEDR64(fp,offset, - AEDR_DATATYPE,&dataType, - AEDR_NUMELEMS,&numElems, - AEDR_NULL),&pStatus)) return pStatus; - tOffset = offset + AEDR_VALUE_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (STRINGdataType(dataType)) { - size_t len; char *newValue = NULL; - len = strlen ((char *)value); - if ((int)len < (int)numElems) { - int ix; - newValue = (char *) cdf_AllocateMemory ((size_t) numElems, NULL); - memcpy (newValue, (char *)value, len); - for (ix = (int) len; ix < (int)numElems; ++ix) - *(newValue+ix) = (char) ' '; - } - if (!sX(WriteBuffer64(CDF,fp,dataType,numElems, - (newValue==NULL?value:(void *)newValue)), - &pStatus)) - return pStatus; - if (newValue != NULL) cdf_FreeMemory (newValue, NULL); - } else - if (!sX(WriteBuffer64(CDF,fp,dataType, - numElems,value),&pStatus)) return pStatus; - break; - } - case AEDR_RECORDSIZE: - case AEDR_AEDRNEXT: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case AEDR_RECORDSIZE: tOffset += (OFF_T) AEDR_RECORDSIZE_OFFSET64; break; - case AEDR_AEDRNEXT: tOffset += (OFF_T) AEDR_AEDRNEXT_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,buffer)) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { -/* case AEDR_RECORDSIZE: tOffset += (OFF_T) AEDR_RECORDSIZE_OFFSET64; break; */ - case AEDR_RECORDTYPE: tOffset += (OFF_T) AEDR_RECORDTYPE_OFFSET64; break; -/* case AEDR_AEDRNEXT: tOffset += (OFF_T) AEDR_AEDRNEXT_OFFSET64; break; */ - case AEDR_ATTRNUM: tOffset += (OFF_T) AEDR_ATTRNUM_OFFSET64; break; - case AEDR_DATATYPE: tOffset += (OFF_T) AEDR_DATATYPE_OFFSET64; break; - case AEDR_NUM: tOffset += (OFF_T) AEDR_NUM_OFFSET64; break; - case AEDR_NUMELEMS: tOffset += (OFF_T) AEDR_NUMELEMS_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32_64(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriterVDR64/zVDR64. -* If the pad value is being written, it is assumed that the value passed -* in is in the host machine's encoding. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteVDR64 (struct CDFstruct *CDF, vFILE *fp, - OFF_T offset, Logical zVar, ...) -#else -STATICforIDL CDFstatus WriteVDR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, zVar); -#else - struct CDFstruct *CDF; vFILE *fp; OFF_T offset; Logical zVar; - VA_START (ap); - CDF = va_arg (ap, struct CDFstruct *); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); - zVar = va_arg (ap, Logical); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case VDR_NULL: - va_end (ap); - return pStatus; - case VDR_RECORD: { - struct VDRstruct64 *VDR = va_arg (ap, struct VDRstruct64 *); - void *padValue = va_arg (ap, void *); - Int32 nDims; - if (!SEEKv64(fp,offset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,&(VDR->RecordSize))) return CWE; - if (!Write32_64(fp,&(VDR->RecordType))) return CWE; - if (!Write64_64(fp,&(VDR->VDRnext))) return CWE; - if (!Write32s_64(fp,&(VDR->DataType),2)) return CWE; -/* - if (!Write32_64(fp,&(VDR->DataType))) return CWE; - if (!Write32_64(fp,&(VDR->MaxRec))) return CWE; -*/ - if (!Write64s_64(fp,&(VDR->VXRhead),2)) return CWE; -/* - if (!Write64_64(fp,&(VDR->VXRhead))) return CWE; - if (!Write64_64(fp,&(VDR->VXRtail))) return CWE; -*/ - if (!Write32s_64(fp,&(VDR->Flags),7)) return CWE; -/* - if (!Write32_64(fp,&(VDR->Flags))) return CWE; - if (!Write32_64(fp,&(VDR->sRecords))) return CWE; - if (!Write32_64(fp,&(VDR->rfuB))) return CWE; - if (!Write32_64(fp,&(VDR->rfuC))) return CWE; - if (!Write32_64(fp,&(VDR->rfuF))) return CWE; - if (!Write32_64(fp,&(VDR->NumElems))) return CWE; - if (!Write32_64(fp,&(VDR->Num))) return CWE; -*/ - if (!Write64_64(fp,&(VDR->CPRorSPRoffset))) return CWE; - if (!Write32_64(fp,&(VDR->blockingFactor))) return CWE; - if (!WRITEv64(VDR->Name,CDF_VAR_NAME_LEN256,1,fp)) return CWE; - if (zVar) { - if (!Write32_64(fp,&(VDR->zNumDims))) return CWE; - if (!Write32s_64(fp,VDR->zDimSizes, - (int)VDR->zNumDims)) return CWE; - } - if (zVar) - nDims = VDR->zNumDims; - else { - OFF_T tOffset = V_tell64 (fp); OFF_T GDRoffset; - if (!sX(ReadCDR64(fp,V3_CDR_OFFSET64, - CDR_GDROFFSET,&GDRoffset, - CDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadGDR64(fp,GDRoffset, - GDR_rNUMDIMS,&nDims, - GDR_NULL),&pStatus)) return pStatus; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - } - if (!Write32s_64(fp,VDR->DimVarys,(int)nDims)) return CWE; - if (PADvalueBITset(VDR->Flags) && padValue != NULL) { - if (STRINGdataType(VDR->DataType)) { - size_t len; char *newPad = NULL; - len = strlen ((char *)padValue); - if ((int)len < (int)VDR->NumElems) { - int ix; - newPad = (char *) cdf_AllocateMemory ((size_t) VDR->NumElems, - NULL); - memcpy (newPad, (char *)padValue, len); - for (ix = (int) len; ix < (int)VDR->NumElems; ++ix) - *(newPad+ix) = (char) ' '; - } - if (!sX(WriteBuffer64(CDF,fp,VDR->DataType,VDR->NumElems, - (newPad==NULL?padValue:(void *)newPad)), - &pStatus)) - return pStatus; - if (newPad != NULL) cdf_FreeMemory (newPad, NULL); - } else - if (!sX(WriteBuffer64(CDF,fp,VDR->DataType, - VDR->NumElems, - padValue),&pStatus)) return pStatus; - } - break; - } - case VDR_NAME: { - char *vName = va_arg (ap, char *); - OFF_T tOffset = offset + VDR_NAME_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!WRITEv64(vName,CDF_VAR_NAME_LEN256,1,fp)) return CWE; - break; - } - case VDR_zNUMDIMS: { - Int32 *numDims = va_arg (ap, Int32 *); - OFF_T tOffset = offset + zVDR_zNUMDIMS_OFFSET64; - if (!zVar) return CDF_INTERNAL_ERROR; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32_64(fp,numDims)) return CWE; - break; - } - case VDR_zDIMSIZES: { - Int32 *zDimSizes = va_arg (ap, Int32 *), zNumDims; - int dimN; OFF_T tOffset; - if (!zVar) return CDF_INTERNAL_ERROR; - if (!sX(ReadVDR64(CDF,fp,offset,zVar, - VDR_zNUMDIMS,&zNumDims, - VDR_NULL),&pStatus)) return pStatus; - tOffset = offset + zVDR_zDIMSIZES_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - for (dimN = 0; dimN < zNumDims; dimN++) { - if (!Write32_64(fp,&(zDimSizes[dimN]))) return CWE; - } - break; - } - case VDR_DIMVARYS: { - Int32 *dimVarys = va_arg (ap, Int32 *), nDims; OFF_T tOffset; - if (zVar) { - if (!sX(ReadVDR64(CDF,fp,offset,zVar, - VDR_zNUMDIMS,&nDims, - VDR_NULL),&pStatus)) return pStatus; - tOffset = offset + (OFF_T) (zVDR_DIMVARYS_OFFSETb64 + - (nDims * sizeof(Int32))); - } - else { - OFF_T GDRoffset; - if (!sX(ReadCDR64(fp,V3_CDR_OFFSET64, - CDR_GDROFFSET,&GDRoffset, - CDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadGDR64(fp,GDRoffset, - GDR_rNUMDIMS,&nDims, - GDR_NULL),&pStatus)) return pStatus; - tOffset = offset + rVDR_DIMVARYS_OFFSET64; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32s_64(fp,dimVarys,(int)nDims)) return CWE; - break; - } - case VDR_PADVALUE: { - void *padValue = va_arg (ap, void *); - Int32 dataType, numElems; OFF_T tOffset; - if (!sX(ReadVDR64(CDF,fp,offset,zVar, - VDR_DATATYPE,&dataType, - VDR_NUMELEMS,&numElems, - VDR_NULL),&pStatus)) return pStatus; - if (zVar) { - Int32 zNumDims; - if (!sX(ReadVDR64(CDF,fp,offset,zVar, - VDR_zNUMDIMS,&zNumDims, - VDR_NULL),&pStatus)) return pStatus; - tOffset = offset + (OFF_T) (zVDR_PADVALUE_OFFSETb64 + - (zNumDims * sizeof(Int32)) + - (zNumDims * sizeof(Int32))); - } - else { - Int32 rNumDims; OFF_T GDRoffset; - if (!sX(ReadCDR64(fp,V3_CDR_OFFSET64, - CDR_GDROFFSET,&GDRoffset, - CDR_NULL),&pStatus)) return pStatus; - if (!sX(ReadGDR64(fp,GDRoffset, - GDR_rNUMDIMS,&rNumDims, - GDR_NULL),&pStatus)) return pStatus; - tOffset = offset + (OFF_T) (rVDR_PADVALUE_OFFSETb64 + - (rNumDims*sizeof(Int32))); - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (STRINGdataType(dataType)) { - size_t len; char *newPad = NULL; - len = strlen ((char *)padValue); - if ((int)len < (int)numElems) { - int ix; - newPad = (char *) cdf_AllocateMemory ((size_t) numElems, NULL); - memcpy (newPad, (char *)padValue, len); - for (ix = (int) len; ix < (int)numElems; ++ix) - *(newPad+ix) = (char) ' '; - } - if (!sX(WriteBuffer64(CDF,fp,dataType,numElems, - (newPad==NULL?padValue:(void *)newPad)), - &pStatus)) - return pStatus; - if (newPad != NULL) cdf_FreeMemory (newPad, NULL); - } else - if (!sX(WriteBuffer64(CDF,fp,dataType, - numElems,padValue),&pStatus)) return pStatus; - break; - } - case VDR_RECORDSIZE: - case VDR_VDRNEXT: - case VDR_VXRHEAD: - case VDR_VXRTAIL: - case VDR_CPRorSPR: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case VDR_RECORDSIZE: tOffset += (OFF_T) VDR_RECORDSIZE_OFFSET64; break; - case VDR_VDRNEXT: tOffset += (OFF_T) VDR_VDRNEXT_OFFSET64; break; - case VDR_VXRHEAD: tOffset += (OFF_T) VDR_VXRHEAD_OFFSET64; break; - case VDR_VXRTAIL: tOffset += (OFF_T) VDR_VXRTAIL_OFFSET64; break; - case VDR_CPRorSPR: tOffset += (OFF_T) VDR_CPRorSPR_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,buffer)) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { -/* case VDR_RECORDSIZE: tOffset += (OFF_T) VDR_RECORDSIZE_OFFSET64; break; */ - case VDR_RECORDTYPE: tOffset += (OFF_T) VDR_RECORDTYPE_OFFSET64; break; -/* case VDR_VDRNEXT: tOffset += (OFF_T) VDR_VDRNEXT_OFFSET64; break; */ - case VDR_DATATYPE: tOffset += (OFF_T) VDR_DATATYPE_OFFSET64; break; - case VDR_MAXREC: tOffset += (OFF_T) VDR_MAXREC_OFFSET64; break; -/* case VDR_VXRHEAD: tOffset += (OFF_T) VDR_VXRHEAD_OFFSET64; break; */ -/* case VDR_VXRTAIL: tOffset += (OFF_T) VDR_VXRTAIL_OFFSET64; break; */ - case VDR_FLAGS: tOffset += (OFF_T) VDR_FLAGS_OFFSET64; break; - case VDR_sRECORDS: tOffset += (OFF_T) VDR_sRECORDS_OFFSET64; break; - case VDR_NUMELEMS: tOffset += (OFF_T) VDR_NUMELEMS_OFFSET64; break; - case VDR_NUM: tOffset += (OFF_T) VDR_NUM_OFFSET64; break; -/* case VDR_CPRorSPR: tOffset += (OFF_T) VDR_CPRorSPR_OFFSET64; break; */ - case VDR_BLOCKING: tOffset += (OFF_T) VDR_BLOCKING_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32_64(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteVXR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteVXR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus WriteVXR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case VXR_NULL: - va_end (ap); - return pStatus; - case VXR_RECORD: { - struct VXRstruct64 *VXR = va_arg (ap, struct VXRstruct64 *); - if (!SEEKv64(fp,offset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,&(VXR->RecordSize))) return CWE; - if (!Write32_64(fp,&(VXR->RecordType))) return CWE; - if (!Write64_64(fp,&(VXR->VXRnext))) return CWE; - if (!Write32s_64(fp,&(VXR->Nentries),2)) return CWE; -/* - if (!Write32_64(fp,&(VXR->Nentries))) return CWE; - if (!Write32_64(fp,&(VXR->NusedEntries))) return CWE; -*/ - if (!Write32s_64(fp,VXR->First,(int)VXR->Nentries)) return CWE; - if (!Write32s_64(fp,VXR->Last,(int)VXR->Nentries)) return CWE; - if (!Write64s_64(fp,VXR->Offset,(int)VXR->Nentries)) return CWE; - break; - } - case VXR_FIRSTREC: - case VXR_LASTREC: { - Int32 *buffer = va_arg (ap, Int32 *), nEntries; - OFF_T tOffset = offset + VXR_FIRSTREC_OFFSET64; - if (!sX(ReadVXR64(fp,offset, - VXR_NENTRIES,&nEntries, - VXR_NULL),&pStatus)) return pStatus; - switch (field) { - case VXR_FIRSTREC: break; - case VXR_LASTREC: tOffset += (OFF_T) nEntries * sizeof(Int32); break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32s_64(fp,buffer,(int)nEntries)) return CWE; - break; - } - case VXR_OFFSET: { - OFF_T *buffer = va_arg (ap, OFF_T *), nEntries; - OFF_T tOffset = offset + VXR_FIRSTREC_OFFSET64; - if (!sX(ReadVXR64(fp,offset, - VXR_NENTRIES,&nEntries, - VXR_NULL),&pStatus)) return pStatus; - tOffset += (OFF_T) (2 * nEntries * sizeof(Int32)); - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write64s_64(fp,buffer,(int)nEntries)) return CWE; - break; - } - case VXR_RECORDSIZE: - case VXR_VXRNEXT: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case VXR_RECORDSIZE: tOffset += (OFF_T) VXR_RECORDSIZE_OFFSET64; break; - case VXR_VXRNEXT: tOffset += (OFF_T) VXR_VXRNEXT_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,buffer)) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { -/* case VXR_RECORDSIZE: tOffset += (OFF_T) VXR_RECORDSIZE_OFFSET64; break; */ - case VXR_RECORDTYPE: tOffset += (OFF_T) VXR_RECORDTYPE_OFFSET64; break; -/* case VXR_VXRNEXT: tOffset += (OFF_T) VXR_VXRNEXT_OFFSET64; break; */ - case VXR_NENTRIES: tOffset += (OFF_T) VXR_NENTRIES_OFFSET64; break; - case VXR_NUSEDENTRIES: tOffset += (OFF_T) VXR_NUSEDENTRIES_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32_64(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteVVR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteVVR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus WriteVVR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case VVR_NULL: - va_end (ap); - return pStatus; - case VVR_RECORDx: { - struct VVRstruct64 *VVR = va_arg (ap, struct VVRstruct64 *); - if (!SEEKv64(fp,offset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,&(VVR->RecordSize))) return CWE; - if (!Write32_64(fp,&(VVR->RecordType))) return CWE; - break; - } - case VVR_RECORDSIZE: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - tOffset += (OFF_T) VVR_RECORDSIZE_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,buffer)) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { -/* case VVR_RECORDSIZE: tOffset += (OFF_T) VVR_RECORDSIZE_OFFSET64; break; */ - case VVR_RECORDTYPE: tOffset += (OFF_T) VVR_RECORDTYPE_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32_64(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteUIR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteUIR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus WriteUIR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case UIR_NULL: - va_end (ap); - return pStatus; - case UIR_RECORD: { - struct UIRstruct64 *UIR = va_arg (ap, struct UIRstruct64 *); - if (!SEEKv64(fp,offset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,&(UIR->RecordSize))) return CWE; - if (!Write32_64(fp,&(UIR->RecordType))) return CWE; - if (!Write64s_64(fp,&(UIR->NextUIR),2)) return CWE; -/* - if (!Write64_64(fp,&(UIR->NextUIR))) return CWE; - if (!Write64_64(fp,&(UIR->PrevUIR))) return CWE; -*/ - break; - } - case UIR_RECORDTYPE: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - tOffset += (OFF_T) UIR_RECORDTYPE_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32_64(fp,buffer)) return CWE; - break; - } - default: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case UIR_RECORDSIZE: tOffset += (OFF_T) UIR_RECORDSIZE_OFFSET64; break; -/* case UIR_RECORDTYPE: tOffset += (OFF_T) UIR_RECORDTYPE_OFFSET64; break; */ - case UIR_NEXTUIR: tOffset += (OFF_T) UIR_NEXTUIR_OFFSET64; break; - case UIR_PREVUIR: tOffset += (OFF_T) UIR_PREVUIR_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteCCR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteCCR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus WriteCCR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CCR_NULL: - va_end (ap); - return pStatus; - case CCR_RECORD: { - struct CCRstruct64 *CCR = va_arg (ap, struct CCRstruct64 *); - if (!SEEKv64(fp,offset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,&(CCR->RecordSize))) return CWE; - if (!Write32_64(fp,&(CCR->RecordType))) return CWE; - if (!Write64s_64(fp,&(CCR->CPRoffset),2)) return CWE; -/* - if (!Write64_64(fp,&(CCR->CPRoffset))) return CWE; - if (!Write64_64(fp,&(CCR->uSize))) return CWE; -*/ - if (!Write32_64(fp,&(CCR->rfuA))) return CWE; - break; - } - case CCR_RECORDTYPE: - case CCR_RFUa: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { - case CCR_RECORDTYPE: tOffset += (OFF_T) CCR_RECORDTYPE_OFFSET64; break; - case CCR_RFUa: tOffset += (OFF_T) CCR_RFUa_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,offset,vSEEK_SET)) return CWE; - if (!Write32_64(fp,buffer)) return CWE; - break; - } - default: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case CCR_RECORDSIZE: tOffset += (OFF_T) CCR_RECORDSIZE_OFFSET64; break; -/* case CCR_RECORDTYPE: tOffset += (OFF_T) CCR_RECORDTYPE_OFFSET64; break; */ - case CCR_CPROFFSET: tOffset += (OFF_T) CCR_CPROFFSET_OFFSET64; break; - case CCR_USIZE: tOffset += (OFF_T) CCR_USIZE_OFFSET64; break; -/* case CCR_RFUa: tOffset += (OFF_T) CCR_RFUa_OFFSET64; break; */ - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteCPR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteCPR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus WriteCPR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CPR_NULL: - va_end (ap); - return pStatus; - case CPR_RECORD: { - struct CPRstruct64 *CPR = va_arg (ap, struct CPRstruct64 *); int i; - if (!SEEKv64(fp,offset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,&(CPR->RecordSize))) return CWE; - if (!Write32s_64(fp,&(CPR->RecordType),4)) return CWE; -/* - if (!Write32_64(fp,&(CPR->RecordType))) return CWE; - if (!Write32_64(fp,&(CPR->cType))) return CWE; - if (!Write32_64(fp,&(CPR->rfuA))) return CWE; - if (!Write32_64(fp,&(CPR->pCount))) return CWE; -*/ - for (i = 0; i < CPR->pCount; i++) { - if (!Write32_64(fp,&(CPR->cParms[i]))) return CWE; - } - break; - } - case CPR_RECORDSIZE: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - tOffset += (OFF_T) CPR_RECORDSIZE_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,buffer)) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { -/* case CPR_RECORDSIZE: tOffset += (OFF_T) CPR_RECORDSIZE_OFFSET64; break; */ - case CPR_RECORDTYPE: tOffset += (OFF_T) CPR_RECORDTYPE_OFFSET64; break; - case CPR_CTYPE: tOffset += (OFF_T) CPR_CTYPE_OFFSET64; break; - case CPR_RFUa: tOffset += (OFF_T) CPR_RFUa_OFFSET64; break; - case CPR_PCOUNT: tOffset += (OFF_T) CPR_PCOUNT_OFFSET64; break; - case CPR_CPARM1: tOffset += (OFF_T) CPR_CPARM1_OFFSET64; break; - case CPR_CPARM2: tOffset += (OFF_T) CPR_CPARM2_OFFSET64; break; - case CPR_CPARM3: tOffset += (OFF_T) CPR_CPARM3_OFFSET64; break; - case CPR_CPARM4: tOffset += (OFF_T) CPR_CPARM4_OFFSET64; break; - case CPR_CPARM5: tOffset += (OFF_T) CPR_CPARM5_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32_64(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteSPR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteSPR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus WriteSPR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case SPR_NULL: - va_end (ap); - return pStatus; - case SPR_RECORD: { - struct SPRstruct64 *SPR = va_arg (ap, struct SPRstruct64 *); int i; - if (!SEEKv64(fp,offset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,&(SPR->RecordSize))) return CWE; - if (!Write32s_64(fp,&(SPR->RecordType),4)) return CWE; -/* - if (!Write32_64(fp,&(SPR->RecordType))) return CWE; - if (!Write32_64(fp,&(SPR->sArraysType))) return CWE; - if (!Write32_64(fp,&(SPR->rfuA))) return CWE; - if (!Write32_64(fp,&(SPR->pCount))) return CWE; -*/ - for (i = 0; i < SPR->pCount; i++) { - if (!Write32_64(fp,&(SPR->sArraysParms[i]))) return CWE; - } - break; - } - case SPR_RECORDSIZE: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - tOffset += (OFF_T) SPR_RECORDSIZE_OFFSET64; - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,buffer)) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { -/* case SPR_RECORDSIZE: tOffset += (OFF_T) SPR_RECORDSIZE_OFFSET64; break; */ - case SPR_RECORDTYPE: tOffset += (OFF_T) SPR_RECORDTYPE_OFFSET64; break; - case SPR_STYPE: tOffset += (OFF_T) SPR_STYPE_OFFSET64; break; - case SPR_RFUa: tOffset += (OFF_T) SPR_RFUa_OFFSET64; break; - case SPR_PCOUNT: tOffset += (OFF_T) SPR_PCOUNT_OFFSET64; break; - case SPR_SPARM1: tOffset += (OFF_T) SPR_SPARM1_OFFSET64; break; - case SPR_SPARM2: tOffset += (OFF_T) SPR_SPARM2_OFFSET64; break; - case SPR_SPARM3: tOffset += (OFF_T) SPR_SPARM3_OFFSET64; break; - case SPR_SPARM4: tOffset += (OFF_T) SPR_SPARM4_OFFSET64; break; - case SPR_SPARM5: tOffset += (OFF_T) SPR_SPARM5_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32_64(fp,buffer)) return CWE; - break; - } - } - } -} - -/****************************************************************************** -* WriteCVVR64. -******************************************************************************/ - -#if defined(STDARG) -STATICforIDL CDFstatus WriteCVVR64 (vFILE *fp, OFF_T offset, ...) -#else -STATICforIDL CDFstatus WriteCVVR64 (va_alist) -va_dcl -#endif -{ - va_list ap; CDFstatus pStatus = CDF_OK; -#if defined(STDARG) - va_start (ap, offset); -#else - vFILE *fp; OFF_T offset; - VA_START (ap); - fp = va_arg (ap, vFILE *); - offset = va_arg (ap, OFF_T); -#endif - for (;;) { - int field = va_arg (ap, int); - switch (field) { - case CVVR_NULL: - va_end (ap); - return pStatus; - case CVVR_RECORDx: { - struct CVVRstruct64 *CVVR = va_arg (ap, struct CVVRstruct64 *); - if (!SEEKv64(fp,offset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,&(CVVR->RecordSize))) return CWE; - if (!Write32s_64(fp,&(CVVR->RecordType),2)) return CWE; -/* - if (!Write32_64(fp,&(CVVR->RecordType))) return CWE; - if (!Write32_64(fp,&(CVVR->rfuA))) return CWE; -*/ - if (!Write64_64(fp,&(CVVR->cSize))) return CWE; - break; - } - case CVVR_RECORDSIZE: - case CVVR_CSIZE: { - OFF_T *buffer = va_arg (ap, OFF_T *); OFF_T tOffset = offset; - switch (field) { - case CVVR_RECORDSIZE: tOffset += (OFF_T) CVVR_RECORDSIZE_OFFSET64; break; - case CVVR_CSIZE: tOffset += (OFF_T) CVVR_CSIZE_OFFSET64; break; - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write64_64(fp,buffer)) return CWE; - break; - } - default: { - Int32 *buffer = va_arg (ap, Int32 *); OFF_T tOffset = offset; - switch (field) { -/* case CVVR_RECORDSIZE: tOffset += (OFF_T) CVVR_RECORDSIZE_OFFSET64; break; */ - case CVVR_RECORDTYPE: tOffset += (OFF_T) CVVR_RECORDTYPE_OFFSET64; break; - case CVVR_RFUa: tOffset += (OFF_T) CVVR_RFUa_OFFSET64; break; -/* case CVVR_CSIZE: tOffset += (OFF_T) CVVR_CSIZE_OFFSET64; break; */ - default: return CDF_INTERNAL_ERROR; - } - if (!SEEKv64(fp,tOffset,vSEEK_SET)) return CWE; - if (!Write32_64(fp,buffer)) return CWE; - break; - } - } - } -} diff --git a/cdf36_3-dist/src/lib/dirutils.c b/cdf36_3-dist/src/lib/dirutils.c deleted file mode 100644 index 1d50b5b..0000000 --- a/cdf36_3-dist/src/lib/dirutils.c +++ /dev/null @@ -1,370 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Directory utilities. -* -* Version 1.5b, 29-Oct-97, Hughes STX. -* -* Modification history: -* -* V1.0 20-Apr-92, J Love Original version. -* V1.1 21-Aug-92, J Love CDF V2.3 (shareable/NeXT). -* V1.2 26-Jan-94, J Love CDF V2.4. -* V1.3 24-Oct-94, J Love CDF V2.5. -* V1.3a 23-Jan-95, J Love IRIX 6.0 (64-bit). -* V1.3b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V1.4 21-Mar-95, J Love POSIX. -* V1.4a 18-Apr-95, J Love More POSIX. -* V1.5 26-Jul-96, J Love CDF V2.6. -* V1.5a 3-Mar-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V1.5b 29-Oct-97, J Love More Windows NT. -* V1.6 11-Jul-05, M Liu Added MingW port for PC. -* -*****************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/***************************************************************************** -* Macro constants. -*****************************************************************************/ - -#if defined(unix) || defined(posixSHELL) -#define DU_MAX_USERNAME_LEN 100 -#define DU_MAX_ENVVAR_LEN 80 -#endif - -/****************************************************************************** -* Local function prototypes. -******************************************************************************/ - -#if defined(unix) || defined(posixSHELL) -static void DerefEnvVar PROTOARGs((char *shortP, - char longP[DU_MAX_PATH_LEN+1])); -static char *NextNonENVchar PROTOARGs((char *ptr)); -#endif - -/****************************************************************************** -* ExpandPath. -******************************************************************************/ - -VISIBLE_PREFIX void ExpandPath (shortP, longP) -char *shortP; -char longP[DU_MAX_PATH_LEN+1]; -{ -#if defined(unix) || defined(posixSHELL) - int len; char *tail; struct passwd *pw; - char username[DU_MAX_USERNAME_LEN+1], tempP[DU_MAX_PATH_LEN+1]; -#endif - -#if (defined(unix) && !defined(__MINGW32__)) || defined(posixSHELL) - DerefEnvVar (shortP, tempP); - if (tempP[0] != '~') - strcpyX (longP, tempP, DU_MAX_PATH_LEN); - else { - tail = strchr (tempP, '/'); - if (tail != NULL) { - len = tail - (tempP + 1); - if (len > 0) { - strcpyX (username, tempP + 1, MINIMUM(len,DU_MAX_USERNAME_LEN)); - pw = getpwnam (username); - } - else - pw = getpwuid (getuid()); - if (pw != NULL) - strcpyX (longP, pw->pw_dir, DU_MAX_PATH_LEN); - else - strcpyX (longP, "?", DU_MAX_PATH_LEN); - strcatX (longP, tail, DU_MAX_PATH_LEN); - } - else { - if (tempP[1] != NUL) - pw = getpwnam (tempP + 1); - else - pw = getpwuid (getuid()); - if (pw != NULL) - strcpyX (longP, pw->pw_dir, DU_MAX_PATH_LEN); - else - strcpyX (longP, "?", DU_MAX_PATH_LEN); - } - } -#endif - -#if defined(dos) || defined(vms) || defined(mac) || defined(win32) || \ - defined(__MINGW32__) - /* If a Macintosh...check for alias? */ - strcpyX (longP, shortP, DU_MAX_PATH_LEN); -#endif - - return; -} - -/****************************************************************************** -* IsReg. -* `stat' on VMS and DOS(/Windows?) systems will indicate a regular file if ANY -* file can be found matching a wildcard specification. On UNIX systems, that -* doesn't happen. -******************************************************************************/ - -VISIBLE_PREFIX Logical IsReg (path) -char *path; -{ - char pathX[DU_MAX_PATH_LEN+1]; -#if defined(mac) - struct FInfo fndrInfo; -#else - struct STAT st; -#endif - ExpandPath (path, pathX); -#if defined(mac) - if (GetFInfo(CtoPstr(pathX),0,&fndrInfo) == noErr) - return TRUE; - else - return FALSE; -#else -# if defined(vms) - if (strchr(pathX,'*') != NULL) return FALSE; - if (strchr(pathX,'%') != NULL) return FALSE; -# endif -# if defined(dos) || defined(win32) - if (strchr(pathX,'*') != NULL) return FALSE; - if (strchr(pathX,'?') != NULL) return FALSE; -# endif - if (STAT(pathX, &st) == 0) { -# if defined(SALFORDC) /* Salford's `stat' is broken. */ - return (st.st_size > 0); -# else -# if defined(S_ISREG) - return S_ISREG(st.st_mode); -# else - return (st.st_mode & S_IFREG); -# endif -# endif - } - else { -# if defined(vms) - /************************************************************************** - * If this is a VMS system and the file is on DECnet (`::' is in the - * pathname following the DECnet nodename), `stat' may produce an error. - * In that case, try to open the file before giving up. - **************************************************************************/ - if (strstr(pathX,"::") != NULL) { - FILE *fp = fopen (pathX, READ_ONLY_a_mode); - if (fp != NULL) { - fclose (fp); - return TRUE; - } - } -# endif - return FALSE; - } -#endif -} - -/****************************************************************************** -* DerefEnvVar. -* (Only used on UNIX/POSIXshell systems). -******************************************************************************/ - -#if defined(unix) || defined(posixSHELL) -static void DerefEnvVar (shortP, longP) -char *shortP; /* Short path (with environment variables). */ -char longP[DU_MAX_PATH_LEN+1]; /* Long path (with environment variables - dereferenced). */ -{ - char *Sptr = shortP; /* Current position in "short" path. */ - char *Lptr = longP; /* End position in "long" path. */ - char *DOLLARptr; /* Pointer to '$' in "short" path. */ - char *ENVptr; /* Pointer to environment variable in "short" path.*/ - char *DEREFptr; /* Pointer to dereferenced environment variable - "value". */ - size_t len; - char *ptr; - char ENVvar[DU_MAX_ENVVAR_LEN + 1]; /* Environment variable. */ - for (*Lptr = NUL;;) { - DOLLARptr = strchr (Sptr, '$'); - if (DOLLARptr != NULL) { - len = DOLLARptr - Sptr; - if (len > 0) { - strcpyX (Lptr, Sptr, MINIMUM(len,DU_MAX_PATH_LEN)); - Lptr += len; - } - if (*(DOLLARptr + 1) == '{') { - ENVptr = DOLLARptr + 2; - ptr = strchr (ENVptr, '}'); - if (ptr != NULL) { - len = ptr - ENVptr; - Sptr = ptr + 1; - } - else { - len = strlen (ENVptr); - Sptr = ENVptr + len; - } - } - else { - ENVptr = DOLLARptr + 1; - ptr = NextNonENVchar (ENVptr + 1); - if (ptr != NULL) { - len = ptr - ENVptr; - Sptr = ptr; - } - else { - len = strlen (ENVptr); - Sptr = ENVptr + len; - } - } - strcpyX (ENVvar, ENVptr, MINIMUM(len,DU_MAX_ENVVAR_LEN)); - DEREFptr = getenv (ENVvar); - if (DEREFptr != NULL) { - len = strlen (DEREFptr); - strcpyX (Lptr, DEREFptr, MINIMUM(len,DU_MAX_PATH_LEN)); - Lptr += len; - } - } - else { - strcatX (Lptr, Sptr, DU_MAX_PATH_LEN); - return; - } - } -} -#endif - -/****************************************************************************** -* NextNonENVchar. -* (Only used on UNIX/POSIXshell systems). -******************************************************************************/ - -#if defined(unix) || defined(posixSHELL) -static char *NextNonENVchar (ptr) -char *ptr; -{ - uChar *p; - for (p = (uChar *) ptr; *p != NUL; p++) { - if (*p <= '/') return ((char *) p); - if (':' <= *p && *p <= '@') return ((char *) p); - if ('[' <= *p && *p <= '^') return ((char *) p); - if (*p == '`') return ((char *) p); - if ('{' <= *p) return ((char *) p); - } - return NULL; -} -#endif - -/****************************************************************************** -* MacDirSpecified. (Only used on Macintosh systems). -* WARNING - Using `PBHGetVol' caused some really weird things to happen. Use -* `HGetVol' instead. -******************************************************************************/ - -#if defined(mac) -STATICforIDL Logical MacDirSpecified (path, vRefNum, dirID) -char *path; /* In: Pathname to be checked. */ -short *vRefNum; /* Out: Volume reference number. */ -long *dirID; /* Out: Directory identifier. */ -{ - char pathX[DU_MAX_PATH_LEN+1]; - OSErr rCode; - short tVRefNum; - long tDirID; - ExpandPath (path, pathX); - /**************************************************************************** - * Check for no directory specified (which implies the current working - * directory) or just `:' (which also implies the current working directory). - ****************************************************************************/ - if (NULstring(pathX) || !strcmp(pathX,":")) { - rCode = HGetVol (NULL, &tVRefNum, &tDirID); - if (rCode != noErr) return FALSE; - } - else { - /************************************************************************** - * Some sort of pathname has been specified (full or partial). - **************************************************************************/ - HParamBlockRec hParms; - CInfoPBRec cParms; - long topDirID; /* Top directory ID of partial pathname. */ - Str255 tempS; - if (pathX[0] == ':') { - /***************************************************************** - * Partial pathname. - *****************************************************************/ - rCode = HGetVol (NULL, &tVRefNum, &topDirID); - if (rCode != noErr) return FALSE; - } - else { - /***************************************************************** - * Full pathname. - *****************************************************************/ - hParms.volumeParam.ioNamePtr = tempS; - strcpyX ((char *) hParms.volumeParam.ioNamePtr, pathX, 255); - CtoPstr ((char *) hParms.volumeParam.ioNamePtr); - hParms.volumeParam.ioVRefNum = 0; - hParms.volumeParam.ioVolIndex = -1; - rCode = PBHGetVInfo (&hParms, FALSE); - if (rCode == noErr) - tVRefNum = hParms.volumeParam.ioVRefNum; - else - return FALSE; - topDirID = 0; - } - cParms.hFileInfo.ioNamePtr = tempS; - strcpyX ((char *) cParms.hFileInfo.ioNamePtr, pathX, 255); - CtoPstr ((char *) cParms.hFileInfo.ioNamePtr); - cParms.hFileInfo.ioVRefNum = tVRefNum; - cParms.hFileInfo.ioFDirIndex = 0; - cParms.hFileInfo.ioDirID = topDirID; - rCode = PBGetCatInfo (&cParms, FALSE); - if (rCode == noErr) - tDirID = cParms.hFileInfo.ioDirID; - else - return FALSE; - if (BITCLR(cParms.hFileInfo.ioFlAttrib,4)) return FALSE; /* `Dir' bit */ - } - /**************************************************************************** - * Pass back volume reference number and directory identifier. - ****************************************************************************/ - ASSIGNnotNULL (vRefNum, tVRefNum) - ASSIGNnotNULL (dirID, tDirID) - return TRUE; -} -#endif - -/****************************************************************************** -* AppendToDir. -* If necessary, appends a '/' (UNIX), a '\' (MS-DOS), or a `:' (Mac) to make -* a directory specification to which the file name can then be appended. -******************************************************************************/ - -VISIBLE_PREFIX void AppendToDir (dir, name) -char *dir; -char *name; -{ -#if defined(vms) - strcatX (dir, name, 0); -#endif -#if defined(unix) || defined(posixSHELL) - if (!NULstring(dir)) { - int lastChar = strlen(dir) - 1; - if (dir[lastChar] != '/') strcatX (dir, "/", 0); - } - strcatX (dir, name, 0); -#endif -#if defined(dos) || defined(win32) - if (!NULstring(dir)) { - int lastChar = strlen(dir) - 1; - if (dir[lastChar] != '\\' && dir[lastChar] != ':') strcatX (dir, "\\", 0); - } - strcatX (dir, name, 0); -#endif -#if defined(mac) - if (!NULstring(dir)) { - int lastChar = strlen(dir) - 1; - if (dir[lastChar] != ':') strcatX (dir, ":", 0); - } - strcatX (dir, name, 0); -#endif - return; -} diff --git a/cdf36_3-dist/src/lib/epochu.c b/cdf36_3-dist/src/lib/epochu.c deleted file mode 100644 index fd96c4d..0000000 --- a/cdf36_3-dist/src/lib/epochu.c +++ /dev/null @@ -1,1735 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF EPOCH utility routines for C applications. -* -* Version 2.5b, 29-Oct-97, Hughes STX. -* -* Modification history: -* -* V1.0 24-Jan-91, D Grogan Original version (for CDF V2.0). -* V1.1 25-Mar-91, J Love Added support for Silicon Graphics (MIPSEB -* encoding, IRIX - UNIX). -* V1.2 26-Mar-91, J Love Added "types.h" include for SunOS 4.0.3 -* systems (UNIX). Added "ctypes.h" include and -* removed definitions of toupper & tolower. Use -* toupper the safe way. Added definition for -* toupper if SunOS 4.0.3. -* V1.3 19-Jun-91, J Love Changed epochParse to return FALSE if illegal -* date/time string (and added more error -* checking) and to set 'tSince0'. -* V1.4 29-Jul-91, J Love TRUE/FALSE. Don't display error messages (the -* caller will do that). -* V1.5 23-Sep-91, J Love Modified for IBM-PC port. -* V2.0 1-Apr-92, J Love Added to CDF library. Added additional ways -* A Warnock to display an EPOCH date/time. -* V2.1 30-Jun-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V2.2 24-Jan-94, J Love CDF V2.4. Handle negative EPOCHs. -* V2.3 13-Dec-94, J Love CDF V2.5. -* V2.3a 18-Jan-95, J Love Made `computeEPOCH' more flexible. -* V2.3b 24-Jan-95, J Love Changed `parseEPOCH' for Salford C. Consider -* milliseconds in `encodeEPOCH1'. -* V2.3c 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V2.4 9-May-95, J Love Added parseEPOCH1, parseEPOCH2, & parseEPOCH3. -* V2.4a 13-Jun-95, J Love EPOCH custom format. -* V2.5 3-Oct-96, J Love CDF V2.6 (and the OSF/1 bug in `sprintf'). -* V2.5a 8-Mar-97, J Love Windows NT for MS Visual C/C++ on an IBM PC. -* V2.5b 29-Oct-97, J Love More Windows NT. -* V2.6 29-Jan-04, M Liu Added a new set of CDF_EPOCH16 functions for -* handling fraction of a second up to picosecond. -* V2.7 25-Feb-10, M Liu Modified computeEPOCH and computeEPOCH16 to -* allow day/time fields out of the previously -* defined range, e.g., 0-23 for hour. -* V2.8 12-Aug-10, M Liu Limited width of the fraction so it will not -* overrun the string in AppendFractionPart. -* V2.9 10-Dec-10, M Liu Added encodeEPOCH4, encodeEPOCH16_4, -* parseEPOCH4, parseEPOCH16_4 to handle epochs -* conforming to ISO 8601. -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* Local macro definitions. -******************************************************************************/ - -#define MAX_PART_LEN 10 -#define MAX_MOD_LEN 10 -#define MAX_ePART_LEN 25 - -/****************************************************************************** -* Local function prototypes. -******************************************************************************/ - -static long JulianDay PROTOARGs((long, long, long)); -static char *MonthToken PROTOARGs((long)); -static char *FullDayToken PROTOARGs((char *)); -static Logical AppendFractionPart PROTOARGs(( - char *encoded, double fraction, int defaultWidth, char *modifier -)); -static Logical AppendIntegerPart PROTOARGs(( - char *encoded, long integer, int defaultWidth, Logical defaultLeading0, - char *modifier -)); -static Logical AppendPart PROTOARGs(( - char *encoded, char *ePart, int width, Logical leading0 -)); -void encodeEPOCH16x2 PROTOARGs(( - double epoch, char *encoded -)); -void encodeEPOCH16x3 PROTOARGs(( - double epoch[], char *encoded, size_t width -)); -void encodeEPOCH16x4 PROTOARGs(( - double epoch, char *encoded -)); -static double computeEpoch PROTOARGs(( - long year, long month, long day, long hour, long minute, long second, - long msec -)); -static double computeEpoch16 PROTOARGs(( - long year, long month, long day, long hour, long minute, long second, - long msec, long usec, long nsec, long psec, double epoch[] -)); - -/****************************************************************************** -* parseEPOCH. -* This function parses an input date/time string and returns an EPOCH -* value. The format must be exactly as shown below. Month abbreviations may -* be in any case and are always the first three letters of the month. -* -* Format: dd-mmm-yyyy hh:mm:ss.mmm -* Examples: 1-Apr-1990 03:05:02.000 -* 10-Oct-1993 23:45:49.999 -* -* The expected format is the same as that produced by encodeEPOCH. -******************************************************************************/ - -VISIBLE_PREFIX double parseEPOCH (inString) -char *inString; -{ - char moString[4]; - long year, month, day, hour, minute, second, msec; - int monthX; - if (sscanf(inString,"%ld-%c%c%c-%ld %ld:%ld:%ld.%ld", - &day, &(moString[0]), &(moString[1]), &(moString[2]), &year, - &hour, &minute, &second, &msec) != 9) return ILLEGAL_EPOCH_VALUE; - moString[0] = (char) MakeUpper((int)moString[0]); /* J */ - moString[1] = (char) MakeLower((int)moString[1]); /* a */ - moString[2] = (char) MakeLower((int)moString[2]); /* n */ - moString[3] = NUL; - for (monthX = 1, month = 0; monthX <= 12; monthX++) { - if (!strcmp(moString,MonthToken(monthX))) { - month = monthX; - break; - } - } - if (month == 0) return ILLEGAL_EPOCH_VALUE; - return computeEPOCH (year, month, day, hour, minute, second, msec); -} - -/****************************************************************************** -* parseEPOCH16. -* This function is an extension of parseEPOCH. It is used to handle the time -* that may contain as small as picoseconds (one trillionth of a second). -* A section of micro-, nano- and pico-second is added. -* -* Format: dd-mmm-yyyy hh:mm:ss.mmm.uuu.nnn.ppp -* Examples: 1-Apr-1990 03:05:02.000.000.000.000 -* 10-Oct-1993 23:45:49.999.999.999.999 -* -* The expected format is the same as that produced by encodeEPOCH16. -******************************************************************************/ - -VISIBLE_PREFIX double parseEPOCH16 (inString, epoch) -char *inString; -double epoch[2]; -{ - char moString[4]; - long year, month, day, hour, minute, second, msec, usec, nsec, psec; - double mmm; - int monthX; - if (sscanf(inString,"%ld-%c%c%c-%ld %ld:%ld:%ld.%ld.%ld.%ld.%ld", - &day, &(moString[0]), &(moString[1]), &(moString[2]), &year, - &hour, &minute, &second, &msec, &usec, &nsec, &psec) != 12) - return ILLEGAL_EPOCH_VALUE; - moString[0] = (char) MakeUpper((int)moString[0]); /* J */ - moString[1] = (char) MakeLower((int)moString[1]); /* a */ - moString[2] = (char) MakeLower((int)moString[2]); /* n */ - moString[3] = NUL; - for (monthX = 1, month = 0; monthX <= 12; monthX++) { - if (!strcmp(moString,MonthToken(monthX))) { - month = monthX; - break; - } - } - if (month == 0) return ILLEGAL_EPOCH_VALUE; - mmm = computeEPOCH (year, month, day, hour, minute, second, 0L); - if (mmm == ILLEGAL_EPOCH_VALUE) return ILLEGAL_EPOCH_VALUE; - if (msec < 0 || msec > 999) return ILLEGAL_EPOCH_VALUE; - if (usec < 0 || usec > 999) return ILLEGAL_EPOCH_VALUE; - if (nsec < 0 || nsec > 999) return ILLEGAL_EPOCH_VALUE; - if (psec < 0 || psec > 999) return ILLEGAL_EPOCH_VALUE; - if (year == 9999 && month == 12 && day == 31 && hour == 23 && minute == 59 && - second == 59 && msec == 999 && usec == 999 && nsec == 999 && psec == 999) { - epoch[0] = -1.0E31; - epoch[1] = -1.0E31; - return 0.0; - } - epoch[0] = mmm / (double) 1000.0; - epoch[1] = msec * pow(10.0, 9.0) + usec * pow(10.0, 6.0) + nsec * pow(10.0, 3.0) + - psec; - return (double) 0.0; -} - -/****************************************************************************** -* parseEPOCH1. -* This function parses an input date/time string and returns an EPOCH -* value. The format must be exactly as shown below. Note that if there are -* less than 8 digits after the decimal point, zeros (0's) are assumed for the -* missing digits. -* -* Format: yyyymmdd.ttttttt -* Examples: 19950508.0000000 -* 19671231.58 (== 19671213.5800000) -* -* The expected format is the same as that produced by encodeEPOCH1. -******************************************************************************/ - -VISIBLE_PREFIX double parseEPOCH1 (inString) -char *inString; -{ - char temp[EPOCH1_STRING_LEN+1]; double fraction; int i; - long year, month, day, hour, minute, second, msec, fractionL; - strcpyX (temp, inString, EPOCH1_STRING_LEN); - for (i = strlen(temp); i < EPOCH1_STRING_LEN; i++) temp[i] = '0'; - temp[i] = NUL; - if (sscanf(temp,"%4ld%2ld%2ld.%ld", - &year, &month, &day, &fractionL) != 4) return ILLEGAL_EPOCH_VALUE; - fraction = ((double) fractionL) / 10000000.0; - hour = (long) (fraction * 24.0); - fraction -= (double) (hour / 24.0); - minute = (long) (fraction * 1440.0); - fraction -= (double) (minute / 1440.0); - second = (long) (fraction * 86400.0); - fraction -= (double) (second / 86400.0); - msec = (long) (fraction * 86400000.0); - return computeEPOCH (year, month, day, hour, minute, second, msec); -} - -/****************************************************************************** -* parseEPOCH16_1. -* This function is an extension of parseEPOCH1. It is used to handle the time -* that may contain as small as picoseconds. -* The ttttttt... portion (at least 7-digit or more) represents a fraction of a -* day, -* -* Format: yyyymmdd.ttttttttttttttt -* Examples: 19950508.000000000000000 -* 19671231.58 (== 19671213.580000000000000) -* -* The expected format is the same as that produced by encodeEPOCH16_1. -******************************************************************************/ - -VISIBLE_PREFIX double parseEPOCH16_1 (inString, epoch) -char *inString; -double epoch[2]; -{ - char temp[EPOCH16_1_STRING_LEN+1]; double fraction; int i; - long year, month, day, hour, minute, second, fractionL1, fractionL2; - double mmm; - - if (!strcmp (inString, "99991231.999999999999999")) { - epoch[0] = -1.0E31; - epoch[1] = -1.0E31; - return 0.0; - } - - strcpyX (temp, inString, EPOCH16_1_STRING_LEN); - for (i = strlen(temp); i < EPOCH16_1_STRING_LEN; i++) temp[i] = '0'; - temp[i] = NUL; - if (sscanf(temp,"%4ld%2ld%2ld.%7ld%8ld", - &year, &month, &day, &fractionL1, &fractionL2) != 5) - return ILLEGAL_EPOCH_VALUE; - fraction = ((double) fractionL1 * pow(10.0, 8.0) + (double) fractionL2) * - pow(10.0, -15.0); - hour = (long) (fraction * 24.0); - fraction -= (double) (hour / 24.0); - minute = (long) (fraction * 1440.0); - fraction -= (double) (minute / 1440.0); - second = (long) (fraction * 86400.0); - fraction -= (double) (second / 86400.0); - mmm = computeEPOCH (year, month, day, hour, minute, second, 0L); - if (mmm == ILLEGAL_EPOCH_VALUE) return ILLEGAL_EPOCH_VALUE; - epoch[0] = mmm / (double) 1000.0; - epoch[1] = fraction * 86400.0 * pow(10.0, 12.0); - return (double) 0.0; -} - -/****************************************************************************** -* parseEPOCH2. -* This function parses an input date/time string and returns an EPOCH -* value. The format must be exactly as shown below. -* -* Format: yyyymmddhhmmss -* Examples: 19950508000000 -* 19671231235959 -* -* The expected format is the same as that produced by encodeEPOCH2. -******************************************************************************/ - -VISIBLE_PREFIX double parseEPOCH2 (inString) -char *inString; -{ - long year, month, day, hour, minute, second; - if (sscanf(inString,"%4ld%2ld%2ld%2ld%2ld%2ld", - &year,&month,&day,&hour,&minute,&second) != 6) { - return ILLEGAL_EPOCH_VALUE; - } - return computeEPOCH (year, month, day, hour, minute, second, 0L); -} - -/****************************************************************************** -* parseEPOCH16_2. -* This function is an extension of parseEPOCH2. It is used to handle the time -* that may contain as small as picoseconds. -* -* Format: yyyymmddhhmmss -* Examples: 19950508000000 -* 19671231235959 -* -* The expected format is the same as that produced by encodeEPOCH16_2. -******************************************************************************/ - -VISIBLE_PREFIX double parseEPOCH16_2 (inString, epoch) -char *inString; -double epoch[2]; -{ - long year, month, day, hour, minute, second; - double mmm; - if (sscanf(inString,"%4ld%2ld%2ld%2ld%2ld%2ld", - &year,&month,&day,&hour,&minute,&second) != 6) { - return ILLEGAL_EPOCH_VALUE; - } - mmm = computeEPOCH (year, month, day, hour, minute, second, 0L); - if (mmm == ILLEGAL_EPOCH_VALUE) return ILLEGAL_EPOCH_VALUE; - epoch[0] = mmm / (double) 1000.0; - epoch[1] = 0.0; - return (double) 0.0; -} - -/****************************************************************************** -* parseEPOCH3. -* This function parses an input date/time string and returns an EPOCH value. -* The format must be exactly as shown below. -* -* Format: yyyy-mm-ddThh:mm:ss.cccZ -* Examples: 1990-04-01T03:05:02.000Z -* 1993-10-10T23:45:49.999Z -* -* The expected format is the same as that produced by encodeEPOCH3. -******************************************************************************/ - -VISIBLE_PREFIX double parseEPOCH3 (inString) -char *inString; -{ - long year, month, day, hour, minute, second, msec; - if (sscanf(inString,"%ld-%ld-%ldT%ld:%ld:%ld.%ldZ", - &year,&month,&day,&hour,&minute,&second,&msec) != 7) { - return ILLEGAL_EPOCH_VALUE; - } - return computeEPOCH (year, month, day, hour, minute, second, msec); -} - -/****************************************************************************** -* parseEPOCH16_3. -* This function is an extension of parseEPOCH3. It is used to handle the time -* that may contain as small as picoseconds. -* -* Format: yyyy-mm-ddThh:mm:ss.ccc.mmm.nnn.pppZ -* Examples: 1990-04-01T03:05:02.000.000.000.000Z -* 1993-10-10T23:45:49.999.999.999.999Z -* -* The expected format is the same as that produced by encodeEPOCH16_3. -******************************************************************************/ - -VISIBLE_PREFIX double parseEPOCH16_3 (inString, epoch) -char *inString; -double epoch[2]; -{ - long year, month, day, hour, minute, second, msec, usec, nsec, psec; - int len; - double mmm; - len = strlen(inString); - if (len < EPOCH16_3_STRING_LEN) return ILLEGAL_EPOCH_VALUE; - if (sscanf(inString,"%ld-%ld-%ldT%ld:%ld:%ld.%ld.%ld.%ld.%ldZ", - &year,&month,&day,&hour,&minute,&second,&msec,&usec,&nsec,&psec) - != 10) { - return ILLEGAL_EPOCH_VALUE; - } - if (year == 9999 && month == 12 && day == 31 && hour == 23 && minute == 59 && - second == 59 && msec == 999 && usec == 999 && nsec == 999 && psec == 999) { - epoch[0] = -1.0E31; - epoch[1] = -1.0E31; - return (double) 0.0; - } - - mmm = computeEPOCH (year, month, day, hour, minute, second, 0L); - if (mmm == ILLEGAL_EPOCH_VALUE) return ILLEGAL_EPOCH_VALUE; - epoch[0] = mmm / (double) 1000.0; - epoch[1] = (double) psec + (double) nsec * pow(10.0, 3.0) + - (double) usec * pow(10.0, 6.0) + (double) msec * pow(10.0, 9.0); - return (double) 0.0; -} - -/****************************************************************************** -* parseEPOCH4. -* This function parses an input date/time string and returns an EPOCH value. -* The format must conform to ISO 8601 as the following shows: -* -* Format: yyyy-mm-ddThh:mm:ss.ccc -* Examples: 1990-04-01T03:05:02.000 -* 1993-10-10T23:45:49.999 -* -* The expected format is the same as that produced by encodeEPOCH4. -******************************************************************************/ - -VISIBLE_PREFIX double parseEPOCH4 (inString) -char *inString; -{ - long year, month, day, hour, minute, second, msec; - if (sscanf(inString,"%ld-%ld-%ldT%ld:%ld:%ld.%ld", - &year,&month,&day,&hour,&minute,&second,&msec) != 7) { - return ILLEGAL_EPOCH_VALUE; - } - return computeEPOCH (year, month, day, hour, minute, second, msec); -} - -/****************************************************************************** -* parseEPOCH16_4. -* This function is an extension of parseEPOCH4. It is used to handle the time -* that may contain as small as picoseconds. The string conforms to ISO 8601. -* -* Format: yyyy-mm-ddThh:mm:ss.cccmmmnnnppp -* Examples: 1990-04-01T03:05:02.000000000000 -* 1993-10-10T23:45:49.999999999999 -* -* The expected format is the same as that produced by encodeEPOCH16_4. -******************************************************************************/ - -VISIBLE_PREFIX double parseEPOCH16_4 (inString, epoch) -char *inString; -double epoch[2]; -{ - long year, month, day, hour, minute, second, msec, usec, nsec, psec; - int len; - double mmm; - len = strlen(inString); - if (len < EPOCH16_4_STRING_LEN) return ILLEGAL_EPOCH_VALUE; - if (sscanf(inString,"%ld-%ld-%ldT%ld:%ld:%ld.%3ld%3ld%3ld%3ld", - &year,&month,&day,&hour,&minute,&second,&msec,&usec,&nsec,&psec) - != 10) { - return ILLEGAL_EPOCH_VALUE; - } - if (year == 9999 && month == 12 && day == 31 && hour == 23 && minute == 59 && - second == 59 && msec == 999 && usec == 999 && nsec == 999 && psec == 999) { - epoch[0] = -1.0E31; - epoch[1] = -1.0E31; - return (double) 0.0; - } - - mmm = computeEPOCH (year, month, day, hour, minute, second, 0L); - if (mmm == ILLEGAL_EPOCH_VALUE) return ILLEGAL_EPOCH_VALUE; - epoch[0] = mmm / (double) 1000.0; - epoch[1] = (double) psec + (double) nsec * pow(10.0, 3.0) + - (double) usec * pow(10.0, 6.0) + (double) msec * pow(10.0, 9.0); - return (double) 0.0; -} - -/****************************************************************************** -* encodeEPOCH. -* Converts an EPOCH value into a readable date/time string. -* -* Format: dd-mmm-yyyy hh:mm:ss.ccc -* Examples: 01-Apr-1990 03:05:02.000 -* 10-Oct-1993 23:45:49.999 -* -* This format is the same as that expected by parseEPOCH. -******************************************************************************/ - -VISIBLE_PREFIX void encodeEPOCH (epoch, epString) -double epoch; -char epString[EPOCH_STRING_LEN+1]; -{ - if (epoch == -1.0E31) { - strcpyX (epString, "31-Dec-9999 23:59:59.999", 0); - return; - } - - encodeEPOCHx (epoch, "-- ::.", - epString); - return; -} - -/****************************************************************************** -* encodeEPOCH16. -* This function is an extension of parseEPOCH. It is used to handle the time -* that may contain as small as picoseconds (10**-12 second). -* -* -* Format: dd-mmm-yyyy hh:mm:ss.ccc.uuu.nnn.ppp -* Examples: 01-Apr-1990 03:05:02.000.000.000.000 -* 10-Oct-1993 23:45:49.999.999.999.999 -* 012345678901234567890123456789012345 -* This format is the same as that expected by parseEPOCH16. -******************************************************************************/ - -VISIBLE_PREFIX void encodeEPOCH16 (epoch, epString) -double epoch[2]; -char epString[EPOCH16_STRING_LEN+1]; -{ - char tmp[EPOCH1_STRING_LEN+1]; - - if (epoch[0] == -1.0E31 && epoch[1] == -1.0E31) { - strcpyX (epString, "31-Dec-9999 23:59:59.999.999.999.999", 0); - return; - } - - encodeEPOCHx (epoch[0]*1000.0, - "-- ::.", - epString); - encodeEPOCH16x2 (epoch[1], tmp); - strcpyX (epString+21, tmp, 15); - epString[EPOCH16_STRING_LEN] = NUL; - return; -} - -/****************************************************************************** -* encodeEPOCH1. -* Converts an EPOCH value into a readable date/time string. -* -* Format: yyyymmdd.ttttttt -* Examples: 19900401.3658893 -* 19611231.0000000 -* -* This format is the same as that expected by parseEPOCH1. -******************************************************************************/ - -VISIBLE_PREFIX void encodeEPOCH1 (epoch, epString) -double epoch; -char epString[EPOCH1_STRING_LEN+1]; -{ - if (epoch == -1.0E31) { - strcpyX (epString, "99991231.9999999", 0); - return; - } - - encodeEPOCHx (epoch, ".", - epString); - return; -} - -/****************************************************************************** -* encodeEPOCH16_1. -* This function is an extension of encodeEPOCH1. It is used to handle the time -* that may contain as small as picoseconds. -* -* Converts an EPOCH value into a readable date/time string. -* -* Format: yyyymmdd.ttttttttttttttt -* Examples: 19900401.365889324567890 -* 19611231.000000000000000 -* -* This format is the same as that expected by parseEPOCH16_1. -******************************************************************************/ - -VISIBLE_PREFIX void encodeEPOCH16_1 (epoch, epString) -double epoch[2]; -char epString[EPOCH16_1_STRING_LEN+1]; -{ - char tmp[15+1]; - - if (epoch[0] == -1.0E31 && epoch[1] == -1.0E31) { - strcpyX (epString, "99991231.999999999999999", 0); - return; - } - - encodeEPOCHx (epoch[0]*1000.0, ".", - epString); - encodeEPOCH16x3 (epoch, tmp, (size_t) sizeof(tmp)-1); - strcpyX (epString+9, tmp, 15); - epString[EPOCH16_1_STRING_LEN] = NUL; - return ; -} - -/****************************************************************************** -* encodeEPOCH2. -* Converts an EPOCH value into a readable date/time string. -* -* Format: yyyymmddhhmmss -* Examples: 19900401235959 -* 19611231000000 -* -* This format is the same as that expected by parseEPOCH2. -******************************************************************************/ - -VISIBLE_PREFIX void encodeEPOCH2 (epoch, epString) -double epoch; -char epString[EPOCH2_STRING_LEN+1]; -{ - if (epoch == -1.0E31) { - strcpyX (epString, "99991231235959", 0); - return; - } - - encodeEPOCHx (epoch, "", - epString); - return; -} - -/****************************************************************************** -* encodeEPOCH16_2. -* This function is an extension of encodeEPOCH2. It is used to handle the time -* that may contain as small as picoseconds. -* -* Format: yyyymmddhhmmss -* Examples: 19900401235959 -* 19611231000000 -* -* This format is the same as that expected by parseEPOCH16_2. -******************************************************************************/ - -VISIBLE_PREFIX void encodeEPOCH16_2 (epoch, epString) -double epoch[2]; -char epString[EPOCH16_2_STRING_LEN+1]; -{ - if (epoch[0] == -1.0E31 && epoch[1] == -1.0E31) { - strcpyX (epString, "99991231235959", 0); - return; - } - - encodeEPOCHx (epoch[0]*1000.0, "", - epString); - return; -} - -/****************************************************************************** -* encodeEPOCH3. -* Converts an EPOCH value into a readable date/time string. -* -* Format: yyyy-mm-ddThh:mm:ss.cccZ -* Examples: 1990-04-01T03:05:02.000Z -* 1993-10-10T23:45:49.999Z -* -* This format is the same as that expected by parseEPOCH3. -******************************************************************************/ - -VISIBLE_PREFIX void encodeEPOCH3 (epoch, epString) -double epoch; -char epString[EPOCH3_STRING_LEN+1]; -{ - if (epoch == -1.0E31) { - strcpyX (epString, "9999-12-31T23:59:59.999Z", 0); - return; - } - - encodeEPOCHx (epoch, "--T::.Z", - epString); - return; -} - -/****************************************************************************** -* encodeEPOCH4. -* Converts an EPOCH value into a readable date/time, ISO 8601 string. -* -* Format: yyyy-mm-ddThh:mm:ss.ccc -* Examples: 1990-04-01T03:05:02.000 -* 1993-10-10T23:45:49.999 -* -* This format is the same as that expected by parseEPOCH4. -******************************************************************************/ - -VISIBLE_PREFIX void encodeEPOCH4 (epoch, epString) -double epoch; -char epString[EPOCH4_STRING_LEN+1]; -{ - if (epoch == -1.0E31) { - strcpyX (epString, "9999-12-31T23:59:59.999", 0); - return; - } - - encodeEPOCHx (epoch, "--T::.", - epString); - return; -} - -/****************************************************************************** -* encodeEPOCH16_3. -* This function is an extension of encodeEPOCH3. It is used to handle the time -* that may contain as small as picoseconds. -* -* Format: yyyy-mm-ddThh:mm:ss.mmm.uuu.nnn.pppZ -* Examples: 1990-04-01T03:05:02.000.000.000.000Z -* 1993-10-10T23:45:49.999.999.999.999Z -* 012345678901234567890123456789012345 -* This format is the same as that expected by parseEPOCH16_3. -******************************************************************************/ - -VISIBLE_PREFIX void encodeEPOCH16_3 (epoch, epString) -double epoch[2]; -char epString[EPOCH16_3_STRING_LEN+1]; -{ - char tmp[EPOCH16_3_STRING_LEN+1]; - - if (epoch[0] == -1.0E31 && epoch[1] == -1.0E31) { - strcpyX (epString, "9999-12-31T23:59:59.999.999.999.999Z", 0); - return; - } - - encodeEPOCHx (epoch[0]*1000.0, - "--T::.", tmp); - strcpyX (epString, tmp, 20); - encodeEPOCH16x2 (epoch[1], tmp); - strcpyX (epString+20, tmp, EPOCH16_3_STRING_LEN-20-1); - epString[EPOCH16_3_STRING_LEN-1] = 'Z'; - epString[EPOCH16_3_STRING_LEN] = NUL; - return; -} - -/****************************************************************************** -* encodeEPOCH16_4. -* This function is an extension of encodeEPOCH4. It is used to handle the time -* that may contain as small as picoseconds and make the string an ISO 8601 -* format. -* -* Format: yyyy-mm-ddThh:mm:ss.mmmuuunnnppp -* Examples: 1990-04-01T03:05:02.000000000000 -* 1993-10-10T23:45:49.999999999999 -* 01234567890123456789012345678901 -* This format is the same as that expected by parseEPOCH16_4. -******************************************************************************/ - -VISIBLE_PREFIX void encodeEPOCH16_4 (epoch, epString) -double epoch[2]; -char epString[EPOCH16_4_STRING_LEN+1]; -{ - char tmp[EPOCH16_4_STRING_LEN+1]; - - if (epoch[0] == -1.0E31 && epoch[1] == -1.0E31) { - strcpyX (epString, "9999-12-31T23:59:59.999999999999", 0); - return; - } - - encodeEPOCHx (epoch[0]*1000.0, - "--T::.", tmp); - strcpyX (epString, tmp, 20); - encodeEPOCH16x4 (epoch[1], tmp); - strcpyX (epString+20, tmp, EPOCH16_4_STRING_LEN-20); - epString[EPOCH16_4_STRING_LEN] = NUL; - return; -} - -/****************************************************************************** -* encodeEPOCHx. -******************************************************************************/ - -VISIBLE_PREFIX void encodeEPOCHx (epoch, format, encoded) -double epoch; -char format[EPOCHx_FORMAT_MAX]; -char encoded[EPOCHx_STRING_MAX+1]; -{ - char *ptr = format; /* Current position in format string. */ - char *ptrD; /* Pointer to decimal point. */ - char *ptrE; /* Pointer to ending right angle bracket. */ - char *p; /* Temporary pointer. */ - char part[MAX_PART_LEN+1]; /* Part being encoded. */ - char mod[MAX_MOD_LEN+1]; /* Part modifier. */ - long year, month, day, hour, - minute, second, msec; /* EPOCH components. */ - /**************************************************************************** - * Break EPOCH down into its components, validate the format specification, - * and initialize the encoded string. - ****************************************************************************/ - if (format == NULL || NULstring(format)) { - encodeEPOCH (epoch, encoded); - return; - } - EPOCHbreakdown (epoch, &year, &month, &day, &hour, &minute, &second, &msec); - MakeNUL (encoded); - /**************************************************************************** - * Scan format string. - ****************************************************************************/ - for (;;) { - switch (*ptr) { - /*********************************************************************** - * End of format string. - ***********************************************************************/ - case NUL: - return; - /*********************************************************************** - * Start of part to be encoded. - ***********************************************************************/ - case '<': - /********************************************************************* - * If next character is also a `<' (character stuffing), then append - * a `<' and move on. - *********************************************************************/ - if (*(ptr+1) == '<') { - strcatX (encoded, "<", EPOCHx_STRING_MAX); - ptr += 2; - break; - } - /********************************************************************* - * Find ending right angle bracket. - *********************************************************************/ - ptrE = strchr (ptr + 1, '>'); - if (ptrE == NULL) { - strcatX (encoded, "?", EPOCHx_STRING_MAX); - return; - } - /********************************************************************* - * Check for a part modifier. - *********************************************************************/ - ptrD = strchr (ptr + 1, '.'); - if (ptrD != NULL && ptrD < ptrE) { - MakeNUL (part); - for (p = ptr+1; p != ptrD; p++) catchrX (part, (int) *p, - MAX_PART_LEN); - MakeNUL (mod); - for (p = ptrD+1; p != ptrE; p++) catchrX (mod, (int) *p, - MAX_MOD_LEN); - } - else { - MakeNUL (part); - for (p = ptr+1; p != ptrE; p++) catchrX (part, (int) *p, - MAX_PART_LEN); - MakeNUL (mod); - } - ptr = ptrE + 1; - /********************************************************************* - * Day (of month), . - *********************************************************************/ - if (!strcmp(part,"dom")) { - if (!AppendIntegerPart(encoded,day,0,FALSE,mod)) return; - break; - } - /********************************************************************* - * Day of year, . - *********************************************************************/ - if (!strcmp(part,"doy")) { - long doy = JulianDay(year,month,day) - JulianDay(year,1L,1L) + 1; - if (!AppendIntegerPart(encoded,doy,3,TRUE,mod)) return; - break; - } - /********************************************************************* - * Month (3-character), . - *********************************************************************/ - if (!strcmp(part,"month")) { - strcatX (encoded, MonthToken(month), EPOCHx_STRING_MAX); - break; - } - /********************************************************************* - * Month (digits), . - *********************************************************************/ - if (!strcmp(part,"mm")) { - if (!AppendIntegerPart(encoded,month,0,FALSE,mod)) return; - break; - } - /********************************************************************* - * Year (full), . - *********************************************************************/ - if (!strcmp(part,"year")) { - if (!AppendIntegerPart(encoded,year,4,TRUE,mod)) return; - break; - } - /********************************************************************* - * Year (2-digit), . - *********************************************************************/ - if (!strcmp(part,"yr")) { - long yr = year % 100L; - if (!AppendIntegerPart(encoded,yr,2,TRUE,mod)) return; - break; - } - /********************************************************************* - * Hour, . - *********************************************************************/ - if (!strcmp(part,"hour")) { - if (!AppendIntegerPart(encoded,hour,2,TRUE,mod)) return; - break; - } - /********************************************************************* - * Minute, . - *********************************************************************/ - if (!strcmp(part,"min")) { - if (!AppendIntegerPart(encoded,minute,2,TRUE,mod)) return; - break; - } - /********************************************************************* - * Second, . - *********************************************************************/ - if (!strcmp(part,"sec")) { - if (!AppendIntegerPart(encoded,second,2,TRUE,mod)) return; - break; - } - /********************************************************************* - * Fraction of second, . - *********************************************************************/ - if (!strcmp(part,"fos")) { - double fos = ((double) msec) / 1000.0; - if (!AppendFractionPart(encoded,fos,3,mod)) return; - break; - } - /********************************************************************* - * Fraction of day, . - *********************************************************************/ - if (!strcmp(part,"fod")) { - double fod = ((double) hour / 24.0) + - ((double) minute / 1440.0) + - ((double) second / 86400.0) + - ((double) msec / 86400000.0); - if (!AppendFractionPart(encoded,fod,8,mod)) return; - break; - } - /********************************************************************* - * Unknown/unsupported part. - *********************************************************************/ - strcatX (encoded, "?", EPOCHx_STRING_MAX); - return; - /*********************************************************************** - * Character to be copied. - ***********************************************************************/ - default: - catchrX (encoded, (int) *ptr, EPOCHx_STRING_MAX); - ptr++; - break; - } - } -} - -/****************************************************************************** -* encodeEPOCH16_x. -******************************************************************************/ - -VISIBLE_PREFIX void encodeEPOCH16_x (epoch, format, encoded) -double epoch[2]; -char format[EPOCHx_FORMAT_MAX]; -char encoded[EPOCHx_STRING_MAX+1]; -{ - char *ptr = format; /* Current position in format string. */ - char *ptrD; /* Pointer to decimal point. */ - char *ptrE; /* Pointer to ending right angle bracket. */ - char *p; /* Temporary pointer. */ - char part[MAX_PART_LEN+1]; /* Part being encoded. */ - char mod[MAX_MOD_LEN+1]; /* Part modifier. */ - long year, month, day, hour, - minute, second; - long msec, usec, nsec, psec; /* EPOCH components. */ - /**************************************************************************** - * Break EPOCH down into its components, validate the format specification, - * and initialize the encoded string. - ****************************************************************************/ - if (format == NULL || NULstring(format)) { - encodeEPOCH (epoch[0]*1000.0, encoded); - /* add epoch[1]... */ - return; - } - EPOCH16breakdown (epoch, &year, &month, &day, &hour, &minute, &second, - &msec, &usec, &nsec, &psec); - MakeNUL (encoded); - /**************************************************************************** - * Scan format string. - ****************************************************************************/ - for (;;) { - switch (*ptr) { - /*********************************************************************** - * End of format string. - ***********************************************************************/ - case NUL: - return; - /*********************************************************************** - * Start of part to be encoded. - ***********************************************************************/ - case '<': - /********************************************************************* - * If next character is also a `<' (character stuffing), then append - * a `<' and move on. - *********************************************************************/ - if (*(ptr+1) == '<') { - strcatX (encoded, "<", EPOCHx_STRING_MAX); - ptr += 2; - break; - } - /********************************************************************* - * Find ending right angle bracket. - *********************************************************************/ - ptrE = strchr (ptr + 1, '>'); - if (ptrE == NULL) { - strcatX (encoded, "?", EPOCHx_STRING_MAX); - return; - } - /********************************************************************* - * Check for a part modifier. - *********************************************************************/ - ptrD = strchr (ptr + 1, '.'); - if (ptrD != NULL && ptrD < ptrE) { - MakeNUL (part); - for (p = ptr+1; p != ptrD; p++) catchrX (part, (int) *p, - MAX_PART_LEN); - MakeNUL (mod); - for (p = ptrD+1; p != ptrE; p++) catchrX (mod, (int) *p, - MAX_MOD_LEN); - } - else { - MakeNUL (part); - for (p = ptr+1; p != ptrE; p++) catchrX (part, (int) *p, - MAX_PART_LEN); - MakeNUL (mod); - } - ptr = ptrE + 1; - /********************************************************************* - * Day (of month), . - *********************************************************************/ - if (!strcmp(part,"dom")) { - if (!AppendIntegerPart(encoded,day,0,FALSE,mod)) return; - break; - } - /********************************************************************* - * Day of year, . - *********************************************************************/ - if (!strcmp(part,"doy")) { - long doy = JulianDay(year,month,day) - JulianDay(year,1L,1L) + 1; - if (!AppendIntegerPart(encoded,doy,3,TRUE,mod)) return; - break; - } - /********************************************************************* - * Month (3-character), . - *********************************************************************/ - if (!strcmp(part,"month")) { - strcatX (encoded, MonthToken(month), EPOCHx_STRING_MAX); - break; - } - /********************************************************************* - * Month (digits), . - *********************************************************************/ - if (!strcmp(part,"mm")) { - if (!AppendIntegerPart(encoded,month,0,FALSE,mod)) return; - break; - } - /********************************************************************* - * Year (full), . - *********************************************************************/ - if (!strcmp(part,"year")) { - if (!AppendIntegerPart(encoded,year,4,TRUE,mod)) return; - break; - } - /********************************************************************* - * Year (2-digit), . - *********************************************************************/ - if (!strcmp(part,"yr")) { - long yr = year % 100L; - if (!AppendIntegerPart(encoded,yr,2,TRUE,mod)) return; - break; - } - /********************************************************************* - * Hour, . - *********************************************************************/ - if (!strcmp(part,"hour")) { - if (!AppendIntegerPart(encoded,hour,2,TRUE,mod)) return; - break; - } - /********************************************************************* - * Minute, . - *********************************************************************/ - if (!strcmp(part,"min")) { - if (!AppendIntegerPart(encoded,minute,2,TRUE,mod)) return; - break; - } - /********************************************************************* - * Second, . - *********************************************************************/ - if (!strcmp(part,"sec")) { - if (!AppendIntegerPart(encoded,second,2,TRUE,mod)) return; - break; - } - /********************************************************************* - * Fraction of second, . - *********************************************************************/ - if (!strcmp(part,"fos")) { - double fos = (double) msec / pow (10.0, 3.0) + - (double) usec / pow (10.0, 6.0) + - (double) nsec / pow (10.0, 9.0) + - (double) psec / pow (10.0, 12.0); - if (!AppendFractionPart(encoded,fos,12,mod)) return; - break; - } - /********************************************************************* - * Millisecond, . - *********************************************************************/ - if (!strcmp(part,"msc")) { - if (!AppendIntegerPart(encoded,msec,3,TRUE,mod)) return; - break; - } - /********************************************************************* - * Microsecond, . - *********************************************************************/ - if (!strcmp(part,"usc")) { - if (!AppendIntegerPart(encoded,usec,3,TRUE,mod)) return; - break; - } - /********************************************************************* - * Nanosecond, . - *********************************************************************/ - if (!strcmp(part,"nsc")) { - if (!AppendIntegerPart(encoded,nsec,3,TRUE,mod)) return; - break; - } - /********************************************************************* - * Picosecond, . - *********************************************************************/ - if (!strcmp(part,"psc")) { - if (!AppendIntegerPart(encoded,psec,3,TRUE,mod)) return; - break; - } - /********************************************************************* - * Fraction of day, . - *********************************************************************/ - if (!strcmp(part,"fod")) { - double fod = ((double) hour / 24.0) + - ((double) minute / 1440.0) + - ((double) second / 86400.0) + - ((double) msec / 86400000.0); - if (!AppendFractionPart(encoded,fod,15,mod)) return; - break; - } - /********************************************************************* - * Unknown/unsupported part. - *********************************************************************/ - strcatX (encoded, "?", EPOCHx_STRING_MAX); - return; - /*********************************************************************** - * Character to be copied. - ***********************************************************************/ - default: - catchrX (encoded, (int) *ptr, EPOCHx_STRING_MAX); - ptr++; - break; - } - } -} - -static Logical AppendFractionPart (encoded, fraction, defaultWidth, modifier) -char *encoded; -double fraction; -int defaultWidth; -char *modifier; -{ - char ePart[MAX_ePART_LEN+1]; int width, i; - if (!NULstring(modifier)) { - if (sscanf(modifier,"%d",&width) != 1) { - strcatX (encoded, "?", EPOCHx_STRING_MAX); - return FALSE; - } - if (width < 1) { - strcatX (encoded, "?", EPOCHx_STRING_MAX); - return FALSE; - } - } - else - width = defaultWidth; - if ((width + 2) > MAX_ePART_LEN) - width = MAX_ePART_LEN - 2; - snprintf (ePart, (size_t) sizeof(ePart), "%*.*f", width + 2, width, - fraction); -#if defined(alphaosf) - /**************************************************************************** - * V3.2 of OSF/1 apparently has a bug involving `sprintf'. The preceeding - * call to `sprintf' produces a string containing one too many digits after - * the decimal. Eg., if width=7 the encoded string might be 0.12345678 - * rather than 0.1234567 as it should be. So we'll fix it... - ****************************************************************************/ - ePart[width+2] = NUL; -#endif - /**************************************************************************** - * If the encoded value was rounded up to 1.000..., then replace all of the - * digits after the decimal with `9's before appending. - ****************************************************************************/ - if (ePart[0] == '1') { - for (i = 0; i < width; i++) ePart[i+2] = '9'; - } - return AppendPart(encoded,strchr(ePart,'.')+1,width,FALSE); -} - -static Logical AppendIntegerPart (encoded, integer, defaultWidth, - defaultLeading0, modifier) -char *encoded; -long integer; -int defaultWidth; -Logical defaultLeading0; -char *modifier; -{ - char ePart[MAX_ePART_LEN+1]; int width; Logical leading0; - if (!NULstring(modifier)) { - if (sscanf(modifier,"%d",&width) != 1) { - strcatX (encoded, "?", EPOCHx_STRING_MAX); - return FALSE; - } - if (width < 0) { - strcatX (encoded, "?", EPOCHx_STRING_MAX); - return FALSE; - } - leading0 = (modifier[0] == '0'); - } - else { - width = defaultWidth; - leading0 = defaultLeading0; - } - snprintf (ePart, (size_t) sizeof(ePart), "%ld", integer); - return AppendPart (encoded, ePart, width, leading0); -} - -static Logical AppendPart (encoded, ePart, width, leading0) -char *encoded; -char *ePart; -int width; -Logical leading0; -{ - int i; - if (width == 0) { - strcatX (encoded, ePart, EPOCHx_STRING_MAX); - } - else { - int length = (int) strlen(ePart); - if (length > width) { - for (i = 0; i < width; i++) strcatX (encoded, "*", EPOCHx_STRING_MAX); - } - else { - int pad = width - length; - if (pad > 0) { - for (i = 0; i < pad; i++) strcatX (encoded, BOO(leading0,"0"," "), - EPOCHx_STRING_MAX); - } - strcatX (encoded, ePart, EPOCHx_STRING_MAX); - } - } - return TRUE; -} - -void encodeEPOCH16x2 (epoch, encoded) -double epoch; -char *encoded; -{ - long msec, usec, nsec, psec; - double mmm; - psec = (long) fmod (epoch, (double) 1000.0); - mmm = epoch / (double) 1000.0; - nsec = (long) fmod (mmm, (double) 1000.0); - mmm = mmm / (double) 1000.0; - usec = (long) fmod (mmm, (double) 1000.0); - msec = (long) (mmm / (double) 1000.0); - snprintf(encoded, (size_t) 15+1, "%3.3ld.%3.3ld.%3.3ld.%3.3ld", - msec, usec, nsec, psec); - encoded[15] = NUL; - return; -} - -void encodeEPOCH16x3 (epoch, encoded, width) -double epoch[2]; -char *encoded; -size_t width; -{ - char tmp[17+1]; - long year, month, day, hour, minute, second, msec, usec, nsec, psec; - double mmm1, mmm2, mmm3; - EPOCH16breakdown (epoch, &year, &month, &day, &hour, &minute, &second, - &msec, &usec, &nsec, &psec); - mmm1 = ((double) hour * 3600.0 + (double) minute * 60.0 + (double) second) / - 86400.0; - mmm2 = ((double) msec * pow(10.0, 9.0) + (double) usec * pow(10.0, 6.0) + - (double) nsec * pow(10.0, 3.0) + (double) psec) / - (86400.0 * pow(10.0, 12.0)); - mmm3 = mmm1 + mmm2; - if (mmm3 >= 1.0) { - if (mmm1 > 0.0 || mmm2 > 1.0E9) - strcpyX (tmp, "0.999999999999999", 0); - } else - snprintf(tmp, (size_t) sizeof(tmp), "%.15f", mmm3); - strcpyX (encoded, tmp+2, (int) width); - return; -} - -void encodeEPOCH16x4 (epoch, encoded) -double epoch; -char *encoded; -{ - long msec, usec, nsec, psec; - double mmm; - psec = (long) fmod (epoch, (double) 1000.0); - mmm = epoch / (double) 1000.0; - nsec = (long) fmod (mmm, (double) 1000.0); - mmm = mmm / (double) 1000.0; - usec = (long) fmod (mmm, (double) 1000.0); - msec = (long) (mmm / (double) 1000.0); - snprintf(encoded, (size_t) 12+1, "%3.3ld%3.3ld%3.3ld%3.3ld", - msec, usec, nsec, psec); - encoded[12] = NUL; - return; -} - -/****************************************************************************** -* computeEPOCH. -* Computes (and returns) an EPOCH value based on its component parts. -* ILLEGAL_EPOCH_VALUE is returned if an illegal component part is detected. -******************************************************************************/ - -VISIBLE_PREFIX double computeEPOCH (year, month, day, hour, minute, second, - msec) -long year, month, day, hour, minute, second, msec; -{ - long daysSince0AD, msecInDay; - - /**************************************************************************** - * Mark 9999-12-31 23:59:59:999 as an invalid date. - ****************************************************************************/ - if (year == 9999L && month == 12L && day == 31L && hour == 23L && - minute == 59L && second == 59L && msec == 999L) - return -1.0*pow(10.0, 31.0); - if (year < 0L) return ILLEGAL_EPOCH_VALUE; - if ((year > 9999L) || (month < 0L || month > 12L) || - (hour < 0L || hour > 23L) || (minute < 0L || minute > 59L) || - (second < 0L || second > 59L) || (msec < 0L || msec > 999L)) - return computeEpoch(year,month,day,hour,minute,second,msec); - if (month == 0L) { - if (day < 1L || day > 366L) - return computeEpoch(year,month,day,hour,minute,second,msec); - } else { - if (day < 1L || day > 31L) - return computeEpoch(year,month,day,hour,minute,second,msec); - } - if (hour == 0L && minute == 0L && second == 0L) { - if (msec < 0L || msec > 86399999L) - return computeEpoch(year,month,day,hour,minute,second,msec); - } - /**************************************************************************** - * Calculate the days since 0 A.D (1-Jan-0000). If a value of zero is passed - * in for `month', assume that `day' is the day-of-year (DOY) with January 1st - * being day 1. - ****************************************************************************/ - if (month == 0L) { - daysSince0AD = JulianDay(year,1L,1L) + (day-1) - 1721060L; - } - else { - daysSince0AD = JulianDay(year,month,day) - 1721060L; - } - /**************************************************************************** - * Calculate the millisecond in the day (with the first millisecond being 0). - * If values of zero are passed in for `hour', `minute', and `second', assume - * that `msec' is the millisecond in the day. - ****************************************************************************/ - if (hour == 0L && minute == 0L && second == 0L) { - msecInDay = msec; - } - else { - msecInDay = (3600000L * hour) + (60000L * minute) + (1000L * second) + msec; - } - /**************************************************************************** - * Return the milliseconds since 0 A.D. - ****************************************************************************/ - return (86400000.0 * daysSince0AD + (double) msecInDay); -} - -/****************************************************************************** -* computeEPOCH16. -* This function is an extension of computeEPOCH. It is used to handle the time -* that may contain as small as picoseconds. -******************************************************************************/ - -VISIBLE_PREFIX double computeEPOCH16 (year, month, day, hour, minute, - second, msec, usec, nsec, psec, - epoch) -long year, month, day, hour, minute, second, msec, usec, nsec, psec; -double epoch[2]; -{ - long daysSince0AD; - /**************************************************************************** - * Mark 9999-12-31 23:59:59:999:999:999:999 as an invalid date. - ****************************************************************************/ - if (year == 9999L && month == 12L && day == 31L && hour == 23L && - minute == 59L && second == 59L && msec == 999L && usec == 999L && - nsec == 999L && psec == 999L) { - epoch[0] = -1.0E31; - epoch[1] = -1.0E31; - return 0.0; - } - if (year < 0L) return ILLEGAL_EPOCH_VALUE; - if ((year > 9999L) || (month < 0L || month > 12L) || - (hour < 0L || hour > 23L) || (minute < 0L || minute > 59L) || - (second < 0L || second > 59L) || (msec < 0L || msec > 999L) || - (usec < 0L || usec > 999L) || (nsec < 0L || nsec > 999L) || - (psec < 0L || psec > 999L)) - return computeEpoch16(year, month, day, hour, minute, second, msec, usec, - nsec, psec, epoch); - if (month == 0L) { - if (day < 1L || day > 366L) - return computeEpoch16(year,month,day,hour,minute,second,msec,usec, - nsec, psec, epoch); - } else { - if (day < 1L || day > 31L) - return computeEpoch16(year,month,day,hour,minute,second,msec,usec, - nsec, psec, epoch); - } - /**************************************************************************** - * Calculate the days since 0 A.D (1-Jan-0000). If a value of zero is passed - * in for `month', assume that `day' is the day-of-year (DOY) with January 1st - * being day 1. - ****************************************************************************/ - if (month == 0L) { - daysSince0AD = JulianDay(year,1L,1L) + (day-1) - 1721060L; - } - else { - daysSince0AD = JulianDay(year,month,day) - 1721060L; - } - /**************************************************************************** - * Return the seconds and picoseconds since 0 A.D. - ****************************************************************************/ - epoch[0] = 86400.0 * daysSince0AD + 3600.0 * hour + 60.0 * minute + - (double) second; - epoch[1] = (double) psec + pow(10.0, 3.0) * nsec + pow(10.0, 6.0) * usec + - pow(10.0, 9.0) * msec; - return (double) 0.0; -} - -/****************************************************************************** -* EPOCHbreakdown. -* Breaks an EPOCH value down into its component parts. -******************************************************************************/ - -VISIBLE_PREFIX void EPOCHbreakdown (epoch, year, month, day, hour, minute, - second, msec) -double epoch; -long *year, *month, *day, *hour, *minute, *second, *msec; -{ - long jd,i,j,k,l,n; - double msec_AD, second_AD, minute_AD, hour_AD, day_AD; - - if (epoch == -1.0E31) { - *year = 9999; - *month = 12; - *day = 31; - *hour = 23; - *minute = 59; - *second = 59; - *msec = 999; - return; - } - - if (NegativeZeroReal8(&epoch)) { - *year = 0; - *month = 0; - *day = 0; - *hour = 0; - *minute = 0; - *second = 0; - *msec = 0; - return; - } - - if (epoch < 0.0) epoch = -epoch; - epoch = MINIMUM ((double)MAX_EPOCH_BINARY, epoch); - msec_AD = epoch; - second_AD = msec_AD / 1000.0; - minute_AD = second_AD / 60.0; - hour_AD = minute_AD / 60.0; - day_AD = hour_AD / 24.0; - - jd = (long) (1721060 + day_AD); - l=jd+68569; - n=4*l/146097; - l=l-(146097*n+3)/4; - i=4000*(l+1)/1461001; - l=l-1461*i/4+31; - j=80*l/2447; - k=l-2447*j/80; - l=j/11; - j=j+2-12*l; - i=100*(n-49)+i+l; - - *year = i; - *month = j; - *day = k; - - *hour = (long) fmod (hour_AD, (double) 24.0); - *minute = (long) fmod (minute_AD, (double) 60.0); - *second = (long) fmod (second_AD, (double) 60.0); - *msec = (long) fmod (msec_AD, (double) 1000.0); - - return; -} - -/****************************************************************************** -* EPOCH16breakdown. -* This function is an extension of EPOCHbreakdown. It is used to handle the -* time that may contain as small as picoseconds. -******************************************************************************/ - -VISIBLE_PREFIX void EPOCH16breakdown (epoch, year, month, day, hour, - minute, second, msec, usec, nsec, psec) -double epoch[2]; -long *year, *month, *day, *hour, *minute, *second; -long *msec, *usec, *nsec, *psec; -{ - long jd,i,j,k,l,n; - double second_AD, minute_AD, hour_AD, day_AD; - double psec_SC, nsec_SC, usec_SC; - - if (epoch[0] == -1.0E31 && epoch[1] == -1.0E31) { - *year = 9999; - *month = 12; - *day = 31; - *hour = 23; - *minute = 59; - *second = 59; - *msec = 999; - *usec = 999; - *nsec = 999; - *psec = 999; - return; - } - - if (NegativeZeroReal8(&epoch[0])) { - *year = 0; - *month = 0; - *day = 0; - *hour = 0; - *minute = 0; - *second = 0; - } - if (NegativeZeroReal8(&epoch[1])) { - *msec = 0; - *usec = 0; - *nsec = 0; - *psec = 0; - } - - if (epoch[0] < 0.0) epoch[0] = -epoch[0]; - if (epoch[1] < 0.0) epoch[1] = -epoch[1]; - epoch[0] = MINIMUM ((double)MAX_EPOCH16_1_BINARY, epoch[0]); - if (epoch[0] == MAX_EPOCH16_1_BINARY) - epoch[1] = MINIMUM ((double)MAX_EPOCH16_2_BINARY, epoch[1]); - else - epoch[1] = MINIMUM ((double)MAX_EPOCH16_2_BINARY+1.0, epoch[1]); - - second_AD = epoch[0]; - minute_AD = second_AD / 60.0; - hour_AD = minute_AD / 60.0; - day_AD = hour_AD / 24.0; - - jd = (long) (1721060 + day_AD); - l=jd+68569; - n=4*l/146097; - l=l-(146097*n+3)/4; - i=4000*(l+1)/1461001; - l=l-1461*i/4+31; - j=80*l/2447; - k=l-2447*j/80; - l=j/11; - j=j+2-12*l; - i=100*(n-49)+i+l; - - *year = i; - *month = j; - *day = k; - - *hour = (long) fmod (hour_AD, (double) 24.0); - *minute = (long) fmod (minute_AD, (double) 60.0); - *second = (long) fmod (second_AD, (double) 60.0); - - psec_SC = epoch[1]; - *psec = (long) fmod(epoch[1], (double) 1000.0); - nsec_SC = psec_SC / 1000.0; - *nsec = (long) fmod(nsec_SC, (double) 1000.0); - usec_SC = nsec_SC / 1000.0; - *usec = (long) fmod(usec_SC, (double) 1000.0); - *msec = (long) (usec_SC / (double) 1000.0); - - return; -} - -/****************************************************************************** -* JulianDay. -* The year, month, and day are assumed to have already been validated. This -* is the day since 0 AD/1 BC. (Julian day may not be the proper term.) -******************************************************************************/ - -static long JulianDay (y,m,d) -long y, m, d; -{ - return (367*y-7*(y+(m+9)/12)/4-3*((y+(m-9)/7)/100+1)/4+275*m/9+d+1721029); -} - -/****************************************************************************** -* MonthToken. -******************************************************************************/ - -static char *MonthToken (month) -long month; -{ - switch (month) { - case 1: return "Jan"; - case 2: return "Feb"; - case 3: return "Mar"; - case 4: return "Apr"; - case 5: return "May"; - case 6: return "Jun"; - case 7: return "Jul"; - case 8: return "Aug"; - case 9: return "Sep"; - case 10: return "Oct"; - case 11: return "Nov"; - case 12: return "Dec"; - } - return "???"; -} - -/****************************************************************************** -* FullDayToken. -******************************************************************************/ - -static char *FullDayToken (day3) -char *day3; -{ - if (!strcmp(day3,"Sun")) return "Sunday"; - if (!strcmp(day3,"Mon")) return "Monday"; - if (!strcmp(day3,"Tue")) return "Tuesday"; - if (!strcmp(day3,"Wed")) return "Wednesday"; - if (!strcmp(day3,"Thu")) return "Thursday"; - if (!strcmp(day3,"Fri")) return "Friday"; - if (!strcmp(day3,"Sat")) return "Saturday"; - return "Someday"; -} - -/****************************************************************************** -* computeEpoch. -******************************************************************************/ - -static double computeEpoch (year, month, day, hour, minute, second, msec) -long year, month, day, hour, minute, second, msec; -{ - long daysSince0AD; - double msecFromEpoch, msecInDay; - - if (month == 0L) { - daysSince0AD = JulianDay(year,1L,1L) + (day-1L) - 1721060L; - } - else { - if (month < 0L) { - --year; - month = 13 + month; - } - daysSince0AD = JulianDay(year,month,day) - 1721060L; - } - if (daysSince0AD < 0L) return ILLEGAL_EPOCH_VALUE; - msecInDay = 3600000.0 * hour + 60000.0 * minute + 1000.0 * second + - (double) msec; - msecFromEpoch = 86400000.0 * daysSince0AD + msecInDay; - if (msecFromEpoch < 0.0) - return ILLEGAL_EPOCH_VALUE; - else - return msecFromEpoch; -} - -/****************************************************************************** -* computeEpoch16. -******************************************************************************/ - -static double computeEpoch16 (year, month, day, hour, minute, second, msec, - usec, nsec, psec, epoch) -long year, month, day, hour, minute, second, msec, usec, nsec, psec; -double epoch[2]; -{ - long daysSince0AD; - if (month == 0L) { - daysSince0AD = JulianDay(year,1L,1L) + (day-1L) - 1721060L; - } - else { - if (month < 0L) { - --year; - month = 13 + month; - } - daysSince0AD = JulianDay(year,month,day) - 1721060L; - } - if (daysSince0AD < 0L) return ILLEGAL_EPOCH_VALUE; - epoch[0] = 86400.0 * daysSince0AD + 3600.0 * hour + 60.0 * minute + - (double) second; - epoch[1] = (double) psec + pow(10.0, 3.0) * nsec + pow(10.0, 6.0) * usec + - pow(10.0, 9.0) * msec; - if (epoch[1] < 0.0 || epoch[1] >= pow(10.0, 12.0)) { - int sec; - double tmp; - if (epoch[1] < 0.0) { - sec = (int) (epoch[1] / pow(10.0, 12.0)); - tmp = epoch[1] - sec * pow(10.0, 12.0); - if (tmp != 0.0 && tmp != -0.0) { - epoch[0] = epoch[0] + (double) sec - 1.0; - epoch[1] = pow(10.0, 12.0) + tmp; - } else { - epoch[0] = epoch[0] + (double) sec; - epoch[1] = 0.0; - } - } else { - sec = (int) (epoch[1] / pow(10.0, 12.0)); - tmp = epoch[1] - sec * pow(10.0, 12.0); - if (tmp != 0.0 && tmp != -0.0) { - epoch[1] = tmp; - epoch[0] = epoch[0] + (double) sec; - } else { - epoch[1] = 0.0; - epoch[0] = epoch[0] + (double) sec; - } - } - } - if (epoch[0] < 0.0) - return ILLEGAL_EPOCH_VALUE; - else - return 0.0; -} - -/****************************************************************************** -* TimeStamp. -* Gets the date & time from the system and encodes a string in the following -* form: -* -* ddddddddd, dd-mmm-yyyy hh:mm:ss -* -* Examples: -* -* Saturday, 23-Oct-1993 09:37:34 -* Sunday, 2-Jan-1994 10:00:00 -* Wednesday, 27-Oct-1993 23:59:59 -* -* Trailing blanks are not appended if the string is shorter than its maximum -* possible length. The passed string buffer has to be at least 32 bytes long. -******************************************************************************/ - -VISIBLE_PREFIX void TimeStamp (stampStr) -char *stampStr; -{ - time_t bintim; - char ctimeStr[CTIME_STRING_LEN+1], dayOfWeek3[3+1], dayOfMonth[2+1], - year[4+1], month[3+1], hourMinuteSecond[8+1]; - time (&bintim); - strcpyX (ctimeStr, ctime(&bintim), CTIME_STRING_LEN); - strcpyX (dayOfWeek3, ctimeStr, 3); - strcpyX (dayOfMonth, &ctimeStr[8], 2); - if (dayOfMonth[0] == ' ') memmove (dayOfMonth, &dayOfMonth[1], 2); - strcpyX (year, &ctimeStr[20], 4); - strcpyX (month, &ctimeStr[4], 3); - strcpyX (hourMinuteSecond, &ctimeStr[11], 8); - snprintf (stampStr, (size_t) 31+1, "%s, %s-%s-%s %s", - FullDayToken(dayOfWeek3), dayOfMonth, month, year, - hourMinuteSecond); - return; -} diff --git a/cdf36_3-dist/src/lib/epochuf.c b/cdf36_3-dist/src/lib/epochuf.c deleted file mode 100644 index cc06794..0000000 --- a/cdf36_3-dist/src/lib/epochuf.c +++ /dev/null @@ -1,783 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF EPOCH utility routines for Fortran applications. -* -* Version 1.2, 9-Sep-96, Hughes STX. -* -* Modification history: -* -* V1.0 7-Nov-94, J Love Original version. -* V1.1 13-Jun-95, J Love EPOCH custom format. Linux. -* V1.2 9-Sep-96, J Love CDF V2.6. -* V2.6 29-Jan-04, M Liu Added a new set of CDF_EPOCH16 functions for -* handling fraction of a second up to picosecond. -* -******************************************************************************/ - -#include "cdflib.h" - -/****************************************************************************** -* parse_EPOCH (FORTRAN equivalent of parseEPOCH). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(parse_epoch__,parse_epoch_,parse_epoch,PARSE_EPOCH) -(string, epoch Fif_GHOSTARG(string_len)) -void *string; -double *epoch; -Fif_GHOSTDEF(string_len) -{ - struct STRINGstruct *ssh = NULL; -#if defined(Fif_DESCR) - *epoch = parseEPOCH(DESCRtoREFnul(string,EPOCH_STRING_LEN,&ssh)); -#endif -#if defined(Fif_GHOSTLEN) - *epoch = parseEPOCH(NULterminate(string,Fif_GHOSTUSE(string_len),&ssh)); -#endif -#if defined(Fif_NOLEN) - *epoch = parseEPOCH(FindEndNUL(string,EPOCH_STRING_LEN,&ssh)); -#endif - FreeStrings (ssh); - return; -} - -/****************************************************************************** -* parse_EPOCH1 (FORTRAN equivalent of parseEPOCH1). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(parse_epoch1__,parse_epoch1_,parse_epoch1,PARSE_EPOCH1) -(string, epoch Fif_GHOSTARG(string_len)) -void *string; -double *epoch; -Fif_GHOSTDEF(string_len) -{ - struct STRINGstruct *ssh = NULL; -#if defined(Fif_DESCR) - *epoch = parseEPOCH1(DESCRtoREFnul(string,EPOCH1_STRING_LEN,&ssh)); -#endif -#if defined(Fif_GHOSTLEN) - *epoch = parseEPOCH1(NULterminate(string,Fif_GHOSTUSE(string_len),&ssh)); -#endif -#if defined(Fif_NOLEN) - *epoch = parseEPOCH1(FindEndNUL(string,EPOCH1_STRING_LEN,&ssh)); -#endif - FreeStrings (ssh); - return; -} - -/****************************************************************************** -* parse_EPOCH2 (FORTRAN equivalent of parseEPOCH2). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(parse_epoch2__,parse_epoch2_,parse_epoch2,PARSE_EPOCH2) -(string, epoch Fif_GHOSTARG(string_len)) -void *string; -double *epoch; -Fif_GHOSTDEF(string_len) -{ - struct STRINGstruct *ssh = NULL; -#if defined(Fif_DESCR) - *epoch = parseEPOCH2(DESCRtoREFnul(string,EPOCH2_STRING_LEN,&ssh)); -#endif -#if defined(Fif_GHOSTLEN) - *epoch = parseEPOCH2(NULterminate(string,Fif_GHOSTUSE(string_len),&ssh)); -#endif -#if defined(Fif_NOLEN) - *epoch = parseEPOCH2(FindEndNUL(string,EPOCH2_STRING_LEN,&ssh)); -#endif - FreeStrings (ssh); - return; -} - -/****************************************************************************** -* parse_EPOCH3 (FORTRAN equivalent of parseEPOCH3). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(parse_epoch3__,parse_epoch3_,parse_epoch3,PARSE_EPOCH3) -(string, epoch Fif_GHOSTARG(string_len)) -void *string; -double *epoch; -Fif_GHOSTDEF(string_len) -{ - struct STRINGstruct *ssh = NULL; -#if defined(Fif_DESCR) - *epoch = parseEPOCH3(DESCRtoREFnul(string,EPOCH3_STRING_LEN,&ssh)); -#endif -#if defined(Fif_GHOSTLEN) - *epoch = parseEPOCH3(NULterminate(string,Fif_GHOSTUSE(string_len),&ssh)); -#endif -#if defined(Fif_NOLEN) - *epoch = parseEPOCH3(FindEndNUL(string,EPOCH3_STRING_LEN,&ssh)); -#endif - FreeStrings (ssh); - return; -} - -/****************************************************************************** -* parse_EPOCH4 (FORTRAN equivalent of parseEPOCH4). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(parse_epoch4__,parse_epoch4_,parse_epoch4,PARSE_EPOCH4) -(string, epoch Fif_GHOSTARG(string_len)) -void *string; -double *epoch; -Fif_GHOSTDEF(string_len) -{ - struct STRINGstruct *ssh = NULL; -#if defined(Fif_DESCR) - *epoch = parseEPOCH4(DESCRtoREFnul(string,EPOCH4_STRING_LEN,&ssh)); -#endif -#if defined(Fif_GHOSTLEN) - *epoch = parseEPOCH4(NULterminate(string,Fif_GHOSTUSE(string_len),&ssh)); -#endif -#if defined(Fif_NOLEN) - *epoch = parseEPOCH4(FindEndNUL(string,EPOCH4_STRING_LEN,&ssh)); -#endif - FreeStrings (ssh); - return; -} - -/****************************************************************************** -* encode_EPOCH (FORTRAN equivalent of encodeEPOCH). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(encode_epoch__,encode_epoch_,encode_epoch,ENCODE_EPOCH) -(epoch, string Fif_GHOSTARG(string_len)) -double *epoch; -void *string; -Fif_GHOSTDEF(string_len) -{ - char tString[EPOCH_STRING_LEN+1]; - encodeEPOCH (*epoch, tString); -#if defined(Fif_GHOSTLEN) - CtoFORTstring (tString, string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (tString, string, EPOCH_STRING_LEN); -#endif - return; -} - -/****************************************************************************** -* encode_EPOCH1 (FORTRAN equivalent of encodeEPOCH1). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(encode_epoch1__,encode_epoch1_,encode_epoch1,ENCODE_EPOCH1) -(epoch, string Fif_GHOSTARG(string_len)) -double *epoch; -void *string; -Fif_GHOSTDEF(string_len) -{ - char tString[EPOCH1_STRING_LEN+1]; - encodeEPOCH1 (*epoch, tString); -#if defined(Fif_GHOSTLEN) - CtoFORTstring (tString, string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (tString, string, EPOCH1_STRING_LEN); -#endif - return; -} - -/****************************************************************************** -* encode_EPOCH2 (FORTRAN equivalent of encodeEPOCH2). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(encode_epoch2__,encode_epoch2_,encode_epoch2,ENCODE_EPOCH2) -(epoch, string Fif_GHOSTARG(string_len)) -double *epoch; -void *string; -Fif_GHOSTDEF(string_len) -{ - char tString[EPOCH2_STRING_LEN+1]; - encodeEPOCH2 (*epoch, tString); -#if defined(Fif_GHOSTLEN) - CtoFORTstring (tString, string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (tString, string, EPOCH2_STRING_LEN); -#endif - return; -} - -/****************************************************************************** -* encode_EPOCH3 (FORTRAN equivalent of encodeEPOCH3). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(encode_epoch3__,encode_epoch3_,encode_epoch3,ENCODE_EPOCH3) -(epoch, string Fif_GHOSTARG(string_len)) -double *epoch; -void *string; -Fif_GHOSTDEF(string_len) -{ - char tString[EPOCH3_STRING_LEN+1]; - encodeEPOCH3 (*epoch, tString); -#if defined(Fif_GHOSTLEN) - CtoFORTstring (tString, string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (tString, string, EPOCH3_STRING_LEN); -#endif - return; -} - -/****************************************************************************** -* encode_EPOCH4 (FORTRAN equivalent of encodeEPOCH4). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(encode_epoch4__,encode_epoch4_,encode_epoch4,ENCODE_EPOCH4) -(epoch, string Fif_GHOSTARG(string_len)) -double *epoch; -void *string; -Fif_GHOSTDEF(string_len) -{ - char tString[EPOCH4_STRING_LEN+1]; - encodeEPOCH4 (*epoch, tString); -#if defined(Fif_GHOSTLEN) - CtoFORTstring (tString, string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (tString, string, EPOCH4_STRING_LEN); -#endif - return; -} - -/****************************************************************************** -* encode_EPOCHx (FORTRAN equivalent of encodeEPOCHx). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(encode_epochx__,encode_epochx_,encode_epochx,ENCODE_EPOCHX) -(epoch, format, string Fif_GHOSTARG(format_len) Fif_GHOSTARG(string_len)) -double *epoch; -void *format; -void *string; -Fif_GHOSTDEF(format_len) -Fif_GHOSTDEF(string_len) -{ - struct STRINGstruct *ssh = NULL; - char tString[EPOCHx_STRING_MAX+1]; -#if defined(Fif_DESCR) - encodeEPOCHx (*epoch, DESCRtoREFnul(format,EPOCHx_FORMAT_MAX,&ssh), tString); -#endif -#if defined(Fif_GHOSTLEN) - encodeEPOCHx (*epoch, NULterminate(format,Fif_GHOSTUSE(format_len),&ssh), - tString); -#endif -#if defined(Fif_NOLEN) - encodeEPOCHx (*epoch, FindEndNUL(format,EPOCHx_FORMAT_MAX,&ssh), tString); -#endif -#if defined(Fif_GHOSTLEN) - CtoFORTstring (tString, string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (tString, string, EPOCHx_STRING_MAX); -#endif - return; -} - -/****************************************************************************** -* EPOCH_breakdown (FORTRAN equivalent of EPOCHbreakdown). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(epoch_breakdown__, - epoch_breakdown_, - epoch_breakdown, - EPOCH_BREAKDOWN) -(epoch, year, month, day, hour, minute, second, msec) -double *epoch; -Int32 *year; -Int32 *month; -Int32 *day; -Int32 *hour; -Int32 *minute; -Int32 *second; -Int32 *msec; -{ - double tEpoch = *epoch; - long tYear, tMonth, tDay, tHour, tMinute, tSecond, tMsec; - EPOCHbreakdown (tEpoch, &tYear, &tMonth, &tDay, &tHour, &tMinute, &tSecond, - &tMsec); - *year = (Int32) tYear; - *month = (Int32) tMonth; - *day = (Int32) tDay; - *hour = (Int32) tHour; - *minute = (Int32) tMinute; - *second = (Int32) tSecond; - *msec = (Int32) tMsec; - return; -} - -/****************************************************************************** -* compute_EPOCH (FORTRAN equivalent of computeEPOCH). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(compute_epoch__,compute_epoch_,compute_epoch,COMPUTE_EPOCH) -(year, month, day, hour, minute, second, msec, epoch) -Int32 *year; -Int32 *month; -Int32 *day; -Int32 *hour; -Int32 *minute; -Int32 *second; -Int32 *msec; -double *epoch; -{ - *epoch = computeEPOCH ((long) *year, (long) *month, (long) *day, - (long) *hour, (long) *minute, (long) *second, - (long) *msec); - return; -} - -/****************************************************************************** -* parse_EPOCH16 (FORTRAN equivalent of parseEPOCH16). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(parse_epoch16__,parse_epoch16_,parse_epoch16, - PARSE_EPOCH16) -(string, epoch Fif_GHOSTARG(string_len)) -void *string; -double *epoch; -Fif_GHOSTDEF(string_len) -{ - struct STRINGstruct *ssh = NULL; - double mmm; -#if defined(Fif_DESCR) - mmm = parseEPOCH16(DESCRtoREFnul(string,EPOCH16_STRING_LEN,&ssh), - epoch); -#endif -#if defined(Fif_GHOSTLEN) - mmm = parseEPOCH16(NULterminate(string,Fif_GHOSTUSE(string_len),&ssh), - epoch); -#endif -#if defined(Fif_NOLEN) - mmm = parseEPOCH16(FindEndNUL(string,EPOCH16_STRING_LEN,&ssh), - epoch); -#endif - FreeStrings (ssh); - return; -} - -/****************************************************************************** -* parse_EPOCH16_1 (FORTRAN equivalent of parseEPOCH16_1). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(parse_epoch16_1__,parse_epoch16_1_,parse_epoch16_1, - PARSE_EPOCH16_1) -(string, epoch Fif_GHOSTARG(string_len)) -void *string; -double *epoch; -Fif_GHOSTDEF(string_len) -{ - struct STRINGstruct *ssh = NULL; - double mmm; -#if defined(Fif_DESCR) - mmm = parseEPOCH16_1(DESCRtoREFnul(string,EPOCH16_1_STRING_LEN,&ssh), - epoch); -#endif -#if defined(Fif_GHOSTLEN) - mmm = parseEPOCH16_1(NULterminate(string,Fif_GHOSTUSE(string_len),&ssh), - epoch); -#endif -#if defined(Fif_NOLEN) - mmm = parseEPOCH16_1(FindEndNUL(string,EPOCH16_1_STRING_LEN,&ssh), - epoch); -#endif - FreeStrings (ssh); - return; -} - -/****************************************************************************** -* parse_EPOCH16_2 (FORTRAN equivalent of parseEPOCH16_2). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(parse_epoch16_2__,parse_epoch16_2_,parse_epoch16_2, - PARSE_EPOCH16_2) -(string, epoch Fif_GHOSTARG(string_len)) -void *string; -double *epoch; -Fif_GHOSTDEF(string_len) -{ - struct STRINGstruct *ssh = NULL; - double mmm; -#if defined(Fif_DESCR) - mmm = parseEPOCH16_2(DESCRtoREFnul(string,EPOCH16_2_STRING_LEN,&ssh), - epoch); -#endif -#if defined(Fif_GHOSTLEN) - mmm = parseEPOCH16_2(NULterminate(string,Fif_GHOSTUSE(string_len),&ssh), - epoch); -#endif -#if defined(Fif_NOLEN) - mmm = parseEPOCH16_2(FindEndNUL(string,EPOCH16_2_STRING_LEN,&ssh), - epoch); -#endif - FreeStrings (ssh); - return; -} - -/****************************************************************************** -* parse_EPOCH16_3 (FORTRAN equivalent of parseEPOCH16_3). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(parse_epoch16_3__,parse_epoch16_3_,parse_epoch16_3, - PARSE_EPOCH16_3) -(string, epoch Fif_GHOSTARG(string_len)) -void *string; -double *epoch; -Fif_GHOSTDEF(string_len) -{ - struct STRINGstruct *ssh = NULL; - double mmm; -#if defined(Fif_DESCR) - mmm = parseEPOCH16_3(DESCRtoREFnul(string,EPOCH16_3_STRING_LEN,&ssh), - epoch); -#endif -#if defined(Fif_GHOSTLEN) - mmm = parseEPOCH16_3(NULterminate(string,Fif_GHOSTUSE(string_len),&ssh), - epoch); -#endif -#if defined(Fif_NOLEN) - mmm = parseEPOCH16_3(FindEndNUL(string,EPOCH16_3_STRING_LEN,&ssh), - epoch); -#endif - FreeStrings (ssh); - return; -} - -/****************************************************************************** -* parse_EPOCH16_4 (FORTRAN equivalent of parseEPOCH16_4). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(parse_epoch16_4__,parse_epoch16_4_,parse_epoch16_4, - PARSE_EPOCH16_4) -(string, epoch Fif_GHOSTARG(string_len)) -void *string; -double *epoch; -Fif_GHOSTDEF(string_len) -{ - struct STRINGstruct *ssh = NULL; - double mmm; -#if defined(Fif_DESCR) - mmm = parseEPOCH16_4(DESCRtoREFnul(string,EPOCH16_4_STRING_LEN,&ssh), - epoch); -#endif -#if defined(Fif_GHOSTLEN) - mmm = parseEPOCH16_4(NULterminate(string,Fif_GHOSTUSE(string_len),&ssh), - epoch); -#endif -#if defined(Fif_NOLEN) - mmm = parseEPOCH16_4(FindEndNUL(string,EPOCH16_4_STRING_LEN,&ssh), - epoch); -#endif - FreeStrings (ssh); - return; -} - -/****************************************************************************** -* encode_EPOCH16 (FORTRAN equivalent of encodeEPOCH16). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(encode_epoch16__,encode_epoch16_,encode_epoch16, - ENCODE_EPOCH16) -(epoch, string Fif_GHOSTARG(string_len)) -double *epoch; -void *string; -Fif_GHOSTDEF(string_len) -{ - char tString[EPOCH16_STRING_LEN+1]; - encodeEPOCH16 (epoch, tString); -#if defined(Fif_GHOSTLEN) - CtoFORTstring (tString, string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (tString, string, EPOCH16_STRING_LEN); -#endif - return; -} - -/****************************************************************************** -* encode_EPOCH16_1 (FORTRAN equivalent of encodeEPOCH16_1). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(encode_epoch16_1__,encode_epoch16_1_,encode_epoch16_1, - ENCODE_EPOCH16_1) -(epoch, string Fif_GHOSTARG(string_len)) -double *epoch; -void *string; -Fif_GHOSTDEF(string_len) -{ - char tString[EPOCH16_1_STRING_LEN+1]; - encodeEPOCH16_1 (epoch, tString); -#if defined(Fif_GHOSTLEN) - CtoFORTstring (tString, string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (tString, string, EPOCH16_1_STRING_LEN); -#endif - return; -} - -/****************************************************************************** -* encode_EPOCH16_2 (FORTRAN equivalent of encodeEPOCH16_2). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(encode_epoch16_2__,encode_epoch16_2_,encode_epoch16_2, - ENCODE_EPOCH16_2) -(epoch, string Fif_GHOSTARG(string_len)) -double *epoch; -void *string; -Fif_GHOSTDEF(string_len) -{ - char tString[EPOCH16_2_STRING_LEN+1]; - encodeEPOCH16_2 (epoch, tString); -#if defined(Fif_GHOSTLEN) - CtoFORTstring (tString, string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (tString, string, EPOCH16_2_STRING_LEN); -#endif - return; -} - -/****************************************************************************** -* encode_EPOCH16_3 (FORTRAN equivalent of encodeEPOCH16_3). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(encode_epoch16_3__,encode_epoch16_3_,encode_epoch16_3, - ENCODE_EPOCH16_3) -(epoch, string Fif_GHOSTARG(string_len)) -double *epoch; -void *string; -Fif_GHOSTDEF(string_len) -{ - char tString[EPOCH16_3_STRING_LEN+1]; - encodeEPOCH16_3 (epoch, tString); -#if defined(Fif_GHOSTLEN) - CtoFORTstring (tString, string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (tString, string, EPOCH16_3_STRING_LEN); -#endif - return; -} - -/****************************************************************************** -* encode_EPOCH16_4 (FORTRAN equivalent of encodeEPOCH16_4). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(encode_epoch16_4__,encode_epoch16_4_,encode_epoch16_4, - ENCODE_EPOCH16_4) -(epoch, string Fif_GHOSTARG(string_len)) -double *epoch; -void *string; -Fif_GHOSTDEF(string_len) -{ - char tString[EPOCH16_4_STRING_LEN+1]; - encodeEPOCH16_4 (epoch, tString); -#if defined(Fif_GHOSTLEN) - CtoFORTstring (tString, string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (tString, string, EPOCH16_4_STRING_LEN); -#endif - return; -} - -/****************************************************************************** -* encode_EPOCH16_x (FORTRAN equivalent of encodeEPOCH16_x). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(encode_epoch16_x__,encode_epoch16_x_,encode_epoch16_x, - ENCODE_EPOCH16_X) -(epoch, format, string Fif_GHOSTARG(format_len) Fif_GHOSTARG(string_len)) -double *epoch; -void *format; -void *string; -Fif_GHOSTDEF(format_len) -Fif_GHOSTDEF(string_len) -{ - struct STRINGstruct *ssh = NULL; - char tString[EPOCHx_STRING_MAX+1]; -#if defined(Fif_DESCR) - encodeEPOCH16_x (epoch, DESCRtoREFnul(format,EPOCHx_FORMAT_MAX,&ssh), - tString); -#endif -#if defined(Fif_GHOSTLEN) - encodeEPOCH16_x (epoch, NULterminate(format,Fif_GHOSTUSE(format_len),&ssh), - tString); -#endif -#if defined(Fif_NOLEN) - encodeEPOCH16_x (epoch, FindEndNUL(format,EPOCHx_FORMAT_MAX,&ssh), - tString); -#endif -#if defined(Fif_GHOSTLEN) - CtoFORTstring (tString, string, Fif_GHOSTUSE(string_len)); -#else - CtoFORTstring (tString, string, EPOCHx_STRING_MAX); -#endif - return; -} - -/****************************************************************************** -* EPOCH16_breakdown (FORTRAN equivalent of EPOCH16breakdown). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(epoch16_breakdown__, - epoch16_breakdown_, - epoch16_breakdown, - EPOCH16_BREAKDOWN) -(epoch, year, month, day, hour, minute, second, msec, usec, nsec, psec) -double *epoch; -Int32 *year; -Int32 *month; -Int32 *day; -Int32 *hour; -Int32 *minute; -Int32 *second; -Int32 *msec; -Int32 *usec; -Int32 *nsec; -Int32 *psec; -{ - double tEpoch[2]; - long tYear, tMonth, tDay, tHour, tMinute, tSecond, tMsec, tUsec, tNsec, tPsec; - tEpoch[0] = *(double *) epoch; - tEpoch[1] = *((double *)epoch + 1); - EPOCH16breakdown (tEpoch, &tYear, &tMonth, &tDay, &tHour, &tMinute, - &tSecond, &tMsec, &tUsec, &tNsec, &tPsec); - *year = (Int32) tYear; - *month = (Int32) tMonth; - *day = (Int32) tDay; - *hour = (Int32) tHour; - *minute = (Int32) tMinute; - *second = (Int32) tSecond; - *msec = (Int32) tMsec; - *usec = (Int32) tUsec; - *nsec = (Int32) tNsec; - *psec = (Int32) tPsec; - return; -} - -/****************************************************************************** -* compute_EPOCH16 (FORTRAN equivalent of computeEPOCH16). -******************************************************************************/ - -VISIBLE_PREFIX -Fif_PREFIXa -void -Fif_PREFIXb -Fif_ENTRYPOINT(compute_epoch16__,compute_epoch16_,compute_epoch16, - COMPUTE_EPOCH16) -(year, month, day, hour, minute, second, msec, usec, nsec, psec, epoch) -Int32 *year; -Int32 *month; -Int32 *day; -Int32 *hour; -Int32 *minute; -Int32 *second; -Int32 *msec; -Int32 *usec; -Int32 *nsec; -Int32 *psec; -double *epoch; -{ - double mmm; - mmm = computeEPOCH16 ((long) *year, (long) *month, (long) *day, - (long) *hour, (long) *minute, (long) *second, - (long) *msec, (long) *usec, (long) *nsec, - (long) *psec, epoch); - return; -} diff --git a/cdf36_3-dist/src/lib/libcdf.exp b/cdf36_3-dist/src/lib/libcdf.exp deleted file mode 100644 index 6e7a619..0000000 --- a/cdf36_3-dist/src/lib/libcdf.exp +++ /dev/null @@ -1,251 +0,0 @@ -cdf_attr_create -cdf_attr_entry_inquire -cdf_attr_get -cdf_attr_inquire -CDFattrInquire -cdf_attr_num -cdf_attr_put -cdf_attr_rename -cdf_close -cdf_close_cdf -cdf_close_zvar -cdf_confirm_attr_existence -cdf_confirm_gentry_existence -cdf_confirm_rentry_existence -cdf_confirm_zentry_existence -cdf_confirm_zvar_existence -cdf_confirm_zvar_padvalue_exist -cdf_create -cdf_create_attr -cdf_create_cdf -CDFcreateCDF -cdf_create_zvar -cdf_delete -cdf_delete_attr -CDFdeleteAttrEntry -cdf_delete_attr_gentry -cdf_delete_attr_rentry -cdf_delete_attr_zentry -cdf_delete_cdf -cdf_delete_zvar -cdf_delete_zvar_recs -cdf_doc -cdf_error -CDFgetAttrEntry -CDFgetAttrEntryDataType -CDFgetAttrEntryNumElements -cdf_get_attr_gentry -cdf_get_attr_gentry_datatype -cdf_get_attr_gentry_numelems -CDFgetAttrMaxEntry -cdf_get_attr_max_gentry -cdf_get_attr_max_rentry -cdf_get_attr_max_zentry -cdf_get_attr_name -cdf_get_attr_num -CDFgetAttrNum -cdf_get_attr_num_gentries -cdf_get_attr_num_rentries -cdf_get_attr_num_zentries -cdf_get_attr_rentry -cdf_get_attr_rentry_datatype -cdf_get_attr_rentry_numelems -cdf_get_attr_scope -cdf_get_attr_zentry -cdf_get_attr_zentry_datatype -cdf_get_attr_zentry_numelems -cdf_get_cachesize -cdf_get_checksum -cdf_get_compress_cachesize -cdf_get_compress_info -cdf_get_compression -cdf_get_copyright -cdf_get_datatype_size -cdf_get_decoding -cdf_get_encoding -cdf_get_filebackward -cdf_get_format -cdf_get_lib_copyright -cdf_get_lib_version -cdf_get_majority -cdf_get_name -cdf_get_negtoposfp0_mode -CDFgetNumAttrEntries -cdf_get_num_attrs -cdf_get_num_gattrs -cdf_get_num_rvars -cdf_get_num_vattrs -cdf_get_num_zvars -cdf_get_readonly_mode -cdf_getrvarsrecorddata -cdf_get_stage_cachesize -cdf_get_status_text -cdf_get_validate -cdf_get_var_num -CDFgetVarNum -CDFgetVarRecordData -cdf_get_vars_maxwrittenrecnums -CDFgetVarsRecordDatabyNames -cdf_get_version -cdf_get_zmode -cdf_get_zvar_allocrecs -cdf_get_zvar_blockingfactor -cdf_get_zvar_cachesize -cdf_get_zvar_compression -cdf_get_zvar_data -cdf_get_zvar_datatype -cdf_get_zvar_dimsizes -cdf_get_zvar_dimvariances -cdf_get_zvar_maxallocrecnum -cdf_get_zvar_maxwrittenrecnum -cdf_get_zvar_name -cdf_get_zvar_numdims -cdf_get_zvar_numelems -cdf_get_zvar_numrecs_written -cdf_get_zvar_padvalue -cdf_get_zvar_recorddata -cdf_get_zvar_recvariance -cdf_get_zvar_reservepercent -cdf_get_zvar_seqdata -cdf_get_zvar_seqpos -cdf_get_zvars_maxwrittenrecnum -cdf_get_zvar_sparserecords -cdf_getzvarsrecorddata -cdf_get_zvars_recorddata -cdf_hyper_get_zvar_data -cdf_hyper_put_zvar_data -cdf_inquire -cdf_inquire_attr -CDFinquireAttr -CDFinquireAttrEntry -cdf_inquire_attr_gentry -cdf_inquire_attr_rentry -cdf_inquire_attr_zentry -cdf_inquire_cdf -cdf_inquire_zvar -cdf_lib -CDFlib -cdf_lib_10 -cdf_lib_11 -cdf_lib_12 -cdf_lib_13 -cdf_lib_14 -cdf_lib_15 -cdf_lib_16 -cdf_lib_17 -cdf_lib_18 -cdf_lib_19 -cdf_lib_20 -cdf_lib_21 -cdf_lib_22 -cdf_lib_23 -cdf_lib_24 -cdf_lib_25 -cdf_lib_4 -cdf_lib_5 -cdf_lib_6 -cdf_lib_7 -cdf_lib_8 -cdf_lib_9 -cdf_open -cdf_open_cdf -CDFputAttrEntry -cdf_put_attr_gentry -cdf_put_attr_rentry -cdf_put_attr_zentry -cdf_putrvarsrecorddata -CDFputVarRecordData -CDFputVarsRecordDatabyNames -cdf_put_zvar_data -cdf_put_zvar_recorddata -cdf_put_zvar_seqdata -cdf_putzvarsrecorddata -cdf_put_zvars_recorddata -cdf_rename_attr -cdf_rename_zvar -CDFsetAttrEntryDataSpec -cdf_set_attr_gentry_dataspec -cdf_set_attr_rentry_dataspec -cdf_set_attr_scope -cdf_set_attr_zentry_dataspec -cdf_set_cachesize -cdf_set_checksum -cdf_set_compress_cachesize -cdf_set_compression -cdf_set_decoding -cdf_set_encoding -cdf_set_filebackward -cdf_set_format -cdf_set_majority -cdf_set_negtoposfp0_mode -cdf_set_readonly_mode -cdf_set_stage_cachesize -cdf_set_Validate -cdf_set_zmode -cdf_set_zvar_allocblockrecs -cdf_set_zvar_allocrecs -cdf_set_zvar_blockingfactor -cdf_set_zvar_cachesize -cdf_set_zvar_compression -cdf_set_zvar_dataspec -cdf_set_zvar_dimvariances -cdf_set_zvar_initialrecs -cdf_set_zvar_padvalue -cdf_set_zvar_recvariance -cdf_set_zvar_reservepercent -cdf_set_zvars_cachesize -cdf_set_zvar_seqpos -cdf_set_zvar_sparserecords -cdf_var_close -cdf_var_create -cdf_var_get -cdf_var_hyper_get -cdf_var_hyper_put -cdf_var_inquire -cdf_var_num -cdf_var_put -cdf_var_rename -compute_epoch -computeEPOCH -compute_epoch16 -computeEPOCH16 -encode_epoch -encodeEPOCH -encode_epoch1 -encodeEPOCH1 -encode_epoch16 -encodeEPOCH16 -encode_epoch16_1 -encodeEPOCH16_1 -encode_epoch16_2 -encodeEPOCH16_2 -encode_epoch16_3 -encodeEPOCH16_3 -encode_epoch16_x -encodeEPOCH16_x -encode_epoch2 -encodeEPOCH2 -encode_epoch3 -encodeEPOCH3 -encode_epochx -encodeEPOCHx -epoch16_breakdown -EPOCH16breakdown -epoch_breakdown -EPOCHbreakdown -parse_epoch -parseEPOCH -parse_epoch1 -parseEPOCH1 -parse_epoch16 -parseEPOCH16 -parse_epoch16_1 -parseEPOCH16_1 -parse_epoch16_2 -parseEPOCH16_2 -parse_epoch16_3 -parseEPOCH16_3 -parse_epoch2 -parseEPOCH2 -parse_epoch3 -parseEPOCH3 diff --git a/cdf36_3-dist/src/lib/libmain.c b/cdf36_3-dist/src/lib/libmain.c deleted file mode 100644 index daa9271..0000000 --- a/cdf36_3-dist/src/lib/libmain.c +++ /dev/null @@ -1,31 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF `LibMain' for Windows DLL. -* -* Version 1.1, 30-Aug-96, Hughes STX. -* -* Modification history: -* -* V1.0 15-Nov-94, J Love Original version. -* V1.1 30-Aug-96, J Love CDF V2.6. Include `cdf.h' rather than -* `cdflib.h'. Including `cdflib.h' caused -* the Borland C 3.0 compiler to crash. -* -******************************************************************************/ - -#include -#include "cdf.h" - -int FAR PASCAL LibMain (HANDLE hInstance, WORD wDataSeg, - WORD cbHeapSize, LPSTR lpCmdLine) { - CDFlib (SELECT_, CDF_, RESERVED_CDFID, - CDF_STATUS_, RESERVED_CDFSTATUS, - NULL_); - /* `UnlockData' not needed - data segment FIXED. */ - return 1; -} diff --git a/cdf36_3-dist/src/lib/vstream.c b/cdf36_3-dist/src/lib/vstream.c deleted file mode 100644 index eb83e3b..0000000 --- a/cdf36_3-dist/src/lib/vstream.c +++ /dev/null @@ -1,1400 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Virtual stream file. -* -* Version 4.7a, 18-Nov-97, Hughes STX. -* -* Modification history: -* -* V1.0 22-Jan-91, J Love Original version (developed for CDF V2.0). -* V2.0 12-Mar-91, J Love All fixes to V1.x. Modified vread and vwrite -* to buffer only when necessary. -* V3.0 14-May-91, J Love Added caching (for CDF V2.1). -* V3.1 31-Jul-91, J Love Added veof. Added 'memmove' for UNIX. Added -* "deq - default extension quantity" if VMS. -* Changed algorithm that looks for bufferN. -* Added number of CACHE buffers as a parameter -* specified in 'Vopen'. Renamed functions to -* avoid collisions on SGi/IRIX. -* V3.2 15-Aug-91, J Love Changed for IBM-PC/MS-DOS port. -* V4.0 20-May-92, J Love IBM PC port/CDF V2.2. -* V4.1 29-Sep-92, J Love CDF V2.3. Dealt with EOFs not at 512-byte -* boundaries (when FTPed from a UNIX machine). -* V4.2 21-Dec-93, J Love CDF V2.4. -* V4.3 12-Dec-94, J Love CDF V2.5. -* V4.3a 19-Jan-95, J Love IRIX 6.0 (64-bit). -* V4.3b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V4.4 7-Jun-95, J Love Virtual memory under Microsoft C 7.00. -* V4.5 25-Jul-95, J Love More virtual memory under Microsoft C 7.00. -* V4.6 29-Sep-95, J Love Improved performance...on non-VMS systems don't -* extend files a block at a time, don't clear -* bytes (anywhere), etc. -* V4.7 26-Aug-96, J Love CDF V2.6. -* V4.7a 18-Nov-97, J Love Windows NT/Visual C++. -* V4.8 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* V4.9 25-Apr-07, D Berger Changed all instances of hardcoded 512 to -* nCACHE_BUFFER_BYTEs. -* V4.10 20-Jun-07, D Berger Added initialization of variables to support -* READONLYon enhancements. -* V4.11 18-Jun-08, M Liu Modified the V_read and V_write to make sure -* the actual read/write bytes is within the -* buffer size. -* V4.12 12-Aug-10, M Liu Fill 0s to each new cache in AllocateBuffer. -* -******************************************************************************/ - -/****************************************************************************** -* Include files. -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" - -/****************************************************************************** -* Local macros/typedef's. -******************************************************************************/ - -#define CLEAR_BYTES 0 - -#if defined(vms) || defined(MPW_C) -#define EXTEND_FILE 1 -#else -#define EXTEND_FILE 0 -#endif - -#define LASTphyBLOCKn(vFp) \ -BOO(vFp->phyLength == 0,NO_BLOCK,((vFp->phyLength - 1)/nCACHE_BUFFER_BYTEs)) - -#if defined(MICROSOFTC_700) && INCLUDEvMEMORY -#define CACHEbufferREADfrom(cache) \ -BOO(useVmem,LoadVMemory((MemHandle)cache->ptr,FALSE),cache->ptr) -#define CACHEbufferWRITEto(cache) \ -BOO(useVmem,LoadVMemory((MemHandle)cache->ptr,TRUE),cache->ptr) -#else -#define CACHEbufferREADfrom(cache) cache->ptr -#define CACHEbufferWRITEto(cache) cache->ptr -#endif - -/****************************************************************************** -* Local function prototypes. -******************************************************************************/ - -static FILE *CDFOpenFile PROTOARGs((char *file_spec, char *a_mode)); -static Logical FreeCache PROTOARGs((vCACHE *firstCache)); -static vCACHE *FindCache PROTOARGs((vFILE *vFp, long blockN)); -static Logical vRead PROTOARGs(( - long offset, void *buffer, size_t nBytes, vFILE *vFp -)); -static Logical vWrite PROTOARGs(( - long offset, void *buffer, size_t nBytes, vFILE *vFp -)); -static vCACHE *AllocateBuffer PROTOARGs((vFILE *vFp)); -static vCACHE *PageIn PROTOARGs((vFILE *vFp, long blockN)); -static Logical WriteBlockFromCache PROTOARGs(( - vFILE *vFp, vCACHE *cache, size_t Nbytes -)); -static Logical WriteBlockFromBuffer PROTOARGs(( - vFILE *vFp, long blockN, void *buffer, size_t Nbytes -)); -#if EXTEND_FILE -static Logical ExtendFile PROTOARGs((vFILE *vFp, long toBlockN)); -#endif - -/****************************************************************************** -* CDFOpenFile. -******************************************************************************/ - -static FILE *CDFOpenFile (file_spec, a_mode) -char *file_spec; -char *a_mode; -{ -#if defined(vms) - char mrs[10+1]; /* Maximum record size. */ - char deq[10+1]; /* Default allocation quantity. */ - snprintf (mrs, (size_t) sizeof(mrs), "mrs=%d", nCACHE_BUFFER_BYTEs); - snprintf (deq, (size_t) sizeof(deq), "deq=%d", - VMS_DEFAULT_nALLOCATION_BLOCKS); - return fopen(file_spec,a_mode,"rfm=fix",mrs,deq); -#else - return FOPEN(file_spec,a_mode); -#endif -} - -/****************************************************************************** -* FindCache. -******************************************************************************/ - -static vCACHE *FindCache (vFp, blockN) -vFILE *vFp; -long blockN; -{ - vCACHE *cache = vFp->cacheHead; - while (cache != NULL) { - if (cache->blockN == blockN) { - if (cache != vFp->cacheHead) { - if (cache == vFp->cacheTail) { - cache->prev->next = NULL; - vFp->cacheTail = cache->prev; - } - else { - cache->next->prev = cache->prev; - cache->prev->next = cache->next; - } - vFp->cacheHead->prev = cache; - cache->next = vFp->cacheHead; - vFp->cacheHead = cache; - cache->prev = NULL; - } - return cache; - } - cache = cache->next; - } - return NULL; -} - -/****************************************************************************** -* FlushCache. -* Write cache buffers to disk from the specified starting buffer to the last -* buffer. -******************************************************************************/ - -VISIBLE_PREFIX Logical FlushCache (vFp, firstCache) -vFILE *vFp; /* Pointer to vFILE structure. */ -vCACHE *firstCache; /* Pointer to the first cache structure to flush. */ -{ - vCACHE *cache; long nBytes; - for (cache = firstCache; cache != NULL; cache = cache->next) { - if (cache->modified) { -#if defined(vms) - nBytes = nCACHE_BUFFER_BYTEs; -#else - nBytes = vFp->length - (cache->blockN * nCACHE_BUFFER_BYTEs); - nBytes = MINIMUM (nBytes, nCACHE_BUFFER_BYTEs); -#endif - if (!WriteBlockFromCache(vFp,cache,(size_t)nBytes)) return FALSE; - cache->modified = FALSE; - } - } - return TRUE; -} - -/****************************************************************************** -* FreeCache. -******************************************************************************/ - -static Logical FreeCache (firstCache) -vCACHE *firstCache; /* Pointer to the first cache structure to free. */ -{ - vCACHE *cache = firstCache; - while (cache != NULL) { - vCACHE *nextCache = cache->next; -#if defined(MICROSOFTC_700) && INCLUDEvMEMORY - if (useVmem) - FreeVMemory ((MemHandle) cache->ptr); - else -#endif - cdf_FreeMemory (cache->ptr, NULL); - cdf_FreeMemory (cache, NULL); - cache = nextCache; - } - return TRUE; -} - -/****************************************************************************** -* AllocateBuffer. -* Allocate a cache structure to use. It may be necessary to page out a block -* to the file. Returns a pointer to the allocated cache structure (or NULL if -* an error occurred). -******************************************************************************/ - -static vCACHE *AllocateBuffer (vFp) -vFILE *vFp; -{ - vCACHE *cache; long nBytes; -#if !defined(vms) - long offset; -#endif - /**************************************************************************** - * Check if a new cache structure can be allocated. If the allocation(s) - * fail, process as if the maximum number of cache buffers has already been - * reached. - ****************************************************************************/ - if (vFp->nBuffers < vFp->maxBuffers) { - cache = (vCACHE *) cdf_AllocateMemory ((size_t)sizeof(vCACHE), NULL); - if (cache != NULL) { -#if defined(MICROSOFTC_700) && INCLUDEvMEMORY - if (useVmem) - cache->ptr = (void *) AllocateVMemory (nCACHE_BUFFER_BYTEs); - else -#endif - cache->ptr = cdf_AllocateMemory ((size_t)nCACHE_BUFFER_BYTEs, NULL); - if (cache->ptr != NULL) { - if (vFp->cacheHead == NULL) { - vFp->cacheHead = cache; - vFp->cacheTail = cache; - cache->next = NULL; - cache->prev = NULL; - } - else { - vFp->cacheHead->prev = cache; - cache->next = vFp->cacheHead; - vFp->cacheHead = cache; - cache->prev = NULL; - } - (vFp->nBuffers)++; - memset(cache->ptr, 0, nCACHE_BUFFER_BYTEs); - return cache; - } - else { - cdf_FreeMemory (cache, NULL); - if (vFp->nBuffers == 0) return NULL; - } - } - } - /**************************************************************************** - * The maximum number of cache buffers have already been created. Scan the - * linked list of cache structures searching for the oldest buffer which has - * not been modified. If one is found, it is moved to the head of the linked - * list. - ****************************************************************************/ - for (cache = vFp->cacheTail; cache != NULL; cache = cache->prev) { - if (!cache->modified) { - if (cache != vFp->cacheHead) { - if (cache == vFp->cacheTail) { - cache->prev->next = NULL; - vFp->cacheTail = cache->prev; - } - else { - cache->prev->next = cache->next; - cache->next->prev = cache->prev; - } - vFp->cacheHead->prev = cache; - cache->next = vFp->cacheHead; - vFp->cacheHead = cache; - cache->prev = NULL; - } - return cache; - } - } - /**************************************************************************** - * An unmodified buffer was not found. The last buffer on the linked list - * will be paged back out to the file and then this cache structure is moved - * to the head of the linked list. - ****************************************************************************/ - cache = vFp->cacheTail; -#if defined(vms) - nBytes = nCACHE_BUFFER_BYTEs; -#else - offset = nCACHE_BUFFER_BYTEs * cache->blockN; - nBytes = vFp->length - offset; - nBytes = MINIMUM (nBytes, nCACHE_BUFFER_BYTEs); -#endif - if (!WriteBlockFromCache(vFp,cache,(size_t)nBytes)) return NULL; - if (cache != vFp->cacheHead) { - cache->prev->next = NULL; - vFp->cacheTail = cache->prev; - vFp->cacheHead->prev = cache; - cache->next = vFp->cacheHead; - vFp->cacheHead = cache; - cache->prev = NULL; - } - (vFp->nPageOuts)++; - memset(cache->ptr, 0, nCACHE_BUFFER_BYTEs); - return cache; -} - -/****************************************************************************** -* ExtendFile. -* Extend the file to a specified number of blocks. -******************************************************************************/ - -#if EXTEND_FILE -static Logical ExtendFile (vFp, toBlockN) -vFILE *vFp; -long toBlockN; -{ - vCACHE *cache; long blockN; - /**************************************************************************** - * First check to see if the physical end-of-file must be extended out to the - * next multiple of the cache/block size. - ****************************************************************************/ - if (vFp->phyLength > 0) { - long lastPhyBlockN = LASTphyBLOCKn (vFp); - long nBytes = vFp->phyLength - (nCACHE_BUFFER_BYTEs * lastPhyBlockN); - if (nBytes < nCACHE_BUFFER_BYTEs) { - cache = FindCache (vFp, lastPhyBlockN); - if (cache != NULL) { - void *buffer = CACHEbufferREADfrom (cache); - if (buffer == NULL) return FALSE; - if (!vWrite(nCACHE_BUFFER_BYTEs * lastPhyBlockN, - buffer,nCACHE_BUFFER_BYTEs,vFp)) return FALSE; - cache->modified = FALSE; - } - else { - Byte1 buffer[nCACHE_BUFFER_BYTEs]; - if (!vRead(nCACHE_BUFFER_BYTEs * lastPhyBlockN, - buffer,(size_t)nBytes,vFp)) return FALSE; -#if CLEAR_BYTES - ClearBytes (buffer, (int) nBytes, nCACHE_BUFFER_BYTEs - 1); -#endif - if (!vWrite(nCACHE_BUFFER_BYTEs * lastPhyBlockN, - buffer,nCACHE_BUFFER_BYTEs,vFp)) return FALSE; - } - vFp->phyLength = nCACHE_BUFFER_BYTEs * (lastPhyBlockN + 1); - } - } - /**************************************************************************** - * Then extend the file the remaining blocks. - ****************************************************************************/ - for (blockN = LASTphyBLOCKn(vFp) + 1; blockN <= toBlockN; blockN++) { - cache = FindCache (vFp, blockN); - if (cache != NULL) { - void *buffer = CACHEbufferREADfrom (cache); - if (buffer == NULL) return FALSE; - if (!vWrite(nCACHE_BUFFER_BYTEs * blockN, - buffer,nCACHE_BUFFER_BYTEs,vFp)) return FALSE; - cache->modified = FALSE; - } - else { - Byte1 buffer[nCACHE_BUFFER_BYTEs]; -#if CLEAR_BYTES - ClearBytes (buffer, 0, nCACHE_BUFFER_BYTEs - 1); -#endif - if (!vWrite(nCACHE_BUFFER_BYTEs * blockN, - buffer,nCACHE_BUFFER_BYTEs,vFp)) return FALSE; - } - vFp->phyLength = nCACHE_BUFFER_BYTEs * (blockN + 1); - } - return TRUE; -} -#endif - -/****************************************************************************** -* PageIn. -* Page in a block from the file. Returns pointer to cache structure used (or -* NULL if an error occurred). -******************************************************************************/ - -static vCACHE *PageIn (vFp, blockN) -vFILE *vFp; -long blockN; -{ - long offset, nBytes; vCACHE *cache; void *buffer; - cache = AllocateBuffer (vFp); - if (cache == NULL) return NULL; - offset = blockN * nCACHE_BUFFER_BYTEs; - nBytes = vFp->phyLength - offset; - nBytes = MINIMUM (nBytes, nCACHE_BUFFER_BYTEs); - buffer = CACHEbufferWRITEto (cache); - if (buffer == NULL) return NULL; - if (!vRead(offset,buffer,(size_t)nBytes,vFp)) return NULL; -#if CLEAR_BYTES - ClearBytes (buffer, (int) nBytes, nCACHE_BUFFER_BYTEs - 1); -#endif - cache->blockN = blockN; - cache->modified = FALSE; - (vFp->nPageIns)++; - return cache; -} - -/****************************************************************************** -* WriteBlockFromCache. -* Write a block out to the file from a cache buffer. Returns TRUE if -* successful, FALSE if an error occurred. -******************************************************************************/ - -static Logical WriteBlockFromCache (vFp, cache, nBytes) -vFILE *vFp; -vCACHE *cache; -size_t nBytes; -{ - long offset; void *buffer; - offset = nCACHE_BUFFER_BYTEs * cache->blockN; -#if EXTEND_FILE - if (offset > vFp->phyLength) { - if (!ExtendFile(vFp,cache->blockN-1)) return FALSE; - } -#endif - buffer = CACHEbufferREADfrom (cache); - if (buffer == NULL) return FALSE; - if (!vWrite(offset,buffer,nBytes,vFp)) return FALSE; - vFp->phyLength = MaxLong (vFp->phyLength, (long) (offset + nBytes)); - return TRUE; -} - -/****************************************************************************** -* WriteBlockFromBuffer. -* Write a block out to the file from the caller's buffer. Returns TRUE if -* successful, FALSE if an error occurred. -******************************************************************************/ - -static Logical WriteBlockFromBuffer (vFp, blockN, buffer, nBytes) -vFILE *vFp; -long blockN; -void *buffer; -size_t nBytes; -{ - long offset = nCACHE_BUFFER_BYTEs * blockN; -#if EXTEND_FILE - if (offset > vFp->phyLength) { - if (!ExtendFile(vFp,blockN-1)) return FALSE; - } -#endif - if (!vWrite(offset,buffer,nBytes,vFp)) return FALSE; - vFp->phyLength = MaxLong (vFp->phyLength, (long) (offset + nBytes)); - return TRUE; -} - -/****************************************************************************** -* vRead. -******************************************************************************/ - -static Logical vRead (offset, buffer, nBytes, vFp) -long offset; -void *buffer; -size_t nBytes; -vFILE *vFp; -{ - int tryN; - /**************************************************************************** - * Does the scratch file exist? It doesn't make sense for it not to. - ****************************************************************************/ - if (vFp->fp == NULL) return FALSE; - /**************************************************************************** - * Tally a block read. - ****************************************************************************/ - (vFp->nBlockReads)++; - /**************************************************************************** - * Read the block. Multiple attempts are made for optical disks. - ****************************************************************************/ - for (tryN = 1; tryN <= vMAX_TRYs; tryN++) { - if (fseek(vFp->fp,offset,vSEEK_SET) == EOF) return FALSE; - if (fread(buffer,nBytes,1,vFp->fp) == 1) return TRUE; - } - return FALSE; -} - -/****************************************************************************** -* vWrite. -******************************************************************************/ - -static Logical vWrite(offset,buffer,nBytes,vFp) -long offset; -void *buffer; -size_t nBytes; -vFILE *vFp; -{ - int tryN, pid; - FILE *fp; -#if defined(__MWERKS__) - int ii; -#endif -#if defined(win32) - char *temp; -#endif - /**************************************************************************** - * Create the scratch file if necessary. If so, the current file path is - * actually the scratch directory to be used. - ****************************************************************************/ - if (vFp->fp == NULL) { - long i; char *tmpPath, *originalPath; size_t pathLength; - pathLength = strlen(vFp->path) + 1 + 8 + 1 + EXT_LEN; - if (pathLength < DU_MAX_DIR_LEN) pathLength = DU_MAX_DIR_LEN; - tmpPath = (char *) cdf_AllocateMemory ((size_t)pathLength + 1, NULL); - if (tmpPath == NULL) return FALSE; - originalPath = (char *) cdf_AllocateMemory ((size_t)pathLength + 1, NULL); - if (originalPath == NULL) return FALSE; - pid = GetMyPID(); - if (pid == -1) { -#if defined(win32) - pid = (int) _getpid(); -#else - pid = (int) getpid(); -#endif - SetMyPID (pid); - srand((unsigned int)pid*time(NULL)); - } - if (vFp->path != NULL && strlen(vFp->path) != 0) { - strcpyX (tmpPath, vFp->path, 0); - AppendToDir (tmpPath, ""); - } else { - /* Use the known tmp direcotry */ -#if defined(linux) || defined(unix) - strcpyX (tmpPath, "/tmp/", 0); -#else -# if defined(win32) - temp = getenv("TEMP"); - if (temp != NULL) { - strcpyX (tmpPath, temp, 0); - strcatX (tmpPath, "\\", 0); - } else { - temp = getenv("TMP"); - if (temp != NULL) { - strcpyX (tmpPath, temp, 0); - strcatX (tmpPath, "\\", 0); - } - } -# else -# if defined(vms) - strcpyX (tmpPath, "SYS$SCRATCH:", 0); -# else - strcpyX (tmpPath, vFp->path, 0); -# endif -# endif -#endif - } - strcpyX (originalPath, tmpPath, 0); - for (i = 1; i <= MAX_TMP; i++) { - snprintf (EofS(tmpPath), (size_t) pathLength + 1 - strlen(tmpPath), - "TMP%05ld.%s", (long)(rand()%100000), vFp->scratchExt); - if (!IsReg(tmpPath)) { - fp = CDFOpenFile (tmpPath, WRITE_PLUS_a_mode); - if (fp != NULL) break; - } - strcpyX (tmpPath, originalPath, 0); - } - cdf_FreeMemory (originalPath, NULL); - if (fp == NULL) { - cdf_FreeMemory (tmpPath, NULL); - return FALSE; - } else { - cdf_FreeMemory (vFp->path, NULL); - vFp->path = tmpPath; - vFp->fp = fp; - } - cdf_FreeMemory (originalPath, NULL); - } - /**************************************************************************** - * Tally a block write. - ****************************************************************************/ - (vFp->nBlockWrites)++; - -#if defined(__MWERKS__) - ii = fseek(vFp->fp, (long)0, vSEEK_END); -#endif - - /**************************************************************************** - * Write the block. Multiple attempts are made for optical disks. - ****************************************************************************/ - for (tryN = 1; tryN <= vMAX_TRYs; tryN++) { - if (fseek(vFp->fp,offset,vSEEK_SET) == EOF) return FALSE; - if (fwrite(buffer,nBytes,1,vFp->fp) == 1) return TRUE; - } - return FALSE; -} - -/****************************************************************************** -* V_open. -* Open the file and setup vFILE structure. -******************************************************************************/ - -VISIBLE_PREFIX vFILE *V_open (file_spec, a_mode) -char *file_spec; /* File specification. */ -char *a_mode; /* Access mode. */ -{ - FILE *fp; /* Temporary file pointer. */ - vFILE *vFp; /* Pointer to vFILE structure. */ -#if defined(vms) - struct STAT st; /* Status block from `stat'. */ -#endif - /**************************************************************************** - * Open the file. - ****************************************************************************/ - fp = CDFOpenFile (file_spec, a_mode); - if (fp == NULL) return NULL; -#if defined(vms) - /**************************************************************************** - * If the file is being opened in a mode which may require it to be extended - * (`r+' [read/write] or `a/a+' [append]), check that the EOF offset in the - * last block is zero (0). If not, rewrite the last block out to the end. - * `r' is not checked because it is read only. - * `w/w+' is not checked because a new file (with EOF == 0) will have been - * created. - ****************************************************************************/ - if (strstr(a_mode,"r+") || strchr(a_mode,'a')) { - long eof; size_t EOFoffsetInBlock; - if (fseek(fp,0,vSEEK_END) == EOF) { - fclose (fp); - return NULL; - } - eof = ftell (fp); - if (eof == EOF) { - fclose (fp); - return NULL; - } - EOFoffsetInBlock = eof % nCACHE_BUFFER_BYTEs; - if (EOFoffsetInBlock != 0) { - long offsetToLastBlock; char buffer[nCACHE_BUFFER_BYTEs]; size_t numitems; int i; - offsetToLastBlock = nCACHE_BUFFER_BYTEs * (eof / nCACHE_BUFFER_BYTEs); - if (fseek(fp,offsetToLastBlock,vSEEK_SET) == EOF) { - fclose (fp); - return NULL; - } - /* for (i = 0; i < nCACHE_BUFFER_BYTEs; i++) buffer[i] = 0; */ - memset (buffer, 0, (size_t) nCACHE_BUFFER_BYTEs); - if (fread(buffer,EOFoffsetInBlock,1,fp) != 1) { - fclose (fp); - return NULL; - } - if (fseek(fp,offsetToLastBlock,vSEEK_SET) == EOF) { - fclose (fp); - return NULL; - } - if (fwrite(buffer,nCACHE_BUFFER_BYTEs,1,fp) != 1) { - fclose (fp); - return NULL; - } - if (fclose(fp) == EOF) { - fclose (fp); - return NULL; - } - fp = CDFOpenFile (file_spec, a_mode); - if (fp == NULL) return NULL; - } - } -#endif - /**************************************************************************** - * Allocate and load vFILE structure. - ****************************************************************************/ - vFp = (vFILE *) cdf_AllocateMemory ((size_t)sizeof(vFILE), NULL); - if (vFp == NULL) { - fclose (fp); - return NULL; - } - vFp->magic_number = VSTREAM_MAGIC_NUMBER; - vFp->fp = fp; - vFp->path = (char *) cdf_AllocateMemory ((size_t)strlen(file_spec) + 1, NULL); - if (vFp->path == NULL) { - cdf_FreeMemory (vFp, NULL); - fclose (fp); - return NULL; - } - else - strcpyX (vFp->path, file_spec, 0); - vFp->scratch = FALSE; - vFp->error = FALSE; - vFp->eof = FALSE; - vFp->cacheHead = NULL; - vFp->cacheTail = NULL; - vFp->maxBuffers = DEFAULT_nCACHE_BUFFERs; - vFp->nBuffers = 0; - vFp->nBlockReads = 0; - vFp->nBlockWrites = 0; - vFp->nV_reads = 0; - vFp->nV_writes = 0; - vFp->nPageIns = 0; - vFp->nPageOuts = 0; - vFp->GDR = NULL; - vFp->GDR64 = NULL; - vFp->ADRList = NULL; - vFp->ADRList64 = NULL; - /**************************************************************************** - * Determine length of file and set current offset. - ****************************************************************************/ -#if defined(vms) - /**************************************************************************** - * This method is used on VMS systems in case the file is on a CD-ROM. Some - * VMS CD-ROM drivers do not correctly handle the EOF marker of a file. - * `stat' might fail, however, if the file specification contains a DECnet - * node. If `stat' fails, try the other method before giving up. - ****************************************************************************/ - if (stat(file_spec,&st) == 0) { - vFp->length = st.st_size; - vFp->phyLength = st.st_size; - } - else { -#endif - if (fseek(vFp->fp,0,vSEEK_END) == EOF) { - cdf_FreeMemory (vFp->path, NULL); - cdf_FreeMemory (vFp, NULL); - fclose (vFp->fp); - return NULL; - } - vFp->length = ftell (vFp->fp); - if (vFp->length == EOF) { - cdf_FreeMemory (vFp->path, NULL); - cdf_FreeMemory (vFp, NULL); - fclose (vFp->fp); - return NULL; - } - vFp->phyLength = vFp->length; -#if defined(vms) - } -#endif - vFp->offset = BOO(strchr(a_mode,'a') == NULL,0,vFp->length); - /**************************************************************************** - * Return pointer to vFILE structure. - ****************************************************************************/ - return vFp; -} - -/****************************************************************************** -* V_scratch. -* Creates a scratch file. Note that the file is not actually created until a -* block needs to be paged out. -******************************************************************************/ - -VISIBLE_PREFIX vFILE *V_scratch (directory, extension) -char *directory; /* Directory in which to create the scratch file (if - necessary). If NULL, use the current directory. */ -char *extension; /* Extension to use for the scratch file. If NULL, - `.ich' is used. */ -{ - vFILE *vFp; /* Pointer to vFILE structure. */ - /**************************************************************************** - * Allocate and load vFILE structure. - ****************************************************************************/ - vFp = (vFILE *) cdf_AllocateMemory ((size_t)sizeof(vFILE), NULL); - if (vFp == NULL) return NULL; - vFp->magic_number = VSTREAM_MAGIC_NUMBER; - vFp->fp = NULL; - vFp->fh = 0; - vFp->path = (char *) cdf_AllocateMemory ((size_t)BOO(directory == NULL, - 0,strlen(directory)) + 1, NULL); - if (vFp->path == NULL) { - cdf_FreeMemory (vFp, NULL); - return NULL; - } - else - strcpyX (vFp->path, BOO(directory == NULL,"",directory), 0); - strcpyX (vFp->scratchExt, BOO(extension == NULL,"ich",extension), EXT_LEN); - vFp->scratch = TRUE; - vFp->error = FALSE; - vFp->eof = FALSE; - vFp->cacheHead = NULL; - vFp->cacheTail = NULL; - vFp->maxBuffers = DEFAULT_nCACHE_BUFFERs; - vFp->nBuffers = 0; - vFp->nBlockReads = 0; - vFp->nBlockWrites = 0; - vFp->nV_reads = 0; - vFp->nV_writes = 0; - vFp->nPageIns = 0; - vFp->nPageOuts = 0; - vFp->length = 0; - vFp->length64 = (OFF_T) 0; - vFp->phyLength = 0; - vFp->phyLength64 = (OFF_T) 0; - vFp->offset = 0; - vFp->offset64 = (OFF_T) 0; - vFp->GDR = NULL; - vFp->GDR64 = NULL; - vFp->ADRList = NULL; - vFp->ADRList64 = NULL; - /**************************************************************************** - * Return pointer to vFILE structure. - ****************************************************************************/ - return vFp; -} - -/****************************************************************************** -* V_setcache. -* Set number of cache buffers. This can be done at any time after the file -* is opened. Note that in some cases the new cache size may be the same as -* the old cache size (do nothing). -******************************************************************************/ - -VISIBLE_PREFIX int V_setcache (vFp, maxBuffers) -vFILE *vFp; /* Pointer to vFILE structure. */ -int maxBuffers; /* New maximum number of cache buffers. */ -{ - if (vFp == NULL) return EOF; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return EOF; - if (vFp->error) return EOF; - if (maxBuffers < 1) return EOF; - if (maxBuffers > vFp->maxBuffers) { - /************************************************************************** - * The number of cache buffers is increasing. - **************************************************************************/ - vFp->maxBuffers = maxBuffers; - } - else { - if (maxBuffers < vFp->maxBuffers) { - /************************************************************************ - * The number of cache buffers is decreasing - flush to disk and free - * the buffers which are going away. - ************************************************************************/ - vCACHE *cache; int count; - if (vFp->nBuffers > maxBuffers) { - for (count = 1, - cache = vFp->cacheHead; - count < maxBuffers; count++) cache = cache->next; - if (!FlushCache(vFp,cache->next)) { - vFp->error = TRUE; - return EOF; - } - FreeCache (cache->next); - cache->next = NULL; - vFp->cacheTail = cache; - vFp->nBuffers = maxBuffers; - } - vFp->maxBuffers = maxBuffers; - } - } - return 0; -} - -/****************************************************************************** -* V_seek. -* Seek to a position in the file. -******************************************************************************/ - -VISIBLE_PREFIX int V_seek (vFp, offset, direction) -vFILE *vFp; /* Pointer to vFILE structure. */ -long offset; /* New current file offset. */ -int direction; /* Reference for offset. */ -{ - if (vFp == NULL) return EOF; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return EOF; - if (vFp->error) return EOF; - vFp->eof = FALSE; /* Cleared before proceeding. */ - switch (direction) { - case vSEEK_SET: - if (offset < 0) return EOF; - vFp->offset = offset; - break; - case vSEEK_CUR: - if (vFp->offset + offset < 0) return EOF; - vFp->offset += offset; - break; - case vSEEK_END: - vFp->offset = vFp->length; - break; - default: - return EOF; - } - return 0; -} - -/****************************************************************************** -* V_tell. -* Return current offset (position) in file. This is the byte offset one past -* the last byte that exists. -******************************************************************************/ - -VISIBLE_PREFIX long V_tell (vFp) -vFILE *vFp; /* Pointer to vFILE structure. */ -{ - if (vFp == NULL) return EOF; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return EOF; - if (vFp->error) return EOF; - return vFp->offset; -} - -/****************************************************************************** -* V_eof. -* Returns non-zero if EOF indicator is set. A read at the EOF must occur -* before the EOF indicator will be set (just like `feof'). -******************************************************************************/ - -VISIBLE_PREFIX int V_eof (vFp) -vFILE *vFp; /* Pointer to vFILE structure. */ -{ - if (vFp == NULL) return EOF; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return EOF; - if (vFp->eof) return 1; - return 0; -} - -/****************************************************************************** -* V_error. -* Returns non-zero if error indicator is set. -******************************************************************************/ - -VISIBLE_PREFIX int V_error (vFp) -vFILE *vFp; /* Pointer to vFILE structure. */ -{ - if (vFp == NULL) return EOF; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return EOF; - if (vFp->error) return 1; - return 0; -} - -/****************************************************************************** -* V_read. -******************************************************************************/ - -VISIBLE_PREFIX size_t V_read (buffer, item_size, n_items, vFp) -void *buffer; /* Pointer to buffer. */ -size_t item_size; /* Size (in bytes) of each item to read. */ -size_t n_items; /* Number of items to read. */ -vFILE *vFp; /* Pointer to vFILE structure. */ -{ - size_t nBytesX; /* Total number of bytes in buffer. */ - size_t nBytes; /* Total number of bytes to read. */ - long remainingItems; /* Number of items remaining after the offset. */ - size_t nItems; /* Number of items to actually be read. */ - long firstBlockN; /* First block involved in read. */ - long lastBlockN; /* Last block involved in read. */ - int bufferOffset; /* Offset (bytes) into buffer. */ - long fileOffset; /* Offset (bytes) into file. */ - size_t xBytes; /* Number of bytes in a transfer. */ - long blockN; /* Block number in file (from 0). */ - long atBlockN; /* Block number in file (from 0) at which to read. */ - vCACHE *cache; /* Pointer to cache structure. */ - Byte1 *cBuffer; /* Pointer to cache buffer. */ - int remainingBytes; /* Number of bytes remaining in a block. */ - /**************************************************************************** - * Validate read. - ****************************************************************************/ -#if defined(DEBUG) - if (getenv("READ.ERROR") != NULL) return 0; -#endif - if (vFp == NULL) return 0; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return 0; - if (vFp->error) return 0; - if ((int) item_size <= 0 || (int) n_items <= 0) return 0; - remainingItems = (vFp->length - vFp->offset) / ((long) item_size); - if (remainingItems < 1) { - vFp->eof = TRUE; - vFp->offset = vFp->length; - return 0; - } - if ((long) n_items > remainingItems) { - nItems = (size_t) remainingItems; - vFp->eof = TRUE; /* File offset set to EOF before returning. */ - } - else - nItems = n_items; - nBytes = nItems * item_size; - nBytesX = n_items * item_size; - (vFp->nV_reads)++; - /**************************************************************************** - * Read from first block... - ****************************************************************************/ - firstBlockN = vFp->offset / nCACHE_BUFFER_BYTEs; - bufferOffset = (int) (vFp->offset % nCACHE_BUFFER_BYTEs); - remainingBytes = nCACHE_BUFFER_BYTEs - bufferOffset; - xBytes = MINIMUM (nBytes, (size_t) remainingBytes); - if (xBytes > nBytesX) return 0; - if (bufferOffset > 0 || xBytes < nCACHE_BUFFER_BYTEs) { - cache = FindCache (vFp, firstBlockN); - if (cache == NULL) cache = PageIn (vFp, firstBlockN); - if (cache == NULL) { - vFp->error = TRUE; - return 0; - } - cBuffer = CACHEbufferREADfrom (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - memmove (buffer, cBuffer + bufferOffset, xBytes); - buffer = (Byte1 *) buffer + xBytes; - atBlockN = firstBlockN + 1; - } - else - atBlockN = firstBlockN; - /**************************************************************************** - * Read from remaining blocks... - ****************************************************************************/ - lastBlockN = (vFp->offset + nBytes - 1) / nCACHE_BUFFER_BYTEs; - for (blockN = atBlockN; blockN <= lastBlockN; blockN++) { - xBytes = (size_t) (vFp->offset + nBytes - (nCACHE_BUFFER_BYTEs * blockN)); - xBytes = MINIMUM (xBytes, nCACHE_BUFFER_BYTEs); - if (xBytes > nBytesX) return 0; - cache = FindCache (vFp, blockN); - if (cache != NULL) { - cBuffer = CACHEbufferREADfrom (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - memmove (buffer, cBuffer, xBytes); - } - else { - if (xBytes < nCACHE_BUFFER_BYTEs) { - cache = PageIn (vFp, blockN); - if (cache == NULL) { - vFp->error = TRUE; - return 0; - } - cBuffer = CACHEbufferREADfrom (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - memmove (buffer, cBuffer, xBytes); - } - else { - fileOffset = nCACHE_BUFFER_BYTEs * blockN; - if (!vRead(fileOffset,buffer,nCACHE_BUFFER_BYTEs,vFp)) { - vFp->error = TRUE; - return 0; - } - } - } - buffer = (Byte1 *) buffer + xBytes; - } - /**************************************************************************** - * Increment current file offset or set to EOF if the EOF indicator was set. - ****************************************************************************/ - vFp->offset = BOO(vFp->eof,vFp->length,vFp->offset + nBytes); - return nItems; -} - -/****************************************************************************** -* V_write. -******************************************************************************/ - -VISIBLE_PREFIX size_t V_write (buffer, item_size, n_items, vFp) -void *buffer; /* Pointer to buffer. */ -size_t item_size; /* Size (in bytes) of each item to write. */ -size_t n_items; /* Number of items to write. */ -vFILE *vFp; /* Pointer to vFILE structure. */ -{ - size_t nBytesX; /* Total number of bytes in buffer. */ - size_t nBytes; /* Total number of bytes in write. */ - long firstBlockN; /* First block involved in write. */ - long lastBlockN; /* Last block involved in write. */ - int bufferOffset; /* Offset (bytes) into buffer. */ - long blockN; /* Block number in file (from 0). */ - long atBlockN; /* Block number in file (from 0) at which to write. */ - size_t xBytes; /* Number of bytes in a transfer. */ - vCACHE *cache; /* Pointer to cache structure. */ - Byte1 *cBuffer; /* Pointer to cache buffer. */ - size_t nBytesInBlock; /* Number of bytes to the end of the block. */ - /**************************************************************************** - * Validate write. - ****************************************************************************/ -#if defined(DEBUG) - if (getenv("WRITE.ERROR") != NULL) return 0; -#endif - if (vFp == NULL) return 0; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return 0; - if (vFp->error) return 0; - if ((int) item_size <= 0 || (int) n_items <= 0) return 0; - vFp->eof = FALSE; /* Cleared before proceeding. */ - nBytes = item_size * n_items; - nBytesX = n_items * item_size; - if (nBytes < 1) return 0; - (vFp->nV_writes)++; - /**************************************************************************** - * Write to first block... - * Note that if this is a scratch file, the first block is always placed in - * the cache (even if a full block). - ****************************************************************************/ - firstBlockN = vFp->offset / nCACHE_BUFFER_BYTEs; - bufferOffset = (int) (vFp->offset % nCACHE_BUFFER_BYTEs); - nBytesInBlock = nCACHE_BUFFER_BYTEs - bufferOffset; - xBytes = MINIMUM (nBytes, nBytesInBlock); - if (xBytes > nBytesX) return 0; - if (vFp->scratch || bufferOffset > 0 || xBytes < nCACHE_BUFFER_BYTEs) { - cache = FindCache (vFp, firstBlockN); - if (cache == NULL) { - if (firstBlockN <= LASTphyBLOCKn(vFp)) { - cache = PageIn (vFp, firstBlockN); - if (cache == NULL) { - vFp->error = TRUE; - return 0; - } - } - else { - cache = AllocateBuffer (vFp); - if (cache == NULL) { - vFp->error = TRUE; - return 0; - } - cache->blockN = firstBlockN; -#if CLEAR_BYTES - cBuffer = CACHEbufferWRITEto (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - ClearBytes (cBuffer, 0, bufferOffset - 1); - ClearBytes (cBuffer, (int) (bufferOffset + xBytes), - nCACHE_BUFFER_BYTEs - 1); -#endif - } - } - cBuffer = CACHEbufferWRITEto (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - memmove (cBuffer + bufferOffset, buffer, xBytes); - cache->modified = TRUE; - vFp->length = MaxLong (vFp->length,(long) (vFp->offset + xBytes)); - buffer = (Byte1 *) buffer + xBytes; - atBlockN = firstBlockN + 1; - } - else - atBlockN = firstBlockN; - /**************************************************************************** - * Write to remaining blocks... - ****************************************************************************/ - lastBlockN = (vFp->offset + nBytes - 1) / nCACHE_BUFFER_BYTEs; - for (blockN = atBlockN; blockN <= lastBlockN; blockN++) { - xBytes = (size_t) (vFp->offset + nBytes - (nCACHE_BUFFER_BYTEs * blockN)); - xBytes = MINIMUM (xBytes, nCACHE_BUFFER_BYTEs); - if (xBytes > nBytesX) return 0; - /************************************************************************* - * Is this block in the cache? If so, move the number of bytes to be - * written at this block to its cache buffer. - *************************************************************************/ - cache = FindCache (vFp, blockN); - if (cache != NULL) { - cBuffer = CACHEbufferWRITEto (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - memmove (cBuffer, buffer, xBytes); - cache->modified = TRUE; - } - else { - /*********************************************************************** - * This block is not in the cache. Is a partial block to be written? - * Note that if this is a scratch file, the block is always placed in - * the cache (even if not a partial block). - ***********************************************************************/ - if (vFp->scratch || xBytes < nCACHE_BUFFER_BYTEs) { - if (blockN <= LASTphyBLOCKn(vFp)) { - cache = PageIn (vFp, blockN); - if (cache == NULL) { - vFp->error = TRUE; - return 0; - } - } - else { - cache = AllocateBuffer (vFp); - if (cache == NULL) { - vFp->error = TRUE; - return 0; - } - cache->blockN = blockN; -#if CLEAR_BYTES - cBuffer = CACHEbufferWRITEto (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - ClearBytes (cBuffer, (int) xBytes, nCACHE_BUFFER_BYTEs - 1); -#endif - } - cBuffer = CACHEbufferWRITEto (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - memmove (cBuffer, buffer, xBytes); - cache->modified = TRUE; - } - else { - /********************************************************************* - * A full block is to be written. - *********************************************************************/ - if (!WriteBlockFromBuffer(vFp,blockN,buffer,nCACHE_BUFFER_BYTEs)) { - vFp->error = TRUE; - return 0; - } - } - } - vFp->length = MaxLong (vFp->length, - (long) ((nCACHE_BUFFER_BYTEs * blockN) + xBytes)); - buffer = (Byte1 *) buffer + xBytes; - } - /**************************************************************************** - * Increment current file offset. - ****************************************************************************/ - vFp->offset += nBytes; - return n_items; -} - -/****************************************************************************** -* V_getc. -******************************************************************************/ - -VISIBLE_PREFIX int V_getc (fp) -vFILE *fp; -{ - uByte tmp; - if (V_read(&tmp,1,1,fp) != 1) return EOF; - return ((int) tmp); -} - -/****************************************************************************** -* V_putc. -******************************************************************************/ - -VISIBLE_PREFIX int V_putc (value, fp) -int value; -vFILE *fp; -{ - uByte tmp = (uByte) value; - if (V_write(&tmp,1,1,fp) != 1) return EOF; - return value; -} - -/****************************************************************************** -* V_clear. -* Marks all cache buffers as unmodified. This is used with scratch files to -* prevent blocks of unwanted data from being paged out to disk. -******************************************************************************/ - -VISIBLE_PREFIX int V_clear (vFp) -vFILE *vFp; /* Pointer to vFILE structure. */ -{ - vCACHE *cache; - if (vFp == NULL) return EOF; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return EOF; - if (vFp->error) return EOF; - for (cache = vFp->cacheHead; cache != NULL; cache = cache->next) { - cache->modified = FALSE; - } - return 0; -} - -/****************************************************************************** -* V_flush. -* Flush the file to disk. -******************************************************************************/ - -VISIBLE_PREFIX int V_flush (vFp) -vFILE *vFp; /* Pointer to vFILE structure. */ -{ - /**************************************************************************** - * Validate. - ****************************************************************************/ - if (vFp == NULL) return EOF; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return EOF; - if (vFp->error) return EOF; - /**************************************************************************** - * Flush cache buffers. If this is a scratch file, this will cause the file - * to be created if it hasn't been already (unless nothing has been written). - ****************************************************************************/ - if (!FlushCache(vFp,vFp->cacheHead)) { - vFp->error = TRUE; - return EOF; - } - /**************************************************************************** - * Flush file. Note that the file will not be flushed if this is a scratch - * file to which nothing has been written. - ****************************************************************************/ - if (vFp->fp != NULL) { - if (fflush(vFp->fp) == EOF) { - vFp->error = TRUE; - return EOF; - } - } - /**************************************************************************** - * Return success. - ****************************************************************************/ - return 0; -} - -/****************************************************************************** -* V_close. -* Returns EOF if an error occurred. -******************************************************************************/ - -VISIBLE_PREFIX int V_close (vFp, CDF, vStats) -vFILE *vFp; /* Pointer to vFILE structure. */ -struct CDFstruct *CDF; /* Indicator whether to perform check sum operation. */ -vSTATS *vStats; /* Pointer to statistics structure. */ -{ - Logical error = FALSE; /* Has an error occurred? */ - /**************************************************************************** - * Check if a valid pointer to a vFILE structure. - ****************************************************************************/ - if (vFp == NULL) return EOF; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return EOF; - /**************************************************************************** - * Write cache buffers. If this is a scratch file, this will cause the file - * to be created if it hasn't been already (unless nothing has been written). - ****************************************************************************/ - if (!FlushCache(vFp,vFp->cacheHead)) error = TRUE; - /**************************************************************************** - * Close the file. Note that the file will not be closed if this is a - * scratch file to which nothing has been written. - ****************************************************************************/ - if (vFp->fp != NULL) { - if (CDF != NULL && (!CDF->readOnly || CDF->status == READ_WRITE) && - CDF->singleFile && (CDF->checksum != NONE_CHECKSUM)) { -/* if (!FLUSHv(vFp)) error = TRUE; */ - if (!CDFAddChecksum(CDF)) error = TRUE; - } - if (fclose(vFp->fp) == EOF) error = TRUE; - } - /**************************************************************************** - * Pass back statistics (if requested). - ****************************************************************************/ - if (vStats != NULL) { - vStats->maxBuffers = vFp->maxBuffers; - vStats->nBuffers = vFp->nBuffers; - vStats->nV_reads = vFp->nV_reads; - vStats->nV_writes = vFp->nV_writes; - vStats->nBlockReads = vFp->nBlockReads; - vStats->nBlockWrites = vFp->nBlockWrites; - vStats->nPageIns = vFp->nPageIns; - vStats->nPageOuts = vFp->nPageOuts; - } - /**************************************************************************** - * Deallocate cache and vFILE structure. - ****************************************************************************/ - FreeCache (vFp->cacheHead); - cdf_FreeMemory (vFp->path, NULL); - cdf_FreeMemory (vFp, NULL); - /**************************************************************************** - * Return status. - ****************************************************************************/ - return BOO(error,EOF,0); -} - -/****************************************************************************** -* V_delete. -* Returns EOF if an error occurred. -******************************************************************************/ - -VISIBLE_PREFIX int V_delete (vFp, vStats) -vFILE *vFp; /* Pointer to vFILE structure. */ -vSTATS *vStats; /* Pointer to statistics structure. */ -{ - Logical error = FALSE; /* Has an error occurred? */ - /**************************************************************************** - * Check if a valid pointer to a vFILE structure. - ****************************************************************************/ - if (vFp == NULL) return EOF; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return EOF; - /**************************************************************************** - * Close the file. - ****************************************************************************/ - if (vFp->fp != NULL) { - if (fclose(vFp->fp) == EOF) error = TRUE; - } - /**************************************************************************** - * Delete the file (unless it was never created). - ****************************************************************************/ - if (vFp->fp != NULL) { - if (!CDFdeleteFile(vFp->path)) error = TRUE; - } - /**************************************************************************** - * Pass back statistics (if requested). - ****************************************************************************/ - if (vStats != NULL) { - vStats->maxBuffers = vFp->maxBuffers; - vStats->nBuffers = vFp->nBuffers; - vStats->nV_reads = vFp->nV_reads; - vStats->nV_writes = vFp->nV_writes; - vStats->nBlockReads = vFp->nBlockReads; - vStats->nBlockWrites = vFp->nBlockWrites; - vStats->nPageIns = vFp->nPageIns; - vStats->nPageOuts = vFp->nPageOuts; - } - /**************************************************************************** - * Deallocate cache and vFILE structure. - ****************************************************************************/ - FreeCache (vFp->cacheHead); - cdf_FreeMemory (vFp->path, NULL); - cdf_FreeMemory (vFp, NULL); - /**************************************************************************** - * Return status. - ****************************************************************************/ - return BOO(error,EOF,0); -} diff --git a/cdf36_3-dist/src/lib/vstream64.c b/cdf36_3-dist/src/lib/vstream64.c deleted file mode 100644 index 8656328..0000000 --- a/cdf36_3-dist/src/lib/vstream64.c +++ /dev/null @@ -1,1492 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF Virtual stream file. -* -* Version 4.7a, 18-Nov-97, Hughes STX. -* -* Modification history: -* -* V1.0 22-Jan-91, J Love Original version (developed for CDF V2.0). -* V2.0 12-Mar-91, J Love All fixes to V1.x. Modified vread and vwrite -* to buffer only when necessary. -* V3.0 14-May-91, J Love Added caching (for CDF V2.1). -* V3.1 31-Jul-91, J Love Added veof. Added 'memmove' for UNIX. Added -* "deq - default extension quantity" if VMS. -* Changed algorithm that looks for bufferN. -* Added number of CACHE buffers as a parameter -* specified in 'Vopen'. Renamed functions to -* avoid collisions on SGi/IRIX. -* V3.2 15-Aug-91, J Love Changed for IBM-PC/MS-DOS port. -* V4.0 20-May-92, J Love IBM PC port/CDF V2.2. -* V4.1 29-Sep-92, J Love CDF V2.3. Dealt with EOFs not at 512-byte -* boundaries (when FTPed from a UNIX machine). -* V4.2 21-Dec-93, J Love CDF V2.4. -* V4.3 12-Dec-94, J Love CDF V2.5. -* V4.3a 19-Jan-95, J Love IRIX 6.0 (64-bit). -* V4.3b 24-Feb-95, J Love Solaris 2.3 IDL i/f. -* V4.4 7-Jun-95, J Love Virtual memory under Microsoft C 7.00. -* V4.5 25-Jul-95, J Love More virtual memory under Microsoft C 7.00. -* V4.6 29-Sep-95, J Love Improved performance...on non-VMS systems don't -* extend files a block at a time, don't clear -* bytes (anywhere), etc. -* V4.7 26-Aug-96, J Love CDF V2.6. -* V4.7a 18-Nov-97, J Love Windows NT/Visual C++. -* V4.8 29-Jun-04, M Liu Added LFS (Large File Support > 2G). -* V5.0 17-Apr-06, M Liu Added checksum function before closing. -* V5.1 25-Apr-07, D Berger Changed all instances of hardcoded 512 to -* nCACHE_BUFFER_BYTEs. -* V5.2 20-Jun-07, D Berger Added initialization of variables to support -* READONLYon enhancements. -* V5.3 18-Jun-08, M Liu Modified the V_read64 and V_write64 to make -* sure the actual read/write bytes is within -* the buffer size. -* V5.4 12-Aug-10, M Liu Fill 0s to each new cache in AllocateBuffer. -* -******************************************************************************/ - -/****************************************************************************** -* Include files. -******************************************************************************/ - -#include "cdflib.h" -#include "cdflib64.h" -#include "errno.h" - -/****************************************************************************** -* Local macros/typedef's. -******************************************************************************/ - -#define CLEAR_BYTES 0 - -#if defined(vms) || defined(MPW_C) -#define EXTEND_FILE 1 -#else -#define EXTEND_FILE 0 -#endif - -#define LASTphyBLOCKn(vFp) \ -BOO(vFp->phyLength64 == 0,NO_BLOCK,(long) ((vFp->phyLength64-1)/nCACHE_BUFFER_BYTEs)) - -#if defined(MICROSOFTC_700) && INCLUDEvMEMORY -#define CACHEbufferREADfrom(cache) \ -BOO(useVmem,LoadVMemory((MemHandle)cache->ptr,FALSE),cache->ptr) -#define CACHEbufferWRITEto(cache) \ -BOO(useVmem,LoadVMemory((MemHandle)cache->ptr,TRUE),cache->ptr) -#else -#define CACHEbufferREADfrom(cache) cache->ptr -#define CACHEbufferWRITEto(cache) cache->ptr -#endif - -int pid = -1; - -/****************************************************************************** -* Local function prototypes. -******************************************************************************/ -#if defined(win32) && (_FILE_OFFSET_BITS == 64) -static int CDFOpenFile PROTOARGs((char *file_spec, char *a_mode)); -#else -static FILE *CDFOpenFile PROTOARGs((char *file_spec, char *a_mode)); -#endif - -static Logical FreeCache PROTOARGs((vCACHE *firstCache)); -static vCACHE *FindCache PROTOARGs((vFILE *vFp, long blockN)); -static int CountCaches PROTOARGs((vFILE *vFp)); -static Logical vRead PROTOARGs(( - OFF_T offset, void *buffer, size_t nBytes, vFILE *vFp -)); -static Logical vWrite PROTOARGs(( - OFF_T offset, void *buffer, size_t nBytes, vFILE *vFp -)); -static vCACHE *AllocateBuffer PROTOARGs((vFILE *vFp)); -static vCACHE *PageIn PROTOARGs((vFILE *vFp, long blockN)); -static Logical WriteBlockFromCache PROTOARGs(( - vFILE *vFp, vCACHE *cache, size_t Nbytes -)); -static Logical WriteBlockFromBuffer PROTOARGs(( - vFILE *vFp, long blockN, void *buffer, size_t Nbytes -)); - -#if EXTEND_FILE -static Logical ExtendFile PROTOARGs((vFILE *vFp, long toBlockN)); -#endif - -/****************************************************************************** -* CDFOpenFile. -******************************************************************************/ -#if defined(win32) && (_FILE_OFFSET_BITS == 64) -static int CDFOpenFile (file_spec, a_mode) -#else -static FILE *CDFOpenFile (file_spec, a_mode) -#endif -char *file_spec; -char *a_mode; -{ -#if defined(vms) - char mrs[10+1]; /* Maximum record size. */ - char deq[10+1]; /* Default allocation quantity. */ - snprintf (mrs, (size_t) sizeof(mrs), "mrs=%d", nCACHE_BUFFER_BYTEs); - snprintf (deq, (size_t) sizeof(deq), "deq=%d", - VMS_DEFAULT_nALLOCATION_BLOCKS); - return fopen(file_spec,a_mode,"rfm=fix",mrs,deq); -#else -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - int oflag; - if (!strcmp(a_mode, READ_ONLY_a_mode)) - oflag = READ_ONLY_a_mode_windows_LFS; - else if (!strcmp(a_mode, READ_PLUS_a_mode)) - oflag = READ_PLUS_a_mode_windows_LFS; - else if (!strcmp(a_mode, WRITE_PLUS_a_mode)) - oflag = WRITE_PLUS_a_mode_windows_LFS; - return FOPEN64 (file_spec,oflag,PMODE); -#else - return FOPEN64 (file_spec,a_mode); -#endif -#endif -} - -/****************************************************************************** -* FindCache. If it is found, then move it to the head. -******************************************************************************/ - -static vCACHE *FindCache (vFp, blockN) -vFILE *vFp; -long blockN; -{ - vCACHE *cache = vFp->cacheHead; - while (cache != NULL) { - if (cache->blockN == blockN) { - if (cache != vFp->cacheHead) { - if (cache == vFp->cacheTail) { - cache->prev->next = NULL; - vFp->cacheTail = cache->prev; - } - else { - cache->next->prev = cache->prev; - cache->prev->next = cache->next; - } - vFp->cacheHead->prev = cache; - cache->next = vFp->cacheHead; - vFp->cacheHead = cache; - cache->prev = NULL; - } - return cache; - } - cache = cache->next; - } - return NULL; -} - -/****************************************************************************** -* CountCaches. -******************************************************************************/ - -static int CountCaches (vFp) -vFILE *vFp; -{ - int ix = 0; - vCACHE *cache = vFp->cacheHead; - while (cache != NULL) { - ++ix; - cache = cache->next; - } - return ix; -} - -/****************************************************************************** -* FlushCache64. -* Write cache buffers to disk from the specified starting buffer to the last -* buffer. -******************************************************************************/ - -VISIBLE_PREFIX Logical FlushCache64 (vFp, firstCache) -vFILE *vFp; /* Pointer to vFILE structure. */ -vCACHE *firstCache; /* Pointer to the first cache structure to flush. */ -{ - vCACHE *cache; long nBytes; OFF_T tmpBytes; - OFF_T tmp; - for (cache = firstCache; cache != NULL; cache = cache->next) { - if (cache->modified) { -#if defined(vms) - nBytes = nCACHE_BUFFER_BYTEs; -#else - tmp = ((OFF_T) cache->blockN) * nCACHE_BUFFER_BYTEs; - tmpBytes = vFp->length64 - tmp; - if (tmpBytes > nCACHE_BUFFER_BYTEs) - nBytes = nCACHE_BUFFER_BYTEs; - else - nBytes = (long) tmpBytes; -#endif - if (!WriteBlockFromCache(vFp,cache,(size_t)nBytes)) return FALSE; - cache->modified = FALSE; - } - } - return TRUE; -} - -/****************************************************************************** -* FreeCache. -******************************************************************************/ - -static Logical FreeCache (firstCache) -vCACHE *firstCache; /* Pointer to the first cache structure to free. */ -{ - vCACHE *cache = firstCache; - while (cache != NULL) { - vCACHE *nextCache = cache->next; -#if defined(MICROSOFTC_700) && INCLUDEvMEMORY - if (useVmem) - FreeVMemory ((MemHandle) cache->ptr); - else -#endif - cdf_FreeMemory (cache->ptr, NULL); - cdf_FreeMemory (cache, NULL); - cache = nextCache; - } - return TRUE; -} - -/****************************************************************************** -* AllocateBuffer. -* Allocate a cache structure to use. It may be necessary to page out a block -* to the file. Returns a pointer to the allocated cache structure (or NULL if -* an error occurred). -******************************************************************************/ - -static vCACHE *AllocateBuffer (vFp) -vFILE *vFp; -{ - vCACHE *cache; long nBytes; OFF_T tmpBytes; -#if !defined(vms) - OFF_T offset; -#endif - /**************************************************************************** - * Check if a new cache structure can be allocated. If the allocation(s) - * fail, process as if the maximum number of cache buffers has already been - * reached. - ****************************************************************************/ - if (vFp->nBuffers < vFp->maxBuffers) { - cache = (vCACHE *) cdf_AllocateMemory ((size_t)sizeof(vCACHE), NULL); - if (cache != NULL) { -#if defined(MICROSOFTC_700) && INCLUDEvMEMORY - if (useVmem) - cache->ptr = (void *) AllocateVMemory (nCACHE_BUFFER_BYTEs); - else -#endif - cache->ptr = cdf_AllocateMemory ((size_t)nCACHE_BUFFER_BYTEs, NULL); - if (cache->ptr != NULL) { - if (vFp->cacheHead == NULL) { - vFp->cacheHead = cache; - vFp->cacheTail = cache; - cache->next = NULL; - cache->prev = NULL; - } - else { - vFp->cacheHead->prev = cache; - cache->next = vFp->cacheHead; - vFp->cacheHead = cache; - cache->prev = NULL; - } - (vFp->nBuffers)++; - memset(cache->ptr, 0, nCACHE_BUFFER_BYTEs); - return cache; - } - else { - cdf_FreeMemory (cache, NULL); - if (vFp->nBuffers == 0) return NULL; - } - } - } - /**************************************************************************** - * The maximum number of cache buffers have already been created. Scan the - * linked list of cache structures searching for the oldest buffer which has - * not been modified. If one is found, it is moved to the head of the linked - * list. - ****************************************************************************/ - for (cache = vFp->cacheTail; cache != NULL; cache = cache->prev) { - if (!cache->modified) { - if (cache != vFp->cacheHead) { - if (cache == vFp->cacheTail) { - cache->prev->next = NULL; - vFp->cacheTail = cache->prev; - } - else { - cache->prev->next = cache->next; - cache->next->prev = cache->prev; - } - vFp->cacheHead->prev = cache; - cache->next = vFp->cacheHead; - vFp->cacheHead = cache; - cache->prev = NULL; - } - return cache; - } - } - /**************************************************************************** - * An unmodified buffer was not found. The last buffer on the linked list - * will be paged back out to the file and then this cache structure is moved - * to the head of the linked list. - ****************************************************************************/ - cache = vFp->cacheTail; -#if defined(vms) - nBytes = nCACHE_BUFFER_BYTEs; -#else - offset = ((OFF_T) cache->blockN) * nCACHE_BUFFER_BYTEs; - tmpBytes = vFp->length64 - offset; - if (tmpBytes > nCACHE_BUFFER_BYTEs) - nBytes = nCACHE_BUFFER_BYTEs; - else - nBytes = (long) tmpBytes; -#endif - if (!WriteBlockFromCache(vFp,cache,(size_t)nBytes)) return NULL; - if (cache != vFp->cacheHead) { - cache->prev->next = NULL; - vFp->cacheTail = cache->prev; - vFp->cacheHead->prev = cache; - cache->next = vFp->cacheHead; - vFp->cacheHead = cache; - cache->prev = NULL; - } - (vFp->nPageOuts)++; - memset(cache->ptr, 0, nCACHE_BUFFER_BYTEs); - return cache; -} - -/****************************************************************************** -* ExtendFile. -* Extend the file to a specified number of blocks. -******************************************************************************/ - -#if EXTEND_FILE -static Logical ExtendFile (vFp, toBlockN) -vFILE *vFp; -long toBlockN; -{ - vCACHE *cache; long blockN; - /**************************************************************************** - * First check to see if the physical end-of-file must be extended out to the - * next multiple of the cache/block size. - ****************************************************************************/ - if (vFp->phyLength64 > 0) { - long lastPhyBlockN = LASTphyBLOCKn (vFp); - long nBytes = (long) (vFp->phyLength64 - (OFF_T) lastPhyBlockN * - nCACHE_BUFFER_BYTEs); - if (nBytes < nCACHE_BUFFER_BYTEs) { - cache = FindCache (vFp, lastPhyBlockN); - if (cache != NULL) { - void *buffer = CACHEbufferREADfrom (cache); - if (buffer == NULL) return FALSE; - if (!vWrite((OFF_T) lastPhyBlockN * nCACHE_BUFFER_BYTEs, - buffer,nCACHE_BUFFER_BYTEs,vFp)) return FALSE; - cache->modified = FALSE; - } - else { - Byte1 buffer[nCACHE_BUFFER_BYTEs]; - if (!vRead(((OFF_T)lastPhyBlockN) * nCACHE_BUFFER_BYTEs, - buffer,(size_t)nBytes,vFp)) return FALSE; -#if CLEAR_BYTES - ClearBytes (buffer, (int) nBytes, nCACHE_BUFFER_BYTEs - 1); -#endif - if (!vWrite((OFF_T) lastPhyBlockN * nCACHE_BUFFER_BYTEs, - buffer,nCACHE_BUFFER_BYTEs,vFp)) return FALSE; - } - vFp->phyLength64 = ((OFF_T) nCACHE_BUFFER_BYTEs) * (lastPhyBlockN + 1); - } - } - /**************************************************************************** - * Then extend the file the remaining blocks. - ****************************************************************************/ - for (blockN = LASTphyBLOCKn(vFp) + 1; blockN <= toBlockN; blockN++) { - cache = FindCache (vFp, blockN); - if (cache != NULL) { - void *buffer = CACHEbufferREADfrom (cache); - if (buffer == NULL) return FALSE; - if (!vWrite((OFF_T) blockN * nCACHE_BUFFER_BYTEs, - buffer,nCACHE_BUFFER_BYTEs,vFp)) return FALSE; - cache->modified = FALSE; - } - else { - Byte1 buffer[nCACHE_BUFFER_BYTEs]; -#if CLEAR_BYTES - ClearBytes (buffer, 0, nCACHE_BUFFER_BYTEs - 1); -#endif - if (!vWrite((OFF_T) blockN * nCACHE_BUFFER_BYTEs, - buffer,nCACHE_BUFFER_BYTEs,vFp)) return FALSE; - } - vFp->phyLength64 = ((OFF_T) blockN + 1) * nCACHE_BUFFER_BYTEs; - } - return TRUE; -} -#endif - -/****************************************************************************** -* PageIn. -* Page in a block from the file. Returns pointer to cache structure used (or -* NULL if an error occurred). -******************************************************************************/ - -static vCACHE *PageIn (vFp, blockN) -vFILE *vFp; -long blockN; -{ - long nBytes; vCACHE *cache; void *buffer; - OFF_T offset, tmpBytes; - cache = AllocateBuffer (vFp); - if (cache == NULL) return NULL; - offset = ((OFF_T) blockN) * nCACHE_BUFFER_BYTEs; - tmpBytes = vFp->phyLength64 - offset; - if (tmpBytes > nCACHE_BUFFER_BYTEs) - nBytes = nCACHE_BUFFER_BYTEs; - else - nBytes = (long) tmpBytes; - buffer = CACHEbufferWRITEto (cache); - if (buffer == NULL) return NULL; - if (!vRead(offset,buffer,(size_t)nBytes,vFp)) return NULL; -#if CLEAR_BYTES - ClearBytes (buffer, (int) nBytes, nCACHE_BUFFER_BYTEs - 1); -#endif - cache->blockN = blockN; - cache->modified = FALSE; - (vFp->nPageIns)++; - return cache; -} - -/****************************************************************************** -* WriteBlockFromCache. -* Write a block out to the file from a cache buffer. Returns TRUE if -* successful, FALSE if an error occurred. -******************************************************************************/ - -static Logical WriteBlockFromCache (vFp, cache, nBytes) -vFILE *vFp; -vCACHE *cache; -size_t nBytes; -{ - OFF_T offset; void *buffer; - offset = ((OFF_T) cache->blockN) * nCACHE_BUFFER_BYTEs; -#if EXTEND_FILE - if (offset > vFp->phyLength64) { - if (!ExtendFile(vFp,cache->blockN-1)) return FALSE; - } -#endif - buffer = CACHEbufferREADfrom (cache); - if (buffer == NULL) return FALSE; - if (!vWrite(offset,buffer,nBytes,vFp)) return FALSE; - vFp->phyLength64 = MaxLongLong (vFp->phyLength64, offset + (OFF_T) nBytes); - return TRUE; -} - -/****************************************************************************** -* WriteBlockFromBuffer. -* Write a block out to the file from the caller's buffer. Returns TRUE if -* successful, FALSE if an error occurred. -******************************************************************************/ - -static Logical WriteBlockFromBuffer (vFp, blockN, buffer, nBytes) -vFILE *vFp; -long blockN; -void *buffer; -size_t nBytes; -{ - OFF_T offset = ((OFF_T) blockN) * nCACHE_BUFFER_BYTEs; -#if EXTEND_FILE - if (offset > vFp->phyLength64) { - if (!ExtendFile(vFp,blockN-1)) return FALSE; - } -#endif - if (!vWrite(offset,buffer,nBytes,vFp)) return FALSE; - vFp->phyLength64 = MaxLongLong (vFp->phyLength64, offset + (OFF_T) nBytes); - return TRUE; -} - -/****************************************************************************** -* vRead. -******************************************************************************/ - -static Logical vRead (offset, buffer, nBytes, vFp) -OFF_T offset; -void *buffer; -size_t nBytes; -vFILE *vFp; -{ - int tryN; - /**************************************************************************** - * Does the scratch file exist? It doesn't make sense for it not to. - ****************************************************************************/ -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (vFp->fh == 0) return FALSE; -#else - if (vFp->fp == NULL) return FALSE; -#endif - /**************************************************************************** - * Tally a block read. - ****************************************************************************/ - (vFp->nBlockReads)++; - /**************************************************************************** - * Read the block. Multiple attempts are made for optical disks. - ****************************************************************************/ - for (tryN = 1; tryN <= vMAX_TRYs; tryN++) { -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (FSEEK64(vFp->fh,(OFF_T) offset,vSEEK_SET) == EOF) return FALSE; - if (FREAD64(vFp->fh,buffer,(unsigned int) nBytes) == (int) nBytes) - return TRUE; -#else - if (FSEEK64(vFp->fp,(OFF_T) offset,vSEEK_SET) == EOF) return FALSE; - if (FREAD64(buffer,nBytes,1,vFp->fp) == 1) return TRUE; -#endif - } - return FALSE; -} - -/****************************************************************************** -* vWrite. -******************************************************************************/ - -static Logical vWrite (offset,buffer,nBytes,vFp) -OFF_T offset; -void *buffer; -size_t nBytes; -vFILE *vFp; -{ - int tryN; -#if defined(__MWERKS__) - int ii; -#endif -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - int fh; -#else - FILE *fp; -#endif -#if defined(win32) - char *temp; -#endif -#if defined(unix) - int ret, endian = 1; - long long tmpx; - union { - long long tmpTime; - unsigned int tmp2[2]; - } totmp; - struct timeval nowtime; -#endif - /**************************************************************************** - * Create the scratch file if necessary. If so, the current file path is - * actually the scratch directory to be used. - ****************************************************************************/ -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (vFp->fh == 0) { -#else - if (vFp->fp == NULL) { -#endif - long i; char *tmpPath, *originalPath; size_t pathLength; - pathLength = strlen(vFp->path) + 1 + 8 + 1 + EXT_LEN; - if (pathLength < DU_MAX_DIR_LEN) pathLength = DU_MAX_DIR_LEN; - tmpPath = (char *) cdf_AllocateMemory ((size_t)pathLength + 1, NULL); - if (tmpPath == NULL) return FALSE; - originalPath = (char *) cdf_AllocateMemory ((size_t)pathLength + 1, NULL); - if (originalPath == NULL) return FALSE; - if (pid == -1) { -#if defined(win32) - pid = (int) _getpid(); -#else - pid = (int) getpid(); -#endif -#if defined(unix) - ret = gettimeofday(&nowtime, NULL); - tmpx = (long long) nowtime.tv_sec*1000000LL + (int) nowtime.tv_usec; - tmpx = tmpx % 10000000000000LL; - totmp.tmpTime = (long long) pid * tmpx; - srand((unsigned int)(*(char *)&endian==1)?totmp.tmp2[0]:totmp.tmp2[1]); -#else - srand((unsigned int)pid*time(NULL)); -#endif - } - if (vFp->path != NULL && strlen(vFp->path) != 0) { - strcpyX (tmpPath, vFp->path, 0); - AppendToDir (tmpPath, ""); - } else { - /* Use the known tmp direcotry */ -#if defined(linux) || defined(unix) || defined(__CYGWIN__) || \ - defined(__MINGw32__) - strcpyX (tmpPath, "/tmp/", 0); -#else -# if defined(win32) - temp = getenv("TEMP"); - if (temp != NULL) { - strcpyX (tmpPath, temp, 0); - strcatX (tmpPath, "\\", 0); - } else { - temp = getenv("TMP"); - if (temp != NULL) { - strcpyX (tmpPath, temp, 0); - strcatX (tmpPath, "\\", 0); - } - } -# else -# if defined(vms) - strcpyX (tmpPath, "SYS$SCRATCH:", 0); -# else - strcpyX (tmpPath, vFp->path, 0); -# endif -# endif -#endif - } - strcpyX (originalPath, tmpPath, 0); - for (i = 1; i <= MAX_TMP; i++) { - snprintf (EofS(tmpPath), (size_t) pathLength + 1 - strlen(tmpPath), - "TMP%05ld.%s", (long)(rand()%100000), vFp->scratchExt); - if (!IsReg(tmpPath)) { -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - fh = CDFOpenFile (tmpPath, WRITE_PLUS_a_mode); - if (fh != -1) break; -#else - fp = CDFOpenFile (tmpPath, WRITE_PLUS_a_mode); - if (fp != NULL) break; -#endif - } - strcpyX (tmpPath, originalPath, 0); -/* srand((unsigned int)pid*(time(NULL)+i-1)); */ - } - cdf_FreeMemory (originalPath, NULL); -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (fh == -1) { -#else - if (fp == NULL) { -#endif - cdf_FreeMemory (tmpPath, NULL); - return FALSE; - } else { - cdf_FreeMemory (vFp->path, NULL); - vFp->path = tmpPath; -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - vFp->fh = fh; -#else - vFp->fp = fp; -#endif - } - } - /**************************************************************************** - * Tally a block write. - ****************************************************************************/ - (vFp->nBlockWrites)++; - -#if defined(__MWERKS__) - ii = FSEEK64(vFp->fp, (long)0, vSEEK_END); -#endif - - /**************************************************************************** - * Write the block. Multiple attempts are made for optical disks. - ****************************************************************************/ - for (tryN = 1; tryN <= vMAX_TRYs; tryN++) { -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (FSEEK64(vFp->fh,(OFF_T) offset,vSEEK_SET) == EOF) return FALSE; - if (FWRITE64(vFp->fh,buffer,(unsigned int)nBytes) == (int)nBytes) - return TRUE; -#else - if (FSEEK64(vFp->fp,(OFF_T) offset,vSEEK_SET) == EOF) return FALSE; - if (FWRITE64(buffer,nBytes,1,vFp->fp) == 1) return TRUE; -#endif - } - return FALSE; -} - -/****************************************************************************** -* V_seek64. -* Seek to a position in the file. -******************************************************************************/ - -VISIBLE_PREFIX int V_seek64 (vFp, offset, direction) -vFILE *vFp; /* Pointer to vFILE structure. */ -OFF_T offset; /* New current file offset. */ -int direction; /* Reference for offset. */ -{ - if (vFp == NULL) return EOF; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return EOF; - if (vFp->error) return EOF; - vFp->eof = FALSE; /* Cleared before proceeding. */ - switch (direction) { - case vSEEK_SET: - if (offset < (OFF_T) 0) return EOF; - vFp->offset64 = offset; - break; - case vSEEK_CUR: - if (vFp->offset64 + offset < (OFF_T) 0) return EOF; - vFp->offset64 += (OFF_T) offset; - break; - case vSEEK_END: - vFp->offset64 = vFp->length64; - break; - default: - return EOF; - } - return 0; -} - -/****************************************************************************** -* V_tell64. -* Return current offset (position) in file. This is the byte offset one past -* the last byte that exists. -******************************************************************************/ - -VISIBLE_PREFIX OFF_T V_tell64 (vFp) -vFILE *vFp; /* Pointer to vFILE structure. */ -{ - if (vFp == NULL) return EOF; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return EOF; - if (vFp->error) return EOF; - return vFp->offset64; -} - -/****************************************************************************** -* V_read64. -******************************************************************************/ - -VISIBLE_PREFIX size_t V_read64 (buffer, item_size, n_items, vFp) -void *buffer; /* Pointer to buffer. */ -size_t item_size; /* Size (in bytes) of each item to read. */ -size_t n_items; /* Number of items to read. */ -vFILE *vFp; /* Pointer to vFILE structure. */ -{ - size_t nBytesX; /* Total number of bytes in buffer. */ - size_t nBytes; /* Total number of bytes to read. */ - OFF_T remainingItems;/* Number of items remaining after the offset. */ - size_t nItems; /* Number of items to actually be read. */ - long firstBlockN; /* First block involved in read. */ - long lastBlockN; /* Last block involved in read. */ - int bufferOffset; /* Offset (bytes) into buffer. */ - OFF_T fileOffset; /* Offset (bytes) into file. */ - size_t xBytes; /* Number of bytes in a transfer. */ - long blockN; /* Block number in file (from 0). */ - long atBlockN; /* Block number in file (from 0) at which to read. */ - vCACHE *cache; /* Pointer to cache structure. */ - Byte1 *cBuffer; /* Pointer to cache buffer. */ - int remainingBytes; /* Number of bytes remaining in a block. */ - /**************************************************************************** - * Validate read. - ****************************************************************************/ -#if defined(DEBUG) - if (getenv("READ.ERROR") != NULL) return 0; -#endif - if (vFp == NULL) return 0; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return 0; - if (vFp->error) return 0; - if ((int) item_size <= 0 || (int) n_items <= 0) return 0; - remainingItems = (OFF_T) ((vFp->length64 - vFp->offset64) / - (OFF_T) item_size); - if (remainingItems < 1) { - vFp->eof = TRUE; - vFp->offset64 = vFp->length64; - return 0; - } - if ((long) n_items > remainingItems) { - nItems = (size_t) remainingItems; - vFp->eof = TRUE; /* File offset set to EOF before returning. */ - } - else - nItems = n_items; - nBytes = nItems * item_size; - nBytesX = n_items * item_size; - (vFp->nV_reads)++; - /**************************************************************************** - * Read from first block... - ****************************************************************************/ - firstBlockN = (long) (vFp->offset64 / (OFF_T) nCACHE_BUFFER_BYTEs); - bufferOffset = (int) ((OFF_T) vFp->offset64 % nCACHE_BUFFER_BYTEs); - remainingBytes = nCACHE_BUFFER_BYTEs - bufferOffset; - xBytes = MINIMUM (nBytes, (size_t) remainingBytes); - if (xBytes > nBytesX) return 0; - if (bufferOffset > 0 || xBytes < nCACHE_BUFFER_BYTEs) { - cache = FindCache (vFp, firstBlockN); - if (cache == NULL) cache = PageIn (vFp, firstBlockN); - if (cache == NULL) { - vFp->error = TRUE; - return 0; - } - cBuffer = CACHEbufferREADfrom (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - memmove (buffer, cBuffer + bufferOffset, (size_t) xBytes); - buffer = (Byte1 *) buffer + xBytes; - atBlockN = firstBlockN + 1; - } - else - atBlockN = firstBlockN; - /**************************************************************************** - * Read from remaining blocks... - ****************************************************************************/ - lastBlockN = (long) ((vFp->offset64 + (OFF_T) nBytes - 1) / - (OFF_T) nCACHE_BUFFER_BYTEs); - for (blockN = atBlockN; blockN <= lastBlockN; blockN++) { - xBytes = (size_t) (((OFF_T)vFp->offset64) + (OFF_T) nBytes - - ((OFF_T) blockN) * nCACHE_BUFFER_BYTEs); - xBytes = MINIMUM (xBytes, nCACHE_BUFFER_BYTEs); - if (xBytes > nBytesX) return 0; - cache = FindCache (vFp, blockN); - if (cache != NULL) { - cBuffer = CACHEbufferREADfrom (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - memmove (buffer, cBuffer, (size_t) xBytes); - } - else { - if (xBytes < nCACHE_BUFFER_BYTEs) { - cache = PageIn (vFp, blockN); - if (cache == NULL) { - vFp->error = TRUE; - return 0; - } - cBuffer = CACHEbufferREADfrom (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - memmove (buffer, cBuffer, (size_t) xBytes); - } - else { - fileOffset = ((OFF_T) blockN) * nCACHE_BUFFER_BYTEs; - if (!vRead(fileOffset,buffer,nCACHE_BUFFER_BYTEs,vFp)) { - vFp->error = TRUE; - return 0; - } - } - - } - buffer = (Byte1 *) buffer + xBytes; - } - /**************************************************************************** - * Increment current file offset or set to EOF if the EOF indicator was set. - ****************************************************************************/ - vFp->offset64 = BOO(vFp->eof,vFp->length64,vFp->offset64 + (OFF_T)nBytes); - return nItems; -} - -/****************************************************************************** -* V_write64. -******************************************************************************/ - -VISIBLE_PREFIX size_t V_write64 (buffer, item_size, n_items, vFp) -void *buffer; /* Pointer to buffer. */ -size_t item_size; /* Size (in bytes) of each item to write. */ -size_t n_items; /* Number of items to write. */ -vFILE *vFp; /* Pointer to vFILE structure. */ -{ - size_t nBytesX; /* Total number of bytes in buffer. */ - size_t nBytes; /* Total number of bytes in write. */ - long firstBlockN; /* First block involved in write. */ - long lastBlockN; /* Last block involved in write. */ - int bufferOffset; /* Offset (bytes) into buffer. */ - long blockN; /* Block number in file (from 0). */ - long atBlockN; /* Block number in file (from 0) at which to write. */ - size_t xBytes; /* Number of bytes in a transfer. */ - vCACHE *cache; /* Pointer to cache structure. */ - Byte1 *cBuffer; /* Pointer to cache buffer. */ - size_t nBytesInBlock; /* Number of bytes to the end of the block. */ - /**************************************************************************** - * Validate write. - ****************************************************************************/ -#if defined(DEBUG) - if (getenv("WRITE.ERROR") != NULL) return 0; -#endif - if (vFp == NULL) return 0; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return 0; - if (vFp->error) return 0; - if ((int) item_size <= 0 || (int) n_items <= 0) return 0; - vFp->eof = FALSE; /* Cleared before proceeding. */ - nBytes = item_size * n_items; - nBytesX = nBytes; - if (nBytes < 1) return 0; - (vFp->nV_writes)++; - /**************************************************************************** - * Write to first block... - * Note that if this is a scratch file, the first block is always placed in - * the cache (even if a full block). - ****************************************************************************/ - firstBlockN = (long) (vFp->offset64 / (OFF_T) nCACHE_BUFFER_BYTEs); - bufferOffset = (int) ((OFF_T) vFp->offset64 % nCACHE_BUFFER_BYTEs); - nBytesInBlock = nCACHE_BUFFER_BYTEs - bufferOffset; - xBytes = MINIMUM (nBytes, nBytesInBlock); - if (xBytes > nBytesX) return 0; - if (vFp->scratch || bufferOffset > 0 || xBytes < nCACHE_BUFFER_BYTEs) { - cache = FindCache (vFp, firstBlockN); - if (cache == NULL) { - if (firstBlockN <= LASTphyBLOCKn(vFp)) { - cache = PageIn (vFp, firstBlockN); - if (cache == NULL) { - vFp->error = TRUE; - return 0; - } - } - else { - cache = AllocateBuffer (vFp); - if (cache == NULL) { - vFp->error = TRUE; - return 0; - } - cache->blockN = firstBlockN; -#if CLEAR_BYTES - cBuffer = CACHEbufferWRITEto (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - ClearBytes (cBuffer, 0, bufferOffset - 1); - ClearBytes (cBuffer, (int) (bufferOffset + xBytes), - nCACHE_BUFFER_BYTEs - 1); -#endif - } - } - cBuffer = CACHEbufferWRITEto (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - memmove (cBuffer + bufferOffset, buffer, (size_t) xBytes); - cache->modified = TRUE; - vFp->length64 = MaxLongLong (vFp->length64, vFp->offset64 + - (OFF_T) xBytes); - buffer = (Byte1 *) buffer + xBytes; - atBlockN = firstBlockN + 1; - } - else - atBlockN = firstBlockN; - /**************************************************************************** - * Write to remaining blocks... - ****************************************************************************/ - lastBlockN = (long) ((vFp->offset64 + (OFF_T) nBytes - 1) / - (OFF_T) nCACHE_BUFFER_BYTEs); - for (blockN = atBlockN; blockN <= lastBlockN; blockN++) { - xBytes = (size_t) (((OFF_T)vFp->offset64) + (OFF_T) nBytes - - ((OFF_T) blockN) * nCACHE_BUFFER_BYTEs); - xBytes = MINIMUM (xBytes, nCACHE_BUFFER_BYTEs); - if (xBytes > nBytesX) return 0; - /************************************************************************* - * Is this block in the cache? If so, move the number of bytes to be - * written at this block to its cache buffer. - *************************************************************************/ - cache = FindCache (vFp, blockN); - if (cache != NULL) { - cBuffer = CACHEbufferWRITEto (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - memmove (cBuffer, buffer, (size_t) xBytes); - cache->modified = TRUE; - } - else { - /*********************************************************************** - * This block is not in the cache. Is a partial block to be written? - * Note that if this is a scratch file, the block is always placed in - * the cache (even if not a partial block). - ***********************************************************************/ - if (vFp->scratch || xBytes < nCACHE_BUFFER_BYTEs) { - if (blockN <= LASTphyBLOCKn(vFp)) { - cache = PageIn (vFp, blockN); - if (cache == NULL) { - vFp->error = TRUE; - return 0; - } - } - else { - cache = AllocateBuffer (vFp); - if (cache == NULL) { - vFp->error = TRUE; - return 0; - } - cache->blockN = blockN; -#if CLEAR_BYTES - cBuffer = CACHEbufferWRITEto (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - ClearBytes (cBuffer, (int) xBytes, nCACHE_BUFFER_BYTEs - 1); -#endif - } - cBuffer = CACHEbufferWRITEto (cache); - if (cBuffer == NULL) { - vFp->error = TRUE; - return 0; - } - memmove (cBuffer, buffer, (size_t) xBytes); - cache->modified = TRUE; - } - else { - /********************************************************************* - * A full block is to be written. - *********************************************************************/ - if (!WriteBlockFromBuffer(vFp,blockN,buffer,nCACHE_BUFFER_BYTEs)) { - vFp->error = TRUE; - return 0; - } - } - } - vFp->length64 = MaxLongLong (vFp->length64, ((OFF_T) blockN) * - nCACHE_BUFFER_BYTEs + (OFF_T) xBytes); - buffer = (Byte1 *) buffer + xBytes; - } - /**************************************************************************** - * Increment current file offset. - ****************************************************************************/ - vFp->offset64 += (OFF_T) nBytes; - return n_items; -} - -/****************************************************************************** -* V_open64. -* Open the file and setup vFILE structure. -******************************************************************************/ - -VISIBLE_PREFIX vFILE *V_open64 (file_spec, a_mode) -char *file_spec; /* File specification. */ -char *a_mode; /* Access mode. */ -{ -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - int fp; -#else - FILE *fp; /* Temporary file pointer. */ -#endif - vFILE *vFp; /* Pointer to vFILE structure. */ -#if defined(vms) - struct STAT st; /* Status block from `stat'. */ -#endif - /**************************************************************************** - * Open the file. - ****************************************************************************/ - fp = CDFOpenFile (file_spec, a_mode); -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (fp == -1) return NULL; -#else - if (fp == NULL) return NULL; -#endif -#if defined(vms) - /**************************************************************************** - * If the file is being opened in a mode which may require it to be extended - * (`r+' [read/write] or `a/a+' [append]), check that the EOF offset in the - * last block is zero (0). If not, rewrite the last block out to the end. - * `r' is not checked because it is read only. - * `w/w+' is not checked because a new file (with EOF == 0) will have been - * created. - ****************************************************************************/ - if (strstr(a_mode,"r+") || strchr(a_mode,'a')) { - OFF_T eof, EOFoffsetInBlock; - if (FSEEK64(fp,0,vSEEK_END) == EOF) { - FCLOSE64 (fp); - return NULL; - } - eof = FTELL64 (fp); - if (eof == EOF) { - FCLOSE64 (fp); - return NULL; - } - EOFoffsetInBlock = eof % nCACHE_BUFFER_BYTEs; - if (EOFoffsetInBlock != 0) { - OFF_T offsetToLastBlock; char buffer[nCACHE_BUFFER_BYTEs]; int i; - offsetToLastBlock = (OFF_T) nCACHE_BUFFER_BYTEs * - (eof / nCACHE_BUFFER_BYTEs); - if (FSEEK64(fp,offsetToLastBlock,vSEEK_SET) == EOF) { - FCLOSE64 (fp); - return NULL; - } - /* for (i = 0; i < nCACHE_BUFFER_BYTEs; i++) buffer[i] = 0; */ - memset (buffer, 0, (size_t) nCACHE_BUFFER_BYTEs); - if (FREAD64(buffer,EOFoffsetInBlock,1,fp) != 1) { - FCLOSE64 (fp); - return NULL; - } - if (FSEEK64(fp,offsetToLastBlock,vSEEK_SET) == EOF) { - FCLOSE64 (fp); - return NULL; - } - if (FWRITE64(buffer,nCACHE_BUFFER_BYTEs,1,fp) != 1) { - FCLOSE64 (fp); - return NULL; - } - if (FCLOSE64(fp) == EOF) { - FCLOSE64 (fp); - return NULL; - } - fp = CDFOpenFile (file_spec, a_mode); - if (fp == NULL) return NULL; - } - } -#endif - /**************************************************************************** - * Allocate and load vFILE structure. - ****************************************************************************/ - vFp = (vFILE *) cdf_AllocateMemory ((size_t)sizeof(vFILE), NULL); - if (vFp == NULL) { - FCLOSE64 (fp); - return NULL; - } - vFp->magic_number = VSTREAM_MAGIC_NUMBER; -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - vFp->fh = fp; -#else - vFp->fp = fp; -#endif - vFp->path = (char *) cdf_AllocateMemory ((size_t)strlen(file_spec) + 1, NULL); - if (vFp->path == NULL) { - cdf_FreeMemory (vFp, NULL); - FCLOSE64 (fp); - return NULL; - } - else - strcpyX (vFp->path, file_spec, 0); - vFp->scratch = FALSE; - vFp->error = FALSE; - vFp->eof = FALSE; - vFp->cacheHead = NULL; - vFp->cacheTail = NULL; - vFp->maxBuffers = DEFAULT_nCACHE_BUFFERs; - vFp->nBuffers = 0; - vFp->nBlockReads = 0; - vFp->nBlockWrites = 0; - vFp->nV_reads = 0; - vFp->nV_writes = 0; - vFp->nPageIns = 0; - vFp->nPageOuts = 0; - vFp->GDR = NULL; - vFp->GDR64 = NULL; - vFp->ADRList = NULL; - vFp->ADRList64 = NULL; - /**************************************************************************** - * Determine length of file and set current offset. - ****************************************************************************/ -#if defined(vms) - /**************************************************************************** - * This method is used on VMS systems in case the file is on a CD-ROM. Some - * VMS CD-ROM drivers do not correctly handle the EOF marker of a file. - * `stat' might fail, however, if the file specification contains a DECnet - * node. If `stat' fails, try the other method before giving up. - ****************************************************************************/ - if (stat(file_spec,&st) == 0) { - vFp->length64 = st.st_size; - vFp->phyLength64 = st.st_size; - } - else { -#endif - /************************************************************************** - * Check for LFS based on its current size and magic numbers. - **************************************************************************/ -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (FSEEK64(vFp->fh,(OFF_T)0,vSEEK_END) == EOF) { -#else - if (FSEEK64(vFp->fp,(OFF_T)0,vSEEK_END) == EOF) { -#endif - cdf_FreeMemory (vFp->path, NULL); - cdf_FreeMemory (vFp, NULL); -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - FCLOSE64 (vFp->fh); -#else - FCLOSE64 (vFp->fp); -#endif - return NULL; - } -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - vFp->length64 = FTELL64(vFp->fh); -#else - vFp->length64 = FTELL64(vFp->fp); -#endif - if (vFp->length64 == (OFF_T) -1) { - cdf_FreeMemory (vFp->path, NULL); - cdf_FreeMemory (vFp, NULL); -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - FCLOSE64 (vFp->fh); -#else - FCLOSE64 (vFp->fp); -#endif - return NULL; - } - vFp->phyLength64 = vFp->length64; - vFp->length = vFp->phyLength = 0; -#if defined(vms) - } -#endif - vFp->offset = BOO(strchr(a_mode,'a') == NULL,0,vFp->length); - vFp->offset64 = BOO(strchr(a_mode,'a') == NULL,(OFF_T) 0,vFp->length64); - /**************************************************************************** - * Return pointer to vFILE structure. - ****************************************************************************/ - return vFp; -} - -/****************************************************************************** -* V_setcache64. -* Set number of cache buffers. This can be done at any time after the file -* is opened. Note that in some cases the new cache size may be the same as -* the old cache size (do nothing). -******************************************************************************/ - -VISIBLE_PREFIX int V_setcache64 (vFp, maxBuffers) -vFILE *vFp; /* Pointer to vFILE structure. */ -int maxBuffers; /* New maximum number of cache buffers. */ -{ - if (vFp == NULL) return EOF; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return EOF; - if (vFp->error) return EOF; - if (maxBuffers < 1) return EOF; - if (maxBuffers > vFp->maxBuffers) { - /************************************************************************** - * The number of cache buffers is increasing. - **************************************************************************/ - vFp->maxBuffers = maxBuffers; - } - else { - if (maxBuffers < vFp->maxBuffers) { - /************************************************************************ - * The number of cache buffers is decreasing - flush to disk and free - * the buffers which are going away. - ************************************************************************/ - vCACHE *cache; int count; - if (vFp->nBuffers > maxBuffers) { - for (count = 1, - cache = vFp->cacheHead; - count < maxBuffers; count++) cache = cache->next; - if (!FlushCache64(vFp,cache->next)) { - vFp->error = TRUE; - return EOF; - } - FreeCache (cache->next); - cache->next = NULL; - vFp->cacheTail = cache; - vFp->nBuffers = maxBuffers; - } - vFp->maxBuffers = maxBuffers; - } - } - return 0; -} - -/****************************************************************************** -* V_flush64. -* Flush the file to disk. -******************************************************************************/ - -VISIBLE_PREFIX int V_flush64 (vFp) -vFILE *vFp; /* Pointer to vFILE structure. */ -{ - /**************************************************************************** - * Validate. - ****************************************************************************/ - if (vFp == NULL) return EOF; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return EOF; - if (vFp->error) return EOF; - /**************************************************************************** - * Flush cache buffers. If this is a scratch file, this will cause the file - * to be created if it hasn't been already (unless nothing has been written). - ****************************************************************************/ - if (!FlushCache64(vFp,vFp->cacheHead)) { - vFp->error = TRUE; - return EOF; - } - /**************************************************************************** - * Flush file. Note that the file will not be flushed if this is a scratch - * file to which nothing has been written. - ****************************************************************************/ -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (vFp->fh != 0) { - if (FLUSH64(vFp->fh) == EOF) { - vFp->error = TRUE; - return EOF; - } - } -#else - if (vFp->fp != NULL) { - if (FLUSH64(vFp->fp) == EOF) { - vFp->error = TRUE; - return EOF; - } - } -#endif - /**************************************************************************** - * Return success. - ****************************************************************************/ - return 0; -} - -/****************************************************************************** -* V_close64. -* Returns EOF if an error occurred. -******************************************************************************/ - -VISIBLE_PREFIX int V_close64 (vFp, CDF, vStats) -vFILE *vFp; /* Pointer to vFILE structure. */ -struct CDFstruct *CDF; /* Check sum operation indicator if non-NULL. */ -vSTATS *vStats; /* Pointer to statistics structure. */ -{ - Logical error = FALSE; /* Has an error occurred? */ - /**************************************************************************** - * Check if a valid pointer to a vFILE structure. - ****************************************************************************/ - if (vFp == NULL) return EOF; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return EOF; - /**************************************************************************** - * Write cache buffers. If this is a scratch file, this will cause the file - * to be created if it hasn't been already (unless nothing has been written). - ****************************************************************************/ - if (!FlushCache64(vFp,vFp->cacheHead)) error = TRUE; - /**************************************************************************** - * Close the file. Note that the file will not be closed if this is a - * scratch file to which nothing has been written. - ****************************************************************************/ -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (vFp->fh != 0) { - if (CDF != NULL && (!CDF->readOnly || CDF->status == READ_WRITE) && - CDF->singleFile && (CDF->checksum != NONE_CHECKSUM)) { -/* if (!FLUSHv64(vFp)) error = TRUE; */ - if (!CDFAddChecksum(CDF)) error = TRUE; - } - if (FCLOSE64 (vFp->fh) == EOF) error = TRUE; - } -#else - if (vFp->fp != NULL) { - if (CDF != NULL && (!CDF->readOnly || CDF->status == READ_WRITE) && - CDF->singleFile && (CDF->checksum != NONE_CHECKSUM)) { -/* if (!FLUSHv64(vFp)) error = TRUE; */ - if (!CDFAddChecksum(CDF)) error = TRUE; - } - if (FCLOSE64 (vFp->fp) == EOF) error = TRUE; - } -#endif - /**************************************************************************** - * Pass back statistics (if requested). - ****************************************************************************/ - if (vStats != NULL) { - vStats->maxBuffers = vFp->maxBuffers; - vStats->nBuffers = vFp->nBuffers; - vStats->nV_reads = vFp->nV_reads; - vStats->nV_writes = vFp->nV_writes; - vStats->nBlockReads = vFp->nBlockReads; - vStats->nBlockWrites = vFp->nBlockWrites; - vStats->nPageIns = vFp->nPageIns; - vStats->nPageOuts = vFp->nPageOuts; - } - /**************************************************************************** - * Deallocate cache and vFILE structure. - ****************************************************************************/ - FreeCache (vFp->cacheHead); - cdf_FreeMemory (vFp->path, NULL); - cdf_FreeMemory (vFp, NULL); - /**************************************************************************** - * Return status. - ****************************************************************************/ - return BOO(error,EOF,0); -} - -/****************************************************************************** -* V_getc64. -******************************************************************************/ - -VISIBLE_PREFIX int V_getc64 (fp) -vFILE *fp; -{ - uByte tmp; - if (V_read64(&tmp,1,1,fp) != 1) return EOF; - return ((int) tmp); -} - -/****************************************************************************** -* V_putc64. -******************************************************************************/ - -VISIBLE_PREFIX int V_putc64 (value, fp) -int value; -vFILE *fp; -{ - uByte tmp = (uByte) value; - if (V_write64(&tmp,1,1,fp) != 1) return EOF; - return value; -} - -/****************************************************************************** -* V_delete64. -* Returns EOF if an error occurred. -******************************************************************************/ - -VISIBLE_PREFIX int V_delete64 (vFp, vStats) -vFILE *vFp; /* Pointer to vFILE structure. */ -vSTATS *vStats; /* Pointer to statistics structure. */ -{ - Logical error = FALSE; /* Has an error occurred? */ - /**************************************************************************** - * Check if a valid pointer to a vFILE structure. - ****************************************************************************/ - if (vFp == NULL) return EOF; - if (vFp->magic_number != VSTREAM_MAGIC_NUMBER) return EOF; - /**************************************************************************** - * Close the file. - ****************************************************************************/ -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (vFp->fh != 0) { - if (FCLOSE64(vFp->fh) == EOF) error = TRUE; - } -#else - if (vFp->fp != NULL) { - if (FCLOSE64(vFp->fp) == EOF) error = TRUE; - } -#endif - /**************************************************************************** - * Delete the file (unless it was never created). - ****************************************************************************/ -#if defined(win32) && (_FILE_OFFSET_BITS == 64) - if (vFp->fh != 0) { -#else - if (vFp->fp != NULL) { -#endif - if (!CDFdeleteFile(vFp->path)) error = TRUE; - } - /**************************************************************************** - * Pass back statistics (if requested). - ****************************************************************************/ - if (vStats != NULL) { - vStats->maxBuffers = vFp->maxBuffers; - vStats->nBuffers = vFp->nBuffers; - vStats->nV_reads = vFp->nV_reads; - vStats->nV_writes = vFp->nV_writes; - vStats->nBlockReads = vFp->nBlockReads; - vStats->nBlockWrites = vFp->nBlockWrites; - vStats->nPageIns = vFp->nPageIns; - vStats->nPageOuts = vFp->nPageOuts; - } - /**************************************************************************** - * Deallocate cache and vFILE structure. - ****************************************************************************/ - FreeCache (vFp->cacheHead); - cdf_FreeMemory (vFp->path, NULL); - cdf_FreeMemory (vFp, NULL); - /**************************************************************************** - * Return status. - ****************************************************************************/ - return BOO(error,EOF,0); -} - - -/****************************************************************************** -* GetMyPID. -* Returns the PID of the session. If -1 then it is not set. -******************************************************************************/ - -VISIBLE_PREFIX int GetMyPID () -{ - return pid; -} - -/****************************************************************************** -* SetMyPID. -* Sets the PID of the session. -******************************************************************************/ - -VISIBLE_PREFIX void SetMyPID (int npid) -{ - pid = npid; -} - diff --git a/cdf36_3-dist/src/lib/zlib/ACKNOWLEDGMENT.txt b/cdf36_3-dist/src/lib/zlib/ACKNOWLEDGMENT.txt deleted file mode 100644 index 097f82b..0000000 --- a/cdf36_3-dist/src/lib/zlib/ACKNOWLEDGMENT.txt +++ /dev/null @@ -1,7 +0,0 @@ -This directory contains some of the compression/decompression codes from zlib, -(@zlib.net) of version 1.2.8, written by Jean-loup Gailly and Mark Adler. -Only the .c and .h source codes are included from the package without any -change to support the gzip functionality provided in the CDF. - -Refer to zlib.h for its copyright notice. - diff --git a/cdf36_3-dist/src/lib/zlib/ChangeLog b/cdf36_3-dist/src/lib/zlib/ChangeLog deleted file mode 100644 index 1e17a5a..0000000 --- a/cdf36_3-dist/src/lib/zlib/ChangeLog +++ /dev/null @@ -1,1472 +0,0 @@ - - ChangeLog file for zlib - -Changes in 1.2.8 (28 Apr 2013) -- Update contrib/minizip/iowin32.c for Windows RT [Vollant] -- Do not force Z_CONST for C++ -- Clean up contrib/vstudio [Ro§] -- Correct spelling error in zlib.h -- Fix mixed line endings in contrib/vstudio - -Changes in 1.2.7.3 (13 Apr 2013) -- Fix version numbers and DLL names in contrib/vstudio/*/zlib.rc - -Changes in 1.2.7.2 (13 Apr 2013) -- Change check for a four-byte type back to hexadecimal -- Fix typo in win32/Makefile.msc -- Add casts in gzwrite.c for pointer differences - -Changes in 1.2.7.1 (24 Mar 2013) -- Replace use of unsafe string functions with snprintf if available -- Avoid including stddef.h on Windows for Z_SOLO compile [Niessink] -- Fix gzgetc undefine when Z_PREFIX set [Turk] -- Eliminate use of mktemp in Makefile (not always available) -- Fix bug in 'F' mode for gzopen() -- Add inflateGetDictionary() function -- Correct comment in deflate.h -- Use _snprintf for snprintf in Microsoft C -- On Darwin, only use /usr/bin/libtool if libtool is not Apple -- Delete "--version" file if created by "ar --version" [Richard G.] -- Fix configure check for veracity of compiler error return codes -- Fix CMake compilation of static lib for MSVC2010 x64 -- Remove unused variable in infback9.c -- Fix argument checks in gzlog_compress() and gzlog_write() -- Clean up the usage of z_const and respect const usage within zlib -- Clean up examples/gzlog.[ch] comparisons of different types -- Avoid shift equal to bits in type (caused endless loop) -- Fix unintialized value bug in gzputc() introduced by const patches -- Fix memory allocation error in examples/zran.c [Nor] -- Fix bug where gzopen(), gzclose() would write an empty file -- Fix bug in gzclose() when gzwrite() runs out of memory -- Check for input buffer malloc failure in examples/gzappend.c -- Add note to contrib/blast to use binary mode in stdio -- Fix comparisons of differently signed integers in contrib/blast -- Check for invalid code length codes in contrib/puff -- Fix serious but very rare decompression bug in inftrees.c -- Update inflateBack() comments, since inflate() can be faster -- Use underscored I/O function names for WINAPI_FAMILY -- Add _tr_flush_bits to the external symbols prefixed by --zprefix -- Add contrib/vstudio/vc10 pre-build step for static only -- Quote --version-script argument in CMakeLists.txt -- Don't specify --version-script on Apple platforms in CMakeLists.txt -- Fix casting error in contrib/testzlib/testzlib.c -- Fix types in contrib/minizip to match result of get_crc_table() -- Simplify contrib/vstudio/vc10 with 'd' suffix -- Add TOP support to win32/Makefile.msc -- Suport i686 and amd64 assembler builds in CMakeLists.txt -- Fix typos in the use of _LARGEFILE64_SOURCE in zconf.h -- Add vc11 and vc12 build files to contrib/vstudio -- Add gzvprintf() as an undocumented function in zlib -- Fix configure for Sun shell -- Remove runtime check in configure for four-byte integer type -- Add casts and consts to ease user conversion to C++ -- Add man pages for minizip and miniunzip -- In Makefile uninstall, don't rm if preceding cd fails -- Do not return Z_BUF_ERROR if deflateParam() has nothing to write - -Changes in 1.2.7 (2 May 2012) -- Replace use of memmove() with a simple copy for portability -- Test for existence of strerror -- Restore gzgetc_ for backward compatibility with 1.2.6 -- Fix build with non-GNU make on Solaris -- Require gcc 4.0 or later on Mac OS X to use the hidden attribute -- Include unistd.h for Watcom C -- Use __WATCOMC__ instead of __WATCOM__ -- Do not use the visibility attribute if NO_VIZ defined -- Improve the detection of no hidden visibility attribute -- Avoid using __int64 for gcc or solo compilation -- Cast to char * in gzprintf to avoid warnings [Zinser] -- Fix make_vms.com for VAX [Zinser] -- Don't use library or built-in byte swaps -- Simplify test and use of gcc hidden attribute -- Fix bug in gzclose_w() when gzwrite() fails to allocate memory -- Add "x" (O_EXCL) and "e" (O_CLOEXEC) modes support to gzopen() -- Fix bug in test/minigzip.c for configure --solo -- Fix contrib/vstudio project link errors [Mohanathas] -- Add ability to choose the builder in make_vms.com [Schweda] -- Add DESTDIR support to mingw32 win32/Makefile.gcc -- Fix comments in win32/Makefile.gcc for proper usage -- Allow overriding the default install locations for cmake -- Generate and install the pkg-config file with cmake -- Build both a static and a shared version of zlib with cmake -- Include version symbols for cmake builds -- If using cmake with MSVC, add the source directory to the includes -- Remove unneeded EXTRA_CFLAGS from win32/Makefile.gcc [Truta] -- Move obsolete emx makefile to old [Truta] -- Allow the use of -Wundef when compiling or using zlib -- Avoid the use of the -u option with mktemp -- Improve inflate() documentation on the use of Z_FINISH -- Recognize clang as gcc -- Add gzopen_w() in Windows for wide character path names -- Rename zconf.h in CMakeLists.txt to move it out of the way -- Add source directory in CMakeLists.txt for building examples -- Look in build directory for zlib.pc in CMakeLists.txt -- Remove gzflags from zlibvc.def in vc9 and vc10 -- Fix contrib/minizip compilation in the MinGW environment -- Update ./configure for Solaris, support --64 [Mooney] -- Remove -R. from Solaris shared build (possible security issue) -- Avoid race condition for parallel make (-j) running example -- Fix type mismatch between get_crc_table() and crc_table -- Fix parsing of version with "-" in CMakeLists.txt [Snider, Ziegler] -- Fix the path to zlib.map in CMakeLists.txt -- Force the native libtool in Mac OS X to avoid GNU libtool [Beebe] -- Add instructions to win32/Makefile.gcc for shared install [Torri] - -Changes in 1.2.6.1 (12 Feb 2012) -- Avoid the use of the Objective-C reserved name "id" -- Include io.h in gzguts.h for Microsoft compilers -- Fix problem with ./configure --prefix and gzgetc macro -- Include gz_header definition when compiling zlib solo -- Put gzflags() functionality back in zutil.c -- Avoid library header include in crc32.c for Z_SOLO -- Use name in GCC_CLASSIC as C compiler for coverage testing, if set -- Minor cleanup in contrib/minizip/zip.c [Vollant] -- Update make_vms.com [Zinser] -- Remove unnecessary gzgetc_ function -- Use optimized byte swap operations for Microsoft and GNU [Snyder] -- Fix minor typo in zlib.h comments [Rzesniowiecki] - -Changes in 1.2.6 (29 Jan 2012) -- Update the Pascal interface in contrib/pascal -- Fix function numbers for gzgetc_ in zlibvc.def files -- Fix configure.ac for contrib/minizip [Schiffer] -- Fix large-entry detection in minizip on 64-bit systems [Schiffer] -- Have ./configure use the compiler return code for error indication -- Fix CMakeLists.txt for cross compilation [McClure] -- Fix contrib/minizip/zip.c for 64-bit architectures [Dalsnes] -- Fix compilation of contrib/minizip on FreeBSD [Marquez] -- Correct suggested usages in win32/Makefile.msc [Shachar, Horvath] -- Include io.h for Turbo C / Borland C on all platforms [Truta] -- Make version explicit in contrib/minizip/configure.ac [Bosmans] -- Avoid warning for no encryption in contrib/minizip/zip.c [Vollant] -- Minor cleanup up contrib/minizip/unzip.c [Vollant] -- Fix bug when compiling minizip with C++ [Vollant] -- Protect for long name and extra fields in contrib/minizip [Vollant] -- Avoid some warnings in contrib/minizip [Vollant] -- Add -I../.. -L../.. to CFLAGS for minizip and miniunzip -- Add missing libs to minizip linker command -- Add support for VPATH builds in contrib/minizip -- Add an --enable-demos option to contrib/minizip/configure -- Add the generation of configure.log by ./configure -- Exit when required parameters not provided to win32/Makefile.gcc -- Have gzputc return the character written instead of the argument -- Use the -m option on ldconfig for BSD systems [Tobias] -- Correct in zlib.map when deflateResetKeep was added - -Changes in 1.2.5.3 (15 Jan 2012) -- Restore gzgetc function for binary compatibility -- Do not use _lseeki64 under Borland C++ [Truta] -- Update win32/Makefile.msc to build test/*.c [Truta] -- Remove old/visualc6 given CMakefile and other alternatives -- Update AS400 build files and documentation [Monnerat] -- Update win32/Makefile.gcc to build test/*.c [Truta] -- Permit stronger flushes after Z_BLOCK flushes -- Avoid extraneous empty blocks when doing empty flushes -- Permit Z_NULL arguments to deflatePending -- Allow deflatePrime() to insert bits in the middle of a stream -- Remove second empty static block for Z_PARTIAL_FLUSH -- Write out all of the available bits when using Z_BLOCK -- Insert the first two strings in the hash table after a flush - -Changes in 1.2.5.2 (17 Dec 2011) -- fix ld error: unable to find version dependency 'ZLIB_1.2.5' -- use relative symlinks for shared libs -- Avoid searching past window for Z_RLE strategy -- Assure that high-water mark initialization is always applied in deflate -- Add assertions to fill_window() in deflate.c to match comments -- Update python link in README -- Correct spelling error in gzread.c -- Fix bug in gzgets() for a concatenated empty gzip stream -- Correct error in comment for gz_make() -- Change gzread() and related to ignore junk after gzip streams -- Allow gzread() and related to continue after gzclearerr() -- Allow gzrewind() and gzseek() after a premature end-of-file -- Simplify gzseek() now that raw after gzip is ignored -- Change gzgetc() to a macro for speed (~40% speedup in testing) -- Fix gzclose() to return the actual error last encountered -- Always add large file support for windows -- Include zconf.h for windows large file support -- Include zconf.h.cmakein for windows large file support -- Update zconf.h.cmakein on make distclean -- Merge vestigial vsnprintf determination from zutil.h to gzguts.h -- Clarify how gzopen() appends in zlib.h comments -- Correct documentation of gzdirect() since junk at end now ignored -- Add a transparent write mode to gzopen() when 'T' is in the mode -- Update python link in zlib man page -- Get inffixed.h and MAKEFIXED result to match -- Add a ./config --solo option to make zlib subset with no libary use -- Add undocumented inflateResetKeep() function for CAB file decoding -- Add --cover option to ./configure for gcc coverage testing -- Add #define ZLIB_CONST option to use const in the z_stream interface -- Add comment to gzdopen() in zlib.h to use dup() when using fileno() -- Note behavior of uncompress() to provide as much data as it can -- Add files in contrib/minizip to aid in building libminizip -- Split off AR options in Makefile.in and configure -- Change ON macro to Z_ARG to avoid application conflicts -- Facilitate compilation with Borland C++ for pragmas and vsnprintf -- Include io.h for Turbo C / Borland C++ -- Move example.c and minigzip.c to test/ -- Simplify incomplete code table filling in inflate_table() -- Remove code from inflate.c and infback.c that is impossible to execute -- Test the inflate code with full coverage -- Allow deflateSetDictionary, inflateSetDictionary at any time (in raw) -- Add deflateResetKeep and fix inflateResetKeep to retain dictionary -- Fix gzwrite.c to accommodate reduced memory zlib compilation -- Have inflate() with Z_FINISH avoid the allocation of a window -- Do not set strm->adler when doing raw inflate -- Fix gzeof() to behave just like feof() when read is not past end of file -- Fix bug in gzread.c when end-of-file is reached -- Avoid use of Z_BUF_ERROR in gz* functions except for premature EOF -- Document gzread() capability to read concurrently written files -- Remove hard-coding of resource compiler in CMakeLists.txt [Blammo] - -Changes in 1.2.5.1 (10 Sep 2011) -- Update FAQ entry on shared builds (#13) -- Avoid symbolic argument to chmod in Makefile.in -- Fix bug and add consts in contrib/puff [Oberhumer] -- Update contrib/puff/zeros.raw test file to have all block types -- Add full coverage test for puff in contrib/puff/Makefile -- Fix static-only-build install in Makefile.in -- Fix bug in unzGetCurrentFileInfo() in contrib/minizip [Kuno] -- Add libz.a dependency to shared in Makefile.in for parallel builds -- Spell out "number" (instead of "nb") in zlib.h for total_in, total_out -- Replace $(...) with `...` in configure for non-bash sh [Bowler] -- Add darwin* to Darwin* and solaris* to SunOS\ 5* in configure [Groffen] -- Add solaris* to Linux* in configure to allow gcc use [Groffen] -- Add *bsd* to Linux* case in configure [Bar-Lev] -- Add inffast.obj to dependencies in win32/Makefile.msc -- Correct spelling error in deflate.h [Kohler] -- Change libzdll.a again to libz.dll.a (!) in win32/Makefile.gcc -- Add test to configure for GNU C looking for gcc in output of $cc -v -- Add zlib.pc generation to win32/Makefile.gcc [Weigelt] -- Fix bug in zlib.h for _FILE_OFFSET_BITS set and _LARGEFILE64_SOURCE not -- Add comment in zlib.h that adler32_combine with len2 < 0 makes no sense -- Make NO_DIVIDE option in adler32.c much faster (thanks to John Reiser) -- Make stronger test in zconf.h to include unistd.h for LFS -- Apply Darwin patches for 64-bit file offsets to contrib/minizip [Slack] -- Fix zlib.h LFS support when Z_PREFIX used -- Add updated as400 support (removed from old) [Monnerat] -- Avoid deflate sensitivity to volatile input data -- Avoid division in adler32_combine for NO_DIVIDE -- Clarify the use of Z_FINISH with deflateBound() amount of space -- Set binary for output file in puff.c -- Use u4 type for crc_table to avoid conversion warnings -- Apply casts in zlib.h to avoid conversion warnings -- Add OF to prototypes for adler32_combine_ and crc32_combine_ [Miller] -- Improve inflateSync() documentation to note indeterminancy -- Add deflatePending() function to return the amount of pending output -- Correct the spelling of "specification" in FAQ [Randers-Pehrson] -- Add a check in configure for stdarg.h, use for gzprintf() -- Check that pointers fit in ints when gzprint() compiled old style -- Add dummy name before $(SHAREDLIBV) in Makefile [Bar-Lev, Bowler] -- Delete line in configure that adds -L. libz.a to LDFLAGS [Weigelt] -- Add debug records in assmebler code [Londer] -- Update RFC references to use http://tools.ietf.org/html/... [Li] -- Add --archs option, use of libtool to configure for Mac OS X [Borstel] - -Changes in 1.2.5 (19 Apr 2010) -- Disable visibility attribute in win32/Makefile.gcc [Bar-Lev] -- Default to libdir as sharedlibdir in configure [Nieder] -- Update copyright dates on modified source files -- Update trees.c to be able to generate modified trees.h -- Exit configure for MinGW, suggesting win32/Makefile.gcc -- Check for NULL path in gz_open [Homurlu] - -Changes in 1.2.4.5 (18 Apr 2010) -- Set sharedlibdir in configure [Torok] -- Set LDFLAGS in Makefile.in [Bar-Lev] -- Avoid mkdir objs race condition in Makefile.in [Bowler] -- Add ZLIB_INTERNAL in front of internal inter-module functions and arrays -- Define ZLIB_INTERNAL to hide internal functions and arrays for GNU C -- Don't use hidden attribute when it is a warning generator (e.g. Solaris) - -Changes in 1.2.4.4 (18 Apr 2010) -- Fix CROSS_PREFIX executable testing, CHOST extract, mingw* [Torok] -- Undefine _LARGEFILE64_SOURCE in zconf.h if it is zero, but not if empty -- Try to use bash or ksh regardless of functionality of /bin/sh -- Fix configure incompatibility with NetBSD sh -- Remove attempt to run under bash or ksh since have better NetBSD fix -- Fix win32/Makefile.gcc for MinGW [Bar-Lev] -- Add diagnostic messages when using CROSS_PREFIX in configure -- Added --sharedlibdir option to configure [Weigelt] -- Use hidden visibility attribute when available [Frysinger] - -Changes in 1.2.4.3 (10 Apr 2010) -- Only use CROSS_PREFIX in configure for ar and ranlib if they exist -- Use CROSS_PREFIX for nm [Bar-Lev] -- Assume _LARGEFILE64_SOURCE defined is equivalent to true -- Avoid use of undefined symbols in #if with && and || -- Make *64 prototypes in gzguts.h consistent with functions -- Add -shared load option for MinGW in configure [Bowler] -- Move z_off64_t to public interface, use instead of off64_t -- Remove ! from shell test in configure (not portable to Solaris) -- Change +0 macro tests to -0 for possibly increased portability - -Changes in 1.2.4.2 (9 Apr 2010) -- Add consistent carriage returns to readme.txt's in masmx86 and masmx64 -- Really provide prototypes for *64 functions when building without LFS -- Only define unlink() in minigzip.c if unistd.h not included -- Update README to point to contrib/vstudio project files -- Move projects/vc6 to old/ and remove projects/ -- Include stdlib.h in minigzip.c for setmode() definition under WinCE -- Clean up assembler builds in win32/Makefile.msc [Rowe] -- Include sys/types.h for Microsoft for off_t definition -- Fix memory leak on error in gz_open() -- Symbolize nm as $NM in configure [Weigelt] -- Use TEST_LDSHARED instead of LDSHARED to link test programs [Weigelt] -- Add +0 to _FILE_OFFSET_BITS and _LFS64_LARGEFILE in case not defined -- Fix bug in gzeof() to take into account unused input data -- Avoid initialization of structures with variables in puff.c -- Updated win32/README-WIN32.txt [Rowe] - -Changes in 1.2.4.1 (28 Mar 2010) -- Remove the use of [a-z] constructs for sed in configure [gentoo 310225] -- Remove $(SHAREDLIB) from LIBS in Makefile.in [Creech] -- Restore "for debugging" comment on sprintf() in gzlib.c -- Remove fdopen for MVS from gzguts.h -- Put new README-WIN32.txt in win32 [Rowe] -- Add check for shell to configure and invoke another shell if needed -- Fix big fat stinking bug in gzseek() on uncompressed files -- Remove vestigial F_OPEN64 define in zutil.h -- Set and check the value of _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE -- Avoid errors on non-LFS systems when applications define LFS macros -- Set EXE to ".exe" in configure for MINGW [Kahle] -- Match crc32() in crc32.c exactly to the prototype in zlib.h [Sherrill] -- Add prefix for cross-compilation in win32/makefile.gcc [Bar-Lev] -- Add DLL install in win32/makefile.gcc [Bar-Lev] -- Allow Linux* or linux* from uname in configure [Bar-Lev] -- Allow ldconfig to be redefined in configure and Makefile.in [Bar-Lev] -- Add cross-compilation prefixes to configure [Bar-Lev] -- Match type exactly in gz_load() invocation in gzread.c -- Match type exactly of zcalloc() in zutil.c to zlib.h alloc_func -- Provide prototypes for *64 functions when building zlib without LFS -- Don't use -lc when linking shared library on MinGW -- Remove errno.h check in configure and vestigial errno code in zutil.h - -Changes in 1.2.4 (14 Mar 2010) -- Fix VER3 extraction in configure for no fourth subversion -- Update zlib.3, add docs to Makefile.in to make .pdf out of it -- Add zlib.3.pdf to distribution -- Don't set error code in gzerror() if passed pointer is NULL -- Apply destination directory fixes to CMakeLists.txt [Lowman] -- Move #cmakedefine's to a new zconf.in.cmakein -- Restore zconf.h for builds that don't use configure or cmake -- Add distclean to dummy Makefile for convenience -- Update and improve INDEX, README, and FAQ -- Update CMakeLists.txt for the return of zconf.h [Lowman] -- Update contrib/vstudio/vc9 and vc10 [Vollant] -- Change libz.dll.a back to libzdll.a in win32/Makefile.gcc -- Apply license and readme changes to contrib/asm686 [Raiter] -- Check file name lengths and add -c option in minigzip.c [Li] -- Update contrib/amd64 and contrib/masmx86/ [Vollant] -- Avoid use of "eof" parameter in trees.c to not shadow library variable -- Update make_vms.com for removal of zlibdefs.h [Zinser] -- Update assembler code and vstudio projects in contrib [Vollant] -- Remove outdated assembler code contrib/masm686 and contrib/asm586 -- Remove old vc7 and vc8 from contrib/vstudio -- Update win32/Makefile.msc, add ZLIB_VER_SUBREVISION [Rowe] -- Fix memory leaks in gzclose_r() and gzclose_w(), file leak in gz_open() -- Add contrib/gcc_gvmat64 for longest_match and inflate_fast [Vollant] -- Remove *64 functions from win32/zlib.def (they're not 64-bit yet) -- Fix bug in void-returning vsprintf() case in gzwrite.c -- Fix name change from inflate.h in contrib/inflate86/inffas86.c -- Check if temporary file exists before removing in make_vms.com [Zinser] -- Fix make install and uninstall for --static option -- Fix usage of _MSC_VER in gzguts.h and zutil.h [Truta] -- Update readme.txt in contrib/masmx64 and masmx86 to assemble - -Changes in 1.2.3.9 (21 Feb 2010) -- Expunge gzio.c -- Move as400 build information to old -- Fix updates in contrib/minizip and contrib/vstudio -- Add const to vsnprintf test in configure to avoid warnings [Weigelt] -- Delete zconf.h (made by configure) [Weigelt] -- Change zconf.in.h to zconf.h.in per convention [Weigelt] -- Check for NULL buf in gzgets() -- Return empty string for gzgets() with len == 1 (like fgets()) -- Fix description of gzgets() in zlib.h for end-of-file, NULL return -- Update minizip to 1.1 [Vollant] -- Avoid MSVC loss of data warnings in gzread.c, gzwrite.c -- Note in zlib.h that gzerror() should be used to distinguish from EOF -- Remove use of snprintf() from gzlib.c -- Fix bug in gzseek() -- Update contrib/vstudio, adding vc9 and vc10 [Kuno, Vollant] -- Fix zconf.h generation in CMakeLists.txt [Lowman] -- Improve comments in zconf.h where modified by configure - -Changes in 1.2.3.8 (13 Feb 2010) -- Clean up text files (tabs, trailing whitespace, etc.) [Oberhumer] -- Use z_off64_t in gz_zero() and gz_skip() to match state->skip -- Avoid comparison problem when sizeof(int) == sizeof(z_off64_t) -- Revert to Makefile.in from 1.2.3.6 (live with the clutter) -- Fix missing error return in gzflush(), add zlib.h note -- Add *64 functions to zlib.map [Levin] -- Fix signed/unsigned comparison in gz_comp() -- Use SFLAGS when testing shared linking in configure -- Add --64 option to ./configure to use -m64 with gcc -- Fix ./configure --help to correctly name options -- Have make fail if a test fails [Levin] -- Avoid buffer overrun in contrib/masmx64/gvmat64.asm [Simpson] -- Remove assembler object files from contrib - -Changes in 1.2.3.7 (24 Jan 2010) -- Always gzopen() with O_LARGEFILE if available -- Fix gzdirect() to work immediately after gzopen() or gzdopen() -- Make gzdirect() more precise when the state changes while reading -- Improve zlib.h documentation in many places -- Catch memory allocation failure in gz_open() -- Complete close operation if seek forward in gzclose_w() fails -- Return Z_ERRNO from gzclose_r() if close() fails -- Return Z_STREAM_ERROR instead of EOF for gzclose() being passed NULL -- Return zero for gzwrite() errors to match zlib.h description -- Return -1 on gzputs() error to match zlib.h description -- Add zconf.in.h to allow recovery from configure modification [Weigelt] -- Fix static library permissions in Makefile.in [Weigelt] -- Avoid warnings in configure tests that hide functionality [Weigelt] -- Add *BSD and DragonFly to Linux case in configure [gentoo 123571] -- Change libzdll.a to libz.dll.a in win32/Makefile.gcc [gentoo 288212] -- Avoid access of uninitialized data for first inflateReset2 call [Gomes] -- Keep object files in subdirectories to reduce the clutter somewhat -- Remove default Makefile and zlibdefs.h, add dummy Makefile -- Add new external functions to Z_PREFIX, remove duplicates, z_z_ -> z_ -- Remove zlibdefs.h completely -- modify zconf.h instead - -Changes in 1.2.3.6 (17 Jan 2010) -- Avoid void * arithmetic in gzread.c and gzwrite.c -- Make compilers happier with const char * for gz_error message -- Avoid unused parameter warning in inflate.c -- Avoid signed-unsigned comparison warning in inflate.c -- Indent #pragma's for traditional C -- Fix usage of strwinerror() in glib.c, change to gz_strwinerror() -- Correct email address in configure for system options -- Update make_vms.com and add make_vms.com to contrib/minizip [Zinser] -- Update zlib.map [Brown] -- Fix Makefile.in for Solaris 10 make of example64 and minizip64 [Torok] -- Apply various fixes to CMakeLists.txt [Lowman] -- Add checks on len in gzread() and gzwrite() -- Add error message for no more room for gzungetc() -- Remove zlib version check in gzwrite() -- Defer compression of gzprintf() result until need to -- Use snprintf() in gzdopen() if available -- Remove USE_MMAP configuration determination (only used by minigzip) -- Remove examples/pigz.c (available separately) -- Update examples/gun.c to 1.6 - -Changes in 1.2.3.5 (8 Jan 2010) -- Add space after #if in zutil.h for some compilers -- Fix relatively harmless bug in deflate_fast() [Exarevsky] -- Fix same problem in deflate_slow() -- Add $(SHAREDLIBV) to LIBS in Makefile.in [Brown] -- Add deflate_rle() for faster Z_RLE strategy run-length encoding -- Add deflate_huff() for faster Z_HUFFMAN_ONLY encoding -- Change name of "write" variable in inffast.c to avoid library collisions -- Fix premature EOF from gzread() in gzio.c [Brown] -- Use zlib header window size if windowBits is 0 in inflateInit2() -- Remove compressBound() call in deflate.c to avoid linking compress.o -- Replace use of errno in gz* with functions, support WinCE [Alves] -- Provide alternative to perror() in minigzip.c for WinCE [Alves] -- Don't use _vsnprintf on later versions of MSVC [Lowman] -- Add CMake build script and input file [Lowman] -- Update contrib/minizip to 1.1 [Svensson, Vollant] -- Moved nintendods directory from contrib to . -- Replace gzio.c with a new set of routines with the same functionality -- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above -- Update contrib/minizip to 1.1b -- Change gzeof() to return 0 on error instead of -1 to agree with zlib.h - -Changes in 1.2.3.4 (21 Dec 2009) -- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility -- Update comments in configure and Makefile.in for default --shared -- Fix test -z's in configure [Marquess] -- Build examplesh and minigzipsh when not testing -- Change NULL's to Z_NULL's in deflate.c and in comments in zlib.h -- Import LDFLAGS from the environment in configure -- Fix configure to populate SFLAGS with discovered CFLAGS options -- Adapt make_vms.com to the new Makefile.in [Zinser] -- Add zlib2ansi script for C++ compilation [Marquess] -- Add _FILE_OFFSET_BITS=64 test to make test (when applicable) -- Add AMD64 assembler code for longest match to contrib [Teterin] -- Include options from $SFLAGS when doing $LDSHARED -- Simplify 64-bit file support by introducing z_off64_t type -- Make shared object files in objs directory to work around old Sun cc -- Use only three-part version number for Darwin shared compiles -- Add rc option to ar in Makefile.in for when ./configure not run -- Add -WI,-rpath,. to LDFLAGS for OSF 1 V4* -- Set LD_LIBRARYN32_PATH for SGI IRIX shared compile -- Protect against _FILE_OFFSET_BITS being defined when compiling zlib -- Rename Makefile.in targets allstatic to static and allshared to shared -- Fix static and shared Makefile.in targets to be independent -- Correct error return bug in gz_open() by setting state [Brown] -- Put spaces before ;;'s in configure for better sh compatibility -- Add pigz.c (parallel implementation of gzip) to examples/ -- Correct constant in crc32.c to UL [Leventhal] -- Reject negative lengths in crc32_combine() -- Add inflateReset2() function to work like inflateEnd()/inflateInit2() -- Include sys/types.h for _LARGEFILE64_SOURCE [Brown] -- Correct typo in doc/algorithm.txt [Janik] -- Fix bug in adler32_combine() [Zhu] -- Catch missing-end-of-block-code error in all inflates and in puff - Assures that random input to inflate eventually results in an error -- Added enough.c (calculation of ENOUGH for inftrees.h) to examples/ -- Update ENOUGH and its usage to reflect discovered bounds -- Fix gzerror() error report on empty input file [Brown] -- Add ush casts in trees.c to avoid pedantic runtime errors -- Fix typo in zlib.h uncompress() description [Reiss] -- Correct inflate() comments with regard to automatic header detection -- Remove deprecation comment on Z_PARTIAL_FLUSH (it stays) -- Put new version of gzlog (2.0) in examples with interruption recovery -- Add puff compile option to permit invalid distance-too-far streams -- Add puff TEST command options, ability to read piped input -- Prototype the *64 functions in zlib.h when _FILE_OFFSET_BITS == 64, but - _LARGEFILE64_SOURCE not defined -- Fix Z_FULL_FLUSH to truly erase the past by resetting s->strstart -- Fix deflateSetDictionary() to use all 32K for output consistency -- Remove extraneous #define MIN_LOOKAHEAD in deflate.c (in deflate.h) -- Clear bytes after deflate lookahead to avoid use of uninitialized data -- Change a limit in inftrees.c to be more transparent to Coverity Prevent -- Update win32/zlib.def with exported symbols from zlib.h -- Correct spelling errors in zlib.h [Willem, Sobrado] -- Allow Z_BLOCK for deflate() to force a new block -- Allow negative bits in inflatePrime() to delete existing bit buffer -- Add Z_TREES flush option to inflate() to return at end of trees -- Add inflateMark() to return current state information for random access -- Add Makefile for NintendoDS to contrib [Costa] -- Add -w in configure compile tests to avoid spurious warnings [Beucler] -- Fix typos in zlib.h comments for deflateSetDictionary() -- Fix EOF detection in transparent gzread() [Maier] - -Changes in 1.2.3.3 (2 October 2006) -- Make --shared the default for configure, add a --static option -- Add compile option to permit invalid distance-too-far streams -- Add inflateUndermine() function which is required to enable above -- Remove use of "this" variable name for C++ compatibility [Marquess] -- Add testing of shared library in make test, if shared library built -- Use ftello() and fseeko() if available instead of ftell() and fseek() -- Provide two versions of all functions that use the z_off_t type for - binary compatibility -- a normal version and a 64-bit offset version, - per the Large File Support Extension when _LARGEFILE64_SOURCE is - defined; use the 64-bit versions by default when _FILE_OFFSET_BITS - is defined to be 64 -- Add a --uname= option to configure to perhaps help with cross-compiling - -Changes in 1.2.3.2 (3 September 2006) -- Turn off silly Borland warnings [Hay] -- Use off64_t and define _LARGEFILE64_SOURCE when present -- Fix missing dependency on inffixed.h in Makefile.in -- Rig configure --shared to build both shared and static [Teredesai, Truta] -- Remove zconf.in.h and instead create a new zlibdefs.h file -- Fix contrib/minizip/unzip.c non-encrypted after encrypted [Vollant] -- Add treebuild.xml (see http://treebuild.metux.de/) [Weigelt] - -Changes in 1.2.3.1 (16 August 2006) -- Add watcom directory with OpenWatcom make files [Daniel] -- Remove #undef of FAR in zconf.in.h for MVS [Fedtke] -- Update make_vms.com [Zinser] -- Use -fPIC for shared build in configure [Teredesai, Nicholson] -- Use only major version number for libz.so on IRIX and OSF1 [Reinholdtsen] -- Use fdopen() (not _fdopen()) for Interix in zutil.h [BŠck] -- Add some FAQ entries about the contrib directory -- Update the MVS question in the FAQ -- Avoid extraneous reads after EOF in gzio.c [Brown] -- Correct spelling of "successfully" in gzio.c [Randers-Pehrson] -- Add comments to zlib.h about gzerror() usage [Brown] -- Set extra flags in gzip header in gzopen() like deflate() does -- Make configure options more compatible with double-dash conventions - [Weigelt] -- Clean up compilation under Solaris SunStudio cc [Rowe, Reinholdtsen] -- Fix uninstall target in Makefile.in [Truta] -- Add pkgconfig support [Weigelt] -- Use $(DESTDIR) macro in Makefile.in [Reinholdtsen, Weigelt] -- Replace set_data_type() with a more accurate detect_data_type() in - trees.c, according to the txtvsbin.txt document [Truta] -- Swap the order of #include and #include "zlib.h" in - gzio.c, example.c and minigzip.c [Truta] -- Shut up annoying VS2005 warnings about standard C deprecation [Rowe, - Truta] (where?) -- Fix target "clean" from win32/Makefile.bor [Truta] -- Create .pdb and .manifest files in win32/makefile.msc [Ziegler, Rowe] -- Update zlib www home address in win32/DLL_FAQ.txt [Truta] -- Update contrib/masmx86/inffas32.asm for VS2005 [Vollant, Van Wassenhove] -- Enable browse info in the "Debug" and "ASM Debug" configurations in - the Visual C++ 6 project, and set (non-ASM) "Debug" as default [Truta] -- Add pkgconfig support [Weigelt] -- Add ZLIB_VER_MAJOR, ZLIB_VER_MINOR and ZLIB_VER_REVISION in zlib.h, - for use in win32/zlib1.rc [Polushin, Rowe, Truta] -- Add a document that explains the new text detection scheme to - doc/txtvsbin.txt [Truta] -- Add rfc1950.txt, rfc1951.txt and rfc1952.txt to doc/ [Truta] -- Move algorithm.txt into doc/ [Truta] -- Synchronize FAQ with website -- Fix compressBound(), was low for some pathological cases [Fearnley] -- Take into account wrapper variations in deflateBound() -- Set examples/zpipe.c input and output to binary mode for Windows -- Update examples/zlib_how.html with new zpipe.c (also web site) -- Fix some warnings in examples/gzlog.c and examples/zran.c (it seems - that gcc became pickier in 4.0) -- Add zlib.map for Linux: "All symbols from zlib-1.1.4 remain - un-versioned, the patch adds versioning only for symbols introduced in - zlib-1.2.0 or later. It also declares as local those symbols which are - not designed to be exported." [Levin] -- Update Z_PREFIX list in zconf.in.h, add --zprefix option to configure -- Do not initialize global static by default in trees.c, add a response - NO_INIT_GLOBAL_POINTERS to initialize them if needed [Marquess] -- Don't use strerror() in gzio.c under WinCE [Yakimov] -- Don't use errno.h in zutil.h under WinCE [Yakimov] -- Move arguments for AR to its usage to allow replacing ar [Marot] -- Add HAVE_VISIBILITY_PRAGMA in zconf.in.h for Mozilla [Randers-Pehrson] -- Improve inflateInit() and inflateInit2() documentation -- Fix structure size comment in inflate.h -- Change configure help option from --h* to --help [Santos] - -Changes in 1.2.3 (18 July 2005) -- Apply security vulnerability fixes to contrib/infback9 as well -- Clean up some text files (carriage returns, trailing space) -- Update testzlib, vstudio, masmx64, and masmx86 in contrib [Vollant] - -Changes in 1.2.2.4 (11 July 2005) -- Add inflatePrime() function for starting inflation at bit boundary -- Avoid some Visual C warnings in deflate.c -- Avoid more silly Visual C warnings in inflate.c and inftrees.c for 64-bit - compile -- Fix some spelling errors in comments [Betts] -- Correct inflateInit2() error return documentation in zlib.h -- Add zran.c example of compressed data random access to examples - directory, shows use of inflatePrime() -- Fix cast for assignments to strm->state in inflate.c and infback.c -- Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer] -- Move declarations of gf2 functions to right place in crc32.c [Oberhumer] -- Add cast in trees.c t avoid a warning [Oberhumer] -- Avoid some warnings in fitblk.c, gun.c, gzjoin.c in examples [Oberhumer] -- Update make_vms.com [Zinser] -- Initialize state->write in inflateReset() since copied in inflate_fast() -- Be more strict on incomplete code sets in inflate_table() and increase - ENOUGH and MAXD -- this repairs a possible security vulnerability for - invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for - discovering the vulnerability and providing test cases. -- Add ia64 support to configure for HP-UX [Smith] -- Add error return to gzread() for format or i/o error [Levin] -- Use malloc.h for OS/2 [Necasek] - -Changes in 1.2.2.3 (27 May 2005) -- Replace 1U constants in inflate.c and inftrees.c for 64-bit compile -- Typecast fread() return values in gzio.c [Vollant] -- Remove trailing space in minigzip.c outmode (VC++ can't deal with it) -- Fix crc check bug in gzread() after gzungetc() [Heiner] -- Add the deflateTune() function to adjust internal compression parameters -- Add a fast gzip decompressor, gun.c, to examples (use of inflateBack) -- Remove an incorrect assertion in examples/zpipe.c -- Add C++ wrapper in infback9.h [Donais] -- Fix bug in inflateCopy() when decoding fixed codes -- Note in zlib.h how much deflateSetDictionary() actually uses -- Remove USE_DICT_HEAD in deflate.c (would mess up inflate if used) -- Add _WIN32_WCE to define WIN32 in zconf.in.h [Spencer] -- Don't include stderr.h or errno.h for _WIN32_WCE in zutil.h [Spencer] -- Add gzdirect() function to indicate transparent reads -- Update contrib/minizip [Vollant] -- Fix compilation of deflate.c when both ASMV and FASTEST [Oberhumer] -- Add casts in crc32.c to avoid warnings [Oberhumer] -- Add contrib/masmx64 [Vollant] -- Update contrib/asm586, asm686, masmx86, testzlib, vstudio [Vollant] - -Changes in 1.2.2.2 (30 December 2004) -- Replace structure assignments in deflate.c and inflate.c with zmemcpy to - avoid implicit memcpy calls (portability for no-library compilation) -- Increase sprintf() buffer size in gzdopen() to allow for large numbers -- Add INFLATE_STRICT to check distances against zlib header -- Improve WinCE errno handling and comments [Chang] -- Remove comment about no gzip header processing in FAQ -- Add Z_FIXED strategy option to deflateInit2() to force fixed trees -- Add updated make_vms.com [Coghlan], update README -- Create a new "examples" directory, move gzappend.c there, add zpipe.c, - fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html. -- Add FAQ entry and comments in deflate.c on uninitialized memory access -- Add Solaris 9 make options in configure [Gilbert] -- Allow strerror() usage in gzio.c for STDC -- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer] -- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant] -- Use z_off_t for adler32_combine() and crc32_combine() lengths -- Make adler32() much faster for small len -- Use OS_CODE in deflate() default gzip header - -Changes in 1.2.2.1 (31 October 2004) -- Allow inflateSetDictionary() call for raw inflate -- Fix inflate header crc check bug for file names and comments -- Add deflateSetHeader() and gz_header structure for custom gzip headers -- Add inflateGetheader() to retrieve gzip headers -- Add crc32_combine() and adler32_combine() functions -- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list -- Use zstreamp consistently in zlib.h (inflate_back functions) -- Remove GUNZIP condition from definition of inflate_mode in inflate.h - and in contrib/inflate86/inffast.S [Truta, Anderson] -- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson] -- Update projects/README.projects and projects/visualc6 [Truta] -- Update win32/DLL_FAQ.txt [Truta] -- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta] -- Deprecate Z_ASCII; use Z_TEXT instead [Truta] -- Use a new algorithm for setting strm->data_type in trees.c [Truta] -- Do not define an exit() prototype in zutil.c unless DEBUG defined -- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta] -- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate() -- Fix Darwin build version identification [Peterson] - -Changes in 1.2.2 (3 October 2004) -- Update zlib.h comments on gzip in-memory processing -- Set adler to 1 in inflateReset() to support Java test suite [Walles] -- Add contrib/dotzlib [Ravn] -- Update win32/DLL_FAQ.txt [Truta] -- Update contrib/minizip [Vollant] -- Move contrib/visual-basic.txt to old/ [Truta] -- Fix assembler builds in projects/visualc6/ [Truta] - -Changes in 1.2.1.2 (9 September 2004) -- Update INDEX file -- Fix trees.c to update strm->data_type (no one ever noticed!) -- Fix bug in error case in inflate.c, infback.c, and infback9.c [Brown] -- Add "volatile" to crc table flag declaration (for DYNAMIC_CRC_TABLE) -- Add limited multitasking protection to DYNAMIC_CRC_TABLE -- Add NO_vsnprintf for VMS in zutil.h [Mozilla] -- Don't declare strerror() under VMS [Mozilla] -- Add comment to DYNAMIC_CRC_TABLE to use get_crc_table() to initialize -- Update contrib/ada [Anisimkov] -- Update contrib/minizip [Vollant] -- Fix configure to not hardcode directories for Darwin [Peterson] -- Fix gzio.c to not return error on empty files [Brown] -- Fix indentation; update version in contrib/delphi/ZLib.pas and - contrib/pascal/zlibpas.pas [Truta] -- Update mkasm.bat in contrib/masmx86 [Truta] -- Update contrib/untgz [Truta] -- Add projects/README.projects [Truta] -- Add project for MS Visual C++ 6.0 in projects/visualc6 [Cadieux, Truta] -- Update win32/DLL_FAQ.txt [Truta] -- Update list of Z_PREFIX symbols in zconf.h [Randers-Pehrson, Truta] -- Remove an unnecessary assignment to curr in inftrees.c [Truta] -- Add OS/2 to exe builds in configure [Poltorak] -- Remove err dummy parameter in zlib.h [Kientzle] - -Changes in 1.2.1.1 (9 January 2004) -- Update email address in README -- Several FAQ updates -- Fix a big fat bug in inftrees.c that prevented decoding valid - dynamic blocks with only literals and no distance codes -- - Thanks to "Hot Emu" for the bug report and sample file -- Add a note to puff.c on no distance codes case. - -Changes in 1.2.1 (17 November 2003) -- Remove a tab in contrib/gzappend/gzappend.c -- Update some interfaces in contrib for new zlib functions -- Update zlib version number in some contrib entries -- Add Windows CE definition for ptrdiff_t in zutil.h [Mai, Truta] -- Support shared libraries on Hurd and KFreeBSD [Brown] -- Fix error in NO_DIVIDE option of adler32.c - -Changes in 1.2.0.8 (4 November 2003) -- Update version in contrib/delphi/ZLib.pas and contrib/pascal/zlibpas.pas -- Add experimental NO_DIVIDE #define in adler32.c - - Possibly faster on some processors (let me know if it is) -- Correct Z_BLOCK to not return on first inflate call if no wrap -- Fix strm->data_type on inflate() return to correctly indicate EOB -- Add deflatePrime() function for appending in the middle of a byte -- Add contrib/gzappend for an example of appending to a stream -- Update win32/DLL_FAQ.txt [Truta] -- Delete Turbo C comment in README [Truta] -- Improve some indentation in zconf.h [Truta] -- Fix infinite loop on bad input in configure script [Church] -- Fix gzeof() for concatenated gzip files [Johnson] -- Add example to contrib/visual-basic.txt [Michael B.] -- Add -p to mkdir's in Makefile.in [vda] -- Fix configure to properly detect presence or lack of printf functions -- Add AS400 support [Monnerat] -- Add a little Cygwin support [Wilson] - -Changes in 1.2.0.7 (21 September 2003) -- Correct some debug formats in contrib/infback9 -- Cast a type in a debug statement in trees.c -- Change search and replace delimiter in configure from % to # [Beebe] -- Update contrib/untgz to 0.2 with various fixes [Truta] -- Add build support for Amiga [Nikl] -- Remove some directories in old that have been updated to 1.2 -- Add dylib building for Mac OS X in configure and Makefile.in -- Remove old distribution stuff from Makefile -- Update README to point to DLL_FAQ.txt, and add comment on Mac OS X -- Update links in README - -Changes in 1.2.0.6 (13 September 2003) -- Minor FAQ updates -- Update contrib/minizip to 1.00 [Vollant] -- Remove test of gz functions in example.c when GZ_COMPRESS defined [Truta] -- Update POSTINC comment for 68060 [Nikl] -- Add contrib/infback9 with deflate64 decoding (unsupported) -- For MVS define NO_vsnprintf and undefine FAR [van Burik] -- Add pragma for fdopen on MVS [van Burik] - -Changes in 1.2.0.5 (8 September 2003) -- Add OF to inflateBackEnd() declaration in zlib.h -- Remember start when using gzdopen in the middle of a file -- Use internal off_t counters in gz* functions to properly handle seeks -- Perform more rigorous check for distance-too-far in inffast.c -- Add Z_BLOCK flush option to return from inflate at block boundary -- Set strm->data_type on return from inflate - - Indicate bits unused, if at block boundary, and if in last block -- Replace size_t with ptrdiff_t in crc32.c, and check for correct size -- Add condition so old NO_DEFLATE define still works for compatibility -- FAQ update regarding the Windows DLL [Truta] -- INDEX update: add qnx entry, remove aix entry [Truta] -- Install zlib.3 into mandir [Wilson] -- Move contrib/zlib_dll_FAQ.txt to win32/DLL_FAQ.txt; update [Truta] -- Adapt the zlib interface to the new DLL convention guidelines [Truta] -- Introduce ZLIB_WINAPI macro to allow the export of functions using - the WINAPI calling convention, for Visual Basic [Vollant, Truta] -- Update msdos and win32 scripts and makefiles [Truta] -- Export symbols by name, not by ordinal, in win32/zlib.def [Truta] -- Add contrib/ada [Anisimkov] -- Move asm files from contrib/vstudio/vc70_32 to contrib/asm386 [Truta] -- Rename contrib/asm386 to contrib/masmx86 [Truta, Vollant] -- Add contrib/masm686 [Truta] -- Fix offsets in contrib/inflate86 and contrib/masmx86/inffas32.asm - [Truta, Vollant] -- Update contrib/delphi; rename to contrib/pascal; add example [Truta] -- Remove contrib/delphi2; add a new contrib/delphi [Truta] -- Avoid inclusion of the nonstandard in contrib/iostream, - and fix some method prototypes [Truta] -- Fix the ZCR_SEED2 constant to avoid warnings in contrib/minizip - [Truta] -- Avoid the use of backslash (\) in contrib/minizip [Vollant] -- Fix file time handling in contrib/untgz; update makefiles [Truta] -- Update contrib/vstudio/vc70_32 to comply with the new DLL guidelines - [Vollant] -- Remove contrib/vstudio/vc15_16 [Vollant] -- Rename contrib/vstudio/vc70_32 to contrib/vstudio/vc7 [Truta] -- Update README.contrib [Truta] -- Invert the assignment order of match_head and s->prev[...] in - INSERT_STRING [Truta] -- Compare TOO_FAR with 32767 instead of 32768, to avoid 16-bit warnings - [Truta] -- Compare function pointers with 0, not with NULL or Z_NULL [Truta] -- Fix prototype of syncsearch in inflate.c [Truta] -- Introduce ASMINF macro to be enabled when using an ASM implementation - of inflate_fast [Truta] -- Change NO_DEFLATE to NO_GZCOMPRESS [Truta] -- Modify test_gzio in example.c to take a single file name as a - parameter [Truta] -- Exit the example.c program if gzopen fails [Truta] -- Add type casts around strlen in example.c [Truta] -- Remove casting to sizeof in minigzip.c; give a proper type - to the variable compared with SUFFIX_LEN [Truta] -- Update definitions of STDC and STDC99 in zconf.h [Truta] -- Synchronize zconf.h with the new Windows DLL interface [Truta] -- Use SYS16BIT instead of __32BIT__ to distinguish between - 16- and 32-bit platforms [Truta] -- Use far memory allocators in small 16-bit memory models for - Turbo C [Truta] -- Add info about the use of ASMV, ASMINF and ZLIB_WINAPI in - zlibCompileFlags [Truta] -- Cygwin has vsnprintf [Wilson] -- In Windows16, OS_CODE is 0, as in MSDOS [Truta] -- In Cygwin, OS_CODE is 3 (Unix), not 11 (Windows32) [Wilson] - -Changes in 1.2.0.4 (10 August 2003) -- Minor FAQ updates -- Be more strict when checking inflateInit2's windowBits parameter -- Change NO_GUNZIP compile option to NO_GZIP to cover deflate as well -- Add gzip wrapper option to deflateInit2 using windowBits -- Add updated QNX rule in configure and qnx directory [Bonnefoy] -- Make inflate distance-too-far checks more rigorous -- Clean up FAR usage in inflate -- Add casting to sizeof() in gzio.c and minigzip.c - -Changes in 1.2.0.3 (19 July 2003) -- Fix silly error in gzungetc() implementation [Vollant] -- Update contrib/minizip and contrib/vstudio [Vollant] -- Fix printf format in example.c -- Correct cdecl support in zconf.in.h [Anisimkov] -- Minor FAQ updates - -Changes in 1.2.0.2 (13 July 2003) -- Add ZLIB_VERNUM in zlib.h for numerical preprocessor comparisons -- Attempt to avoid warnings in crc32.c for pointer-int conversion -- Add AIX to configure, remove aix directory [Bakker] -- Add some casts to minigzip.c -- Improve checking after insecure sprintf() or vsprintf() calls -- Remove #elif's from crc32.c -- Change leave label to inf_leave in inflate.c and infback.c to avoid - library conflicts -- Remove inflate gzip decoding by default--only enable gzip decoding by - special request for stricter backward compatibility -- Add zlibCompileFlags() function to return compilation information -- More typecasting in deflate.c to avoid warnings -- Remove leading underscore from _Capital #defines [Truta] -- Fix configure to link shared library when testing -- Add some Windows CE target adjustments [Mai] -- Remove #define ZLIB_DLL in zconf.h [Vollant] -- Add zlib.3 [Rodgers] -- Update RFC URL in deflate.c and algorithm.txt [Mai] -- Add zlib_dll_FAQ.txt to contrib [Truta] -- Add UL to some constants [Truta] -- Update minizip and vstudio [Vollant] -- Remove vestigial NEED_DUMMY_RETURN from zconf.in.h -- Expand use of NO_DUMMY_DECL to avoid all dummy structures -- Added iostream3 to contrib [Schwardt] -- Replace rewind() with fseek() for WinCE [Truta] -- Improve setting of zlib format compression level flags - - Report 0 for huffman and rle strategies and for level == 0 or 1 - - Report 2 only for level == 6 -- Only deal with 64K limit when necessary at compile time [Truta] -- Allow TOO_FAR check to be turned off at compile time [Truta] -- Add gzclearerr() function [Souza] -- Add gzungetc() function - -Changes in 1.2.0.1 (17 March 2003) -- Add Z_RLE strategy for run-length encoding [Truta] - - When Z_RLE requested, restrict matches to distance one - - Update zlib.h, minigzip.c, gzopen(), gzdopen() for Z_RLE -- Correct FASTEST compilation to allow level == 0 -- Clean up what gets compiled for FASTEST -- Incorporate changes to zconf.in.h [Vollant] - - Refine detection of Turbo C need for dummy returns - - Refine ZLIB_DLL compilation - - Include additional header file on VMS for off_t typedef -- Try to use _vsnprintf where it supplants vsprintf [Vollant] -- Add some casts in inffast.c -- Enchance comments in zlib.h on what happens if gzprintf() tries to - write more than 4095 bytes before compression -- Remove unused state from inflateBackEnd() -- Remove exit(0) from minigzip.c, example.c -- Get rid of all those darn tabs -- Add "check" target to Makefile.in that does the same thing as "test" -- Add "mostlyclean" and "maintainer-clean" targets to Makefile.in -- Update contrib/inflate86 [Anderson] -- Update contrib/testzlib, contrib/vstudio, contrib/minizip [Vollant] -- Add msdos and win32 directories with makefiles [Truta] -- More additions and improvements to the FAQ - -Changes in 1.2.0 (9 March 2003) -- New and improved inflate code - - About 20% faster - - Does not allocate 32K window unless and until needed - - Automatically detects and decompresses gzip streams - - Raw inflate no longer needs an extra dummy byte at end - - Added inflateBack functions using a callback interface--even faster - than inflate, useful for file utilities (gzip, zip) - - Added inflateCopy() function to record state for random access on - externally generated deflate streams (e.g. in gzip files) - - More readable code (I hope) -- New and improved crc32() - - About 50% faster, thanks to suggestions from Rodney Brown -- Add deflateBound() and compressBound() functions -- Fix memory leak in deflateInit2() -- Permit setting dictionary for raw deflate (for parallel deflate) -- Fix const declaration for gzwrite() -- Check for some malloc() failures in gzio.c -- Fix bug in gzopen() on single-byte file 0x1f -- Fix bug in gzread() on concatenated file with 0x1f at end of buffer - and next buffer doesn't start with 0x8b -- Fix uncompress() to return Z_DATA_ERROR on truncated input -- Free memory at end of example.c -- Remove MAX #define in trees.c (conflicted with some libraries) -- Fix static const's in deflate.c, gzio.c, and zutil.[ch] -- Declare malloc() and free() in gzio.c if STDC not defined -- Use malloc() instead of calloc() in zutil.c if int big enough -- Define STDC for AIX -- Add aix/ with approach for compiling shared library on AIX -- Add HP-UX support for shared libraries in configure -- Add OpenUNIX support for shared libraries in configure -- Use $cc instead of gcc to build shared library -- Make prefix directory if needed when installing -- Correct Macintosh avoidance of typedef Byte in zconf.h -- Correct Turbo C memory allocation when under Linux -- Use libz.a instead of -lz in Makefile (assure use of compiled library) -- Update configure to check for snprintf or vsnprintf functions and their - return value, warn during make if using an insecure function -- Fix configure problem with compile-time knowledge of HAVE_UNISTD_H that - is lost when library is used--resolution is to build new zconf.h -- Documentation improvements (in zlib.h): - - Document raw deflate and inflate - - Update RFCs URL - - Point out that zlib and gzip formats are different - - Note that Z_BUF_ERROR is not fatal - - Document string limit for gzprintf() and possible buffer overflow - - Note requirement on avail_out when flushing - - Note permitted values of flush parameter of inflate() -- Add some FAQs (and even answers) to the FAQ -- Add contrib/inflate86/ for x86 faster inflate -- Add contrib/blast/ for PKWare Data Compression Library decompression -- Add contrib/puff/ simple inflate for deflate format description - -Changes in 1.1.4 (11 March 2002) -- ZFREE was repeated on same allocation on some error conditions. - This creates a security problem described in - http://www.zlib.org/advisory-2002-03-11.txt -- Returned incorrect error (Z_MEM_ERROR) on some invalid data -- Avoid accesses before window for invalid distances with inflate window - less than 32K. -- force windowBits > 8 to avoid a bug in the encoder for a window size - of 256 bytes. (A complete fix will be available in 1.1.5). - -Changes in 1.1.3 (9 July 1998) -- fix "an inflate input buffer bug that shows up on rare but persistent - occasions" (Mark) -- fix gzread and gztell for concatenated .gz files (Didier Le Botlan) -- fix gzseek(..., SEEK_SET) in write mode -- fix crc check after a gzeek (Frank Faubert) -- fix miniunzip when the last entry in a zip file is itself a zip file - (J Lillge) -- add contrib/asm586 and contrib/asm686 (Brian Raiter) - See http://www.muppetlabs.com/~breadbox/software/assembly.html -- add support for Delphi 3 in contrib/delphi (Bob Dellaca) -- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti) -- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren) -- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks) -- added a FAQ file - -- Support gzdopen on Mac with Metrowerks (Jason Linhart) -- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart) -- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young) -- avoid some warnings with Borland C (Tom Tanner) -- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant) -- emulate utime() for WIN32 in contrib/untgz (Gilles Vollant) -- allow several arguments to configure (Tim Mooney, Frodo Looijaard) -- use libdir and includedir in Makefile.in (Tim Mooney) -- support shared libraries on OSF1 V4 (Tim Mooney) -- remove so_locations in "make clean" (Tim Mooney) -- fix maketree.c compilation error (Glenn, Mark) -- Python interface to zlib now in Python 1.5 (Jeremy Hylton) -- new Makefile.riscos (Rich Walker) -- initialize static descriptors in trees.c for embedded targets (Nick Smith) -- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith) -- add the OS/2 files in Makefile.in too (Andrew Zabolotny) -- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane) -- fix maketree.c to allow clean compilation of inffixed.h (Mark) -- fix parameter check in deflateCopy (Gunther Nikl) -- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler) -- Many portability patches by Christian Spieler: - . zutil.c, zutil.h: added "const" for zmem* - . Make_vms.com: fixed some typos - . Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists - . msdos/Makefile.msc: remove "default rtl link library" info from obj files - . msdos/Makefile.*: use model-dependent name for the built zlib library - . msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc: - new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT) -- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane) -- replace __far with _far for better portability (Christian Spieler, Tom Lane) -- fix test for errno.h in configure (Tim Newsham) - -Changes in 1.1.2 (19 March 98) -- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant) - See http://www.winimage.com/zLibDll/unzip.html -- preinitialize the inflate tables for fixed codes, to make the code - completely thread safe (Mark) -- some simplifications and slight speed-up to the inflate code (Mark) -- fix gzeof on non-compressed files (Allan Schrum) -- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs) -- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn) -- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny) -- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori) -- do not wrap extern "C" around system includes (Tom Lane) -- mention zlib binding for TCL in README (Andreas Kupries) -- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert) -- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson) -- allow "configure --prefix $HOME" (Tim Mooney) -- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson) -- move Makefile.sas to amiga/Makefile.sas - -Changes in 1.1.1 (27 Feb 98) -- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson) -- remove block truncation heuristic which had very marginal effect for zlib - (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the - compression ratio on some files. This also allows inlining _tr_tally for - matches in deflate_slow. -- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier) - -Changes in 1.1.0 (24 Feb 98) -- do not return STREAM_END prematurely in inflate (John Bowler) -- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler) -- compile with -DFASTEST to get compression code optimized for speed only -- in minigzip, try mmap'ing the input file first (Miguel Albrecht) -- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain - on Sun but significant on HP) - -- add a pointer to experimental unzip library in README (Gilles Vollant) -- initialize variable gcc in configure (Chris Herborth) - -Changes in 1.0.9 (17 Feb 1998) -- added gzputs and gzgets functions -- do not clear eof flag in gzseek (Mark Diekhans) -- fix gzseek for files in transparent mode (Mark Diekhans) -- do not assume that vsprintf returns the number of bytes written (Jens Krinke) -- replace EXPORT with ZEXPORT to avoid conflict with other programs -- added compress2 in zconf.h, zlib.def, zlib.dnt -- new asm code from Gilles Vollant in contrib/asm386 -- simplify the inflate code (Mark): - . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new() - . ZALLOC the length list in inflate_trees_fixed() instead of using stack - . ZALLOC the value area for huft_build() instead of using stack - . Simplify Z_FINISH check in inflate() - -- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8 -- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi) -- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with - the declaration of FAR (Gilles VOllant) -- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann) -- read_buf buf parameter of type Bytef* instead of charf* -- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout) -- do not redeclare unlink in minigzip.c for WIN32 (John Bowler) -- fix check for presence of directories in "make install" (Ian Willis) - -Changes in 1.0.8 (27 Jan 1998) -- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant) -- fix gzgetc and gzputc for big endian systems (Markus Oberhumer) -- added compress2() to allow setting the compression level -- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong) -- use constant arrays for the static trees in trees.c instead of computing - them at run time (thanks to Ken Raeburn for this suggestion). To create - trees.h, compile with GEN_TREES_H and run "make test". -- check return code of example in "make test" and display result -- pass minigzip command line options to file_compress -- simplifying code of inflateSync to avoid gcc 2.8 bug - -- support CC="gcc -Wall" in configure -s (QingLong) -- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn) -- fix test for shared library support to avoid compiler warnings -- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant) -- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit) -- do not use fdopen for Metrowerks on Mac (Brad Pettit)) -- add checks for gzputc and gzputc in example.c -- avoid warnings in gzio.c and deflate.c (Andreas Kleinert) -- use const for the CRC table (Ken Raeburn) -- fixed "make uninstall" for shared libraries -- use Tracev instead of Trace in infblock.c -- in example.c use correct compressed length for test_sync -- suppress +vnocompatwarnings in configure for HPUX (not always supported) - -Changes in 1.0.7 (20 Jan 1998) -- fix gzseek which was broken in write mode -- return error for gzseek to negative absolute position -- fix configure for Linux (Chun-Chung Chen) -- increase stack space for MSC (Tim Wegner) -- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant) -- define EXPORTVA for gzprintf (Gilles Vollant) -- added man page zlib.3 (Rick Rodgers) -- for contrib/untgz, fix makedir() and improve Makefile - -- check gzseek in write mode in example.c -- allocate extra buffer for seeks only if gzseek is actually called -- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant) -- add inflateSyncPoint in zconf.h -- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def - -Changes in 1.0.6 (19 Jan 1998) -- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and - gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code) -- Fix a deflate bug occurring only with compression level 0 (thanks to - Andy Buckler for finding this one). -- In minigzip, pass transparently also the first byte for .Z files. -- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress() -- check Z_FINISH in inflate (thanks to Marc Schluper) -- Implement deflateCopy (thanks to Adam Costello) -- make static libraries by default in configure, add --shared option. -- move MSDOS or Windows specific files to directory msdos -- suppress the notion of partial flush to simplify the interface - (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4) -- suppress history buffer provided by application to simplify the interface - (this feature was not implemented anyway in 1.0.4) -- next_in and avail_in must be initialized before calling inflateInit or - inflateInit2 -- add EXPORT in all exported functions (for Windows DLL) -- added Makefile.nt (thanks to Stephen Williams) -- added the unsupported "contrib" directory: - contrib/asm386/ by Gilles Vollant - 386 asm code replacing longest_match(). - contrib/iostream/ by Kevin Ruland - A C++ I/O streams interface to the zlib gz* functions - contrib/iostream2/ by Tyge Løvset - Another C++ I/O streams interface - contrib/untgz/ by "Pedro A. Aranda Guti\irrez" - A very simple tar.gz file extractor using zlib - contrib/visual-basic.txt by Carlos Rios - How to use compress(), uncompress() and the gz* functions from VB. -- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression - level) in minigzip (thanks to Tom Lane) - -- use const for rommable constants in deflate -- added test for gzseek and gztell in example.c -- add undocumented function inflateSyncPoint() (hack for Paul Mackerras) -- add undocumented function zError to convert error code to string - (for Tim Smithers) -- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code. -- Use default memcpy for Symantec MSDOS compiler. -- Add EXPORT keyword for check_func (needed for Windows DLL) -- add current directory to LD_LIBRARY_PATH for "make test" -- create also a link for libz.so.1 -- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura) -- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX) -- added -soname for Linux in configure (Chun-Chung Chen, -- assign numbers to the exported functions in zlib.def (for Windows DLL) -- add advice in zlib.h for best usage of deflateSetDictionary -- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn) -- allow compilation with ANSI keywords only enabled for TurboC in large model -- avoid "versionString"[0] (Borland bug) -- add NEED_DUMMY_RETURN for Borland -- use variable z_verbose for tracing in debug mode (L. Peter Deutsch). -- allow compilation with CC -- defined STDC for OS/2 (David Charlap) -- limit external names to 8 chars for MVS (Thomas Lund) -- in minigzip.c, use static buffers only for 16-bit systems -- fix suffix check for "minigzip -d foo.gz" -- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee) -- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau) -- added makelcc.bat for lcc-win32 (Tom St Denis) -- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe) -- Avoid expanded $Id: ChangeLog,v 1.1.1.1 2016/10/12 19:21:25 liu Exp $. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion. -- check for unistd.h in configure (for off_t) -- remove useless check parameter in inflate_blocks_free -- avoid useless assignment of s->check to itself in inflate_blocks_new -- do not flush twice in gzclose (thanks to Ken Raeburn) -- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h -- use NO_ERRNO_H instead of enumeration of operating systems with errno.h -- work around buggy fclose on pipes for HP/UX -- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson) -- fix configure if CC is already equal to gcc - -Changes in 1.0.5 (3 Jan 98) -- Fix inflate to terminate gracefully when fed corrupted or invalid data -- Use const for rommable constants in inflate -- Eliminate memory leaks on error conditions in inflate -- Removed some vestigial code in inflate -- Update web address in README - -Changes in 1.0.4 (24 Jul 96) -- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF - bit, so the decompressor could decompress all the correct data but went - on to attempt decompressing extra garbage data. This affected minigzip too. -- zlibVersion and gzerror return const char* (needed for DLL) -- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno) -- use z_error only for DEBUG (avoid problem with DLLs) - -Changes in 1.0.3 (2 Jul 96) -- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS - small and medium models; this makes the library incompatible with previous - versions for these models. (No effect in large model or on other systems.) -- return OK instead of BUF_ERROR if previous deflate call returned with - avail_out as zero but there is nothing to do -- added memcmp for non STDC compilers -- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly) -- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO) -- better check for 16-bit mode MSC (avoids problem with Symantec) - -Changes in 1.0.2 (23 May 96) -- added Windows DLL support -- added a function zlibVersion (for the DLL support) -- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model) -- Bytef is define's instead of typedef'd only for Borland C -- avoid reading uninitialized memory in example.c -- mention in README that the zlib format is now RFC1950 -- updated Makefile.dj2 -- added algorithm.doc - -Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion] -- fix array overlay in deflate.c which sometimes caused bad compressed data -- fix inflate bug with empty stored block -- fix MSDOS medium model which was broken in 0.99 -- fix deflateParams() which could generated bad compressed data. -- Bytef is define'd instead of typedef'ed (work around Borland bug) -- added an INDEX file -- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32), - Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas) -- speed up adler32 for modern machines without auto-increment -- added -ansi for IRIX in configure -- static_init_done in trees.c is an int -- define unlink as delete for VMS -- fix configure for QNX -- add configure branch for SCO and HPUX -- avoid many warnings (unused variables, dead assignments, etc...) -- no fdopen for BeOS -- fix the Watcom fix for 32 bit mode (define FAR as empty) -- removed redefinition of Byte for MKWERKS -- work around an MWKERKS bug (incorrect merge of all .h files) - -Changes in 0.99 (27 Jan 96) -- allow preset dictionary shared between compressor and decompressor -- allow compression level 0 (no compression) -- add deflateParams in zlib.h: allow dynamic change of compression level - and compression strategy. -- test large buffers and deflateParams in example.c -- add optional "configure" to build zlib as a shared library -- suppress Makefile.qnx, use configure instead -- fixed deflate for 64-bit systems (detected on Cray) -- fixed inflate_blocks for 64-bit systems (detected on Alpha) -- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2) -- always return Z_BUF_ERROR when deflate() has nothing to do -- deflateInit and inflateInit are now macros to allow version checking -- prefix all global functions and types with z_ with -DZ_PREFIX -- make falloc completely reentrant (inftrees.c) -- fixed very unlikely race condition in ct_static_init -- free in reverse order of allocation to help memory manager -- use zlib-1.0/* instead of zlib/* inside the tar.gz -- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith - -Wconversion -Wstrict-prototypes -Wmissing-prototypes" -- allow gzread on concatenated .gz files -- deflateEnd now returns Z_DATA_ERROR if it was premature -- deflate is finally (?) fully deterministic (no matches beyond end of input) -- Document Z_SYNC_FLUSH -- add uninstall in Makefile -- Check for __cpluplus in zlib.h -- Better test in ct_align for partial flush -- avoid harmless warnings for Borland C++ -- initialize hash_head in deflate.c -- avoid warning on fdopen (gzio.c) for HP cc -Aa -- include stdlib.h for STDC compilers -- include errno.h for Cray -- ignore error if ranlib doesn't exist -- call ranlib twice for NeXTSTEP -- use exec_prefix instead of prefix for libz.a -- renamed ct_* as _tr_* to avoid conflict with applications -- clear z->msg in inflateInit2 before any error return -- initialize opaque in example.c, gzio.c, deflate.c and inflate.c -- fixed typo in zconf.h (_GNUC__ => __GNUC__) -- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode) -- fix typo in Make_vms.com (f$trnlnm -> f$getsyi) -- in fcalloc, normalize pointer if size > 65520 bytes -- don't use special fcalloc for 32 bit Borland C++ -- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc... -- use Z_BINARY instead of BINARY -- document that gzclose after gzdopen will close the file -- allow "a" as mode in gzopen. -- fix error checking in gzread -- allow skipping .gz extra-field on pipes -- added reference to Perl interface in README -- put the crc table in FAR data (I dislike more and more the medium model :) -- added get_crc_table -- added a dimension to all arrays (Borland C can't count). -- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast -- guard against multiple inclusion of *.h (for precompiled header on Mac) -- Watcom C pretends to be Microsoft C small model even in 32 bit mode. -- don't use unsized arrays to avoid silly warnings by Visual C++: - warning C4746: 'inflate_mask' : unsized array treated as '__far' - (what's wrong with far data in far model?). -- define enum out of inflate_blocks_state to allow compilation with C++ - -Changes in 0.95 (16 Aug 95) -- fix MSDOS small and medium model (now easier to adapt to any compiler) -- inlined send_bits -- fix the final (:-) bug for deflate with flush (output was correct but - not completely flushed in rare occasions). -- default window size is same for compression and decompression - (it's now sufficient to set MAX_WBITS in zconf.h). -- voidp -> voidpf and voidnp -> voidp (for consistency with other - typedefs and because voidnp was not near in large model). - -Changes in 0.94 (13 Aug 95) -- support MSDOS medium model -- fix deflate with flush (could sometimes generate bad output) -- fix deflateReset (zlib header was incorrectly suppressed) -- added support for VMS -- allow a compression level in gzopen() -- gzflush now calls fflush -- For deflate with flush, flush even if no more input is provided. -- rename libgz.a as libz.a -- avoid complex expression in infcodes.c triggering Turbo C bug -- work around a problem with gcc on Alpha (in INSERT_STRING) -- don't use inline functions (problem with some gcc versions) -- allow renaming of Byte, uInt, etc... with #define. -- avoid warning about (unused) pointer before start of array in deflate.c -- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c -- avoid reserved word 'new' in trees.c - -Changes in 0.93 (25 June 95) -- temporarily disable inline functions -- make deflate deterministic -- give enough lookahead for PARTIAL_FLUSH -- Set binary mode for stdin/stdout in minigzip.c for OS/2 -- don't even use signed char in inflate (not portable enough) -- fix inflate memory leak for segmented architectures - -Changes in 0.92 (3 May 95) -- don't assume that char is signed (problem on SGI) -- Clear bit buffer when starting a stored block -- no memcpy on Pyramid -- suppressed inftest.c -- optimized fill_window, put longest_match inline for gcc -- optimized inflate on stored blocks. -- untabify all sources to simplify patches - -Changes in 0.91 (2 May 95) -- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h -- Document the memory requirements in zconf.h -- added "make install" -- fix sync search logic in inflateSync -- deflate(Z_FULL_FLUSH) now works even if output buffer too short -- after inflateSync, don't scare people with just "lo world" -- added support for DJGPP - -Changes in 0.9 (1 May 95) -- don't assume that zalloc clears the allocated memory (the TurboC bug - was Mark's bug after all :) -- let again gzread copy uncompressed data unchanged (was working in 0.71) -- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented -- added a test of inflateSync in example.c -- moved MAX_WBITS to zconf.h because users might want to change that. -- document explicitly that zalloc(64K) on MSDOS must return a normalized - pointer (zero offset) -- added Makefiles for Microsoft C, Turbo C, Borland C++ -- faster crc32() - -Changes in 0.8 (29 April 95) -- added fast inflate (inffast.c) -- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this - is incompatible with previous versions of zlib which returned Z_OK. -- work around a TurboC compiler bug (bad code for b << 0, see infutil.h) - (actually that was not a compiler bug, see 0.81 above) -- gzread no longer reads one extra byte in certain cases -- In gzio destroy(), don't reference a freed structure -- avoid many warnings for MSDOS -- avoid the ERROR symbol which is used by MS Windows - -Changes in 0.71 (14 April 95) -- Fixed more MSDOS compilation problems :( There is still a bug with - TurboC large model. - -Changes in 0.7 (14 April 95) -- Added full inflate support. -- Simplified the crc32() interface. The pre- and post-conditioning - (one's complement) is now done inside crc32(). WARNING: this is - incompatible with previous versions; see zlib.h for the new usage. - -Changes in 0.61 (12 April 95) -- workaround for a bug in TurboC. example and minigzip now work on MSDOS. - -Changes in 0.6 (11 April 95) -- added minigzip.c -- added gzdopen to reopen a file descriptor as gzFile -- added transparent reading of non-gziped files in gzread. -- fixed bug in gzread (don't read crc as data) -- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose). -- don't allocate big arrays in the stack (for MSDOS) -- fix some MSDOS compilation problems - -Changes in 0.5: -- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but - not yet Z_FULL_FLUSH. -- support decompression but only in a single step (forced Z_FINISH) -- added opaque object for zalloc and zfree. -- added deflateReset and inflateReset -- added a variable zlib_version for consistency checking. -- renamed the 'filter' parameter of deflateInit2 as 'strategy'. - Added Z_FILTERED and Z_HUFFMAN_ONLY constants. - -Changes in 0.4: -- avoid "zip" everywhere, use zlib instead of ziplib. -- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush - if compression method == 8. -- added adler32 and crc32 -- renamed deflateOptions as deflateInit2, call one or the other but not both -- added the method parameter for deflateInit2. -- added inflateInit2 -- simplied considerably deflateInit and inflateInit by not supporting - user-provided history buffer. This is supported only in deflateInit2 - and inflateInit2. - -Changes in 0.3: -- prefix all macro names with Z_ -- use Z_FINISH instead of deflateEnd to finish compression. -- added Z_HUFFMAN_ONLY -- added gzerror() diff --git a/cdf36_3-dist/src/lib/zlib/Makefile b/cdf36_3-dist/src/lib/zlib/Makefile deleted file mode 100644 index 7f14dac..0000000 --- a/cdf36_3-dist/src/lib/zlib/Makefile +++ /dev/null @@ -1,68 +0,0 @@ -#------------------------------------------------------------------------------ -# Copyright 1996-2016 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# All Rights Reserved. -#------------------------------------------------------------------------------ -# -# NSSDC/CDF zlib makefile. -# -# Version 1.0, 27-Mar-12, GSFC/SPDF. -# -# Modification history: -# -# V1.0 27-Mar-12, M Liu Original version. -#------------------------------------------------------------------------------ - -.SILENT: - -SHELL=/bin/sh -NULL=true - -PIC= -CCx= -COPTIONS= -MAKE=make - -INCLUDEzlib=. - -CC=$(CCx) - -CFLAGS=$(COPTIONS) $(PIC) -I$(INCLUDEzlib) -DZ_PREFIX - -OBJs= adler32.o inffast.o trees.o crc32.o inflate.o infback.o zutil.o \ -deflate.o inftrees.o - -ZLIB1h= zutil.h zlib.h zconf.h -ZLIB2h= inftrees.h inflate.h inffast.h - -#------------------------------------------------------------------------------ -# Compile/link. -#------------------------------------------------------------------------------ - -all: $(OBJs) - -.c.o: - @echo $(CC) $(CFLAGS) -c $< - $(CC) $(CFLAGS) -c $< - -adler32.o: adler32.c $(ZLIB1h) -crc32.o: crc32.c $(ZLIB1h) crc32.h -deflate.o: deflate.c $(ZLIB1h) deflate.h -inffast.o: inffast.c $(ZLIB1h) $(ZLIB2h) -inflate.o: inflate.c $(ZLIB1h) $(ZLIB2h) -infback.o: infback.c $(ZLIB1h) $(ZLIB2h) -inftrees.o: inftrees.c $(ZLIB1h) inftrees.h -trees.o: trees.c deflate.h trees.h $(ZLIB1h) -zutil.o: zutil.c $(ZLIB1h) - -#------------------------------------------------------------------------------ -# Clean/purge. -#------------------------------------------------------------------------------ - -clean: - @-rm -f *.o - @-rm -f core - -purge: - @-rm -f *~ - @-rm -f *# diff --git a/cdf36_3-dist/src/lib/zlib/adler32.c b/cdf36_3-dist/src/lib/zlib/adler32.c deleted file mode 100644 index e32d41c..0000000 --- a/cdf36_3-dist/src/lib/zlib/adler32.c +++ /dev/null @@ -1,179 +0,0 @@ -/* adler32.c -- compute the Adler-32 checksum of a data stream - * Copyright (C) 1995-2011 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id: adler32.c,v 1.1.1.1 2016/10/12 19:21:25 liu Exp $ */ - -#include "zutil.h" - -#define local static - -local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); - -#define BASE 65521 /* largest prime smaller than 65536 */ -#define NMAX 5552 -/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ - -#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} -#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); -#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); -#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); -#define DO16(buf) DO8(buf,0); DO8(buf,8); - -/* use NO_DIVIDE if your processor does not do division in hardware -- - try it both ways to see which is faster */ -#ifdef NO_DIVIDE -/* note that this assumes BASE is 65521, where 65536 % 65521 == 15 - (thank you to John Reiser for pointing this out) */ -# define CHOP(a) \ - do { \ - unsigned long tmp = a >> 16; \ - a &= 0xffffUL; \ - a += (tmp << 4) - tmp; \ - } while (0) -# define MOD28(a) \ - do { \ - CHOP(a); \ - if (a >= BASE) a -= BASE; \ - } while (0) -# define MOD(a) \ - do { \ - CHOP(a); \ - MOD28(a); \ - } while (0) -# define MOD63(a) \ - do { /* this assumes a is not negative */ \ - z_off64_t tmp = a >> 32; \ - a &= 0xffffffffL; \ - a += (tmp << 8) - (tmp << 5) + tmp; \ - tmp = a >> 16; \ - a &= 0xffffL; \ - a += (tmp << 4) - tmp; \ - tmp = a >> 16; \ - a &= 0xffffL; \ - a += (tmp << 4) - tmp; \ - if (a >= BASE) a -= BASE; \ - } while (0) -#else -# define MOD(a) a %= BASE -# define MOD28(a) a %= BASE -# define MOD63(a) a %= BASE -#endif - -/* ========================================================================= */ -uLong ZEXPORT adler32(adler, buf, len) - uLong adler; - const Bytef *buf; - uInt len; -{ - unsigned long sum2; - unsigned n; - - /* split Adler-32 into component sums */ - sum2 = (adler >> 16) & 0xffff; - adler &= 0xffff; - - /* in case user likes doing a byte at a time, keep it fast */ - if (len == 1) { - adler += buf[0]; - if (adler >= BASE) - adler -= BASE; - sum2 += adler; - if (sum2 >= BASE) - sum2 -= BASE; - return adler | (sum2 << 16); - } - - /* initial Adler-32 value (deferred check for len == 1 speed) */ - if (buf == Z_NULL) - return 1L; - - /* in case short lengths are provided, keep it somewhat fast */ - if (len < 16) { - while (len--) { - adler += *buf++; - sum2 += adler; - } - if (adler >= BASE) - adler -= BASE; - MOD28(sum2); /* only added so many BASE's */ - return adler | (sum2 << 16); - } - - /* do length NMAX blocks -- requires just one modulo operation */ - while (len >= NMAX) { - len -= NMAX; - n = NMAX / 16; /* NMAX is divisible by 16 */ - do { - DO16(buf); /* 16 sums unrolled */ - buf += 16; - } while (--n); - MOD(adler); - MOD(sum2); - } - - /* do remaining bytes (less than NMAX, still just one modulo) */ - if (len) { /* avoid modulos if none remaining */ - while (len >= 16) { - len -= 16; - DO16(buf); - buf += 16; - } - while (len--) { - adler += *buf++; - sum2 += adler; - } - MOD(adler); - MOD(sum2); - } - - /* return recombined sums */ - return adler | (sum2 << 16); -} - -/* ========================================================================= */ -local uLong adler32_combine_(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ - unsigned long sum1; - unsigned long sum2; - unsigned rem; - - /* for negative len, return invalid adler32 as a clue for debugging */ - if (len2 < 0) - return 0xffffffffUL; - - /* the derivation of this formula is left as an exercise for the reader */ - MOD63(len2); /* assumes len2 >= 0 */ - rem = (unsigned)len2; - sum1 = adler1 & 0xffff; - sum2 = rem * sum1; - MOD(sum2); - sum1 += (adler2 & 0xffff) + BASE - 1; - sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; - if (sum1 >= BASE) sum1 -= BASE; - if (sum1 >= BASE) sum1 -= BASE; - if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); - if (sum2 >= BASE) sum2 -= BASE; - return sum1 | (sum2 << 16); -} - -/* ========================================================================= */ -uLong ZEXPORT adler32_combine(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off_t len2; -{ - return adler32_combine_(adler1, adler2, len2); -} - -uLong ZEXPORT adler32_combine64(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ - return adler32_combine_(adler1, adler2, len2); -} diff --git a/cdf36_3-dist/src/lib/zlib/compress.c b/cdf36_3-dist/src/lib/zlib/compress.c deleted file mode 100644 index 50f6f08..0000000 --- a/cdf36_3-dist/src/lib/zlib/compress.c +++ /dev/null @@ -1,80 +0,0 @@ -/* compress.c -- compress a memory buffer - * Copyright (C) 1995-2005 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id: compress.c,v 1.1.1.1 2016/10/12 19:21:25 liu Exp $ */ - -#define ZLIB_INTERNAL -#include "zlib.h" - -/* =========================================================================== - Compresses the source buffer into the destination buffer. The level - parameter has the same meaning as in deflateInit. sourceLen is the byte - length of the source buffer. Upon entry, destLen is the total size of the - destination buffer, which must be at least 0.1% larger than sourceLen plus - 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. - - compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_BUF_ERROR if there was not enough room in the output buffer, - Z_STREAM_ERROR if the level parameter is invalid. -*/ -int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; - int level; -{ - z_stream stream; - int err; - - stream.next_in = (z_const Bytef *)source; - stream.avail_in = (uInt)sourceLen; -#ifdef MAXSEG_64K - /* Check for source > 64K on 16-bit machine: */ - if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; -#endif - stream.next_out = dest; - stream.avail_out = (uInt)*destLen; - if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; - - stream.zalloc = (alloc_func)0; - stream.zfree = (free_func)0; - stream.opaque = (voidpf)0; - - err = deflateInit(&stream, level); - if (err != Z_OK) return err; - - err = deflate(&stream, Z_FINISH); - if (err != Z_STREAM_END) { - deflateEnd(&stream); - return err == Z_OK ? Z_BUF_ERROR : err; - } - *destLen = stream.total_out; - - err = deflateEnd(&stream); - return err; -} - -/* =========================================================================== - */ -int ZEXPORT compress (dest, destLen, source, sourceLen) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; -{ - return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); -} - -/* =========================================================================== - If the default memLevel or windowBits for deflateInit() is changed, then - this function needs to be updated. - */ -uLong ZEXPORT compressBound (sourceLen) - uLong sourceLen; -{ - return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + - (sourceLen >> 25) + 13; -} diff --git a/cdf36_3-dist/src/lib/zlib/crc32.c b/cdf36_3-dist/src/lib/zlib/crc32.c deleted file mode 100644 index 67f89e4..0000000 --- a/cdf36_3-dist/src/lib/zlib/crc32.c +++ /dev/null @@ -1,425 +0,0 @@ -/* crc32.c -- compute the CRC-32 of a data stream - * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - * - * Thanks to Rodney Brown for his contribution of faster - * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing - * tables for updating the shift register in one step with three exclusive-ors - * instead of four steps with four exclusive-ors. This results in about a - * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. - */ - -/* @(#) $Id: crc32.c,v 1.1.1.1 2016/10/12 19:21:25 liu Exp $ */ - -/* - Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore - protection on the static variables used to control the first-use generation - of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should - first call get_crc_table() to initialize the tables before allowing more than - one thread to use crc32(). - - DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h. - */ - -#ifdef MAKECRCH -# include -# ifndef DYNAMIC_CRC_TABLE -# define DYNAMIC_CRC_TABLE -# endif /* !DYNAMIC_CRC_TABLE */ -#endif /* MAKECRCH */ - -#include "zutil.h" /* for STDC and FAR definitions */ - -#define local static - -/* Definitions for doing the crc four data bytes at a time. */ -#if !defined(NOBYFOUR) && defined(Z_U4) -# define BYFOUR -#endif -#ifdef BYFOUR - local unsigned long crc32_little OF((unsigned long, - const unsigned char FAR *, unsigned)); - local unsigned long crc32_big OF((unsigned long, - const unsigned char FAR *, unsigned)); -# define TBLS 8 -#else -# define TBLS 1 -#endif /* BYFOUR */ - -/* Local functions for crc concatenation */ -local unsigned long gf2_matrix_times OF((unsigned long *mat, - unsigned long vec)); -local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); -local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2)); - - -#ifdef DYNAMIC_CRC_TABLE - -local volatile int crc_table_empty = 1; -local z_crc_t FAR crc_table[TBLS][256]; -local void make_crc_table OF((void)); -#ifdef MAKECRCH - local void write_table OF((FILE *, const z_crc_t FAR *)); -#endif /* MAKECRCH */ -/* - Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: - x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. - - Polynomials over GF(2) are represented in binary, one bit per coefficient, - with the lowest powers in the most significant bit. Then adding polynomials - is just exclusive-or, and multiplying a polynomial by x is a right shift by - one. If we call the above polynomial p, and represent a byte as the - polynomial q, also with the lowest power in the most significant bit (so the - byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, - where a mod b means the remainder after dividing a by b. - - This calculation is done using the shift-register method of multiplying and - taking the remainder. The register is initialized to zero, and for each - incoming bit, x^32 is added mod p to the register if the bit is a one (where - x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by - x (which is shifting right by one and adding x^32 mod p if the bit shifted - out is a one). We start with the highest power (least significant bit) of - q and repeat for all eight bits of q. - - The first table is simply the CRC of all possible eight bit values. This is - all the information needed to generate CRCs on data a byte at a time for all - combinations of CRC register values and incoming bytes. The remaining tables - allow for word-at-a-time CRC calculation for both big-endian and little- - endian machines, where a word is four bytes. -*/ -local void make_crc_table() -{ - z_crc_t c; - int n, k; - z_crc_t poly; /* polynomial exclusive-or pattern */ - /* terms of polynomial defining this crc (except x^32): */ - static volatile int first = 1; /* flag to limit concurrent making */ - static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; - - /* See if another task is already doing this (not thread-safe, but better - than nothing -- significantly reduces duration of vulnerability in - case the advice about DYNAMIC_CRC_TABLE is ignored) */ - if (first) { - first = 0; - - /* make exclusive-or pattern from polynomial (0xedb88320UL) */ - poly = 0; - for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++) - poly |= (z_crc_t)1 << (31 - p[n]); - - /* generate a crc for every 8-bit value */ - for (n = 0; n < 256; n++) { - c = (z_crc_t)n; - for (k = 0; k < 8; k++) - c = c & 1 ? poly ^ (c >> 1) : c >> 1; - crc_table[0][n] = c; - } - -#ifdef BYFOUR - /* generate crc for each value followed by one, two, and three zeros, - and then the byte reversal of those as well as the first table */ - for (n = 0; n < 256; n++) { - c = crc_table[0][n]; - crc_table[4][n] = ZSWAP32(c); - for (k = 1; k < 4; k++) { - c = crc_table[0][c & 0xff] ^ (c >> 8); - crc_table[k][n] = c; - crc_table[k + 4][n] = ZSWAP32(c); - } - } -#endif /* BYFOUR */ - - crc_table_empty = 0; - } - else { /* not first */ - /* wait for the other guy to finish (not efficient, but rare) */ - while (crc_table_empty) - ; - } - -#ifdef MAKECRCH - /* write out CRC tables to crc32.h */ - { - FILE *out; - - out = fopen("crc32.h", "w"); - if (out == NULL) return; - fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); - fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); - fprintf(out, "local const z_crc_t FAR "); - fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); - write_table(out, crc_table[0]); -# ifdef BYFOUR - fprintf(out, "#ifdef BYFOUR\n"); - for (k = 1; k < 8; k++) { - fprintf(out, " },\n {\n"); - write_table(out, crc_table[k]); - } - fprintf(out, "#endif\n"); -# endif /* BYFOUR */ - fprintf(out, " }\n};\n"); - fclose(out); - } -#endif /* MAKECRCH */ -} - -#ifdef MAKECRCH -local void write_table(out, table) - FILE *out; - const z_crc_t FAR *table; -{ - int n; - - for (n = 0; n < 256; n++) - fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", - (unsigned long)(table[n]), - n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); -} -#endif /* MAKECRCH */ - -#else /* !DYNAMIC_CRC_TABLE */ -/* ======================================================================== - * Tables of CRC-32s of all single-byte values, made by make_crc_table(). - */ -#include "crc32.h" -#endif /* DYNAMIC_CRC_TABLE */ - -/* ========================================================================= - * This function can be used by asm versions of crc32() - */ -const z_crc_t FAR * ZEXPORT get_crc_table() -{ -#ifdef DYNAMIC_CRC_TABLE - if (crc_table_empty) - make_crc_table(); -#endif /* DYNAMIC_CRC_TABLE */ - return (const z_crc_t FAR *)crc_table; -} - -/* ========================================================================= */ -#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) -#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 - -/* ========================================================================= */ -unsigned long ZEXPORT crc32(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - uInt len; -{ - if (buf == Z_NULL) return 0UL; - -#ifdef DYNAMIC_CRC_TABLE - if (crc_table_empty) - make_crc_table(); -#endif /* DYNAMIC_CRC_TABLE */ - -#ifdef BYFOUR - if (sizeof(void *) == sizeof(ptrdiff_t)) { - z_crc_t endian; - - endian = 1; - if (*((unsigned char *)(&endian))) - return crc32_little(crc, buf, len); - else - return crc32_big(crc, buf, len); - } -#endif /* BYFOUR */ - crc = crc ^ 0xffffffffUL; - while (len >= 8) { - DO8; - len -= 8; - } - if (len) do { - DO1; - } while (--len); - return crc ^ 0xffffffffUL; -} - -#ifdef BYFOUR - -/* ========================================================================= */ -#define DOLIT4 c ^= *buf4++; \ - c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ - crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] -#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 - -/* ========================================================================= */ -local unsigned long crc32_little(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - unsigned len; -{ - register z_crc_t c; - register const z_crc_t FAR *buf4; - - c = (z_crc_t)crc; - c = ~c; - while (len && ((ptrdiff_t)buf & 3)) { - c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); - len--; - } - - buf4 = (const z_crc_t FAR *)(const void FAR *)buf; - while (len >= 32) { - DOLIT32; - len -= 32; - } - while (len >= 4) { - DOLIT4; - len -= 4; - } - buf = (const unsigned char FAR *)buf4; - - if (len) do { - c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); - } while (--len); - c = ~c; - return (unsigned long)c; -} - -/* ========================================================================= */ -#define DOBIG4 c ^= *++buf4; \ - c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ - crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] -#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 - -/* ========================================================================= */ -local unsigned long crc32_big(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - unsigned len; -{ - register z_crc_t c; - register const z_crc_t FAR *buf4; - - c = ZSWAP32((z_crc_t)crc); - c = ~c; - while (len && ((ptrdiff_t)buf & 3)) { - c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); - len--; - } - - buf4 = (const z_crc_t FAR *)(const void FAR *)buf; - buf4--; - while (len >= 32) { - DOBIG32; - len -= 32; - } - while (len >= 4) { - DOBIG4; - len -= 4; - } - buf4++; - buf = (const unsigned char FAR *)buf4; - - if (len) do { - c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); - } while (--len); - c = ~c; - return (unsigned long)(ZSWAP32(c)); -} - -#endif /* BYFOUR */ - -#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ - -/* ========================================================================= */ -local unsigned long gf2_matrix_times(mat, vec) - unsigned long *mat; - unsigned long vec; -{ - unsigned long sum; - - sum = 0; - while (vec) { - if (vec & 1) - sum ^= *mat; - vec >>= 1; - mat++; - } - return sum; -} - -/* ========================================================================= */ -local void gf2_matrix_square(square, mat) - unsigned long *square; - unsigned long *mat; -{ - int n; - - for (n = 0; n < GF2_DIM; n++) - square[n] = gf2_matrix_times(mat, mat[n]); -} - -/* ========================================================================= */ -local uLong crc32_combine_(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off64_t len2; -{ - int n; - unsigned long row; - unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ - unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ - - /* degenerate case (also disallow negative lengths) */ - if (len2 <= 0) - return crc1; - - /* put operator for one zero bit in odd */ - odd[0] = 0xedb88320UL; /* CRC-32 polynomial */ - row = 1; - for (n = 1; n < GF2_DIM; n++) { - odd[n] = row; - row <<= 1; - } - - /* put operator for two zero bits in even */ - gf2_matrix_square(even, odd); - - /* put operator for four zero bits in odd */ - gf2_matrix_square(odd, even); - - /* apply len2 zeros to crc1 (first square will put the operator for one - zero byte, eight zero bits, in even) */ - do { - /* apply zeros operator for this bit of len2 */ - gf2_matrix_square(even, odd); - if (len2 & 1) - crc1 = gf2_matrix_times(even, crc1); - len2 >>= 1; - - /* if no more bits set, then done */ - if (len2 == 0) - break; - - /* another iteration of the loop with odd and even swapped */ - gf2_matrix_square(odd, even); - if (len2 & 1) - crc1 = gf2_matrix_times(odd, crc1); - len2 >>= 1; - - /* if no more bits set, then done */ - } while (len2 != 0); - - /* return combined crc */ - crc1 ^= crc2; - return crc1; -} - -/* ========================================================================= */ -uLong ZEXPORT crc32_combine(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off_t len2; -{ - return crc32_combine_(crc1, crc2, len2); -} - -uLong ZEXPORT crc32_combine64(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off64_t len2; -{ - return crc32_combine_(crc1, crc2, len2); -} diff --git a/cdf36_3-dist/src/lib/zlib/crc32.h b/cdf36_3-dist/src/lib/zlib/crc32.h deleted file mode 100644 index 9e0c778..0000000 --- a/cdf36_3-dist/src/lib/zlib/crc32.h +++ /dev/null @@ -1,441 +0,0 @@ -/* crc32.h -- tables for rapid CRC calculation - * Generated automatically by crc32.c - */ - -local const z_crc_t FAR crc_table[TBLS][256] = -{ - { - 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL, - 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL, - 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL, - 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL, - 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL, - 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL, - 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL, - 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL, - 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL, - 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL, - 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL, - 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL, - 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL, - 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL, - 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL, - 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL, - 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL, - 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL, - 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL, - 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL, - 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL, - 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL, - 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL, - 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL, - 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL, - 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL, - 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL, - 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL, - 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL, - 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL, - 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL, - 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL, - 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL, - 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL, - 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL, - 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL, - 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL, - 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL, - 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL, - 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL, - 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL, - 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL, - 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL, - 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL, - 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL, - 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL, - 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL, - 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL, - 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL, - 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL, - 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL, - 0x2d02ef8dUL -#ifdef BYFOUR - }, - { - 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL, - 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL, - 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL, - 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL, - 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL, - 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL, - 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL, - 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL, - 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL, - 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL, - 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL, - 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL, - 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL, - 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL, - 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL, - 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL, - 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL, - 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL, - 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL, - 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL, - 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL, - 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL, - 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL, - 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL, - 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL, - 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL, - 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL, - 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL, - 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL, - 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL, - 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL, - 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL, - 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL, - 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL, - 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL, - 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL, - 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL, - 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL, - 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL, - 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL, - 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL, - 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL, - 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL, - 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL, - 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL, - 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL, - 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL, - 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL, - 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL, - 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL, - 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL, - 0x9324fd72UL - }, - { - 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL, - 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL, - 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL, - 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL, - 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL, - 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL, - 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL, - 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL, - 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL, - 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL, - 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL, - 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL, - 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL, - 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL, - 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL, - 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL, - 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL, - 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL, - 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL, - 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL, - 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL, - 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL, - 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL, - 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL, - 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL, - 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL, - 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL, - 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL, - 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL, - 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL, - 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL, - 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL, - 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL, - 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL, - 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL, - 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL, - 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL, - 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL, - 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL, - 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL, - 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL, - 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL, - 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL, - 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL, - 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL, - 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL, - 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL, - 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL, - 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL, - 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL, - 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL, - 0xbe9834edUL - }, - { - 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL, - 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL, - 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL, - 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL, - 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL, - 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL, - 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL, - 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL, - 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL, - 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL, - 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL, - 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL, - 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL, - 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL, - 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL, - 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL, - 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL, - 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL, - 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL, - 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL, - 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL, - 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL, - 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL, - 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL, - 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL, - 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL, - 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL, - 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL, - 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL, - 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL, - 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL, - 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL, - 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL, - 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL, - 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL, - 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL, - 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL, - 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL, - 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL, - 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL, - 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL, - 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL, - 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL, - 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL, - 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL, - 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL, - 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL, - 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL, - 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL, - 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL, - 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL, - 0xde0506f1UL - }, - { - 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL, - 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL, - 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL, - 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL, - 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL, - 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL, - 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL, - 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL, - 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL, - 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL, - 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL, - 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL, - 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL, - 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL, - 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL, - 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL, - 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL, - 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL, - 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL, - 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL, - 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL, - 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL, - 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL, - 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL, - 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL, - 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL, - 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL, - 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL, - 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL, - 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL, - 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL, - 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL, - 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL, - 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL, - 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL, - 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL, - 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL, - 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL, - 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL, - 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL, - 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL, - 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL, - 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL, - 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL, - 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL, - 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL, - 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL, - 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL, - 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL, - 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL, - 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL, - 0x8def022dUL - }, - { - 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL, - 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL, - 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL, - 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL, - 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL, - 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL, - 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL, - 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL, - 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL, - 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL, - 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL, - 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL, - 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL, - 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL, - 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL, - 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL, - 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL, - 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL, - 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL, - 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL, - 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL, - 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL, - 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL, - 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL, - 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL, - 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL, - 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL, - 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL, - 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL, - 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL, - 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL, - 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL, - 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL, - 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL, - 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL, - 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL, - 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL, - 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL, - 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL, - 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL, - 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL, - 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL, - 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL, - 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL, - 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL, - 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL, - 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL, - 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL, - 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL, - 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL, - 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL, - 0x72fd2493UL - }, - { - 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL, - 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL, - 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL, - 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL, - 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL, - 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL, - 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL, - 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL, - 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL, - 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL, - 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL, - 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL, - 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL, - 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL, - 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL, - 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL, - 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL, - 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL, - 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL, - 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL, - 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL, - 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL, - 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL, - 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL, - 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL, - 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL, - 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL, - 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL, - 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL, - 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL, - 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL, - 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL, - 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL, - 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL, - 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL, - 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL, - 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL, - 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL, - 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL, - 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL, - 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL, - 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL, - 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL, - 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL, - 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL, - 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL, - 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL, - 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL, - 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL, - 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL, - 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL, - 0xed3498beUL - }, - { - 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL, - 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL, - 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL, - 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL, - 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL, - 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL, - 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL, - 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL, - 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL, - 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL, - 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL, - 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL, - 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL, - 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL, - 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL, - 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL, - 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL, - 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL, - 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL, - 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL, - 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL, - 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL, - 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL, - 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL, - 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL, - 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL, - 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL, - 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL, - 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL, - 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL, - 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL, - 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL, - 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL, - 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL, - 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL, - 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL, - 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL, - 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL, - 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL, - 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL, - 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL, - 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL, - 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL, - 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL, - 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL, - 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL, - 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL, - 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL, - 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL, - 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL, - 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL, - 0xf10605deUL -#endif - } -}; diff --git a/cdf36_3-dist/src/lib/zlib/deflate.c b/cdf36_3-dist/src/lib/zlib/deflate.c deleted file mode 100644 index 1101507..0000000 --- a/cdf36_3-dist/src/lib/zlib/deflate.c +++ /dev/null @@ -1,1967 +0,0 @@ -/* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * ALGORITHM - * - * The "deflation" process depends on being able to identify portions - * of the input text which are identical to earlier input (within a - * sliding window trailing behind the input currently being processed). - * - * The most straightforward technique turns out to be the fastest for - * most input files: try all possible matches and select the longest. - * The key feature of this algorithm is that insertions into the string - * dictionary are very simple and thus fast, and deletions are avoided - * completely. Insertions are performed at each input character, whereas - * string matches are performed only when the previous match ends. So it - * is preferable to spend more time in matches to allow very fast string - * insertions and avoid deletions. The matching algorithm for small - * strings is inspired from that of Rabin & Karp. A brute force approach - * is used to find longer strings when a small match has been found. - * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze - * (by Leonid Broukhis). - * A previous version of this file used a more sophisticated algorithm - * (by Fiala and Greene) which is guaranteed to run in linear amortized - * time, but has a larger average cost, uses more memory and is patented. - * However the F&G algorithm may be faster for some highly redundant - * files if the parameter max_chain_length (described below) is too large. - * - * ACKNOWLEDGEMENTS - * - * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and - * I found it in 'freeze' written by Leonid Broukhis. - * Thanks to many people for bug reports and testing. - * - * REFERENCES - * - * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". - * Available in http://tools.ietf.org/html/rfc1951 - * - * A description of the Rabin and Karp algorithm is given in the book - * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. - * - * Fiala,E.R., and Greene,D.H. - * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 - * - */ - -/* @(#) $Id: deflate.c,v 1.1.1.1 2016/10/12 19:21:25 liu Exp $ */ - -#include "deflate.h" - -const char deflate_copyright[] = - " deflate 1.2.8 Copyright 1995-2013 Jean-loup Gailly and Mark Adler "; -/* - If you use the zlib library in a product, an acknowledgment is welcome - in the documentation of your product. If for some reason you cannot - include such an acknowledgment, I would appreciate that you keep this - copyright string in the executable of your product. - */ - -/* =========================================================================== - * Function prototypes. - */ -typedef enum { - need_more, /* block not completed, need more input or more output */ - block_done, /* block flush performed */ - finish_started, /* finish started, need only more output at next deflate */ - finish_done /* finish done, accept no more input or output */ -} block_state; - -typedef block_state (*compress_func) OF((deflate_state *s, int flush)); -/* Compression function. Returns the block state after the call. */ - -local void fill_window OF((deflate_state *s)); -local block_state deflate_stored OF((deflate_state *s, int flush)); -local block_state deflate_fast OF((deflate_state *s, int flush)); -#ifndef FASTEST -local block_state deflate_slow OF((deflate_state *s, int flush)); -#endif -local block_state deflate_rle OF((deflate_state *s, int flush)); -local block_state deflate_huff OF((deflate_state *s, int flush)); -local void lm_init OF((deflate_state *s)); -local void putShortMSB OF((deflate_state *s, uInt b)); -local void flush_pending OF((z_streamp strm)); -local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); -#ifdef ASMV - void match_init OF((void)); /* asm code initialization */ - uInt longest_match OF((deflate_state *s, IPos cur_match)); -#else -local uInt longest_match OF((deflate_state *s, IPos cur_match)); -#endif - -#ifdef DEBUG -local void check_match OF((deflate_state *s, IPos start, IPos match, - int length)); -#endif - -/* =========================================================================== - * Local data - */ - -#define NIL 0 -/* Tail of hash chains */ - -#ifndef TOO_FAR -# define TOO_FAR 4096 -#endif -/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ - -/* Values for max_lazy_match, good_match and max_chain_length, depending on - * the desired pack level (0..9). The values given below have been tuned to - * exclude worst case performance for pathological files. Better values may be - * found for specific files. - */ -typedef struct config_s { - ush good_length; /* reduce lazy search above this match length */ - ush max_lazy; /* do not perform lazy search above this match length */ - ush nice_length; /* quit search above this match length */ - ush max_chain; - compress_func func; -} config; - -#ifdef FASTEST -local const config configuration_table[2] = { -/* good lazy nice chain */ -/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ -/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */ -#else -local const config configuration_table[10] = { -/* good lazy nice chain */ -/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ -/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */ -/* 2 */ {4, 5, 16, 8, deflate_fast}, -/* 3 */ {4, 6, 32, 32, deflate_fast}, - -/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ -/* 5 */ {8, 16, 32, 32, deflate_slow}, -/* 6 */ {8, 16, 128, 128, deflate_slow}, -/* 7 */ {8, 32, 128, 256, deflate_slow}, -/* 8 */ {32, 128, 258, 1024, deflate_slow}, -/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */ -#endif - -/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 - * For deflate_fast() (levels <= 3) good is ignored and lazy has a different - * meaning. - */ - -#define EQUAL 0 -/* result of memcmp for equal strings */ - -#ifndef NO_DUMMY_DECL -struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ -#endif - -/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */ -#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0)) - -/* =========================================================================== - * Update a hash value with the given input byte - * IN assertion: all calls to to UPDATE_HASH are made with consecutive - * input characters, so that a running hash key can be computed from the - * previous key instead of complete recalculation each time. - */ -#define UPDATE_HASH(s,h,c) (h = (((h)<hash_shift) ^ (c)) & s->hash_mask) - - -/* =========================================================================== - * Insert string str in the dictionary and set match_head to the previous head - * of the hash chain (the most recent string with same hash key). Return - * the previous length of the hash chain. - * If this file is compiled with -DFASTEST, the compression level is forced - * to 1, and no hash chains are maintained. - * IN assertion: all calls to to INSERT_STRING are made with consecutive - * input characters and the first MIN_MATCH bytes of str are valid - * (except for the last MIN_MATCH-1 bytes of the input file). - */ -#ifdef FASTEST -#define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - match_head = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) -#else -#define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) -#endif - -/* =========================================================================== - * Initialize the hash table (avoiding 64K overflow for 16 bit systems). - * prev[] will be initialized on the fly. - */ -#define CLEAR_HASH(s) \ - s->head[s->hash_size-1] = NIL; \ - zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); - -/* ========================================================================= */ -int ZEXPORT deflateInit_(strm, level, version, stream_size) - z_streamp strm; - int level; - const char *version; - int stream_size; -{ - return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, version, stream_size); - /* To do: ignore strm->next_in if we use it as window */ -} - -/* ========================================================================= */ -int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, - version, stream_size) - z_streamp strm; - int level; - int method; - int windowBits; - int memLevel; - int strategy; - const char *version; - int stream_size; -{ - deflate_state *s; - int wrap = 1; - static const char my_version[] = ZLIB_VERSION; - - ushf *overlay; - /* We overlay pending_buf and d_buf+l_buf. This works since the average - * output size for (length,distance) codes is <= 24 bits. - */ - - if (version == Z_NULL || version[0] != my_version[0] || - stream_size != sizeof(z_stream)) { - return Z_VERSION_ERROR; - } - if (strm == Z_NULL) return Z_STREAM_ERROR; - - strm->msg = Z_NULL; - if (strm->zalloc == (alloc_func)0) { -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; -#endif - } - if (strm->zfree == (free_func)0) -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zfree = zcfree; -#endif - -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif - - if (windowBits < 0) { /* suppress zlib wrapper */ - wrap = 0; - windowBits = -windowBits; - } -#ifdef GZIP - else if (windowBits > 15) { - wrap = 2; /* write gzip wrapper instead */ - windowBits -= 16; - } -#endif - if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || - windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || - strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; - } - if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ - s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); - if (s == Z_NULL) return Z_MEM_ERROR; - strm->state = (struct internal_state FAR *)s; - s->strm = strm; - - s->wrap = wrap; - s->gzhead = Z_NULL; - s->w_bits = windowBits; - s->w_size = 1 << s->w_bits; - s->w_mask = s->w_size - 1; - - s->hash_bits = memLevel + 7; - s->hash_size = 1 << s->hash_bits; - s->hash_mask = s->hash_size - 1; - s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); - - s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); - s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); - s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); - - s->high_water = 0; /* nothing written to s->window yet */ - - s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ - - overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); - s->pending_buf = (uchf *) overlay; - s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); - - if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || - s->pending_buf == Z_NULL) { - s->status = FINISH_STATE; - strm->msg = ERR_MSG(Z_MEM_ERROR); - deflateEnd (strm); - return Z_MEM_ERROR; - } - s->d_buf = overlay + s->lit_bufsize/sizeof(ush); - s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; - - s->level = level; - s->strategy = strategy; - s->method = (Byte)method; - - return deflateReset(strm); -} - -/* ========================================================================= */ -int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) - z_streamp strm; - const Bytef *dictionary; - uInt dictLength; -{ - deflate_state *s; - uInt str, n; - int wrap; - unsigned avail; - z_const unsigned char *next; - - if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL) - return Z_STREAM_ERROR; - s = strm->state; - wrap = s->wrap; - if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead) - return Z_STREAM_ERROR; - - /* when using zlib wrappers, compute Adler-32 for provided dictionary */ - if (wrap == 1) - strm->adler = adler32(strm->adler, dictionary, dictLength); - s->wrap = 0; /* avoid computing Adler-32 in read_buf */ - - /* if dictionary would fill window, just replace the history */ - if (dictLength >= s->w_size) { - if (wrap == 0) { /* already empty otherwise */ - CLEAR_HASH(s); - s->strstart = 0; - s->block_start = 0L; - s->insert = 0; - } - dictionary += dictLength - s->w_size; /* use the tail */ - dictLength = s->w_size; - } - - /* insert dictionary into window and hash */ - avail = strm->avail_in; - next = strm->next_in; - strm->avail_in = dictLength; - strm->next_in = (z_const Bytef *)dictionary; - fill_window(s); - while (s->lookahead >= MIN_MATCH) { - str = s->strstart; - n = s->lookahead - (MIN_MATCH-1); - do { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - } while (--n); - s->strstart = str; - s->lookahead = MIN_MATCH-1; - fill_window(s); - } - s->strstart += s->lookahead; - s->block_start = (long)s->strstart; - s->insert = s->lookahead; - s->lookahead = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - strm->next_in = next; - strm->avail_in = avail; - s->wrap = wrap; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateResetKeep (strm) - z_streamp strm; -{ - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL || - strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) { - return Z_STREAM_ERROR; - } - - strm->total_in = strm->total_out = 0; - strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ - strm->data_type = Z_UNKNOWN; - - s = (deflate_state *)strm->state; - s->pending = 0; - s->pending_out = s->pending_buf; - - if (s->wrap < 0) { - s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ - } - s->status = s->wrap ? INIT_STATE : BUSY_STATE; - strm->adler = -#ifdef GZIP - s->wrap == 2 ? crc32(0L, Z_NULL, 0) : -#endif - adler32(0L, Z_NULL, 0); - s->last_flush = Z_NO_FLUSH; - - _tr_init(s); - - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateReset (strm) - z_streamp strm; -{ - int ret; - - ret = deflateResetKeep(strm); - if (ret == Z_OK) - lm_init(strm->state); - return ret; -} - -/* ========================================================================= */ -int ZEXPORT deflateSetHeader (strm, head) - z_streamp strm; - gz_headerp head; -{ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - if (strm->state->wrap != 2) return Z_STREAM_ERROR; - strm->state->gzhead = head; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflatePending (strm, pending, bits) - unsigned *pending; - int *bits; - z_streamp strm; -{ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - if (pending != Z_NULL) - *pending = strm->state->pending; - if (bits != Z_NULL) - *bits = strm->state->bi_valid; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflatePrime (strm, bits, value) - z_streamp strm; - int bits; - int value; -{ - deflate_state *s; - int put; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - s = strm->state; - if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3)) - return Z_BUF_ERROR; - do { - put = Buf_size - s->bi_valid; - if (put > bits) - put = bits; - s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid); - s->bi_valid += put; - _tr_flush_bits(s); - value >>= put; - bits -= put; - } while (bits); - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateParams(strm, level, strategy) - z_streamp strm; - int level; - int strategy; -{ - deflate_state *s; - compress_func func; - int err = Z_OK; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - s = strm->state; - -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif - if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; - } - func = configuration_table[s->level].func; - - if ((strategy != s->strategy || func != configuration_table[level].func) && - strm->total_in != 0) { - /* Flush the last buffer: */ - err = deflate(strm, Z_BLOCK); - if (err == Z_BUF_ERROR && s->pending == 0) - err = Z_OK; - } - if (s->level != level) { - s->level = level; - s->max_lazy_match = configuration_table[level].max_lazy; - s->good_match = configuration_table[level].good_length; - s->nice_match = configuration_table[level].nice_length; - s->max_chain_length = configuration_table[level].max_chain; - } - s->strategy = strategy; - return err; -} - -/* ========================================================================= */ -int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) - z_streamp strm; - int good_length; - int max_lazy; - int nice_length; - int max_chain; -{ - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - s = strm->state; - s->good_match = good_length; - s->max_lazy_match = max_lazy; - s->nice_match = nice_length; - s->max_chain_length = max_chain; - return Z_OK; -} - -/* ========================================================================= - * For the default windowBits of 15 and memLevel of 8, this function returns - * a close to exact, as well as small, upper bound on the compressed size. - * They are coded as constants here for a reason--if the #define's are - * changed, then this function needs to be changed as well. The return - * value for 15 and 8 only works for those exact settings. - * - * For any setting other than those defaults for windowBits and memLevel, - * the value returned is a conservative worst case for the maximum expansion - * resulting from using fixed blocks instead of stored blocks, which deflate - * can emit on compressed data for some combinations of the parameters. - * - * This function could be more sophisticated to provide closer upper bounds for - * every combination of windowBits and memLevel. But even the conservative - * upper bound of about 14% expansion does not seem onerous for output buffer - * allocation. - */ -uLong ZEXPORT deflateBound(strm, sourceLen) - z_streamp strm; - uLong sourceLen; -{ - deflate_state *s; - uLong complen, wraplen; - Bytef *str; - - /* conservative upper bound for compressed data */ - complen = sourceLen + - ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; - - /* if can't get parameters, return conservative bound plus zlib wrapper */ - if (strm == Z_NULL || strm->state == Z_NULL) - return complen + 6; - - /* compute wrapper length */ - s = strm->state; - switch (s->wrap) { - case 0: /* raw deflate */ - wraplen = 0; - break; - case 1: /* zlib wrapper */ - wraplen = 6 + (s->strstart ? 4 : 0); - break; - case 2: /* gzip wrapper */ - wraplen = 18; - if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ - if (s->gzhead->extra != Z_NULL) - wraplen += 2 + s->gzhead->extra_len; - str = s->gzhead->name; - if (str != Z_NULL) - do { - wraplen++; - } while (*str++); - str = s->gzhead->comment; - if (str != Z_NULL) - do { - wraplen++; - } while (*str++); - if (s->gzhead->hcrc) - wraplen += 2; - } - break; - default: /* for compiler happiness */ - wraplen = 6; - } - - /* if not default parameters, return conservative bound */ - if (s->w_bits != 15 || s->hash_bits != 8 + 7) - return complen + wraplen; - - /* default settings: return tight bound for that case */ - return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + - (sourceLen >> 25) + 13 - 6 + wraplen; -} - -/* ========================================================================= - * Put a short in the pending buffer. The 16-bit value is put in MSB order. - * IN assertion: the stream state is correct and there is enough room in - * pending_buf. - */ -local void putShortMSB (s, b) - deflate_state *s; - uInt b; -{ - put_byte(s, (Byte)(b >> 8)); - put_byte(s, (Byte)(b & 0xff)); -} - -/* ========================================================================= - * Flush as much pending output as possible. All deflate() output goes - * through this function so some applications may wish to modify it - * to avoid allocating a large strm->next_out buffer and copying into it. - * (See also read_buf()). - */ -local void flush_pending(strm) - z_streamp strm; -{ - unsigned len; - deflate_state *s = strm->state; - - _tr_flush_bits(s); - len = s->pending; - if (len > strm->avail_out) len = strm->avail_out; - if (len == 0) return; - - zmemcpy(strm->next_out, s->pending_out, len); - strm->next_out += len; - s->pending_out += len; - strm->total_out += len; - strm->avail_out -= len; - s->pending -= len; - if (s->pending == 0) { - s->pending_out = s->pending_buf; - } -} - -/* ========================================================================= */ -int ZEXPORT deflate (strm, flush) - z_streamp strm; - int flush; -{ - int old_flush; /* value of flush param for previous deflate call */ - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL || - flush > Z_BLOCK || flush < 0) { - return Z_STREAM_ERROR; - } - s = strm->state; - - if (strm->next_out == Z_NULL || - (strm->next_in == Z_NULL && strm->avail_in != 0) || - (s->status == FINISH_STATE && flush != Z_FINISH)) { - ERR_RETURN(strm, Z_STREAM_ERROR); - } - if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); - - s->strm = strm; /* just in case */ - old_flush = s->last_flush; - s->last_flush = flush; - - /* Write the header */ - if (s->status == INIT_STATE) { -#ifdef GZIP - if (s->wrap == 2) { - strm->adler = crc32(0L, Z_NULL, 0); - put_byte(s, 31); - put_byte(s, 139); - put_byte(s, 8); - if (s->gzhead == Z_NULL) { - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, s->level == 9 ? 2 : - (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? - 4 : 0)); - put_byte(s, OS_CODE); - s->status = BUSY_STATE; - } - else { - put_byte(s, (s->gzhead->text ? 1 : 0) + - (s->gzhead->hcrc ? 2 : 0) + - (s->gzhead->extra == Z_NULL ? 0 : 4) + - (s->gzhead->name == Z_NULL ? 0 : 8) + - (s->gzhead->comment == Z_NULL ? 0 : 16) - ); - put_byte(s, (Byte)(s->gzhead->time & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); - put_byte(s, s->level == 9 ? 2 : - (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? - 4 : 0)); - put_byte(s, s->gzhead->os & 0xff); - if (s->gzhead->extra != Z_NULL) { - put_byte(s, s->gzhead->extra_len & 0xff); - put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); - } - if (s->gzhead->hcrc) - strm->adler = crc32(strm->adler, s->pending_buf, - s->pending); - s->gzindex = 0; - s->status = EXTRA_STATE; - } - } - else -#endif - { - uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; - uInt level_flags; - - if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) - level_flags = 0; - else if (s->level < 6) - level_flags = 1; - else if (s->level == 6) - level_flags = 2; - else - level_flags = 3; - header |= (level_flags << 6); - if (s->strstart != 0) header |= PRESET_DICT; - header += 31 - (header % 31); - - s->status = BUSY_STATE; - putShortMSB(s, header); - - /* Save the adler32 of the preset dictionary: */ - if (s->strstart != 0) { - putShortMSB(s, (uInt)(strm->adler >> 16)); - putShortMSB(s, (uInt)(strm->adler & 0xffff)); - } - strm->adler = adler32(0L, Z_NULL, 0); - } - } -#ifdef GZIP - if (s->status == EXTRA_STATE) { - if (s->gzhead->extra != Z_NULL) { - uInt beg = s->pending; /* start of bytes to update crc */ - - while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { - if (s->pending == s->pending_buf_size) { - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - flush_pending(strm); - beg = s->pending; - if (s->pending == s->pending_buf_size) - break; - } - put_byte(s, s->gzhead->extra[s->gzindex]); - s->gzindex++; - } - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - if (s->gzindex == s->gzhead->extra_len) { - s->gzindex = 0; - s->status = NAME_STATE; - } - } - else - s->status = NAME_STATE; - } - if (s->status == NAME_STATE) { - if (s->gzhead->name != Z_NULL) { - uInt beg = s->pending; /* start of bytes to update crc */ - int val; - - do { - if (s->pending == s->pending_buf_size) { - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - flush_pending(strm); - beg = s->pending; - if (s->pending == s->pending_buf_size) { - val = 1; - break; - } - } - val = s->gzhead->name[s->gzindex++]; - put_byte(s, val); - } while (val != 0); - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - if (val == 0) { - s->gzindex = 0; - s->status = COMMENT_STATE; - } - } - else - s->status = COMMENT_STATE; - } - if (s->status == COMMENT_STATE) { - if (s->gzhead->comment != Z_NULL) { - uInt beg = s->pending; /* start of bytes to update crc */ - int val; - - do { - if (s->pending == s->pending_buf_size) { - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - flush_pending(strm); - beg = s->pending; - if (s->pending == s->pending_buf_size) { - val = 1; - break; - } - } - val = s->gzhead->comment[s->gzindex++]; - put_byte(s, val); - } while (val != 0); - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - if (val == 0) - s->status = HCRC_STATE; - } - else - s->status = HCRC_STATE; - } - if (s->status == HCRC_STATE) { - if (s->gzhead->hcrc) { - if (s->pending + 2 > s->pending_buf_size) - flush_pending(strm); - if (s->pending + 2 <= s->pending_buf_size) { - put_byte(s, (Byte)(strm->adler & 0xff)); - put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); - strm->adler = crc32(0L, Z_NULL, 0); - s->status = BUSY_STATE; - } - } - else - s->status = BUSY_STATE; - } -#endif - - /* Flush as much pending output as possible */ - if (s->pending != 0) { - flush_pending(strm); - if (strm->avail_out == 0) { - /* Since avail_out is 0, deflate will be called again with - * more output space, but possibly with both pending and - * avail_in equal to zero. There won't be anything to do, - * but this is not an error situation so make sure we - * return OK instead of BUF_ERROR at next call of deflate: - */ - s->last_flush = -1; - return Z_OK; - } - - /* Make sure there is something to do and avoid duplicate consecutive - * flushes. For repeated and useless calls with Z_FINISH, we keep - * returning Z_STREAM_END instead of Z_BUF_ERROR. - */ - } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) && - flush != Z_FINISH) { - ERR_RETURN(strm, Z_BUF_ERROR); - } - - /* User must not provide more input after the first FINISH: */ - if (s->status == FINISH_STATE && strm->avail_in != 0) { - ERR_RETURN(strm, Z_BUF_ERROR); - } - - /* Start a new block or continue the current one. - */ - if (strm->avail_in != 0 || s->lookahead != 0 || - (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { - block_state bstate; - - bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : - (s->strategy == Z_RLE ? deflate_rle(s, flush) : - (*(configuration_table[s->level].func))(s, flush)); - - if (bstate == finish_started || bstate == finish_done) { - s->status = FINISH_STATE; - } - if (bstate == need_more || bstate == finish_started) { - if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ - } - return Z_OK; - /* If flush != Z_NO_FLUSH && avail_out == 0, the next call - * of deflate should use the same flush parameter to make sure - * that the flush is complete. So we don't have to output an - * empty block here, this will be done at next call. This also - * ensures that for a very small output buffer, we emit at most - * one empty block. - */ - } - if (bstate == block_done) { - if (flush == Z_PARTIAL_FLUSH) { - _tr_align(s); - } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ - _tr_stored_block(s, (char*)0, 0L, 0); - /* For a full flush, this empty block will be recognized - * as a special marker by inflate_sync(). - */ - if (flush == Z_FULL_FLUSH) { - CLEAR_HASH(s); /* forget history */ - if (s->lookahead == 0) { - s->strstart = 0; - s->block_start = 0L; - s->insert = 0; - } - } - } - flush_pending(strm); - if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ - return Z_OK; - } - } - } - Assert(strm->avail_out > 0, "bug2"); - - if (flush != Z_FINISH) return Z_OK; - if (s->wrap <= 0) return Z_STREAM_END; - - /* Write the trailer */ -#ifdef GZIP - if (s->wrap == 2) { - put_byte(s, (Byte)(strm->adler & 0xff)); - put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); - put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); - put_byte(s, (Byte)((strm->adler >> 24) & 0xff)); - put_byte(s, (Byte)(strm->total_in & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 8) & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 16) & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 24) & 0xff)); - } - else -#endif - { - putShortMSB(s, (uInt)(strm->adler >> 16)); - putShortMSB(s, (uInt)(strm->adler & 0xffff)); - } - flush_pending(strm); - /* If avail_out is zero, the application will call deflate again - * to flush the rest. - */ - if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ - return s->pending != 0 ? Z_OK : Z_STREAM_END; -} - -/* ========================================================================= */ -int ZEXPORT deflateEnd (strm) - z_streamp strm; -{ - int status; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - - status = strm->state->status; - if (status != INIT_STATE && - status != EXTRA_STATE && - status != NAME_STATE && - status != COMMENT_STATE && - status != HCRC_STATE && - status != BUSY_STATE && - status != FINISH_STATE) { - return Z_STREAM_ERROR; - } - - /* Deallocate in reverse order of allocations: */ - TRY_FREE(strm, strm->state->pending_buf); - TRY_FREE(strm, strm->state->head); - TRY_FREE(strm, strm->state->prev); - TRY_FREE(strm, strm->state->window); - - ZFREE(strm, strm->state); - strm->state = Z_NULL; - - return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; -} - -/* ========================================================================= - * Copy the source state to the destination state. - * To simplify the source, this is not supported for 16-bit MSDOS (which - * doesn't have enough memory anyway to duplicate compression states). - */ -int ZEXPORT deflateCopy (dest, source) - z_streamp dest; - z_streamp source; -{ -#ifdef MAXSEG_64K - return Z_STREAM_ERROR; -#else - deflate_state *ds; - deflate_state *ss; - ushf *overlay; - - - if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { - return Z_STREAM_ERROR; - } - - ss = source->state; - - zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); - - ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); - if (ds == Z_NULL) return Z_MEM_ERROR; - dest->state = (struct internal_state FAR *) ds; - zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); - ds->strm = dest; - - ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); - ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); - ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); - ds->pending_buf = (uchf *) overlay; - - if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || - ds->pending_buf == Z_NULL) { - deflateEnd (dest); - return Z_MEM_ERROR; - } - /* following zmemcpy do not work for 16-bit MSDOS */ - zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); - zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); - zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); - zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); - - ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); - ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); - ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; - - ds->l_desc.dyn_tree = ds->dyn_ltree; - ds->d_desc.dyn_tree = ds->dyn_dtree; - ds->bl_desc.dyn_tree = ds->bl_tree; - - return Z_OK; -#endif /* MAXSEG_64K */ -} - -/* =========================================================================== - * Read a new buffer from the current input stream, update the adler32 - * and total number of bytes read. All deflate() input goes through - * this function so some applications may wish to modify it to avoid - * allocating a large strm->next_in buffer and copying from it. - * (See also flush_pending()). - */ -local int read_buf(strm, buf, size) - z_streamp strm; - Bytef *buf; - unsigned size; -{ - unsigned len = strm->avail_in; - - if (len > size) len = size; - if (len == 0) return 0; - - strm->avail_in -= len; - - zmemcpy(buf, strm->next_in, len); - if (strm->state->wrap == 1) { - strm->adler = adler32(strm->adler, buf, len); - } -#ifdef GZIP - else if (strm->state->wrap == 2) { - strm->adler = crc32(strm->adler, buf, len); - } -#endif - strm->next_in += len; - strm->total_in += len; - - return (int)len; -} - -/* =========================================================================== - * Initialize the "longest match" routines for a new zlib stream - */ -local void lm_init (s) - deflate_state *s; -{ - s->window_size = (ulg)2L*s->w_size; - - CLEAR_HASH(s); - - /* Set the default configuration parameters: - */ - s->max_lazy_match = configuration_table[s->level].max_lazy; - s->good_match = configuration_table[s->level].good_length; - s->nice_match = configuration_table[s->level].nice_length; - s->max_chain_length = configuration_table[s->level].max_chain; - - s->strstart = 0; - s->block_start = 0L; - s->lookahead = 0; - s->insert = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - s->ins_h = 0; -#ifndef FASTEST -#ifdef ASMV - match_init(); /* initialize the asm code */ -#endif -#endif -} - -#ifndef FASTEST -/* =========================================================================== - * Set match_start to the longest match starting at the given string and - * return its length. Matches shorter or equal to prev_length are discarded, - * in which case the result is equal to prev_length and match_start is - * garbage. - * IN assertions: cur_match is the head of the hash chain for the current - * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 - * OUT assertion: the match length is not greater than s->lookahead. - */ -#ifndef ASMV -/* For 80x86 and 680x0, an optimized version will be provided in match.asm or - * match.S. The code will be functionally equivalent. - */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ - unsigned chain_length = s->max_chain_length;/* max hash chain length */ - register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ - register int len; /* length of current match */ - int best_len = s->prev_length; /* best match length so far */ - int nice_match = s->nice_match; /* stop if match long enough */ - IPos limit = s->strstart > (IPos)MAX_DIST(s) ? - s->strstart - (IPos)MAX_DIST(s) : NIL; - /* Stop when cur_match becomes <= limit. To simplify the code, - * we prevent matches with the string of window index 0. - */ - Posf *prev = s->prev; - uInt wmask = s->w_mask; - -#ifdef UNALIGNED_OK - /* Compare two bytes at a time. Note: this is not always beneficial. - * Try with and without -DUNALIGNED_OK to check. - */ - register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; - register ush scan_start = *(ushf*)scan; - register ush scan_end = *(ushf*)(scan+best_len-1); -#else - register Bytef *strend = s->window + s->strstart + MAX_MATCH; - register Byte scan_end1 = scan[best_len-1]; - register Byte scan_end = scan[best_len]; -#endif - - /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - - /* Do not waste too much time if we already have a good match: */ - if (s->prev_length >= s->good_match) { - chain_length >>= 2; - } - /* Do not look for matches beyond the end of the input. This is necessary - * to make deflate deterministic. - */ - if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; - - Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); - - do { - Assert(cur_match < s->strstart, "no future"); - match = s->window + cur_match; - - /* Skip to next match if the match length cannot increase - * or if the match length is less than 2. Note that the checks below - * for insufficient lookahead only occur occasionally for performance - * reasons. Therefore uninitialized memory will be accessed, and - * conditional jumps will be made that depend on those values. - * However the length of the match is limited to the lookahead, so - * the output of deflate is not affected by the uninitialized values. - */ -#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) - /* This code assumes sizeof(unsigned short) == 2. Do not use - * UNALIGNED_OK if your compiler uses a different size. - */ - if (*(ushf*)(match+best_len-1) != scan_end || - *(ushf*)match != scan_start) continue; - - /* It is not necessary to compare scan[2] and match[2] since they are - * always equal when the other bytes match, given that the hash keys - * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at - * strstart+3, +5, ... up to strstart+257. We check for insufficient - * lookahead only every 4th comparison; the 128th check will be made - * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is - * necessary to put more guard bytes at the end of the window, or - * to check more often for insufficient lookahead. - */ - Assert(scan[2] == match[2], "scan[2]?"); - scan++, match++; - do { - } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - scan < strend); - /* The funny "do {}" generates better code on most compilers */ - - /* Here, scan <= window+strstart+257 */ - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - if (*scan == *match) scan++; - - len = (MAX_MATCH - 1) - (int)(strend-scan); - scan = strend - (MAX_MATCH-1); - -#else /* UNALIGNED_OK */ - - if (match[best_len] != scan_end || - match[best_len-1] != scan_end1 || - *match != *scan || - *++match != scan[1]) continue; - - /* The check at best_len-1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match++; - Assert(*scan == *match, "match[2]?"); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart+258. - */ - do { - } while (*++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - - len = MAX_MATCH - (int)(strend - scan); - scan = strend - MAX_MATCH; - -#endif /* UNALIGNED_OK */ - - if (len > best_len) { - s->match_start = cur_match; - best_len = len; - if (len >= nice_match) break; -#ifdef UNALIGNED_OK - scan_end = *(ushf*)(scan+best_len-1); -#else - scan_end1 = scan[best_len-1]; - scan_end = scan[best_len]; -#endif - } - } while ((cur_match = prev[cur_match & wmask]) > limit - && --chain_length != 0); - - if ((uInt)best_len <= s->lookahead) return (uInt)best_len; - return s->lookahead; -} -#endif /* ASMV */ - -#else /* FASTEST */ - -/* --------------------------------------------------------------------------- - * Optimized version for FASTEST only - */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ - register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ - register int len; /* length of current match */ - register Bytef *strend = s->window + s->strstart + MAX_MATCH; - - /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - - Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); - - Assert(cur_match < s->strstart, "no future"); - - match = s->window + cur_match; - - /* Return failure if the match length is less than 2: - */ - if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; - - /* The check at best_len-1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match += 2; - Assert(*scan == *match, "match[2]?"); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart+258. - */ - do { - } while (*++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - - len = MAX_MATCH - (int)(strend - scan); - - if (len < MIN_MATCH) return MIN_MATCH - 1; - - s->match_start = cur_match; - return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; -} - -#endif /* FASTEST */ - -#ifdef DEBUG -/* =========================================================================== - * Check that the match at match_start is indeed a match. - */ -local void check_match(s, start, match, length) - deflate_state *s; - IPos start, match; - int length; -{ - /* check that the match is indeed a match */ - if (zmemcmp(s->window + match, - s->window + start, length) != EQUAL) { - fprintf(stderr, " start %u, match %u, length %d\n", - start, match, length); - do { - fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); - } while (--length != 0); - z_error("invalid match"); - } - if (z_verbose > 1) { - fprintf(stderr,"\\[%d,%d]", start-match, length); - do { putc(s->window[start++], stderr); } while (--length != 0); - } -} -#else -# define check_match(s, start, match, length) -#endif /* DEBUG */ - -/* =========================================================================== - * Fill the window when the lookahead becomes insufficient. - * Updates strstart and lookahead. - * - * IN assertion: lookahead < MIN_LOOKAHEAD - * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD - * At least one byte has been read, or avail_in == 0; reads are - * performed for at least two bytes (required for the zip translate_eol - * option -- not supported here). - */ -local void fill_window(s) - deflate_state *s; -{ - register unsigned n, m; - register Posf *p; - unsigned more; /* Amount of free space at the end of the window. */ - uInt wsize = s->w_size; - - Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); - - do { - more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); - - /* Deal with !@#$% 64K limit: */ - if (sizeof(int) <= 2) { - if (more == 0 && s->strstart == 0 && s->lookahead == 0) { - more = wsize; - - } else if (more == (unsigned)(-1)) { - /* Very unlikely, but possible on 16 bit machine if - * strstart == 0 && lookahead == 1 (input done a byte at time) - */ - more--; - } - } - - /* If the window is almost full and there is insufficient lookahead, - * move the upper half to the lower one to make room in the upper half. - */ - if (s->strstart >= wsize+MAX_DIST(s)) { - - zmemcpy(s->window, s->window+wsize, (unsigned)wsize); - s->match_start -= wsize; - s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ - s->block_start -= (long) wsize; - - /* Slide the hash table (could be avoided with 32 bit values - at the expense of memory usage). We slide even when level == 0 - to keep the hash table consistent if we switch back to level > 0 - later. (Using level 0 permanently is not an optimal usage of - zlib, so we don't care about this pathological case.) - */ - n = s->hash_size; - p = &s->head[n]; - do { - m = *--p; - *p = (Pos)(m >= wsize ? m-wsize : NIL); - } while (--n); - - n = wsize; -#ifndef FASTEST - p = &s->prev[n]; - do { - m = *--p; - *p = (Pos)(m >= wsize ? m-wsize : NIL); - /* If n is not on any hash chain, prev[n] is garbage but - * its value will never be used. - */ - } while (--n); -#endif - more += wsize; - } - if (s->strm->avail_in == 0) break; - - /* If there was no sliding: - * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && - * more == window_size - lookahead - strstart - * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) - * => more >= window_size - 2*WSIZE + 2 - * In the BIG_MEM or MMAP case (not yet supported), - * window_size == input_size + MIN_LOOKAHEAD && - * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. - * Otherwise, window_size == 2*WSIZE so more >= 2. - * If there was sliding, more >= WSIZE. So in all cases, more >= 2. - */ - Assert(more >= 2, "more < 2"); - - n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); - s->lookahead += n; - - /* Initialize the hash value now that we have some input: */ - if (s->lookahead + s->insert >= MIN_MATCH) { - uInt str = s->strstart - s->insert; - s->ins_h = s->window[str]; - UPDATE_HASH(s, s->ins_h, s->window[str + 1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - while (s->insert) { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - s->insert--; - if (s->lookahead + s->insert < MIN_MATCH) - break; - } - } - /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, - * but this is not important since only literal bytes will be emitted. - */ - - } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); - - /* If the WIN_INIT bytes after the end of the current data have never been - * written, then zero those bytes in order to avoid memory check reports of - * the use of uninitialized (or uninitialised as Julian writes) bytes by - * the longest match routines. Update the high water mark for the next - * time through here. WIN_INIT is set to MAX_MATCH since the longest match - * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. - */ - if (s->high_water < s->window_size) { - ulg curr = s->strstart + (ulg)(s->lookahead); - ulg init; - - if (s->high_water < curr) { - /* Previous high water mark below current data -- zero WIN_INIT - * bytes or up to end of window, whichever is less. - */ - init = s->window_size - curr; - if (init > WIN_INIT) - init = WIN_INIT; - zmemzero(s->window + curr, (unsigned)init); - s->high_water = curr + init; - } - else if (s->high_water < (ulg)curr + WIN_INIT) { - /* High water mark at or above current data, but below current data - * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up - * to end of window, whichever is less. - */ - init = (ulg)curr + WIN_INIT - s->high_water; - if (init > s->window_size - s->high_water) - init = s->window_size - s->high_water; - zmemzero(s->window + s->high_water, (unsigned)init); - s->high_water += init; - } - } - - Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, - "not enough room for search"); -} - -/* =========================================================================== - * Flush the current block, with given end-of-file flag. - * IN assertion: strstart is set to the end of the current match. - */ -#define FLUSH_BLOCK_ONLY(s, last) { \ - _tr_flush_block(s, (s->block_start >= 0L ? \ - (charf *)&s->window[(unsigned)s->block_start] : \ - (charf *)Z_NULL), \ - (ulg)((long)s->strstart - s->block_start), \ - (last)); \ - s->block_start = s->strstart; \ - flush_pending(s->strm); \ - Tracev((stderr,"[FLUSH]")); \ -} - -/* Same but force premature exit if necessary. */ -#define FLUSH_BLOCK(s, last) { \ - FLUSH_BLOCK_ONLY(s, last); \ - if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ -} - -/* =========================================================================== - * Copy without compression as much as possible from the input stream, return - * the current block state. - * This function does not insert new strings in the dictionary since - * uncompressible data is probably not useful. This function is used - * only for the level=0 compression option. - * NOTE: this function should be optimized to avoid extra copying from - * window to pending_buf. - */ -local block_state deflate_stored(s, flush) - deflate_state *s; - int flush; -{ - /* Stored blocks are limited to 0xffff bytes, pending_buf is limited - * to pending_buf_size, and each stored block has a 5 byte header: - */ - ulg max_block_size = 0xffff; - ulg max_start; - - if (max_block_size > s->pending_buf_size - 5) { - max_block_size = s->pending_buf_size - 5; - } - - /* Copy as much as possible from input to output: */ - for (;;) { - /* Fill the window as much as possible: */ - if (s->lookahead <= 1) { - - Assert(s->strstart < s->w_size+MAX_DIST(s) || - s->block_start >= (long)s->w_size, "slide too late"); - - fill_window(s); - if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; - - if (s->lookahead == 0) break; /* flush the current block */ - } - Assert(s->block_start >= 0L, "block gone"); - - s->strstart += s->lookahead; - s->lookahead = 0; - - /* Emit a stored block if pending_buf will be full: */ - max_start = s->block_start + max_block_size; - if (s->strstart == 0 || (ulg)s->strstart >= max_start) { - /* strstart == 0 is possible when wraparound on 16-bit machine */ - s->lookahead = (uInt)(s->strstart - max_start); - s->strstart = (uInt)max_start; - FLUSH_BLOCK(s, 0); - } - /* Flush if we may have to slide, otherwise block_start may become - * negative and the data will be gone: - */ - if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { - FLUSH_BLOCK(s, 0); - } - } - s->insert = 0; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if ((long)s->strstart > s->block_start) - FLUSH_BLOCK(s, 0); - return block_done; -} - -/* =========================================================================== - * Compress as much as possible from the input stream, return the current - * block state. - * This function does not perform lazy evaluation of matches and inserts - * new strings in the dictionary only for unmatched strings or for short - * matches. It is used only for the fast compression options. - */ -local block_state deflate_fast(s, flush) - deflate_state *s; - int flush; -{ - IPos hash_head; /* head of the hash chain */ - int bflush; /* set if current block must be flushed */ - - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the next match, plus MIN_MATCH bytes to insert the - * string following the next match. - */ - if (s->lookahead < MIN_LOOKAHEAD) { - fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart+2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - hash_head = NIL; - if (s->lookahead >= MIN_MATCH) { - INSERT_STRING(s, s->strstart, hash_head); - } - - /* Find the longest match, discarding those <= prev_length. - * At this point we have always match_length < MIN_MATCH - */ - if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - s->match_length = longest_match (s, hash_head); - /* longest_match() sets match_start */ - } - if (s->match_length >= MIN_MATCH) { - check_match(s, s->strstart, s->match_start, s->match_length); - - _tr_tally_dist(s, s->strstart - s->match_start, - s->match_length - MIN_MATCH, bflush); - - s->lookahead -= s->match_length; - - /* Insert new strings in the hash table only if the match length - * is not too large. This saves time but degrades compression. - */ -#ifndef FASTEST - if (s->match_length <= s->max_insert_length && - s->lookahead >= MIN_MATCH) { - s->match_length--; /* string at strstart already in table */ - do { - s->strstart++; - INSERT_STRING(s, s->strstart, hash_head); - /* strstart never exceeds WSIZE-MAX_MATCH, so there are - * always MIN_MATCH bytes ahead. - */ - } while (--s->match_length != 0); - s->strstart++; - } else -#endif - { - s->strstart += s->match_length; - s->match_length = 0; - s->ins_h = s->window[s->strstart]; - UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not - * matter since it will be recomputed at next deflate call. - */ - } - } else { - /* No match, output a literal byte */ - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit (s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - } - if (bflush) FLUSH_BLOCK(s, 0); - } - s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->last_lit) - FLUSH_BLOCK(s, 0); - return block_done; -} - -#ifndef FASTEST -/* =========================================================================== - * Same as above, but achieves better compression. We use a lazy - * evaluation for matches: a match is finally adopted only if there is - * no better match at the next window position. - */ -local block_state deflate_slow(s, flush) - deflate_state *s; - int flush; -{ - IPos hash_head; /* head of hash chain */ - int bflush; /* set if current block must be flushed */ - - /* Process the input block. */ - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the next match, plus MIN_MATCH bytes to insert the - * string following the next match. - */ - if (s->lookahead < MIN_LOOKAHEAD) { - fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart+2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - hash_head = NIL; - if (s->lookahead >= MIN_MATCH) { - INSERT_STRING(s, s->strstart, hash_head); - } - - /* Find the longest match, discarding those <= prev_length. - */ - s->prev_length = s->match_length, s->prev_match = s->match_start; - s->match_length = MIN_MATCH-1; - - if (hash_head != NIL && s->prev_length < s->max_lazy_match && - s->strstart - hash_head <= MAX_DIST(s)) { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - s->match_length = longest_match (s, hash_head); - /* longest_match() sets match_start */ - - if (s->match_length <= 5 && (s->strategy == Z_FILTERED -#if TOO_FAR <= 32767 - || (s->match_length == MIN_MATCH && - s->strstart - s->match_start > TOO_FAR) -#endif - )) { - - /* If prev_match is also MIN_MATCH, match_start is garbage - * but we will ignore the current match anyway. - */ - s->match_length = MIN_MATCH-1; - } - } - /* If there was a match at the previous step and the current - * match is not better, output the previous match: - */ - if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { - uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; - /* Do not insert strings in hash table beyond this. */ - - check_match(s, s->strstart-1, s->prev_match, s->prev_length); - - _tr_tally_dist(s, s->strstart -1 - s->prev_match, - s->prev_length - MIN_MATCH, bflush); - - /* Insert in hash table all strings up to the end of the match. - * strstart-1 and strstart are already inserted. If there is not - * enough lookahead, the last two strings are not inserted in - * the hash table. - */ - s->lookahead -= s->prev_length-1; - s->prev_length -= 2; - do { - if (++s->strstart <= max_insert) { - INSERT_STRING(s, s->strstart, hash_head); - } - } while (--s->prev_length != 0); - s->match_available = 0; - s->match_length = MIN_MATCH-1; - s->strstart++; - - if (bflush) FLUSH_BLOCK(s, 0); - - } else if (s->match_available) { - /* If there was no match at the previous position, output a - * single literal. If there was a match but the current match - * is longer, truncate the previous match to a single literal. - */ - Tracevv((stderr,"%c", s->window[s->strstart-1])); - _tr_tally_lit(s, s->window[s->strstart-1], bflush); - if (bflush) { - FLUSH_BLOCK_ONLY(s, 0); - } - s->strstart++; - s->lookahead--; - if (s->strm->avail_out == 0) return need_more; - } else { - /* There is no previous match to compare with, wait for - * the next step to decide. - */ - s->match_available = 1; - s->strstart++; - s->lookahead--; - } - } - Assert (flush != Z_NO_FLUSH, "no flush?"); - if (s->match_available) { - Tracevv((stderr,"%c", s->window[s->strstart-1])); - _tr_tally_lit(s, s->window[s->strstart-1], bflush); - s->match_available = 0; - } - s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->last_lit) - FLUSH_BLOCK(s, 0); - return block_done; -} -#endif /* FASTEST */ - -/* =========================================================================== - * For Z_RLE, simply look for runs of bytes, generate matches only of distance - * one. Do not maintain a hash table. (It will be regenerated if this run of - * deflate switches away from Z_RLE.) - */ -local block_state deflate_rle(s, flush) - deflate_state *s; - int flush; -{ - int bflush; /* set if current block must be flushed */ - uInt prev; /* byte at distance one to match */ - Bytef *scan, *strend; /* scan goes up to strend for length of run */ - - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the longest run, plus one for the unrolled loop. - */ - if (s->lookahead <= MAX_MATCH) { - fill_window(s); - if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* See how many times the previous byte repeats */ - s->match_length = 0; - if (s->lookahead >= MIN_MATCH && s->strstart > 0) { - scan = s->window + s->strstart - 1; - prev = *scan; - if (prev == *++scan && prev == *++scan && prev == *++scan) { - strend = s->window + s->strstart + MAX_MATCH; - do { - } while (prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - scan < strend); - s->match_length = MAX_MATCH - (int)(strend - scan); - if (s->match_length > s->lookahead) - s->match_length = s->lookahead; - } - Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan"); - } - - /* Emit match if have run of MIN_MATCH or longer, else emit literal */ - if (s->match_length >= MIN_MATCH) { - check_match(s, s->strstart, s->strstart - 1, s->match_length); - - _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush); - - s->lookahead -= s->match_length; - s->strstart += s->match_length; - s->match_length = 0; - } else { - /* No match, output a literal byte */ - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit (s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - } - if (bflush) FLUSH_BLOCK(s, 0); - } - s->insert = 0; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->last_lit) - FLUSH_BLOCK(s, 0); - return block_done; -} - -/* =========================================================================== - * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. - * (It will be regenerated if this run of deflate switches away from Huffman.) - */ -local block_state deflate_huff(s, flush) - deflate_state *s; - int flush; -{ - int bflush; /* set if current block must be flushed */ - - for (;;) { - /* Make sure that we have a literal to write. */ - if (s->lookahead == 0) { - fill_window(s); - if (s->lookahead == 0) { - if (flush == Z_NO_FLUSH) - return need_more; - break; /* flush the current block */ - } - } - - /* Output a literal byte */ - s->match_length = 0; - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit (s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - if (bflush) FLUSH_BLOCK(s, 0); - } - s->insert = 0; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->last_lit) - FLUSH_BLOCK(s, 0); - return block_done; -} diff --git a/cdf36_3-dist/src/lib/zlib/deflate.h b/cdf36_3-dist/src/lib/zlib/deflate.h deleted file mode 100644 index 827489f..0000000 --- a/cdf36_3-dist/src/lib/zlib/deflate.h +++ /dev/null @@ -1,346 +0,0 @@ -/* deflate.h -- internal compression state - * Copyright (C) 1995-2012 Jean-loup Gailly - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* @(#) $Id: deflate.h,v 1.1.1.1 2016/10/12 19:21:25 liu Exp $ */ - -#ifndef DEFLATE_H -#define DEFLATE_H - -#include "zutil.h" - -/* define NO_GZIP when compiling if you want to disable gzip header and - trailer creation by deflate(). NO_GZIP would be used to avoid linking in - the crc code when it is not needed. For shared libraries, gzip encoding - should be left enabled. */ -#ifndef NO_GZIP -# define GZIP -#endif - -/* =========================================================================== - * Internal compression state. - */ - -#define LENGTH_CODES 29 -/* number of length codes, not counting the special END_BLOCK code */ - -#define LITERALS 256 -/* number of literal bytes 0..255 */ - -#define L_CODES (LITERALS+1+LENGTH_CODES) -/* number of Literal or Length codes, including the END_BLOCK code */ - -#define D_CODES 30 -/* number of distance codes */ - -#define BL_CODES 19 -/* number of codes used to transfer the bit lengths */ - -#define HEAP_SIZE (2*L_CODES+1) -/* maximum heap size */ - -#define MAX_BITS 15 -/* All codes must not exceed MAX_BITS bits */ - -#define Buf_size 16 -/* size of bit buffer in bi_buf */ - -#define INIT_STATE 42 -#define EXTRA_STATE 69 -#define NAME_STATE 73 -#define COMMENT_STATE 91 -#define HCRC_STATE 103 -#define BUSY_STATE 113 -#define FINISH_STATE 666 -/* Stream status */ - - -/* Data structure describing a single value and its code string. */ -typedef struct ct_data_s { - union { - ush freq; /* frequency count */ - ush code; /* bit string */ - } fc; - union { - ush dad; /* father node in Huffman tree */ - ush len; /* length of bit string */ - } dl; -} FAR ct_data; - -#define Freq fc.freq -#define Code fc.code -#define Dad dl.dad -#define Len dl.len - -typedef struct static_tree_desc_s static_tree_desc; - -typedef struct tree_desc_s { - ct_data *dyn_tree; /* the dynamic tree */ - int max_code; /* largest code with non zero frequency */ - static_tree_desc *stat_desc; /* the corresponding static tree */ -} FAR tree_desc; - -typedef ush Pos; -typedef Pos FAR Posf; -typedef unsigned IPos; - -/* A Pos is an index in the character window. We use short instead of int to - * save space in the various tables. IPos is used only for parameter passing. - */ - -typedef struct internal_state { - z_streamp strm; /* pointer back to this zlib stream */ - int status; /* as the name implies */ - Bytef *pending_buf; /* output still pending */ - ulg pending_buf_size; /* size of pending_buf */ - Bytef *pending_out; /* next pending byte to output to the stream */ - uInt pending; /* nb of bytes in the pending buffer */ - int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ - gz_headerp gzhead; /* gzip header information to write */ - uInt gzindex; /* where in extra, name, or comment */ - Byte method; /* can only be DEFLATED */ - int last_flush; /* value of flush param for previous deflate call */ - - /* used by deflate.c: */ - - uInt w_size; /* LZ77 window size (32K by default) */ - uInt w_bits; /* log2(w_size) (8..16) */ - uInt w_mask; /* w_size - 1 */ - - Bytef *window; - /* Sliding window. Input bytes are read into the second half of the window, - * and move to the first half later to keep a dictionary of at least wSize - * bytes. With this organization, matches are limited to a distance of - * wSize-MAX_MATCH bytes, but this ensures that IO is always - * performed with a length multiple of the block size. Also, it limits - * the window size to 64K, which is quite useful on MSDOS. - * To do: use the user input buffer as sliding window. - */ - - ulg window_size; - /* Actual size of window: 2*wSize, except when the user input buffer - * is directly used as sliding window. - */ - - Posf *prev; - /* Link to older string with same hash index. To limit the size of this - * array to 64K, this link is maintained only for the last 32K strings. - * An index in this array is thus a window index modulo 32K. - */ - - Posf *head; /* Heads of the hash chains or NIL. */ - - uInt ins_h; /* hash index of string to be inserted */ - uInt hash_size; /* number of elements in hash table */ - uInt hash_bits; /* log2(hash_size) */ - uInt hash_mask; /* hash_size-1 */ - - uInt hash_shift; - /* Number of bits by which ins_h must be shifted at each input - * step. It must be such that after MIN_MATCH steps, the oldest - * byte no longer takes part in the hash key, that is: - * hash_shift * MIN_MATCH >= hash_bits - */ - - long block_start; - /* Window position at the beginning of the current output block. Gets - * negative when the window is moved backwards. - */ - - uInt match_length; /* length of best match */ - IPos prev_match; /* previous match */ - int match_available; /* set if previous match exists */ - uInt strstart; /* start of string to insert */ - uInt match_start; /* start of matching string */ - uInt lookahead; /* number of valid bytes ahead in window */ - - uInt prev_length; - /* Length of the best match at previous step. Matches not greater than this - * are discarded. This is used in the lazy match evaluation. - */ - - uInt max_chain_length; - /* To speed up deflation, hash chains are never searched beyond this - * length. A higher limit improves compression ratio but degrades the - * speed. - */ - - uInt max_lazy_match; - /* Attempt to find a better match only when the current match is strictly - * smaller than this value. This mechanism is used only for compression - * levels >= 4. - */ -# define max_insert_length max_lazy_match - /* Insert new strings in the hash table only if the match length is not - * greater than this length. This saves time but degrades compression. - * max_insert_length is used only for compression levels <= 3. - */ - - int level; /* compression level (1..9) */ - int strategy; /* favor or force Huffman coding*/ - - uInt good_match; - /* Use a faster search when the previous match is longer than this */ - - int nice_match; /* Stop searching when current match exceeds this */ - - /* used by trees.c: */ - /* Didn't use ct_data typedef below to suppress compiler warning */ - struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ - struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ - struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ - - struct tree_desc_s l_desc; /* desc. for literal tree */ - struct tree_desc_s d_desc; /* desc. for distance tree */ - struct tree_desc_s bl_desc; /* desc. for bit length tree */ - - ush bl_count[MAX_BITS+1]; - /* number of codes at each bit length for an optimal tree */ - - int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ - int heap_len; /* number of elements in the heap */ - int heap_max; /* element of largest frequency */ - /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. - * The same heap array is used to build all trees. - */ - - uch depth[2*L_CODES+1]; - /* Depth of each subtree used as tie breaker for trees of equal frequency - */ - - uchf *l_buf; /* buffer for literals or lengths */ - - uInt lit_bufsize; - /* Size of match buffer for literals/lengths. There are 4 reasons for - * limiting lit_bufsize to 64K: - * - frequencies can be kept in 16 bit counters - * - if compression is not successful for the first block, all input - * data is still in the window so we can still emit a stored block even - * when input comes from standard input. (This can also be done for - * all blocks if lit_bufsize is not greater than 32K.) - * - if compression is not successful for a file smaller than 64K, we can - * even emit a stored file instead of a stored block (saving 5 bytes). - * This is applicable only for zip (not gzip or zlib). - * - creating new Huffman trees less frequently may not provide fast - * adaptation to changes in the input data statistics. (Take for - * example a binary file with poorly compressible code followed by - * a highly compressible string table.) Smaller buffer sizes give - * fast adaptation but have of course the overhead of transmitting - * trees more frequently. - * - I can't count above 4 - */ - - uInt last_lit; /* running index in l_buf */ - - ushf *d_buf; - /* Buffer for distances. To simplify the code, d_buf and l_buf have - * the same number of elements. To use different lengths, an extra flag - * array would be necessary. - */ - - ulg opt_len; /* bit length of current block with optimal trees */ - ulg static_len; /* bit length of current block with static trees */ - uInt matches; /* number of string matches in current block */ - uInt insert; /* bytes at end of window left to insert */ - -#ifdef DEBUG - ulg compressed_len; /* total bit length of compressed file mod 2^32 */ - ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ -#endif - - ush bi_buf; - /* Output buffer. bits are inserted starting at the bottom (least - * significant bits). - */ - int bi_valid; - /* Number of valid bits in bi_buf. All bits above the last valid bit - * are always zero. - */ - - ulg high_water; - /* High water mark offset in window for initialized bytes -- bytes above - * this are set to zero in order to avoid memory check warnings when - * longest match routines access bytes past the input. This is then - * updated to the new high water mark. - */ - -} FAR deflate_state; - -/* Output a byte on the stream. - * IN assertion: there is enough room in pending_buf. - */ -#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} - - -#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) -/* Minimum amount of lookahead, except at the end of the input file. - * See deflate.c for comments about the MIN_MATCH+1. - */ - -#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) -/* In order to simplify the code, particularly on 16 bit machines, match - * distances are limited to MAX_DIST instead of WSIZE. - */ - -#define WIN_INIT MAX_MATCH -/* Number of bytes after end of data in window to initialize in order to avoid - memory checker errors from longest match routines */ - - /* in trees.c */ -void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); -int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); -void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); -void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); - -#define d_code(dist) \ - ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) -/* Mapping from a distance to a distance code. dist is the distance - 1 and - * must not have side effects. _dist_code[256] and _dist_code[257] are never - * used. - */ - -#ifndef DEBUG -/* Inline versions of _tr_tally for speed: */ - -#if defined(GEN_TREES_H) || !defined(STDC) - extern uch ZLIB_INTERNAL _length_code[]; - extern uch ZLIB_INTERNAL _dist_code[]; -#else - extern const uch ZLIB_INTERNAL _length_code[]; - extern const uch ZLIB_INTERNAL _dist_code[]; -#endif - -# define _tr_tally_lit(s, c, flush) \ - { uch cc = (c); \ - s->d_buf[s->last_lit] = 0; \ - s->l_buf[s->last_lit++] = cc; \ - s->dyn_ltree[cc].Freq++; \ - flush = (s->last_lit == s->lit_bufsize-1); \ - } -# define _tr_tally_dist(s, distance, length, flush) \ - { uch len = (length); \ - ush dist = (distance); \ - s->d_buf[s->last_lit] = dist; \ - s->l_buf[s->last_lit++] = len; \ - dist--; \ - s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ - s->dyn_dtree[d_code(dist)].Freq++; \ - flush = (s->last_lit == s->lit_bufsize-1); \ - } -#else -# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) -# define _tr_tally_dist(s, distance, length, flush) \ - flush = _tr_tally(s, distance, length) -#endif - -#endif /* DEFLATE_H */ diff --git a/cdf36_3-dist/src/lib/zlib/gzclose.c b/cdf36_3-dist/src/lib/zlib/gzclose.c deleted file mode 100644 index caeb99a..0000000 --- a/cdf36_3-dist/src/lib/zlib/gzclose.c +++ /dev/null @@ -1,25 +0,0 @@ -/* gzclose.c -- zlib gzclose() function - * Copyright (C) 2004, 2010 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "gzguts.h" - -/* gzclose() is in a separate file so that it is linked in only if it is used. - That way the other gzclose functions can be used instead to avoid linking in - unneeded compression or decompression routines. */ -int ZEXPORT gzclose(file) - gzFile file; -{ -#ifndef NO_GZCOMPRESS - gz_statep state; - - if (file == NULL) - return Z_STREAM_ERROR; - state = (gz_statep)file; - - return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); -#else - return gzclose_r(file); -#endif -} diff --git a/cdf36_3-dist/src/lib/zlib/gzguts.h b/cdf36_3-dist/src/lib/zlib/gzguts.h deleted file mode 100644 index d87659d..0000000 --- a/cdf36_3-dist/src/lib/zlib/gzguts.h +++ /dev/null @@ -1,209 +0,0 @@ -/* gzguts.h -- zlib internal header definitions for gz* operations - * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#ifdef _LARGEFILE64_SOURCE -# ifndef _LARGEFILE_SOURCE -# define _LARGEFILE_SOURCE 1 -# endif -# ifdef _FILE_OFFSET_BITS -# undef _FILE_OFFSET_BITS -# endif -#endif - -#ifdef HAVE_HIDDEN -# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) -#else -# define ZLIB_INTERNAL -#endif - -#include -#include "zlib.h" -#ifdef STDC -# include -# include -# include -#endif -#include - -#ifdef _WIN32 -# include -#endif - -#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) -# include -#endif - -#ifdef WINAPI_FAMILY -# define open _open -# define read _read -# define write _write -# define close _close -#endif - -#ifdef NO_DEFLATE /* for compatibility with old definition */ -# define NO_GZCOMPRESS -#endif - -#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) -# ifndef HAVE_VSNPRINTF -# define HAVE_VSNPRINTF -# endif -#endif - -#if defined(__CYGWIN__) -# ifndef HAVE_VSNPRINTF -# define HAVE_VSNPRINTF -# endif -#endif - -#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410) -# ifndef HAVE_VSNPRINTF -# define HAVE_VSNPRINTF -# endif -#endif - -#ifndef HAVE_VSNPRINTF -# ifdef MSDOS -/* vsnprintf may exist on some MS-DOS compilers (DJGPP?), - but for now we just assume it doesn't. */ -# define NO_vsnprintf -# endif -# ifdef __TURBOC__ -# define NO_vsnprintf -# endif -# ifdef WIN32 -/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ -# if !defined(vsnprintf) && !defined(NO_vsnprintf) -# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) -# define vsnprintf _vsnprintf -# endif -# endif -# endif -# ifdef __SASC -# define NO_vsnprintf -# endif -# ifdef VMS -# define NO_vsnprintf -# endif -# ifdef __OS400__ -# define NO_vsnprintf -# endif -# ifdef __MVS__ -# define NO_vsnprintf -# endif -#endif - -/* unlike snprintf (which is required in C99, yet still not supported by - Microsoft more than a decade later!), _snprintf does not guarantee null - termination of the result -- however this is only used in gzlib.c where - the result is assured to fit in the space provided */ -#ifdef _MSC_VER -# define snprintf _snprintf -#endif - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - -/* gz* functions always use library allocation functions */ -#ifndef STDC - extern voidp malloc OF((uInt size)); - extern void free OF((voidpf ptr)); -#endif - -/* get errno and strerror definition */ -#if defined UNDER_CE -# include -# define zstrerror() gz_strwinerror((DWORD)GetLastError()) -#else -# ifndef NO_STRERROR -# include -# define zstrerror() strerror(errno) -# else -# define zstrerror() "stdio error (consult errno)" -# endif -#endif - -/* provide prototypes for these when building zlib without LFS */ -#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); - ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); -#endif - -/* default memLevel */ -#if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -#else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif - -/* default i/o buffer size -- double this for output when reading (this and - twice this must be able to fit in an unsigned type) */ -#define GZBUFSIZE 8192 - -/* gzip modes, also provide a little integrity check on the passed structure */ -#define GZ_NONE 0 -#define GZ_READ 7247 -#define GZ_WRITE 31153 -#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ - -/* values for gz_state how */ -#define LOOK 0 /* look for a gzip header */ -#define COPY 1 /* copy input directly */ -#define GZIP 2 /* decompress a gzip stream */ - -/* internal gzip file state data structure */ -typedef struct { - /* exposed contents for gzgetc() macro */ - struct gzFile_s x; /* "x" for exposed */ - /* x.have: number of bytes available at x.next */ - /* x.next: next output data to deliver or write */ - /* x.pos: current position in uncompressed data */ - /* used for both reading and writing */ - int mode; /* see gzip modes above */ - int fd; /* file descriptor */ - char *path; /* path or fd for error messages */ - unsigned size; /* buffer size, zero if not allocated yet */ - unsigned want; /* requested buffer size, default is GZBUFSIZE */ - unsigned char *in; /* input buffer */ - unsigned char *out; /* output buffer (double-sized when reading) */ - int direct; /* 0 if processing gzip, 1 if transparent */ - /* just for reading */ - int how; /* 0: get header, 1: copy, 2: decompress */ - z_off64_t start; /* where the gzip data started, for rewinding */ - int eof; /* true if end of input file reached */ - int past; /* true if read requested past end */ - /* just for writing */ - int level; /* compression level */ - int strategy; /* compression strategy */ - /* seek request */ - z_off64_t skip; /* amount to skip (already rewound if backwards) */ - int seek; /* true if seek request pending */ - /* error information */ - int err; /* error code */ - char *msg; /* error message */ - /* zlib inflate or deflate stream */ - z_stream strm; /* stream structure in-place (not a pointer) */ -} gz_state; -typedef gz_state FAR *gz_statep; - -/* shared functions */ -void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); -#if defined UNDER_CE -char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); -#endif - -/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t - value -- needed when comparing unsigned to z_off64_t, which is signed - (possible z_off64_t types off_t, off64_t, and long are all signed) */ -#ifdef INT_MAX -# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) -#else -unsigned ZLIB_INTERNAL gz_intmax OF((void)); -# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) -#endif diff --git a/cdf36_3-dist/src/lib/zlib/gzlib.c b/cdf36_3-dist/src/lib/zlib/gzlib.c deleted file mode 100644 index fae202e..0000000 --- a/cdf36_3-dist/src/lib/zlib/gzlib.c +++ /dev/null @@ -1,634 +0,0 @@ -/* gzlib.c -- zlib functions common to reading and writing gzip files - * Copyright (C) 2004, 2010, 2011, 2012, 2013 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "gzguts.h" - -#if defined(_WIN32) && !defined(__BORLANDC__) -# define LSEEK _lseeki64 -#else -#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 -# define LSEEK lseek64 -#else -# define LSEEK lseek -#endif -#endif - -/* Local functions */ -local void gz_reset OF((gz_statep)); -local gzFile gz_open OF((const void *, int, const char *)); - -#if defined UNDER_CE - -/* Map the Windows error number in ERROR to a locale-dependent error message - string and return a pointer to it. Typically, the values for ERROR come - from GetLastError. - - The string pointed to shall not be modified by the application, but may be - overwritten by a subsequent call to gz_strwinerror - - The gz_strwinerror function does not change the current setting of - GetLastError. */ -char ZLIB_INTERNAL *gz_strwinerror (error) - DWORD error; -{ - static char buf[1024]; - - wchar_t *msgbuf; - DWORD lasterr = GetLastError(); - DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM - | FORMAT_MESSAGE_ALLOCATE_BUFFER, - NULL, - error, - 0, /* Default language */ - (LPVOID)&msgbuf, - 0, - NULL); - if (chars != 0) { - /* If there is an \r\n appended, zap it. */ - if (chars >= 2 - && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { - chars -= 2; - msgbuf[chars] = 0; - } - - if (chars > sizeof (buf) - 1) { - chars = sizeof (buf) - 1; - msgbuf[chars] = 0; - } - - wcstombs(buf, msgbuf, chars + 1); - LocalFree(msgbuf); - } - else { - sprintf(buf, "unknown win32 error (%ld)", error); - } - - SetLastError(lasterr); - return buf; -} - -#endif /* UNDER_CE */ - -/* Reset gzip file state */ -local void gz_reset(state) - gz_statep state; -{ - state->x.have = 0; /* no output data available */ - if (state->mode == GZ_READ) { /* for reading ... */ - state->eof = 0; /* not at end of file */ - state->past = 0; /* have not read past end yet */ - state->how = LOOK; /* look for gzip header */ - } - state->seek = 0; /* no seek request pending */ - gz_error(state, Z_OK, NULL); /* clear error */ - state->x.pos = 0; /* no uncompressed data yet */ - state->strm.avail_in = 0; /* no input data yet */ -} - -/* Open a gzip file either by name or file descriptor. */ -local gzFile gz_open(path, fd, mode) - const void *path; - int fd; - const char *mode; -{ - gz_statep state; - size_t len; - int oflag; -#ifdef O_CLOEXEC - int cloexec = 0; -#endif -#ifdef O_EXCL - int exclusive = 0; -#endif - - /* check input */ - if (path == NULL) - return NULL; - - /* allocate gzFile structure to return */ - state = (gz_statep)malloc(sizeof(gz_state)); - if (state == NULL) - return NULL; - state->size = 0; /* no buffers allocated yet */ - state->want = GZBUFSIZE; /* requested buffer size */ - state->msg = NULL; /* no error message yet */ - - /* interpret mode */ - state->mode = GZ_NONE; - state->level = Z_DEFAULT_COMPRESSION; - state->strategy = Z_DEFAULT_STRATEGY; - state->direct = 0; - while (*mode) { - if (*mode >= '0' && *mode <= '9') - state->level = *mode - '0'; - else - switch (*mode) { - case 'r': - state->mode = GZ_READ; - break; -#ifndef NO_GZCOMPRESS - case 'w': - state->mode = GZ_WRITE; - break; - case 'a': - state->mode = GZ_APPEND; - break; -#endif - case '+': /* can't read and write at the same time */ - free(state); - return NULL; - case 'b': /* ignore -- will request binary anyway */ - break; -#ifdef O_CLOEXEC - case 'e': - cloexec = 1; - break; -#endif -#ifdef O_EXCL - case 'x': - exclusive = 1; - break; -#endif - case 'f': - state->strategy = Z_FILTERED; - break; - case 'h': - state->strategy = Z_HUFFMAN_ONLY; - break; - case 'R': - state->strategy = Z_RLE; - break; - case 'F': - state->strategy = Z_FIXED; - break; - case 'T': - state->direct = 1; - break; - default: /* could consider as an error, but just ignore */ - ; - } - mode++; - } - - /* must provide an "r", "w", or "a" */ - if (state->mode == GZ_NONE) { - free(state); - return NULL; - } - - /* can't force transparent read */ - if (state->mode == GZ_READ) { - if (state->direct) { - free(state); - return NULL; - } - state->direct = 1; /* for empty file */ - } - - /* save the path name for error messages */ -#ifdef _WIN32 - if (fd == -2) { - len = wcstombs(NULL, path, 0); - if (len == (size_t)-1) - len = 0; - } - else -#endif - len = strlen((const char *)path); - state->path = (char *)malloc(len + 1); - if (state->path == NULL) { - free(state); - return NULL; - } -#ifdef _WIN32 - if (fd == -2) - if (len) - wcstombs(state->path, path, len + 1); - else - *(state->path) = 0; - else -#endif -#if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(state->path, len + 1, "%s", (const char *)path); -#else - strcpy(state->path, path); -#endif - - /* compute the flags for open() */ - oflag = -#ifdef O_LARGEFILE - O_LARGEFILE | -#endif -#ifdef O_BINARY - O_BINARY | -#endif -#ifdef O_CLOEXEC - (cloexec ? O_CLOEXEC : 0) | -#endif - (state->mode == GZ_READ ? - O_RDONLY : - (O_WRONLY | O_CREAT | -#ifdef O_EXCL - (exclusive ? O_EXCL : 0) | -#endif - (state->mode == GZ_WRITE ? - O_TRUNC : - O_APPEND))); - - /* open the file with the appropriate flags (or just use fd) */ - state->fd = fd > -1 ? fd : ( -#ifdef _WIN32 - fd == -2 ? _wopen(path, oflag, 0666) : -#endif - open((const char *)path, oflag, 0666)); - if (state->fd == -1) { - free(state->path); - free(state); - return NULL; - } - if (state->mode == GZ_APPEND) - state->mode = GZ_WRITE; /* simplify later checks */ - - /* save the current position for rewinding (only if reading) */ - if (state->mode == GZ_READ) { - state->start = LSEEK(state->fd, 0, SEEK_CUR); - if (state->start == -1) state->start = 0; - } - - /* initialize stream */ - gz_reset(state); - - /* return stream */ - return (gzFile)state; -} - -/* -- see zlib.h -- */ -gzFile ZEXPORT gzopen(path, mode) - const char *path; - const char *mode; -{ - return gz_open(path, -1, mode); -} - -/* -- see zlib.h -- */ -gzFile ZEXPORT gzopen64(path, mode) - const char *path; - const char *mode; -{ - return gz_open(path, -1, mode); -} - -/* -- see zlib.h -- */ -gzFile ZEXPORT gzdopen(fd, mode) - int fd; - const char *mode; -{ - char *path; /* identifier for error messages */ - gzFile gz; - - if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL) - return NULL; -#if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(path, 7 + 3 * sizeof(int), "", fd); /* for debugging */ -#else - sprintf(path, "", fd); /* for debugging */ -#endif - gz = gz_open(path, fd, mode); - free(path); - return gz; -} - -/* -- see zlib.h -- */ -#ifdef _WIN32 -gzFile ZEXPORT gzopen_w(path, mode) - const wchar_t *path; - const char *mode; -{ - return gz_open(path, -2, mode); -} -#endif - -/* -- see zlib.h -- */ -int ZEXPORT gzbuffer(file, size) - gzFile file; - unsigned size; -{ - gz_statep state; - - /* get internal structure and check integrity */ - if (file == NULL) - return -1; - state = (gz_statep)file; - if (state->mode != GZ_READ && state->mode != GZ_WRITE) - return -1; - - /* make sure we haven't already allocated memory */ - if (state->size != 0) - return -1; - - /* check and set requested size */ - if (size < 2) - size = 2; /* need two bytes to check magic header */ - state->want = size; - return 0; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzrewind(file) - gzFile file; -{ - gz_statep state; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - - /* check that we're reading and that there's no error */ - if (state->mode != GZ_READ || - (state->err != Z_OK && state->err != Z_BUF_ERROR)) - return -1; - - /* back up and start over */ - if (LSEEK(state->fd, state->start, SEEK_SET) == -1) - return -1; - gz_reset(state); - return 0; -} - -/* -- see zlib.h -- */ -z_off64_t ZEXPORT gzseek64(file, offset, whence) - gzFile file; - z_off64_t offset; - int whence; -{ - unsigned n; - z_off64_t ret; - gz_statep state; - - /* get internal structure and check integrity */ - if (file == NULL) - return -1; - state = (gz_statep)file; - if (state->mode != GZ_READ && state->mode != GZ_WRITE) - return -1; - - /* check that there's no error */ - if (state->err != Z_OK && state->err != Z_BUF_ERROR) - return -1; - - /* can only seek from start or relative to current position */ - if (whence != SEEK_SET && whence != SEEK_CUR) - return -1; - - /* normalize offset to a SEEK_CUR specification */ - if (whence == SEEK_SET) - offset -= state->x.pos; - else if (state->seek) - offset += state->skip; - state->seek = 0; - - /* if within raw area while reading, just go there */ - if (state->mode == GZ_READ && state->how == COPY && - state->x.pos + offset >= 0) { - ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR); - if (ret == -1) - return -1; - state->x.have = 0; - state->eof = 0; - state->past = 0; - state->seek = 0; - gz_error(state, Z_OK, NULL); - state->strm.avail_in = 0; - state->x.pos += offset; - return state->x.pos; - } - - /* calculate skip amount, rewinding if needed for back seek when reading */ - if (offset < 0) { - if (state->mode != GZ_READ) /* writing -- can't go backwards */ - return -1; - offset += state->x.pos; - if (offset < 0) /* before start of file! */ - return -1; - if (gzrewind(file) == -1) /* rewind, then skip to offset */ - return -1; - } - - /* if reading, skip what's in output buffer (one less gzgetc() check) */ - if (state->mode == GZ_READ) { - n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ? - (unsigned)offset : state->x.have; - state->x.have -= n; - state->x.next += n; - state->x.pos += n; - offset -= n; - } - - /* request skip (if not zero) */ - if (offset) { - state->seek = 1; - state->skip = offset; - } - return state->x.pos + offset; -} - -/* -- see zlib.h -- */ -z_off_t ZEXPORT gzseek(file, offset, whence) - gzFile file; - z_off_t offset; - int whence; -{ - z_off64_t ret; - - ret = gzseek64(file, (z_off64_t)offset, whence); - return ret == (z_off_t)ret ? (z_off_t)ret : -1; -} - -/* -- see zlib.h -- */ -z_off64_t ZEXPORT gztell64(file) - gzFile file; -{ - gz_statep state; - - /* get internal structure and check integrity */ - if (file == NULL) - return -1; - state = (gz_statep)file; - if (state->mode != GZ_READ && state->mode != GZ_WRITE) - return -1; - - /* return position */ - return state->x.pos + (state->seek ? state->skip : 0); -} - -/* -- see zlib.h -- */ -z_off_t ZEXPORT gztell(file) - gzFile file; -{ - z_off64_t ret; - - ret = gztell64(file); - return ret == (z_off_t)ret ? (z_off_t)ret : -1; -} - -/* -- see zlib.h -- */ -z_off64_t ZEXPORT gzoffset64(file) - gzFile file; -{ - z_off64_t offset; - gz_statep state; - - /* get internal structure and check integrity */ - if (file == NULL) - return -1; - state = (gz_statep)file; - if (state->mode != GZ_READ && state->mode != GZ_WRITE) - return -1; - - /* compute and return effective offset in file */ - offset = LSEEK(state->fd, 0, SEEK_CUR); - if (offset == -1) - return -1; - if (state->mode == GZ_READ) /* reading */ - offset -= state->strm.avail_in; /* don't count buffered input */ - return offset; -} - -/* -- see zlib.h -- */ -z_off_t ZEXPORT gzoffset(file) - gzFile file; -{ - z_off64_t ret; - - ret = gzoffset64(file); - return ret == (z_off_t)ret ? (z_off_t)ret : -1; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzeof(file) - gzFile file; -{ - gz_statep state; - - /* get internal structure and check integrity */ - if (file == NULL) - return 0; - state = (gz_statep)file; - if (state->mode != GZ_READ && state->mode != GZ_WRITE) - return 0; - - /* return end-of-file state */ - return state->mode == GZ_READ ? state->past : 0; -} - -/* -- see zlib.h -- */ -const char * ZEXPORT gzerror(file, errnum) - gzFile file; - int *errnum; -{ - gz_statep state; - - /* get internal structure and check integrity */ - if (file == NULL) - return NULL; - state = (gz_statep)file; - if (state->mode != GZ_READ && state->mode != GZ_WRITE) - return NULL; - - /* return error information */ - if (errnum != NULL) - *errnum = state->err; - return state->err == Z_MEM_ERROR ? "out of memory" : - (state->msg == NULL ? "" : state->msg); -} - -/* -- see zlib.h -- */ -void ZEXPORT gzclearerr(file) - gzFile file; -{ - gz_statep state; - - /* get internal structure and check integrity */ - if (file == NULL) - return; - state = (gz_statep)file; - if (state->mode != GZ_READ && state->mode != GZ_WRITE) - return; - - /* clear error and end-of-file */ - if (state->mode == GZ_READ) { - state->eof = 0; - state->past = 0; - } - gz_error(state, Z_OK, NULL); -} - -/* Create an error message in allocated memory and set state->err and - state->msg accordingly. Free any previous error message already there. Do - not try to free or allocate space if the error is Z_MEM_ERROR (out of - memory). Simply save the error message as a static string. If there is an - allocation failure constructing the error message, then convert the error to - out of memory. */ -void ZLIB_INTERNAL gz_error(state, err, msg) - gz_statep state; - int err; - const char *msg; -{ - /* free previously allocated message and clear */ - if (state->msg != NULL) { - if (state->err != Z_MEM_ERROR) - free(state->msg); - state->msg = NULL; - } - - /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */ - if (err != Z_OK && err != Z_BUF_ERROR) - state->x.have = 0; - - /* set error code, and if no message, then done */ - state->err = err; - if (msg == NULL) - return; - - /* for an out of memory error, return literal string when requested */ - if (err == Z_MEM_ERROR) - return; - - /* construct error message with path */ - if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) == - NULL) { - state->err = Z_MEM_ERROR; - return; - } -#if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(state->msg, strlen(state->path) + strlen(msg) + 3, - "%s%s%s", state->path, ": ", msg); -#else - strcpy(state->msg, state->path); - strcat(state->msg, ": "); - strcat(state->msg, msg); -#endif - return; -} - -#ifndef INT_MAX -/* portably return maximum value for an int (when limits.h presumed not - available) -- we need to do this to cover cases where 2's complement not - used, since C standard permits 1's complement and sign-bit representations, - otherwise we could just use ((unsigned)-1) >> 1 */ -unsigned ZLIB_INTERNAL gz_intmax() -{ - unsigned p, q; - - p = 1; - do { - q = p; - p <<= 1; - p++; - } while (p > q); - return q >> 1; -} -#endif diff --git a/cdf36_3-dist/src/lib/zlib/gzread.c b/cdf36_3-dist/src/lib/zlib/gzread.c deleted file mode 100644 index bf4538e..0000000 --- a/cdf36_3-dist/src/lib/zlib/gzread.c +++ /dev/null @@ -1,594 +0,0 @@ -/* gzread.c -- zlib functions for reading gzip files - * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "gzguts.h" - -/* Local functions */ -local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); -local int gz_avail OF((gz_statep)); -local int gz_look OF((gz_statep)); -local int gz_decomp OF((gz_statep)); -local int gz_fetch OF((gz_statep)); -local int gz_skip OF((gz_statep, z_off64_t)); - -/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from - state->fd, and update state->eof, state->err, and state->msg as appropriate. - This function needs to loop on read(), since read() is not guaranteed to - read the number of bytes requested, depending on the type of descriptor. */ -local int gz_load(state, buf, len, have) - gz_statep state; - unsigned char *buf; - unsigned len; - unsigned *have; -{ - int ret; - - *have = 0; - do { - ret = read(state->fd, buf + *have, len - *have); - if (ret <= 0) - break; - *have += ret; - } while (*have < len); - if (ret < 0) { - gz_error(state, Z_ERRNO, zstrerror()); - return -1; - } - if (ret == 0) - state->eof = 1; - return 0; -} - -/* Load up input buffer and set eof flag if last data loaded -- return -1 on - error, 0 otherwise. Note that the eof flag is set when the end of the input - file is reached, even though there may be unused data in the buffer. Once - that data has been used, no more attempts will be made to read the file. - If strm->avail_in != 0, then the current data is moved to the beginning of - the input buffer, and then the remainder of the buffer is loaded with the - available data from the input file. */ -local int gz_avail(state) - gz_statep state; -{ - unsigned got; - z_streamp strm = &(state->strm); - - if (state->err != Z_OK && state->err != Z_BUF_ERROR) - return -1; - if (state->eof == 0) { - if (strm->avail_in) { /* copy what's there to the start */ - unsigned char *p = state->in; - unsigned const char *q = strm->next_in; - unsigned n = strm->avail_in; - do { - *p++ = *q++; - } while (--n); - } - if (gz_load(state, state->in + strm->avail_in, - state->size - strm->avail_in, &got) == -1) - return -1; - strm->avail_in += got; - strm->next_in = state->in; - } - return 0; -} - -/* Look for gzip header, set up for inflate or copy. state->x.have must be 0. - If this is the first time in, allocate required memory. state->how will be - left unchanged if there is no more input data available, will be set to COPY - if there is no gzip header and direct copying will be performed, or it will - be set to GZIP for decompression. If direct copying, then leftover input - data from the input buffer will be copied to the output buffer. In that - case, all further file reads will be directly to either the output buffer or - a user buffer. If decompressing, the inflate state will be initialized. - gz_look() will return 0 on success or -1 on failure. */ -local int gz_look(state) - gz_statep state; -{ - z_streamp strm = &(state->strm); - - /* allocate read buffers and inflate memory */ - if (state->size == 0) { - /* allocate buffers */ - state->in = (unsigned char *)malloc(state->want); - state->out = (unsigned char *)malloc(state->want << 1); - if (state->in == NULL || state->out == NULL) { - if (state->out != NULL) - free(state->out); - if (state->in != NULL) - free(state->in); - gz_error(state, Z_MEM_ERROR, "out of memory"); - return -1; - } - state->size = state->want; - - /* allocate inflate memory */ - state->strm.zalloc = Z_NULL; - state->strm.zfree = Z_NULL; - state->strm.opaque = Z_NULL; - state->strm.avail_in = 0; - state->strm.next_in = Z_NULL; - if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */ - free(state->out); - free(state->in); - state->size = 0; - gz_error(state, Z_MEM_ERROR, "out of memory"); - return -1; - } - } - - /* get at least the magic bytes in the input buffer */ - if (strm->avail_in < 2) { - if (gz_avail(state) == -1) - return -1; - if (strm->avail_in == 0) - return 0; - } - - /* look for gzip magic bytes -- if there, do gzip decoding (note: there is - a logical dilemma here when considering the case of a partially written - gzip file, to wit, if a single 31 byte is written, then we cannot tell - whether this is a single-byte file, or just a partially written gzip - file -- for here we assume that if a gzip file is being written, then - the header will be written in a single operation, so that reading a - single byte is sufficient indication that it is not a gzip file) */ - if (strm->avail_in > 1 && - strm->next_in[0] == 31 && strm->next_in[1] == 139) { - inflateReset(strm); - state->how = GZIP; - state->direct = 0; - return 0; - } - - /* no gzip header -- if we were decoding gzip before, then this is trailing - garbage. Ignore the trailing garbage and finish. */ - if (state->direct == 0) { - strm->avail_in = 0; - state->eof = 1; - state->x.have = 0; - return 0; - } - - /* doing raw i/o, copy any leftover input to output -- this assumes that - the output buffer is larger than the input buffer, which also assures - space for gzungetc() */ - state->x.next = state->out; - if (strm->avail_in) { - memcpy(state->x.next, strm->next_in, strm->avail_in); - state->x.have = strm->avail_in; - strm->avail_in = 0; - } - state->how = COPY; - state->direct = 1; - return 0; -} - -/* Decompress from input to the provided next_out and avail_out in the state. - On return, state->x.have and state->x.next point to the just decompressed - data. If the gzip stream completes, state->how is reset to LOOK to look for - the next gzip stream or raw data, once state->x.have is depleted. Returns 0 - on success, -1 on failure. */ -local int gz_decomp(state) - gz_statep state; -{ - int ret = Z_OK; - unsigned had; - z_streamp strm = &(state->strm); - - /* fill output buffer up to end of deflate stream */ - had = strm->avail_out; - do { - /* get more input for inflate() */ - if (strm->avail_in == 0 && gz_avail(state) == -1) - return -1; - if (strm->avail_in == 0) { - gz_error(state, Z_BUF_ERROR, "unexpected end of file"); - break; - } - - /* decompress and handle errors */ - ret = inflate(strm, Z_NO_FLUSH); - if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) { - gz_error(state, Z_STREAM_ERROR, - "internal error: inflate stream corrupt"); - return -1; - } - if (ret == Z_MEM_ERROR) { - gz_error(state, Z_MEM_ERROR, "out of memory"); - return -1; - } - if (ret == Z_DATA_ERROR) { /* deflate stream invalid */ - gz_error(state, Z_DATA_ERROR, - strm->msg == NULL ? "compressed data error" : strm->msg); - return -1; - } - } while (strm->avail_out && ret != Z_STREAM_END); - - /* update available output */ - state->x.have = had - strm->avail_out; - state->x.next = strm->next_out - state->x.have; - - /* if the gzip stream completed successfully, look for another */ - if (ret == Z_STREAM_END) - state->how = LOOK; - - /* good decompression */ - return 0; -} - -/* Fetch data and put it in the output buffer. Assumes state->x.have is 0. - Data is either copied from the input file or decompressed from the input - file depending on state->how. If state->how is LOOK, then a gzip header is - looked for to determine whether to copy or decompress. Returns -1 on error, - otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the - end of the input file has been reached and all data has been processed. */ -local int gz_fetch(state) - gz_statep state; -{ - z_streamp strm = &(state->strm); - - do { - switch(state->how) { - case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */ - if (gz_look(state) == -1) - return -1; - if (state->how == LOOK) - return 0; - break; - case COPY: /* -> COPY */ - if (gz_load(state, state->out, state->size << 1, &(state->x.have)) - == -1) - return -1; - state->x.next = state->out; - return 0; - case GZIP: /* -> GZIP or LOOK (if end of gzip stream) */ - strm->avail_out = state->size << 1; - strm->next_out = state->out; - if (gz_decomp(state) == -1) - return -1; - } - } while (state->x.have == 0 && (!state->eof || strm->avail_in)); - return 0; -} - -/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ -local int gz_skip(state, len) - gz_statep state; - z_off64_t len; -{ - unsigned n; - - /* skip over len bytes or reach end-of-file, whichever comes first */ - while (len) - /* skip over whatever is in output buffer */ - if (state->x.have) { - n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ? - (unsigned)len : state->x.have; - state->x.have -= n; - state->x.next += n; - state->x.pos += n; - len -= n; - } - - /* output buffer empty -- return if we're at the end of the input */ - else if (state->eof && state->strm.avail_in == 0) - break; - - /* need more data to skip -- load up output buffer */ - else { - /* get more output, looking for header if required */ - if (gz_fetch(state) == -1) - return -1; - } - return 0; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzread(file, buf, len) - gzFile file; - voidp buf; - unsigned len; -{ - unsigned got, n; - gz_statep state; - z_streamp strm; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - strm = &(state->strm); - - /* check that we're reading and that there's no (serious) error */ - if (state->mode != GZ_READ || - (state->err != Z_OK && state->err != Z_BUF_ERROR)) - return -1; - - /* since an int is returned, make sure len fits in one, otherwise return - with an error (this avoids the flaw in the interface) */ - if ((int)len < 0) { - gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); - return -1; - } - - /* if len is zero, avoid unnecessary operations */ - if (len == 0) - return 0; - - /* process a skip request */ - if (state->seek) { - state->seek = 0; - if (gz_skip(state, state->skip) == -1) - return -1; - } - - /* get len bytes to buf, or less than len if at the end */ - got = 0; - do { - /* first just try copying data from the output buffer */ - if (state->x.have) { - n = state->x.have > len ? len : state->x.have; - memcpy(buf, state->x.next, n); - state->x.next += n; - state->x.have -= n; - } - - /* output buffer empty -- return if we're at the end of the input */ - else if (state->eof && strm->avail_in == 0) { - state->past = 1; /* tried to read past end */ - break; - } - - /* need output data -- for small len or new stream load up our output - buffer */ - else if (state->how == LOOK || len < (state->size << 1)) { - /* get more output, looking for header if required */ - if (gz_fetch(state) == -1) - return -1; - continue; /* no progress yet -- go back to copy above */ - /* the copy above assures that we will leave with space in the - output buffer, allowing at least one gzungetc() to succeed */ - } - - /* large len -- read directly into user buffer */ - else if (state->how == COPY) { /* read directly */ - if (gz_load(state, (unsigned char *)buf, len, &n) == -1) - return -1; - } - - /* large len -- decompress directly into user buffer */ - else { /* state->how == GZIP */ - strm->avail_out = len; - strm->next_out = (unsigned char *)buf; - if (gz_decomp(state) == -1) - return -1; - n = state->x.have; - state->x.have = 0; - } - - /* update progress */ - len -= n; - buf = (char *)buf + n; - got += n; - state->x.pos += n; - } while (len); - - /* return number of bytes read into user buffer (will fit in int) */ - return (int)got; -} - -/* -- see zlib.h -- */ -#ifdef Z_PREFIX_SET -# undef z_gzgetc -#else -# undef gzgetc -#endif -int ZEXPORT gzgetc(file) - gzFile file; -{ - int ret; - unsigned char buf[1]; - gz_statep state; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - - /* check that we're reading and that there's no (serious) error */ - if (state->mode != GZ_READ || - (state->err != Z_OK && state->err != Z_BUF_ERROR)) - return -1; - - /* try output buffer (no need to check for skip request) */ - if (state->x.have) { - state->x.have--; - state->x.pos++; - return *(state->x.next)++; - } - - /* nothing there -- try gzread() */ - ret = gzread(file, buf, 1); - return ret < 1 ? -1 : buf[0]; -} - -int ZEXPORT gzgetc_(file) -gzFile file; -{ - return gzgetc(file); -} - -/* -- see zlib.h -- */ -int ZEXPORT gzungetc(c, file) - int c; - gzFile file; -{ - gz_statep state; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - - /* check that we're reading and that there's no (serious) error */ - if (state->mode != GZ_READ || - (state->err != Z_OK && state->err != Z_BUF_ERROR)) - return -1; - - /* process a skip request */ - if (state->seek) { - state->seek = 0; - if (gz_skip(state, state->skip) == -1) - return -1; - } - - /* can't push EOF */ - if (c < 0) - return -1; - - /* if output buffer empty, put byte at end (allows more pushing) */ - if (state->x.have == 0) { - state->x.have = 1; - state->x.next = state->out + (state->size << 1) - 1; - state->x.next[0] = c; - state->x.pos--; - state->past = 0; - return c; - } - - /* if no room, give up (must have already done a gzungetc()) */ - if (state->x.have == (state->size << 1)) { - gz_error(state, Z_DATA_ERROR, "out of room to push characters"); - return -1; - } - - /* slide output data if needed and insert byte before existing data */ - if (state->x.next == state->out) { - unsigned char *src = state->out + state->x.have; - unsigned char *dest = state->out + (state->size << 1); - while (src > state->out) - *--dest = *--src; - state->x.next = dest; - } - state->x.have++; - state->x.next--; - state->x.next[0] = c; - state->x.pos--; - state->past = 0; - return c; -} - -/* -- see zlib.h -- */ -char * ZEXPORT gzgets(file, buf, len) - gzFile file; - char *buf; - int len; -{ - unsigned left, n; - char *str; - unsigned char *eol; - gz_statep state; - - /* check parameters and get internal structure */ - if (file == NULL || buf == NULL || len < 1) - return NULL; - state = (gz_statep)file; - - /* check that we're reading and that there's no (serious) error */ - if (state->mode != GZ_READ || - (state->err != Z_OK && state->err != Z_BUF_ERROR)) - return NULL; - - /* process a skip request */ - if (state->seek) { - state->seek = 0; - if (gz_skip(state, state->skip) == -1) - return NULL; - } - - /* copy output bytes up to new line or len - 1, whichever comes first -- - append a terminating zero to the string (we don't check for a zero in - the contents, let the user worry about that) */ - str = buf; - left = (unsigned)len - 1; - if (left) do { - /* assure that something is in the output buffer */ - if (state->x.have == 0 && gz_fetch(state) == -1) - return NULL; /* error */ - if (state->x.have == 0) { /* end of file */ - state->past = 1; /* read past end */ - break; /* return what we have */ - } - - /* look for end-of-line in current output buffer */ - n = state->x.have > left ? left : state->x.have; - eol = (unsigned char *)memchr(state->x.next, '\n', n); - if (eol != NULL) - n = (unsigned)(eol - state->x.next) + 1; - - /* copy through end-of-line, or remainder if not found */ - memcpy(buf, state->x.next, n); - state->x.have -= n; - state->x.next += n; - state->x.pos += n; - left -= n; - buf += n; - } while (left && eol == NULL); - - /* return terminated string, or if nothing, end of file */ - if (buf == str) - return NULL; - buf[0] = 0; - return str; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzdirect(file) - gzFile file; -{ - gz_statep state; - - /* get internal structure */ - if (file == NULL) - return 0; - state = (gz_statep)file; - - /* if the state is not known, but we can find out, then do so (this is - mainly for right after a gzopen() or gzdopen()) */ - if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0) - (void)gz_look(state); - - /* return 1 if transparent, 0 if processing a gzip stream */ - return state->direct; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzclose_r(file) - gzFile file; -{ - int ret, err; - gz_statep state; - - /* get internal structure */ - if (file == NULL) - return Z_STREAM_ERROR; - state = (gz_statep)file; - - /* check that we're reading */ - if (state->mode != GZ_READ) - return Z_STREAM_ERROR; - - /* free memory and close file */ - if (state->size) { - inflateEnd(&(state->strm)); - free(state->out); - free(state->in); - } - err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK; - gz_error(state, Z_OK, NULL); - free(state->path); - ret = close(state->fd); - free(state); - return ret ? Z_ERRNO : err; -} diff --git a/cdf36_3-dist/src/lib/zlib/gzwrite.c b/cdf36_3-dist/src/lib/zlib/gzwrite.c deleted file mode 100644 index aa767fb..0000000 --- a/cdf36_3-dist/src/lib/zlib/gzwrite.c +++ /dev/null @@ -1,577 +0,0 @@ -/* gzwrite.c -- zlib functions for writing gzip files - * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "gzguts.h" - -/* Local functions */ -local int gz_init OF((gz_statep)); -local int gz_comp OF((gz_statep, int)); -local int gz_zero OF((gz_statep, z_off64_t)); - -/* Initialize state for writing a gzip file. Mark initialization by setting - state->size to non-zero. Return -1 on failure or 0 on success. */ -local int gz_init(state) - gz_statep state; -{ - int ret; - z_streamp strm = &(state->strm); - - /* allocate input buffer */ - state->in = (unsigned char *)malloc(state->want); - if (state->in == NULL) { - gz_error(state, Z_MEM_ERROR, "out of memory"); - return -1; - } - - /* only need output buffer and deflate state if compressing */ - if (!state->direct) { - /* allocate output buffer */ - state->out = (unsigned char *)malloc(state->want); - if (state->out == NULL) { - free(state->in); - gz_error(state, Z_MEM_ERROR, "out of memory"); - return -1; - } - - /* allocate deflate memory, set up for gzip compression */ - strm->zalloc = Z_NULL; - strm->zfree = Z_NULL; - strm->opaque = Z_NULL; - ret = deflateInit2(strm, state->level, Z_DEFLATED, - MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy); - if (ret != Z_OK) { - free(state->out); - free(state->in); - gz_error(state, Z_MEM_ERROR, "out of memory"); - return -1; - } - } - - /* mark state as initialized */ - state->size = state->want; - - /* initialize write buffer if compressing */ - if (!state->direct) { - strm->avail_out = state->size; - strm->next_out = state->out; - state->x.next = strm->next_out; - } - return 0; -} - -/* Compress whatever is at avail_in and next_in and write to the output file. - Return -1 if there is an error writing to the output file, otherwise 0. - flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH, - then the deflate() state is reset to start a new gzip stream. If gz->direct - is true, then simply write to the output file without compressing, and - ignore flush. */ -local int gz_comp(state, flush) - gz_statep state; - int flush; -{ - int ret, got; - unsigned have; - z_streamp strm = &(state->strm); - - /* allocate memory if this is the first time through */ - if (state->size == 0 && gz_init(state) == -1) - return -1; - - /* write directly if requested */ - if (state->direct) { - got = write(state->fd, strm->next_in, strm->avail_in); - if (got < 0 || (unsigned)got != strm->avail_in) { - gz_error(state, Z_ERRNO, zstrerror()); - return -1; - } - strm->avail_in = 0; - return 0; - } - - /* run deflate() on provided input until it produces no more output */ - ret = Z_OK; - do { - /* write out current buffer contents if full, or if flushing, but if - doing Z_FINISH then don't write until we get to Z_STREAM_END */ - if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && - (flush != Z_FINISH || ret == Z_STREAM_END))) { - have = (unsigned)(strm->next_out - state->x.next); - if (have && ((got = write(state->fd, state->x.next, have)) < 0 || - (unsigned)got != have)) { - gz_error(state, Z_ERRNO, zstrerror()); - return -1; - } - if (strm->avail_out == 0) { - strm->avail_out = state->size; - strm->next_out = state->out; - } - state->x.next = strm->next_out; - } - - /* compress */ - have = strm->avail_out; - ret = deflate(strm, flush); - if (ret == Z_STREAM_ERROR) { - gz_error(state, Z_STREAM_ERROR, - "internal error: deflate stream corrupt"); - return -1; - } - have -= strm->avail_out; - } while (have); - - /* if that completed a deflate stream, allow another to start */ - if (flush == Z_FINISH) - deflateReset(strm); - - /* all done, no errors */ - return 0; -} - -/* Compress len zeros to output. Return -1 on error, 0 on success. */ -local int gz_zero(state, len) - gz_statep state; - z_off64_t len; -{ - int first; - unsigned n; - z_streamp strm = &(state->strm); - - /* consume whatever's left in the input buffer */ - if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) - return -1; - - /* compress len zeros (len guaranteed > 0) */ - first = 1; - while (len) { - n = GT_OFF(state->size) || (z_off64_t)state->size > len ? - (unsigned)len : state->size; - if (first) { - memset(state->in, 0, n); - first = 0; - } - strm->avail_in = n; - strm->next_in = state->in; - state->x.pos += n; - if (gz_comp(state, Z_NO_FLUSH) == -1) - return -1; - len -= n; - } - return 0; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzwrite(file, buf, len) - gzFile file; - voidpc buf; - unsigned len; -{ - unsigned put = len; - gz_statep state; - z_streamp strm; - - /* get internal structure */ - if (file == NULL) - return 0; - state = (gz_statep)file; - strm = &(state->strm); - - /* check that we're writing and that there's no error */ - if (state->mode != GZ_WRITE || state->err != Z_OK) - return 0; - - /* since an int is returned, make sure len fits in one, otherwise return - with an error (this avoids the flaw in the interface) */ - if ((int)len < 0) { - gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); - return 0; - } - - /* if len is zero, avoid unnecessary operations */ - if (len == 0) - return 0; - - /* allocate memory if this is the first time through */ - if (state->size == 0 && gz_init(state) == -1) - return 0; - - /* check for seek request */ - if (state->seek) { - state->seek = 0; - if (gz_zero(state, state->skip) == -1) - return 0; - } - - /* for small len, copy to input buffer, otherwise compress directly */ - if (len < state->size) { - /* copy to input buffer, compress when full */ - do { - unsigned have, copy; - - if (strm->avail_in == 0) - strm->next_in = state->in; - have = (unsigned)((strm->next_in + strm->avail_in) - state->in); - copy = state->size - have; - if (copy > len) - copy = len; - memcpy(state->in + have, buf, copy); - strm->avail_in += copy; - state->x.pos += copy; - buf = (const char *)buf + copy; - len -= copy; - if (len && gz_comp(state, Z_NO_FLUSH) == -1) - return 0; - } while (len); - } - else { - /* consume whatever's left in the input buffer */ - if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) - return 0; - - /* directly compress user buffer to file */ - strm->avail_in = len; - strm->next_in = (z_const Bytef *)buf; - state->x.pos += len; - if (gz_comp(state, Z_NO_FLUSH) == -1) - return 0; - } - - /* input was all buffered or compressed (put will fit in int) */ - return (int)put; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzputc(file, c) - gzFile file; - int c; -{ - unsigned have; - unsigned char buf[1]; - gz_statep state; - z_streamp strm; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - strm = &(state->strm); - - /* check that we're writing and that there's no error */ - if (state->mode != GZ_WRITE || state->err != Z_OK) - return -1; - - /* check for seek request */ - if (state->seek) { - state->seek = 0; - if (gz_zero(state, state->skip) == -1) - return -1; - } - - /* try writing to input buffer for speed (state->size == 0 if buffer not - initialized) */ - if (state->size) { - if (strm->avail_in == 0) - strm->next_in = state->in; - have = (unsigned)((strm->next_in + strm->avail_in) - state->in); - if (have < state->size) { - state->in[have] = c; - strm->avail_in++; - state->x.pos++; - return c & 0xff; - } - } - - /* no room in buffer or not initialized, use gz_write() */ - buf[0] = c; - if (gzwrite(file, buf, 1) != 1) - return -1; - return c & 0xff; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzputs(file, str) - gzFile file; - const char *str; -{ - int ret; - unsigned len; - - /* write string */ - len = (unsigned)strlen(str); - ret = gzwrite(file, str, len); - return ret == 0 && len != 0 ? -1 : ret; -} - -#if defined(STDC) || defined(Z_HAVE_STDARG_H) -#include - -/* -- see zlib.h -- */ -int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) -{ - int size, len; - gz_statep state; - z_streamp strm; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - strm = &(state->strm); - - /* check that we're writing and that there's no error */ - if (state->mode != GZ_WRITE || state->err != Z_OK) - return 0; - - /* make sure we have some buffer space */ - if (state->size == 0 && gz_init(state) == -1) - return 0; - - /* check for seek request */ - if (state->seek) { - state->seek = 0; - if (gz_zero(state, state->skip) == -1) - return 0; - } - - /* consume whatever's left in the input buffer */ - if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) - return 0; - - /* do the printf() into the input buffer, put length in len */ - size = (int)(state->size); - state->in[size - 1] = 0; -#ifdef NO_vsnprintf -# ifdef HAS_vsprintf_void - (void)vsprintf((char *)(state->in), format, va); - for (len = 0; len < size; len++) - if (state->in[len] == 0) break; -# else - len = vsprintf((char *)(state->in), format, va); -# endif -#else -# ifdef HAS_vsnprintf_void - (void)vsnprintf((char *)(state->in), size, format, va); - len = strlen((char *)(state->in)); -# else - len = vsnprintf((char *)(state->in), size, format, va); -# endif -#endif - - /* check that printf() results fit in buffer */ - if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) - return 0; - - /* update buffer and position, defer compression until needed */ - strm->avail_in = (unsigned)len; - strm->next_in = state->in; - state->x.pos += len; - return len; -} - -int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) -{ - va_list va; - int ret; - - va_start(va, format); - ret = gzvprintf(file, format, va); - va_end(va); - return ret; -} - -#else /* !STDC && !Z_HAVE_STDARG_H */ - -/* -- see zlib.h -- */ -int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, - a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) - gzFile file; - const char *format; - int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, - a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; -{ - int size, len; - gz_statep state; - z_streamp strm; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - strm = &(state->strm); - - /* check that can really pass pointer in ints */ - if (sizeof(int) != sizeof(void *)) - return 0; - - /* check that we're writing and that there's no error */ - if (state->mode != GZ_WRITE || state->err != Z_OK) - return 0; - - /* make sure we have some buffer space */ - if (state->size == 0 && gz_init(state) == -1) - return 0; - - /* check for seek request */ - if (state->seek) { - state->seek = 0; - if (gz_zero(state, state->skip) == -1) - return 0; - } - - /* consume whatever's left in the input buffer */ - if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) - return 0; - - /* do the printf() into the input buffer, put length in len */ - size = (int)(state->size); - state->in[size - 1] = 0; -#ifdef NO_snprintf -# ifdef HAS_sprintf_void - sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8, - a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); - for (len = 0; len < size; len++) - if (state->in[len] == 0) break; -# else - len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8, - a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); -# endif -#else -# ifdef HAS_snprintf_void - snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8, - a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); - len = strlen((char *)(state->in)); -# else - len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, - a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, - a19, a20); -# endif -#endif - - /* check that printf() results fit in buffer */ - if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) - return 0; - - /* update buffer and position, defer compression until needed */ - strm->avail_in = (unsigned)len; - strm->next_in = state->in; - state->x.pos += len; - return len; -} - -#endif - -/* -- see zlib.h -- */ -int ZEXPORT gzflush(file, flush) - gzFile file; - int flush; -{ - gz_statep state; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - - /* check that we're writing and that there's no error */ - if (state->mode != GZ_WRITE || state->err != Z_OK) - return Z_STREAM_ERROR; - - /* check flush parameter */ - if (flush < 0 || flush > Z_FINISH) - return Z_STREAM_ERROR; - - /* check for seek request */ - if (state->seek) { - state->seek = 0; - if (gz_zero(state, state->skip) == -1) - return -1; - } - - /* compress remaining data with requested flush */ - gz_comp(state, flush); - return state->err; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzsetparams(file, level, strategy) - gzFile file; - int level; - int strategy; -{ - gz_statep state; - z_streamp strm; - - /* get internal structure */ - if (file == NULL) - return Z_STREAM_ERROR; - state = (gz_statep)file; - strm = &(state->strm); - - /* check that we're writing and that there's no error */ - if (state->mode != GZ_WRITE || state->err != Z_OK) - return Z_STREAM_ERROR; - - /* if no change is requested, then do nothing */ - if (level == state->level && strategy == state->strategy) - return Z_OK; - - /* check for seek request */ - if (state->seek) { - state->seek = 0; - if (gz_zero(state, state->skip) == -1) - return -1; - } - - /* change compression parameters for subsequent input */ - if (state->size) { - /* flush previous input with previous parameters before changing */ - if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1) - return state->err; - deflateParams(strm, level, strategy); - } - state->level = level; - state->strategy = strategy; - return Z_OK; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzclose_w(file) - gzFile file; -{ - int ret = Z_OK; - gz_statep state; - - /* get internal structure */ - if (file == NULL) - return Z_STREAM_ERROR; - state = (gz_statep)file; - - /* check that we're writing */ - if (state->mode != GZ_WRITE) - return Z_STREAM_ERROR; - - /* check for seek request */ - if (state->seek) { - state->seek = 0; - if (gz_zero(state, state->skip) == -1) - ret = state->err; - } - - /* flush, free memory, and close file */ - if (gz_comp(state, Z_FINISH) == -1) - ret = state->err; - if (state->size) { - if (!state->direct) { - (void)deflateEnd(&(state->strm)); - free(state->out); - } - free(state->in); - } - gz_error(state, Z_OK, NULL); - free(state->path); - if (close(state->fd) == -1) - ret = Z_ERRNO; - free(state); - return ret; -} diff --git a/cdf36_3-dist/src/lib/zlib/infback.c b/cdf36_3-dist/src/lib/zlib/infback.c deleted file mode 100644 index f3833c2..0000000 --- a/cdf36_3-dist/src/lib/zlib/infback.c +++ /dev/null @@ -1,640 +0,0 @@ -/* infback.c -- inflate using a call-back interface - * Copyright (C) 1995-2011 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - This code is largely copied from inflate.c. Normally either infback.o or - inflate.o would be linked into an application--not both. The interface - with inffast.c is retained so that optimized assembler-coded versions of - inflate_fast() can be used with either inflate.c or infback.c. - */ - -#include "zutil.h" -#include "inftrees.h" -#include "inflate.h" -#include "inffast.h" - -/* function prototypes */ -local void fixedtables OF((struct inflate_state FAR *state)); - -/* - strm provides memory allocation functions in zalloc and zfree, or - Z_NULL to use the library memory allocation functions. - - windowBits is in the range 8..15, and window is a user-supplied - window and output buffer that is 2**windowBits bytes. - */ -int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size) -z_streamp strm; -int windowBits; -unsigned char FAR *window; -const char *version; -int stream_size; -{ - struct inflate_state FAR *state; - - if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || - stream_size != (int)(sizeof(z_stream))) - return Z_VERSION_ERROR; - if (strm == Z_NULL || window == Z_NULL || - windowBits < 8 || windowBits > 15) - return Z_STREAM_ERROR; - strm->msg = Z_NULL; /* in case we return an error */ - if (strm->zalloc == (alloc_func)0) { -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; -#endif - } - if (strm->zfree == (free_func)0) -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zfree = zcfree; -#endif - state = (struct inflate_state FAR *)ZALLOC(strm, 1, - sizeof(struct inflate_state)); - if (state == Z_NULL) return Z_MEM_ERROR; - Tracev((stderr, "inflate: allocated\n")); - strm->state = (struct internal_state FAR *)state; - state->dmax = 32768U; - state->wbits = windowBits; - state->wsize = 1U << windowBits; - state->window = window; - state->wnext = 0; - state->whave = 0; - return Z_OK; -} - -/* - Return state with length and distance decoding tables and index sizes set to - fixed code decoding. Normally this returns fixed tables from inffixed.h. - If BUILDFIXED is defined, then instead this routine builds the tables the - first time it's called, and returns those tables the first time and - thereafter. This reduces the size of the code by about 2K bytes, in - exchange for a little execution time. However, BUILDFIXED should not be - used for threaded applications, since the rewriting of the tables and virgin - may not be thread-safe. - */ -local void fixedtables(state) -struct inflate_state FAR *state; -{ -#ifdef BUILDFIXED - static int virgin = 1; - static code *lenfix, *distfix; - static code fixed[544]; - - /* build fixed huffman tables if first call (may not be thread safe) */ - if (virgin) { - unsigned sym, bits; - static code *next; - - /* literal/length table */ - sym = 0; - while (sym < 144) state->lens[sym++] = 8; - while (sym < 256) state->lens[sym++] = 9; - while (sym < 280) state->lens[sym++] = 7; - while (sym < 288) state->lens[sym++] = 8; - next = fixed; - lenfix = next; - bits = 9; - inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); - - /* distance table */ - sym = 0; - while (sym < 32) state->lens[sym++] = 5; - distfix = next; - bits = 5; - inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); - - /* do this just once */ - virgin = 0; - } -#else /* !BUILDFIXED */ -# include "inffixed.h" -#endif /* BUILDFIXED */ - state->lencode = lenfix; - state->lenbits = 9; - state->distcode = distfix; - state->distbits = 5; -} - -/* Macros for inflateBack(): */ - -/* Load returned state from inflate_fast() */ -#define LOAD() \ - do { \ - put = strm->next_out; \ - left = strm->avail_out; \ - next = strm->next_in; \ - have = strm->avail_in; \ - hold = state->hold; \ - bits = state->bits; \ - } while (0) - -/* Set state from registers for inflate_fast() */ -#define RESTORE() \ - do { \ - strm->next_out = put; \ - strm->avail_out = left; \ - strm->next_in = next; \ - strm->avail_in = have; \ - state->hold = hold; \ - state->bits = bits; \ - } while (0) - -/* Clear the input bit accumulator */ -#define INITBITS() \ - do { \ - hold = 0; \ - bits = 0; \ - } while (0) - -/* Assure that some input is available. If input is requested, but denied, - then return a Z_BUF_ERROR from inflateBack(). */ -#define PULL() \ - do { \ - if (have == 0) { \ - have = in(in_desc, &next); \ - if (have == 0) { \ - next = Z_NULL; \ - ret = Z_BUF_ERROR; \ - goto inf_leave; \ - } \ - } \ - } while (0) - -/* Get a byte of input into the bit accumulator, or return from inflateBack() - with an error if there is no input available. */ -#define PULLBYTE() \ - do { \ - PULL(); \ - have--; \ - hold += (unsigned long)(*next++) << bits; \ - bits += 8; \ - } while (0) - -/* Assure that there are at least n bits in the bit accumulator. If there is - not enough available input to do that, then return from inflateBack() with - an error. */ -#define NEEDBITS(n) \ - do { \ - while (bits < (unsigned)(n)) \ - PULLBYTE(); \ - } while (0) - -/* Return the low n bits of the bit accumulator (n < 16) */ -#define BITS(n) \ - ((unsigned)hold & ((1U << (n)) - 1)) - -/* Remove n bits from the bit accumulator */ -#define DROPBITS(n) \ - do { \ - hold >>= (n); \ - bits -= (unsigned)(n); \ - } while (0) - -/* Remove zero to seven bits as needed to go to a byte boundary */ -#define BYTEBITS() \ - do { \ - hold >>= bits & 7; \ - bits -= bits & 7; \ - } while (0) - -/* Assure that some output space is available, by writing out the window - if it's full. If the write fails, return from inflateBack() with a - Z_BUF_ERROR. */ -#define ROOM() \ - do { \ - if (left == 0) { \ - put = state->window; \ - left = state->wsize; \ - state->whave = left; \ - if (out(out_desc, put, left)) { \ - ret = Z_BUF_ERROR; \ - goto inf_leave; \ - } \ - } \ - } while (0) - -/* - strm provides the memory allocation functions and window buffer on input, - and provides information on the unused input on return. For Z_DATA_ERROR - returns, strm will also provide an error message. - - in() and out() are the call-back input and output functions. When - inflateBack() needs more input, it calls in(). When inflateBack() has - filled the window with output, or when it completes with data in the - window, it calls out() to write out the data. The application must not - change the provided input until in() is called again or inflateBack() - returns. The application must not change the window/output buffer until - inflateBack() returns. - - in() and out() are called with a descriptor parameter provided in the - inflateBack() call. This parameter can be a structure that provides the - information required to do the read or write, as well as accumulated - information on the input and output such as totals and check values. - - in() should return zero on failure. out() should return non-zero on - failure. If either in() or out() fails, than inflateBack() returns a - Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it - was in() or out() that caused in the error. Otherwise, inflateBack() - returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format - error, or Z_MEM_ERROR if it could not allocate memory for the state. - inflateBack() can also return Z_STREAM_ERROR if the input parameters - are not correct, i.e. strm is Z_NULL or the state was not initialized. - */ -int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) -z_streamp strm; -in_func in; -void FAR *in_desc; -out_func out; -void FAR *out_desc; -{ - struct inflate_state FAR *state; - z_const unsigned char FAR *next; /* next input */ - unsigned char FAR *put; /* next output */ - unsigned have, left; /* available input and output */ - unsigned long hold; /* bit buffer */ - unsigned bits; /* bits in bit buffer */ - unsigned copy; /* number of stored or match bytes to copy */ - unsigned char FAR *from; /* where to copy match bytes from */ - code here; /* current decoding table entry */ - code last; /* parent table entry */ - unsigned len; /* length to copy for repeats, bits to drop */ - int ret; /* return code */ - static const unsigned short order[19] = /* permutation of code lengths */ - {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; - - /* Check that the strm exists and that the state was initialized */ - if (strm == Z_NULL || strm->state == Z_NULL) - return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - - /* Reset the state */ - strm->msg = Z_NULL; - state->mode = TYPE; - state->last = 0; - state->whave = 0; - next = strm->next_in; - have = next != Z_NULL ? strm->avail_in : 0; - hold = 0; - bits = 0; - put = state->window; - left = state->wsize; - - /* Inflate until end of block marked as last */ - for (;;) - switch (state->mode) { - case TYPE: - /* determine and dispatch block type */ - if (state->last) { - BYTEBITS(); - state->mode = DONE; - break; - } - NEEDBITS(3); - state->last = BITS(1); - DROPBITS(1); - switch (BITS(2)) { - case 0: /* stored block */ - Tracev((stderr, "inflate: stored block%s\n", - state->last ? " (last)" : "")); - state->mode = STORED; - break; - case 1: /* fixed block */ - fixedtables(state); - Tracev((stderr, "inflate: fixed codes block%s\n", - state->last ? " (last)" : "")); - state->mode = LEN; /* decode codes */ - break; - case 2: /* dynamic block */ - Tracev((stderr, "inflate: dynamic codes block%s\n", - state->last ? " (last)" : "")); - state->mode = TABLE; - break; - case 3: - strm->msg = (char *)"invalid block type"; - state->mode = BAD; - } - DROPBITS(2); - break; - - case STORED: - /* get and verify stored block length */ - BYTEBITS(); /* go to byte boundary */ - NEEDBITS(32); - if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { - strm->msg = (char *)"invalid stored block lengths"; - state->mode = BAD; - break; - } - state->length = (unsigned)hold & 0xffff; - Tracev((stderr, "inflate: stored length %u\n", - state->length)); - INITBITS(); - - /* copy stored block from input to output */ - while (state->length != 0) { - copy = state->length; - PULL(); - ROOM(); - if (copy > have) copy = have; - if (copy > left) copy = left; - zmemcpy(put, next, copy); - have -= copy; - next += copy; - left -= copy; - put += copy; - state->length -= copy; - } - Tracev((stderr, "inflate: stored end\n")); - state->mode = TYPE; - break; - - case TABLE: - /* get dynamic table entries descriptor */ - NEEDBITS(14); - state->nlen = BITS(5) + 257; - DROPBITS(5); - state->ndist = BITS(5) + 1; - DROPBITS(5); - state->ncode = BITS(4) + 4; - DROPBITS(4); -#ifndef PKZIP_BUG_WORKAROUND - if (state->nlen > 286 || state->ndist > 30) { - strm->msg = (char *)"too many length or distance symbols"; - state->mode = BAD; - break; - } -#endif - Tracev((stderr, "inflate: table sizes ok\n")); - - /* get code length code lengths (not a typo) */ - state->have = 0; - while (state->have < state->ncode) { - NEEDBITS(3); - state->lens[order[state->have++]] = (unsigned short)BITS(3); - DROPBITS(3); - } - while (state->have < 19) - state->lens[order[state->have++]] = 0; - state->next = state->codes; - state->lencode = (code const FAR *)(state->next); - state->lenbits = 7; - ret = inflate_table(CODES, state->lens, 19, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid code lengths set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: code lengths ok\n")); - - /* get length and distance code code lengths */ - state->have = 0; - while (state->have < state->nlen + state->ndist) { - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.val < 16) { - DROPBITS(here.bits); - state->lens[state->have++] = here.val; - } - else { - if (here.val == 16) { - NEEDBITS(here.bits + 2); - DROPBITS(here.bits); - if (state->have == 0) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - len = (unsigned)(state->lens[state->have - 1]); - copy = 3 + BITS(2); - DROPBITS(2); - } - else if (here.val == 17) { - NEEDBITS(here.bits + 3); - DROPBITS(here.bits); - len = 0; - copy = 3 + BITS(3); - DROPBITS(3); - } - else { - NEEDBITS(here.bits + 7); - DROPBITS(here.bits); - len = 0; - copy = 11 + BITS(7); - DROPBITS(7); - } - if (state->have + copy > state->nlen + state->ndist) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - while (copy--) - state->lens[state->have++] = (unsigned short)len; - } - } - - /* handle error breaks in while */ - if (state->mode == BAD) break; - - /* check for end-of-block code (better have one) */ - if (state->lens[256] == 0) { - strm->msg = (char *)"invalid code -- missing end-of-block"; - state->mode = BAD; - break; - } - - /* build code tables -- note: do not change the lenbits or distbits - values here (9 and 6) without reading the comments in inftrees.h - concerning the ENOUGH constants, which depend on those values */ - state->next = state->codes; - state->lencode = (code const FAR *)(state->next); - state->lenbits = 9; - ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid literal/lengths set"; - state->mode = BAD; - break; - } - state->distcode = (code const FAR *)(state->next); - state->distbits = 6; - ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, - &(state->next), &(state->distbits), state->work); - if (ret) { - strm->msg = (char *)"invalid distances set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: codes ok\n")); - state->mode = LEN; - - case LEN: - /* use inflate_fast() if we have enough input and output */ - if (have >= 6 && left >= 258) { - RESTORE(); - if (state->whave < state->wsize) - state->whave = state->wsize - left; - inflate_fast(strm, state->wsize); - LOAD(); - break; - } - - /* get a literal, length, or end-of-block code */ - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.op && (here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->lencode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - } - DROPBITS(here.bits); - state->length = (unsigned)here.val; - - /* process literal */ - if (here.op == 0) { - Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? - "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", here.val)); - ROOM(); - *put++ = (unsigned char)(state->length); - left--; - state->mode = LEN; - break; - } - - /* process end of block */ - if (here.op & 32) { - Tracevv((stderr, "inflate: end of block\n")); - state->mode = TYPE; - break; - } - - /* invalid code */ - if (here.op & 64) { - strm->msg = (char *)"invalid literal/length code"; - state->mode = BAD; - break; - } - - /* length code -- get extra bits, if any */ - state->extra = (unsigned)(here.op) & 15; - if (state->extra != 0) { - NEEDBITS(state->extra); - state->length += BITS(state->extra); - DROPBITS(state->extra); - } - Tracevv((stderr, "inflate: length %u\n", state->length)); - - /* get distance code */ - for (;;) { - here = state->distcode[BITS(state->distbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if ((here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->distcode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - } - DROPBITS(here.bits); - if (here.op & 64) { - strm->msg = (char *)"invalid distance code"; - state->mode = BAD; - break; - } - state->offset = (unsigned)here.val; - - /* get distance extra bits, if any */ - state->extra = (unsigned)(here.op) & 15; - if (state->extra != 0) { - NEEDBITS(state->extra); - state->offset += BITS(state->extra); - DROPBITS(state->extra); - } - if (state->offset > state->wsize - (state->whave < state->wsize ? - left : 0)) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } - Tracevv((stderr, "inflate: distance %u\n", state->offset)); - - /* copy match from window to output */ - do { - ROOM(); - copy = state->wsize - state->offset; - if (copy < left) { - from = put + copy; - copy = left - copy; - } - else { - from = put - state->offset; - copy = left; - } - if (copy > state->length) copy = state->length; - state->length -= copy; - left -= copy; - do { - *put++ = *from++; - } while (--copy); - } while (state->length != 0); - break; - - case DONE: - /* inflate stream terminated properly -- write leftover output */ - ret = Z_STREAM_END; - if (left < state->wsize) { - if (out(out_desc, state->window, state->wsize - left)) - ret = Z_BUF_ERROR; - } - goto inf_leave; - - case BAD: - ret = Z_DATA_ERROR; - goto inf_leave; - - default: /* can't happen, but makes compilers happy */ - ret = Z_STREAM_ERROR; - goto inf_leave; - } - - /* Return unused input */ - inf_leave: - strm->next_in = next; - strm->avail_in = have; - return ret; -} - -int ZEXPORT inflateBackEnd(strm) -z_streamp strm; -{ - if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) - return Z_STREAM_ERROR; - ZFREE(strm, strm->state); - strm->state = Z_NULL; - Tracev((stderr, "inflate: end\n")); - return Z_OK; -} diff --git a/cdf36_3-dist/src/lib/zlib/inffast.c b/cdf36_3-dist/src/lib/zlib/inffast.c deleted file mode 100644 index bda59ce..0000000 --- a/cdf36_3-dist/src/lib/zlib/inffast.c +++ /dev/null @@ -1,340 +0,0 @@ -/* inffast.c -- fast decoding - * Copyright (C) 1995-2008, 2010, 2013 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "inftrees.h" -#include "inflate.h" -#include "inffast.h" - -#ifndef ASMINF - -/* Allow machine dependent optimization for post-increment or pre-increment. - Based on testing to date, - Pre-increment preferred for: - - PowerPC G3 (Adler) - - MIPS R5000 (Randers-Pehrson) - Post-increment preferred for: - - none - No measurable difference: - - Pentium III (Anderson) - - M68060 (Nikl) - */ -#ifdef POSTINC -# define OFF 0 -# define PUP(a) *(a)++ -#else -# define OFF 1 -# define PUP(a) *++(a) -#endif - -/* - Decode literal, length, and distance codes and write out the resulting - literal and match bytes until either not enough input or output is - available, an end-of-block is encountered, or a data error is encountered. - When large enough input and output buffers are supplied to inflate(), for - example, a 16K input buffer and a 64K output buffer, more than 95% of the - inflate execution time is spent in this routine. - - Entry assumptions: - - state->mode == LEN - strm->avail_in >= 6 - strm->avail_out >= 258 - start >= strm->avail_out - state->bits < 8 - - On return, state->mode is one of: - - LEN -- ran out of enough output space or enough available input - TYPE -- reached end of block code, inflate() to interpret next block - BAD -- error in block data - - Notes: - - - The maximum input bits used by a length/distance pair is 15 bits for the - length code, 5 bits for the length extra, 15 bits for the distance code, - and 13 bits for the distance extra. This totals 48 bits, or six bytes. - Therefore if strm->avail_in >= 6, then there is enough input to avoid - checking for available input while decoding. - - - The maximum bytes that a single length/distance pair can output is 258 - bytes, which is the maximum length that can be coded. inflate_fast() - requires strm->avail_out >= 258 for each loop to avoid checking for - output space. - */ -void ZLIB_INTERNAL inflate_fast(strm, start) -z_streamp strm; -unsigned start; /* inflate()'s starting value for strm->avail_out */ -{ - struct inflate_state FAR *state; - z_const unsigned char FAR *in; /* local strm->next_in */ - z_const unsigned char FAR *last; /* have enough input while in < last */ - unsigned char FAR *out; /* local strm->next_out */ - unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ - unsigned char FAR *end; /* while out < end, enough space available */ -#ifdef INFLATE_STRICT - unsigned dmax; /* maximum distance from zlib header */ -#endif - unsigned wsize; /* window size or zero if not using window */ - unsigned whave; /* valid bytes in the window */ - unsigned wnext; /* window write index */ - unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ - unsigned long hold; /* local strm->hold */ - unsigned bits; /* local strm->bits */ - code const FAR *lcode; /* local strm->lencode */ - code const FAR *dcode; /* local strm->distcode */ - unsigned lmask; /* mask for first level of length codes */ - unsigned dmask; /* mask for first level of distance codes */ - code here; /* retrieved table entry */ - unsigned op; /* code bits, operation, extra bits, or */ - /* window position, window bytes to copy */ - unsigned len; /* match length, unused bytes */ - unsigned dist; /* match distance */ - unsigned char FAR *from; /* where to copy match from */ - - /* copy state to local variables */ - state = (struct inflate_state FAR *)strm->state; - in = strm->next_in - OFF; - last = in + (strm->avail_in - 5); - out = strm->next_out - OFF; - beg = out - (start - strm->avail_out); - end = out + (strm->avail_out - 257); -#ifdef INFLATE_STRICT - dmax = state->dmax; -#endif - wsize = state->wsize; - whave = state->whave; - wnext = state->wnext; - window = state->window; - hold = state->hold; - bits = state->bits; - lcode = state->lencode; - dcode = state->distcode; - lmask = (1U << state->lenbits) - 1; - dmask = (1U << state->distbits) - 1; - - /* decode literals and length/distances until end-of-block or not enough - input data or output space */ - do { - if (bits < 15) { - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - } - here = lcode[hold & lmask]; - dolen: - op = (unsigned)(here.bits); - hold >>= op; - bits -= op; - op = (unsigned)(here.op); - if (op == 0) { /* literal */ - Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? - "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", here.val)); - PUP(out) = (unsigned char)(here.val); - } - else if (op & 16) { /* length base */ - len = (unsigned)(here.val); - op &= 15; /* number of extra bits */ - if (op) { - if (bits < op) { - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - } - len += (unsigned)hold & ((1U << op) - 1); - hold >>= op; - bits -= op; - } - Tracevv((stderr, "inflate: length %u\n", len)); - if (bits < 15) { - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - } - here = dcode[hold & dmask]; - dodist: - op = (unsigned)(here.bits); - hold >>= op; - bits -= op; - op = (unsigned)(here.op); - if (op & 16) { /* distance base */ - dist = (unsigned)(here.val); - op &= 15; /* number of extra bits */ - if (bits < op) { - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - if (bits < op) { - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - } - } - dist += (unsigned)hold & ((1U << op) - 1); -#ifdef INFLATE_STRICT - if (dist > dmax) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#endif - hold >>= op; - bits -= op; - Tracevv((stderr, "inflate: distance %u\n", dist)); - op = (unsigned)(out - beg); /* max distance in output */ - if (dist > op) { /* see if copy from window */ - op = dist - op; /* distance back in window */ - if (op > whave) { - if (state->sane) { - strm->msg = - (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR - if (len <= op - whave) { - do { - PUP(out) = 0; - } while (--len); - continue; - } - len -= op - whave; - do { - PUP(out) = 0; - } while (--op > whave); - if (op == 0) { - from = out - dist; - do { - PUP(out) = PUP(from); - } while (--len); - continue; - } -#endif - } - from = window - OFF; - if (wnext == 0) { /* very common case */ - from += wsize - op; - if (op < len) { /* some from window */ - len -= op; - do { - PUP(out) = PUP(from); - } while (--op); - from = out - dist; /* rest from output */ - } - } - else if (wnext < op) { /* wrap around window */ - from += wsize + wnext - op; - op -= wnext; - if (op < len) { /* some from end of window */ - len -= op; - do { - PUP(out) = PUP(from); - } while (--op); - from = window - OFF; - if (wnext < len) { /* some from start of window */ - op = wnext; - len -= op; - do { - PUP(out) = PUP(from); - } while (--op); - from = out - dist; /* rest from output */ - } - } - } - else { /* contiguous in window */ - from += wnext - op; - if (op < len) { /* some from window */ - len -= op; - do { - PUP(out) = PUP(from); - } while (--op); - from = out - dist; /* rest from output */ - } - } - while (len > 2) { - PUP(out) = PUP(from); - PUP(out) = PUP(from); - PUP(out) = PUP(from); - len -= 3; - } - if (len) { - PUP(out) = PUP(from); - if (len > 1) - PUP(out) = PUP(from); - } - } - else { - from = out - dist; /* copy direct from output */ - do { /* minimum length is three */ - PUP(out) = PUP(from); - PUP(out) = PUP(from); - PUP(out) = PUP(from); - len -= 3; - } while (len > 2); - if (len) { - PUP(out) = PUP(from); - if (len > 1) - PUP(out) = PUP(from); - } - } - } - else if ((op & 64) == 0) { /* 2nd level distance code */ - here = dcode[here.val + (hold & ((1U << op) - 1))]; - goto dodist; - } - else { - strm->msg = (char *)"invalid distance code"; - state->mode = BAD; - break; - } - } - else if ((op & 64) == 0) { /* 2nd level length code */ - here = lcode[here.val + (hold & ((1U << op) - 1))]; - goto dolen; - } - else if (op & 32) { /* end-of-block */ - Tracevv((stderr, "inflate: end of block\n")); - state->mode = TYPE; - break; - } - else { - strm->msg = (char *)"invalid literal/length code"; - state->mode = BAD; - break; - } - } while (in < last && out < end); - - /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ - len = bits >> 3; - in -= len; - bits -= len << 3; - hold &= (1U << bits) - 1; - - /* update state and return */ - strm->next_in = in + OFF; - strm->next_out = out + OFF; - strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); - strm->avail_out = (unsigned)(out < end ? - 257 + (end - out) : 257 - (out - end)); - state->hold = hold; - state->bits = bits; - return; -} - -/* - inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): - - Using bit fields for code structure - - Different op definition to avoid & for extra bits (do & for table bits) - - Three separate decoding do-loops for direct, window, and wnext == 0 - - Special case for distance > 1 copies to do overlapped load and store copy - - Explicit branch predictions (based on measured branch probabilities) - - Deferring match copy and interspersed it with decoding subsequent codes - - Swapping literal/length else - - Swapping window/direct else - - Larger unrolled copy loops (three is about right) - - Moving len -= 3 statement into middle of loop - */ - -#endif /* !ASMINF */ diff --git a/cdf36_3-dist/src/lib/zlib/inffast.h b/cdf36_3-dist/src/lib/zlib/inffast.h deleted file mode 100644 index e5c1aa4..0000000 --- a/cdf36_3-dist/src/lib/zlib/inffast.h +++ /dev/null @@ -1,11 +0,0 @@ -/* inffast.h -- header to use inffast.c - * Copyright (C) 1995-2003, 2010 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); diff --git a/cdf36_3-dist/src/lib/zlib/inffixed.h b/cdf36_3-dist/src/lib/zlib/inffixed.h deleted file mode 100644 index d628327..0000000 --- a/cdf36_3-dist/src/lib/zlib/inffixed.h +++ /dev/null @@ -1,94 +0,0 @@ - /* inffixed.h -- table for decoding fixed codes - * Generated automatically by makefixed(). - */ - - /* WARNING: this file should *not* be used by applications. - It is part of the implementation of this library and is - subject to change. Applications should only use zlib.h. - */ - - static const code lenfix[512] = { - {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, - {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, - {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, - {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, - {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, - {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, - {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, - {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, - {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, - {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, - {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, - {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, - {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, - {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, - {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, - {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, - {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, - {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, - {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, - {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, - {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, - {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, - {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, - {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, - {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, - {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, - {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, - {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, - {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, - {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, - {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, - {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, - {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, - {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, - {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, - {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, - {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, - {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, - {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, - {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, - {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, - {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, - {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, - {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, - {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, - {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, - {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, - {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, - {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, - {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, - {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, - {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, - {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, - {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, - {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, - {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, - {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, - {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, - {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, - {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, - {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, - {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, - {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, - {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, - {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, - {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, - {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, - {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, - {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, - {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, - {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, - {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, - {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, - {0,9,255} - }; - - static const code distfix[32] = { - {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, - {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, - {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, - {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, - {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, - {22,5,193},{64,5,0} - }; diff --git a/cdf36_3-dist/src/lib/zlib/inflate.c b/cdf36_3-dist/src/lib/zlib/inflate.c deleted file mode 100644 index 870f89b..0000000 --- a/cdf36_3-dist/src/lib/zlib/inflate.c +++ /dev/null @@ -1,1512 +0,0 @@ -/* inflate.c -- zlib decompression - * Copyright (C) 1995-2012 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * Change history: - * - * 1.2.beta0 24 Nov 2002 - * - First version -- complete rewrite of inflate to simplify code, avoid - * creation of window when not needed, minimize use of window when it is - * needed, make inffast.c even faster, implement gzip decoding, and to - * improve code readability and style over the previous zlib inflate code - * - * 1.2.beta1 25 Nov 2002 - * - Use pointers for available input and output checking in inffast.c - * - Remove input and output counters in inffast.c - * - Change inffast.c entry and loop from avail_in >= 7 to >= 6 - * - Remove unnecessary second byte pull from length extra in inffast.c - * - Unroll direct copy to three copies per loop in inffast.c - * - * 1.2.beta2 4 Dec 2002 - * - Change external routine names to reduce potential conflicts - * - Correct filename to inffixed.h for fixed tables in inflate.c - * - Make hbuf[] unsigned char to match parameter type in inflate.c - * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset) - * to avoid negation problem on Alphas (64 bit) in inflate.c - * - * 1.2.beta3 22 Dec 2002 - * - Add comments on state->bits assertion in inffast.c - * - Add comments on op field in inftrees.h - * - Fix bug in reuse of allocated window after inflateReset() - * - Remove bit fields--back to byte structure for speed - * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths - * - Change post-increments to pre-increments in inflate_fast(), PPC biased? - * - Add compile time option, POSTINC, to use post-increments instead (Intel?) - * - Make MATCH copy in inflate() much faster for when inflate_fast() not used - * - Use local copies of stream next and avail values, as well as local bit - * buffer and bit count in inflate()--for speed when inflate_fast() not used - * - * 1.2.beta4 1 Jan 2003 - * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings - * - Move a comment on output buffer sizes from inffast.c to inflate.c - * - Add comments in inffast.c to introduce the inflate_fast() routine - * - Rearrange window copies in inflate_fast() for speed and simplification - * - Unroll last copy for window match in inflate_fast() - * - Use local copies of window variables in inflate_fast() for speed - * - Pull out common wnext == 0 case for speed in inflate_fast() - * - Make op and len in inflate_fast() unsigned for consistency - * - Add FAR to lcode and dcode declarations in inflate_fast() - * - Simplified bad distance check in inflate_fast() - * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new - * source file infback.c to provide a call-back interface to inflate for - * programs like gzip and unzip -- uses window as output buffer to avoid - * window copying - * - * 1.2.beta5 1 Jan 2003 - * - Improved inflateBack() interface to allow the caller to provide initial - * input in strm. - * - Fixed stored blocks bug in inflateBack() - * - * 1.2.beta6 4 Jan 2003 - * - Added comments in inffast.c on effectiveness of POSTINC - * - Typecasting all around to reduce compiler warnings - * - Changed loops from while (1) or do {} while (1) to for (;;), again to - * make compilers happy - * - Changed type of window in inflateBackInit() to unsigned char * - * - * 1.2.beta7 27 Jan 2003 - * - Changed many types to unsigned or unsigned short to avoid warnings - * - Added inflateCopy() function - * - * 1.2.0 9 Mar 2003 - * - Changed inflateBack() interface to provide separate opaque descriptors - * for the in() and out() functions - * - Changed inflateBack() argument and in_func typedef to swap the length - * and buffer address return values for the input function - * - Check next_in and next_out for Z_NULL on entry to inflate() - * - * The history for versions after 1.2.0 are in ChangeLog in zlib distribution. - */ - -#include "zutil.h" -#include "inftrees.h" -#include "inflate.h" -#include "inffast.h" - -#ifdef MAKEFIXED -# ifndef BUILDFIXED -# define BUILDFIXED -# endif -#endif - -/* function prototypes */ -local void fixedtables OF((struct inflate_state FAR *state)); -local int updatewindow OF((z_streamp strm, const unsigned char FAR *end, - unsigned copy)); -#ifdef BUILDFIXED - void makefixed OF((void)); -#endif -local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, - unsigned len)); - -int ZEXPORT inflateResetKeep(strm) -z_streamp strm; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - strm->total_in = strm->total_out = state->total = 0; - strm->msg = Z_NULL; - if (state->wrap) /* to support ill-conceived Java test suite */ - strm->adler = state->wrap & 1; - state->mode = HEAD; - state->last = 0; - state->havedict = 0; - state->dmax = 32768U; - state->head = Z_NULL; - state->hold = 0; - state->bits = 0; - state->lencode = state->distcode = state->next = state->codes; - state->sane = 1; - state->back = -1; - Tracev((stderr, "inflate: reset\n")); - return Z_OK; -} - -int ZEXPORT inflateReset(strm) -z_streamp strm; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - state->wsize = 0; - state->whave = 0; - state->wnext = 0; - return inflateResetKeep(strm); -} - -int ZEXPORT inflateReset2(strm, windowBits) -z_streamp strm; -int windowBits; -{ - int wrap; - struct inflate_state FAR *state; - - /* get the state */ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - - /* extract wrap request from windowBits parameter */ - if (windowBits < 0) { - wrap = 0; - windowBits = -windowBits; - } - else { - wrap = (windowBits >> 4) + 1; -#ifdef GUNZIP - if (windowBits < 48) - windowBits &= 15; -#endif - } - - /* set number of window bits, free window if different */ - if (windowBits && (windowBits < 8 || windowBits > 15)) - return Z_STREAM_ERROR; - if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) { - ZFREE(strm, state->window); - state->window = Z_NULL; - } - - /* update state and reset the rest of it */ - state->wrap = wrap; - state->wbits = (unsigned)windowBits; - return inflateReset(strm); -} - -int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) -z_streamp strm; -int windowBits; -const char *version; -int stream_size; -{ - int ret; - struct inflate_state FAR *state; - - if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || - stream_size != (int)(sizeof(z_stream))) - return Z_VERSION_ERROR; - if (strm == Z_NULL) return Z_STREAM_ERROR; - strm->msg = Z_NULL; /* in case we return an error */ - if (strm->zalloc == (alloc_func)0) { -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; -#endif - } - if (strm->zfree == (free_func)0) -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zfree = zcfree; -#endif - state = (struct inflate_state FAR *) - ZALLOC(strm, 1, sizeof(struct inflate_state)); - if (state == Z_NULL) return Z_MEM_ERROR; - Tracev((stderr, "inflate: allocated\n")); - strm->state = (struct internal_state FAR *)state; - state->window = Z_NULL; - ret = inflateReset2(strm, windowBits); - if (ret != Z_OK) { - ZFREE(strm, state); - strm->state = Z_NULL; - } - return ret; -} - -int ZEXPORT inflateInit_(strm, version, stream_size) -z_streamp strm; -const char *version; -int stream_size; -{ - return inflateInit2_(strm, DEF_WBITS, version, stream_size); -} - -int ZEXPORT inflatePrime(strm, bits, value) -z_streamp strm; -int bits; -int value; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (bits < 0) { - state->hold = 0; - state->bits = 0; - return Z_OK; - } - if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR; - value &= (1L << bits) - 1; - state->hold += value << state->bits; - state->bits += bits; - return Z_OK; -} - -/* - Return state with length and distance decoding tables and index sizes set to - fixed code decoding. Normally this returns fixed tables from inffixed.h. - If BUILDFIXED is defined, then instead this routine builds the tables the - first time it's called, and returns those tables the first time and - thereafter. This reduces the size of the code by about 2K bytes, in - exchange for a little execution time. However, BUILDFIXED should not be - used for threaded applications, since the rewriting of the tables and virgin - may not be thread-safe. - */ -local void fixedtables(state) -struct inflate_state FAR *state; -{ -#ifdef BUILDFIXED - static int virgin = 1; - static code *lenfix, *distfix; - static code fixed[544]; - - /* build fixed huffman tables if first call (may not be thread safe) */ - if (virgin) { - unsigned sym, bits; - static code *next; - - /* literal/length table */ - sym = 0; - while (sym < 144) state->lens[sym++] = 8; - while (sym < 256) state->lens[sym++] = 9; - while (sym < 280) state->lens[sym++] = 7; - while (sym < 288) state->lens[sym++] = 8; - next = fixed; - lenfix = next; - bits = 9; - inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); - - /* distance table */ - sym = 0; - while (sym < 32) state->lens[sym++] = 5; - distfix = next; - bits = 5; - inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); - - /* do this just once */ - virgin = 0; - } -#else /* !BUILDFIXED */ -# include "inffixed.h" -#endif /* BUILDFIXED */ - state->lencode = lenfix; - state->lenbits = 9; - state->distcode = distfix; - state->distbits = 5; -} - -#ifdef MAKEFIXED -#include - -/* - Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also - defines BUILDFIXED, so the tables are built on the fly. makefixed() writes - those tables to stdout, which would be piped to inffixed.h. A small program - can simply call makefixed to do this: - - void makefixed(void); - - int main(void) - { - makefixed(); - return 0; - } - - Then that can be linked with zlib built with MAKEFIXED defined and run: - - a.out > inffixed.h - */ -void makefixed() -{ - unsigned low, size; - struct inflate_state state; - - fixedtables(&state); - puts(" /* inffixed.h -- table for decoding fixed codes"); - puts(" * Generated automatically by makefixed()."); - puts(" */"); - puts(""); - puts(" /* WARNING: this file should *not* be used by applications."); - puts(" It is part of the implementation of this library and is"); - puts(" subject to change. Applications should only use zlib.h."); - puts(" */"); - puts(""); - size = 1U << 9; - printf(" static const code lenfix[%u] = {", size); - low = 0; - for (;;) { - if ((low % 7) == 0) printf("\n "); - printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op, - state.lencode[low].bits, state.lencode[low].val); - if (++low == size) break; - putchar(','); - } - puts("\n };"); - size = 1U << 5; - printf("\n static const code distfix[%u] = {", size); - low = 0; - for (;;) { - if ((low % 6) == 0) printf("\n "); - printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, - state.distcode[low].val); - if (++low == size) break; - putchar(','); - } - puts("\n };"); -} -#endif /* MAKEFIXED */ - -/* - Update the window with the last wsize (normally 32K) bytes written before - returning. If window does not exist yet, create it. This is only called - when a window is already in use, or when output has been written during this - inflate call, but the end of the deflate stream has not been reached yet. - It is also called to create a window for dictionary data when a dictionary - is loaded. - - Providing output buffers larger than 32K to inflate() should provide a speed - advantage, since only the last 32K of output is copied to the sliding window - upon return from inflate(), and since all distances after the first 32K of - output will fall in the output data, making match copies simpler and faster. - The advantage may be dependent on the size of the processor's data caches. - */ -local int updatewindow(strm, end, copy) -z_streamp strm; -const Bytef *end; -unsigned copy; -{ - struct inflate_state FAR *state; - unsigned dist; - - state = (struct inflate_state FAR *)strm->state; - - /* if it hasn't been done already, allocate space for the window */ - if (state->window == Z_NULL) { - state->window = (unsigned char FAR *) - ZALLOC(strm, 1U << state->wbits, - sizeof(unsigned char)); - if (state->window == Z_NULL) return 1; - } - - /* if window not in use yet, initialize */ - if (state->wsize == 0) { - state->wsize = 1U << state->wbits; - state->wnext = 0; - state->whave = 0; - } - - /* copy state->wsize or less output bytes into the circular window */ - if (copy >= state->wsize) { - zmemcpy(state->window, end - state->wsize, state->wsize); - state->wnext = 0; - state->whave = state->wsize; - } - else { - dist = state->wsize - state->wnext; - if (dist > copy) dist = copy; - zmemcpy(state->window + state->wnext, end - copy, dist); - copy -= dist; - if (copy) { - zmemcpy(state->window, end - copy, copy); - state->wnext = copy; - state->whave = state->wsize; - } - else { - state->wnext += dist; - if (state->wnext == state->wsize) state->wnext = 0; - if (state->whave < state->wsize) state->whave += dist; - } - } - return 0; -} - -/* Macros for inflate(): */ - -/* check function to use adler32() for zlib or crc32() for gzip */ -#ifdef GUNZIP -# define UPDATE(check, buf, len) \ - (state->flags ? crc32(check, buf, len) : adler32(check, buf, len)) -#else -# define UPDATE(check, buf, len) adler32(check, buf, len) -#endif - -/* check macros for header crc */ -#ifdef GUNZIP -# define CRC2(check, word) \ - do { \ - hbuf[0] = (unsigned char)(word); \ - hbuf[1] = (unsigned char)((word) >> 8); \ - check = crc32(check, hbuf, 2); \ - } while (0) - -# define CRC4(check, word) \ - do { \ - hbuf[0] = (unsigned char)(word); \ - hbuf[1] = (unsigned char)((word) >> 8); \ - hbuf[2] = (unsigned char)((word) >> 16); \ - hbuf[3] = (unsigned char)((word) >> 24); \ - check = crc32(check, hbuf, 4); \ - } while (0) -#endif - -/* Load registers with state in inflate() for speed */ -#define LOAD() \ - do { \ - put = strm->next_out; \ - left = strm->avail_out; \ - next = strm->next_in; \ - have = strm->avail_in; \ - hold = state->hold; \ - bits = state->bits; \ - } while (0) - -/* Restore state from registers in inflate() */ -#define RESTORE() \ - do { \ - strm->next_out = put; \ - strm->avail_out = left; \ - strm->next_in = next; \ - strm->avail_in = have; \ - state->hold = hold; \ - state->bits = bits; \ - } while (0) - -/* Clear the input bit accumulator */ -#define INITBITS() \ - do { \ - hold = 0; \ - bits = 0; \ - } while (0) - -/* Get a byte of input into the bit accumulator, or return from inflate() - if there is no input available. */ -#define PULLBYTE() \ - do { \ - if (have == 0) goto inf_leave; \ - have--; \ - hold += (unsigned long)(*next++) << bits; \ - bits += 8; \ - } while (0) - -/* Assure that there are at least n bits in the bit accumulator. If there is - not enough available input to do that, then return from inflate(). */ -#define NEEDBITS(n) \ - do { \ - while (bits < (unsigned)(n)) \ - PULLBYTE(); \ - } while (0) - -/* Return the low n bits of the bit accumulator (n < 16) */ -#define BITS(n) \ - ((unsigned)hold & ((1U << (n)) - 1)) - -/* Remove n bits from the bit accumulator */ -#define DROPBITS(n) \ - do { \ - hold >>= (n); \ - bits -= (unsigned)(n); \ - } while (0) - -/* Remove zero to seven bits as needed to go to a byte boundary */ -#define BYTEBITS() \ - do { \ - hold >>= bits & 7; \ - bits -= bits & 7; \ - } while (0) - -/* - inflate() uses a state machine to process as much input data and generate as - much output data as possible before returning. The state machine is - structured roughly as follows: - - for (;;) switch (state) { - ... - case STATEn: - if (not enough input data or output space to make progress) - return; - ... make progress ... - state = STATEm; - break; - ... - } - - so when inflate() is called again, the same case is attempted again, and - if the appropriate resources are provided, the machine proceeds to the - next state. The NEEDBITS() macro is usually the way the state evaluates - whether it can proceed or should return. NEEDBITS() does the return if - the requested bits are not available. The typical use of the BITS macros - is: - - NEEDBITS(n); - ... do something with BITS(n) ... - DROPBITS(n); - - where NEEDBITS(n) either returns from inflate() if there isn't enough - input left to load n bits into the accumulator, or it continues. BITS(n) - gives the low n bits in the accumulator. When done, DROPBITS(n) drops - the low n bits off the accumulator. INITBITS() clears the accumulator - and sets the number of available bits to zero. BYTEBITS() discards just - enough bits to put the accumulator on a byte boundary. After BYTEBITS() - and a NEEDBITS(8), then BITS(8) would return the next byte in the stream. - - NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return - if there is no input available. The decoding of variable length codes uses - PULLBYTE() directly in order to pull just enough bytes to decode the next - code, and no more. - - Some states loop until they get enough input, making sure that enough - state information is maintained to continue the loop where it left off - if NEEDBITS() returns in the loop. For example, want, need, and keep - would all have to actually be part of the saved state in case NEEDBITS() - returns: - - case STATEw: - while (want < need) { - NEEDBITS(n); - keep[want++] = BITS(n); - DROPBITS(n); - } - state = STATEx; - case STATEx: - - As shown above, if the next state is also the next case, then the break - is omitted. - - A state may also return if there is not enough output space available to - complete that state. Those states are copying stored data, writing a - literal byte, and copying a matching string. - - When returning, a "goto inf_leave" is used to update the total counters, - update the check value, and determine whether any progress has been made - during that inflate() call in order to return the proper return code. - Progress is defined as a change in either strm->avail_in or strm->avail_out. - When there is a window, goto inf_leave will update the window with the last - output written. If a goto inf_leave occurs in the middle of decompression - and there is no window currently, goto inf_leave will create one and copy - output to the window for the next call of inflate(). - - In this implementation, the flush parameter of inflate() only affects the - return code (per zlib.h). inflate() always writes as much as possible to - strm->next_out, given the space available and the provided input--the effect - documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers - the allocation of and copying into a sliding window until necessary, which - provides the effect documented in zlib.h for Z_FINISH when the entire input - stream available. So the only thing the flush parameter actually does is: - when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it - will return Z_BUF_ERROR if it has not reached the end of the stream. - */ - -int ZEXPORT inflate(strm, flush) -z_streamp strm; -int flush; -{ - struct inflate_state FAR *state; - z_const unsigned char FAR *next; /* next input */ - unsigned char FAR *put; /* next output */ - unsigned have, left; /* available input and output */ - unsigned long hold; /* bit buffer */ - unsigned bits; /* bits in bit buffer */ - unsigned in, out; /* save starting available input and output */ - unsigned copy; /* number of stored or match bytes to copy */ - unsigned char FAR *from; /* where to copy match bytes from */ - code here; /* current decoding table entry */ - code last; /* parent table entry */ - unsigned len; /* length to copy for repeats, bits to drop */ - int ret; /* return code */ -#ifdef GUNZIP - unsigned char hbuf[4]; /* buffer for gzip header crc calculation */ -#endif - static const unsigned short order[19] = /* permutation of code lengths */ - {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; - - if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL || - (strm->next_in == Z_NULL && strm->avail_in != 0)) - return Z_STREAM_ERROR; - - state = (struct inflate_state FAR *)strm->state; - if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */ - LOAD(); - in = have; - out = left; - ret = Z_OK; - for (;;) - switch (state->mode) { - case HEAD: - if (state->wrap == 0) { - state->mode = TYPEDO; - break; - } - NEEDBITS(16); -#ifdef GUNZIP - if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */ - state->check = crc32(0L, Z_NULL, 0); - CRC2(state->check, hold); - INITBITS(); - state->mode = FLAGS; - break; - } - state->flags = 0; /* expect zlib header */ - if (state->head != Z_NULL) - state->head->done = -1; - if (!(state->wrap & 1) || /* check if zlib header allowed */ -#else - if ( -#endif - ((BITS(8) << 8) + (hold >> 8)) % 31) { - strm->msg = (char *)"incorrect header check"; - state->mode = BAD; - break; - } - if (BITS(4) != Z_DEFLATED) { - strm->msg = (char *)"unknown compression method"; - state->mode = BAD; - break; - } - DROPBITS(4); - len = BITS(4) + 8; - if (state->wbits == 0) - state->wbits = len; - else if (len > state->wbits) { - strm->msg = (char *)"invalid window size"; - state->mode = BAD; - break; - } - state->dmax = 1U << len; - Tracev((stderr, "inflate: zlib header ok\n")); - strm->adler = state->check = adler32(0L, Z_NULL, 0); - state->mode = hold & 0x200 ? DICTID : TYPE; - INITBITS(); - break; -#ifdef GUNZIP - case FLAGS: - NEEDBITS(16); - state->flags = (int)(hold); - if ((state->flags & 0xff) != Z_DEFLATED) { - strm->msg = (char *)"unknown compression method"; - state->mode = BAD; - break; - } - if (state->flags & 0xe000) { - strm->msg = (char *)"unknown header flags set"; - state->mode = BAD; - break; - } - if (state->head != Z_NULL) - state->head->text = (int)((hold >> 8) & 1); - if (state->flags & 0x0200) CRC2(state->check, hold); - INITBITS(); - state->mode = TIME; - case TIME: - NEEDBITS(32); - if (state->head != Z_NULL) - state->head->time = hold; - if (state->flags & 0x0200) CRC4(state->check, hold); - INITBITS(); - state->mode = OS; - case OS: - NEEDBITS(16); - if (state->head != Z_NULL) { - state->head->xflags = (int)(hold & 0xff); - state->head->os = (int)(hold >> 8); - } - if (state->flags & 0x0200) CRC2(state->check, hold); - INITBITS(); - state->mode = EXLEN; - case EXLEN: - if (state->flags & 0x0400) { - NEEDBITS(16); - state->length = (unsigned)(hold); - if (state->head != Z_NULL) - state->head->extra_len = (unsigned)hold; - if (state->flags & 0x0200) CRC2(state->check, hold); - INITBITS(); - } - else if (state->head != Z_NULL) - state->head->extra = Z_NULL; - state->mode = EXTRA; - case EXTRA: - if (state->flags & 0x0400) { - copy = state->length; - if (copy > have) copy = have; - if (copy) { - if (state->head != Z_NULL && - state->head->extra != Z_NULL) { - len = state->head->extra_len - state->length; - zmemcpy(state->head->extra + len, next, - len + copy > state->head->extra_max ? - state->head->extra_max - len : copy); - } - if (state->flags & 0x0200) - state->check = crc32(state->check, next, copy); - have -= copy; - next += copy; - state->length -= copy; - } - if (state->length) goto inf_leave; - } - state->length = 0; - state->mode = NAME; - case NAME: - if (state->flags & 0x0800) { - if (have == 0) goto inf_leave; - copy = 0; - do { - len = (unsigned)(next[copy++]); - if (state->head != Z_NULL && - state->head->name != Z_NULL && - state->length < state->head->name_max) - state->head->name[state->length++] = len; - } while (len && copy < have); - if (state->flags & 0x0200) - state->check = crc32(state->check, next, copy); - have -= copy; - next += copy; - if (len) goto inf_leave; - } - else if (state->head != Z_NULL) - state->head->name = Z_NULL; - state->length = 0; - state->mode = COMMENT; - case COMMENT: - if (state->flags & 0x1000) { - if (have == 0) goto inf_leave; - copy = 0; - do { - len = (unsigned)(next[copy++]); - if (state->head != Z_NULL && - state->head->comment != Z_NULL && - state->length < state->head->comm_max) - state->head->comment[state->length++] = len; - } while (len && copy < have); - if (state->flags & 0x0200) - state->check = crc32(state->check, next, copy); - have -= copy; - next += copy; - if (len) goto inf_leave; - } - else if (state->head != Z_NULL) - state->head->comment = Z_NULL; - state->mode = HCRC; - case HCRC: - if (state->flags & 0x0200) { - NEEDBITS(16); - if (hold != (state->check & 0xffff)) { - strm->msg = (char *)"header crc mismatch"; - state->mode = BAD; - break; - } - INITBITS(); - } - if (state->head != Z_NULL) { - state->head->hcrc = (int)((state->flags >> 9) & 1); - state->head->done = 1; - } - strm->adler = state->check = crc32(0L, Z_NULL, 0); - state->mode = TYPE; - break; -#endif - case DICTID: - NEEDBITS(32); - strm->adler = state->check = ZSWAP32(hold); - INITBITS(); - state->mode = DICT; - case DICT: - if (state->havedict == 0) { - RESTORE(); - return Z_NEED_DICT; - } - strm->adler = state->check = adler32(0L, Z_NULL, 0); - state->mode = TYPE; - case TYPE: - if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave; - case TYPEDO: - if (state->last) { - BYTEBITS(); - state->mode = CHECK; - break; - } - NEEDBITS(3); - state->last = BITS(1); - DROPBITS(1); - switch (BITS(2)) { - case 0: /* stored block */ - Tracev((stderr, "inflate: stored block%s\n", - state->last ? " (last)" : "")); - state->mode = STORED; - break; - case 1: /* fixed block */ - fixedtables(state); - Tracev((stderr, "inflate: fixed codes block%s\n", - state->last ? " (last)" : "")); - state->mode = LEN_; /* decode codes */ - if (flush == Z_TREES) { - DROPBITS(2); - goto inf_leave; - } - break; - case 2: /* dynamic block */ - Tracev((stderr, "inflate: dynamic codes block%s\n", - state->last ? " (last)" : "")); - state->mode = TABLE; - break; - case 3: - strm->msg = (char *)"invalid block type"; - state->mode = BAD; - } - DROPBITS(2); - break; - case STORED: - BYTEBITS(); /* go to byte boundary */ - NEEDBITS(32); - if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { - strm->msg = (char *)"invalid stored block lengths"; - state->mode = BAD; - break; - } - state->length = (unsigned)hold & 0xffff; - Tracev((stderr, "inflate: stored length %u\n", - state->length)); - INITBITS(); - state->mode = COPY_; - if (flush == Z_TREES) goto inf_leave; - case COPY_: - state->mode = COPY; - case COPY: - copy = state->length; - if (copy) { - if (copy > have) copy = have; - if (copy > left) copy = left; - if (copy == 0) goto inf_leave; - zmemcpy(put, next, copy); - have -= copy; - next += copy; - left -= copy; - put += copy; - state->length -= copy; - break; - } - Tracev((stderr, "inflate: stored end\n")); - state->mode = TYPE; - break; - case TABLE: - NEEDBITS(14); - state->nlen = BITS(5) + 257; - DROPBITS(5); - state->ndist = BITS(5) + 1; - DROPBITS(5); - state->ncode = BITS(4) + 4; - DROPBITS(4); -#ifndef PKZIP_BUG_WORKAROUND - if (state->nlen > 286 || state->ndist > 30) { - strm->msg = (char *)"too many length or distance symbols"; - state->mode = BAD; - break; - } -#endif - Tracev((stderr, "inflate: table sizes ok\n")); - state->have = 0; - state->mode = LENLENS; - case LENLENS: - while (state->have < state->ncode) { - NEEDBITS(3); - state->lens[order[state->have++]] = (unsigned short)BITS(3); - DROPBITS(3); - } - while (state->have < 19) - state->lens[order[state->have++]] = 0; - state->next = state->codes; - state->lencode = (const code FAR *)(state->next); - state->lenbits = 7; - ret = inflate_table(CODES, state->lens, 19, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid code lengths set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: code lengths ok\n")); - state->have = 0; - state->mode = CODELENS; - case CODELENS: - while (state->have < state->nlen + state->ndist) { - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.val < 16) { - DROPBITS(here.bits); - state->lens[state->have++] = here.val; - } - else { - if (here.val == 16) { - NEEDBITS(here.bits + 2); - DROPBITS(here.bits); - if (state->have == 0) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - len = state->lens[state->have - 1]; - copy = 3 + BITS(2); - DROPBITS(2); - } - else if (here.val == 17) { - NEEDBITS(here.bits + 3); - DROPBITS(here.bits); - len = 0; - copy = 3 + BITS(3); - DROPBITS(3); - } - else { - NEEDBITS(here.bits + 7); - DROPBITS(here.bits); - len = 0; - copy = 11 + BITS(7); - DROPBITS(7); - } - if (state->have + copy > state->nlen + state->ndist) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - while (copy--) - state->lens[state->have++] = (unsigned short)len; - } - } - - /* handle error breaks in while */ - if (state->mode == BAD) break; - - /* check for end-of-block code (better have one) */ - if (state->lens[256] == 0) { - strm->msg = (char *)"invalid code -- missing end-of-block"; - state->mode = BAD; - break; - } - - /* build code tables -- note: do not change the lenbits or distbits - values here (9 and 6) without reading the comments in inftrees.h - concerning the ENOUGH constants, which depend on those values */ - state->next = state->codes; - state->lencode = (const code FAR *)(state->next); - state->lenbits = 9; - ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid literal/lengths set"; - state->mode = BAD; - break; - } - state->distcode = (const code FAR *)(state->next); - state->distbits = 6; - ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, - &(state->next), &(state->distbits), state->work); - if (ret) { - strm->msg = (char *)"invalid distances set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: codes ok\n")); - state->mode = LEN_; - if (flush == Z_TREES) goto inf_leave; - case LEN_: - state->mode = LEN; - case LEN: - if (have >= 6 && left >= 258) { - RESTORE(); - inflate_fast(strm, out); - LOAD(); - if (state->mode == TYPE) - state->back = -1; - break; - } - state->back = 0; - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.op && (here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->lencode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - state->back += last.bits; - } - DROPBITS(here.bits); - state->back += here.bits; - state->length = (unsigned)here.val; - if ((int)(here.op) == 0) { - Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? - "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", here.val)); - state->mode = LIT; - break; - } - if (here.op & 32) { - Tracevv((stderr, "inflate: end of block\n")); - state->back = -1; - state->mode = TYPE; - break; - } - if (here.op & 64) { - strm->msg = (char *)"invalid literal/length code"; - state->mode = BAD; - break; - } - state->extra = (unsigned)(here.op) & 15; - state->mode = LENEXT; - case LENEXT: - if (state->extra) { - NEEDBITS(state->extra); - state->length += BITS(state->extra); - DROPBITS(state->extra); - state->back += state->extra; - } - Tracevv((stderr, "inflate: length %u\n", state->length)); - state->was = state->length; - state->mode = DIST; - case DIST: - for (;;) { - here = state->distcode[BITS(state->distbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if ((here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->distcode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - state->back += last.bits; - } - DROPBITS(here.bits); - state->back += here.bits; - if (here.op & 64) { - strm->msg = (char *)"invalid distance code"; - state->mode = BAD; - break; - } - state->offset = (unsigned)here.val; - state->extra = (unsigned)(here.op) & 15; - state->mode = DISTEXT; - case DISTEXT: - if (state->extra) { - NEEDBITS(state->extra); - state->offset += BITS(state->extra); - DROPBITS(state->extra); - state->back += state->extra; - } -#ifdef INFLATE_STRICT - if (state->offset > state->dmax) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#endif - Tracevv((stderr, "inflate: distance %u\n", state->offset)); - state->mode = MATCH; - case MATCH: - if (left == 0) goto inf_leave; - copy = out - left; - if (state->offset > copy) { /* copy from window */ - copy = state->offset - copy; - if (copy > state->whave) { - if (state->sane) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR - Trace((stderr, "inflate.c too far\n")); - copy -= state->whave; - if (copy > state->length) copy = state->length; - if (copy > left) copy = left; - left -= copy; - state->length -= copy; - do { - *put++ = 0; - } while (--copy); - if (state->length == 0) state->mode = LEN; - break; -#endif - } - if (copy > state->wnext) { - copy -= state->wnext; - from = state->window + (state->wsize - copy); - } - else - from = state->window + (state->wnext - copy); - if (copy > state->length) copy = state->length; - } - else { /* copy from output */ - from = put - state->offset; - copy = state->length; - } - if (copy > left) copy = left; - left -= copy; - state->length -= copy; - do { - *put++ = *from++; - } while (--copy); - if (state->length == 0) state->mode = LEN; - break; - case LIT: - if (left == 0) goto inf_leave; - *put++ = (unsigned char)(state->length); - left--; - state->mode = LEN; - break; - case CHECK: - if (state->wrap) { - NEEDBITS(32); - out -= left; - strm->total_out += out; - state->total += out; - if (out) - strm->adler = state->check = - UPDATE(state->check, put - out, out); - out = left; - if (( -#ifdef GUNZIP - state->flags ? hold : -#endif - ZSWAP32(hold)) != state->check) { - strm->msg = (char *)"incorrect data check"; - state->mode = BAD; - break; - } - INITBITS(); - Tracev((stderr, "inflate: check matches trailer\n")); - } -#ifdef GUNZIP - state->mode = LENGTH; - case LENGTH: - if (state->wrap && state->flags) { - NEEDBITS(32); - if (hold != (state->total & 0xffffffffUL)) { - strm->msg = (char *)"incorrect length check"; - state->mode = BAD; - break; - } - INITBITS(); - Tracev((stderr, "inflate: length matches trailer\n")); - } -#endif - state->mode = DONE; - case DONE: - ret = Z_STREAM_END; - goto inf_leave; - case BAD: - ret = Z_DATA_ERROR; - goto inf_leave; - case MEM: - return Z_MEM_ERROR; - case SYNC: - default: - return Z_STREAM_ERROR; - } - - /* - Return from inflate(), updating the total counts and the check value. - If there was no progress during the inflate() call, return a buffer - error. Call updatewindow() to create and/or update the window state. - Note: a memory error from inflate() is non-recoverable. - */ - inf_leave: - RESTORE(); - if (state->wsize || (out != strm->avail_out && state->mode < BAD && - (state->mode < CHECK || flush != Z_FINISH))) - if (updatewindow(strm, strm->next_out, out - strm->avail_out)) { - state->mode = MEM; - return Z_MEM_ERROR; - } - in -= strm->avail_in; - out -= strm->avail_out; - strm->total_in += in; - strm->total_out += out; - state->total += out; - if (state->wrap && out) - strm->adler = state->check = - UPDATE(state->check, strm->next_out - out, out); - strm->data_type = state->bits + (state->last ? 64 : 0) + - (state->mode == TYPE ? 128 : 0) + - (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0); - if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) - ret = Z_BUF_ERROR; - return ret; -} - -int ZEXPORT inflateEnd(strm) -z_streamp strm; -{ - struct inflate_state FAR *state; - if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) - return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (state->window != Z_NULL) ZFREE(strm, state->window); - ZFREE(strm, strm->state); - strm->state = Z_NULL; - Tracev((stderr, "inflate: end\n")); - return Z_OK; -} - -int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength) -z_streamp strm; -Bytef *dictionary; -uInt *dictLength; -{ - struct inflate_state FAR *state; - - /* check state */ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - - /* copy dictionary */ - if (state->whave && dictionary != Z_NULL) { - zmemcpy(dictionary, state->window + state->wnext, - state->whave - state->wnext); - zmemcpy(dictionary + state->whave - state->wnext, - state->window, state->wnext); - } - if (dictLength != Z_NULL) - *dictLength = state->whave; - return Z_OK; -} - -int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) -z_streamp strm; -const Bytef *dictionary; -uInt dictLength; -{ - struct inflate_state FAR *state; - unsigned long dictid; - int ret; - - /* check state */ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (state->wrap != 0 && state->mode != DICT) - return Z_STREAM_ERROR; - - /* check for correct dictionary identifier */ - if (state->mode == DICT) { - dictid = adler32(0L, Z_NULL, 0); - dictid = adler32(dictid, dictionary, dictLength); - if (dictid != state->check) - return Z_DATA_ERROR; - } - - /* copy dictionary to window using updatewindow(), which will amend the - existing dictionary if appropriate */ - ret = updatewindow(strm, dictionary + dictLength, dictLength); - if (ret) { - state->mode = MEM; - return Z_MEM_ERROR; - } - state->havedict = 1; - Tracev((stderr, "inflate: dictionary set\n")); - return Z_OK; -} - -int ZEXPORT inflateGetHeader(strm, head) -z_streamp strm; -gz_headerp head; -{ - struct inflate_state FAR *state; - - /* check state */ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if ((state->wrap & 2) == 0) return Z_STREAM_ERROR; - - /* save header structure */ - state->head = head; - head->done = 0; - return Z_OK; -} - -/* - Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found - or when out of input. When called, *have is the number of pattern bytes - found in order so far, in 0..3. On return *have is updated to the new - state. If on return *have equals four, then the pattern was found and the - return value is how many bytes were read including the last byte of the - pattern. If *have is less than four, then the pattern has not been found - yet and the return value is len. In the latter case, syncsearch() can be - called again with more data and the *have state. *have is initialized to - zero for the first call. - */ -local unsigned syncsearch(have, buf, len) -unsigned FAR *have; -const unsigned char FAR *buf; -unsigned len; -{ - unsigned got; - unsigned next; - - got = *have; - next = 0; - while (next < len && got < 4) { - if ((int)(buf[next]) == (got < 2 ? 0 : 0xff)) - got++; - else if (buf[next]) - got = 0; - else - got = 4 - got; - next++; - } - *have = got; - return next; -} - -int ZEXPORT inflateSync(strm) -z_streamp strm; -{ - unsigned len; /* number of bytes to look at or looked at */ - unsigned long in, out; /* temporary to save total_in and total_out */ - unsigned char buf[4]; /* to restore bit buffer to byte string */ - struct inflate_state FAR *state; - - /* check parameters */ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR; - - /* if first time, start search in bit buffer */ - if (state->mode != SYNC) { - state->mode = SYNC; - state->hold <<= state->bits & 7; - state->bits -= state->bits & 7; - len = 0; - while (state->bits >= 8) { - buf[len++] = (unsigned char)(state->hold); - state->hold >>= 8; - state->bits -= 8; - } - state->have = 0; - syncsearch(&(state->have), buf, len); - } - - /* search available input */ - len = syncsearch(&(state->have), strm->next_in, strm->avail_in); - strm->avail_in -= len; - strm->next_in += len; - strm->total_in += len; - - /* return no joy or set up to restart inflate() on a new block */ - if (state->have != 4) return Z_DATA_ERROR; - in = strm->total_in; out = strm->total_out; - inflateReset(strm); - strm->total_in = in; strm->total_out = out; - state->mode = TYPE; - return Z_OK; -} - -/* - Returns true if inflate is currently at the end of a block generated by - Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP - implementation to provide an additional safety check. PPP uses - Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored - block. When decompressing, PPP checks that at the end of input packet, - inflate is waiting for these length bytes. - */ -int ZEXPORT inflateSyncPoint(strm) -z_streamp strm; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - return state->mode == STORED && state->bits == 0; -} - -int ZEXPORT inflateCopy(dest, source) -z_streamp dest; -z_streamp source; -{ - struct inflate_state FAR *state; - struct inflate_state FAR *copy; - unsigned char FAR *window; - unsigned wsize; - - /* check input */ - if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL || - source->zalloc == (alloc_func)0 || source->zfree == (free_func)0) - return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)source->state; - - /* allocate space */ - copy = (struct inflate_state FAR *) - ZALLOC(source, 1, sizeof(struct inflate_state)); - if (copy == Z_NULL) return Z_MEM_ERROR; - window = Z_NULL; - if (state->window != Z_NULL) { - window = (unsigned char FAR *) - ZALLOC(source, 1U << state->wbits, sizeof(unsigned char)); - if (window == Z_NULL) { - ZFREE(source, copy); - return Z_MEM_ERROR; - } - } - - /* copy state */ - zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); - zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); - if (state->lencode >= state->codes && - state->lencode <= state->codes + ENOUGH - 1) { - copy->lencode = copy->codes + (state->lencode - state->codes); - copy->distcode = copy->codes + (state->distcode - state->codes); - } - copy->next = copy->codes + (state->next - state->codes); - if (window != Z_NULL) { - wsize = 1U << state->wbits; - zmemcpy(window, state->window, wsize); - } - copy->window = window; - dest->state = (struct internal_state FAR *)copy; - return Z_OK; -} - -int ZEXPORT inflateUndermine(strm, subvert) -z_streamp strm; -int subvert; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - state->sane = !subvert; -#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR - return Z_OK; -#else - state->sane = 1; - return Z_DATA_ERROR; -#endif -} - -long ZEXPORT inflateMark(strm) -z_streamp strm; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16; - state = (struct inflate_state FAR *)strm->state; - return ((long)(state->back) << 16) + - (state->mode == COPY ? state->length : - (state->mode == MATCH ? state->was - state->length : 0)); -} diff --git a/cdf36_3-dist/src/lib/zlib/inflate.h b/cdf36_3-dist/src/lib/zlib/inflate.h deleted file mode 100644 index 95f4986..0000000 --- a/cdf36_3-dist/src/lib/zlib/inflate.h +++ /dev/null @@ -1,122 +0,0 @@ -/* inflate.h -- internal inflate state definition - * Copyright (C) 1995-2009 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* define NO_GZIP when compiling if you want to disable gzip header and - trailer decoding by inflate(). NO_GZIP would be used to avoid linking in - the crc code when it is not needed. For shared libraries, gzip decoding - should be left enabled. */ -#ifndef NO_GZIP -# define GUNZIP -#endif - -/* Possible inflate modes between inflate() calls */ -typedef enum { - HEAD, /* i: waiting for magic header */ - FLAGS, /* i: waiting for method and flags (gzip) */ - TIME, /* i: waiting for modification time (gzip) */ - OS, /* i: waiting for extra flags and operating system (gzip) */ - EXLEN, /* i: waiting for extra length (gzip) */ - EXTRA, /* i: waiting for extra bytes (gzip) */ - NAME, /* i: waiting for end of file name (gzip) */ - COMMENT, /* i: waiting for end of comment (gzip) */ - HCRC, /* i: waiting for header crc (gzip) */ - DICTID, /* i: waiting for dictionary check value */ - DICT, /* waiting for inflateSetDictionary() call */ - TYPE, /* i: waiting for type bits, including last-flag bit */ - TYPEDO, /* i: same, but skip check to exit inflate on new block */ - STORED, /* i: waiting for stored size (length and complement) */ - COPY_, /* i/o: same as COPY below, but only first time in */ - COPY, /* i/o: waiting for input or output to copy stored block */ - TABLE, /* i: waiting for dynamic block table lengths */ - LENLENS, /* i: waiting for code length code lengths */ - CODELENS, /* i: waiting for length/lit and distance code lengths */ - LEN_, /* i: same as LEN below, but only first time in */ - LEN, /* i: waiting for length/lit/eob code */ - LENEXT, /* i: waiting for length extra bits */ - DIST, /* i: waiting for distance code */ - DISTEXT, /* i: waiting for distance extra bits */ - MATCH, /* o: waiting for output space to copy string */ - LIT, /* o: waiting for output space to write literal */ - CHECK, /* i: waiting for 32-bit check value */ - LENGTH, /* i: waiting for 32-bit length (gzip) */ - DONE, /* finished check, done -- remain here until reset */ - BAD, /* got a data error -- remain here until reset */ - MEM, /* got an inflate() memory error -- remain here until reset */ - SYNC /* looking for synchronization bytes to restart inflate() */ -} inflate_mode; - -/* - State transitions between above modes - - - (most modes can go to BAD or MEM on error -- not shown for clarity) - - Process header: - HEAD -> (gzip) or (zlib) or (raw) - (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> - HCRC -> TYPE - (zlib) -> DICTID or TYPE - DICTID -> DICT -> TYPE - (raw) -> TYPEDO - Read deflate blocks: - TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK - STORED -> COPY_ -> COPY -> TYPE - TABLE -> LENLENS -> CODELENS -> LEN_ - LEN_ -> LEN - Read deflate codes in fixed or dynamic block: - LEN -> LENEXT or LIT or TYPE - LENEXT -> DIST -> DISTEXT -> MATCH -> LEN - LIT -> LEN - Process trailer: - CHECK -> LENGTH -> DONE - */ - -/* state maintained between inflate() calls. Approximately 10K bytes. */ -struct inflate_state { - inflate_mode mode; /* current inflate mode */ - int last; /* true if processing last block */ - int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ - int havedict; /* true if dictionary provided */ - int flags; /* gzip header method and flags (0 if zlib) */ - unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ - unsigned long check; /* protected copy of check value */ - unsigned long total; /* protected copy of output count */ - gz_headerp head; /* where to save gzip header information */ - /* sliding window */ - unsigned wbits; /* log base 2 of requested window size */ - unsigned wsize; /* window size or zero if not using window */ - unsigned whave; /* valid bytes in the window */ - unsigned wnext; /* window write index */ - unsigned char FAR *window; /* allocated sliding window, if needed */ - /* bit accumulator */ - unsigned long hold; /* input bit accumulator */ - unsigned bits; /* number of bits in "in" */ - /* for string and stored block copying */ - unsigned length; /* literal or length of data to copy */ - unsigned offset; /* distance back to copy string from */ - /* for table and code decoding */ - unsigned extra; /* extra bits needed */ - /* fixed and dynamic code tables */ - code const FAR *lencode; /* starting table for length/literal codes */ - code const FAR *distcode; /* starting table for distance codes */ - unsigned lenbits; /* index bits for lencode */ - unsigned distbits; /* index bits for distcode */ - /* dynamic table building */ - unsigned ncode; /* number of code length code lengths */ - unsigned nlen; /* number of length code lengths */ - unsigned ndist; /* number of distance code lengths */ - unsigned have; /* number of code lengths in lens[] */ - code FAR *next; /* next available space in codes[] */ - unsigned short lens[320]; /* temporary storage for code lengths */ - unsigned short work[288]; /* work area for code table building */ - code codes[ENOUGH]; /* space for code tables */ - int sane; /* if false, allow invalid distance too far */ - int back; /* bits back of last unprocessed length/lit */ - unsigned was; /* initial length of match */ -}; diff --git a/cdf36_3-dist/src/lib/zlib/inftrees.c b/cdf36_3-dist/src/lib/zlib/inftrees.c deleted file mode 100644 index 44d89cf..0000000 --- a/cdf36_3-dist/src/lib/zlib/inftrees.c +++ /dev/null @@ -1,306 +0,0 @@ -/* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2013 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "inftrees.h" - -#define MAXBITS 15 - -const char inflate_copyright[] = - " inflate 1.2.8 Copyright 1995-2013 Mark Adler "; -/* - If you use the zlib library in a product, an acknowledgment is welcome - in the documentation of your product. If for some reason you cannot - include such an acknowledgment, I would appreciate that you keep this - copyright string in the executable of your product. - */ - -/* - Build a set of tables to decode the provided canonical Huffman code. - The code lengths are lens[0..codes-1]. The result starts at *table, - whose indices are 0..2^bits-1. work is a writable array of at least - lens shorts, which is used as a work area. type is the type of code - to be generated, CODES, LENS, or DISTS. On return, zero is success, - -1 is an invalid code, and +1 means that ENOUGH isn't enough. table - on return points to the next available entry's address. bits is the - requested root table index bits, and on return it is the actual root - table index bits. It will differ if the request is greater than the - longest code or if it is less than the shortest code. - */ -int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) -codetype type; -unsigned short FAR *lens; -unsigned codes; -code FAR * FAR *table; -unsigned FAR *bits; -unsigned short FAR *work; -{ - unsigned len; /* a code's length in bits */ - unsigned sym; /* index of code symbols */ - unsigned min, max; /* minimum and maximum code lengths */ - unsigned root; /* number of index bits for root table */ - unsigned curr; /* number of index bits for current table */ - unsigned drop; /* code bits to drop for sub-table */ - int left; /* number of prefix codes available */ - unsigned used; /* code entries in table used */ - unsigned huff; /* Huffman code */ - unsigned incr; /* for incrementing code, index */ - unsigned fill; /* index for replicating entries */ - unsigned low; /* low bits for current root entry */ - unsigned mask; /* mask for low root bits */ - code here; /* table entry for duplication */ - code FAR *next; /* next available space in table */ - const unsigned short FAR *base; /* base value table to use */ - const unsigned short FAR *extra; /* extra bits table to use */ - int end; /* use base and extra for symbol > end */ - unsigned short count[MAXBITS+1]; /* number of codes of each length */ - unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ - static const unsigned short lbase[31] = { /* Length codes 257..285 base */ - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; - static const unsigned short lext[31] = { /* Length codes 257..285 extra */ - 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78}; - static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, - 8193, 12289, 16385, 24577, 0, 0}; - static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ - 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, - 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, - 28, 28, 29, 29, 64, 64}; - - /* - Process a set of code lengths to create a canonical Huffman code. The - code lengths are lens[0..codes-1]. Each length corresponds to the - symbols 0..codes-1. The Huffman code is generated by first sorting the - symbols by length from short to long, and retaining the symbol order - for codes with equal lengths. Then the code starts with all zero bits - for the first code of the shortest length, and the codes are integer - increments for the same length, and zeros are appended as the length - increases. For the deflate format, these bits are stored backwards - from their more natural integer increment ordering, and so when the - decoding tables are built in the large loop below, the integer codes - are incremented backwards. - - This routine assumes, but does not check, that all of the entries in - lens[] are in the range 0..MAXBITS. The caller must assure this. - 1..MAXBITS is interpreted as that code length. zero means that that - symbol does not occur in this code. - - The codes are sorted by computing a count of codes for each length, - creating from that a table of starting indices for each length in the - sorted table, and then entering the symbols in order in the sorted - table. The sorted table is work[], with that space being provided by - the caller. - - The length counts are used for other purposes as well, i.e. finding - the minimum and maximum length codes, determining if there are any - codes at all, checking for a valid set of lengths, and looking ahead - at length counts to determine sub-table sizes when building the - decoding tables. - */ - - /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ - for (len = 0; len <= MAXBITS; len++) - count[len] = 0; - for (sym = 0; sym < codes; sym++) - count[lens[sym]]++; - - /* bound code lengths, force root to be within code lengths */ - root = *bits; - for (max = MAXBITS; max >= 1; max--) - if (count[max] != 0) break; - if (root > max) root = max; - if (max == 0) { /* no symbols to code at all */ - here.op = (unsigned char)64; /* invalid code marker */ - here.bits = (unsigned char)1; - here.val = (unsigned short)0; - *(*table)++ = here; /* make a table to force an error */ - *(*table)++ = here; - *bits = 1; - return 0; /* no symbols, but wait for decoding to report error */ - } - for (min = 1; min < max; min++) - if (count[min] != 0) break; - if (root < min) root = min; - - /* check for an over-subscribed or incomplete set of lengths */ - left = 1; - for (len = 1; len <= MAXBITS; len++) { - left <<= 1; - left -= count[len]; - if (left < 0) return -1; /* over-subscribed */ - } - if (left > 0 && (type == CODES || max != 1)) - return -1; /* incomplete set */ - - /* generate offsets into symbol table for each length for sorting */ - offs[1] = 0; - for (len = 1; len < MAXBITS; len++) - offs[len + 1] = offs[len] + count[len]; - - /* sort symbols by length, by symbol order within each length */ - for (sym = 0; sym < codes; sym++) - if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; - - /* - Create and fill in decoding tables. In this loop, the table being - filled is at next and has curr index bits. The code being used is huff - with length len. That code is converted to an index by dropping drop - bits off of the bottom. For codes where len is less than drop + curr, - those top drop + curr - len bits are incremented through all values to - fill the table with replicated entries. - - root is the number of index bits for the root table. When len exceeds - root, sub-tables are created pointed to by the root entry with an index - of the low root bits of huff. This is saved in low to check for when a - new sub-table should be started. drop is zero when the root table is - being filled, and drop is root when sub-tables are being filled. - - When a new sub-table is needed, it is necessary to look ahead in the - code lengths to determine what size sub-table is needed. The length - counts are used for this, and so count[] is decremented as codes are - entered in the tables. - - used keeps track of how many table entries have been allocated from the - provided *table space. It is checked for LENS and DIST tables against - the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in - the initial root table size constants. See the comments in inftrees.h - for more information. - - sym increments through all symbols, and the loop terminates when - all codes of length max, i.e. all codes, have been processed. This - routine permits incomplete codes, so another loop after this one fills - in the rest of the decoding tables with invalid code markers. - */ - - /* set up for code type */ - switch (type) { - case CODES: - base = extra = work; /* dummy value--not used */ - end = 19; - break; - case LENS: - base = lbase; - base -= 257; - extra = lext; - extra -= 257; - end = 256; - break; - default: /* DISTS */ - base = dbase; - extra = dext; - end = -1; - } - - /* initialize state for loop */ - huff = 0; /* starting code */ - sym = 0; /* starting code symbol */ - len = min; /* starting code length */ - next = *table; /* current table to fill in */ - curr = root; /* current table index bits */ - drop = 0; /* current bits to drop from code for index */ - low = (unsigned)(-1); /* trigger new sub-table when len > root */ - used = 1U << root; /* use root table entries */ - mask = used - 1; /* mask for comparing low */ - - /* check available table space */ - if ((type == LENS && used > ENOUGH_LENS) || - (type == DISTS && used > ENOUGH_DISTS)) - return 1; - - /* process all codes and make table entries */ - for (;;) { - /* create table entry */ - here.bits = (unsigned char)(len - drop); - if ((int)(work[sym]) < end) { - here.op = (unsigned char)0; - here.val = work[sym]; - } - else if ((int)(work[sym]) > end) { - here.op = (unsigned char)(extra[work[sym]]); - here.val = base[work[sym]]; - } - else { - here.op = (unsigned char)(32 + 64); /* end of block */ - here.val = 0; - } - - /* replicate for those indices with low len bits equal to huff */ - incr = 1U << (len - drop); - fill = 1U << curr; - min = fill; /* save offset to next table */ - do { - fill -= incr; - next[(huff >> drop) + fill] = here; - } while (fill != 0); - - /* backwards increment the len-bit code huff */ - incr = 1U << (len - 1); - while (huff & incr) - incr >>= 1; - if (incr != 0) { - huff &= incr - 1; - huff += incr; - } - else - huff = 0; - - /* go to next symbol, update count, len */ - sym++; - if (--(count[len]) == 0) { - if (len == max) break; - len = lens[work[sym]]; - } - - /* create new sub-table if needed */ - if (len > root && (huff & mask) != low) { - /* if first time, transition to sub-tables */ - if (drop == 0) - drop = root; - - /* increment past last table */ - next += min; /* here min is 1 << curr */ - - /* determine length of next table */ - curr = len - drop; - left = (int)(1 << curr); - while (curr + drop < max) { - left -= count[curr + drop]; - if (left <= 0) break; - curr++; - left <<= 1; - } - - /* check for enough space */ - used += 1U << curr; - if ((type == LENS && used > ENOUGH_LENS) || - (type == DISTS && used > ENOUGH_DISTS)) - return 1; - - /* point entry in root table to sub-table */ - low = huff & mask; - (*table)[low].op = (unsigned char)curr; - (*table)[low].bits = (unsigned char)root; - (*table)[low].val = (unsigned short)(next - *table); - } - } - - /* fill in remaining table entry if code is incomplete (guaranteed to have - at most one remaining entry, since if the code is incomplete, the - maximum code length that was allowed to get this far is one bit) */ - if (huff != 0) { - here.op = (unsigned char)64; /* invalid code marker */ - here.bits = (unsigned char)(len - drop); - here.val = (unsigned short)0; - next[huff] = here; - } - - /* set return parameters */ - *table += used; - *bits = root; - return 0; -} diff --git a/cdf36_3-dist/src/lib/zlib/inftrees.h b/cdf36_3-dist/src/lib/zlib/inftrees.h deleted file mode 100644 index baa53a0..0000000 --- a/cdf36_3-dist/src/lib/zlib/inftrees.h +++ /dev/null @@ -1,62 +0,0 @@ -/* inftrees.h -- header to use inftrees.c - * Copyright (C) 1995-2005, 2010 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* Structure for decoding tables. Each entry provides either the - information needed to do the operation requested by the code that - indexed that table entry, or it provides a pointer to another - table that indexes more bits of the code. op indicates whether - the entry is a pointer to another table, a literal, a length or - distance, an end-of-block, or an invalid code. For a table - pointer, the low four bits of op is the number of index bits of - that table. For a length or distance, the low four bits of op - is the number of extra bits to get after the code. bits is - the number of bits in this code or part of the code to drop off - of the bit buffer. val is the actual byte to output in the case - of a literal, the base length or distance, or the offset from - the current table to the next table. Each entry is four bytes. */ -typedef struct { - unsigned char op; /* operation, extra bits, table bits */ - unsigned char bits; /* bits in this part of the code */ - unsigned short val; /* offset in table or code value */ -} code; - -/* op values as set by inflate_table(): - 00000000 - literal - 0000tttt - table link, tttt != 0 is the number of table index bits - 0001eeee - length or distance, eeee is the number of extra bits - 01100000 - end of block - 01000000 - invalid code - */ - -/* Maximum size of the dynamic table. The maximum number of code structures is - 1444, which is the sum of 852 for literal/length codes and 592 for distance - codes. These values were found by exhaustive searches using the program - examples/enough.c found in the zlib distribtution. The arguments to that - program are the number of symbols, the initial root table size, and the - maximum bit length of a code. "enough 286 9 15" for literal/length codes - returns returns 852, and "enough 30 6 15" for distance codes returns 592. - The initial root table size (9 or 6) is found in the fifth argument of the - inflate_table() calls in inflate.c and infback.c. If the root table size is - changed, then these maximum sizes would be need to be recalculated and - updated. */ -#define ENOUGH_LENS 852 -#define ENOUGH_DISTS 592 -#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) - -/* Type of code to build for inflate_table() */ -typedef enum { - CODES, - LENS, - DISTS -} codetype; - -int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, - unsigned codes, code FAR * FAR *table, - unsigned FAR *bits, unsigned short FAR *work)); diff --git a/cdf36_3-dist/src/lib/zlib/trees.c b/cdf36_3-dist/src/lib/zlib/trees.c deleted file mode 100644 index 67da8b5..0000000 --- a/cdf36_3-dist/src/lib/zlib/trees.c +++ /dev/null @@ -1,1226 +0,0 @@ -/* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2012 Jean-loup Gailly - * detect_data_type() function provided freely by Cosmin Truta, 2006 - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * ALGORITHM - * - * The "deflation" process uses several Huffman trees. The more - * common source values are represented by shorter bit sequences. - * - * Each code tree is stored in a compressed form which is itself - * a Huffman encoding of the lengths of all the code strings (in - * ascending order by source values). The actual code strings are - * reconstructed from the lengths in the inflate process, as described - * in the deflate specification. - * - * REFERENCES - * - * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". - * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc - * - * Storer, James A. - * Data Compression: Methods and Theory, pp. 49-50. - * Computer Science Press, 1988. ISBN 0-7167-8156-5. - * - * Sedgewick, R. - * Algorithms, p290. - * Addison-Wesley, 1983. ISBN 0-201-06672-6. - */ - -/* @(#) $Id: trees.c,v 1.1.1.1 2016/10/12 19:21:25 liu Exp $ */ - -/* #define GEN_TREES_H */ - -#include "deflate.h" - -#ifdef DEBUG -# include -#endif - -/* =========================================================================== - * Constants - */ - -#define MAX_BL_BITS 7 -/* Bit length codes must not exceed MAX_BL_BITS bits */ - -#define END_BLOCK 256 -/* end of block literal code */ - -#define REP_3_6 16 -/* repeat previous bit length 3-6 times (2 bits of repeat count) */ - -#define REPZ_3_10 17 -/* repeat a zero length 3-10 times (3 bits of repeat count) */ - -#define REPZ_11_138 18 -/* repeat a zero length 11-138 times (7 bits of repeat count) */ - -local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ - = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; - -local const int extra_dbits[D_CODES] /* extra bits for each distance code */ - = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; - -local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ - = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; - -local const uch bl_order[BL_CODES] - = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; -/* The lengths of the bit length codes are sent in order of decreasing - * probability, to avoid transmitting the lengths for unused bit length codes. - */ - -/* =========================================================================== - * Local data. These are initialized only once. - */ - -#define DIST_CODE_LEN 512 /* see definition of array dist_code below */ - -#if defined(GEN_TREES_H) || !defined(STDC) -/* non ANSI compilers may not accept trees.h */ - -local ct_data static_ltree[L_CODES+2]; -/* The static literal tree. Since the bit lengths are imposed, there is no - * need for the L_CODES extra codes used during heap construction. However - * The codes 286 and 287 are needed to build a canonical tree (see _tr_init - * below). - */ - -local ct_data static_dtree[D_CODES]; -/* The static distance tree. (Actually a trivial tree since all codes use - * 5 bits.) - */ - -uch _dist_code[DIST_CODE_LEN]; -/* Distance codes. The first 256 values correspond to the distances - * 3 .. 258, the last 256 values correspond to the top 8 bits of - * the 15 bit distances. - */ - -uch _length_code[MAX_MATCH-MIN_MATCH+1]; -/* length code for each normalized match length (0 == MIN_MATCH) */ - -local int base_length[LENGTH_CODES]; -/* First normalized length for each code (0 = MIN_MATCH) */ - -local int base_dist[D_CODES]; -/* First normalized distance for each code (0 = distance of 1) */ - -#else -# include "trees.h" -#endif /* GEN_TREES_H */ - -struct static_tree_desc_s { - const ct_data *static_tree; /* static tree or NULL */ - const intf *extra_bits; /* extra bits for each code or NULL */ - int extra_base; /* base index for extra_bits */ - int elems; /* max number of elements in the tree */ - int max_length; /* max bit length for the codes */ -}; - -local static_tree_desc static_l_desc = -{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; - -local static_tree_desc static_d_desc = -{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; - -local static_tree_desc static_bl_desc = -{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; - -/* =========================================================================== - * Local (static) routines in this file. - */ - -local void tr_static_init OF((void)); -local void init_block OF((deflate_state *s)); -local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); -local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); -local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); -local void build_tree OF((deflate_state *s, tree_desc *desc)); -local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local int build_bl_tree OF((deflate_state *s)); -local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, - int blcodes)); -local void compress_block OF((deflate_state *s, const ct_data *ltree, - const ct_data *dtree)); -local int detect_data_type OF((deflate_state *s)); -local unsigned bi_reverse OF((unsigned value, int length)); -local void bi_windup OF((deflate_state *s)); -local void bi_flush OF((deflate_state *s)); -local void copy_block OF((deflate_state *s, charf *buf, unsigned len, - int header)); - -#ifdef GEN_TREES_H -local void gen_trees_header OF((void)); -#endif - -#ifndef DEBUG -# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) - /* Send a code of the given tree. c and tree must not have side effects */ - -#else /* DEBUG */ -# define send_code(s, c, tree) \ - { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ - send_bits(s, tree[c].Code, tree[c].Len); } -#endif - -/* =========================================================================== - * Output a short LSB first on the stream. - * IN assertion: there is enough room in pendingBuf. - */ -#define put_short(s, w) { \ - put_byte(s, (uch)((w) & 0xff)); \ - put_byte(s, (uch)((ush)(w) >> 8)); \ -} - -/* =========================================================================== - * Send a value on a given number of bits. - * IN assertion: length <= 16 and value fits in length bits. - */ -#ifdef DEBUG -local void send_bits OF((deflate_state *s, int value, int length)); - -local void send_bits(s, value, length) - deflate_state *s; - int value; /* value to send */ - int length; /* number of bits */ -{ - Tracevv((stderr," l %2d v %4x ", length, value)); - Assert(length > 0 && length <= 15, "invalid length"); - s->bits_sent += (ulg)length; - - /* If not enough room in bi_buf, use (valid) bits from bi_buf and - * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) - * unused bits in value. - */ - if (s->bi_valid > (int)Buf_size - length) { - s->bi_buf |= (ush)value << s->bi_valid; - put_short(s, s->bi_buf); - s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); - s->bi_valid += length - Buf_size; - } else { - s->bi_buf |= (ush)value << s->bi_valid; - s->bi_valid += length; - } -} -#else /* !DEBUG */ - -#define send_bits(s, value, length) \ -{ int len = length;\ - if (s->bi_valid > (int)Buf_size - len) {\ - int val = value;\ - s->bi_buf |= (ush)val << s->bi_valid;\ - put_short(s, s->bi_buf);\ - s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ - s->bi_valid += len - Buf_size;\ - } else {\ - s->bi_buf |= (ush)(value) << s->bi_valid;\ - s->bi_valid += len;\ - }\ -} -#endif /* DEBUG */ - - -/* the arguments must not have side effects */ - -/* =========================================================================== - * Initialize the various 'constant' tables. - */ -local void tr_static_init() -{ -#if defined(GEN_TREES_H) || !defined(STDC) - static int static_init_done = 0; - int n; /* iterates over tree elements */ - int bits; /* bit counter */ - int length; /* length value */ - int code; /* code value */ - int dist; /* distance index */ - ush bl_count[MAX_BITS+1]; - /* number of codes at each bit length for an optimal tree */ - - if (static_init_done) return; - - /* For some embedded targets, global variables are not initialized: */ -#ifdef NO_INIT_GLOBAL_POINTERS - static_l_desc.static_tree = static_ltree; - static_l_desc.extra_bits = extra_lbits; - static_d_desc.static_tree = static_dtree; - static_d_desc.extra_bits = extra_dbits; - static_bl_desc.extra_bits = extra_blbits; -#endif - - /* Initialize the mapping length (0..255) -> length code (0..28) */ - length = 0; - for (code = 0; code < LENGTH_CODES-1; code++) { - base_length[code] = length; - for (n = 0; n < (1< dist code (0..29) */ - dist = 0; - for (code = 0 ; code < 16; code++) { - base_dist[code] = dist; - for (n = 0; n < (1<>= 7; /* from now on, all distances are divided by 128 */ - for ( ; code < D_CODES; code++) { - base_dist[code] = dist << 7; - for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { - _dist_code[256 + dist++] = (uch)code; - } - } - Assert (dist == 256, "tr_static_init: 256+dist != 512"); - - /* Construct the codes of the static literal tree */ - for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; - n = 0; - while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++; - while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++; - while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++; - while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++; - /* Codes 286 and 287 do not exist, but we must include them in the - * tree construction to get a canonical Huffman tree (longest code - * all ones) - */ - gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count); - - /* The static distance tree is trivial: */ - for (n = 0; n < D_CODES; n++) { - static_dtree[n].Len = 5; - static_dtree[n].Code = bi_reverse((unsigned)n, 5); - } - static_init_done = 1; - -# ifdef GEN_TREES_H - gen_trees_header(); -# endif -#endif /* defined(GEN_TREES_H) || !defined(STDC) */ -} - -/* =========================================================================== - * Genererate the file trees.h describing the static trees. - */ -#ifdef GEN_TREES_H -# ifndef DEBUG -# include -# endif - -# define SEPARATOR(i, last, width) \ - ((i) == (last)? "\n};\n\n" : \ - ((i) % (width) == (width)-1 ? ",\n" : ", ")) - -void gen_trees_header() -{ - FILE *header = fopen("trees.h", "w"); - int i; - - Assert (header != NULL, "Can't open trees.h"); - fprintf(header, - "/* header created automatically with -DGEN_TREES_H */\n\n"); - - fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); - for (i = 0; i < L_CODES+2; i++) { - fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, - static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); - } - - fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); - for (i = 0; i < D_CODES; i++) { - fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, - static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); - } - - fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n"); - for (i = 0; i < DIST_CODE_LEN; i++) { - fprintf(header, "%2u%s", _dist_code[i], - SEPARATOR(i, DIST_CODE_LEN-1, 20)); - } - - fprintf(header, - "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); - for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { - fprintf(header, "%2u%s", _length_code[i], - SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); - } - - fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); - for (i = 0; i < LENGTH_CODES; i++) { - fprintf(header, "%1u%s", base_length[i], - SEPARATOR(i, LENGTH_CODES-1, 20)); - } - - fprintf(header, "local const int base_dist[D_CODES] = {\n"); - for (i = 0; i < D_CODES; i++) { - fprintf(header, "%5u%s", base_dist[i], - SEPARATOR(i, D_CODES-1, 10)); - } - - fclose(header); -} -#endif /* GEN_TREES_H */ - -/* =========================================================================== - * Initialize the tree data structures for a new zlib stream. - */ -void ZLIB_INTERNAL _tr_init(s) - deflate_state *s; -{ - tr_static_init(); - - s->l_desc.dyn_tree = s->dyn_ltree; - s->l_desc.stat_desc = &static_l_desc; - - s->d_desc.dyn_tree = s->dyn_dtree; - s->d_desc.stat_desc = &static_d_desc; - - s->bl_desc.dyn_tree = s->bl_tree; - s->bl_desc.stat_desc = &static_bl_desc; - - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef DEBUG - s->compressed_len = 0L; - s->bits_sent = 0L; -#endif - - /* Initialize the first block of the first file: */ - init_block(s); -} - -/* =========================================================================== - * Initialize a new block. - */ -local void init_block(s) - deflate_state *s; -{ - int n; /* iterates over tree elements */ - - /* Initialize the trees. */ - for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; - for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; - for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; - - s->dyn_ltree[END_BLOCK].Freq = 1; - s->opt_len = s->static_len = 0L; - s->last_lit = s->matches = 0; -} - -#define SMALLEST 1 -/* Index within the heap array of least frequent node in the Huffman tree */ - - -/* =========================================================================== - * Remove the smallest element from the heap and recreate the heap with - * one less element. Updates heap and heap_len. - */ -#define pqremove(s, tree, top) \ -{\ - top = s->heap[SMALLEST]; \ - s->heap[SMALLEST] = s->heap[s->heap_len--]; \ - pqdownheap(s, tree, SMALLEST); \ -} - -/* =========================================================================== - * Compares to subtrees, using the tree depth as tie breaker when - * the subtrees have equal frequency. This minimizes the worst case length. - */ -#define smaller(tree, n, m, depth) \ - (tree[n].Freq < tree[m].Freq || \ - (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) - -/* =========================================================================== - * Restore the heap property by moving down the tree starting at node k, - * exchanging a node with the smallest of its two sons if necessary, stopping - * when the heap property is re-established (each father smaller than its - * two sons). - */ -local void pqdownheap(s, tree, k) - deflate_state *s; - ct_data *tree; /* the tree to restore */ - int k; /* node to move down */ -{ - int v = s->heap[k]; - int j = k << 1; /* left son of k */ - while (j <= s->heap_len) { - /* Set j to the smallest of the two sons: */ - if (j < s->heap_len && - smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { - j++; - } - /* Exit if v is smaller than both sons */ - if (smaller(tree, v, s->heap[j], s->depth)) break; - - /* Exchange v with the smallest son */ - s->heap[k] = s->heap[j]; k = j; - - /* And continue down the tree, setting j to the left son of k */ - j <<= 1; - } - s->heap[k] = v; -} - -/* =========================================================================== - * Compute the optimal bit lengths for a tree and update the total bit length - * for the current block. - * IN assertion: the fields freq and dad are set, heap[heap_max] and - * above are the tree nodes sorted by increasing frequency. - * OUT assertions: the field len is set to the optimal bit length, the - * array bl_count contains the frequencies for each bit length. - * The length opt_len is updated; static_len is also updated if stree is - * not null. - */ -local void gen_bitlen(s, desc) - deflate_state *s; - tree_desc *desc; /* the tree descriptor */ -{ - ct_data *tree = desc->dyn_tree; - int max_code = desc->max_code; - const ct_data *stree = desc->stat_desc->static_tree; - const intf *extra = desc->stat_desc->extra_bits; - int base = desc->stat_desc->extra_base; - int max_length = desc->stat_desc->max_length; - int h; /* heap index */ - int n, m; /* iterate over the tree elements */ - int bits; /* bit length */ - int xbits; /* extra bits */ - ush f; /* frequency */ - int overflow = 0; /* number of elements with bit length too large */ - - for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; - - /* In a first pass, compute the optimal bit lengths (which may - * overflow in the case of the bit length tree). - */ - tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ - - for (h = s->heap_max+1; h < HEAP_SIZE; h++) { - n = s->heap[h]; - bits = tree[tree[n].Dad].Len + 1; - if (bits > max_length) bits = max_length, overflow++; - tree[n].Len = (ush)bits; - /* We overwrite tree[n].Dad which is no longer needed */ - - if (n > max_code) continue; /* not a leaf node */ - - s->bl_count[bits]++; - xbits = 0; - if (n >= base) xbits = extra[n-base]; - f = tree[n].Freq; - s->opt_len += (ulg)f * (bits + xbits); - if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); - } - if (overflow == 0) return; - - Trace((stderr,"\nbit length overflow\n")); - /* This happens for example on obj2 and pic of the Calgary corpus */ - - /* Find the first bit length which could increase: */ - do { - bits = max_length-1; - while (s->bl_count[bits] == 0) bits--; - s->bl_count[bits]--; /* move one leaf down the tree */ - s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ - s->bl_count[max_length]--; - /* The brother of the overflow item also moves one step up, - * but this does not affect bl_count[max_length] - */ - overflow -= 2; - } while (overflow > 0); - - /* Now recompute all bit lengths, scanning in increasing frequency. - * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all - * lengths instead of fixing only the wrong ones. This idea is taken - * from 'ar' written by Haruhiko Okumura.) - */ - for (bits = max_length; bits != 0; bits--) { - n = s->bl_count[bits]; - while (n != 0) { - m = s->heap[--h]; - if (m > max_code) continue; - if ((unsigned) tree[m].Len != (unsigned) bits) { - Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); - s->opt_len += ((long)bits - (long)tree[m].Len) - *(long)tree[m].Freq; - tree[m].Len = (ush)bits; - } - n--; - } - } -} - -/* =========================================================================== - * Generate the codes for a given tree and bit counts (which need not be - * optimal). - * IN assertion: the array bl_count contains the bit length statistics for - * the given tree and the field len is set for all tree elements. - * OUT assertion: the field code is set for all tree elements of non - * zero code length. - */ -local void gen_codes (tree, max_code, bl_count) - ct_data *tree; /* the tree to decorate */ - int max_code; /* largest code with non zero frequency */ - ushf *bl_count; /* number of codes at each bit length */ -{ - ush next_code[MAX_BITS+1]; /* next code value for each bit length */ - ush code = 0; /* running code value */ - int bits; /* bit index */ - int n; /* code index */ - - /* The distribution counts are first used to generate the code values - * without bit reversal. - */ - for (bits = 1; bits <= MAX_BITS; bits++) { - next_code[bits] = code = (code + bl_count[bits-1]) << 1; - } - /* Check that the bit counts in bl_count are consistent. The last code - * must be all ones. - */ - Assert (code + bl_count[MAX_BITS]-1 == (1<dyn_tree; - const ct_data *stree = desc->stat_desc->static_tree; - int elems = desc->stat_desc->elems; - int n, m; /* iterate over heap elements */ - int max_code = -1; /* largest code with non zero frequency */ - int node; /* new node being created */ - - /* Construct the initial heap, with least frequent element in - * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. - * heap[0] is not used. - */ - s->heap_len = 0, s->heap_max = HEAP_SIZE; - - for (n = 0; n < elems; n++) { - if (tree[n].Freq != 0) { - s->heap[++(s->heap_len)] = max_code = n; - s->depth[n] = 0; - } else { - tree[n].Len = 0; - } - } - - /* The pkzip format requires that at least one distance code exists, - * and that at least one bit should be sent even if there is only one - * possible code. So to avoid special checks later on we force at least - * two codes of non zero frequency. - */ - while (s->heap_len < 2) { - node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); - tree[node].Freq = 1; - s->depth[node] = 0; - s->opt_len--; if (stree) s->static_len -= stree[node].Len; - /* node is 0 or 1 so it does not have extra bits */ - } - desc->max_code = max_code; - - /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, - * establish sub-heaps of increasing lengths: - */ - for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); - - /* Construct the Huffman tree by repeatedly combining the least two - * frequent nodes. - */ - node = elems; /* next internal node of the tree */ - do { - pqremove(s, tree, n); /* n = node of least frequency */ - m = s->heap[SMALLEST]; /* m = node of next least frequency */ - - s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ - s->heap[--(s->heap_max)] = m; - - /* Create a new node father of n and m */ - tree[node].Freq = tree[n].Freq + tree[m].Freq; - s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ? - s->depth[n] : s->depth[m]) + 1); - tree[n].Dad = tree[m].Dad = (ush)node; -#ifdef DUMP_BL_TREE - if (tree == s->bl_tree) { - fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", - node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); - } -#endif - /* and insert the new node in the heap */ - s->heap[SMALLEST] = node++; - pqdownheap(s, tree, SMALLEST); - - } while (s->heap_len >= 2); - - s->heap[--(s->heap_max)] = s->heap[SMALLEST]; - - /* At this point, the fields freq and dad are set. We can now - * generate the bit lengths. - */ - gen_bitlen(s, (tree_desc *)desc); - - /* The field len is now set, we can generate the bit codes */ - gen_codes ((ct_data *)tree, max_code, s->bl_count); -} - -/* =========================================================================== - * Scan a literal or distance tree to determine the frequencies of the codes - * in the bit length tree. - */ -local void scan_tree (s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ -{ - int n; /* iterates over all tree elements */ - int prevlen = -1; /* last emitted length */ - int curlen; /* length of current code */ - int nextlen = tree[0].Len; /* length of next code */ - int count = 0; /* repeat count of the current code */ - int max_count = 7; /* max repeat count */ - int min_count = 4; /* min repeat count */ - - if (nextlen == 0) max_count = 138, min_count = 3; - tree[max_code+1].Len = (ush)0xffff; /* guard */ - - for (n = 0; n <= max_code; n++) { - curlen = nextlen; nextlen = tree[n+1].Len; - if (++count < max_count && curlen == nextlen) { - continue; - } else if (count < min_count) { - s->bl_tree[curlen].Freq += count; - } else if (curlen != 0) { - if (curlen != prevlen) s->bl_tree[curlen].Freq++; - s->bl_tree[REP_3_6].Freq++; - } else if (count <= 10) { - s->bl_tree[REPZ_3_10].Freq++; - } else { - s->bl_tree[REPZ_11_138].Freq++; - } - count = 0; prevlen = curlen; - if (nextlen == 0) { - max_count = 138, min_count = 3; - } else if (curlen == nextlen) { - max_count = 6, min_count = 3; - } else { - max_count = 7, min_count = 4; - } - } -} - -/* =========================================================================== - * Send a literal or distance tree in compressed form, using the codes in - * bl_tree. - */ -local void send_tree (s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ -{ - int n; /* iterates over all tree elements */ - int prevlen = -1; /* last emitted length */ - int curlen; /* length of current code */ - int nextlen = tree[0].Len; /* length of next code */ - int count = 0; /* repeat count of the current code */ - int max_count = 7; /* max repeat count */ - int min_count = 4; /* min repeat count */ - - /* tree[max_code+1].Len = -1; */ /* guard already set */ - if (nextlen == 0) max_count = 138, min_count = 3; - - for (n = 0; n <= max_code; n++) { - curlen = nextlen; nextlen = tree[n+1].Len; - if (++count < max_count && curlen == nextlen) { - continue; - } else if (count < min_count) { - do { send_code(s, curlen, s->bl_tree); } while (--count != 0); - - } else if (curlen != 0) { - if (curlen != prevlen) { - send_code(s, curlen, s->bl_tree); count--; - } - Assert(count >= 3 && count <= 6, " 3_6?"); - send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); - - } else if (count <= 10) { - send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); - - } else { - send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); - } - count = 0; prevlen = curlen; - if (nextlen == 0) { - max_count = 138, min_count = 3; - } else if (curlen == nextlen) { - max_count = 6, min_count = 3; - } else { - max_count = 7, min_count = 4; - } - } -} - -/* =========================================================================== - * Construct the Huffman tree for the bit lengths and return the index in - * bl_order of the last bit length code to send. - */ -local int build_bl_tree(s) - deflate_state *s; -{ - int max_blindex; /* index of last bit length code of non zero freq */ - - /* Determine the bit length frequencies for literal and distance trees */ - scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); - scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); - - /* Build the bit length tree: */ - build_tree(s, (tree_desc *)(&(s->bl_desc))); - /* opt_len now includes the length of the tree representations, except - * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. - */ - - /* Determine the number of bit length codes to send. The pkzip format - * requires that at least 4 bit length codes be sent. (appnote.txt says - * 3 but the actual value used is 4.) - */ - for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { - if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; - } - /* Update opt_len to include the bit length tree and counts */ - s->opt_len += 3*(max_blindex+1) + 5+5+4; - Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", - s->opt_len, s->static_len)); - - return max_blindex; -} - -/* =========================================================================== - * Send the header for a block using dynamic Huffman trees: the counts, the - * lengths of the bit length codes, the literal tree and the distance tree. - * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. - */ -local void send_all_trees(s, lcodes, dcodes, blcodes) - deflate_state *s; - int lcodes, dcodes, blcodes; /* number of codes for each tree */ -{ - int rank; /* index in bl_order */ - - Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); - Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, - "too many codes"); - Tracev((stderr, "\nbl counts: ")); - send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ - send_bits(s, dcodes-1, 5); - send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ - for (rank = 0; rank < blcodes; rank++) { - Tracev((stderr, "\nbl code %2d ", bl_order[rank])); - send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); - } - Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); - - send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ - Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); - - send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ - Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); -} - -/* =========================================================================== - * Send a stored block - */ -void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) - deflate_state *s; - charf *buf; /* input block */ - ulg stored_len; /* length of input block */ - int last; /* one if this is the last block for a file */ -{ - send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ -#ifdef DEBUG - s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; - s->compressed_len += (stored_len + 4) << 3; -#endif - copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ -} - -/* =========================================================================== - * Flush the bits in the bit buffer to pending output (leaves at most 7 bits) - */ -void ZLIB_INTERNAL _tr_flush_bits(s) - deflate_state *s; -{ - bi_flush(s); -} - -/* =========================================================================== - * Send one empty static block to give enough lookahead for inflate. - * This takes 10 bits, of which 7 may remain in the bit buffer. - */ -void ZLIB_INTERNAL _tr_align(s) - deflate_state *s; -{ - send_bits(s, STATIC_TREES<<1, 3); - send_code(s, END_BLOCK, static_ltree); -#ifdef DEBUG - s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ -#endif - bi_flush(s); -} - -/* =========================================================================== - * Determine the best encoding for the current block: dynamic trees, static - * trees or store, and output the encoded block to the zip file. - */ -void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) - deflate_state *s; - charf *buf; /* input block, or NULL if too old */ - ulg stored_len; /* length of input block */ - int last; /* one if this is the last block for a file */ -{ - ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ - int max_blindex = 0; /* index of last bit length code of non zero freq */ - - /* Build the Huffman trees unless a stored block is forced */ - if (s->level > 0) { - - /* Check if the file is binary or text */ - if (s->strm->data_type == Z_UNKNOWN) - s->strm->data_type = detect_data_type(s); - - /* Construct the literal and distance trees */ - build_tree(s, (tree_desc *)(&(s->l_desc))); - Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, - s->static_len)); - - build_tree(s, (tree_desc *)(&(s->d_desc))); - Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, - s->static_len)); - /* At this point, opt_len and static_len are the total bit lengths of - * the compressed block data, excluding the tree representations. - */ - - /* Build the bit length tree for the above two trees, and get the index - * in bl_order of the last bit length code to send. - */ - max_blindex = build_bl_tree(s); - - /* Determine the best encoding. Compute the block lengths in bytes. */ - opt_lenb = (s->opt_len+3+7)>>3; - static_lenb = (s->static_len+3+7)>>3; - - Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", - opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, - s->last_lit)); - - if (static_lenb <= opt_lenb) opt_lenb = static_lenb; - - } else { - Assert(buf != (char*)0, "lost buf"); - opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ - } - -#ifdef FORCE_STORED - if (buf != (char*)0) { /* force stored block */ -#else - if (stored_len+4 <= opt_lenb && buf != (char*)0) { - /* 4: two words for the lengths */ -#endif - /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. - * Otherwise we can't have processed more than WSIZE input bytes since - * the last block flush, because compression would have been - * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to - * transform a block into a stored block. - */ - _tr_stored_block(s, buf, stored_len, last); - -#ifdef FORCE_STATIC - } else if (static_lenb >= 0) { /* force static trees */ -#else - } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { -#endif - send_bits(s, (STATIC_TREES<<1)+last, 3); - compress_block(s, (const ct_data *)static_ltree, - (const ct_data *)static_dtree); -#ifdef DEBUG - s->compressed_len += 3 + s->static_len; -#endif - } else { - send_bits(s, (DYN_TREES<<1)+last, 3); - send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, - max_blindex+1); - compress_block(s, (const ct_data *)s->dyn_ltree, - (const ct_data *)s->dyn_dtree); -#ifdef DEBUG - s->compressed_len += 3 + s->opt_len; -#endif - } - Assert (s->compressed_len == s->bits_sent, "bad compressed size"); - /* The above check is made mod 2^32, for files larger than 512 MB - * and uLong implemented on 32 bits. - */ - init_block(s); - - if (last) { - bi_windup(s); -#ifdef DEBUG - s->compressed_len += 7; /* align on byte boundary */ -#endif - } - Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, - s->compressed_len-7*last)); -} - -/* =========================================================================== - * Save the match info and tally the frequency counts. Return true if - * the current block must be flushed. - */ -int ZLIB_INTERNAL _tr_tally (s, dist, lc) - deflate_state *s; - unsigned dist; /* distance of matched string */ - unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ -{ - s->d_buf[s->last_lit] = (ush)dist; - s->l_buf[s->last_lit++] = (uch)lc; - if (dist == 0) { - /* lc is the unmatched char */ - s->dyn_ltree[lc].Freq++; - } else { - s->matches++; - /* Here, lc is the match length - MIN_MATCH */ - dist--; /* dist = match distance - 1 */ - Assert((ush)dist < (ush)MAX_DIST(s) && - (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && - (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); - - s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; - s->dyn_dtree[d_code(dist)].Freq++; - } - -#ifdef TRUNCATE_BLOCK - /* Try to guess if it is profitable to stop the current block here */ - if ((s->last_lit & 0x1fff) == 0 && s->level > 2) { - /* Compute an upper bound for the compressed length */ - ulg out_length = (ulg)s->last_lit*8L; - ulg in_length = (ulg)((long)s->strstart - s->block_start); - int dcode; - for (dcode = 0; dcode < D_CODES; dcode++) { - out_length += (ulg)s->dyn_dtree[dcode].Freq * - (5L+extra_dbits[dcode]); - } - out_length >>= 3; - Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", - s->last_lit, in_length, out_length, - 100L - out_length*100L/in_length)); - if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1; - } -#endif - return (s->last_lit == s->lit_bufsize-1); - /* We avoid equality with lit_bufsize because of wraparound at 64K - * on 16 bit machines and because stored blocks are restricted to - * 64K-1 bytes. - */ -} - -/* =========================================================================== - * Send the block data compressed using the given Huffman trees - */ -local void compress_block(s, ltree, dtree) - deflate_state *s; - const ct_data *ltree; /* literal tree */ - const ct_data *dtree; /* distance tree */ -{ - unsigned dist; /* distance of matched string */ - int lc; /* match length or unmatched char (if dist == 0) */ - unsigned lx = 0; /* running index in l_buf */ - unsigned code; /* the code to send */ - int extra; /* number of extra bits to send */ - - if (s->last_lit != 0) do { - dist = s->d_buf[lx]; - lc = s->l_buf[lx++]; - if (dist == 0) { - send_code(s, lc, ltree); /* send a literal byte */ - Tracecv(isgraph(lc), (stderr," '%c' ", lc)); - } else { - /* Here, lc is the match length - MIN_MATCH */ - code = _length_code[lc]; - send_code(s, code+LITERALS+1, ltree); /* send the length code */ - extra = extra_lbits[code]; - if (extra != 0) { - lc -= base_length[code]; - send_bits(s, lc, extra); /* send the extra length bits */ - } - dist--; /* dist is now the match distance - 1 */ - code = d_code(dist); - Assert (code < D_CODES, "bad d_code"); - - send_code(s, code, dtree); /* send the distance code */ - extra = extra_dbits[code]; - if (extra != 0) { - dist -= base_dist[code]; - send_bits(s, dist, extra); /* send the extra distance bits */ - } - } /* literal or match pair ? */ - - /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ - Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, - "pendingBuf overflow"); - - } while (lx < s->last_lit); - - send_code(s, END_BLOCK, ltree); -} - -/* =========================================================================== - * Check if the data type is TEXT or BINARY, using the following algorithm: - * - TEXT if the two conditions below are satisfied: - * a) There are no non-portable control characters belonging to the - * "black list" (0..6, 14..25, 28..31). - * b) There is at least one printable character belonging to the - * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). - * - BINARY otherwise. - * - The following partially-portable control characters form a - * "gray list" that is ignored in this detection algorithm: - * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). - * IN assertion: the fields Freq of dyn_ltree are set. - */ -local int detect_data_type(s) - deflate_state *s; -{ - /* black_mask is the bit mask of black-listed bytes - * set bits 0..6, 14..25, and 28..31 - * 0xf3ffc07f = binary 11110011111111111100000001111111 - */ - unsigned long black_mask = 0xf3ffc07fUL; - int n; - - /* Check for non-textual ("black-listed") bytes. */ - for (n = 0; n <= 31; n++, black_mask >>= 1) - if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0)) - return Z_BINARY; - - /* Check for textual ("white-listed") bytes. */ - if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 - || s->dyn_ltree[13].Freq != 0) - return Z_TEXT; - for (n = 32; n < LITERALS; n++) - if (s->dyn_ltree[n].Freq != 0) - return Z_TEXT; - - /* There are no "black-listed" or "white-listed" bytes: - * this stream either is empty or has tolerated ("gray-listed") bytes only. - */ - return Z_BINARY; -} - -/* =========================================================================== - * Reverse the first len bits of a code, using straightforward code (a faster - * method would use a table) - * IN assertion: 1 <= len <= 15 - */ -local unsigned bi_reverse(code, len) - unsigned code; /* the value to invert */ - int len; /* its bit length */ -{ - register unsigned res = 0; - do { - res |= code & 1; - code >>= 1, res <<= 1; - } while (--len > 0); - return res >> 1; -} - -/* =========================================================================== - * Flush the bit buffer, keeping at most 7 bits in it. - */ -local void bi_flush(s) - deflate_state *s; -{ - if (s->bi_valid == 16) { - put_short(s, s->bi_buf); - s->bi_buf = 0; - s->bi_valid = 0; - } else if (s->bi_valid >= 8) { - put_byte(s, (Byte)s->bi_buf); - s->bi_buf >>= 8; - s->bi_valid -= 8; - } -} - -/* =========================================================================== - * Flush the bit buffer and align the output on a byte boundary - */ -local void bi_windup(s) - deflate_state *s; -{ - if (s->bi_valid > 8) { - put_short(s, s->bi_buf); - } else if (s->bi_valid > 0) { - put_byte(s, (Byte)s->bi_buf); - } - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef DEBUG - s->bits_sent = (s->bits_sent+7) & ~7; -#endif -} - -/* =========================================================================== - * Copy a stored block, storing first the length and its - * one's complement if requested. - */ -local void copy_block(s, buf, len, header) - deflate_state *s; - charf *buf; /* the input data */ - unsigned len; /* its length */ - int header; /* true if block header must be written */ -{ - bi_windup(s); /* align on byte boundary */ - - if (header) { - put_short(s, (ush)len); - put_short(s, (ush)~len); -#ifdef DEBUG - s->bits_sent += 2*16; -#endif - } -#ifdef DEBUG - s->bits_sent += (ulg)len<<3; -#endif - while (len--) { - put_byte(s, *buf++); - } -} diff --git a/cdf36_3-dist/src/lib/zlib/trees.h b/cdf36_3-dist/src/lib/zlib/trees.h deleted file mode 100644 index d35639d..0000000 --- a/cdf36_3-dist/src/lib/zlib/trees.h +++ /dev/null @@ -1,128 +0,0 @@ -/* header created automatically with -DGEN_TREES_H */ - -local const ct_data static_ltree[L_CODES+2] = { -{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, -{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, -{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, -{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, -{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, -{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, -{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, -{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, -{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, -{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, -{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, -{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, -{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, -{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, -{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, -{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, -{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, -{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, -{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, -{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, -{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, -{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, -{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, -{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, -{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, -{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, -{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, -{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, -{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, -{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, -{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, -{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, -{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, -{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, -{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, -{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, -{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, -{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, -{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, -{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, -{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, -{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, -{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, -{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, -{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, -{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, -{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, -{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, -{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, -{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, -{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, -{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, -{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, -{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, -{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, -{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, -{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, -{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} -}; - -local const ct_data static_dtree[D_CODES] = { -{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, -{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, -{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, -{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, -{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, -{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} -}; - -const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = { - 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, - 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, -10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, -11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, -12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, -13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, -13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, -14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, -14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, -14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, -15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, -15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, -15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, -18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, -23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, -26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, -26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, -27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, -27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, -28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, -28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, -28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, -29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, -29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, -29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 -}; - -const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, -13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, -17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, -19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, -21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, -22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, -23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, -25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, -26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, -26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, -27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 -}; - -local const int base_length[LENGTH_CODES] = { -0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, -64, 80, 96, 112, 128, 160, 192, 224, 0 -}; - -local const int base_dist[D_CODES] = { - 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, - 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, - 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 -}; - diff --git a/cdf36_3-dist/src/lib/zlib/uncompr.c b/cdf36_3-dist/src/lib/zlib/uncompr.c deleted file mode 100644 index b86995f..0000000 --- a/cdf36_3-dist/src/lib/zlib/uncompr.c +++ /dev/null @@ -1,59 +0,0 @@ -/* uncompr.c -- decompress a memory buffer - * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id: uncompr.c,v 1.1.1.1 2016/10/12 19:21:25 liu Exp $ */ - -#define ZLIB_INTERNAL -#include "zlib.h" - -/* =========================================================================== - Decompresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be large enough to hold the - entire uncompressed data. (The size of the uncompressed data must have - been saved previously by the compressor and transmitted to the decompressor - by some mechanism outside the scope of this compression library.) - Upon exit, destLen is the actual size of the compressed buffer. - - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer, or Z_DATA_ERROR if the input data was corrupted. -*/ -int ZEXPORT uncompress (dest, destLen, source, sourceLen) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; -{ - z_stream stream; - int err; - - stream.next_in = (z_const Bytef *)source; - stream.avail_in = (uInt)sourceLen; - /* Check for source > 64K on 16-bit machine: */ - if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; - - stream.next_out = dest; - stream.avail_out = (uInt)*destLen; - if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; - - stream.zalloc = (alloc_func)0; - stream.zfree = (free_func)0; - - err = inflateInit(&stream); - if (err != Z_OK) return err; - - err = inflate(&stream, Z_FINISH); - if (err != Z_STREAM_END) { - inflateEnd(&stream); - if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) - return Z_DATA_ERROR; - return err; - } - *destLen = stream.total_out; - - err = inflateEnd(&stream); - return err; -} diff --git a/cdf36_3-dist/src/lib/zlib/zconf.h b/cdf36_3-dist/src/lib/zlib/zconf.h deleted file mode 100644 index a02b488..0000000 --- a/cdf36_3-dist/src/lib/zlib/zconf.h +++ /dev/null @@ -1,511 +0,0 @@ -/* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2013 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id: zconf.h,v 1.1.1.1 2016/10/12 19:21:25 liu Exp $ */ - -#ifndef ZCONF_H -#define ZCONF_H - -/* - * If you *really* need a unique prefix for all types and library functions, - * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. - * Even better than compiling with -DZ_PREFIX would be to use configure to set - * this permanently in zconf.h using "./configure --zprefix". - */ -#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ -# define Z_PREFIX_SET - -/* all linked symbols */ -# define _dist_code z__dist_code -# define _length_code z__length_code -# define _tr_align z__tr_align -# define _tr_flush_bits z__tr_flush_bits -# define _tr_flush_block z__tr_flush_block -# define _tr_init z__tr_init -# define _tr_stored_block z__tr_stored_block -# define _tr_tally z__tr_tally -# define adler32 z_adler32 -# define adler32_combine z_adler32_combine -# define adler32_combine64 z_adler32_combine64 -# ifndef Z_SOLO -# define compress z_compress -# define compress2 z_compress2 -# define compressBound z_compressBound -# endif -# define crc32 z_crc32 -# define crc32_combine z_crc32_combine -# define crc32_combine64 z_crc32_combine64 -# define deflate z_deflate -# define deflateBound z_deflateBound -# define deflateCopy z_deflateCopy -# define deflateEnd z_deflateEnd -# define deflateInit2_ z_deflateInit2_ -# define deflateInit_ z_deflateInit_ -# define deflateParams z_deflateParams -# define deflatePending z_deflatePending -# define deflatePrime z_deflatePrime -# define deflateReset z_deflateReset -# define deflateResetKeep z_deflateResetKeep -# define deflateSetDictionary z_deflateSetDictionary -# define deflateSetHeader z_deflateSetHeader -# define deflateTune z_deflateTune -# define deflate_copyright z_deflate_copyright -# define get_crc_table z_get_crc_table -# ifndef Z_SOLO -# define gz_error z_gz_error -# define gz_intmax z_gz_intmax -# define gz_strwinerror z_gz_strwinerror -# define gzbuffer z_gzbuffer -# define gzclearerr z_gzclearerr -# define gzclose z_gzclose -# define gzclose_r z_gzclose_r -# define gzclose_w z_gzclose_w -# define gzdirect z_gzdirect -# define gzdopen z_gzdopen -# define gzeof z_gzeof -# define gzerror z_gzerror -# define gzflush z_gzflush -# define gzgetc z_gzgetc -# define gzgetc_ z_gzgetc_ -# define gzgets z_gzgets -# define gzoffset z_gzoffset -# define gzoffset64 z_gzoffset64 -# define gzopen z_gzopen -# define gzopen64 z_gzopen64 -# ifdef _WIN32 -# define gzopen_w z_gzopen_w -# endif -# define gzprintf z_gzprintf -# define gzvprintf z_gzvprintf -# define gzputc z_gzputc -# define gzputs z_gzputs -# define gzread z_gzread -# define gzrewind z_gzrewind -# define gzseek z_gzseek -# define gzseek64 z_gzseek64 -# define gzsetparams z_gzsetparams -# define gztell z_gztell -# define gztell64 z_gztell64 -# define gzungetc z_gzungetc -# define gzwrite z_gzwrite -# endif -# define inflate z_inflate -# define inflateBack z_inflateBack -# define inflateBackEnd z_inflateBackEnd -# define inflateBackInit_ z_inflateBackInit_ -# define inflateCopy z_inflateCopy -# define inflateEnd z_inflateEnd -# define inflateGetHeader z_inflateGetHeader -# define inflateInit2_ z_inflateInit2_ -# define inflateInit_ z_inflateInit_ -# define inflateMark z_inflateMark -# define inflatePrime z_inflatePrime -# define inflateReset z_inflateReset -# define inflateReset2 z_inflateReset2 -# define inflateSetDictionary z_inflateSetDictionary -# define inflateGetDictionary z_inflateGetDictionary -# define inflateSync z_inflateSync -# define inflateSyncPoint z_inflateSyncPoint -# define inflateUndermine z_inflateUndermine -# define inflateResetKeep z_inflateResetKeep -# define inflate_copyright z_inflate_copyright -# define inflate_fast z_inflate_fast -# define inflate_table z_inflate_table -# ifndef Z_SOLO -# define uncompress z_uncompress -# endif -# define zError z_zError -# ifndef Z_SOLO -# define zcalloc z_zcalloc -# define zcfree z_zcfree -# endif -# define zlibCompileFlags z_zlibCompileFlags -# define zlibVersion z_zlibVersion - -/* all zlib typedefs in zlib.h and zconf.h */ -# define Byte z_Byte -# define Bytef z_Bytef -# define alloc_func z_alloc_func -# define charf z_charf -# define free_func z_free_func -# ifndef Z_SOLO -# define gzFile z_gzFile -# endif -# define gz_header z_gz_header -# define gz_headerp z_gz_headerp -# define in_func z_in_func -# define intf z_intf -# define out_func z_out_func -# define uInt z_uInt -# define uIntf z_uIntf -# define uLong z_uLong -# define uLongf z_uLongf -# define voidp z_voidp -# define voidpc z_voidpc -# define voidpf z_voidpf - -/* all zlib structs in zlib.h and zconf.h */ -# define gz_header_s z_gz_header_s -# define internal_state z_internal_state - -#endif - -#if defined(__MSDOS__) && !defined(MSDOS) -# define MSDOS -#endif -#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) -# define OS2 -#endif -#if defined(_WINDOWS) && !defined(WINDOWS) -# define WINDOWS -#endif -#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) -# ifndef WIN32 -# define WIN32 -# endif -#endif -#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) -# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) -# ifndef SYS16BIT -# define SYS16BIT -# endif -# endif -#endif - -/* - * Compile with -DMAXSEG_64K if the alloc function cannot allocate more - * than 64k bytes at a time (needed on systems with 16-bit int). - */ -#ifdef SYS16BIT -# define MAXSEG_64K -#endif -#ifdef MSDOS -# define UNALIGNED_OK -#endif - -#ifdef __STDC_VERSION__ -# ifndef STDC -# define STDC -# endif -# if __STDC_VERSION__ >= 199901L -# ifndef STDC99 -# define STDC99 -# endif -# endif -#endif -#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) -# define STDC -#endif -#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) -# define STDC -#endif -#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) -# define STDC -#endif -#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) -# define STDC -#endif - -#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ -# define STDC -#endif - -#ifndef STDC -# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ -# define const /* note: need a more gentle solution here */ -# endif -#endif - -#if defined(ZLIB_CONST) && !defined(z_const) -# define z_const const -#else -# define z_const -#endif - -/* Some Mac compilers merge all .h files incorrectly: */ -#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) -# define NO_DUMMY_DECL -#endif - -/* Maximum value for memLevel in deflateInit2 */ -#ifndef MAX_MEM_LEVEL -# ifdef MAXSEG_64K -# define MAX_MEM_LEVEL 8 -# else -# define MAX_MEM_LEVEL 9 -# endif -#endif - -/* Maximum value for windowBits in deflateInit2 and inflateInit2. - * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files - * created by gzip. (Files created by minigzip can still be extracted by - * gzip.) - */ -#ifndef MAX_WBITS -# define MAX_WBITS 15 /* 32K LZ77 window */ -#endif - -/* The memory requirements for deflate are (in bytes): - (1 << (windowBits+2)) + (1 << (memLevel+9)) - that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) - plus a few kilobytes for small objects. For example, if you want to reduce - the default memory requirements from 256K to 128K, compile with - make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" - Of course this will generally degrade compression (there's no free lunch). - - The memory requirements for inflate are (in bytes) 1 << windowBits - that is, 32K for windowBits=15 (default value) plus a few kilobytes - for small objects. -*/ - - /* Type declarations */ - -#ifndef OF /* function prototypes */ -# ifdef STDC -# define OF(args) args -# else -# define OF(args) () -# endif -#endif - -#ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif -#endif - -/* The following definitions for FAR are needed only for MSDOS mixed - * model programming (small or medium model with some far allocations). - * This was tested only with MSC; for other MSDOS compilers you may have - * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, - * just define FAR to be empty. - */ -#ifdef SYS16BIT -# if defined(M_I86SM) || defined(M_I86MM) - /* MSC small or medium model */ -# define SMALL_MEDIUM -# ifdef _MSC_VER -# define FAR _far -# else -# define FAR far -# endif -# endif -# if (defined(__SMALL__) || defined(__MEDIUM__)) - /* Turbo C small or medium model */ -# define SMALL_MEDIUM -# ifdef __BORLANDC__ -# define FAR _far -# else -# define FAR far -# endif -# endif -#endif - -#if defined(WINDOWS) || defined(WIN32) - /* If building or using zlib as a DLL, define ZLIB_DLL. - * This is not mandatory, but it offers a little performance increase. - */ -# ifdef ZLIB_DLL -# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) -# ifdef ZLIB_INTERNAL -# define ZEXTERN extern __declspec(dllexport) -# else -# define ZEXTERN extern __declspec(dllimport) -# endif -# endif -# endif /* ZLIB_DLL */ - /* If building or using zlib with the WINAPI/WINAPIV calling convention, - * define ZLIB_WINAPI. - * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. - */ -# ifdef ZLIB_WINAPI -# ifdef FAR -# undef FAR -# endif -# include - /* No need for _export, use ZLIB.DEF instead. */ - /* For complete Windows compatibility, use WINAPI, not __stdcall. */ -# define ZEXPORT WINAPI -# ifdef WIN32 -# define ZEXPORTVA WINAPIV -# else -# define ZEXPORTVA FAR CDECL -# endif -# endif -#endif - -#if defined (__BEOS__) -# ifdef ZLIB_DLL -# ifdef ZLIB_INTERNAL -# define ZEXPORT __declspec(dllexport) -# define ZEXPORTVA __declspec(dllexport) -# else -# define ZEXPORT __declspec(dllimport) -# define ZEXPORTVA __declspec(dllimport) -# endif -# endif -#endif - -#ifndef ZEXTERN -# define ZEXTERN extern -#endif -#ifndef ZEXPORT -# define ZEXPORT -#endif -#ifndef ZEXPORTVA -# define ZEXPORTVA -#endif - -#ifndef FAR -# define FAR -#endif - -#if !defined(__MACTYPES__) -typedef unsigned char Byte; /* 8 bits */ -#endif -typedef unsigned int uInt; /* 16 bits or more */ -typedef unsigned long uLong; /* 32 bits or more */ - -#ifdef SMALL_MEDIUM - /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ -# define Bytef Byte FAR -#else - typedef Byte FAR Bytef; -#endif -typedef char FAR charf; -typedef int FAR intf; -typedef uInt FAR uIntf; -typedef uLong FAR uLongf; - -#ifdef STDC - typedef void const *voidpc; - typedef void FAR *voidpf; - typedef void *voidp; -#else - typedef Byte const *voidpc; - typedef Byte FAR *voidpf; - typedef Byte *voidp; -#endif - -#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) -# include -# if (UINT_MAX == 0xffffffffUL) -# define Z_U4 unsigned -# elif (ULONG_MAX == 0xffffffffUL) -# define Z_U4 unsigned long -# elif (USHRT_MAX == 0xffffffffUL) -# define Z_U4 unsigned short -# endif -#endif - -#ifdef Z_U4 - typedef Z_U4 z_crc_t; -#else - typedef unsigned long z_crc_t; -#endif - -#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ -# define Z_HAVE_UNISTD_H -#endif - -#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ -# define Z_HAVE_STDARG_H -#endif - -#ifdef STDC -# ifndef Z_SOLO -# include /* for off_t */ -# endif -#endif - -#if defined(STDC) || defined(Z_HAVE_STDARG_H) -# ifndef Z_SOLO -# include /* for va_list */ -# endif -#endif - -#ifdef _WIN32 -# ifndef Z_SOLO -# include /* for wchar_t */ -# endif -#endif - -/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and - * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even - * though the former does not conform to the LFS document), but considering - * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as - * equivalently requesting no 64-bit operations - */ -#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 -# undef _LARGEFILE64_SOURCE -#endif - -#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) -# define Z_HAVE_UNISTD_H -#endif -#ifndef Z_SOLO -# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) -# include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ -# ifdef VMS -# include /* for off_t */ -# endif -# ifndef z_off_t -# define z_off_t off_t -# endif -# endif -#endif - -#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 -# define Z_LFS64 -#endif - -#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) -# define Z_LARGE64 -#endif - -#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) -# define Z_WANT64 -#endif - -#if !defined(SEEK_SET) && !defined(Z_SOLO) -# define SEEK_SET 0 /* Seek from beginning of file. */ -# define SEEK_CUR 1 /* Seek from current position. */ -# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ -#endif - -#ifndef z_off_t -# define z_off_t long -#endif - -#if !defined(_WIN32) && defined(Z_LARGE64) -# define z_off64_t off64_t -#else -# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) -# define z_off64_t __int64 -# else -# define z_off64_t z_off_t -# endif -#endif - -/* MVS linker does not support external names larger than 8 bytes */ -#if defined(__MVS__) - #pragma map(deflateInit_,"DEIN") - #pragma map(deflateInit2_,"DEIN2") - #pragma map(deflateEnd,"DEEND") - #pragma map(deflateBound,"DEBND") - #pragma map(inflateInit_,"ININ") - #pragma map(inflateInit2_,"ININ2") - #pragma map(inflateEnd,"INEND") - #pragma map(inflateSync,"INSY") - #pragma map(inflateSetDictionary,"INSEDI") - #pragma map(compressBound,"CMBND") - #pragma map(inflate_table,"INTABL") - #pragma map(inflate_fast,"INFA") - #pragma map(inflate_copyright,"INCOPY") -#endif - -#endif /* ZCONF_H */ diff --git a/cdf36_3-dist/src/lib/zlib/zlib.h b/cdf36_3-dist/src/lib/zlib/zlib.h deleted file mode 100644 index 3e0c767..0000000 --- a/cdf36_3-dist/src/lib/zlib/zlib.h +++ /dev/null @@ -1,1768 +0,0 @@ -/* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.8, April 28th, 2013 - - Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 - (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). -*/ - -#ifndef ZLIB_H -#define ZLIB_H - -#include "zconf.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define ZLIB_VERSION "1.2.8" -#define ZLIB_VERNUM 0x1280 -#define ZLIB_VER_MAJOR 1 -#define ZLIB_VER_MINOR 2 -#define ZLIB_VER_REVISION 8 -#define ZLIB_VER_SUBREVISION 0 - -/* - The 'zlib' compression library provides in-memory compression and - decompression functions, including integrity checks of the uncompressed data. - This version of the library supports only one compression method (deflation) - but other algorithms will be added later and will have the same stream - interface. - - Compression can be done in a single step if the buffers are large enough, - or can be done by repeated calls of the compression function. In the latter - case, the application must provide more input and/or consume the output - (providing more output space) before each call. - - The compressed data format used by default by the in-memory functions is - the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped - around a deflate stream, which is itself documented in RFC 1951. - - The library also supports reading and writing files in gzip (.gz) format - with an interface similar to that of stdio using the functions that start - with "gz". The gzip format is different from the zlib format. gzip is a - gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. - - This library can optionally read and write gzip streams in memory as well. - - The zlib format was designed to be compact and fast for use in memory - and on communications channels. The gzip format was designed for single- - file compression on file systems, has a larger header than zlib to maintain - directory information, and uses a different, slower check method than zlib. - - The library does not install any signal handler. The decoder checks - the consistency of the compressed data, so the library should never crash - even in case of corrupted input. -*/ - -typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); -typedef void (*free_func) OF((voidpf opaque, voidpf address)); - -struct internal_state; - -typedef struct z_stream_s { - z_const Bytef *next_in; /* next input byte */ - uInt avail_in; /* number of bytes available at next_in */ - uLong total_in; /* total number of input bytes read so far */ - - Bytef *next_out; /* next output byte should be put there */ - uInt avail_out; /* remaining free space at next_out */ - uLong total_out; /* total number of bytes output so far */ - - z_const char *msg; /* last error message, NULL if no error */ - struct internal_state FAR *state; /* not visible by applications */ - - alloc_func zalloc; /* used to allocate the internal state */ - free_func zfree; /* used to free the internal state */ - voidpf opaque; /* private data object passed to zalloc and zfree */ - - int data_type; /* best guess about the data type: binary or text */ - uLong adler; /* adler32 value of the uncompressed data */ - uLong reserved; /* reserved for future use */ -} z_stream; - -typedef z_stream FAR *z_streamp; - -/* - gzip header information passed to and from zlib routines. See RFC 1952 - for more details on the meanings of these fields. -*/ -typedef struct gz_header_s { - int text; /* true if compressed data believed to be text */ - uLong time; /* modification time */ - int xflags; /* extra flags (not used when writing a gzip file) */ - int os; /* operating system */ - Bytef *extra; /* pointer to extra field or Z_NULL if none */ - uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ - uInt extra_max; /* space at extra (only when reading header) */ - Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ - uInt name_max; /* space at name (only when reading header) */ - Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ - uInt comm_max; /* space at comment (only when reading header) */ - int hcrc; /* true if there was or will be a header crc */ - int done; /* true when done reading gzip header (not used - when writing a gzip file) */ -} gz_header; - -typedef gz_header FAR *gz_headerp; - -/* - The application must update next_in and avail_in when avail_in has dropped - to zero. It must update next_out and avail_out when avail_out has dropped - to zero. The application must initialize zalloc, zfree and opaque before - calling the init function. All other fields are set by the compression - library and must not be updated by the application. - - The opaque value provided by the application will be passed as the first - parameter for calls of zalloc and zfree. This can be useful for custom - memory management. The compression library attaches no meaning to the - opaque value. - - zalloc must return Z_NULL if there is not enough memory for the object. - If zlib is used in a multi-threaded application, zalloc and zfree must be - thread safe. - - On 16-bit systems, the functions zalloc and zfree must be able to allocate - exactly 65536 bytes, but will not be required to allocate more than this if - the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers - returned by zalloc for objects of exactly 65536 bytes *must* have their - offset normalized to zero. The default allocation function provided by this - library ensures this (see zutil.c). To reduce memory requirements and avoid - any allocation of 64K objects, at the expense of compression ratio, compile - the library with -DMAX_WBITS=14 (see zconf.h). - - The fields total_in and total_out can be used for statistics or progress - reports. After compression, total_in holds the total size of the - uncompressed data and may be saved for use in the decompressor (particularly - if the decompressor wants to decompress everything in a single step). -*/ - - /* constants */ - -#define Z_NO_FLUSH 0 -#define Z_PARTIAL_FLUSH 1 -#define Z_SYNC_FLUSH 2 -#define Z_FULL_FLUSH 3 -#define Z_FINISH 4 -#define Z_BLOCK 5 -#define Z_TREES 6 -/* Allowed flush values; see deflate() and inflate() below for details */ - -#define Z_OK 0 -#define Z_STREAM_END 1 -#define Z_NEED_DICT 2 -#define Z_ERRNO (-1) -#define Z_STREAM_ERROR (-2) -#define Z_DATA_ERROR (-3) -#define Z_MEM_ERROR (-4) -#define Z_BUF_ERROR (-5) -#define Z_VERSION_ERROR (-6) -/* Return codes for the compression/decompression functions. Negative values - * are errors, positive values are used for special but normal events. - */ - -#define Z_NO_COMPRESSION 0 -#define Z_BEST_SPEED 1 -#define Z_BEST_COMPRESSION 9 -#define Z_DEFAULT_COMPRESSION (-1) -/* compression levels */ - -#define Z_FILTERED 1 -#define Z_HUFFMAN_ONLY 2 -#define Z_RLE 3 -#define Z_FIXED 4 -#define Z_DEFAULT_STRATEGY 0 -/* compression strategy; see deflateInit2() below for details */ - -#define Z_BINARY 0 -#define Z_TEXT 1 -#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ -#define Z_UNKNOWN 2 -/* Possible values of the data_type field (though see inflate()) */ - -#define Z_DEFLATED 8 -/* The deflate compression method (the only one supported in this version) */ - -#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ - -#define zlib_version zlibVersion() -/* for compatibility with versions < 1.0.2 */ - - - /* basic functions */ - -ZEXTERN const char * ZEXPORT zlibVersion OF((void)); -/* The application can compare zlibVersion and ZLIB_VERSION for consistency. - If the first character differs, the library code actually used is not - compatible with the zlib.h header file used by the application. This check - is automatically made by deflateInit and inflateInit. - */ - -/* -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); - - Initializes the internal stream state for compression. The fields - zalloc, zfree and opaque must be initialized before by the caller. If - zalloc and zfree are set to Z_NULL, deflateInit updates them to use default - allocation functions. - - The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: - 1 gives best speed, 9 gives best compression, 0 gives no compression at all - (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION - requests a default compromise between speed and compression (currently - equivalent to level 6). - - deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if level is not a valid compression level, or - Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible - with the version assumed by the caller (ZLIB_VERSION). msg is set to null - if there is no error message. deflateInit does not perform any compression: - this will be done by deflate(). -*/ - - -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); -/* - deflate compresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce - some output latency (reading input without producing any output) except when - forced to flush. - - The detailed semantics are as follows. deflate performs one or both of the - following actions: - - - Compress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in and avail_in are updated and - processing will resume at this point for the next call of deflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. This action is forced if the parameter flush is non zero. - Forcing flush frequently degrades the compression ratio, so this parameter - should be set only when necessary (in interactive applications). Some - output may be provided even if flush is not set. - - Before the call of deflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming more - output, and updating avail_in or avail_out accordingly; avail_out should - never be zero before the call. The application can consume the compressed - output when it wants, for example when the output buffer is full (avail_out - == 0), or after each call of deflate(). If deflate returns Z_OK and with - zero avail_out, it must be called again after making room in the output - buffer because there might be more output pending. - - Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to - decide how much data to accumulate before producing output, in order to - maximize compression. - - If the parameter flush is set to Z_SYNC_FLUSH, all pending output is - flushed to the output buffer and the output is aligned on a byte boundary, so - that the decompressor can get all input data available so far. (In - particular avail_in is zero after the call if enough output space has been - provided before the call.) Flushing may degrade compression for some - compression algorithms and so it should be used only when necessary. This - completes the current deflate block and follows it with an empty stored block - that is three bits plus filler bits to the next byte, followed by four bytes - (00 00 ff ff). - - If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the - output buffer, but the output is not aligned to a byte boundary. All of the - input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. - This completes the current deflate block and follows it with an empty fixed - codes block that is 10 bits long. This assures that enough bytes are output - in order for the decompressor to finish the block before the empty fixed code - block. - - If flush is set to Z_BLOCK, a deflate block is completed and emitted, as - for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to - seven bits of the current block are held to be written as the next byte after - the next deflate block is completed. In this case, the decompressor may not - be provided enough bits at this point in order to complete decompression of - the data provided so far to the compressor. It may need to wait for the next - block to be emitted. This is for advanced applications that need to control - the emission of deflate blocks. - - If flush is set to Z_FULL_FLUSH, all output is flushed as with - Z_SYNC_FLUSH, and the compression state is reset so that decompression can - restart from this point if previous compressed data has been damaged or if - random access is desired. Using Z_FULL_FLUSH too often can seriously degrade - compression. - - If deflate returns with avail_out == 0, this function must be called again - with the same value of the flush parameter and more output space (updated - avail_out), until the flush is complete (deflate returns with non-zero - avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that - avail_out is greater than six to avoid repeated flush markers due to - avail_out == 0 on return. - - If the parameter flush is set to Z_FINISH, pending input is processed, - pending output is flushed and deflate returns with Z_STREAM_END if there was - enough output space; if deflate returns with Z_OK, this function must be - called again with Z_FINISH and more output space (updated avail_out) but no - more input data, until it returns with Z_STREAM_END or an error. After - deflate has returned Z_STREAM_END, the only possible operations on the stream - are deflateReset or deflateEnd. - - Z_FINISH can be used immediately after deflateInit if all the compression - is to be done in a single step. In this case, avail_out must be at least the - value returned by deflateBound (see below). Then deflate is guaranteed to - return Z_STREAM_END. If not enough output space is provided, deflate will - not return Z_STREAM_END, and it must be called again as described above. - - deflate() sets strm->adler to the adler32 checksum of all input read - so far (that is, total_in bytes). - - deflate() may update strm->data_type if it can make a good guess about - the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered - binary. This field is only for information purposes and does not affect the - compression algorithm in any manner. - - deflate() returns Z_OK if some progress has been made (more input - processed or more output produced), Z_STREAM_END if all input has been - consumed and all output has been produced (only when flush is set to - Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example - if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible - (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not - fatal, and deflate() can be called again with more input and more output - space to continue compressing. -*/ - - -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any pending - output. - - deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the - stream state was inconsistent, Z_DATA_ERROR if the stream was freed - prematurely (some input or output was discarded). In the error case, msg - may be set but then points to a static string (which must not be - deallocated). -*/ - - -/* -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); - - Initializes the internal stream state for decompression. The fields - next_in, avail_in, zalloc, zfree and opaque must be initialized before by - the caller. If next_in is not Z_NULL and avail_in is large enough (the - exact value depends on the compression method), inflateInit determines the - compression method from the zlib header and allocates all data structures - accordingly; otherwise the allocation will be deferred to the first call of - inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to - use default allocation functions. - - inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_VERSION_ERROR if the zlib library version is incompatible with the - version assumed by the caller, or Z_STREAM_ERROR if the parameters are - invalid, such as a null pointer to the structure. msg is set to null if - there is no error message. inflateInit does not perform any decompression - apart from possibly reading the zlib header if present: actual decompression - will be done by inflate(). (So next_in and avail_in may be modified, but - next_out and avail_out are unused and unchanged.) The current implementation - of inflateInit() does not process any header information -- that is deferred - until inflate() is called. -*/ - - -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); -/* - inflate decompresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce - some output latency (reading input without producing any output) except when - forced to flush. - - The detailed semantics are as follows. inflate performs one or both of the - following actions: - - - Decompress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in is updated and processing will - resume at this point for the next call of inflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. inflate() provides as much output as possible, until there is - no more input data or no more space in the output buffer (see below about - the flush parameter). - - Before the call of inflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming more - output, and updating the next_* and avail_* values accordingly. The - application can consume the uncompressed output when it wants, for example - when the output buffer is full (avail_out == 0), or after each call of - inflate(). If inflate returns Z_OK and with zero avail_out, it must be - called again after making room in the output buffer because there might be - more output pending. - - The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, - Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much - output as possible to the output buffer. Z_BLOCK requests that inflate() - stop if and when it gets to the next deflate block boundary. When decoding - the zlib or gzip format, this will cause inflate() to return immediately - after the header and before the first block. When doing a raw inflate, - inflate() will go ahead and process the first block, and will return when it - gets to the end of that block, or when it runs out of data. - - The Z_BLOCK option assists in appending to or combining deflate streams. - Also to assist in this, on return inflate() will set strm->data_type to the - number of unused bits in the last byte taken from strm->next_in, plus 64 if - inflate() is currently decoding the last block in the deflate stream, plus - 128 if inflate() returned immediately after decoding an end-of-block code or - decoding the complete header up to just before the first byte of the deflate - stream. The end-of-block will not be indicated until all of the uncompressed - data from that block has been written to strm->next_out. The number of - unused bits may in general be greater than seven, except when bit 7 of - data_type is set, in which case the number of unused bits will be less than - eight. data_type is set as noted here every time inflate() returns for all - flush options, and so can be used to determine the amount of currently - consumed input in bits. - - The Z_TREES option behaves as Z_BLOCK does, but it also returns when the - end of each deflate block header is reached, before any actual data in that - block is decoded. This allows the caller to determine the length of the - deflate block header for later use in random access within a deflate block. - 256 is added to the value of strm->data_type when inflate() returns - immediately after reaching the end of the deflate block header. - - inflate() should normally be called until it returns Z_STREAM_END or an - error. However if all decompression is to be performed in a single step (a - single call of inflate), the parameter flush should be set to Z_FINISH. In - this case all pending input is processed and all pending output is flushed; - avail_out must be large enough to hold all of the uncompressed data for the - operation to complete. (The size of the uncompressed data may have been - saved by the compressor for this purpose.) The use of Z_FINISH is not - required to perform an inflation in one step. However it may be used to - inform inflate that a faster approach can be used for the single inflate() - call. Z_FINISH also informs inflate to not maintain a sliding window if the - stream completes, which reduces inflate's memory footprint. If the stream - does not complete, either because not all of the stream is provided or not - enough output space is provided, then a sliding window will be allocated and - inflate() can be called again to continue the operation as if Z_NO_FLUSH had - been used. - - In this implementation, inflate() always flushes as much output as - possible to the output buffer, and always uses the faster approach on the - first call. So the effects of the flush parameter in this implementation are - on the return value of inflate() as noted below, when inflate() returns early - when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of - memory for a sliding window when Z_FINISH is used. - - If a preset dictionary is needed after this call (see inflateSetDictionary - below), inflate sets strm->adler to the Adler-32 checksum of the dictionary - chosen by the compressor and returns Z_NEED_DICT; otherwise it sets - strm->adler to the Adler-32 checksum of all output produced so far (that is, - total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described - below. At the end of the stream, inflate() checks that its computed adler32 - checksum is equal to that saved by the compressor and returns Z_STREAM_END - only if the checksum is correct. - - inflate() can decompress and check either zlib-wrapped or gzip-wrapped - deflate data. The header type is detected automatically, if requested when - initializing with inflateInit2(). Any information contained in the gzip - header is not retained, so applications that need that information should - instead use raw inflate, see inflateInit2() below, or inflateBack() and - perform their own processing of the gzip header and trailer. When processing - gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output - producted so far. The CRC-32 is checked against the gzip trailer. - - inflate() returns Z_OK if some progress has been made (more input processed - or more output produced), Z_STREAM_END if the end of the compressed data has - been reached and all uncompressed output has been produced, Z_NEED_DICT if a - preset dictionary is needed at this point, Z_DATA_ERROR if the input data was - corrupted (input stream not conforming to the zlib format or incorrect check - value), Z_STREAM_ERROR if the stream structure was inconsistent (for example - next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, - Z_BUF_ERROR if no progress is possible or if there was not enough room in the - output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and - inflate() can be called again with more input and more output space to - continue decompressing. If Z_DATA_ERROR is returned, the application may - then call inflateSync() to look for a good compression block if a partial - recovery of the data is desired. -*/ - - -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any pending - output. - - inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state - was inconsistent. In the error case, msg may be set but then points to a - static string (which must not be deallocated). -*/ - - - /* Advanced functions */ - -/* - The following functions are needed only in some special applications. -*/ - -/* -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy)); - - This is another version of deflateInit with more compression options. The - fields next_in, zalloc, zfree and opaque must be initialized before by the - caller. - - The method parameter is the compression method. It must be Z_DEFLATED in - this version of the library. - - The windowBits parameter is the base two logarithm of the window size - (the size of the history buffer). It should be in the range 8..15 for this - version of the library. Larger values of this parameter result in better - compression at the expense of memory usage. The default value is 15 if - deflateInit is used instead. - - windowBits can also be -8..-15 for raw deflate. In this case, -windowBits - determines the window size. deflate() will then generate raw deflate data - with no zlib header or trailer, and will not compute an adler32 check value. - - windowBits can also be greater than 15 for optional gzip encoding. Add - 16 to windowBits to write a simple gzip header and trailer around the - compressed data instead of a zlib wrapper. The gzip header will have no - file name, no extra data, no comment, no modification time (set to zero), no - header crc, and the operating system will be set to 255 (unknown). If a - gzip stream is being written, strm->adler is a crc32 instead of an adler32. - - The memLevel parameter specifies how much memory should be allocated - for the internal compression state. memLevel=1 uses minimum memory but is - slow and reduces compression ratio; memLevel=9 uses maximum memory for - optimal speed. The default value is 8. See zconf.h for total memory usage - as a function of windowBits and memLevel. - - The strategy parameter is used to tune the compression algorithm. Use the - value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a - filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no - string match), or Z_RLE to limit match distances to one (run-length - encoding). Filtered data consists mostly of small values with a somewhat - random distribution. In this case, the compression algorithm is tuned to - compress them better. The effect of Z_FILTERED is to force more Huffman - coding and less string matching; it is somewhat intermediate between - Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as - fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The - strategy parameter only affects the compression ratio but not the - correctness of the compressed output even if it is not set appropriately. - Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler - decoder for special applications. - - deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid - method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is - incompatible with the version assumed by the caller (ZLIB_VERSION). msg is - set to null if there is no error message. deflateInit2 does not perform any - compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); -/* - Initializes the compression dictionary from the given byte sequence - without producing any compressed output. When using the zlib format, this - function must be called immediately after deflateInit, deflateInit2 or - deflateReset, and before any call of deflate. When doing raw deflate, this - function must be called either before any call of deflate, or immediately - after the completion of a deflate block, i.e. after all input has been - consumed and all output has been delivered when using any of the flush - options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The - compressor and decompressor must use exactly the same dictionary (see - inflateSetDictionary). - - The dictionary should consist of strings (byte sequences) that are likely - to be encountered later in the data to be compressed, with the most commonly - used strings preferably put towards the end of the dictionary. Using a - dictionary is most useful when the data to be compressed is short and can be - predicted with good accuracy; the data can then be compressed better than - with the default empty dictionary. - - Depending on the size of the compression data structures selected by - deflateInit or deflateInit2, a part of the dictionary may in effect be - discarded, for example if the dictionary is larger than the window size - provided in deflateInit or deflateInit2. Thus the strings most likely to be - useful should be put at the end of the dictionary, not at the front. In - addition, the current implementation of deflate will use at most the window - size minus 262 bytes of the provided dictionary. - - Upon return of this function, strm->adler is set to the adler32 value - of the dictionary; the decompressor may later use this value to determine - which dictionary has been used by the compressor. (The adler32 value - applies to the whole dictionary even if only a subset of the dictionary is - actually used by the compressor.) If a raw deflate was requested, then the - adler32 value is not computed and strm->adler is not set. - - deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a - parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is - inconsistent (for example if deflate has already been called for this stream - or if not at a block boundary for raw deflate). deflateSetDictionary does - not perform any compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, - z_streamp source)); -/* - Sets the destination stream as a complete copy of the source stream. - - This function can be useful when several compression strategies will be - tried, for example when there are several ways of pre-processing the input - data with a filter. The streams that will be discarded should then be freed - by calling deflateEnd. Note that deflateCopy duplicates the internal - compression state which can be quite large, so this strategy is slow and can - consume lots of memory. - - deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being Z_NULL). msg is left unchanged in both source and - destination. -*/ - -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); -/* - This function is equivalent to deflateEnd followed by deflateInit, - but does not free and reallocate all the internal compression state. The - stream will keep the same compression level and any other attributes that - may have been set by deflateInit2. - - deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being Z_NULL). -*/ - -ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, - int level, - int strategy)); -/* - Dynamically update the compression level and compression strategy. The - interpretation of level and strategy is as in deflateInit2. This can be - used to switch between compression and straight copy of the input data, or - to switch to a different kind of input data requiring a different strategy. - If the compression level is changed, the input available so far is - compressed with the old level (and may be flushed); the new level will take - effect only at the next call of deflate(). - - Before the call of deflateParams, the stream state must be set as for - a call of deflate(), since the currently available input may have to be - compressed and flushed. In particular, strm->avail_out must be non-zero. - - deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source - stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if - strm->avail_out was zero. -*/ - -ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, - int good_length, - int max_lazy, - int nice_length, - int max_chain)); -/* - Fine tune deflate's internal compression parameters. This should only be - used by someone who understands the algorithm used by zlib's deflate for - searching for the best matching string, and even then only by the most - fanatic optimizer trying to squeeze out the last compressed bit for their - specific input data. Read the deflate.c source code for the meaning of the - max_lazy, good_length, nice_length, and max_chain parameters. - - deflateTune() can be called after deflateInit() or deflateInit2(), and - returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. - */ - -ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, - uLong sourceLen)); -/* - deflateBound() returns an upper bound on the compressed size after - deflation of sourceLen bytes. It must be called after deflateInit() or - deflateInit2(), and after deflateSetHeader(), if used. This would be used - to allocate an output buffer for deflation in a single pass, and so would be - called before deflate(). If that first deflate() call is provided the - sourceLen input bytes, an output buffer allocated to the size returned by - deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed - to return Z_STREAM_END. Note that it is possible for the compressed size to - be larger than the value returned by deflateBound() if flush options other - than Z_FINISH or Z_NO_FLUSH are used. -*/ - -ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, - unsigned *pending, - int *bits)); -/* - deflatePending() returns the number of bytes and bits of output that have - been generated, but not yet provided in the available output. The bytes not - provided would be due to the available output space having being consumed. - The number of bits of output not provided are between 0 and 7, where they - await more bits to join them in order to fill out a full byte. If pending - or bits are Z_NULL, then those values are not set. - - deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. - */ - -ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, - int bits, - int value)); -/* - deflatePrime() inserts bits in the deflate output stream. The intent - is that this function is used to start off the deflate output with the bits - leftover from a previous deflate stream when appending to it. As such, this - function can only be used for raw deflate, and must be used before the first - deflate() call after a deflateInit2() or deflateReset(). bits must be less - than or equal to 16, and that many of the least significant bits of value - will be inserted in the output. - - deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough - room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the - source stream state was inconsistent. -*/ - -ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, - gz_headerp head)); -/* - deflateSetHeader() provides gzip header information for when a gzip - stream is requested by deflateInit2(). deflateSetHeader() may be called - after deflateInit2() or deflateReset() and before the first call of - deflate(). The text, time, os, extra field, name, and comment information - in the provided gz_header structure are written to the gzip header (xflag is - ignored -- the extra flags are set according to the compression level). The - caller must assure that, if not Z_NULL, name and comment are terminated with - a zero byte, and that if extra is not Z_NULL, that extra_len bytes are - available there. If hcrc is true, a gzip header crc is included. Note that - the current versions of the command-line version of gzip (up through version - 1.3.x) do not support header crc's, and will report that it is a "multi-part - gzip file" and give up. - - If deflateSetHeader is not used, the default gzip header has text false, - the time set to zero, and os set to 255, with no extra, name, or comment - fields. The gzip header is returned to the default state by deflateReset(). - - deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. -*/ - -/* -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, - int windowBits)); - - This is another version of inflateInit with an extra parameter. The - fields next_in, avail_in, zalloc, zfree and opaque must be initialized - before by the caller. - - The windowBits parameter is the base two logarithm of the maximum window - size (the size of the history buffer). It should be in the range 8..15 for - this version of the library. The default value is 15 if inflateInit is used - instead. windowBits must be greater than or equal to the windowBits value - provided to deflateInit2() while compressing, or it must be equal to 15 if - deflateInit2() was not used. If a compressed stream with a larger window - size is given as input, inflate() will return with the error code - Z_DATA_ERROR instead of trying to allocate a larger window. - - windowBits can also be zero to request that inflate use the window size in - the zlib header of the compressed stream. - - windowBits can also be -8..-15 for raw inflate. In this case, -windowBits - determines the window size. inflate() will then process raw deflate data, - not looking for a zlib or gzip header, not generating a check value, and not - looking for any check values for comparison at the end of the stream. This - is for use with other formats that use the deflate compressed data format - such as zip. Those formats provide their own check values. If a custom - format is developed using the raw deflate format for compressed data, it is - recommended that a check value such as an adler32 or a crc32 be applied to - the uncompressed data as is done in the zlib, gzip, and zip formats. For - most applications, the zlib format should be used as is. Note that comments - above on the use in deflateInit2() applies to the magnitude of windowBits. - - windowBits can also be greater than 15 for optional gzip decoding. Add - 32 to windowBits to enable zlib and gzip decoding with automatic header - detection, or add 16 to decode only the gzip format (the zlib format will - return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a - crc32 instead of an adler32. - - inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_VERSION_ERROR if the zlib library version is incompatible with the - version assumed by the caller, or Z_STREAM_ERROR if the parameters are - invalid, such as a null pointer to the structure. msg is set to null if - there is no error message. inflateInit2 does not perform any decompression - apart from possibly reading the zlib header if present: actual decompression - will be done by inflate(). (So next_in and avail_in may be modified, but - next_out and avail_out are unused and unchanged.) The current implementation - of inflateInit2() does not process any header information -- that is - deferred until inflate() is called. -*/ - -ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); -/* - Initializes the decompression dictionary from the given uncompressed byte - sequence. This function must be called immediately after a call of inflate, - if that call returned Z_NEED_DICT. The dictionary chosen by the compressor - can be determined from the adler32 value returned by that call of inflate. - The compressor and decompressor must use exactly the same dictionary (see - deflateSetDictionary). For raw inflate, this function can be called at any - time to set the dictionary. If the provided dictionary is smaller than the - window and there is already data in the window, then the provided dictionary - will amend what's there. The application must insure that the dictionary - that was used for compression is provided. - - inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a - parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is - inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the - expected one (incorrect adler32 value). inflateSetDictionary does not - perform any decompression: this will be done by subsequent calls of - inflate(). -*/ - -ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, - Bytef *dictionary, - uInt *dictLength)); -/* - Returns the sliding dictionary being maintained by inflate. dictLength is - set to the number of bytes in the dictionary, and that many bytes are copied - to dictionary. dictionary must have enough space, where 32768 bytes is - always enough. If inflateGetDictionary() is called with dictionary equal to - Z_NULL, then only the dictionary length is returned, and nothing is copied. - Similary, if dictLength is Z_NULL, then it is not set. - - inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the - stream state is inconsistent. -*/ - -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); -/* - Skips invalid compressed data until a possible full flush point (see above - for the description of deflate with Z_FULL_FLUSH) can be found, or until all - available input is skipped. No output is provided. - - inflateSync searches for a 00 00 FF FF pattern in the compressed data. - All full flush points have this pattern, but not all occurrences of this - pattern are full flush points. - - inflateSync returns Z_OK if a possible full flush point has been found, - Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point - has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. - In the success case, the application may save the current current value of - total_in which indicates where valid compressed data was found. In the - error case, the application may repeatedly call inflateSync, providing more - input each time, until success or end of the input data. -*/ - -ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, - z_streamp source)); -/* - Sets the destination stream as a complete copy of the source stream. - - This function can be useful when randomly accessing a large stream. The - first pass through the stream can periodically record the inflate state, - allowing restarting inflate at those points when randomly accessing the - stream. - - inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being Z_NULL). msg is left unchanged in both source and - destination. -*/ - -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); -/* - This function is equivalent to inflateEnd followed by inflateInit, - but does not free and reallocate all the internal decompression state. The - stream will keep attributes that may have been set by inflateInit2. - - inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being Z_NULL). -*/ - -ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, - int windowBits)); -/* - This function is the same as inflateReset, but it also permits changing - the wrap and window size requests. The windowBits parameter is interpreted - the same as it is for inflateInit2. - - inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being Z_NULL), or if - the windowBits parameter is invalid. -*/ - -ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, - int bits, - int value)); -/* - This function inserts bits in the inflate input stream. The intent is - that this function is used to start inflating at a bit position in the - middle of a byte. The provided bits will be used before any bytes are used - from next_in. This function should only be used with raw inflate, and - should be used before the first inflate() call after inflateInit2() or - inflateReset(). bits must be less than or equal to 16, and that many of the - least significant bits of value will be inserted in the input. - - If bits is negative, then the input stream bit buffer is emptied. Then - inflatePrime() can be called again to put bits in the buffer. This is used - to clear out bits leftover after feeding inflate a block description prior - to feeding inflate codes. - - inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. -*/ - -ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); -/* - This function returns two values, one in the lower 16 bits of the return - value, and the other in the remaining upper bits, obtained by shifting the - return value down 16 bits. If the upper value is -1 and the lower value is - zero, then inflate() is currently decoding information outside of a block. - If the upper value is -1 and the lower value is non-zero, then inflate is in - the middle of a stored block, with the lower value equaling the number of - bytes from the input remaining to copy. If the upper value is not -1, then - it is the number of bits back from the current bit position in the input of - the code (literal or length/distance pair) currently being processed. In - that case the lower value is the number of bytes already emitted for that - code. - - A code is being processed if inflate is waiting for more input to complete - decoding of the code, or if it has completed decoding but is waiting for - more output space to write the literal or match data. - - inflateMark() is used to mark locations in the input data for random - access, which may be at bit positions, and to note those cases where the - output of a code may span boundaries of random access blocks. The current - location in the input stream can be determined from avail_in and data_type - as noted in the description for the Z_BLOCK flush parameter for inflate. - - inflateMark returns the value noted above or -1 << 16 if the provided - source stream state was inconsistent. -*/ - -ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, - gz_headerp head)); -/* - inflateGetHeader() requests that gzip header information be stored in the - provided gz_header structure. inflateGetHeader() may be called after - inflateInit2() or inflateReset(), and before the first call of inflate(). - As inflate() processes the gzip stream, head->done is zero until the header - is completed, at which time head->done is set to one. If a zlib stream is - being decoded, then head->done is set to -1 to indicate that there will be - no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be - used to force inflate() to return immediately after header processing is - complete and before any actual data is decompressed. - - The text, time, xflags, and os fields are filled in with the gzip header - contents. hcrc is set to true if there is a header CRC. (The header CRC - was valid if done is set to one.) If extra is not Z_NULL, then extra_max - contains the maximum number of bytes to write to extra. Once done is true, - extra_len contains the actual extra field length, and extra contains the - extra field, or that field truncated if extra_max is less than extra_len. - If name is not Z_NULL, then up to name_max characters are written there, - terminated with a zero unless the length is greater than name_max. If - comment is not Z_NULL, then up to comm_max characters are written there, - terminated with a zero unless the length is greater than comm_max. When any - of extra, name, or comment are not Z_NULL and the respective field is not - present in the header, then that field is set to Z_NULL to signal its - absence. This allows the use of deflateSetHeader() with the returned - structure to duplicate the header. However if those fields are set to - allocated memory, then the application will need to save those pointers - elsewhere so that they can be eventually freed. - - If inflateGetHeader is not used, then the header information is simply - discarded. The header is always checked for validity, including the header - CRC if present. inflateReset() will reset the process to discard the header - information. The application would need to call inflateGetHeader() again to - retrieve the header from the next gzip stream. - - inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. -*/ - -/* -ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, - unsigned char FAR *window)); - - Initialize the internal stream state for decompression using inflateBack() - calls. The fields zalloc, zfree and opaque in strm must be initialized - before the call. If zalloc and zfree are Z_NULL, then the default library- - derived memory allocation routines are used. windowBits is the base two - logarithm of the window size, in the range 8..15. window is a caller - supplied buffer of that size. Except for special applications where it is - assured that deflate was used with small window sizes, windowBits must be 15 - and a 32K byte window must be supplied to be able to decompress general - deflate streams. - - See inflateBack() for the usage of these routines. - - inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of - the parameters are invalid, Z_MEM_ERROR if the internal state could not be - allocated, or Z_VERSION_ERROR if the version of the library does not match - the version of the header file. -*/ - -typedef unsigned (*in_func) OF((void FAR *, - z_const unsigned char FAR * FAR *)); -typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); - -ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, - in_func in, void FAR *in_desc, - out_func out, void FAR *out_desc)); -/* - inflateBack() does a raw inflate with a single call using a call-back - interface for input and output. This is potentially more efficient than - inflate() for file i/o applications, in that it avoids copying between the - output and the sliding window by simply making the window itself the output - buffer. inflate() can be faster on modern CPUs when used with large - buffers. inflateBack() trusts the application to not change the output - buffer passed by the output function, at least until inflateBack() returns. - - inflateBackInit() must be called first to allocate the internal state - and to initialize the state with the user-provided window buffer. - inflateBack() may then be used multiple times to inflate a complete, raw - deflate stream with each call. inflateBackEnd() is then called to free the - allocated state. - - A raw deflate stream is one with no zlib or gzip header or trailer. - This routine would normally be used in a utility that reads zip or gzip - files and writes out uncompressed files. The utility would decode the - header and process the trailer on its own, hence this routine expects only - the raw deflate stream to decompress. This is different from the normal - behavior of inflate(), which expects either a zlib or gzip header and - trailer around the deflate stream. - - inflateBack() uses two subroutines supplied by the caller that are then - called by inflateBack() for input and output. inflateBack() calls those - routines until it reads a complete deflate stream and writes out all of the - uncompressed data, or until it encounters an error. The function's - parameters and return types are defined above in the in_func and out_func - typedefs. inflateBack() will call in(in_desc, &buf) which should return the - number of bytes of provided input, and a pointer to that input in buf. If - there is no input available, in() must return zero--buf is ignored in that - case--and inflateBack() will return a buffer error. inflateBack() will call - out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() - should return zero on success, or non-zero on failure. If out() returns - non-zero, inflateBack() will return with an error. Neither in() nor out() - are permitted to change the contents of the window provided to - inflateBackInit(), which is also the buffer that out() uses to write from. - The length written by out() will be at most the window size. Any non-zero - amount of input may be provided by in(). - - For convenience, inflateBack() can be provided input on the first call by - setting strm->next_in and strm->avail_in. If that input is exhausted, then - in() will be called. Therefore strm->next_in must be initialized before - calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called - immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in - must also be initialized, and then if strm->avail_in is not zero, input will - initially be taken from strm->next_in[0 .. strm->avail_in - 1]. - - The in_desc and out_desc parameters of inflateBack() is passed as the - first parameter of in() and out() respectively when they are called. These - descriptors can be optionally used to pass any information that the caller- - supplied in() and out() functions need to do their job. - - On return, inflateBack() will set strm->next_in and strm->avail_in to - pass back any unused input that was provided by the last in() call. The - return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR - if in() or out() returned an error, Z_DATA_ERROR if there was a format error - in the deflate stream (in which case strm->msg is set to indicate the nature - of the error), or Z_STREAM_ERROR if the stream was not properly initialized. - In the case of Z_BUF_ERROR, an input or output error can be distinguished - using strm->next_in which will be Z_NULL only if in() returned an error. If - strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning - non-zero. (in() will always be called before out(), so strm->next_in is - assured to be defined if out() returns non-zero.) Note that inflateBack() - cannot return Z_OK. -*/ - -ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); -/* - All memory allocated by inflateBackInit() is freed. - - inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream - state was inconsistent. -*/ - -ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); -/* Return flags indicating compile-time options. - - Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: - 1.0: size of uInt - 3.2: size of uLong - 5.4: size of voidpf (pointer) - 7.6: size of z_off_t - - Compiler, assembler, and debug options: - 8: DEBUG - 9: ASMV or ASMINF -- use ASM code - 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention - 11: 0 (reserved) - - One-time table building (smaller code, but not thread-safe if true): - 12: BUILDFIXED -- build static block decoding tables when needed - 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed - 14,15: 0 (reserved) - - Library content (indicates missing functionality): - 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking - deflate code when not needed) - 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect - and decode gzip streams (to avoid linking crc code) - 18-19: 0 (reserved) - - Operation variations (changes in library functionality): - 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate - 21: FASTEST -- deflate algorithm with only one, lowest compression level - 22,23: 0 (reserved) - - The sprintf variant used by gzprintf (zero is best): - 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format - 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! - 26: 0 = returns value, 1 = void -- 1 means inferred string length returned - - Remainder: - 27-31: 0 (reserved) - */ - -#ifndef Z_SOLO - - /* utility functions */ - -/* - The following utility functions are implemented on top of the basic - stream-oriented functions. To simplify the interface, some default options - are assumed (compression level and memory usage, standard memory allocation - functions). The source code of these utility functions can be modified if - you need special options. -*/ - -ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); -/* - Compresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total size - of the destination buffer, which must be at least the value returned by - compressBound(sourceLen). Upon exit, destLen is the actual size of the - compressed buffer. - - compress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer. -*/ - -ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen, - int level)); -/* - Compresses the source buffer into the destination buffer. The level - parameter has the same meaning as in deflateInit. sourceLen is the byte - length of the source buffer. Upon entry, destLen is the total size of the - destination buffer, which must be at least the value returned by - compressBound(sourceLen). Upon exit, destLen is the actual size of the - compressed buffer. - - compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_BUF_ERROR if there was not enough room in the output buffer, - Z_STREAM_ERROR if the level parameter is invalid. -*/ - -ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); -/* - compressBound() returns an upper bound on the compressed size after - compress() or compress2() on sourceLen bytes. It would be used before a - compress() or compress2() call to allocate the destination buffer. -*/ - -ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); -/* - Decompresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total size - of the destination buffer, which must be large enough to hold the entire - uncompressed data. (The size of the uncompressed data must have been saved - previously by the compressor and transmitted to the decompressor by some - mechanism outside the scope of this compression library.) Upon exit, destLen - is the actual size of the uncompressed buffer. - - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In - the case where there is not enough room, uncompress() will fill the output - buffer with the uncompressed data up to that point. -*/ - - /* gzip file access functions */ - -/* - This library supports reading and writing files in gzip (.gz) format with - an interface similar to that of stdio, using the functions that start with - "gz". The gzip format is different from the zlib format. gzip is a gzip - wrapper, documented in RFC 1952, wrapped around a deflate stream. -*/ - -typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ - -/* -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); - - Opens a gzip (.gz) file for reading or writing. The mode parameter is as - in fopen ("rb" or "wb") but can also include a compression level ("wb9") or - a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only - compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' - for fixed code compression as in "wb9F". (See the description of - deflateInit2 for more information about the strategy parameter.) 'T' will - request transparent writing or appending with no compression and not using - the gzip format. - - "a" can be used instead of "w" to request that the gzip stream that will - be written be appended to the file. "+" will result in an error, since - reading and writing to the same gzip file is not supported. The addition of - "x" when writing will create the file exclusively, which fails if the file - already exists. On systems that support it, the addition of "e" when - reading or writing will set the flag to close the file on an execve() call. - - These functions, as well as gzip, will read and decode a sequence of gzip - streams in a file. The append function of gzopen() can be used to create - such a file. (Also see gzflush() for another way to do this.) When - appending, gzopen does not test whether the file begins with a gzip stream, - nor does it look for the end of the gzip streams to begin appending. gzopen - will simply append a gzip stream to the existing file. - - gzopen can be used to read a file which is not in gzip format; in this - case gzread will directly read from the file without decompression. When - reading, this will be detected automatically by looking for the magic two- - byte gzip header. - - gzopen returns NULL if the file could not be opened, if there was - insufficient memory to allocate the gzFile state, or if an invalid mode was - specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). - errno can be checked to determine if the reason gzopen failed was that the - file could not be opened. -*/ - -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); -/* - gzdopen associates a gzFile with the file descriptor fd. File descriptors - are obtained from calls like open, dup, creat, pipe or fileno (if the file - has been previously opened with fopen). The mode parameter is as in gzopen. - - The next call of gzclose on the returned gzFile will also close the file - descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor - fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, - mode);. The duplicated descriptor should be saved to avoid a leak, since - gzdopen does not close fd if it fails. If you are using fileno() to get the - file descriptor from a FILE *, then you will have to use dup() to avoid - double-close()ing the file descriptor. Both gzclose() and fclose() will - close the associated file descriptor, so they need to have different file - descriptors. - - gzdopen returns NULL if there was insufficient memory to allocate the - gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not - provided, or '+' was provided), or if fd is -1. The file descriptor is not - used until the next gz* read, write, seek, or close operation, so gzdopen - will not detect if fd is invalid (unless fd is -1). -*/ - -ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); -/* - Set the internal buffer size used by this library's functions. The - default buffer size is 8192 bytes. This function must be called after - gzopen() or gzdopen(), and before any other calls that read or write the - file. The buffer memory allocation is always deferred to the first read or - write. Two buffers are allocated, either both of the specified size when - writing, or one of the specified size and the other twice that size when - reading. A larger buffer size of, for example, 64K or 128K bytes will - noticeably increase the speed of decompression (reading). - - The new buffer size also affects the maximum length for gzprintf(). - - gzbuffer() returns 0 on success, or -1 on failure, such as being called - too late. -*/ - -ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); -/* - Dynamically update the compression level or strategy. See the description - of deflateInit2 for the meaning of these parameters. - - gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not - opened for writing. -*/ - -ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); -/* - Reads the given number of uncompressed bytes from the compressed file. If - the input file is not in gzip format, gzread copies the given number of - bytes into the buffer directly from the file. - - After reaching the end of a gzip stream in the input, gzread will continue - to read, looking for another gzip stream. Any number of gzip streams may be - concatenated in the input file, and will all be decompressed by gzread(). - If something other than a gzip stream is encountered after a gzip stream, - that remaining trailing garbage is ignored (and no error is returned). - - gzread can be used to read a gzip file that is being concurrently written. - Upon reaching the end of the input, gzread will return with the available - data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then - gzclearerr can be used to clear the end of file indicator in order to permit - gzread to be tried again. Z_OK indicates that a gzip stream was completed - on the last gzread. Z_BUF_ERROR indicates that the input file ended in the - middle of a gzip stream. Note that gzread does not return -1 in the event - of an incomplete gzip stream. This error is deferred until gzclose(), which - will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip - stream. Alternatively, gzerror can be used before gzclose to detect this - case. - - gzread returns the number of uncompressed bytes actually read, less than - len for end of file, or -1 for error. -*/ - -ZEXTERN int ZEXPORT gzwrite OF((gzFile file, - voidpc buf, unsigned len)); -/* - Writes the given number of uncompressed bytes into the compressed file. - gzwrite returns the number of uncompressed bytes written or 0 in case of - error. -*/ - -ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); -/* - Converts, formats, and writes the arguments to the compressed file under - control of the format string, as in fprintf. gzprintf returns the number of - uncompressed bytes actually written, or 0 in case of error. The number of - uncompressed bytes written is limited to 8191, or one less than the buffer - size given to gzbuffer(). The caller should assure that this limit is not - exceeded. If it is exceeded, then gzprintf() will return an error (0) with - nothing written. In this case, there may also be a buffer overflow with - unpredictable consequences, which is possible only if zlib was compiled with - the insecure functions sprintf() or vsprintf() because the secure snprintf() - or vsnprintf() functions were not available. This can be determined using - zlibCompileFlags(). -*/ - -ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); -/* - Writes the given null-terminated string to the compressed file, excluding - the terminating null character. - - gzputs returns the number of characters written, or -1 in case of error. -*/ - -ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); -/* - Reads bytes from the compressed file until len-1 characters are read, or a - newline character is read and transferred to buf, or an end-of-file - condition is encountered. If any characters are read or if len == 1, the - string is terminated with a null character. If no characters are read due - to an end-of-file or len < 1, then the buffer is left untouched. - - gzgets returns buf which is a null-terminated string, or it returns NULL - for end-of-file or in case of error. If there was an error, the contents at - buf are indeterminate. -*/ - -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); -/* - Writes c, converted to an unsigned char, into the compressed file. gzputc - returns the value that was written, or -1 in case of error. -*/ - -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); -/* - Reads one byte from the compressed file. gzgetc returns this byte or -1 - in case of end of file or error. This is implemented as a macro for speed. - As such, it does not do all of the checking the other functions do. I.e. - it does not check to see if file is NULL, nor whether the structure file - points to has been clobbered or not. -*/ - -ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); -/* - Push one character back onto the stream to be read as the first character - on the next read. At least one character of push-back is allowed. - gzungetc() returns the character pushed, or -1 on failure. gzungetc() will - fail if c is -1, and may fail if a character has been pushed but not read - yet. If gzungetc is used immediately after gzopen or gzdopen, at least the - output buffer size of pushed characters is allowed. (See gzbuffer above.) - The pushed character will be discarded if the stream is repositioned with - gzseek() or gzrewind(). -*/ - -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); -/* - Flushes all pending output into the compressed file. The parameter flush - is as in the deflate() function. The return value is the zlib error number - (see function gzerror below). gzflush is only permitted when writing. - - If the flush parameter is Z_FINISH, the remaining data is written and the - gzip stream is completed in the output. If gzwrite() is called again, a new - gzip stream will be started in the output. gzread() is able to read such - concatented gzip streams. - - gzflush should be called only when strictly necessary because it will - degrade compression if called too often. -*/ - -/* -ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, - z_off_t offset, int whence)); - - Sets the starting position for the next gzread or gzwrite on the given - compressed file. The offset represents a number of bytes in the - uncompressed data stream. The whence parameter is defined as in lseek(2); - the value SEEK_END is not supported. - - If the file is opened for reading, this function is emulated but can be - extremely slow. If the file is opened for writing, only forward seeks are - supported; gzseek then compresses a sequence of zeroes up to the new - starting position. - - gzseek returns the resulting offset location as measured in bytes from - the beginning of the uncompressed stream, or -1 in case of error, in - particular if the file is opened for writing and the new starting position - would be before the current position. -*/ - -ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); -/* - Rewinds the given file. This function is supported only for reading. - - gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) -*/ - -/* -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); - - Returns the starting position for the next gzread or gzwrite on the given - compressed file. This position represents a number of bytes in the - uncompressed data stream, and is zero when starting, even if appending or - reading a gzip stream from the middle of a file using gzdopen(). - - gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) -*/ - -/* -ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); - - Returns the current offset in the file being read or written. This offset - includes the count of bytes that precede the gzip stream, for example when - appending or when using gzdopen() for reading. When reading, the offset - does not include as yet unused buffered input. This information can be used - for a progress indicator. On error, gzoffset() returns -1. -*/ - -ZEXTERN int ZEXPORT gzeof OF((gzFile file)); -/* - Returns true (1) if the end-of-file indicator has been set while reading, - false (0) otherwise. Note that the end-of-file indicator is set only if the - read tried to go past the end of the input, but came up short. Therefore, - just like feof(), gzeof() may return false even if there is no more data to - read, in the event that the last read request was for the exact number of - bytes remaining in the input file. This will happen if the input file size - is an exact multiple of the buffer size. - - If gzeof() returns true, then the read functions will return no more data, - unless the end-of-file indicator is reset by gzclearerr() and the input file - has grown since the previous end of file was detected. -*/ - -ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); -/* - Returns true (1) if file is being copied directly while reading, or false - (0) if file is a gzip stream being decompressed. - - If the input file is empty, gzdirect() will return true, since the input - does not contain a gzip stream. - - If gzdirect() is used immediately after gzopen() or gzdopen() it will - cause buffers to be allocated to allow reading the file to determine if it - is a gzip file. Therefore if gzbuffer() is used, it should be called before - gzdirect(). - - When writing, gzdirect() returns true (1) if transparent writing was - requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: - gzdirect() is not needed when writing. Transparent writing must be - explicitly requested, so the application already knows the answer. When - linking statically, using gzdirect() will include all of the zlib code for - gzip file reading and decompression, which may not be desired.) -*/ - -ZEXTERN int ZEXPORT gzclose OF((gzFile file)); -/* - Flushes all pending output if necessary, closes the compressed file and - deallocates the (de)compression state. Note that once file is closed, you - cannot call gzerror with file, since its structures have been deallocated. - gzclose must not be called more than once on the same file, just as free - must not be called more than once on the same allocation. - - gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a - file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the - last read ended in the middle of a gzip stream, or Z_OK on success. -*/ - -ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); -ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); -/* - Same as gzclose(), but gzclose_r() is only for use when reading, and - gzclose_w() is only for use when writing or appending. The advantage to - using these instead of gzclose() is that they avoid linking in zlib - compression or decompression code that is not used when only reading or only - writing respectively. If gzclose() is used, then both compression and - decompression code will be included the application when linking to a static - zlib library. -*/ - -ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); -/* - Returns the error message for the last error which occurred on the given - compressed file. errnum is set to zlib error number. If an error occurred - in the file system and not in the compression library, errnum is set to - Z_ERRNO and the application may consult errno to get the exact error code. - - The application must not modify the returned string. Future calls to - this function may invalidate the previously returned string. If file is - closed, then the string previously returned by gzerror will no longer be - available. - - gzerror() should be used to distinguish errors from end-of-file for those - functions above that do not distinguish those cases in their return values. -*/ - -ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); -/* - Clears the error and end-of-file flags for file. This is analogous to the - clearerr() function in stdio. This is useful for continuing to read a gzip - file that is being written concurrently. -*/ - -#endif /* !Z_SOLO */ - - /* checksum functions */ - -/* - These functions are not related to compression but are exported - anyway because they might be useful in applications using the compression - library. -*/ - -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); -/* - Update a running Adler-32 checksum with the bytes buf[0..len-1] and - return the updated checksum. If buf is Z_NULL, this function returns the - required initial value for the checksum. - - An Adler-32 checksum is almost as reliable as a CRC32 but can be computed - much faster. - - Usage example: - - uLong adler = adler32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - adler = adler32(adler, buffer, length); - } - if (adler != original_adler) error(); -*/ - -/* -ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, - z_off_t len2)); - - Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 - and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for - each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of - seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note - that the z_off_t type (like off_t) is a signed integer. If len2 is - negative, the result has no meaning or utility. -*/ - -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); -/* - Update a running CRC-32 with the bytes buf[0..len-1] and return the - updated CRC-32. If buf is Z_NULL, this function returns the required - initial value for the crc. Pre- and post-conditioning (one's complement) is - performed within this function so it shouldn't be done by the application. - - Usage example: - - uLong crc = crc32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - crc = crc32(crc, buffer, length); - } - if (crc != original_crc) error(); -*/ - -/* -ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); - - Combine two CRC-32 check values into one. For two sequences of bytes, - seq1 and seq2 with lengths len1 and len2, CRC-32 check values were - calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 - check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and - len2. -*/ - - - /* various hacks, don't look :) */ - -/* deflateInit and inflateInit are macros to allow checking the zlib version - * and the compiler's view of z_stream: - */ -ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, - int windowBits, int memLevel, - int strategy, const char *version, - int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, - unsigned char FAR *window, - const char *version, - int stream_size)); -#define deflateInit(strm, level) \ - deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) -#define inflateInit(strm) \ - inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) -#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ - deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ - (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) -#define inflateInit2(strm, windowBits) \ - inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ - (int)sizeof(z_stream)) -#define inflateBackInit(strm, windowBits, window) \ - inflateBackInit_((strm), (windowBits), (window), \ - ZLIB_VERSION, (int)sizeof(z_stream)) - -#ifndef Z_SOLO - -/* gzgetc() macro and its supporting function and exposed data structure. Note - * that the real internal state is much larger than the exposed structure. - * This abbreviated structure exposes just enough for the gzgetc() macro. The - * user should not mess with these exposed elements, since their names or - * behavior could change in the future, perhaps even capriciously. They can - * only be used by the gzgetc() macro. You have been warned. - */ -struct gzFile_s { - unsigned have; - unsigned char *next; - z_off64_t pos; -}; -ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ -#ifdef Z_PREFIX_SET -# undef z_gzgetc -# define z_gzgetc(g) \ - ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) -#else -# define gzgetc(g) \ - ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) -#endif - -/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or - * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if - * both are true, the application gets the *64 functions, and the regular - * functions are changed to 64 bits) -- in case these are set on systems - * without large file support, _LFS64_LARGEFILE must also be true - */ -#ifdef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); - ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); -#endif - -#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) -# ifdef Z_PREFIX_SET -# define z_gzopen z_gzopen64 -# define z_gzseek z_gzseek64 -# define z_gztell z_gztell64 -# define z_gzoffset z_gzoffset64 -# define z_adler32_combine z_adler32_combine64 -# define z_crc32_combine z_crc32_combine64 -# else -# define gzopen gzopen64 -# define gzseek gzseek64 -# define gztell gztell64 -# define gzoffset gzoffset64 -# define adler32_combine adler32_combine64 -# define crc32_combine crc32_combine64 -# endif -# ifndef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); -# endif -#else - ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); -#endif - -#else /* Z_SOLO */ - - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); - -#endif /* !Z_SOLO */ - -/* hack for buggy compilers */ -#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) - struct internal_state {int dummy;}; -#endif - -/* undocumented functions */ -ZEXTERN const char * ZEXPORT zError OF((int)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); -ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); -ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); -ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); -ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); -#if defined(_WIN32) && !defined(Z_SOLO) -ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, - const char *mode)); -#endif -#if defined(STDC) || defined(Z_HAVE_STDARG_H) -# ifndef Z_SOLO -ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, - const char *format, - va_list va)); -# endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* ZLIB_H */ diff --git a/cdf36_3-dist/src/lib/zlib/zutil.c b/cdf36_3-dist/src/lib/zlib/zutil.c deleted file mode 100644 index 2526d43..0000000 --- a/cdf36_3-dist/src/lib/zlib/zutil.c +++ /dev/null @@ -1,326 +0,0 @@ -/* zutil.c -- target dependent utility functions for the compression library - * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id: zutil.c,v 1.1.1.1 2016/10/12 19:21:25 liu Exp $ */ - -#include "zutil.h" - -#ifndef Z_SOLO -# include "gzguts.h" -#endif - - -#ifndef NO_DUMMY_DECL -struct internal_state {int dummy;}; /* for buggy compilers */ -#endif - -z_const char * const z_errmsg[10] = { -"need dictionary", /* Z_NEED_DICT 2 */ -"stream end", /* Z_STREAM_END 1 */ -"", /* Z_OK 0 */ -"file error", /* Z_ERRNO (-1) */ -"stream error", /* Z_STREAM_ERROR (-2) */ -"data error", /* Z_DATA_ERROR (-3) */ -"insufficient memory", /* Z_MEM_ERROR (-4) */ -"buffer error", /* Z_BUF_ERROR (-5) */ -"incompatible version",/* Z_VERSION_ERROR (-6) */ -""}; - - -const char * ZEXPORT zlibVersion() -{ - return ZLIB_VERSION; -} - -uLong ZEXPORT zlibCompileFlags() -{ - uLong flags; - - flags = 0; - switch ((int)(sizeof(uInt))) { - case 2: break; - case 4: flags += 1; break; - case 8: flags += 2; break; - default: flags += 3; - } - switch ((int)(sizeof(uLong))) { - case 2: break; - case 4: flags += 1 << 2; break; - case 8: flags += 2 << 2; break; - default: flags += 3 << 2; - } - switch ((int)(sizeof(voidpf))) { - case 2: break; - case 4: flags += 1 << 4; break; - case 8: flags += 2 << 4; break; - default: flags += 3 << 4; - } - switch ((int)(sizeof(z_off_t))) { - case 2: break; - case 4: flags += 1 << 6; break; - case 8: flags += 2 << 6; break; - default: flags += 3 << 6; - } -#ifdef DEBUG - flags += 1 << 8; -#endif -#if defined(ASMV) || defined(ASMINF) - flags += 1 << 9; -#endif -#ifdef ZLIB_WINAPI - flags += 1 << 10; -#endif -#ifdef BUILDFIXED - flags += 1 << 12; -#endif -#ifdef DYNAMIC_CRC_TABLE - flags += 1 << 13; -#endif -#ifdef NO_GZCOMPRESS - flags += 1L << 16; -#endif -#ifdef NO_GZIP - flags += 1L << 17; -#endif -#ifdef PKZIP_BUG_WORKAROUND - flags += 1L << 20; -#endif -#ifdef FASTEST - flags += 1L << 21; -#endif -#if defined(STDC) || defined(Z_HAVE_STDARG_H) -# ifdef NO_vsnprintf - flags += 1L << 25; -# ifdef HAS_vsprintf_void - flags += 1L << 26; -# endif -# else -# ifdef HAS_vsnprintf_void - flags += 1L << 26; -# endif -# endif -#else - flags += 1L << 24; -# ifdef NO_snprintf - flags += 1L << 25; -# ifdef HAS_sprintf_void - flags += 1L << 26; -# endif -# else -# ifdef HAS_snprintf_void - flags += 1L << 26; -# endif -# endif -#endif - return flags; -} - -#ifdef DEBUG - -# ifndef verbose -# define verbose 0 -# endif -int ZLIB_INTERNAL z_verbose = verbose; - -void ZLIB_INTERNAL z_error (m) - char *m; -{ - fprintf(stderr, "%s\n", m); - exit(1); -} -#endif - -/* exported to allow conversion of error code to string for compress() and - * uncompress() - */ -const char * ZEXPORT zError(err) - int err; -{ - return ERR_MSG(err); -} - -#if defined(_WIN32_WCE) - /* The Microsoft C Run-Time Library for Windows CE doesn't have - * errno. We define it as a global variable to simplify porting. - * Its value is always 0 and should not be used. - */ - int errno = 0; -#endif - -#ifndef HAVE_MEMCPY - -void ZLIB_INTERNAL zmemcpy(dest, source, len) - Bytef* dest; - const Bytef* source; - uInt len; -{ - if (len == 0) return; - do { - *dest++ = *source++; /* ??? to be unrolled */ - } while (--len != 0); -} - -int ZLIB_INTERNAL zmemcmp(s1, s2, len) - const Bytef* s1; - const Bytef* s2; - uInt len; -{ - uInt j; - - for (j = 0; j < len; j++) { - if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; - } - return 0; -} - -void ZLIB_INTERNAL zmemzero(dest, len) - Bytef* dest; - uInt len; -{ - if (len == 0) return; - do { - *dest++ = 0; /* ??? to be unrolled */ - } while (--len != 0); -} -#endif - -#ifndef Z_SOLO - -#ifdef SYS16BIT - -#ifdef __TURBOC__ -/* Turbo C in 16-bit mode */ - -# define MY_ZCALLOC - -/* Turbo C malloc() does not allow dynamic allocation of 64K bytes - * and farmalloc(64K) returns a pointer with an offset of 8, so we - * must fix the pointer. Warning: the pointer must be put back to its - * original form in order to free it, use zcfree(). - */ - -#define MAX_PTR 10 -/* 10*64K = 640K */ - -local int next_ptr = 0; - -typedef struct ptr_table_s { - voidpf org_ptr; - voidpf new_ptr; -} ptr_table; - -local ptr_table table[MAX_PTR]; -/* This table is used to remember the original form of pointers - * to large buffers (64K). Such pointers are normalized with a zero offset. - * Since MSDOS is not a preemptive multitasking OS, this table is not - * protected from concurrent access. This hack doesn't work anyway on - * a protected system like OS/2. Use Microsoft C instead. - */ - -voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) -{ - voidpf buf = opaque; /* just to make some compilers happy */ - ulg bsize = (ulg)items*size; - - /* If we allocate less than 65520 bytes, we assume that farmalloc - * will return a usable pointer which doesn't have to be normalized. - */ - if (bsize < 65520L) { - buf = farmalloc(bsize); - if (*(ush*)&buf != 0) return buf; - } else { - buf = farmalloc(bsize + 16L); - } - if (buf == NULL || next_ptr >= MAX_PTR) return NULL; - table[next_ptr].org_ptr = buf; - - /* Normalize the pointer to seg:0 */ - *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; - *(ush*)&buf = 0; - table[next_ptr++].new_ptr = buf; - return buf; -} - -void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) -{ - int n; - if (*(ush*)&ptr != 0) { /* object < 64K */ - farfree(ptr); - return; - } - /* Find the original pointer */ - for (n = 0; n < next_ptr; n++) { - if (ptr != table[n].new_ptr) continue; - - farfree(table[n].org_ptr); - while (++n < next_ptr) { - table[n-1] = table[n]; - } - next_ptr--; - return; - } - ptr = opaque; /* just to make some compilers happy */ - Assert(0, "zcfree: ptr not found"); -} - -#endif /* __TURBOC__ */ - - -#ifdef M_I86 -/* Microsoft C in 16-bit mode */ - -# define MY_ZCALLOC - -#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) -# define _halloc halloc -# define _hfree hfree -#endif - -voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) -{ - if (opaque) opaque = 0; /* to make compiler happy */ - return _halloc((long)items, size); -} - -void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) -{ - if (opaque) opaque = 0; /* to make compiler happy */ - _hfree(ptr); -} - -#endif /* M_I86 */ - -#endif /* SYS16BIT */ - - -#ifndef MY_ZCALLOC /* Any system without a special alloc function */ - -#ifndef STDC -extern voidp malloc OF((uInt size)); -extern voidp calloc OF((uInt items, uInt size)); -extern void free OF((voidpf ptr)); -#endif - -voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) - voidpf opaque; - unsigned items; - unsigned size; -{ - if (opaque) items += size - size; /* make compiler happy */ - return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : - (voidpf)calloc(items, size); -} - -void ZLIB_INTERNAL zcfree (opaque, ptr) - voidpf opaque; - voidpf ptr; -{ - free(ptr); - if (opaque) return; /* make compiler happy */ -} - -#endif /* MY_ZCALLOC */ - -#endif /* !Z_SOLO */ diff --git a/cdf36_3-dist/src/lib/zlib/zutil.h b/cdf36_3-dist/src/lib/zlib/zutil.h deleted file mode 100644 index 2188133..0000000 --- a/cdf36_3-dist/src/lib/zlib/zutil.h +++ /dev/null @@ -1,253 +0,0 @@ -/* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-2013 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* @(#) $Id: zutil.h,v 1.1.1.1 2016/10/12 19:21:25 liu Exp $ */ - -#ifndef ZUTIL_H -#define ZUTIL_H - -#ifdef HAVE_HIDDEN -# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) -#else -# define ZLIB_INTERNAL -#endif - -#include "zlib.h" - -#if defined(STDC) && !defined(Z_SOLO) -# if !(defined(_WIN32_WCE) && defined(_MSC_VER)) -# include -# endif -# include -# include -#endif - -#ifdef Z_SOLO - typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */ -#endif - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - -typedef unsigned char uch; -typedef uch FAR uchf; -typedef unsigned short ush; -typedef ush FAR ushf; -typedef unsigned long ulg; - -extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ -/* (size given to avoid silly warnings with Visual C++) */ - -#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] - -#define ERR_RETURN(strm,err) \ - return (strm->msg = ERR_MSG(err), (err)) -/* To be used only when the state is known to be valid */ - - /* common constants */ - -#ifndef DEF_WBITS -# define DEF_WBITS MAX_WBITS -#endif -/* default windowBits for decompression. MAX_WBITS is for compression only */ - -#if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -#else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif -/* default memLevel */ - -#define STORED_BLOCK 0 -#define STATIC_TREES 1 -#define DYN_TREES 2 -/* The three kinds of block type */ - -#define MIN_MATCH 3 -#define MAX_MATCH 258 -/* The minimum and maximum match lengths */ - -#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ - - /* target dependencies */ - -#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) -# define OS_CODE 0x00 -# ifndef Z_SOLO -# if defined(__TURBOC__) || defined(__BORLANDC__) -# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) - /* Allow compilation with ANSI keywords only enabled */ - void _Cdecl farfree( void *block ); - void *_Cdecl farmalloc( unsigned long nbytes ); -# else -# include -# endif -# else /* MSC or DJGPP */ -# include -# endif -# endif -#endif - -#ifdef AMIGA -# define OS_CODE 0x01 -#endif - -#if defined(VAXC) || defined(VMS) -# define OS_CODE 0x02 -# define F_OPEN(name, mode) \ - fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") -#endif - -#if defined(ATARI) || defined(atarist) -# define OS_CODE 0x05 -#endif - -#ifdef OS2 -# define OS_CODE 0x06 -# if defined(M_I86) && !defined(Z_SOLO) -# include -# endif -#endif - -#if defined(MACOS) || defined(TARGET_OS_MAC) -# define OS_CODE 0x07 -# ifndef Z_SOLO -# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os -# include /* for fdopen */ -# else -# ifndef fdopen -# define fdopen(fd,mode) NULL /* No fdopen() */ -# endif -# endif -# endif -#endif - -#ifdef TOPS20 -# define OS_CODE 0x0a -#endif - -#ifdef WIN32 -# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ -# define OS_CODE 0x0b -# endif -#endif - -#ifdef __50SERIES /* Prime/PRIMOS */ -# define OS_CODE 0x0f -#endif - -#if defined(_BEOS_) || defined(RISCOS) -# define fdopen(fd,mode) NULL /* No fdopen() */ -#endif - -#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX -# if defined(_WIN32_WCE) -# define fdopen(fd,mode) NULL /* No fdopen() */ -# ifndef _PTRDIFF_T_DEFINED - typedef int ptrdiff_t; -# define _PTRDIFF_T_DEFINED -# endif -# else -# define fdopen(fd,type) _fdopen(fd,type) -# endif -#endif - -#if defined(__BORLANDC__) && !defined(MSDOS) - #pragma warn -8004 - #pragma warn -8008 - #pragma warn -8066 -#endif - -/* provide prototypes for these when building zlib without LFS */ -#if !defined(_WIN32) && \ - (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); -#endif - - /* common defaults */ - -#ifndef OS_CODE -# define OS_CODE 0x03 /* assume Unix */ -#endif - -#ifndef F_OPEN -# define F_OPEN(name, mode) fopen((name), (mode)) -#endif - - /* functions */ - -#if defined(pyr) || defined(Z_SOLO) -# define NO_MEMCPY -#endif -#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) - /* Use our own functions for small and medium model with MSC <= 5.0. - * You may have to use the same strategy for Borland C (untested). - * The __SC__ check is for Symantec. - */ -# define NO_MEMCPY -#endif -#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) -# define HAVE_MEMCPY -#endif -#ifdef HAVE_MEMCPY -# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ -# define zmemcpy _fmemcpy -# define zmemcmp _fmemcmp -# define zmemzero(dest, len) _fmemset(dest, 0, len) -# else -# define zmemcpy memcpy -# define zmemcmp memcmp -# define zmemzero(dest, len) memset(dest, 0, len) -# endif -#else - void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); - int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); - void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); -#endif - -/* Diagnostic functions */ -#ifdef DEBUG -# include - extern int ZLIB_INTERNAL z_verbose; - extern void ZLIB_INTERNAL z_error OF((char *m)); -# define Assert(cond,msg) {if(!(cond)) z_error(msg);} -# define Trace(x) {if (z_verbose>=0) fprintf x ;} -# define Tracev(x) {if (z_verbose>0) fprintf x ;} -# define Tracevv(x) {if (z_verbose>1) fprintf x ;} -# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} -# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} -#else -# define Assert(cond,msg) -# define Trace(x) -# define Tracev(x) -# define Tracevv(x) -# define Tracec(c,x) -# define Tracecv(c,x) -#endif - -#ifndef Z_SOLO - voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, - unsigned size)); - void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); -#endif - -#define ZALLOC(strm, items, size) \ - (*((strm)->zalloc))((strm)->opaque, (items), (size)) -#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) -#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} - -/* Reverse the bytes in a 32-bit value */ -#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ - (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) - -#endif /* ZUTIL_H */ diff --git a/cdf36_3-dist/src/tools/cdf2skt.c b/cdf36_3-dist/src/tools/cdf2skt.c deleted file mode 100644 index 35debf5..0000000 --- a/cdf36_3-dist/src/tools/cdf2skt.c +++ /dev/null @@ -1,1928 +0,0 @@ -/****************************************************************************** -* Copyright 1996-2014 United States Government as represented by the -* Administrator of the National Aeronautics and Space Administration. -* All Rights Reserved. -******************************************************************************/ -/****************************************************************************** -* -* NSSDC/CDF SkeletonTable. -* -* Version 1.4b, 18-Nov-97, Hughes STX. -* -* Modification history: -* -* V1.0 18-May-92, J Love Original version. -* V1.1 2-Sep-92, J Love CDF V2.3 (shareable/NeXT/zVar). -* V1.2 25-Jan-94, J Love CDF V2.4. -* V1.3 13-Dec-94, J Love CDF V2.5. -* V1.3a 10-Jan-95, J Love Uppercase file extensions on the Macintosh. -* V1.3b 28-Feb-95, J Love Pass `char' as `int'. -* V1.3c 6-Apr-95, J Love POSIX. -* V1.3d 9-May-95, J Love EPOCH styles. -* V1.3e 4-Aug-95, J Love CDFexport-related changes. -* V1.3f 19-Sep-95, J Love CHECKforABORTso. -* V1.3g 28-Sep-95, J Love Macintosh dialog filtering. Outline default -* button. -* V1.4 26-Aug-96, J Love CDF V2.6. -* V1.4a 24-Feb-97, J Love Removed RICE. Fixed `values' qualifier. -* V1.4b 18-Nov-97, J Love Windows NT/Visual C++. -* V1.5 13-Oct-06, M Liu Changed to allow upper and lower case CDF -* name to be used on win32. -* V3.3 10-Jan-09, M Liu Validate a file before it is used. -* V3.3a 20-Jul-09, M Liu Added validation for input parameters. -* V3.3b 04-Apr-11, M Liu Modified to handle TT2000 epoch. -* -******************************************************************************/ - -#include "cdf2skt.h" - -/****************************************************************************** -* Increased stack size for Borland C on IBM PC. -******************************************************************************/ - -#if defined(BORLANDC) -extern unsigned _stklen = BORLANDC_STACK_SIZE; -#endif - -/****************************************************************************** -* Global variables. -******************************************************************************/ - -Logical mLog; -FILE *SKTfp; -Logical useFormat; -Logical report[3]; -Logical displayStats; - -/****************************************************************************** -* Main. -******************************************************************************/ - -#if !defined(win32) || (defined(win32) && defined(ALONE)) -MAIN { - Logical success = TRUE; - strcpyX (pgmName, "SkeletonTable", MAX_PROGRAM_NAME_LEN); -#if defined(mac) - MacExecuteSO (CreateSkeletonTable, SkeletonTableQOPs); -#else - success = CreateSkeletonTable (argc, argv); -#endif -#if defined(DEBUG) - if (cdf_FreeMemory(NULL,FatalError) > 0) DisplayWarning ("Abandoned buffers."); -#else - cdf_FreeMemory (NULL, FatalError); -#endif - return BOO(success,EXIT_SUCCESS_,EXIT_FAILURE_); -} -#endif - -/****************************************************************************** -* CreateSkeletonTable. -******************************************************************************/ - -Logical CreateSkeletonTable (argC, argV) -int argC; -char *argV[]; -{ -CDFstatus status; CDFid id; -char CDFpath[DU_MAX_PATH_LEN+1], CDFpathX[DU_MAX_PATH_LEN+1]; -char CDFname[DU_MAX_NAME_LEN+1], dir[DU_MAX_DIR_LEN+1]; -char SKTpath[DU_MAX_PATH_LEN+1], SKTpathX[DU_MAX_PATH_LEN+1]; -char creationStamp[TIME_STAMP_LEN+1]; -int count, varValues; long zMode; Logical negToPosFp0, outToScreen; -long workingCache, stageCache, compressCache; -char *variables = NULL; -Logical qopError = FALSE; -QOP *qop; -static char *validQuals[] = { - "skeleton", "nonrv", "nrvfile", "nrvtable", "log", "nolog", "zmode", - "neg2posfp0", "noneg2posfp0", "format", "noformat", "report", "screen", - "noscreen", "cache", "values", "page", "nopage", "about", "statistics", - "nostatistics", NULL }; -static int optRequired[] = { - TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, - TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, 0 -}; -static char *reportTokens[] = { "errors", "warnings", "informationals" }; - -/****************************************************************************** -* Parse qualifiers/options/parameters (QOP). -******************************************************************************/ - -switch (argC) { - case 1: - PageOLH ("cdf2skt.olh", argV[0]); - return TRUE; - case 2: - if (strcmp(argV[1],"-java") == 0) { - pagingOn = FALSE; - PageOLH ("cdf2sktj.olh", argV[0]); - return TRUE; - } - default: - qop = Qop (argC, argV, validQuals, optRequired); - if (qop == NULL) return FALSE; - /************************************************************************** - * Check for `about' qualifier. - **************************************************************************/ - if (qop->qualEntered[ABOUTqual]) { - DisplayIdentification (pgmName); - cdf_FreeMemory (qop, FatalError); - return TRUE; - } - /************************************************************************** - * Get CDF pathname. - **************************************************************************/ - if (qop->Nparms < 1) { - DisplayError ("Missing parameter."); - qopError = TRUE; - } - else { - strcpyX (CDFpath, qop->parms[CDFPATHparm], DU_MAX_PATH_LEN); - ParsePath (CDFpath, dir, CDFname); - } - /************************************************************************** - * Check if a skeleton table pathname was specified. - **************************************************************************/ - if (qop->qualEntered[SKTqual]) { - if (!ValidateQual(qop->qualOpt[SKTqual], validQuals)) - strcpyX (SKTpath, qop->qualOpt[SKTqual], DU_MAX_PATH_LEN); - else { - DisplayError ("Invalid \"skeleton\" qualifier."); - qopError = TRUE; - } - } else { - if (EndsWithIgCase(CDFname, ".cdf")) - RemoveCDFFileExtension (CDFname, SKTpath); - else - strcpyX (SKTpath, CDFname, DU_MAX_PATH_LEN); - } - /************************************************************************** - * Check if which variable values should be displayed was specified. - **************************************************************************/ - count = 0; - if (qop->qualEntered[NONRVqual]) count++; - if (qop->qualEntered[NRVFILEqual]) count++; - if (qop->qualEntered[NRVTABLEqual]) count++; - if (qop->qualEntered[VALUESqual]) count++; - switch (count) { - case 0: - varValues = DEFAULTvaluesCDF2SKT; - break; - case 1: - if (qop->qualEntered[NONRVqual]) { - varValues = NOvalues; - break; - } - if (qop->qualEntered[NRVFILEqual]) { - DisplayWarning ("NRV files are no longer supported."); - varValues = NRVvalues; - break; - } - if (qop->qualEntered[NRVTABLEqual]) { - varValues = NRVvalues; - break; - } - if (qop->qualEntered[VALUESqual]) { - if (ValidateQual(qop->qualOpt[VALUESqual], validQuals)) { - DisplayError ("Invalid \"values\" qualifier."); - qopError = TRUE; - } else { - size_t len = strlen(qop->qualOpt[VALUESqual]); - if (strcmpIgCase(qop->qualOpt[VALUESqual],"none") == 1) - varValues = NOvalues; - else if (strcmpIgCase(qop->qualOpt[VALUESqual],"nrv") == 1) - varValues = NRVvalues; - else if (strcmpIgCase(qop->qualOpt[VALUESqual],"rv") == 1) - varValues = RVvalues; - else if (strcmpIgCase(qop->qualOpt[VALUESqual],"all") == 1) - varValues = ALLvalues; - else { - varValues = NAMEDvalues; - variables = cdf_AllocateMemory ((size_t)len + 1, FatalError); - strcpyX (variables, qop->qualOpt[VALUESqual], len); - } - } - } - break; - default: - DisplayError ("Specify only one variable values qualifier."); - qopError = TRUE; - } - /************************************************************************** - * Check for /ZMODE,-zmode qualifier. - **************************************************************************/ - if (qop->qualEntered[ZMODEqual]) { - switch (qop->qualOpt[ZMODEqual][0]) { - case '0': zMode = zMODEoff; break; - case '1': zMode = zMODEon1; break; - case '2': zMode = zMODEon2; break; - default: { - DisplayError ("Illegal zMode."); - qopError = TRUE; - } - } - } - else - zMode = DEFAULTzModeCDF2SKT; - /************************************************************************** - * Check for `report' qualifier. If absent, use defaults. - **************************************************************************/ - if (qop->qualEntered[REPORTqual]) { - if (!ParseOptionList(3,reportTokens,qop->qualOpt[REPORTqual],report)) { - DisplayError ("Illegal list of `report' options."); - qopError = TRUE; - } - } - else { - report[ERRORs] = REPORTerrorsDEFAULT; - report[WARNs] = REPORTwarningsDEFAULT; - report[INFOs] = REPORTinfosDEFAULT; - } - /*********************************************************************** - * Check for `cache' qualifier. - ***********************************************************************/ - if (qop->qualEntered[CACHEqual]) { - if (!ParseCacheSizes(qop->qualOpt[CACHEqual], - &workingCache,&stageCache,&compressCache)) { - DisplayError ("Illegal cache size/type."); - qopError = TRUE; - } - } - else { - workingCache = useDEFAULTcacheSIZE; - stageCache = useDEFAULTcacheSIZE; - compressCache = useDEFAULTcacheSIZE; - } - /************************************************************************** - * Check for `statistics', `log', `neg2posfp0', `screen', `page', and - * `format' qualifiers. - **************************************************************************/ - qopError = qopError | !TFqualifier (qop,&displayStats,STATSqual, - NOSTATSqual,DEFAULTstatsCDF2SKT, - "statistics"); - qopError = qopError | !TFqualifier(qop,&outToScreen,SCREENqual, - NOSCREENqual,DEFAULTscreenCDF2SKT, - "screen"); - qopError = qopError | !TFqualifier(qop,&pagingOn,PAGEqual,NOPAGEqual, - DEFAULTpageCDF2SKT,"page"); - qopError = qopError | !TFqualifier(qop,&mLog,LOGqual,NOLOGqual, - DEFAULTlogCDF2SKT,"log"); - qopError = qopError | !TFqualifier(qop,&negToPosFp0,NEG2POSqual, - NONEG2POSqual,DEFAULT_NEGtoPOSfp0, - "neg2posfp0"); - qopError = qopError | !TFqualifier(qop,&useFormat,FORMATqual,NOFORMATqual, - DEFAULTformatCDF2SKT,"format"); - /************************************************************************** - * Check for conflicting/missing qualifiers. - **************************************************************************/ - if (qop->qualEntered[SKTqual] && qop->qualEntered[SCREENqual]) { - DisplayError ("Conflicting qualifiers (`skeleton' and `screen')."); - qopError = TRUE; - } - if (!qop->qualEntered[SCREENqual] && qop->qualEntered[PAGEqual]) { - DisplayError ("Conflicting qualifiers (`noscreen' and `page')."); - qopError = TRUE; - } - /************************************************************************** - * Check for overridding qualifiers. - **************************************************************************/ - if (qop->qualEntered[SCREENqual]) mLog = FALSE; - /************************************************************************** - * Free QOP memory and check for an error. - **************************************************************************/ - cdf_FreeMemory (qop, FatalError); - if (qopError) return FALSE; - break; -} - -/* CDFsetValidate (VALIDATEFILEon); */ -/****************************************************************************** -* Create skeleton table. -******************************************************************************/ - -if (mLog) { - WriteOut (stdout, "Name of CDF: "); - WriteOut (stdout, CDFname); - WriteOut (stdout, "\n"); -} - -TimeStamp (creationStamp); - -if (outToScreen) - SKTfp = stdout; -else { - if (!EndsWithIgCase(SKTpath, ".skt")) - strcatX (SKTpath, ".skt", DU_MAX_PATH_LEN); - ExpandPath (SKTpath, SKTpathX); - -/****************************************************************************** -* Display information. -******************************************************************************/ - - WriteOut (stdout, "Making a skeleton table from \""); - WriteOut (stdout, CDFpath); - if (!EndsWithIgCase(CDFpath, ".cdf")) - WriteOut (stdout, ".cdf"); - WriteOut (stdout, "\" to \""); - WriteOut (stdout, SKTpath); - WriteOut (stdout, "\"...\n"); - - SKTfp = fopen (SKTpathX, "w"); - if (SKTfp == NULL) { - WriteOut (stdout, "Error creating skeleton table ("); - WriteOut (stdout, SKTpath); - WriteOut (stdout, ").\n"); - return FALSE; - } -} - -WriteOut (SKTfp, "! Skeleton table for the \""); -WriteOut (SKTfp, CDFname); -WriteOut (SKTfp, "\" CDF."); - -WriteOut (SKTfp, "\n! Generated: "); -WriteOut (SKTfp, creationStamp); - -/****************************************************************************** -* Open CDF. -******************************************************************************/ - -ExpandPath (CDFpath, CDFpathX); -status = CDFlib (OPEN_, CDF_, CDFpathX, &id, - SELECT_, CDF_READONLY_MODE_, READONLYon, - CDF_zMODE_, zMode, - CDF_NEGtoPOSfp0_MODE_, BOO(negToPosFp0, - NEGtoPOSfp0on, - NEGtoPOSfp0off), - CDF_CACHESIZE_, workingCache, - STAGE_CACHESIZE_, stageCache, - COMPRESS_CACHESIZE_, compressCache, - NULL_); -if (!StatusHandlerC2S(status)) return FALSE; - -/****************************************************************************** -* Write header section. -******************************************************************************/ - -CHECKforABORTso -if (mLog) WriteOut (stdout, "Printing Header Information...\n"); -if (!WriteHeader(CDFname, varValues, variables)) return FALSE; - -/****************************************************************************** -* Write global scope attributes section. -******************************************************************************/ - -if (mLog) WriteOut (stdout, "Printing Attribute Information...\n"); -if (!WriteGlobalAttr()) return FALSE; - -/****************************************************************************** -* Write variable scope attributes section. -******************************************************************************/ - -if (!WriteVarAttr()) return FALSE; - -/****************************************************************************** -* Write variables section. -******************************************************************************/ - -if (mLog) WriteOut (stdout, "Printing Variable Information...\n"); -if (!WriteVars(varValues,variables)) return FALSE; - -/****************************************************************************** -* End section. -******************************************************************************/ - -if (!WriteEnd()) return FALSE; - -/****************************************************************************** -* Clean up. -******************************************************************************/ - -WriteOut (SKTfp, "\n"); -if (SKTfp != stdout) fclose (SKTfp); - -if (displayStats) { - vSTATS vStatsDotCDF, vStatsStage, vStatsCompress; - status = CDFlib (CLOSE_, CDFwithSTATS_, &vStatsDotCDF, - &vStatsStage, - &vStatsCompress, - NULL_); - if (!StatusHandlerC2S(status)) return FALSE; - DisplayStatistics ("CDF", &vStatsDotCDF, &vStatsStage, &vStatsCompress); -} -else { - status = CDFlib (CLOSE_, CDF_, - NULL_); - if (!StatusHandlerC2S(status)) return FALSE; -} - -if (variables != NULL) cdf_FreeMemory (variables, FatalError); - -return TRUE; -} - - -/****************************************************************************** -* WriteHeader. -******************************************************************************/ - -Logical WriteHeader (CDFname, varValues, variables) -char *CDFname; -int varValues; -char *variables; -{ -CDFstatus status; -long encoding, majority, format; -long numDims; -long dimSizes[CDF_MAX_DIMS]; -long numVars, numZvars, maxRec; -long numVattrs, numGattrs; -int dimN; -long lastUpdated = -1L, version, release, increment; -char sizes[MAX_SIZES_LEN+1], subIncrement; -char text[MAX_TEXT_LEN+1], tempS[MAX_LINE_LEN+1]; -long compress, compParms[CDF_MAX_DIMS], compPct, checkSum; - -status = CDFlib (GET_, CDF_VERSION_, &version, - CDF_RELEASE_, &release, - CDF_INCREMENT_, &increment, - NULL_); -if (!StatusHandlerC2S(status)) return FALSE; - -if (version > 2) { - status = CDFlib (GET_, CDF_LEAPSECONDLASTUPDATED_, &lastUpdated, - NULL_); - if (!StatusHandlerC2S(status)) return FALSE; -} - -WriteOutFP (SKTfp, "\n! CDF created/modified by CDF V%ld.%ld.%ld", - version, release, increment); - -status = CDFlib (GET_, LIB_VERSION_, &version, - LIB_RELEASE_, &release, - LIB_INCREMENT_, &increment, - LIB_subINCREMENT_, &subIncrement, - NULL_); -if (!StatusHandlerC2S(status)) return FALSE; - -if (subIncrement != ' ') - WriteOutFP (SKTfp, "\n! Skeleton table created by CDF V%ld.%ld.%ld_%c", - version, release, increment, subIncrement); -else - WriteOutFP (SKTfp, "\n! Skeleton table created by CDF V%ld.%ld.%ld", - version, release, increment); - -WriteOut (SKTfp, "\n"); -WriteOut (SKTfp, "\n#header"); - -status = CDFlib (GET_, CDF_ENCODING_, &encoding, - CDF_MAJORITY_, &majority, - CDF_FORMAT_, &format, - rVARs_NUMDIMS_, &numDims, - rVARs_DIMSIZES_, dimSizes, - CDF_NUMrVARS_, &numVars, - CDF_NUMzVARS_, &numZvars, - CDF_NUMgATTRS_, &numGattrs, - CDF_NUMvATTRS_, &numVattrs, - rVARs_MAXREC_, &maxRec, - NULL_); -if (!StatusHandlerC2S(status)) return FALSE; - -WriteOut (SKTfp, "\n"); -WriteOut (SKTfp, "\n CDF NAME: "); -WriteOut (SKTfp, CDFname); - -WriteOut (SKTfp, "\n DATA ENCODING: "); -WriteOut (SKTfp, EncodingToken(encoding)); - -WriteOut (SKTfp, "\n MAJORITY: "); -WriteOut (SKTfp, MajorityToken(majority)); - -WriteOut (SKTfp, "\n FORMAT: "); -WriteOut (SKTfp, FormatToken(format)); - -if (numDims > 0) { - sizes[0] = NUL; - for (dimN = 0; dimN < numDims; dimN++) { - snprintf (&sizes[strlen(sizes)], (size_t) sizeof(sizes)-strlen(sizes), - "%ld ", dimSizes[dimN]); - } - sizes[strlen(sizes)-1] = NUL; /* Wipe out trailing blank. */ -} -else - strcpyX (sizes, "", MAX_SIZES_LEN); - -WriteOut (SKTfp, "\n"); -WriteOut (SKTfp, - "\n! Variables G.Attributes V.Attributes Records Dims "); - -Ncharacters (SKTfp, FRONTpadLABEL("Sizes",sizes), (int) ' '); -WriteOut (SKTfp, "Sizes"); - -WriteOut (SKTfp, - "\n! --------- ------------ ------------ ------- ---- "); - -Ncharacters (SKTfp, MaxInt((int)strlen("Sizes"),(int)strlen(sizes)), (int)'-'); - -WriteOut (SKTfp, "\n"); -Ncharacters (SKTfp, 2, (int) ' '); -snprintf (text, (size_t) sizeof(text), "%ld/%ld", numVars, numZvars); -Ncharacters (SKTfp, MaxInt((int)(6 - strlen(text)),0), (int) ' '); -snprintf (tempS, (size_t) sizeof(tempS), - "%s %7ld %7ld %5ld/z %3ld", - text, numGattrs, numVattrs, maxRec + 1, numDims); -WriteOut (SKTfp, tempS); - -if (numDims > 0) { - WriteOut (SKTfp, " "); - Ncharacters (SKTfp, FRONTpadVALUE("Sizes",sizes), (int) ' '); - WriteOut (SKTfp, sizes); -} - -status = CDFlib (GET_, CDF_COMPRESSION_, &compress, compParms, &compPct, - NULL_); -if (!StatusHandlerC2S(status)) return FALSE; - -/* -if (compress != NO_COMPRESSION || compress != NO_CHECKSUM) - WriteOutFP (SKTfp, "\n"); -*/ - -/* if (compress != NO_COMPRESSION) */ - WriteOutFP (SKTfp, "\n! CDF_COMPRESSION: %s", - CompressionToken(compress, compParms)); - WriteOutFP (SKTfp, "\n! (Valid compression: None, GZIP.1-9, RLE.0, HUFF.0, AHUFF.0)"); - -status = CDFlib (GET_, CDF_CHECKSUM_, &checkSum, - NULL_); -if (!StatusHandlerC2S(status)) return FALSE; - -/* if (checkSum != NO_CHECKSUM) */ -WriteOutFP (SKTfp, "\n! CDF_CHECKSUM: %s", ChecksumToken(checkSum)); -WriteOutFP (SKTfp, "\n! (Valid checksum: None, MD5)"); - -if (!PriorTo ("3.5.0", version, release, increment)) { - if (lastUpdated > -1 || WriteTT2000VarData(varValues, variables)) { - if (lastUpdated > -1) - WriteOutFP (SKTfp, "\n! CDF_LEAPSECONDLASTUPDATED: %ld", lastUpdated); - else { - long year, month, day; -#if defined(vms) - CDFgetLastDateinLeapSecondsTBL (&year, &month, &day); -#else - CDFgetLastDateinLeapSecondsTable (&year, &month, &day); -#endif - WriteOutFP (SKTfp, "\n! CDF_LEAPSECONDLASTUPDATED: %ld", 10000*year+ - 100*month+day); - } - } -} -return TRUE; -} - - -/****************************************************************************** -* WriteGlobalAttr. -******************************************************************************/ - -Logical WriteGlobalAttr () -{ -CDFstatus status; -char delim; /* Delimeter for attribute name. */ -long attrN, numAttrs, scope, maxEntry; -long dataType, numElements, entryN; -int ccc; /* Current Cursor Column (base is 0). */ -void *value; -char attrName[CDF_ATTR_NAME_LEN256+1], - tempS[MAX_LINE_LEN+1]; -int GattrCount = 0; /* Number of global scope attributes. */ -int entryCount; - -WriteOut (SKTfp, "\n\n"); -WriteOut (SKTfp, "\n#GLOBALattributes"); - -status = CDFlib (GET_, CDF_NUMATTRS_, &numAttrs, - NULL_); -if (!StatusHandlerC2S(status)) return FALSE; - -if (numAttrs > 0) { - for (attrN = 0; attrN < numAttrs; attrN++) { - status = CDFlib (SELECT_, ATTR_, attrN, - GET_, ATTR_NAME_, attrName, - ATTR_SCOPE_, &scope, - NULL_); - if (!StatusHandlerC2S(status)) return FALSE; - if (scope == GLOBAL_SCOPE) { - /*********************************************************************** - * Global scope attribute... - ***********************************************************************/ - GattrCount++; - - status = CDFlib (GET_, ATTR_MAXgENTRY_, &maxEntry, - NULL_); - if (!StatusHandlerC2S(status)) return FALSE; - - /*********************************************************************** - * If first global scope attribute found, print field headings. - ***********************************************************************/ - - if (GattrCount == 1) { - WriteOut (SKTfp, "\n\n"); - ccc = WriteOut (SKTfp, "! Attribute"); - Ncharacters (SKTfp, ENTRY_NUM_COL - ccc, (int) ' '); - ccc += ENTRY_NUM_COL - ccc; - ccc += WriteOut (SKTfp, "Entry Data"); - - WriteOut (SKTfp, "\n"); - ccc = WriteOut (SKTfp, "! Name "); - Ncharacters (SKTfp, ENTRY_NUM_COL - ccc, (int) ' '); - ccc += ENTRY_NUM_COL - ccc; - ccc += WriteOut (SKTfp, "Number Type Value"); - - WriteOut (SKTfp, "\n"); - ccc = WriteOut (SKTfp, "! ---------"); - Ncharacters (SKTfp, ENTRY_NUM_COL - ccc, (int) ' '); - ccc += ENTRY_NUM_COL - ccc; - ccc += WriteOut (SKTfp, "------ ---- -----"); - } - - /*********************************************************************** - * Write name. - ***********************************************************************/ - - delim = PickDelimiter (attrName, strlen(attrName)); - WriteOut (SKTfp, "\n\n"); - snprintf (tempS, (size_t) sizeof(tempS), - " %c%s%c", delim, attrName, delim); - ccc = WriteOut (SKTfp, tempS); - - /*********************************************************************** - * Write each entry. - ***********************************************************************/ - - entryCount = 0; - - for (entryN = 0; entryN <= maxEntry; entryN++) { - status = CDFlib (SELECT_, gENTRY_, entryN, - GET_, gENTRY_DATATYPE_, &dataType, - gENTRY_NUMELEMS_, &numElements, - NULL_); - if (status != NO_SUCH_ENTRY) { - if (!StatusHandlerC2S(status)) return FALSE; - entryCount++; - - value = cdf_AllocateMemory ((size_t) (CDFelemSize(dataType) * - numElements), FatalError); - - status = CDFlib (GET_, gENTRY_DATA_, value, - NULL_); - if (!StatusHandlerC2S(status)) return FALSE; - - if (entryCount == 1) { - if (ccc > ENTRY_NUM_COL - 1) { - WriteOut (SKTfp, "\n"); - ccc = 0; - } - } - else { - WriteOut (SKTfp, "\n"); - ccc = 0; - } - - Ncharacters (SKTfp, ENTRY_NUM_COL - ccc, (int) ' '); - ccc += ENTRY_NUM_COL - ccc; - - snprintf (tempS, (size_t) sizeof(tempS), - "%*ld: %s ", ENTRY_NUM_WIDTH, entryN + 1, - DataTypePaddedString(dataType)); - ccc += WriteOut (SKTfp, tempS); - - if (STRINGdataType (dataType)) { /* not allow LF and CR */ - int ii; - for (ii = 0; ii < (int) numElements; ++ii) { - if (((int)*(((char *)value)+ii) == (int) '\n') || - ((int)*(((char *)value)+ii) == (int) '\r')) - memcpy (((char *)value)+ii, " ", 1); - } - } - - ccc += WriteOut (SKTfp, "{ "); - WriteEntryValue (SKTfp, dataType, numElements, value, ccc, - MAX_COL_TO_USE - 4); - /* -4 for possible " } ." */ - ccc += WriteOut (SKTfp, " }"); - - cdf_FreeMemory (value, FatalError); - } - CHECKforABORTso - } - /*********************************************************************** - * Write '.' after last entry. - ***********************************************************************/ - WriteOut (SKTfp, " ."); - if (!ISTPname(attrName)) { - WriteOut (SKTfp, "\n"); - WriteOutFP (SKTfp, - "! Warning: \"%s\": Not ISTP compliant... not recommended", - attrName); - } - } - CHECKforABORTso - } - if (GattrCount == 0) WriteOut (SKTfp, "\n\n! No global scope attributes."); -} -else - WriteOut (SKTfp, "\n\n! No global scope attributes."); - -return TRUE; -} - - -/****************************************************************************** -* WriteVarAttr. -******************************************************************************/ - -Logical WriteVarAttr () -{ -CDFstatus status; -char delim, /* Delimeter for attribute name. */ - tempS[MAX_LINE_LEN+1]; -long attrN, numAttrs, scope; -char attrName[CDF_ATTR_NAME_LEN256+1]; -int VattrCount = 0; /* Number of variable scope attributes. */ - -WriteOut (SKTfp, "\n\n"); -WriteOut (SKTfp, "\n#VARIABLEattributes"); -WriteOut (SKTfp, "\n"); - -status = CDFlib (GET_, CDF_NUMATTRS_, &numAttrs, - NULL_); -if (!StatusHandlerC2S(status)) return FALSE; - -if (numAttrs > 0) { - for (attrN = 0; attrN < numAttrs; attrN++) { - status = CDFlib (SELECT_, ATTR_, attrN, - GET_, ATTR_NAME_, attrName, - ATTR_SCOPE_, &scope, - NULL_); - if (!StatusHandlerC2S(status)) return FALSE; - if (scope == VARIABLE_SCOPE) { - /*********************************************************************** - * Variable scope attribute... - ***********************************************************************/ - VattrCount++; - delim = PickDelimiter (attrName, strlen(attrName)); - snprintf (tempS, (size_t) sizeof(tempS), - "\n %c%s%c", delim, attrName, delim); - WriteOut (SKTfp, tempS); - if (!ISTPname(attrName)) { - WriteOut (SKTfp, "\n"); - WriteOutFP (SKTfp, - "! Warning: \"%s\": Not ISTP compliant... not recommended", - attrName); - } - } - CHECKforABORTso - } - if (VattrCount == 0) WriteOut (SKTfp, "\n! No variable scope attributes."); -} -else - WriteOut (SKTfp, "\n! No variable scope attributes."); - -return TRUE; -} - - -/****************************************************************************** -* WriteVars. -******************************************************************************/ - -Logical WriteVars (varValues, variables) -int varValues; -char *variables; -{ -CDFstatus status; -long numVars; -long numZvars; -long varN; - -status = CDFlib (GET_, CDF_NUMrVARS_, &numVars, - CDF_NUMzVARS_, &numZvars, - NULL_); -if (!StatusHandlerC2S(status)) return FALSE; - -WriteOut (SKTfp, "\n\n"); -WriteOut (SKTfp, "\n#variables"); - -if (numVars == 0) - WriteOut (SKTfp, "\n\n! No rVariables."); -else - for (varN = 0; varN < numVars; varN++) { - if (!WriteVar(varN,varValues,variables,FALSE)) return FALSE; - } - -WriteOut (SKTfp, "\n\n"); -WriteOut (SKTfp, "\n#zVariables"); - -if (numZvars == 0) - WriteOut (SKTfp, "\n\n! No zVariables."); -else - for (varN = 0; varN < numZvars; varN++) { - if (!WriteVar(varN,varValues,variables,TRUE)) return FALSE; - } - -return TRUE; -} - -/****************************************************************************** -* WriteVar. -******************************************************************************/ - -Logical WriteVar (varN, varValues, variables, zVar) -long varN; -int varValues; -char *variables; -Logical zVar; -{ -CDFstatus status; -long numDims, dimSizes[CDF_MAX_DIMS]; -long numAttrs; -long maxRec; -long varDataType, varNumElements; -long entryDataType, entryNumElements; -long recVary, dimVarys[CDF_MAX_DIMS]; -char varName[CDF_VAR_NAME_LEN256+1]; -char attrName[CDF_ATTR_NAME_LEN256+1]; -char delim; -long attrN; -long scope; -int dimN; -int ccc; /* Current Cursor Column (base is 0). */ -int ddd; -void *value; -int VattrCount; -char varys[MAX_VARYS_LEN+1]; -char sizes[MAX_SIZES_LEN+1]; -char tempS[MAX_LINE_LEN+1]; -long cType, cParms[CDF_MAX_DIMS], cPct, sparse, bf; -void *pad = NULL; -int padValue; -long sarray[CDF_MAX_PARMS]; - -sarray[0] = 0; -status = CDFlib (SELECT_, VAR(zVar), varN, - GET_, VAR_NAME(zVar), varName, - VAR_DATATYPE(zVar), &varDataType, - VAR_NUMELEMS(zVar), &varNumElements, - VAR_RECVARY(zVar), &recVary, - VAR_DIMVARYS(zVar), dimVarys, - VAR_MAXREC(zVar), &maxRec, - VAR_COMPRESSION(zVar), &cType, cParms, &cPct, - VAR_SPARSERECORDS(zVar), &sparse, - VAR_BLOCKINGFACTOR(zVar), &bf, - NULL_); -if (!StatusHandlerC2S(status)) return FALSE; - -if (zVar) - status = CDFlib (SELECT_, zVAR_, varN, - GET_, zVAR_NUMDIMS_, &numDims, - zVAR_DIMSIZES_, dimSizes, - NULL_); -else - status = CDFlib (GET_, rVARs_NUMDIMS_, &numDims, - rVARs_DIMSIZES_, dimSizes, - NULL_); -if (!StatusHandlerC2S(status)) return FALSE; - -pad = cdf_AllocateMemory ((size_t) ((varNumElements + - (STRINGdataType(varDataType)? 1 : 0)) * - CDFelemSize(varDataType)), - FatalError); -status = CDFlib (GET_, VAR_PADVALUE(zVar), pad, - NULL_); -if (!StatusHandlerC2S(status)) return FALSE; -if (status != NO_PADVALUE_SPECIFIED) - padValue = 1; -else - padValue = 0; - -/*************************************************************************** -* If zVariable, build dimension sizes string. -***************************************************************************/ - -if (numDims > 0) { - sizes[0] = NUL; - for (dimN = 0; dimN < numDims; dimN++) { - snprintf (&sizes[strlen(sizes)], (size_t) sizeof(sizes)-strlen(sizes), - "%ld ", dimSizes[dimN]); - } - sizes[strlen(sizes)-1] = NUL; /* Wipe out trailing blank. */ -} -else - strcpyX (sizes, "", MAX_SIZES_LEN); - -/*************************************************************************** -* Build dimension variance string. -***************************************************************************/ - -if (numDims > 0) { - strcpyX (varys, "", MAX_VARYS_LEN); - for (dimN = 0; dimN < numDims; dimN++) { - strcatX (varys, TFvarianceToken(dimVarys[dimN]), MAX_VARYS_LEN); - strcatX (varys, " ", MAX_VARYS_LEN); - } - varys[strlen(varys)-1] = NUL; /* Wipe out trailing blank. */ -} -else - strcpyX (varys, "", MAX_VARYS_LEN); - -/*************************************************************************** -* Write headings. -***************************************************************************/ - -if (varN != 0) WriteOut (SKTfp, "\n"); /* Skip 2 lines after first - variable. */ -WriteOut (SKTfp, "\n\n"); -ccc = WriteOut (SKTfp, "! Variable"); -Ncharacters (SKTfp, VAR_DATATYPE_COL - ccc, (int) ' '); -WriteOut (SKTfp, " Data Number "); - -if (zVar) { - Ncharacters (SKTfp, 4, (int) ' '); - Ncharacters (SKTfp, 2, (int) ' '); - Ncharacters (SKTfp, MaxInt((int)strlen(sizes), - (int)strlen("Sizes")), (int) ' '); - Ncharacters (SKTfp, 2, (int) ' '); -} - -WriteOut (SKTfp, " Record "); -Ncharacters (SKTfp, FRONTpadLABEL("Dimension",varys), (int) ' '); -WriteOut (SKTfp, "Dimension"); - -WriteOut (SKTfp, "\n"); -ccc = WriteOut (SKTfp, "! Name "); -Ncharacters (SKTfp, VAR_DATATYPE_COL - ccc, (int) ' '); -WriteOut (SKTfp, " Type Elements "); - -if (zVar) { - WriteOut (SKTfp, "Dims"); - Ncharacters (SKTfp, 2, (int) ' '); - Ncharacters (SKTfp, FRONTpadLABEL("Sizes",sizes), (int) ' '); - WriteOut (SKTfp, "Sizes"); - Ncharacters (SKTfp, BACKpadLABEL("Sizes",sizes), (int) ' '); - Ncharacters (SKTfp, 2, (int) ' '); -} - -WriteOut (SKTfp, "Variance "); - -Ncharacters (SKTfp, FRONTpadLABEL("Variances",varys), (int) ' '); -WriteOut (SKTfp, "Variances"); - -WriteOut (SKTfp, "\n"); -ccc = WriteOut (SKTfp, "! --------"); -Ncharacters (SKTfp, VAR_DATATYPE_COL - ccc, (int) ' '); -WriteOut (SKTfp, " ---- -------- "); - -if (zVar) { - Ncharacters (SKTfp, 4, (int) '-'); - Ncharacters (SKTfp, 2, (int) ' '); - Ncharacters (SKTfp, MaxInt((int)strlen("Sizes"), - (int)strlen(sizes)), (int) '-'); - Ncharacters (SKTfp, 2, (int) ' '); -} - -WriteOut (SKTfp, "-------- "); - -Ncharacters (SKTfp, MaxInt((int)strlen("Variances"), - (int)strlen(varys)), (int) '-'); - -/*************************************************************************** -* Write variable definition line. -***************************************************************************/ - -WriteOut (SKTfp, "\n"); - -delim = PickDelimiter (varName, strlen(varName)); -WriteOut (SKTfp, "\n"); -snprintf (tempS, (size_t) sizeof(tempS), " %c%s%c", delim, varName, delim); -ccc = WriteOut (SKTfp, tempS); - -if (varDataType != CDF_TIME_TT2000) ddd = 0; -else ddd = 4; - -if (ccc > (VAR_DATATYPE_COL - 3 - ddd)) { - WriteOut (SKTfp, "\n"); - ccc = 0; -} - -Ncharacters (SKTfp, VAR_DATATYPE_COL - ccc - ddd, (int) ' '); - -snprintf (tempS, (size_t) sizeof(tempS), - "%s %*ld ", DataTypePaddedString(varDataType), - VAR_NUMELEMS_WIDTH, varNumElements); -WriteOut (SKTfp, tempS); - -Ncharacters (SKTfp, 2, (int) ' '); - -if (zVar) { - snprintf (tempS, (size_t) sizeof(tempS), - " %*ld ", zVAR_NUMDIMS_WIDTH, numDims); - WriteOut (SKTfp, tempS); - Ncharacters (SKTfp, 2, (int) ' '); - Ncharacters (SKTfp, FRONTpadVALUE("Sizes",sizes), (int) ' '); - WriteOut (SKTfp, sizes); - Ncharacters (SKTfp, BACKpadVALUE("Sizes",sizes), (int) ' '); - Ncharacters (SKTfp, 2, (int) ' '); -} - -WriteOut (SKTfp, " "); -WriteOut (SKTfp, TFvarianceToken(recVary)); - -if (numDims > 0) { - Ncharacters (SKTfp, 3, (int) ' '); - Ncharacters (SKTfp, 2, (int) ' '); - Ncharacters (SKTfp, FRONTpadVALUE("Variances",varys), (int) ' '); - WriteOut (SKTfp, varys); -} - -WriteOutFP (SKTfp, "\n"); - -if (!ISTPname(varName)) { - WriteOutFP (SKTfp, "! Warning: \"%s\": Not ISTP compliant... not recommended", - varName); -} - -/* if (cType != NO_COMPRESSION) */ - WriteOutFP (SKTfp, "\n ! VAR_COMPRESSION: %s", - CompressionToken(cType, cParms)); - WriteOutFP (SKTfp, "\n ! (Valid compression: None, GZIP.1-9, RLE.0, HUFF.0, AHUFF.0)"); - -/* if (recVary == VARY) { */ - WriteOutFP (SKTfp, "\n ! VAR_SPARSERECORDS: %s", - SparsenessToken(sparse, NO_SPARSEARRAYS, sarray)); - WriteOutFP (SKTfp, "\n ! (Valid sparserecords: None, sRecords.PAD, sRecords.PREV)"); -/* } */ - -if (bf != 0) { - WriteOutFP (SKTfp, "\n ! VAR_BLOCKINGFACTOR: %ld", bf); -} - -if (STRINGdataType(varDataType)) { - int ix, iy; - if (padValue == 0) { /* Only output a single blank */ - *(((char *) pad)+0) = (char) DEFAULT_CHAR_PADVALUE; - *(((char *) pad)+1) = (char) '\0'; - } else { - long numBytes = (long) UTF8StrLength ((unsigned char *)pad); - iy = -1; - if (numBytes == varNumElements) { - for (ix = 0; ix < (int) varNumElements; ++ix) - if (!Printable(*(((char *) pad)+ix))) *(((char *) pad)+ix) = '.'; - } - for (ix = (varNumElements-1); ix >= 0; --ix) { - if (*(((char *) pad)+ix) != ' ') { - iy = ix; - break; - } - } - if (iy == -1) /* All blanks... output a single blank */ - *(((char *) pad)+1) = (char) '\0'; - else - *(((char *) pad)+iy+1) = (char) '\0'; - } - if (strchr(pad, '"') == NULL) - WriteOutFP (SKTfp, "\n ! VAR_PADVALUE: \"%s\"", pad); - else if (strchr(pad, '\'') == NULL) - WriteOutFP (SKTfp, "\n ! VAR_PADVALUE: '%s'", pad); - else - WriteOutFP (SKTfp, "\n ! VAR_PADVALUE: $%s$", pad); -} else { - char string[101], *format; - int style; - if (TT2000dataType(varDataType)) style = TT2000_3_STYLE; - else style = EPOCH0_STYLE; - status = GetFormatEntry (zVar, varN, &format); - if (padValue == 1 && useFormat && format != NULL) - EncodeValue (varDataType, pad, string, style, 100); - else - EncodeValue (varDataType, pad, string, style, 100); - WriteOutFP (SKTfp, "\n ! VAR_PADVALUE: %s", string); - if (format != NULL) cdf_FreeMemory (format, FatalError); -} -cdf_FreeMemory (pad, FatalError); - -CHECKforABORTso - -/*************************************************************************** -* Write corresponding attribute entries. -***************************************************************************/ - -status = CDFlib (GET_, CDF_NUMATTRS_, &numAttrs, - NULL_); -if (!StatusHandlerC2S(status)) return FALSE; - -VattrCount = 0; - -WriteOut (SKTfp, "\n"); - -for (attrN = 0; attrN < numAttrs; attrN++) { - status = CDFlib (SELECT_, ATTR_, attrN, - GET_, ATTR_SCOPE_, &scope, - ATTR_NAME_, attrName, - NULL_); - if (!StatusHandlerC2S(status)) return FALSE; - - if (scope == VARIABLE_SCOPE) { - status = CDFlib (SELECT_, BOO(zVar,zENTRY_,rENTRY_), varN, - GET_, BOO(zVar,zENTRY_DATATYPE_, - rENTRY_DATATYPE_), &entryDataType, - BOO(zVar,zENTRY_NUMELEMS_, - rENTRY_NUMELEMS_), &entryNumElements, - NULL_); - if (status != NO_SUCH_ENTRY) { - if (!StatusHandlerC2S(status)) return FALSE; - VattrCount++; - - if (VattrCount == 1) { - WriteOut (SKTfp, "\n"); - ccc = WriteOut (SKTfp, " ! Attribute"); - Ncharacters (SKTfp, ENTRY_DATATYPE_COL - ccc, (int) ' '); - ccc += ENTRY_DATATYPE_COL - ccc; - ccc += WriteOut (SKTfp, " Data"); - - WriteOut (SKTfp, "\n"); - ccc = WriteOut (SKTfp, " ! Name "); - Ncharacters (SKTfp, ENTRY_DATATYPE_COL - ccc, (int) ' '); - ccc += ENTRY_DATATYPE_COL - ccc; - ccc += WriteOut (SKTfp, " Type Value"); - - WriteOut (SKTfp, "\n"); - ccc = WriteOut (SKTfp, " ! --------"); - Ncharacters (SKTfp, ENTRY_DATATYPE_COL - ccc, (int) ' '); - ccc += ENTRY_DATATYPE_COL - ccc; - ccc += WriteOut (SKTfp, " ---- -----"); - - WriteOut (SKTfp, "\n"); - } - - value = cdf_AllocateMemory ((size_t) (entryNumElements * - CDFelemSize(entryDataType)), - FatalError); - - status = CDFlib (GET_, BOO(zVar,zENTRY_DATA_,rENTRY_DATA_), value, - NULL_); - if (!StatusHandlerC2S(status)) return FALSE; - - delim = PickDelimiter (attrName, strlen(attrName)); - WriteOut (SKTfp, "\n"); - snprintf (tempS, (size_t) sizeof(tempS), - " %c%s%c", delim, attrName, delim); - ccc = WriteOut (SKTfp, tempS); - - if (entryDataType != CDF_TIME_TT2000) ddd = 0; - else ddd = 4; - - if (ccc > (ENTRY_DATATYPE_COL - 2 - ddd)) { - WriteOut (SKTfp, "\n"); - ccc = 0; - } - - Ncharacters (SKTfp, ENTRY_DATATYPE_COL - ccc - ddd, (int) ' '); - ccc += ENTRY_DATATYPE_COL - ccc; - - ccc += WriteOut (SKTfp, DataTypePaddedString(entryDataType)); - ccc += WriteOut (SKTfp, " "); - - if (STRINGdataType (entryDataType)) { /* not allow LF and CR */ - int ii; - for (ii = 0; ii < (int) entryNumElements; ++ii) { - if (((int)*(((char *)value)+ii) == (int) '\n') || - ((int)*(((char *)value)+ii) == (int) '\r')) - memcpy (((char *)value)+ii, " ", 1); - } - } - - ccc += WriteOut (SKTfp, "{ "); - WriteEntryValue (SKTfp, entryDataType, entryNumElements, - value, ccc, MAX_COL_TO_USE - 4); - /* -4 for possible " } ." */ - ccc += WriteOut (SKTfp, " }"); - - cdf_FreeMemory (value, FatalError); - } - } - CHECKforABORTso -} - -if (VattrCount == 0) { - WriteOut (SKTfp, - "\n ! No variable scope attribute entries for this variable."); -} - -/*************************************************************************** -* Write terminating period. -***************************************************************************/ - -if (VattrCount == 0) { - WriteOut (SKTfp, "\n\n ."); - WriteOut (SKTfp, - " ! Terminating period required."); -} -else - WriteOut (SKTfp, " ."); - -/*************************************************************************** -* Write data values (if requested). -***************************************************************************/ - -switch (varValues) { - case NOvalues: - WriteOut (SKTfp, "\n\n ! Values were not requested."); - break; - case NRVvalues: - if (recVary) - WriteOut (SKTfp, "\n\n ! RV values were not requested."); - else - if (maxRec == 0) { - WriteOut (SKTfp, "\n\n ! NRV values follow...\n"); - if (!WriteVariableData(SKTfp,zVar,varN,varDataType, - varNumElements,numDims,dimSizes, - recVary,dimVarys,maxRec)) return FALSE; - } - else - WriteOut (SKTfp, "\n\n ! No values (no records for this variable)."); - break; - case RVvalues: - if (!recVary) - WriteOut (SKTfp, "\n\n ! NRV values were not requested."); - else - if (maxRec > -1) { - WriteOut (SKTfp, "\n\n ! RV values follow...\n"); - if (!WriteVariableData(SKTfp,zVar,varN,varDataType, - varNumElements,numDims,dimSizes, - recVary,dimVarys,maxRec)) return FALSE; - } - else - WriteOut (SKTfp, "\n\n ! No values (no records for this variable)."); - break; - case ALLvalues: - if (maxRec > -1) { - WriteOut (SKTfp, "\n\n ! Values follow...\n"); - if (!WriteVariableData(SKTfp,zVar,varN,varDataType, - varNumElements,numDims,dimSizes, - recVary,dimVarys,maxRec)) return FALSE; - } - else - WriteOut (SKTfp, "\n\n ! No values (no records for this variable)."); - break; - case NAMEDvalues: - if (VariableSelected(varName,variables)) - if (maxRec > -1) { - WriteOut (SKTfp, "\n\n ! Values follow...\n"); - if (!WriteVariableData(SKTfp,zVar,varN,varDataType, - varNumElements,numDims,dimSizes, - recVary,dimVarys,maxRec)) return FALSE; - } - else - WriteOut (SKTfp, "\n\n ! No values (no records for this variable)."); - else - WriteOut (SKTfp, "\n\n ! Values were not requested."); - break; -} - -return TRUE; -} - -/****************************************************************************** -* WriteEnd. -******************************************************************************/ - -Logical WriteEnd () -{ - WriteOut (SKTfp, "\n\n"); - WriteOut (SKTfp, "\n#end"); - return TRUE; -} - -/****************************************************************************** -* WriteVariableData. -* It is assumed that there is at least one record in the CDF. -******************************************************************************/ - -Logical WriteVariableData (fp, zVar, varN, dataType, numElements, numDims, - dimSizes, recVary, dimVarys, maxRec) -FILE *fp; -Logical zVar; -long varN; -long dataType; -long numElements; -long numDims; -long dimSizes[]; -long recVary; -long dimVarys[]; -long maxRec; -{ - CDFstatus status; - long indices[CDF_MAX_DIMS]; - long counts[CDF_MAX_DIMS]; - void *value; - long majority; - int ccc; - long nRecValues, i, recN; - int dimN; - char Evalue[80+1], *format, tempS[MAX_LINE_LEN+1]; - int style; - if (TT2000dataType(dataType)) style = TT2000_3_STYLE; - else style = EPOCH0_STYLE; - status = CDFlib (SELECT_, VAR(zVar), varN, - GET_, CDF_MAJORITY_, &majority, - NULL_); - if (!StatusHandlerC2S(status)) return FALSE; - nRecValues = 1; - if (numDims > 0) { - for (dimN = 0; dimN < numDims; dimN++) { - indices[dimN] = 0; - if (dimVarys[dimN]) { - nRecValues *= dimSizes[dimN]; - counts[dimN] = dimSizes[dimN]; - } - else - counts[dimN] = 1; - } - } - value = cdf_AllocateMemory ((size_t) (numElements * CDFelemSize(dataType)), - FatalError); - if (useFormat) { - status = GetFormatEntry (zVar, varN, &format); - if (!StatusHandlerC2S(status)) { - cdf_FreeMemory (value, FatalError); - return FALSE; - } - } - else - format = NULL; - for (recN = 0; recN <= maxRec; recN++) { - status = CDFlib (SELECT_, BOO(zVar,zVAR_RECNUMBER_, - rVARs_RECNUMBER_), recN, - NULL_); - if (!StatusHandlerC2S(status)) { - cdf_FreeMemory (value, FatalError); - if (format != NULL) cdf_FreeMemory (format, FatalError); - return FALSE; - } - if (status == VIRTUAL_RECORD_DATA) continue; - for (i = 0; i < nRecValues; i++) { - status = CDFlib (SELECT_, BOO(zVar,zVAR_DIMINDICES_, - rVARs_DIMINDICES_), indices, - GET_, VAR_DATA(zVar), value, - NULL_); - if (!StatusHandlerC2S(status)) { - cdf_FreeMemory (value, FatalError); - if (format != NULL) cdf_FreeMemory (format, FatalError); - return FALSE; - } - if (status == VIRTUAL_RECORD_DATA) break; - ccc = WriteOut (fp, "\n "); - if (recVary) { - snprintf (tempS, (size_t) sizeof(tempS), "%ld:[", recN + 1); - } - else - strcpyX (tempS, "[", MAX_LINE_LEN); - if (numDims > 0) { - for (dimN = 0; dimN < numDims; dimN++) { - snprintf (EofS(tempS), (size_t) sizeof(tempS)-strlen(tempS), - "%ld", indices[dimN] + 1); - if (dimN != numDims-1) strcatX (tempS, ",", MAX_LINE_LEN); - } - } - strcatX (tempS, "] = ",MAX_LINE_LEN); - ccc += WriteOut (SKTfp, tempS); - if (STRINGdataType(dataType)) { - ccc += WriteOut (fp, "{ "); - WriteStringValue (fp, numElements, value, ccc, - MAX_COL_TO_USE - 2); /* -2 for " }" */ - WriteOut (fp, " }"); - } - else { - if (useFormat && format != NULL) { - if ((dataType == CDF_FLOAT) || (dataType == CDF_REAL4)) { - if (!isnan((double)*(float *)value) && - *(float *)value <= DEFAULT_FLOAT_PADVALUE) { - EncodeValueFormat (dataType, value, Evalue, NULL, 0, 80, - style, (size_t) sizeof(Evalue)); - } else - EncodeValue (dataType, value, Evalue, style, - (size_t) sizeof(Evalue)); - } else if ((dataType == CDF_DOUBLE) || (dataType == CDF_REAL8)) { - if (!isnan(*(double *)value) && - *(double *)value <= DEFAULT_DOUBLE_PADVALUE) { - EncodeValueFormat (dataType, value, Evalue, NULL, 0, 80, - style, (size_t) sizeof(Evalue)); - } else - EncodeValue (dataType, value, Evalue, style, - (size_t) sizeof(Evalue)); - } else - EncodeValueFormat (dataType, value, Evalue, format, 0, 80, - style, (size_t) sizeof(Evalue)); - } else - EncodeValue (dataType, value, Evalue, style, - (size_t) sizeof(Evalue)); - /* Don't care about width. */ - WriteOut (fp, Evalue); - } - if (ROWmajor(majority)) - INCRindicesROW (numDims, counts, indices); - else - INCRindicesCOL (numDims, counts, indices); - CHECKforABORTso - } - } - cdf_FreeMemory (value, FatalError); - if (format != NULL) cdf_FreeMemory (format, FatalError); - return TRUE; -} - -/****************************************************************************** -* VariableSelected. -* The assumed format of the list of delimited variable names is... -* ,,..., -******************************************************************************/ - -Logical VariableSelected (varName, variables) -char *varName; -char *variables; -{ -/* - char *d1, *d2, varNameT[CDF_VAR_NAME_LEN256+1]; - size_t len; - d1 = variables; - for (;;) { - while (*d1 != NUL && Spacing(*d1)) d1++; - if (*d1 == NUL) return FALSE; - d2 = d1 + 1; - while (*d2 != NUL && *d2 != *d1) d2++; - if (*d2 == NUL) return FALSE; - len = (size_t) (d2 - d1 - 1); - strcpyX (varNameT, d1 + 1, MINIMUM(len,CDF_VAR_NAME_LEN256)); - if (!strcmpITB(varName,varNameT)) return TRUE; - d1 = d2 + 1; - while (*d1 != NUL && *d1 != ',') d1++; - if (*d1 == NUL) return FALSE; - d1++; - } -*/ - if (variables == NULL) return FALSE; - if (strstr((const char *)variables, (const char *)varName) != NULL) - return TRUE; - else - return FALSE; -} - -/****************************************************************************** -* DataTypePaddedString. -* Strings are blank-padded on the end to all be the same length. -******************************************************************************/ - -char *DataTypePaddedString (dataType) -long dataType; -{ -switch (dataType) { - case CDF_BYTE: return "CDF_BYTE "; - case CDF_INT1: return "CDF_INT1 "; - case CDF_INT2: return "CDF_INT2 "; - case CDF_INT4: return "CDF_INT4 "; - case CDF_INT8: return "CDF_INT8 "; - case CDF_UINT1: return "CDF_UINT1 "; - case CDF_UINT2: return "CDF_UINT2 "; - case CDF_UINT4: return "CDF_UINT4 "; - case CDF_REAL4: return "CDF_REAL4 "; - case CDF_REAL8: return "CDF_REAL8 "; - case CDF_FLOAT: return "CDF_FLOAT "; - case CDF_DOUBLE: return "CDF_DOUBLE"; - case CDF_EPOCH: return "CDF_EPOCH "; - case CDF_CHAR: return "CDF_CHAR "; - case CDF_UCHAR: return "CDF_UCHAR "; - case CDF_EPOCH16: return "CDF_EPOCH16"; - case CDF_TIME_TT2000: return "CDF_TIME_TT2000"; -} -return "??????????"; -} - -/****************************************************************************** -* StatusHandlerC2S. -******************************************************************************/ - -Logical StatusHandlerC2S (status) -CDFstatus status; -{ - char text[CDF_STATUSTEXT_LEN + 1]; - - if (StatusERROR(status)) { - if (report[ERRORs]) { - CDFlib (SELECT_, CDF_STATUS_, status, - GET_, STATUS_TEXT_, text, - NULL_); - WriteOut (stdout, "\nERROR> "); - WriteOut (stdout, text); - WriteOut (stdout, "\n"); - } - CDFlib (CLOSE_, CDF_, - NULL_); - WriteOut (stdout, "**** THE SKELETON TABLE IS INCOMPLETE ****\n"); - if (SKTfp != stdout) { - WriteOut (SKTfp, "\n"); - WriteOut (SKTfp, "\n**** THIS SKELETON TABLE IS NOT COMPLETE ****"); - WriteOut (SKTfp, "\n"); - fclose (SKTfp); - } - return FALSE; - } - - if (StatusWARN(status) && report[WARNs]) { - CDFlib (SELECT_, CDF_STATUS_, status, - GET_, STATUS_TEXT_, text, - NULL_); - WriteOut (stdout, "\nWARNING> "); - WriteOut (stdout, text); - WriteOut (stdout, "\n"); - return TRUE; - } - - if (StatusINFO(status) && report[INFOs]) { - CDFlib (SELECT_, CDF_STATUS_, status, - GET_, STATUS_TEXT_, text, - NULL_); - WriteOut (stdout, "\nINFO> "); - WriteOut (stdout, text); - WriteOut (stdout, "\n"); - return TRUE; - } - - return TRUE; /* CDF_OK */ -} - -/****************************************************************************** -* WriteTT2000VarData. -******************************************************************************/ - -Logical WriteTT2000VarData (varValues, variables) -int varValues; -char *variables; -{ -CDFstatus status; -long numVars, numZvars; -long varN, recVary, varDataType, maxRec; -char varName[CDF_VAR_NAME_LEN256+1]; - -if (varValues == NOvalues) return FALSE; -status = CDFlib (GET_, CDF_NUMrVARS_, &numVars, - CDF_NUMzVARS_, &numZvars, - NULL_); -if (!StatusHandlerC2S(status)) return FALSE; -if (numVars > 0) { - for (varN = 0; varN < numVars; varN++) { - status = CDFlib (SELECT_, rVAR_, varN, - GET_, rVAR_NAME_, varName, - rVAR_DATATYPE_, &varDataType, - rVAR_RECVARY_, &recVary, - rVAR_MAXREC_, &maxRec, - NULL_); - if (!StatusHandlerC2S(status)) return FALSE; - if (varDataType == CDF_TIME_TT2000) { - switch (varValues) { - case NRVvalues: - if (!recVary && maxRec == 0) return TRUE; - break; - case RVvalues: - if (!recVary && maxRec > -1) return TRUE; - break; - case ALLvalues: - if (maxRec > -1) return TRUE; - break; - case NAMEDvalues: - if (VariableSelected(varName,variables) && maxRec > -1) return TRUE; - break; - default: - break; - } - } - } -} -if (numZvars > 0) { - for (varN = 0; varN < numZvars; varN++) { - status = CDFlib (SELECT_, zVAR_, varN, - GET_, zVAR_NAME_, varName, - zVAR_DATATYPE_, &varDataType, - zVAR_RECVARY_, &recVary, - zVAR_MAXREC_, &maxRec, - NULL_); - if (!StatusHandlerC2S(status)) return FALSE; - if (varDataType == CDF_TIME_TT2000) { - switch (varValues) { - case NRVvalues: - if (!recVary && maxRec == 0) return TRUE; - break; - case RVvalues: - if (!recVary && maxRec > -1) return TRUE; - break; - case ALLvalues: - if (maxRec > -1) return TRUE; - break; - case NAMEDvalues: - if (VariableSelected(varName,variables) && maxRec > -1) return TRUE; - break; - default: - break; - } - } - } -} -return FALSE; -} - -/****************************************************************************** -* SkeletonTableQOPs. -* Returns TRUE if execution should continue. -******************************************************************************/ - -#if defined(mac) -Logical SkeletonTableQOPs (argC, argV) -int *argC; -char **argV[]; -{ - DialogPtr dialogP; - DialogRecord dRecord; - WindowPtr behind = (WindowPtr) -1; - ControlHandle controlHs[MAXIMUMin+1]; - Rect iRect; -#ifdef __MWERKS__ - ModalFilterUPP FilterDialogQOPsoUPP; - FileFilterUPP FilterForCDFsUPP; - UserItemUPP OutlineDefaultButtonUPP; -#endif - short itemN, iType, i; - static Logical first = TRUE; - char cancelTitle[] = "Cancel"; - static Logical outToScreen = DEFAULTscreenCDF2SKT; - static Logical useFormat = DEFAULTformatCDF2SKT; - static Logical negToPos = DEFAULT_NEGtoPOSfp0; - static Logical pageOutput = DEFAULTpageCDF2SKT; - static Logical reportInfos = REPORTinfosDEFAULT; - static Logical reportWarns = REPORTwarningsDEFAULT; - static Logical reportErrors = REPORTerrorsDEFAULT; - static Logical logMsg = DEFAULTlogCDF2SKT; - static Logical dispStats = DEFAULTstatsEDIT; - static int zModeSrc = DEFAULTzModeCDF2SKT; - static int varValues = DEFAULTvaluesCDF2SKT; - static Str255 CDFtext = "\p"; - static Str255 sktText = "\p"; - static Str255 cacheText = "\p"; - static Str255 varsText = "\p"; - /**************************************************************************** - * Create the dialog and get the control handles. - ****************************************************************************/ - dialogP = GetNewDialog (QOPri, &dRecord, behind); - for (itemN = 1; itemN <= MAXIMUMin; itemN++) { - GetDItem (dialogP, itemN, &iType, (Handle *) &controlHs[itemN], &iRect); - } - /**************************************************************************** - * Set the control values. - ****************************************************************************/ - SetIText ((Handle) controlHs[CDFTEXTin], CDFtext); - SetIText ((Handle) controlHs[SKTTEXTin], sktText); - SetIText ((Handle) controlHs[CACHEin], cacheText); - SetIText ((Handle) controlHs[VARSin], varsText); - if (outToScreen) SetCtlValue (controlHs[SCREENin], 1); - if (useFormat) SetCtlValue (controlHs[FORMATin], 1); - if (negToPos) SetCtlValue (controlHs[NEGZin], 1); - if (pageOutput) SetCtlValue (controlHs[PAGEin], 1); - if (reportInfos) SetCtlValue (controlHs[INFOin], 1); - if (reportWarns) SetCtlValue (controlHs[WARNin], 1); - if (reportErrors) SetCtlValue (controlHs[ERRORin], 1); - if (dispStats) SetCtlValue (controlHs[STATSin], 1); - if (logMsg) SetCtlValue (controlHs[LOGin], 1); - SetCtlValue (controlHs[ZMODEinBASE+zModeSrc], 1); - SetCtlValue (controlHs[VALUESinBASE+varValues], 1); - -#ifndef __MWERKS__ - SetDItem (dialogP, (short) ODBin, (short) userItem, - (Handle) OutlineDefaultButton, &iRect); -#else - OutlineDefaultButtonUPP = NewUserItemProc (OutlineDefaultButton); - SetDItem (dialogP, (short) ODBin, (short) userItem, - (Handle) OutlineDefaultButtonUPP, &iRect); -#endif - /**************************************************************************** - * Change the "Quit" button to a "Cancel" button after the first time. - ****************************************************************************/ - if (first) - first = FALSE; - else - SetCTitle (controlHs[CANCELin], CtoPstr(cancelTitle)); - /**************************************************************************** - * Display the dialog and wait for user actions. - ****************************************************************************/ - ShowWindow ((WindowPtr) dialogP); - SetCursor (ARROW_CURSOR); -#ifdef __MWERKS__ - FilterDialogQOPsoUPP = NewModalFilterProc (FilterDialogQOPso); -#endif - - for (;;) { -#ifndef __MWERKS__ - ModalDialog (FilterDialogQOPso, &itemN); -#else - ModalDialog (FilterDialogQOPsoUPP, &itemN); -#endif - switch (itemN) { - /************************************************************************ - * Ok. - ************************************************************************/ - case OKin: { - char *valuesOptions[5] = { "off", "nrv", "rv", "all", NULL }; - int n; - char tempS1[1+1]; - /********************************************************************** - * Get the value of each control. - **********************************************************************/ - GetIText ((Handle) controlHs[CDFTEXTin], CDFtext); - GetIText ((Handle) controlHs[SKTTEXTin], sktText); - GetIText ((Handle) controlHs[CACHEin], cacheText); - GetIText ((Handle) controlHs[VARSin], varsText); - outToScreen = GetCtlValue (controlHs[SCREENin]); - useFormat = GetCtlValue (controlHs[FORMATin]); - negToPos = GetCtlValue (controlHs[NEGZin]); - pageOutput = GetCtlValue (controlHs[PAGEin]); - reportInfos = GetCtlValue (controlHs[INFOin]); - reportWarns = GetCtlValue (controlHs[WARNin]); - reportErrors = GetCtlValue (controlHs[ERRORin]); - dispStats = GetCtlValue (controlHs[STATSin]); - logMsg = GetCtlValue (controlHs[LOGin]); - for (varValues = 0; varValues < 5; varValues++) { - if (GetCtlValue(controlHs[VALUESinBASE+varValues])) break; - } - for (zModeSrc = 0; zModeSrc < 3; zModeSrc++) { - if (GetCtlValue(controlHs[ZMODEinBASE+zModeSrc])) break; - } - /********************************************************************** - * Build argc/argv. - **********************************************************************/ - *argC = 13 + BOO(NULpString(CDFtext),0,1) + - BOO(NULpString(sktText),0,2) + - BOO(NULpString(cacheText),0,2); - *argV = (char **) cdf_AllocateMemory ((size_t)*argC * sizeof(char *), - FatalError); - n = 0; - MAKEstrARGv (argV, n, pgmName) - MAKEbooARGv (argV, n, outToScreen, "-screen", "-noscreen") - MAKEbooARGv (argV, n, useFormat, "-format", "-noformat") - MAKEbooARGv (argV, n, negToPos, "-neg2posfp0", "-noneg2posfp0") - MAKEbooARGv (argV, n, pageOutput, "-page", "-nopage") - MAKEbooARGv (argV, n, dispStats, "-statistics", "-nostatistics") - MAKEbooARGv (argV, n, logMsg, "-log", "-nolog") - MAKEstrARGv (argV, n, "-zmode") - snprintf (tempS1, (size_t) sizeof(tempS1), "%d", zModeSrc); - MAKEstrARGv (argV, n, tempS1) - MAKEstrARGv (argV, n, "-report") - MAKEstrARGv (argV, n, StatusCodeReportOptions(reportErrors, - reportWarns, - reportInfos)) - MAKEstrARGv (argV, n, "-values") - switch (varValues) { - case NAMEDvalues: - PtoCstr (varsText); - MAKEstrARGv (argV, n, (char *) varsText) - CtoPstr ((char *) varsText); - break; - default: - MAKEstrARGv (argV, n, valuesOptions[varValues]) - break; - } - if (!NULpString(sktText)) { - MAKEstrARGv (argV, n, "-skeleton") - PtoCstr (sktText); - MAKEstrARGv (argV, n, (char *) sktText) - CtoPstr ((char *) sktText); - } - if (!NULpString(cacheText)) { - MAKEstrARGv (argV, n, "-cache") - PtoCstr (cacheText); - MAKEstrARGv (argV, n, (char *) cacheText) - CtoPstr ((char *) cacheText); - } - if (!NULpString(CDFtext)) { - PtoCstr (CDFtext); - MAKEstrARGv (argV, n, (char *) CDFtext) - CtoPstr ((char *) CDFtext); - } - /********************************************************************** - * Close the dialog and return. - **********************************************************************/ - CloseDialog (dialogP); -#ifdef __MWERKS__ - DisposeRoutineDescriptor (FilterDialogQOPsoUPP); - DisposeRoutineDescriptor (OutlineDefaultButtonUPP); -#endif - return TRUE; - } - /************************************************************************ - * Help. - ************************************************************************/ - case HELPin: { - int n; - *argC = 1; - *argV = (char **) cdf_AllocateMemory ((size_t)*argC * sizeof(char *), FatalError); - n = 0; - MAKEstrARGv (argV, n, pgmName) -#ifdef __MWERKS__ - DisposeRoutineDescriptor (FilterDialogQOPsoUPP); - DisposeRoutineDescriptor (OutlineDefaultButtonUPP); -#endif - CloseDialog (dialogP); - return TRUE; - } - /************************************************************************ - * Cancel. - ************************************************************************/ - case CANCELin: -#ifdef __MWERKS__ - DisposeRoutineDescriptor (FilterDialogQOPsoUPP); - DisposeRoutineDescriptor (OutlineDefaultButtonUPP); -#endif - CloseDialog (dialogP); - return FALSE; - /************************************************************************ - * Select CDF specification. - ************************************************************************/ - case CDFSELECTin: { - StandardFileReply CDFreply; - char CDFpath[DU_MAX_PATH_LEN+1]; -#ifndef __MWERKS__ - StandardGetFile (FilterForCDFs, -1, NULL, &CDFreply); -#else - FilterForCDFsUPP = NewFileFilterProc((ProcPtr) FilterForCDFs); - StandardGetFile (FilterForCDFsUPP, -1, NULL, &CDFreply); - DisposeRoutineDescriptor (FilterForCDFsUPP); -#endif - if (CDFreply.sfGood && !CDFreply.sfIsFolder && !CDFreply.sfIsVolume) { - BuildMacPath (&CDFreply.sfFile, CDFpath, TRUE); - CDFtext[0] = strlen (CDFpath); - strcpyX ((char *) &CDFtext[1], CDFpath, 255); - SetIText ((Handle) controlHs[CDFTEXTin], CDFtext); - } - break; - } - /************************************************************************ - * Select skeleton CDF. - * The cursor is set because `StandardPutFile' leaves the cursor as an - * iBeam (instead of returning it to what it was). - ************************************************************************/ - case SKTSELECTin: { - StandardFileReply sktReply; - char sktPath[DU_MAX_PATH_LEN+1], prompt[] = "Enter skeleton table:"; - StandardPutFile (CtoPstr(prompt), CtoPstr(""), &sktReply); - if (sktReply.sfGood && !sktReply.sfIsFolder && !sktReply.sfIsVolume) { - BuildMacPath (&sktReply.sfFile, sktPath, TRUE); - sktText[0] = strlen (sktPath); - strcpyX ((char *) &sktText[1], sktPath, 255); - SetIText ((Handle) controlHs[SKTTEXTin], sktText); - } - SetCursor (&(qd.arrow)); - break; - } - /************************************************************************ - * Check boxes. - ************************************************************************/ - case SCREENin: - case FORMATin: - case NEGZin: - case PAGEin: - case INFOin: - case WARNin: - case ERRORin: - case STATSin: - case LOGin: - SetCtlValue (controlHs[itemN], BOO(GetCtlValue(controlHs[itemN]),0,1)); - break; - /************************************************************************ - * Radio buttons. - ************************************************************************/ - case VALUESinBASE+0: - case VALUESinBASE+1: - case VALUESinBASE+2: - case VALUESinBASE+3: - case VALUESinBASE+4: - for (i = 0; i < 5; i++) SetCtlValue (controlHs[VALUESinBASE+i], 0); - SetCtlValue (controlHs[itemN], 1); - break; - case ZMODEinBASE+0: - case ZMODEinBASE+1: - case ZMODEinBASE+2: - for (i = 0; i < 3; i++) SetCtlValue (controlHs[ZMODEinBASE+i], 0); - SetCtlValue (controlHs[itemN], 1); - break; - } - } -} -#endif diff --git a/cdf36_3-dist/CDFLeapSeconds.txt b/cdf38_1-dist/CDFLeapSeconds.txt similarity index 100% rename from cdf36_3-dist/CDFLeapSeconds.txt rename to cdf38_1-dist/CDFLeapSeconds.txt diff --git a/cdf36_3-dist/CDF_copyright.txt b/cdf38_1-dist/CDF_copyright.txt similarity index 96% rename from cdf36_3-dist/CDF_copyright.txt rename to cdf38_1-dist/CDF_copyright.txt index e6bf172..c9a317a 100644 --- a/cdf36_3-dist/CDF_copyright.txt +++ b/cdf38_1-dist/CDF_copyright.txt @@ -1,4 +1,4 @@ -Copyright 2017 +Common Data Format (CDF) Space Physics Data Facility NASA/Goddard Space Flight Center diff --git a/cdf36_3-dist/CHANGES.txt b/cdf38_1-dist/CHANGES.txt similarity index 68% rename from cdf36_3-dist/CHANGES.txt rename to cdf38_1-dist/CHANGES.txt index 8440731..2a929d4 100644 --- a/cdf36_3-dist/CHANGES.txt +++ b/cdf38_1-dist/CHANGES.txt @@ -1,4 +1,4 @@ -CDF Changes Log, CDF V3.6 +CDF Changes Log, CDF V3.8 V2.0.0 11-Feb-91 Release of CDF V2.0. V2.1.0 7-Jun-91 Release of CDF V2.1. @@ -177,7 +177,7 @@ V3.5.0 25-Feb-13 The original beta version Minor code changes for filling space(s) for writing string type pad value. 64-bit Windows package now distributes 64-bit Cygwin-based libraries and tools. Bugs fixed. Added - support for nan, inf and -inf for floting point values in + support for nan, inf and -inf for floating point values in the tool programs. V3.6.0 5-Feb-15 for version 3.6.0.3 Added a new leap second for 2015-07-01 to the leap second @@ -187,7 +187,7 @@ V3.6.0 5-Feb-15 for version 3.6.0.3 Added an option to renumber the sparse variable records after a record(s) is deleted. Added sort and detect options in tool cdfconvert. Skip checking the file/path name's - characters when reading a CDF file. Enfoce ASCII chars for + characters when reading a CDF file. Enforce ASCII chars for file name (not including the directory portion) only. Minor bug fixes. 1-May-15 for version 3.6.0.4 @@ -223,4 +223,93 @@ V3.6.3 20-Oct-16 for version 3.6.3.0 the (latest) leap second table if the CDF is created based on an existing master CDF that has an older leap second table. - +V3.6.4 10-Feb-17 for version 3.6.4.0 + For Unix-based systems, use C's "mkstemp" function to create + the temporary files, in the template form of + "mycdftmp.XXXXXX". On Windows, use VS's "_mktemp_s" to do + the same. Use the random number generator to create the + temporary file name as the last resort if C's function + fails to create one. + For Unix-based systems, the temporary files will be + created in the current directory if it is writable and + neither environment variable CDF_TMP nor TMPDIR is defined. + Otherwise, it will try the directory defined by the + environment variable CDF_TMP first and then TMPDIR. + If the current directory is not writable, then system's + "/tmp" is used. On Windows, both "TMP" and "TEMP" directory + will be tried if CDF_TMP is not defined. If all fail, + the last resort is to use the current directory. + Modified cdfexport to not truncate variable name while + displaying its data. Have a separate patch for supporting + IDL 8.6. +V3.7.0 11-May-18 for version 3.7.0.0 + For variable attribute, multi-strings are allowed. A header + field in the internal data structure for entry is used to + stored the number of strings. A function to free the + retrieved strings, when reading, is created. The data + validation control process, thru CDF_VALIDATE environment + variable, is modified to also skip the checksum + verification, in addition to the data sanity check, if the + validation is turned off. cdfconvert tool allows the output + of the converted file to replace the source file. + Added support for ARM ports, little or big-endian. The + string-typed data for attribute entry or variable data can + be Nul-terminated. The default pad value can also be empty. + Previously, space(s) is filled if the data length is + shorter than the defined number of elements. Added openVMS + on Itanium (IA64) ports: IA64VMSi, IA64VMSd and IA64VMSg. + Added cdfj.jar, the pure Java package for CDF read and + write without needing CDF library and JNI. A revised cdf + schema is included for CDF's XML support. +V3.7.1 21-Aug-18 for version 3.7.1.0 + Modified to make the encoded date/time string for CDF_EPOCH + and CDF_EPOCH16 in the form of ISO 8601 as the default, as + yyyy-mm-ddThh:mm:ss.ccc or yyyy-mm-ddThh:mm:ss.cccuuunnnppp + respectively. Enhanced the CDFML xsd schema. Do not throw + an error if the ILLEGAL_TT2000_VALUE is encountered. When + encoding its value into date/time string, it is presented + as 1707-09-22T12:12:10.961224195. (Read CDF's C document.) + Add a set of general encoding/parsing functions for each + of the CDF epoch data type. Added a set of time conversion + functions between CDF_EPOCH/CDF_EPOCH16/CDF_TIME_TT2000 time + and unix time. Reset the rVariables' dimension to zero if + a cdf is converted, by cdfconvert, with "zMode 2". +V3.8.0 27-Oct-19 for version 3.8.0.0 + Modified the code to use a variable's FILLVAL, replacing + its PAD value, for all record varying variable's virtual + record data if it exists. To use FILLVAL, it must have a + data type equivalent to its variable's. String typed + variable's pad value is filled with a single space and + followed by NUL(s), instead of multiple spaces. + Changed skt2cdf tool program to allow handling a skeleton + table directly from Windows (with \r\n at the end in each + line) on non-Windows systems. Added new options to + cdfconvert tool program to + 1. remove non-varying dimension(s) from the source + zVariable(s) if it does not have DEPEND_* attribute + defined to the destination variable. + 2. replace any pad value(s) in a variable's data by its + FILLVAL value, if FILLVAL attribute exists and has + an equivalent data type as variable's. + Modified the tool programs to use FORMAT attribute to encode + both data and metadata if the format is to be used. These + include all C-based and Java-based tools. A new option is + added to cdf2skt tool to allow users to choose how to + display variable's metadata and data, either with or witout + format. + 7-Jul-20 for version 3.8.0.1 + Modified CDF epoch breakdown functions that might cause + incorrect day being returned. +V3.8.1 27-Oct-21 for version 3.8.1.0 + Added a set of easy-to-use read functions: READCDF and + READVARIABLE, to read CDF and variable information for + Java, C#, Perl and IDL interface in a single call. + Allowed building the fat JNI from the main CDF Makefile + build. Modified TT2000 type handling routine in C/Java to + accept minus leap second in the future. Added Json-CDF + converters in Java package. Enhanced netCDF-to-CDF + converter. Support characters in UTF-8 encoding. Dynamic + space allocation is no longer placed into a linked list. + Modified TT2000 handling function to handle reverse + leap second (no 59 second). Added support for Apple M1 + processor. diff --git a/cdf36_3-dist/HOWTO.run-Java-tools b/cdf38_1-dist/HOWTO.run-Java-tools similarity index 73% rename from cdf36_3-dist/HOWTO.run-Java-tools rename to cdf38_1-dist/HOWTO.run-Java-tools index 143cce0..503623a 100644 --- a/cdf36_3-dist/HOWTO.run-Java-tools +++ b/cdf38_1-dist/HOWTO.run-Java-tools @@ -18,17 +18,23 @@ Note for Mac OS X users: 1. Set the CLASSPATH environment variable. - CLASSPATH should point to the the locations (full path names) of the + CLASSPATH should point to the locations (full path names) of the following files: /cdfjava/cdftools/CDFToolsDriver.jar /cdfjava/classes/cdfjava.jar + /cdfjava/classes/cdfjson.jar + /cdfjava/classes/gson-2.8.6.jar + /cdfjava/classes/javax.json-1.0.4.jar /cdfjava/cdfml/cdfml.jar Example: - setenv CLASSPATH .:/home/cdf/cdf33_2-dist/cdfjava/classes/cdfjava.jar: \ - /home/cdf/cdf33_2-dist/cdfjava/cdftools/CDFToolsDriver.jar \ - /home/cdf/cdf33_2-dist/cdfjava/cdfml/cdfml.jar + setenv CLASSPATH .:/home/cdf/cdf38_1-dist/cdfjava/classes/cdfjava.jar: \ + /home/cdf/cdf38_1-dist/cdfjava/classes/cdfjson.jar: \ + /home/cdf/cdf38_1-dist/cdfjava/classes/gson-2.8.6.jar: \ + /home/cdf/cdf38_1-dist/cdfjava/classes/javax.json-1.0.4.jar: \ + /home/cdf/cdf38_1-dist/cdfjava/cdftools/CDFToolsDriver.jar \ + /home/cdf/cdf38_1-dist/cdfjava/cdfml/cdfml.jar 2. Set the LD_LIBRARY_PATH environment variable. @@ -41,13 +47,13 @@ Note for Mac OS X users: - the location (full path name) of the CDF library (libcdf.[so|sl|dylib] Example: - setenv LD_LIBRARY_PATH .:/home/cdf/cdf33_-dist/cdfjava/lib: \ - /home/cdf/cdf33_2-dist/lib + setenv LD_LIBRARY_PATH .:/home/cdf/cdf38_1-dist/cdfjava/lib: \ + /home/cdf/cdf38_1-dist/lib Or, for Mac OS X, - setenv DYLD_LIBRARY_PATH .:/Users/cdf/cdf33_2-dist/cdfjava/lib: \ - /Users/cdf/cdf33_2-dist/lib + setenv DYLD_LIBRARY_PATH .:/Users/cdf/cdf38_1-dist/cdfjava/lib: \ + /Users/cdf/cdf38_1-dist/lib 3. Invoke a desired CDF tool as follows: diff --git a/cdf38_1-dist/HOWTO.run-cdf-json-tools b/cdf38_1-dist/HOWTO.run-cdf-json-tools new file mode 100644 index 0000000..85e36b6 --- /dev/null +++ b/cdf38_1-dist/HOWTO.run-cdf-json-tools @@ -0,0 +1,43 @@ +*************************************************************************** +* Please make sure that you have done the following before proceeding * +* with the CDF Json utilities: * +* * +* - Installed JDK 1.7 or later. * +* - installed/built the CDF distribution package. * +* - executed the setenv.bat located in the top distribution to set up * +* proper environment variables. * +*************************************************************************** + +Instructions for using the CDF's Json programs +----------------------------------------------- + +1. CDF2Json: convert a CDF file into a CDF-specific Json form. + + To get the help information and valid arguments/options, enter: + + java CDF2Json + + Use the proper options to run the converter. + +2. Json2CDF: converter a CDF-specific Json file into a CDF file. + + To get the instructions and valid arguments/options, enter: + + java Json2CDF + + Use the proper options to run the converter. + +3. CDFJsonReader: display the data contents from a CDF-specific Json file + + To get the instructions and valid arguments/options, enter: + + java CDFJsonReader + + Use the proper options to run the reader. + +Please direct any comments or questions to: + + NASA-CDF-Support@nasa.onmicrosoft.com + +Note: cdfjson.jar and others are in classes folder. + diff --git a/cdf36_3-dist/cdfjava/cdfml/Readme.txt b/cdf38_1-dist/HOWTO.run-cdf-xml-tools similarity index 58% rename from cdf36_3-dist/cdfjava/cdfml/Readme.txt rename to cdf38_1-dist/HOWTO.run-cdf-xml-tools index 44fe389..c96805a 100644 --- a/cdf36_3-dist/cdfjava/cdfml/Readme.txt +++ b/cdf38_1-dist/HOWTO.run-cdf-xml-tools @@ -2,61 +2,54 @@ * Please make sure that you have done the following before proceeding * * with the CDF Markup Language (CDFML) utilities: * * * -* - installed JDK 1.5. Programs may fail running under an earleir JVM.* +* - Installed JDK 1.7 or later. * * - installed/built the CDF distribution package. * -* - executed the definitions.* file located under the bin directory * -* of CDF installation (e.g. `source definitions.C' for C shell) to * -* define the environment variables (e.g. CDF_BASE, CDF_LIB, etc). * -* - installed the CDF Java APIs and built the CDF-Java JNI. * -* (Download the latest CDF Java APIs if you already have the * -* CDF-Java JNI.) * * - optionally, install Sun's Multi-Schema XML Validator. * *************************************************************************** -Instructions for using the CDF's CDFML programs +Instructions for using the CDF's CDFML programs ----------------------------------------------- -1. Download and un-tar the cdfml.tar archive file from the directory that - contains cdf35_0-dist. - -2. Set the CLASSPATH and LD_LIBRARY_PATH (DYLD_LIBRARY_PATH for Mac OSX) - environment variables. +1. Set the CLASSPATH and LD_LIBRARY_PATH (DYLD_LIBRARY_PATH for Mac OSX) + environment variables. [On Windows, run setenv.bat located in the top + distribution to the setup, if not already done when the package + was installed.] 1) CLASSPATH should point to the following information: - the location (full path name) of the cdfml.jar file that was extracted in step 1. - - the location (full path name) of the cdfjava.jar file. + - the location (full path name) of the cdfjava.jar file. - Examples: + Examples: - - using Sun's V1.5 + - using Sun's V1.7 setenv CLASSPATH ${CLASSPATH}:.: \ - /home/cdf/cdf35_0-dist/cdfjava/classes/cdfjava.jar: \ - /home/cdf/cdf35_0-dist/cdfjava/cdfml/cdfml.jar + /home/cdf/cdf38_1-dist/cdfjava/classes/cdfjava.jar: \ + /home/cdf/cdf38_1-dist/cdfjava/cdfml/cdfml.jar Note: - Absolute/full path name (not relative path) MUST be used when adding - the location of a program to the CLASSPATH environment variable. + Absolute/full path name (not relative path) MUST be used when adding + the location of a program to the CLASSPATH environment variable. + - 2) LD_LIBRARY_PATH should point to the following information: - - the location (full path name) of the CDF-Java JNI - libcdfNativeLibrary.[so|sl|jnilib] (it should be under cdfjava/lib - from the distribution) + - the location (full path name) of the CDF-Java JNI + libcdfNativeLibrary.[so|sl|jnilib] (it should be under cdfjava/lib + from the distribution) - - the location (full path name) of the CDF shared library that is - defined by the environment variable CDF_LIB. This variable is + - the location (full path name) of the CDF shared library that is + defined by the environment variable CDF_LIB. This variable is defined when the CDF library is installed. - Example: - setenv LD_LIBRARY_PATH .:/home/cdf/cdf35_0-dist/cdfjava/lib:${CDF_LIB} + Example: + setenv LD_LIBRARY_PATH .:/home/cdf/cdf38_1-dist/cdfjava/lib:${CDF_LIB} OR for Mac OSX, - setenv DYLD_LIBRARY_PATH .:/home/cdf/cdf35_0-dist/cdfjava/lib:${CDF_LIB} + setenv DYLD_LIBRARY_PATH .:/home/cdf/cdf38_1-dist/cdfjava/lib:${CDF_LIB} -3. Use CDF2CDFML Java program to create a CDFML document from a CDF file. +3. Use CDF2CDFML Java program to create a CDFML document from a CDF file. To get the instructions and valid arguments/options, enter: java CDF2CDFML @@ -81,4 +74,5 @@ Note: that should be transparent to the users. Please direct any comments or questions to: - gsfc-cdf-support@lists.nasa.gov + gsfc-cdf-support@lists.nasa.gov + diff --git a/cdf36_3-dist/HOWTO.run_previous_version b/cdf38_1-dist/HOWTO.run_previous_version similarity index 92% rename from cdf36_3-dist/HOWTO.run_previous_version rename to cdf38_1-dist/HOWTO.run_previous_version index 8f25843..0b32db4 100644 --- a/cdf36_3-dist/HOWTO.run_previous_version +++ b/cdf38_1-dist/HOWTO.run_previous_version @@ -14,7 +14,7 @@ How to access any CDF previous version $ . /bin/definitions.B where is the base folder of a previous CDF version, e.g., - cdf34_0-dist. + cdf38_1-dist. From C-shell or tcsh: @@ -42,7 +42,7 @@ How to access any CDF previous version $ . /bin/definitions.B where is the base folder of a previous CDF version, e.g., - /Applications/cdf34_0-dist. + /Applications/cdf/cdf38_1-dist. From C-shell or tcsh: @@ -66,7 +66,7 @@ How to access any CDF previous version Otherwise, go to CDF home page to download it. Bring up a command-line terminal, then go to the directory that the - intended CDF version is located, e.g. c:\CDF distribution\cdf34_0-dist, + intended CDF version is located, e.g. c:\CDF_distribution\cdf38_1-dist, to check if the batch file: setenv.bat, exists. If it does, run setenv.bat to set up the environment variables. @@ -80,7 +80,7 @@ How to access any CDF previous version set PATH=%mydir%;%mydir%bin;%mydir%lib;%PATH% set TERMINFO=%mydir%lib\terminfo - If the previous CDF version is for V3.4.0 or later, add one more line to + If the previous CDF version is for V3.6.0 or later, add one more line to the batch file: set CDF_LEAPSECONDSTABLE=%mydir%CDFLeapSeconds.txt @@ -95,7 +95,7 @@ How to access any CDF previous version Execute the definitions command to set up logical names and symbols from a previous version in a terminal session: set the current directory to - the selected CDF version, e.g., [cdf34_0-dist]. Run the command: + the selected CDF version, e.g., [cdf38_1-dist]. Run the command: @definitions. Once logical names and symbols are set, CDF tools, e.g., cdfexport, cdfedit, diff --git a/cdf36_3-dist/Help.all b/cdf38_1-dist/Help.all similarity index 80% rename from cdf36_3-dist/Help.all rename to cdf38_1-dist/Help.all index 0efeccd..9763c3e 100644 --- a/cdf36_3-dist/Help.all +++ b/cdf38_1-dist/Help.all @@ -6,7 +6,7 @@ variables are used to configure the distribution for your particular operating system and environment. They are specified on the command line as part of the `make' command. The "Examples" section below illustrates how to specify `make' variables. If your operating system and/or environment is not supported, -please contact CDFsupport (gsfc-cdf-support@lists.nasa.gov). +please contact CDFsupport (NASA-CDF-Support@nasa.onmicrosoft.com). We will either add the support or tell you how to patch the `make' file in the top-level directory of the CDF distribution. If your operating system and environment is supported but you still have problems, refer to the section @@ -23,12 +23,15 @@ Make Variables ENV REQUIRED. The environment begin used (eg. C compiler). SHARED Optional. Should the shareable CDF library be built? CURSES Optional. Should Curses-based toolkit programs be built? - FORTRAN Optional. Should the Fortran interface be tested? - FC_ Optional. Specifies non-default Fortran compiler. + FORTRAN Optional. Should the FORTRAN interface be tested? + FC_ Optional. Specifies non-default FORTRAN compiler. CC__ Optional. Specifies non-default C compiler. UCOPTIONS Optional. Specifies additional options passed to the C compiler. MAKE Optional. Specifies make utility to use. + JNI Optional. Should the JNI library to be built? + JDK_HOME Optional. Specifies where the top-level JDK is. It is used + to build JNI library. A detailed description of each variable follows... @@ -81,21 +84,21 @@ Make Variables different compiler. ENV=gnu For a Sun machine or PC (32/64-bit) building - 32-bit mode. Compile using Gnu C (gcc). + 32-bit mode. Compile using GNU C (gcc). This is for building 32-bit mode programs but using the 64-bit (off_t) offset, instead of 32-bit (size_t). ENV=gnu64 For a Solaris on Sparc building 64-mode. This is similar to above ENV by - using the Gnu C (gcc). But, it is for + using the GNU C (gcc). But, it is for building 64-bit mode programs. Make sure that the gcc compiler supports the 64-bit. ENV=gnu64i For a Solaris on Intel (64-bit) building 64-bit mode. This is similar to above ENV by - using the Gnu C (gcc). But, it is for + using the GNU C (gcc). But, it is for building 64-bit mode programs. Make sure that the gcc compiler supports the 64-bit. @@ -120,7 +123,7 @@ Make Variables using the 64-bit (off_t) offset, instead of 32-bit (size_t). - ENV=gnu Compile using Gnu C (gcc). + ENV=gnu Compile using GNU C (gcc). This is for building Tru64 programs and using the 64-bit (off_t) offset, instead of 32-bit (size_t). @@ -133,26 +136,46 @@ Make Variables mode. ENV=sgi64 Compile using the SGi-supplied C compiler (cc) in the 64-bit mode. - ENV=gnu Compile using Gnu C (gcc). + ENV=gnu Compile using GNU C (gcc). OS=macosx For Mac OS X on a Power PC or Intel Mac. The possible environments are... - ENV=gnu32 Compile using the Gnu compiler (gcc) for + ENV=gnu32 Compile using the GNU compiler (gcc) for 32-bit. - ENV=gnu Compile using the Gnu compiler (gcc) for + ENV=gnu Compile using the GNU compiler (gcc) for 64-bit. - ENV=ppc Compile using the Apple-modified Gnu C + ENV=ppc Compile using the Apple-modified GNU C compiler (clang) in 32-bit mode for Power PC. - ENV=i386 Compile using the Apple-modified Gnu C + ENV=i386 Compile using the Apple-modified GNU C compiler (clang) in 32-bit mode for Intel Mac. + This option is no longer allowed from Apple + Mac OS's Big Sur. - ENV=x86_64 Compile using the Apple-modified Gnu C + ENV=x86_64 Compile using the Apple-modified GNU C compiler (clang) in 64-bit mode for Intel Mac. + ENV=arm Compile using the Apple-modified GNU C + compiler (clang) in its default mode (64-bit) + for Apple Silicon or other 32|64-bit ARM + platforms. Can also be used for + cross-compilation from Intel-based systems, + which will made "-arch arm64" code, if run + from an x86_64 platform. + + ENV=arm64 Compile using the Apple-modified GNU C + compiler (clang) in 64-bit mode for Apple + Silicon or other ARM platforms. May not be + available for all platforms. + + ENV=arm32 Compile using the Apple-modified GNU C + compiler (clang) in 32-bit mode for Apple + Silicon or other ARM platforms. May not be + available for all platforms. + All built, the stand-alone tool programs are linked dynamically. To run the programs, the environment variable DYLB_LIBRARY_PATH needs to point to the folder @@ -162,17 +185,18 @@ Make Variables if the CDF is installed at folder and libcdf.dylib is in its lib sub-directory.. - OS=linux For Linux on an IBM PC (Intel 32/64 or AMD64), a Mac - Power PC or a Dual Alpha. The possible environments - are... + OS=linux For Linux on an IBM PC (Intel 32/64 or AMD64), a Mac + Power PC, a Dual Alpha and ARM (Raspbian/Fedora/Ubuntu). + The possible environments are... - ENV=gnu Compile using Gnu C (gcc). + ENV=gnu Compile using GNU C (gcc). This is for building the programs using the 64-bit (off_t) offset, instead of 32-bit (long). It will build 64-bit mode on 64-bit machines, or 32-bit mode on 32-bit machines. + (ARM-architecture build uses this option.) - ENV=gnu32 Compile using Gnu C (gcc). + ENV=gnu32 Compile using GNU C (gcc). This is for building the programs using the 64-bit (off_t) offset, instead of 32-bit (long). It is used to build 32-bit mode on @@ -186,7 +210,7 @@ Make Variables Or it will build a 32-bit mode on a 32-bit machine. - If Intel's Fortran compiler is being used, + If Intel's FORTRAN compiler is being used, specify FC_intel=ifort @@ -222,9 +246,9 @@ Make Variables ENV=opt64 Compile using the C compiler "sold as an optional separate product" (see the `man' page for `cc'). This is for 64-bit mode. - ENV=gnu Compile using Gnu C (gcc). This is for 32-bit + ENV=gnu Compile using GNU C (gcc). This is for 32-bit mode. - ENV=gnu64 Compile using Gnu C (gcc). This is for 64-bit + ENV=gnu64 Compile using GNU C (gcc). This is for 64-bit mode. The Curses-based toolkit programs rely on `ncurses' being @@ -237,12 +261,12 @@ Make Variables compiler (cc). This is for 32-mode. ENV=ibm64 Compile using the IBM-supplied VisualAge C compiler (cc). This is for 64-mode. - ENV=gnu Compile using Gnu C (gcc). This is for 32-mode. - ENV=gnu64 Compile using Gnu C (gcc). This is for 64-mode. + ENV=gnu Compile using GNU C (gcc). This is for 32-mode. + ENV=gnu64 Compile using GNU C (gcc). This is for 64-mode. OS=cygwin For Cygwin on a PC. The possible environments are... - ENV=gnu Compile using Gnu C (gcc). This is the C + ENV=gnu Compile using GNU C (gcc). This is the C compiler for Cygwin systems. The Curses-based toolkit programs rely on `ncurses' being available. @@ -258,13 +282,13 @@ Make Variables OS=freebsd For freeBSD 4/5/6 on a PC. The possible environments are... - ENV=gnu Compile using Gnu C (gcc). This seems to + ENV=gnu Compile using GNU C (gcc). This seems to be the C compiler most commonly found on freeBSD systems. OS=mingw For MinGW on a PC. The possible environments are... - ENV=gnu Compile using Gnu C (gcc). This is the C + ENV=gnu Compile using GNU C (gcc). This is the C compiler for MinGW systems. The Curses-based toolkit programs rely on `pdcurses' being installed. @@ -290,28 +314,34 @@ Make Variables combinations which support System V flavored Curses. Specifying `no' prevents the compilation/linking of the toolkit programs which depend on the Curses full-screen management package. + Note: To fully support UTF-8 encoded characters, a new version of + ncurses (at least V6.0 | 6.1) is needed. Try to download the + latest source from this site: + https://invisible-island.net/ncurses/ FORTRAN=yes|no This variable defaults to `no' if not specified. Specifying `yes' - causes the compilation/linking of test programs for the Fortran - interfaces. You must of course have a Fortran compiler installed - on your system if you specify `yes'. Note that the Fortran interfaces - will always be present in the CDF library. - - FC_= + causes the compilation/linking of test programs for the FORTRAN + interfaces. You must of course have a FORTRAN compiler installed + on your system if you specify `yes'. Note that the FORTRAN interfaces + will always be present in the CDF library. i + Note: As of Apple Silicon M1, gFORTRAN is not yet ready to make + pure ARM-based code. + + FC_= This variable defaults to f77 or gfortran in most cases with the following exceptions: os=solaris : compiler=g77 os=aix : compiler=xlf os=cygwin : compiler=g77 - Note that if the Fortran compiler is not the default, there may be + Note that if the FORTRAN compiler is not the default, there may be problems with compilation/linking because CDF symbol names defined - in the Fortran interface to the C based CDF library will not match - those generated by the Fortran compiler. If problems are encountered, + in the FORTRAN interface to the C based CDF library will not match + those generated by the FORTRAN compiler. If problems are encountered, it will generally be because the CDF library symbol names have two - trailing underscores while the Fortran compiler is using one trailing + trailing underscores while the FORTRAN compiler is using one trailing underscore. The default behavior of the make process in generating - CDF library Fortran interface symbol names can be overridden with the + CDF library FORTRAN interface symbol names can be overridden with the UCOPTIONS make variable. Trailing single underscores can be forced with -Dsingle_underscore (i.e., UCOPTIONS=-Dsingle_underscore). No trailing underscore or double trailing underscores can also be forced with @@ -323,7 +353,7 @@ Make Variables This variable allows the addition of user supplied C options to those already defined in the make process (dependent on OS and ENV). It may be necessary to use this make variable to accommodate non-default - Fortran compilers (see FC_). + FORTRAN compilers (see FC_). CC__= This variable defaults to gcc when env=gnu, ppc, ppc64, or i386 @@ -340,6 +370,24 @@ Make Variables its native make might have difficulties handling certain statements in the Makefile. Use GNU version of make, gmake, will solve the problem. + JNI=yes|no + This variable defaults to `no' if not specified. Specifying `yes' + causes the compilation/linking of JNI library for Java-CDF interface. + Make sure the JDK home directory is provided, through either JDK_HOME + variable to Makefile or an environment variable. The JNI library will + be linked with the static CDF library. + + JDK_HOME= + This variable specifies where the top-level JDK home directory is. This + is needed to build JNI library. The Java development kit home directory + can also be set through an environment variable of the same name or + another name, JAVA_HOME. Make sure JNI is consistent with the Java + application with either 64 or 32-bit mode. This is the top level of the + JDK location. For examples, on Mac, it is like: + JDK_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk + For Linux, it is like: + JDK_HOME=/usr/lib/jvm/java-1.8.0 + Examples -------- @@ -349,7 +397,7 @@ Examples make OS=sunos ENV=sysV all To build the CDF distribution on a linux machine using gnu compilers and - building the Fortran interface test programs with the non-default compiler, + building the FORTRAN interface test programs with the non-default compiler, gfortran... make OS=linux ENV=gnu FORTRAN=yes FC_linux=gfortran all @@ -367,8 +415,8 @@ Possible Problems is not available, then specify `CURSES=no' (causing CDFedit, CDFlist, and CDFwalk to not be built). - Undefined symbols when using Gnu C. - When linking the Fortran test programs to a CDF library built with Gnu C + Undefined symbols when using GNU C. + When linking the FORTRAN test programs to a CDF library built with GNU C you may get undefined symbols. C compiler not found. diff --git a/cdf36_3-dist/Help.install b/cdf38_1-dist/Help.install similarity index 100% rename from cdf36_3-dist/Help.install rename to cdf38_1-dist/Help.install diff --git a/cdf36_3-dist/Help.test b/cdf38_1-dist/Help.test similarity index 100% rename from cdf36_3-dist/Help.test rename to cdf38_1-dist/Help.test diff --git a/cdf36_3-dist/Makefile b/cdf38_1-dist/Makefile similarity index 76% rename from cdf36_3-dist/Makefile rename to cdf38_1-dist/Makefile index 12952f7..4e3e592 100644 --- a/cdf36_3-dist/Makefile +++ b/cdf38_1-dist/Makefile @@ -32,6 +32,12 @@ # V2.0 20-Feb-16, M Liu Added version to dynamic library name for Mac. # Mac OS to build both 32 and 64-bit universal # binary for libraries and tools. +# V3.0 16-Mar-20, M Liu For Mac OS X, Xcode version 10 or newer +# will only build x86_64 application. Only +# older versions can make both 32 and 64-mode. +# V3.8 26-Jun-20, M Liu Added JNI compilation. +# V3.9 8-Jan-21, M Liu Added no string overflow check for gnu C and +# no print directory for gnu make. #------------------------------------------------------------------------------ # # Notes: @@ -50,7 +56,9 @@ PART=all TARGET= SOURCE= DESTINATION= -VERSION=3.6.3 +VERSION=3.8.1 +JDK_HOME= +JNIOS= #------------------------------------------------------------------------------ # Directory locations. @@ -63,6 +71,8 @@ TOOLSsrcDIR=src/tools TESTSsrcDIR=src/tests HELPsrcDIR=src/help LIBsrcZlibDIR=src/lib/zlib +JNIsrcDIR=cdfjava/jni +MYHOME=$(shell printenv HOME) #------------------------------------------------------------------------------ # Macros specified on the `make' command line. @@ -75,17 +85,21 @@ OS= ENV= INSTALLDIR=. UCOPTIONS= +JNI=no #------------------------------------------------------------------------------ # Other macros. #------------------------------------------------------------------------------ - +LDLIB= +EXTRAMAKE= MORE=$(shell uname -a | cut -f5 -d " ") ifeq ("$(OS)","solaris") ifeq ("$(ENV)","x86") + EXTRAMAKE=--no-print-directory MAKE=gmake else ifeq ("$(ENV)","x64") + EXTRAMAKE=--no-print-directory MAKE=gmake else MAKE=make @@ -93,19 +107,61 @@ ifeq ("$(OS)","solaris") endif else ifeq ("$(MORE)","i86pc") + EXTRAMAKE=--no-print-directory MAKE=gmake else - MAKE=make + GNU=$(shell make --version | head -1 | cut -f1 -d' ') + ifeq ("$(GNU)","GNU") + EXTRAMAKE=--no-print-directory + MAKE=make + else + MAKE=make + endif endif endif RANLIB=ranlib WHICHOS=$(shell uname) MACVERSION=0 -MACLIB= +# MACLIB= +XCODEVERSION= +XCODEVERSION2=0 ifeq ("$(WHICHOS)","Darwin") MACVERSION=$(shell uname -r | cut -f1 -d.) - MACLIB=$(shell echo $$HOME)/lib +# MACLIB=$(shell echo $$HOME)/lib + XCODEVERSION=$(shell /usr/bin/xcodebuild -version | sed '2d' | cut -f2 -d' ') + XCODEVERSION2=$(shell echo $(XCODEVERSION) | cut -f1 -d.) + FORJNI=/Contents/Home +else + FORJNI= +endif + +JAVA_HOME= +ifneq ("$(JDK_HOME)","") + JAVA_HOME=$(JDK_HOME)$(FORJNI) +else + WHICHJDK=$(shell printenv JDK_HOME) + ifneq ("$(WHICHJDK)","") + JAVA_HOME=$(WHICHJDK)$(FORJNI) + else + WHICHJDK=$(shell printenv JAVA_HOME) + ifneq ("$(WHICHJDK)", "") + JAVA_HOME=$(WHICHJDK)$(FORJNI) + endif + endif +endif + +JNI2=$(JNI) +ifeq ("$(JNI)","yes") + ifneq ("$(JAVA_HOME)","") + JNI_FILE=$(JAVA_HOME)/include/jni.h + TEST_JNI=$(shell test -e $(JNI_FILE) && echo yes) + ifneq ($(TEST_JNI), yes) + JNI2=no + endif + else + JNI2=no + endif endif #------------------------------------------------------------------------------ @@ -120,6 +176,8 @@ AROPTIONS_solaris=rc RANLIB_solaris=no FC_solaris=f90 EXEEXT_solaris= +JNIOS_solaris=solaris +JNIEXT_solaris=so CURSES_solaris_sparc=yes CC_solaris_sparc=cc @@ -229,26 +287,36 @@ FOPTIONSld_macosx= SHAREDEXT_macosx=dylib AROPTIONS_macosx=rc RANLIB_macosx=yes -FC_macosx=gfortran +#FC_macosx=gfortran EXEEXT_macosx= MACOSxlink= MACOSxFopt= +FORTWARN= WHICHOS=$(shell uname) ifeq ("$(WHICHOS)","Darwin") KERNELVERSION=$(shell uname -r | cut -f1 -d.) ifeq ("$(KERNELVERSION)","9") MACOSxlink=-L/usr/lib/gcc/i686-apple-darwin9/4.2.1 -lm -lc -lgcc - MACOSxmin=-macosx_version_min 10.4 else MACOSxlink=-lc -lm MACOSxFopt=-m64 - MACOSxmin=-macosx_version_min 10.6 + endif + ifeq ($(shell test $(KERNELVERSION) -gt 19; echo $$?),0) +# Bigsur + XCODEDir=$(shell xcode-select -p) + LDLIB=-L$(XCODEDir)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib +# LDLIB=-L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib + FORTWARN=-w -fallow-argument-mismatch endif endif +FC_macosx=gfortran $(FORTWARN) +JNIOS_macosx=darwin +JNIEXT_macosx=jnilib CURSES_macosx_gnu32=yes CC_macosx_gnu32=gcc -LD_macosx_gnu32=libtool $(MACOSxmin) +#LD_macosx_gnu32=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool +LD_macosx_gnu32=libtool LDOPTIONS_macosx_gnu32=-dynamic PIC_macosx_gnu32= COPTIONS_macosx_gnu32=-m32 -D__MACH__ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -O2 @@ -262,7 +330,8 @@ SYSLIBSshr_macosx_gnu32=$(MACOSxlink) -m32 CURSES_macosx_gnu=yes CC_macosx_gnu=gcc -LD_macosx_gnu=libtool $(MACOSxmin) +#LD_macosx_gnu=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool +LD_macosx_gnu=libtool LDOPTIONS_macosx_gnu=-dynamic PIC_macosx_gnu= COPTIONS_macosx_gnu=-m64 -D__MACH__ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -O2 @@ -276,7 +345,8 @@ SYSLIBSshr_macosx_gnu=$(MACOSxlink) CURSES_macosx_ppc=yes CC_macosx_ppc=gcc -LD_macosx_ppc=libtool -syslibroot /Developer/SDKs/MacOSX10.5.sdk -macosx_version_min 10.4 -arch_only ppc +#LD_macosx_ppc=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -syslibroot /Developer/SDKs/MacOSX10.5.sdk -arch_only ppc +LD_macosx_ppc=libtool -syslibroot /Developer/SDKs/MacOSX10.5.sdk -arch_only ppc LDOPTIONS_macosx_ppc=-dynamic PIC_macosx_ppc= COPTIONS_macosx_ppc=-isysroot/Developer/SDKs/MacOSX10.5.sdk -arch ppc -D__ppc__ -D__MACH__ -D__APPLE__ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -O2 @@ -290,7 +360,7 @@ SYSLIBSshr_macosx_ppc=-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib -L/usr/lib/gcc/po CURSES_macosx_ppc64=yes CC_macosx_ppc64=gcc -LD_macosx_ppc64=libtool -syslibroot /Developer/SDKs/MacOSX10.5.sdk -macosx_version_min 10.4 -arch_only ppc64 +LD_macosx_ppc64=libtool -syslibroot /Developer/SDKs/MacOSX10.5.sdk -arch_only ppc64 LDOPTIONS_macosx_ppc64=-dynamic PIC_macosx_ppc64= COPTIONS_macosx_ppc64=-isysroot/Developer/SDKs/MacOSX10.5.sdk -arch ppc64 -m64 -DMACOSX64 -D__ppc__ -D__MACH__ -D__APPLE__ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -O2 @@ -302,40 +372,102 @@ CURSESLIB_macosx_ppc64=-lcurses SYSLIBSexe_macosx_ppc64=-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib -L/usr/lib/gcc/powerpc-apple-darwin9/4.0.1/ppc64 -lm -lc -lgcc SYSLIBSshr_macosx_ppc64=-L/Developer/SDKs/MacOSX10.5.sdk/usr/lib -L/usr/lib/gcc/powerpc-apple-darwin9/4.0.1/ppc64 -lm -lc -lgcc +#COPTIONS_macosx=-Di386 -D__MACH__ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -O2 +COPTIONS_macosx=-D__MACH__ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -O2 + CURSES_macosx_i386=yes CC_macosx_i386=clang -#LD_macosx_i386=libtool $(MACOSxmin) -arch_only i386 -LD_macosx_i386=libtool $(MACOSxmin) +ifeq ($(shell test $(XCODEVERSION2) -lt 10; echo $$?),0) + COPTIONS_macosx_i386=-arch i386 -arch x86_64 -Di386 $(COPTIONS_macosx) + COPTIONSld_macosx_i386=-arch i386 -arch x86_64 +endif +LD_macosx_i386=libtool LDOPTIONS_macosx_i386=-dynamic PIC_macosx_i386= -COPTIONS_macosx_i386=-mmacosx-version-min=10.4 -arch i386 -arch x86_64 -Di386 -D__MACH__ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -O2 -#COPTIONS_macosx_i386=-mmacosx-version-min=10.4 -m32 -Di386 -D__MACH__ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -O2 COPTIONSZlib_macosx_i386=-DHAVE_STDARG_H -DHAVE_UNISTD_H -COPTIONSld_macosx_i386=-mmacosx-version-min=10.4 -arch i386 -arch x86_64 -#COPTIONSld_macosx_i386=-mmacosx-version-min=10.4 -m32 FOPTIONS_macosx_i386=-w -m32 FOPTIONSld_macosx_i386=-m32 CURSESLIB_macosx_i386=-lcurses -# SYSLIBSexe_macosx_i386=-L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -lm -lc -lgcc -SYSLIBSexe_macosx_i386=-lc -lm -# SYSLIBSshr_macosx_i386=-L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -lm -lc -lgcc -SYSLIBSshr_macosx_i386=-lc -lm +SYSLIBSexe_macosx_i386=-lc -lm +SYSLIBSshr_macosx_i386=-lc -lm CURSES_macosx_x86_64=yes CC_macosx_x86_64=clang -#LD_macosx_x86_64=libtool $(MACOSxmin) -arch_only x86_64 -LD_macosx_x86_64=libtool $(MACOSxmin) -LDOPTIONS_macosx_x86_64=-dynamic +ifeq ($(shell test $(XCODEVERSION2) -gt 9; echo $$?),0) + COPTIONS_macosx_x86_64=-arch x86_64 -Di386 $(COPTIONS_macosx) + COPTIONSld_macosx_x86_64=-arch x86_64 +else +# COPTIONS_macosx_x86_64=-arch i386 -arch x86_64 -Di386 $(COPTIONS_macosx) +# COPTIONSld_macosx_x86_64=-arch i386 -arch x86_64 + COPTIONS_macosx_x86_64=-arch x86_64 -Di386 $(COPTIONS_macosx) + COPTIONSld_macosx_x86_64=-arch x86_64 +endif +LD_macosx_x86_64=ld +LDOPTIONS_macosx_x86_64=-dynamic -dylib PIC_macosx_x86_64= -#COPTIONS_macosx_x86_64=-mmacosx-version-min=10.4 -m64 -Di386 -D__MACH__ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -O2 -COPTIONS_macosx_x86_64=-mmacosx-version-min=10.4 -arch x86_64 -arch i386 -Di386 -D__MACH__ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -O2 COPTIONSZlib_macosx_x86_64=-DHAVE_STDARG_H -DHAVE_UNISTD_H -COPTIONSld_macosx_x86_64=-mmacosx-version-min=10.4 -arch x86_64 -arch i386 FOPTIONS_macosx_x86_64=-w -m64 FOPTIONSld_macosx_x86_64=-m64 CURSESLIB_macosx_x86_64=-lcurses -SYSLIBSexe_macosx_x86_64=-lc -lm -SYSLIBSshr_macosx_x86_64=-lc -lm +SYSLIBSexe_macosx_x86_64=$(LDLIB) -lc -lm +SYSLIBSshr_macosx_x86_64=$(LDLIB) -lc -lm + +WHICHARM=$(shell uname -m) +CARM= +ifeq ("$(WHICHARM)","arm64") + CARM=-arch arm64 + FARM=-arch arm64 +else + ifeq ("$(WHICHARM)","arm") + CARM=-arch arm32 + FARM=-m32 + else + CARM=-arch arm64 + FARM=-m64 + endif +endif + +CURSES_macosx_arm=yes +CC_macosx_arm=clang +COPTIONS_macosx_arm=$(COPTIONS_macosx) $(CARM) +COPTIONSld_macosx_arm=$(CARM) +LD_macosx_arm=ld +LDOPTIONS_macosx_arm=-dynamic -dylib $(CARM) +PIC_macosx_arm= +COPTIONSZlib_macosx_arm=-DHAVE_STDARG_H -DHAVE_UNISTD_H +FOPTIONS_macosx_arm=-w $(FARM) +FOPTIONSld_macosx_arm=$(FARM) +CURSESLIB_macosx_arm=-lcurses +SYSLIBSexe_macosx_arm=$(LDLIB) -lc -lm +SYSLIBSshr_macosx_arm=$(LDLIB) -lc -lm + +CURSES_macosx_arm64=yes +CC_macosx_arm64=clang +COPTIONS_macosx_arm64=$(COPTIONS_macosx) -arch arm64 +COPTIONSld_macosx_arm64=-arch arm64 +LD_macosx_arm64=ld +LDOPTIONS_macosx_arm64=-dynamic -dylib -arch arm64 +PIC_macosx_arm64= +COPTIONSZlib_macosx_arm64=-DHAVE_STDARG_H -DHAVE_UNISTD_H +FOPTIONS_macosx_arm64=-w $(FARM) +FOPTIONSld_macosx_arm64=$(FARM) +CURSESLIB_macosx_arm64=-lcurses +SYSLIBSexe_macosx_arm64=$(LDLIB) -lc -lm +SYSLIBSshr_macosx_arm64=$(LDLIB) -lc -lm + +CURSES_macosx_arm32=yes +CC_macosx_arm32=clang +COPTIONS_macosx_arm32=$(COPTIONS_macosx) -arch arm32 +COPTIONSld_macosx_arm32=-arch arm32 +LD_macosx_arm=ld +LDOPTIONS_macosx_arm32=-dynamic -dylib -arch arm32 +PIC_macosx_arm32= +COPTIONSZlib_macosx_arm32=-DHAVE_STDARG_H -DHAVE_UNISTD_H +FOPTIONS_macosx_arm32=-w $(FARM) +FOPTIONSld_macosx_arm32=$(FARM) +CURSESLIB_macosx_arm32=-lcurses +SYSLIBSexe_macosx_arm32=$(LDLIB) -lc -lm +SYSLIBSshr_macosx_arm32=$(LDLIB) -lc -lm #------------------------------------------------------------------------------ # Macros for OSF (Digital UNIX). @@ -349,6 +481,8 @@ AROPTIONS_osf=rc RANLIB_osf=yes FC_osf=f77 EXEEXT_osf= +JNIOS_osf=osf +JNIEXT_osf=so CURSES_osf_dec=yes CC_osf_dec=cc @@ -389,6 +523,8 @@ SHAREDEXT_irix6=so AROPTIONS_irix6=rc RANLIB_irix6=no FC_irix6=f77 +JNIOS_irix6=irix +JNIEXT_irix6=so CURSES_irix6_sgin32=yes CC_irix6_sgin32=cc @@ -443,19 +579,20 @@ SHAREDEXT_linux=so AROPTIONS_linux=rc RANLIB_linux=yes FC_linux=gfortran -EXEEXT_linux= +JNIOS_linux=linux +JNIEXT_linux=so CURSES_linux_gnu=yes CC_linux_gnu=gcc LD_linux_gnu=gcc LDOPTIONS_linux_gnu=-shared PIC_linux_gnu=-fPIC -COPTIONS_linux_gnu=-I/usr/include/ncurses -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DMALLOC_CHECK_=0 -O2 +COPTIONS_linux_gnu=-I/usr/include/ncurses -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DMALLOC_CHECK_=0 -O2 -Wno-stringop-overflow COPTIONSZlib_linux_gnu=-DHAVE_STDARG_H -DHAVE_UNISTD_H COPTIONSld_linux_gnu= FOPTIONS_linux_gnu=-fsecond-underscore FOPTIONSld_linux_gnu= -CURSESLIB_linux_gnu=-lcurses +CURSESLIB_linux_gnu=-lncursesw SYSLIBSexe_linux_gnu=-lm -lc SYSLIBSshr_linux_gnu=-lm -lc @@ -464,12 +601,12 @@ CC_linux_gnu32=gcc LD_linux_gnu32=gcc LDOPTIONS_linux_gnu32=-shared -m32 PIC_linux_gnu32=-fPIC -COPTIONS_linux_gnu32=-m32 -I/usr/include/ncurses -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DMALLOC_CHECK_=0 -O2 +COPTIONS_linux_gnu32=-m32 -I/usr/include/ncurses -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DMALLOC_CHECK_=0 -O2 -Wno-stringop-overflow COPTIONSZlib_linux_gnu32=-DHAVE_STDARG_H -DHAVE_UNISTD_H COPTIONSld_linux_gnu32=-m32 FOPTIONS_linux_gnu32=-m32 -fsecond-underscore FOPTIONSld_linux_gnu32=-m32 -CURSESLIB_linux_gnu32=-lcurses +CURSESLIB_linux_gnu32=-lncursesw SYSLIBSexe_linux_gnu32=-lm -lc SYSLIBSshr_linux_gnu32=-lm -lc @@ -478,12 +615,12 @@ CC_linux_gnu64=gcc LD_linux_gnu64=gcc LDOPTIONS_linux_gnu64=-shared -m64 PIC_linux_gnu64=-fPIC -COPTIONS_linux_gnu64=-m64 -I/usr/include/ncurses -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DMALLOC_CHECK_=0 -O2 +COPTIONS_linux_gnu64=-m64 -I/usr/include/ncurses -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DMALLOC_CHECK_=0 -O2 -Wno-stringop-overflow COPTIONSZlib_linux_gnu64=-DHAVE_STDARG_H -DHAVE_UNISTD_H COPTIONSld_linux_gnu64=-m64 FOPTIONS_linux_gnu64=-m64 -fsecond-underscore FOPTIONSld_linux_gnu64=-m64 -CURSESLIB_linux_gnu64=-lcurses +CURSESLIB_linux_gnu64=-lncursesw SYSLIBSexe_linux_gnu64=-lm -lc SYSLIBSshr_linux_gnu64=-lm -lc @@ -513,6 +650,8 @@ AROPTIONS_aix=rc AROPTIONS_aix64=-r -c -X 64 RANLIB_aix=yes FC_aix=xlf +JNIOS_aix=aix +JNIEXT_aix=o CURSES_aix_ibm=yes CC_aix_ibm=cc @@ -583,6 +722,8 @@ SHAREDEXT_hpux=sl AROPTIONS_hpux=rc RANLIB_hpux=no FC_hpux=f77 +JNIOS_hpux=hpux +JNIEXT_hpux=sl CURSES_hpux_std=yes CC_hpux_std=cc @@ -680,20 +821,22 @@ AROPTIONS_cygwin=rc RANLIB_cygwin=yes FC_cygwin=gfortran EXEEXT_cygwin=.exe +JNIOS_cygwin=cygwin +JNIEXT_cygwin=dll CURSES_cygwin_gnu=yes CC_cygwin_gnu=gcc LD_cygwin_gnu=gcc LDOPTIONS_cygwin_gnu=-shared PIC_cygwin_gnu= -COPTIONS_cygwin_gnu=-I/usr/include/ncurses -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -O2 +COPTIONS_cygwin_gnu=-I/usr/include/ncurses -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -O2 -Wno-stringop-overflow COPTIONSZlib_cygwin_gnu=-DHAVE_STDARG_H -DHAVE_UNISTD_H COPTIONSld_cygwin_gnu= FOPTIONS_cygwin_gnu=-fsecond-underscore FOPTIONSld_cygwin_gnu= -CURSESLIB_cygwin_gnu=-lncurses -SYSLIBSexe_cygwin_gnu=-lgcc -SYSLIBSshr_cygwin_gnu=-lgcc +CURSESLIB_cygwin_gnu=-lncursesw +SYSLIBSexe_cygwin_gnu=-lgcc +SYSLIBSshr_cygwin_gnu=-lgcc #------------------------------------------------------------------------------ # Macros for MinGW. @@ -707,6 +850,8 @@ AROPTIONS_mingw=rc RANLIB_mingw=yes FC_mingw=gfortran EXEEXT_mingw=.exe +JNIOS_mingw=mingw +JNIEXT_mingw=dll CURSES_mingw_gnu=yes CC_mingw_gnu=gcc @@ -733,6 +878,8 @@ SHAREDEXT_freebsd=so AROPTIONS_freebsd=rc RANLIB_freebsd=yes FC_freebsd=f77 +JNIOS_freebsd=freebsd +JNIEXT_freebsd=so CURSES_freebsd_gnu=yes CC_freebsd_gnu=gcc @@ -796,21 +943,27 @@ all.macosx.gnu32: all.build all.macosx.gnu: all.build all.macosx.ppc: all.build all.macosx.ppc64: all.build -all.macosx.i386: all.build +all.macosx.i386: + @if [ ${XCODEVERSION2} -gt 9 ] ; then \ + $(MAKE) note1.macx.i386 ; \ + else \ + $(MAKE) all.build ; \ + fi all.macosx.x86_64: all.build +all.macosx.arm: all.build +all.macosx.arm64: all.build +all.macosx.arm32: all.build all.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_$(OS)_$(ENV))" \ "CCx=$(CC_$(OS)_$(ENV))" \ -"MAKE=$(MAKE)" \ "COPTIONS=$(UCOPTIONS) $(COPTIONS_$(OS)_$(ENV)) $(COPTIONSZlib_$(OS)_$(ENV))" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(AND.$(SHARED).$(SHARED_$(OS)))" \ "PIC=$(PIC_$(OS)_$(ENV))" \ "CCx=$(CC_$(OS)_$(ENV))" \ -"MAKE=$(MAKE)" \ "LDx=$(LD_$(OS)_$(ENV))" \ "COPTIONS=$(UCOPTIONS) $(COPTIONS_$(OS)_$(ENV))" \ "SYSLIBS=$(SYSLIBSshr_$(OS)_$(ENV))" \ @@ -820,19 +973,17 @@ all "RANLIB=$(RANLIB_$(OS))" \ "VERSION=$(VERSION)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_$(OS)_$(ENV))" \ -"MAKE=$(MAKE)" \ "COPTIONS=$(COPTIONS_$(OS)_$(ENV))" \ "COPTIONSld=$(COPTIONSld_$(OS)_$(ENV))" \ "SYSLIBS=$(SYSLIBSexe_$(OS)_$(ENV))" \ "CURSESLIB=$(CURSESLIB_$(OS)_$(ENV))" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_$(OS))" \ -"MAKE=$(MAKE)" \ "CCx=$(CC_$(OS)_$(ENV))" \ "SHARED=$(AND.$(SHARED).$(SHARED_$(OS)))" \ "FOPTIONS=$(FOPTIONS_$(OS)) $(FOPTIONS_$(OS)_$(ENV))" \ @@ -841,6 +992,30 @@ all "COPTIONSld=$(COPTIONSld_$(OS)_$(ENV))" \ "SYSLIBS=$(SYSLIBSexe_$(OS)_$(ENV))" \ "SHAREDEXT=$(SHAREDEXT_$(OS))" \ +all + @if [ "$(JNI)" == "yes" ] ; then \ + if [ "$(JNI2)" == "yes" ] ; then \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) JNIOS=$(JNIOS_$(OS)) JNIEXT=$(JNIEXT_$(OS)) JDK_HOME=$(JAVA_HOME) build.jni ; \ + else \ + echo "*** JNI is not built as JDK or jni.h is not found..." ; \ + fi \ + fi + +build.jni: + @cd $(JNIsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ +"SHARED=$(AND.$(SHARED).$(SHARED_$(OS)))" \ +"PIC=$(PIC_$(OS)_$(ENV))" \ +"CCx=$(CC_$(OS)_$(ENV))" \ +"LDx=$(LD_$(OS)_$(ENV))" \ +"COPTIONS=$(UCOPTIONS) $(COPTIONS_$(OS)_$(ENV))" \ +"SYSLIBS=$(SYSLIBSshr_$(OS)_$(ENV))" \ +"SHAREDEXT=$(SHAREDEXT_$(OS))" \ +"LDOPTIONS=$(LDOPTIONS_$(OS)_$(ENV))" \ +"VERSION=$(VERSION)" \ +"JAVA_HOME=$(JDK_HOME)" \ +"JNIOS=$(JNIOS)" \ +"JNIEXT=$(JNIEXT)" \ +"LDLIB=$(LDLIB)" \ all #------------------------------------------------------------------------------ @@ -855,7 +1030,7 @@ test.help: fi test: - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) test + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) test #------------------------------------------------------------------------------ # Install files. @@ -880,80 +1055,114 @@ install.help_: create.help copy.help install.lib: create.lib copy.lib.a @if [ -f $(LIBsrcDIR)/libcdf.so ] ; then \ - $(MAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIR)" install.lib.so ; \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIR)" install.lib.so ; \ else \ $(NULL) ; \ fi @if [ -f $(LIBsrcDIR)/libcdf.sl ] ; then \ - $(MAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIR)" install.lib.sl ; \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIR)" install.lib.sl ; \ else \ $(NULL) ; \ fi @if [ -f $(LIBsrcDIR)/libcdf.dylib ] ; then \ - $(MAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIR)" install.lib.dylib ; \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIR)" install.lib.dylib ; \ + else \ + $(NULL) ; \ + fi + @if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.so ] ; then \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIR)" install.lib.jnilib ; \ + else \ + $(NULL) ; \ + fi + @if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.jnilib ] ; then \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIR)" install.lib.jnilib ; \ + else \ + $(NULL) ; \ + fi + @if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.dll ] ; then \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIR)" install.lib.jnilib ; \ + else \ + $(NULL) ; \ + fi + @if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.sl ] ; then \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIR)" install.lib.jnilib ; \ else \ $(NULL) ; \ fi @if [ -f $(LIBsrcDIR)/libcdf.o ] ; then \ - $(MAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIR)" install.lib.o ; \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIR)" install.lib.o ; \ else \ $(NULL) ; \ fi @if [ -f $(LIBsrcDIR)/libcdf.dll ] ; then \ - $(MAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIR)" install.lib.dll ; \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIR)" install.lib.dll ; \ else \ $(NULL) ; \ fi install.lib.so: create.lib copy.lib.so install.lib.sl: create.lib copy.lib.sl -install.lib.dylib: create.lib create.maclib copy.lib.dylib +# install.lib.dylib: create.lib create.maclib copy.lib.dylib +install.lib.dylib: create.lib copy.lib.dylib +install.lib.jnilib: create.lib copy.lib.jnilib +install.lib.jnilib2: create.lib2 copy.lib.jnilib install.lib.o: create.lib copy.lib.o install.lib.dll: create.lib copy.lib.dll create.include: @if [ ! -d $(INSTALLDIR)/include ] ; then \ - $(MAKE) MAKE=$(MAKE) "TARGET=$(INSTALLDIR)/include" create.dir ; \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "TARGET=$(INSTALLDIR)/include" create.dir ; \ else \ $(NULL) ; \ fi create.bin: @if [ ! -d $(INSTALLDIR)/bin ] ; then \ - $(MAKE) MAKE=$(MAKE) "TARGET=$(INSTALLDIR)/bin" create.dir ; \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "TARGET=$(INSTALLDIR)/bin" create.dir ; \ else \ $(NULL) ; \ fi create.lib: @if [ ! -d $(INSTALLDIR)/lib ] ; then \ - $(MAKE) MAKE=$(MAKE) "TARGET=$(INSTALLDIR)/lib" create.dir ; \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "TARGET=$(INSTALLDIR)/lib" create.dir ; \ else \ $(NULL) ; \ fi + @if [ $(MACVERSION) -gt 0 ] ; then \ + if [ ! -d $(MYHOME)/lib ] ; then \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "TARGET=$(MYHOME)/lib" create.dir ; \ + else \ + $(NULL) ; \ + fi \ + else \ + $(NULL) ; \ + fi -create.maclib: - @if [ $(MACVERSION) -gt 14 ] ; then \ - if [ ! -d $(MACLIB) ] ; then \ - $(MAKE) MAKE=$(MAKE) "TARGET=$(MACLIB)" create.dir ; \ +create.lib2: + @if [ $(MACVERSION) -gt 0 ] ; then \ + if [ ! -d $(MYHOME)/Library/Java/Extensions ] ; then \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "TARGET=$(MYHOME)/Library/Java/Extensions" create.dir ; \ else \ - $(NULL) ; \ + $(NULL) ; \ fi \ + else \ + $(NULL) ; \ fi create.help: @if [ ! -d $(INSTALLDIR)/lib ] ; then \ - $(MAKE) MAKE=$(MAKE) "TARGET=$(INSTALLDIR)/lib" create.dir ; \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "TARGET=$(INSTALLDIR)/lib" create.dir ; \ else \ $(NULL) ; \ fi @if [ ! -d $(INSTALLDIR)/lib/cdf ] ; then \ - $(MAKE) MAKE=$(MAKE) "TARGET=$(INSTALLDIR)/lib/cdf" create.dir ; \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "TARGET=$(INSTALLDIR)/lib/cdf" create.dir ; \ else \ $(NULL) ; \ fi @if [ ! -d $(INSTALLDIR)/lib/cdf/help ] ; then \ - $(MAKE) MAKE=$(MAKE) "TARGET=$(INSTALLDIR)/lib/cdf/help" create.dir ; \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "TARGET=$(INSTALLDIR)/lib/cdf/help" create.dir ; \ else \ $(NULL) ; \ fi @@ -991,6 +1200,8 @@ copy.include: cp $(INCsrcDIR)/cdfdist.h $(INSTALLDIR)/include @echo cp $(INCsrcDIR)/cdfconfig.h $(INSTALLDIR)/include cp $(INCsrcDIR)/cdfconfig.h $(INSTALLDIR)/include + @echo cp $(INCsrcDIR)/cdftools.h $(INSTALLDIR)/include + cp $(INCsrcDIR)/cdftools.h $(INSTALLDIR)/include copy.lib.so: @echo cp $(LIBsrcDIR)/libcdf.so $(INSTALLDIR)/lib @@ -1011,12 +1222,48 @@ copy.lib.dylib: cp $(LIBsrcDIR)/libcdf.dylib $(INSTALLDIR)/lib/libcdf.$(VERSION).dylib rm -f $(INSTALLDIR)/lib/libcdf.dylib cd $(INSTALLDIR)/lib && ln -s libcdf.$(VERSION).dylib libcdf.dylib - @if [ $(MACVERSION) -gt 14 ] ; then \ - cp $(LIBsrcDIR)/libcdf.dylib $(MACLIB)/libcdf.$(VERSION).dylib ; \ - rm -f $(MACLIB)/libcdf.dylib ; \ - cd $(MACLIB) && ln -s libcdf.$(VERSION).dylib libcdf.dylib ; \ + @if [ $(MACVERSION) -gt 0 ]; then \ + mkdir -p ${MYHOME}/lib ; \ + cp $(LIBsrcDIR)/libcdf.dylib $(MYHOME)/lib/libcdf.$(VERSION).dylib ; \ + rm -f $(MYHOME)/lib/libcdf.dylib ; \ + cd $(MYHOME)/lib && ln -s libcdf.$(VERSION).dylib libcdf.dylib ; \ + fi + +copy.lib.jnilib: + @if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.so ] ; then \ + echo cp $(JNIsrcDIR)/libcdfNativeLibrary.so $(INSTALLDIR)/lib/libcdfNativeLibrary.$(VERSION).so ; \ + cp $(JNIsrcDIR)/libcdfNativeLibrary.so $(INSTALLDIR)/lib/libcdfNativeLibrary.$(VERSION).so ; \ + rm -f $(INSTALLDIR)/lib/libcdfNativeLibrary.so ; \ + cd $(INSTALLDIR)/lib && ln -s libcdfNativeLibrary.$(VERSION).so libcdfNativeLibrary.so ; \ + fi + @if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.dll ] ; then \ + echo cp $(JNIsrcDIR)/libcdfNativeLibrary.dll $(INSTALLDIR)/lib/libcdfNativeLibrary.$(VERSION).dll ; \ + cp $(JNIsrcDIR)/libcdfNativeLibrary.dll $(INSTALLDIR)/lib/libcdfNativeLibrary.$(VERSION).dll ; \ + rm -f $(INSTALLDIR)/lib/libcdfNativeLibrary.dll ; \ + cd $(INSTALLDIR)/lib && ln -s libcdfNativeLibrary.$(VERSION).dll libcdfNativeLibrary.dll ; \ + fi + @if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.jnilib ] ; then \ + echo cp $(JNIsrcDIR)/libcdfNativeLibrary.jnilib $(INSTALLDIR)/lib/libcdfNativeLibrary.$(VERSION).jnilib ; \ + cp $(JNIsrcDIR)/libcdfNativeLibrary.jnilib $(INSTALLDIR)/lib/libcdfNativeLibrary.$(VERSION).jnilib ; \ + mkdir -p $(MYHOME)/lib ; \ + echo cp $(JNIsrcDIR)/libcdfNativeLibrary.jnilib $(MYHOME)/lib/libcdfNativeLibrary.$(VERSION).jnilib ; \ + cp $(JNIsrcDIR)/libcdfNativeLibrary.jnilib $(MYHOME)/lib/libcdfNativeLibrary.$(VERSION).jnilib ; \ + mkdir -p $(MYHOME)/Library/Java/Extensions ; \ + echo cp $(JNIsrcDIR)/libcdfNativeLibrary.jnilib $(MYHOME)/Library/Java/Extensions/libcdfNativeLibrary.$(VERSION).jnilib ; \ + cp $(JNIsrcDIR)/libcdfNativeLibrary.jnilib $(MYHOME)/Library/Java/Extensions/libcdfNativeLibrary.$(VERSION).jnilib ; \ + rm -f $(INSTALLDIR)/lib/libcdfNativeLibrary.jnilib ; \ + cd $(INSTALLDIR)/lib && ln -s libcdfNativeLibrary.$(VERSION).jnilib libcdfNativeLibrary.jnilib ; \ + rm -f $(MYHOME)/lib/libcdfNativeLibrary.jnilib ; \ + cd $(MYHOME)/lib && ln -s libcdfNativeLibrary.$(VERSION).jnilib libcdfNativeLibrary.jnilib ; \ + rm -f $(MYHOME)/Library/Java/Extensions/libcdfNativeLibrary.jnilib ; \ + cd $(MYHOME)/Library/Java/Extensions && ln -s libcdfNativeLibrary.$(VERSION).jnilib libcdfNativeLibrary.jnilib ; \ + fi + @if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.sl ] ; then \ + echo cp $(JNIsrcDIR)/libcdfNativeLibrary.sl $(INSTALLDIR)/lib/libcdfNativeLibrary.$(VERSION).sl ; \ + cp $(JNIsrcDIR)/libcdfNativeLibrary.sl $(INSTALLDIR)/lib/libcdfNativeLibrary.$(VERSION).sl ; \ + rm -f $(INSTALLDIR)/lib/libcdfNativeLibrary.sl ; \ + cd $(INSTALLDIR)/lib && ln -s libcdfNativeLibrary.$(VERSION).sl libcdfNativeLibrary.sl ; \ fi - copy.lib.o: @echo cp $(LIBsrcDIR)/libcdf.o $(INSTALLDIR)/lib @@ -1030,17 +1277,22 @@ copy.lib.dll: cd $(INSTALLDIR)/lib && ln -s libcdf.$(VERSION).dll libcdf.dll copy.lib.a: - @echo cp -p $(LIBsrcDIR)/libcdf.a $(INSTALLDIR)/lib - cp -p $(LIBsrcDIR)/libcdf.a $(INSTALLDIR)/lib + @echo cp $(LIBsrcDIR)/libcdf.a $(INSTALLDIR)/lib + cp $(LIBsrcDIR)/libcdf.a $(INSTALLDIR)/lib + @if [ $(MACVERSION) -gt 0 ]; then \ + mkdir -p ${MYHOME}/lib ; \ + cp $(LIBsrcDIR)/libcdf.a $(MYHOME)/lib ; \ + fi + copy.tools: @if [ -f $(TOOLSsrcDIR)/cdfedit.exe ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfedit.exe" \ "DESTINATION=$(INSTALLDIR)/bin/cdfedit.exe" \ copy.file ; \ elif [ -f $(TOOLSsrcDIR)/cdfedit ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfedit" \ "DESTINATION=$(INSTALLDIR)/bin/cdfedit" \ copy.file ; \ @@ -1048,12 +1300,12 @@ copy.tools: $(NULL) ; \ fi @if [ -f $(TOOLSsrcDIR)/cdfxp.exe ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfxp.exe" \ "DESTINATION=$(INSTALLDIR)/bin/cdfexport.exe" \ copy.file ; \ elif [ -f $(TOOLSsrcDIR)/cdfxp ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfxp" \ "DESTINATION=$(INSTALLDIR)/bin/cdfexport" \ copy.file ; \ @@ -1061,12 +1313,12 @@ copy.tools: $(NULL) ; \ fi @if [ -f $(TOOLSsrcDIR)/cdfcvt.exe ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfcvt.exe" \ "DESTINATION=$(INSTALLDIR)/bin/cdfconvert.exe" \ copy.file ; \ elif [ -f $(TOOLSsrcDIR)/cdfcvt ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfcvt" \ "DESTINATION=$(INSTALLDIR)/bin/cdfconvert" \ copy.file ; \ @@ -1074,12 +1326,12 @@ copy.tools: $(NULL) ; \ fi @if [ -f $(TOOLSsrcDIR)/skt2cdf.exe ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/skt2cdf.exe" \ "DESTINATION=$(INSTALLDIR)/bin/skeletoncdf.exe" \ copy.file ; \ elif [ -f $(TOOLSsrcDIR)/skt2cdf ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/skt2cdf" \ "DESTINATION=$(INSTALLDIR)/bin/skeletoncdf" \ copy.file ; \ @@ -1087,12 +1339,12 @@ copy.tools: $(NULL) ; \ fi @if [ -f $(TOOLSsrcDIR)/cdf2skt.exe ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdf2skt.exe" \ "DESTINATION=$(INSTALLDIR)/bin/skeletontable.exe" \ copy.file ; \ elif [ -f $(TOOLSsrcDIR)/cdf2skt ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdf2skt" \ "DESTINATION=$(INSTALLDIR)/bin/skeletontable" \ copy.file ; \ @@ -1100,12 +1352,12 @@ copy.tools: $(NULL) ; \ fi @if [ -f $(TOOLSsrcDIR)/cdfinq.exe ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfinq.exe" \ "DESTINATION=$(INSTALLDIR)/bin/cdfinquire.exe" \ copy.file ; \ elif [ -f $(TOOLSsrcDIR)/cdfinq ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfinq" \ "DESTINATION=$(INSTALLDIR)/bin/cdfinquire" \ copy.file ; \ @@ -1113,12 +1365,12 @@ copy.tools: $(NULL) ; \ fi @if [ -f $(TOOLSsrcDIR)/cdfstats.exe ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfstats.exe" \ "DESTINATION=$(INSTALLDIR)/bin/cdfstats.exe" \ copy.file ; \ elif [ -f $(TOOLSsrcDIR)/cdfstats ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfstats" \ "DESTINATION=$(INSTALLDIR)/bin/cdfstats" \ copy.file ; \ @@ -1126,12 +1378,12 @@ copy.tools: $(NULL) ; \ fi @if [ -f $(TOOLSsrcDIR)/cdfcmp.exe ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfcmp.exe" \ "DESTINATION=$(INSTALLDIR)/bin/cdfcompare.exe" \ copy.file ; \ elif [ -f $(TOOLSsrcDIR)/cdfcmp ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfcmp" \ "DESTINATION=$(INSTALLDIR)/bin/cdfcompare" \ copy.file ; \ @@ -1139,12 +1391,12 @@ copy.tools: $(NULL) ; \ fi @if [ -f $(TOOLSsrcDIR)/cdfdump.exe ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfdump.exe" \ "DESTINATION=$(INSTALLDIR)/bin/cdfdump.exe" \ copy.file ; \ elif [ -f $(TOOLSsrcDIR)/cdfdump ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfdump" \ "DESTINATION=$(INSTALLDIR)/bin/cdfdump" \ copy.file ; \ @@ -1152,12 +1404,12 @@ copy.tools: $(NULL) ; \ fi @if [ -f $(TOOLSsrcDIR)/cdfirsdump.exe ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfirsdump.exe" \ "DESTINATION=$(INSTALLDIR)/bin/cdfirsdump.exe" \ copy.file ; \ elif [ -f $(TOOLSsrcDIR)/cdfirsdump ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfirsdump" \ "DESTINATION=$(INSTALLDIR)/bin/cdfirsdump" \ copy.file ; \ @@ -1165,12 +1417,12 @@ copy.tools: $(NULL) ; \ fi @if [ -f $(TOOLSsrcDIR)/cdfmerge.exe ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfmerge.exe" \ "DESTINATION=$(INSTALLDIR)/bin/cdfmerge.exe" \ copy.file ; \ elif [ -f $(TOOLSsrcDIR)/cdfmerge ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfmerge" \ "DESTINATION=$(INSTALLDIR)/bin/cdfmerge" \ copy.file ; \ @@ -1178,12 +1430,12 @@ copy.tools: $(NULL) ; \ fi @if [ -f $(TOOLSsrcDIR)/cdfvalidate.exe ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfvalidate.exe" \ "DESTINATION=$(INSTALLDIR)/bin/cdfvalidate.exe" \ copy.file ; \ elif [ -f $(TOOLSsrcDIR)/cdfvalidate ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfvalidate" \ "DESTINATION=$(INSTALLDIR)/bin/cdfvalidate" \ copy.file ; \ @@ -1191,12 +1443,12 @@ copy.tools: $(NULL) ; \ fi @if [ -f $(TOOLSsrcDIR)/cdfleapsecondsinfo.exe ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfleapsecondsinfo.exe" \ "DESTINATION=$(INSTALLDIR)/bin/cdfleapsecondsinfo.exe" \ copy.file ; \ elif [ -f $(TOOLSsrcDIR)/cdfleapsecondsinfo ] ; then \ - $(MAKE) MAKE=$(MAKE) \ + $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SOURCE=$(TOOLSsrcDIR)/cdfleapsecondsinfo" \ "DESTINATION=$(INSTALLDIR)/bin/cdfleapsecondsinfo" \ copy.file ; \ @@ -1271,6 +1523,7 @@ create.dir: copy.file: @echo cp $(SOURCE) $(DESTINATION) cp $(SOURCE) $(DESTINATION) + chmod +x $(DESTINATION) notify.user: @echo @@ -1294,7 +1547,7 @@ notify.user: fi @echo @echo - @echo If you use BASH or BSH, run the following command: + @echo If you use BASH/BSH and ZSH, run the following command: @echo @if [ $(INSTALLDIR) = "." ] ; then \ echo " . `pwd`/bin/definitions.B" ; \ @@ -1311,6 +1564,15 @@ notify.user: echo " . $(INSTALLDIR)/bin/definitions.K" ; \ fi @echo + @echo + @echo If you use ZSH, run the following command: + @echo + @if [ $(INSTALLDIR) = "." ] ; then \ + echo " . `pwd`/bin/definitions.Z" ; \ + else \ + echo " . $(INSTALLDIR)/bin/definitions.Z" ; \ + fi + @echo ranlib.file: @echo $(RANLIB) $(TARGET) @@ -1323,10 +1585,13 @@ ranlib.file: clean: @-rm -f core @-rm -f samples/core - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) clean - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) clean - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) clean - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) clean + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) clean + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) clean + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) clean + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) clean + @if [ -f $(JNIsrcDIR) ] ; then \ + @cd $(JNIsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) clean ; \ + fi purge: @-rm -f *~ @@ -1339,10 +1604,13 @@ purge: @-rm -f $(DEFSsrcDIR)/*# @-rm -f $(INCsrcDIR)/*~ @-rm -f $(INCsrcDIR)/*# - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) purge - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) purge - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) purge - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) purge + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) purge + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) purge + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) purge + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) purge + @if [ -f $(JNIsrcDIR) ] ; then \ + @cd $(JNIsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) purge ; \ + fi #------------------------------------------------------------------------------ # Ultrix. @@ -1352,12 +1620,12 @@ all.ultrix.risc: note1.all.ultrix.risc.build all.ultrix.gnu: note1.1st all.ultrix.gnu.build all.ultrix.risc.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_ultrix_risc)" \ "CCx=$(CC_ultrix_risc)" \ "COPTIONS=$(COPTIONS_ultrix_risc)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED_ultrix)" \ "PIC=$(PIC_ultrix_risc)" \ "CCx=$(CC_ultrix_risc)" \ @@ -1369,7 +1637,7 @@ all "AROPTIONS=$(AROPTIONS_ultrix)" \ "RANLIB=$(RANLIB_ultrix)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_ultrix_risc)" \ "COPTIONS=$(COPTIONS_ultrix_risc)" \ @@ -1377,7 +1645,7 @@ all "SYSLIBS=$(SYSLIBSexe_ultrix_risc)" \ "CURSESLIB=$(CURSESLIB_ultrix_risc)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_ultrix)" \ "CCx=$(CC_ultrix_risc)" \ @@ -1391,12 +1659,12 @@ all all all.ultrix.gnu.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_ultrix_gnu)" \ "CCx=$(CC_ultrix_gnu)" \ "COPTIONS=$(COPTIONS_ultrix_gnu)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED_ultrix)" \ "PIC=$(PIC_ultrix_gnu)" \ "CCx=$(CC_ultrix_gnu)" \ @@ -1408,7 +1676,7 @@ all "AROPTIONS=$(AROPTIONS_ultrix)" \ "RANLIB=$(RANLIB_ultrix)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_ultrix_gnu)" \ "COPTIONS=$(COPTIONS_ultrix_gnu)" \ @@ -1416,7 +1684,7 @@ all "SYSLIBS=$(SYSLIBSexe_ultrix_gnu)" \ "CURSESLIB=$(CURSESLIB_ultrix_gnu)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_ultrix)" \ "CCx=$(CC_ultrix_gnu)" \ @@ -1439,12 +1707,12 @@ all.hpux.gnu64: all.hpux.gnu64.build all.hpux.opt64: all.hpux.opt64.build all.hpux.std.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_hpux_std)" \ "CCx=$(CC_hpux_std)" \ "COPTIONS=$(COPTIONS_hpux_std) $(COPTIONSZlib_hpux_std)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED_hpux_std)" \ "PIC=$(PIC_hpux_std)" \ "CCx=$(CC_hpux_std)" \ @@ -1456,7 +1724,7 @@ all "AROPTIONS=$(AROPTIONS_hpux)" \ "RANLIB=$(RANLIB_hpux)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_hpux_std)" \ "COPTIONS=$(COPTIONS_hpux_std)" \ @@ -1464,7 +1732,7 @@ all "SYSLIBS=$(SYSLIBSexe_hpux_std)" \ "CURSESLIB=$(CURSESLIB_hpux_std)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_hpux)" \ "CCx=$(CC_hpux_std)" \ @@ -1478,12 +1746,12 @@ all all all.hpux.opt.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_hpux_opt)" \ "CCx=$(CC_hpux_opt)" \ "COPTIONS=$(COPTIONS_hpux_opt) $(COPTIONSZlib_hpux_opt)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED)" \ "PIC=$(PIC_hpux_opt)" \ "CCx=$(CC_hpux_opt)" \ @@ -1495,7 +1763,7 @@ all "AROPTIONS=$(AROPTIONS_hpux)" \ "RANLIB=$(RANLIB_hpux)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_hpux_opt)" \ "COPTIONS=$(COPTIONS_hpux_opt)" \ @@ -1503,7 +1771,7 @@ all "SYSLIBS=$(SYSLIBSexe_hpux_opt)" \ "CURSESLIB=$(CURSESLIB_hpux_opt)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_hpux)" \ "CCx=$(CC_hpux_opt)" \ @@ -1517,12 +1785,12 @@ all all all.hpux.opt64.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_hpux_opt64)" \ "CCx=$(CC_hpux_opt64)" \ "COPTIONS=$(COPTIONS_hpux_opt64) $(COPTIONSZlib_hpux_opt64)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED)" \ "PIC=$(PIC_hpux_opt64)" \ "CCx=$(CC_hpux_opt64)" \ @@ -1534,7 +1802,7 @@ all "AROPTIONS=$(AROPTIONS_hpux)" \ "RANLIB=$(RANLIB_hpux)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_hpux_opt64)" \ "COPTIONS=$(COPTIONS_hpux_opt64)" \ @@ -1542,7 +1810,7 @@ all "SYSLIBS=$(SYSLIBSexe_hpux_opt64)" \ "CURSESLIB=$(CURSESLIB_hpux_opt64)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_hpux)" \ "CCx=$(CC_hpux_opt64)" \ @@ -1556,12 +1824,12 @@ all all all.hpux.posix.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_hpux_posix)" \ "CCx=$(CC_hpux_posix)" \ "COPTIONS=$(COPTIONS_hpux_posix) $(COPTIONSZlib_hpux_posix)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED)" \ "PIC=$(PIC_hpux_posix)" \ "CCx=$(CC_hpux_posix)" \ @@ -1573,7 +1841,7 @@ all "AROPTIONS=$(AROPTIONS_hpux)" \ "RANLIB=$(RANLIB_hpux)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_hpux_posix)" \ "COPTIONS=$(COPTIONS_hpux_posix)" \ @@ -1581,7 +1849,7 @@ all "SYSLIBS=$(SYSLIBSexe_hpux_posix)" \ "CURSESLIB=$(CURSESLIB_hpux_posix)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_hpux)" \ "CCx=$(CC_hpux_posix)" \ @@ -1595,12 +1863,12 @@ all all all.hpux.gnu.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_hpux_gnu)" \ "CCx=$(CC_hpux_gnu)" \ "COPTIONS=$(COPTIONS_hpux_gnu) $(COPTIONSZlib_hpux_gnu)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED)" \ "PIC=$(PIC_hpux_gnu)" \ "CCx=$(CC_hpux_gnu)" \ @@ -1612,7 +1880,7 @@ all "AROPTIONS=$(AROPTIONS_hpux)" \ "RANLIB=$(RANLIB_hpux)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_hpux_gnu)" \ "COPTIONS=$(COPTIONS_hpux_gnu)" \ @@ -1620,7 +1888,7 @@ all "SYSLIBS=$(SYSLIBSexe_hpux_gnu)" \ "CURSESLIB=$(CURSESLIB_hpux_gnu)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_hpux)" \ "CCx=$(CC_hpux_gnu)" \ @@ -1634,12 +1902,12 @@ all all all.hpux.gnu64.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_hpux_gnu64)" \ "CCx=$(CC_hpux_gnu64)" \ "COPTIONS=$(COPTIONS_hpux_gnu64) $(COPTIONSZlib_hpux_gnu64)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED)" \ "PIC=$(PIC_hpux_gnu64)" \ "CCx=$(CC_hpux_gnu64)" \ @@ -1651,7 +1919,7 @@ all "AROPTIONS=$(AROPTIONS_hpux)" \ "RANLIB=$(RANLIB_hpux)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_hpux_gnu64)" \ "COPTIONS=$(COPTIONS_hpux_gnu64)" \ @@ -1659,7 +1927,7 @@ all "SYSLIBS=$(SYSLIBSexe_hpux_gnu64)" \ "CURSESLIB=$(CURSESLIB_hpux_gnu64)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_hpux)" \ "CCx=$(CC_hpux_gnu64)" \ @@ -1680,12 +1948,12 @@ all.irix6.sgi64: all.irix6.sgi64.build all.irix6.gnu: note1.1st all.irix6.gnu.build all.irix6.sgin32.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_irix6_sgin32)" \ "CCx=$(CC_irix6_sgin32)" \ "COPTIONS=$(COPTIONS_irix6_sgin32) $(COPTIONSZlib_irix6_sgin32)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED)" \ "PIC=$(PIC_irix6_sgin32)" \ "CCx=$(CC_irix6_sgin32)" \ @@ -1697,7 +1965,7 @@ all "AROPTIONS=$(AROPTIONS_irix6)" \ "RANLIB=$(RANLIB_irix6)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_irix6_sgin32)" \ "COPTIONS=$(COPTIONS_irix6_sgin32)" \ @@ -1705,7 +1973,7 @@ all "SYSLIBS=$(SYSLIBSexe_irix6_sgin32)" \ "CURSESLIB=$(CURSESLIB_irix6_sgin32)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_irix6)" \ "CCx=$(CC_irix6_sgin32)" \ @@ -1719,12 +1987,12 @@ all all all.irix6.sgi64.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_irix6_sgi64)" \ "CCx=$(CC_irix6_sgi64)" \ "COPTIONS=$(COPTIONS_irix6_sgi64) $(COPTIONSZlib_irix6_sgi64)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED)" \ "PIC=$(PIC_irix6_sgi64)" \ "CCx=$(CC_irix6_sgi64)" \ @@ -1736,7 +2004,7 @@ all "AROPTIONS=$(AROPTIONS_irix6)" \ "RANLIB=$(RANLIB_irix6)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_irix6_sgi64)" \ "COPTIONS=$(COPTIONS_irix6_sgi64)" \ @@ -1744,7 +2012,7 @@ all "SYSLIBS=$(SYSLIBSexe_irix6_sgi64)" \ "CURSESLIB=$(CURSESLIB_irix6_sgi64)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_irix6)" \ "CCx=$(CC_irix6_sgi64)" \ @@ -1758,12 +2026,12 @@ all all all.irix6.gnu.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_irix6_gnu)" \ "CCx=$(CC_irix6_gnu)" \ "COPTIONS=$(COPTIONS_irix6_gnu) $(COPTIONSZlib_irix6_gnu)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED)" \ "PIC=$(PIC_irix6_gnu)" \ "CCx=$(CC_irix6_gnu)" \ @@ -1775,7 +2043,7 @@ all "AROPTIONS=$(AROPTIONS_irix6)" \ "RANLIB=$(RANLIB_irix6)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_irix6_gnu)" \ "COPTIONS=$(COPTIONS_irix6_gnu)" \ @@ -1783,7 +2051,7 @@ all "SYSLIBS=$(SYSLIBSexe_irix6_gnu)" \ "CURSESLIB=$(CURSESLIB_irix6_gnu)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_irix6)" \ "CCx=$(CC_irix6_gnu)" \ @@ -1806,12 +2074,12 @@ all.aix.ibm64: all.aix.ibm64.build all.aix.gnu64: all.aix.gnu64.build all.aix.ibm.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_aix_ibm)" \ "CCx=$(CC_aix_ibm)" \ "COPTIONS=$(COPTIONS_aix_ibm) $(COPTIONSZlib_aix_ibm)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED)" \ "PIC=$(PIC_aix_ibm)" \ "CCx=$(CC_aix_ibm)" \ @@ -1823,7 +2091,7 @@ all "AROPTIONS=$(AROPTIONS_aix)" \ "RANLIB=$(RANLIB_aix)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_aix_ibm)" \ "COPTIONS=$(COPTIONS_aix_ibm)" \ @@ -1831,7 +2099,7 @@ all "SYSLIBS=$(SYSLIBSexe_aix_ibm)" \ "CURSESLIB=$(CURSESLIB_aix_ibm)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_aix)" \ "CCx=$(CC_aix_ibm)" \ @@ -1845,12 +2113,12 @@ all all all.aix.gnu.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_aix_gnu)" \ "CCx=$(CC_aix_gnu)" \ "COPTIONS=$(COPTIONS_aix_gnu) $(COPTIONSZlib_aix_gnu)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED)" \ "PIC=$(PIC_aix_gnu)" \ "CCx=$(CC_aix_gnu)" \ @@ -1862,7 +2130,7 @@ all "AROPTIONS=$(AROPTIONS_aix)" \ "RANLIB=$(RANLIB_aix)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_aix_gnu)" \ "COPTIONS=$(COPTIONS_aix_gnu)" \ @@ -1870,7 +2138,7 @@ all "SYSLIBS=$(SYSLIBSexe_aix_gnu)" \ "CURSESLIB=$(CURSESLIB_aix_gnu)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_aix)" \ "CCx=$(CC_aix_gnu)" \ @@ -1884,12 +2152,12 @@ all all all.aix.ibm64.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_aix_ibm64)" \ "CCx=$(CC_aix_ibm64)" \ "COPTIONS=$(COPTIONS_aix_ibm64) $(COPTIONSZlib_aix_ibm64)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED)" \ "PIC=$(PIC_aix_ibm64)" \ "CCx=$(CC_aix_ibm64)" \ @@ -1901,7 +2169,7 @@ all "AROPTIONS=$(AROPTIONS_aix64)" \ "RANLIB=$(RANLIB_aix)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_aix_ibm64)" \ "COPTIONS=$(COPTIONS_aix_ibm64)" \ @@ -1909,7 +2177,7 @@ all "SYSLIBS=$(SYSLIBSexe_aix_ibm64)" \ "CURSESLIB=$(CURSESLIB_aix_ibm64)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_aix)" \ "CCx=$(CC_aix_ibm64)" \ @@ -1923,12 +2191,12 @@ all all all.aix.gnu64.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_aix_gnu64)" \ "CCx=$(CC_aix_gnu64)" \ "COPTIONS=$(COPTIONS_aix_gnu64) $(COPTIONSZlib_aix_gnu64)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED)" \ "PIC=$(PIC_aix_gnu64)" \ "CCx=$(CC_aix_gnu64)" \ @@ -1940,7 +2208,7 @@ all "AROPTIONS=$(AROPTIONS_aix64)" \ "RANLIB=$(RANLIB_aix)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(AND.$(CURSES).$(CURSES_$(OS)_$(ENV)))" \ "CCx=$(CC_aix_gnu64)" \ "COPTIONS=$(COPTIONS_aix_gnu64)" \ @@ -1948,7 +2216,7 @@ all "SYSLIBS=$(SYSLIBSexe_aix_gnu64)" \ "CURSESLIB=$(CURSESLIB_aix_gnu64)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_aix)" \ "CCx=$(CC_aix_gnu64)" \ @@ -1970,12 +2238,12 @@ all.mach.macosx: all.mach.macosx.build all.mach.gnu: note1.1st all.mach.gnu.build all.mach.next.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_mach_next)" \ "CCx=$(CC_mach_next)" \ "COPTIONS=$(COPTIONS_mach_next)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED_mach)" \ "PIC=$(PIC_mach_next)" \ "CCx=$(CC_mach_next)" \ @@ -1987,7 +2255,7 @@ all "AROPTIONS=$(AROPTIONS_mach)" \ "RANLIB=$(RANLIB_mach)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(CURSES_mach_next)" \ "CCx=$(CC_mach_next)" \ "COPTIONS=$(COPTIONS_mach_next)" \ @@ -1995,7 +2263,7 @@ all "SYSLIBS=$(SYSLIBSexe_mach_next)" \ "CURSESLIB=$(CURSESLIB_mach_next)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_mach)" \ "CCx=$(CC_mach_next)" \ @@ -2009,12 +2277,12 @@ all all all.mach.macosx.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_mach_macosx)" \ "CCx=$(CC_mach_macosx)" \ "COPTIONS=$(COPTIONS_mach_macosx)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED_mach)" \ "PIC=$(PIC_mach_macosx)" \ "CCx=$(CC_mach_macosx)" \ @@ -2026,7 +2294,7 @@ all "AROPTIONS=$(AROPTIONS_mach)" \ "RANLIB=$(RANLIB_mach)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(CURSES_mach_macosx)" \ "CCx=$(CC_mach_macosx)" \ "COPTIONS=$(COPTIONS_mach_macosx)" \ @@ -2034,7 +2302,7 @@ all "SYSLIBS=$(SYSLIBSexe_mach_macosx)" \ "CURSESLIB=$(CURSESLIB_mach_macosx)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_mach)" \ "CCx=$(CC_mach_macosx)" \ @@ -2048,12 +2316,12 @@ all all all.mach.gnu.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_mach_gnu)" \ "CCx=$(CC_mach_gnu)" \ "COPTIONS=$(COPTIONS_mach_gnu)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED_mach)" \ "PIC=$(PIC_mach_gnu)" \ "CCx=$(CC_mach_gnu)" \ @@ -2065,7 +2333,7 @@ all "AROPTIONS=$(AROPTIONS_mach)" \ "RANLIB=$(RANLIB_mach)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(CURSES_mach_gnu)" \ "CCx=$(CC_mach_gnu)" \ "COPTIONS=$(COPTIONS_mach_gnu)" \ @@ -2073,7 +2341,7 @@ all "SYSLIBS=$(SYSLIBSexe_mach_gnu)" \ "CURSESLIB=$(CURSESLIB_mach_gnu)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_mach)" \ "CCx=$(CC_mach_gnu)" \ @@ -2093,12 +2361,12 @@ all all.qnx.ccwat: note1.1st all.qnx.ccwat.build all.qnx.ccwat.build: - @cd $(LIBsrcZlibDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcZlibDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "PIC=$(PIC_qnx_ccwat)" \ "CCx=$(CC_qnx_ccwat)" \ "COPTIONS=$(COPTIONS_qnx_ccwat)" \ all - @cd $(LIBsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "SHARED=$(SHARED_qnx)" \ "PIC=$(PIC_qnx_ccwat)" \ "CCx=$(CC_qnx_ccwat)" \ @@ -2110,7 +2378,7 @@ all "AROPTIONS=$(AROPTIONS_qnx)" \ "RANLIB=$(RANLIB_qnx)" \ all - @cd $(TOOLSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "CURSES=$(CURSES_qnx_ccwat)" \ "CCx=$(CC_qnx_ccwat)" \ "COPTIONS=$(COPTIONS_qnx_ccwat)" \ @@ -2118,7 +2386,7 @@ all "SYSLIBS=$(SYSLIBSexe_qnx_ccwat)" \ "CURSESLIB=$(CURSESLIB_qnx_ccwat)" \ all - @cd $(TESTSsrcDIR); $(MAKE) MAKE=$(MAKE) \ + @cd $(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \ "FORTRAN=$(FORTRAN)" \ "FCx=$(FC_qnx)" \ "CCx=$(CC_qnx_ccwat)" \ @@ -2189,6 +2457,11 @@ show.posix.vax: show.supported show.posix.alphaD: show.supported show.posix.alphaG: show.supported show.posix.alphaI: show.supported +show.macosx.i386: show.supported +show.macosx.x86_64: show.supported +show.macosx.arm: show.supported +show.macosx.arm64: show.supported +show.macosx.arm32: show.supported show.supported: @echo SHARED is $(SUPPORTED.$(SHARED_$(OS))) @@ -2231,3 +2504,8 @@ note1.macx.no: note1.macx.yes: @$(NOOP) + +note1.macx.i386: + @echo + @echo Xcode version: $(XCODEVERSION) no longer supports i386 build... + @echo diff --git a/cdf36_3-dist/Note.1st b/cdf38_1-dist/Note.1st similarity index 90% rename from cdf36_3-dist/Note.1st rename to cdf38_1-dist/Note.1st index efb96f9..80f5fb7 100644 --- a/cdf36_3-dist/Note.1st +++ b/cdf38_1-dist/Note.1st @@ -4,7 +4,7 @@ The OS/ENV combination you have selected has not been tested. The options which will be used are based on previous experiences with the operating system being used. If an error occurs, don't panic, simply -contact us [GSFC-cdf-support@lists.nasa.gov]. The reason that your +contact us [NASA-CDF-Support@nasa.onmicrosoft.com]. The reason that your OS/ENV combination is not tested is probably because we no longer have a guest account on a machine having that particular OS/ENV combination. If you would like to offer us a guest account for testing purposes we diff --git a/cdf36_3-dist/Note.gcc b/cdf38_1-dist/Note.gcc similarity index 100% rename from cdf36_3-dist/Note.gcc rename to cdf38_1-dist/Note.gcc diff --git a/cdf36_3-dist/Note.intel b/cdf38_1-dist/Note.intel similarity index 100% rename from cdf36_3-dist/Note.intel rename to cdf38_1-dist/Note.intel diff --git a/cdf38_1-dist/Note.linux b/cdf38_1-dist/Note.linux new file mode 100644 index 0000000..f91b7bb --- /dev/null +++ b/cdf38_1-dist/Note.linux @@ -0,0 +1,22 @@ +If + $ make OS=linux ENV=gnu ... all + +fails due to missing ncurses that is used by a couple of tool programs, cdfedit +and cdfexport, you can do the following to install the ncurses (with root +authority): + + For Debian/Ubuntu based distributions, do + $ sudo apt install libncurses5-dev + For RPM based distributions, do + $ sudo dnf install ncurses-devel + +Or, you can do this to bypass the build of ncurses-based tools: + + $ make OS=linux ENV=gnu CURSES=no .... all + +Recommended/tested gcc: + Version 4.4.2 or later + +Recommended/tested gfortran: + Version 4.4.2 or later + diff --git a/cdf38_1-dist/Note.macosx b/cdf38_1-dist/Note.macosx new file mode 100644 index 0000000..392d0eb --- /dev/null +++ b/cdf38_1-dist/Note.macosx @@ -0,0 +1,16 @@ +To compile and link on Mac OS X 10.6, make the following changes to Makefile: + 1) Replace MacOSX10.5.sdk with MacOSX10.6.sdk + 2) Replace /usr/lib/gcc/powerpc-apple-darwin9 with + /usr/lib/gcc/powerpc-apple-darwin10 + +To compile and link on Mac OS X Big Sur + 1) Make sure that the Xcode is updated with v13 at later, depending on the + OS version. The Xcode should be placed at /Applications/Xcode.app folder. + 2) For gfortran, make sure its version is also updated. + https://github.com/fxcoudert/gfortran-for-macOS/releases/tag/11.2-bigsur-intel + If you encounter this error: + gfortran: error: unrecognized command line option ‘-fallow-argument-mismatch’ + it means the gfortran might be too old. Either upgrade the gfortran, or + edit the Makefile. Search for the line with ‘-fallow-argument-mismatch’ + option and remove this option from the line. + diff --git a/cdf36_3-dist/Note.noCC b/cdf38_1-dist/Note.noCC similarity index 100% rename from cdf36_3-dist/Note.noCC rename to cdf38_1-dist/Note.noCC diff --git a/cdf36_3-dist/Note.solaris b/cdf38_1-dist/Note.solaris similarity index 100% rename from cdf36_3-dist/Note.solaris rename to cdf38_1-dist/Note.solaris diff --git a/cdf36_3-dist/README.after_install b/cdf38_1-dist/README.after_install similarity index 95% rename from cdf36_3-dist/README.after_install rename to cdf38_1-dist/README.after_install index c3fd9d1..4f52f26 100644 --- a/cdf36_3-dist/README.after_install +++ b/cdf38_1-dist/README.after_install @@ -1,4 +1,4 @@ -This is the CDF V3.5.0 online software distribution directory for Unix +This is the CDF V3.8.1 online software distribution directory for Unix systems. This directory contains the following files: Welcome.txt The welcome information for the current version. @@ -32,7 +32,7 @@ README_cdf_tools.txt This file contains a description of the CDF tools that allow users to manipulate CDF files (e.g. CDFEdit, CDFExport, etc.) -Release.notes CDF 3.5.0 release notes. +Release.notes CDF 3.8.1 release notes. cdfjava This directory contains the CDF Java APIs, the JNI code, and example programs that demonstrate how to diff --git a/cdf36_3-dist/README.install b/cdf38_1-dist/README.install similarity index 91% rename from cdf36_3-dist/README.install rename to cdf38_1-dist/README.install index 4110851..c4477e3 100644 --- a/cdf36_3-dist/README.install +++ b/cdf38_1-dist/README.install @@ -1,4 +1,4 @@ - CDF Version 3.3.2, UNIX/POSIX Systems + CDF Version 3.8.1, UNIX/POSIX Systems Common Data Format (CDF) is a conceptual data abstraction for storing multi-dimensional data sets. The basic component of CDF is a software @@ -33,7 +33,7 @@ Manual, and the CDF Fortran Reference Manual. Requests for assistance or documentation should be sent to: - gsfc-cdf-support@lists.nasa.gov + NASA-CDF-Support@nasa.onmicrosoft.com If you get the distribution, please send CDFSUPPORT a message so we can put you on our mailing list. That way you will be notified of new releases. @@ -42,36 +42,36 @@ you on our mailing list. That way you will be notified of new releases. UNIX/POSIX Installation Instructions ------------------------------------ -CDF V3.3.2 is distributed for UNIX and POSIX systems as a gzipped compressed +CDF V3.8.1 is distributed for UNIX and POSIX systems as a gzipped compressed 'tar' file . -To uncompress cdf33_2-dist-all.tar.gz, cdf33_2-dist-cdf.tar.gz, -cdf33_2-dist-java.tar.gz, use the `gzip' command as follows... +To uncompress cdf38_1-dist-all.tar.gz, cdf38_1-dist-cdf.tar.gz, +cdf38_1-dist-java.tar.gz, use the `gzip' command as follows... gunzip -The resulting file will be named cdf33_2-dist-all.tar, cdf33_2-dist-cdf.tar, -or cdf33_2-dist-java.tar. +The resulting file will be named cdf38_1-dist-all.tar, cdf38_1-dist-cdf.tar, +or cdf38_1-dist-java.tar. Then use the `tar' command to extract the CDF source files. `tar' will create -a directory named `cdf33_2-dist' containing several subdirectories. The source +a directory named `cdf38_1-dist' containing several subdirectories. The source files for the distribution will be placed into these directories. The syntax for the `tar' command is different on some flavors of UNIX. For most UNIX systems (and the POSIX shell) use... - tar -xvf cdf33_2-dist-all.tar + tar -xvf cdf38_1-dist-all.tar For the IBM-RS6000/AIX use... - tar -x -v -f cdf33_2-dist-all.tar + tar -x -v -f cdf38_1-dist-all.tar CDF distribution has a makefile that automatically builds the CDF library and tools. The following steps should be taken to build and install CDF. 1. Set your current directory (cd) to the top level CDF directory - (the directory named `cdf33_2-dist' created by `tar'). + (the directory named `cdf38_1-dist' created by `tar'). 2. If desired, modify the include file named `cdfconfig.h' in the `src/include' directory to the desired default parameters for diff --git a/cdf36_3-dist/README.install_java_APIs b/cdf38_1-dist/README.install_java_APIs similarity index 97% rename from cdf36_3-dist/README.install_java_APIs rename to cdf38_1-dist/README.install_java_APIs index 371faf6..073baf1 100644 --- a/cdf36_3-dist/README.install_java_APIs +++ b/cdf38_1-dist/README.install_java_APIs @@ -1,4 +1,4 @@ - CDF Version 3.5.0, UNIX/POSIX Systems + CDF Version 3.8.1, UNIX/POSIX Systems The CDF distribution package now contains the CDF Java APIs, in addition to the existing C and Fortran APIs, to allow users to develop platform-independent @@ -31,10 +31,10 @@ Installation instructions of the CDF Java APIs cd $CDF_BASE 2. If you downloaded a tar file that contains both the CDF library and the - CDF Java APIs (i.e. cdf35_0-dist-all.tar), go to step 3. + CDF Java APIs (i.e. cdf38_1-dist-all.tar), go to step 3. - Untar the CDF Java APIs, cdf35_0-dist-java.tar, as follows: - tar xvf cdf35_0-dist-java.tar + Untar the CDF Java APIs, cdf38_1-dist-java.tar, as follows: + tar xvf cdf38_1-dist-java.tar 3. Set your current directory (cd) to the cdfjava/jni directory. diff --git a/cdf36_3-dist/README_cdf_tools.txt b/cdf38_1-dist/README_cdf_tools.txt similarity index 100% rename from cdf36_3-dist/README_cdf_tools.txt rename to cdf38_1-dist/README_cdf_tools.txt diff --git a/cdf36_3-dist/Release.notes b/cdf38_1-dist/Release.notes similarity index 54% rename from cdf36_3-dist/Release.notes rename to cdf38_1-dist/Release.notes index 99e6ae5..56792c6 100644 --- a/cdf36_3-dist/Release.notes +++ b/cdf38_1-dist/Release.notes @@ -1,16 +1,16 @@ /-----------------------------------/ -/ CDF V3.6.3.1 Release Notes / +/ CDF V3.8.1.0 Release Notes / /-----------------------------------/ 1. Compatibility with all CDF 3.*, 2.7.6 and earlier versions -CDF V3.6.3 is backward compatible with the previous versions of CDF, and it +CDF V3.8.1 is backward compatible with the previous versions of CDF, and it can read CDF files that were created with earlier versions. If a file was created with CDF 2.7 and read and modified by CDF 3.*, the resultant file will be saved in the CDF 2.7 format, not CDF 3.*. The same principle applies to files that were created with CDF 2.5 and 2.6. CDF -files that are created from scratch with CDF V3.6.3 are compatible in file +files that are created from scratch with CDF V3.7.1 are compatible in file structure with all CDF 3.*, but not compatible (due to a 64-bit file offsets used since CDF 3.0 versions) with CDF 2.7.2 or earlier, and an attempt to read CDF 3.* files from CDF 2.7.2 or earlier will produce an error. Since a @@ -35,11 +35,64 @@ to that release. 2. Changes -The following changes have been made/added in V3.6.3.*: - +The following changes have been made/added in V3.8.1.* and prior versions: + + * Added support for ARM processor for Apple iOS (silicone) and other + platforms. + * The dynamic memory is no longer placed into a linked list. + * Added a couple of attribute entry read/write functions for string in + expanded standard interface. + * Allowed characters in UTF-8 encoding to be handled by the CDF. + * Allowed building fat JNI library from the main CDF build. + * Modified TT2000 type handling routine in C/Java to accept reverse leap + second (no 59 second) in the future. + * Added Json-CDF converters in Java package. + * Enhanced netCDF-to-CDF converter. + * Added a set of quick read functions/methods: READCDF and READVARIABLE, + to Java, Perl, C# and IDL interface to read CDF/Variable information in a + single call. + * Modified the CDF epoch breakdown functions that might cause incorrect + day being returned. + * Added a new option "-advformat" to tool program skeletontable to manage + how FORMAT attribute is used to encode the data and metadata. This option + will show data with more precision in the skeleton table. + * Modified code to use FILLVAL to fill the missing data if it exists, instead + of the pad value. + * String typed variable's pad value will only hold a single space and then + followed by NULs, instead of all spaces (for the number of elements). + * Modified skeletoncdf program to handle skeleton table with hidden character + carriage-return (\r) made from Windows. + * Added a few features to cdfconvert tool program. + * Added a few features to cdfconvert tool program. + * Modified skt2cdf to allow processing a skeleton table made in Windows + * to be used on non-Windows systems. + * Upgrade the zlib package to V2.1.11, which has code improvements and bug + * fixed. + * Added a set of time conversion functions between CDF_EPOCH, CDF_EPOCH16 + and CDF_TIME_TT2000 time and unix time. + * Added a new, general set of epoch encoding (toEncodexxxx) and parsing + toParsexxxx functions (where xxxx is EPOCH, EPOCH16 or TT2000) for each + of the CDF epoch data type. + * Expanded the CDF XML schema and allowed special characters used in + name. + * Encoded CDF epoch data in ISO8601 format, except skeleton table. + * Added ARM port. + * Added IA64 OpenVMS. + * Allowed Nul-terminting string data for attribute and variable data. + * Allowed multi-strings for variable attribute entries. + * Skip checksum verification if the data validation is turned off. + * Added cdfj.jar, the pure Java APIs that can read/write CDFs without + needing the CDF library and JNI. + * Revised the CDF schema to support new features. + * For Unix-based systems, "mkstemp" function is used to create the + temporary file in the template form of "mycdftmp.XXXXXX". + * For Unix-based systems, if CDF_TEMP is not defined, the temporary files + are created on the current directory (pwd), if it is writable. Otherwise, + environment variable: TMPDIR is used if it is defined. Otherwise, /tmp + directory is used. * If adding data to a master file to create a new CDF, the leap second last updated header field is updated with the information from the leap second - table. + table if the data is of TT2000 data type. * Added a new leap second for 1/1/2017. * Added a new set of CDFread functions that will allocate the needed space for the user. It is user's responsiblility to free the space after @@ -84,21 +137,21 @@ Please refer to CHANGES.txt for the detailed code changes in various versions. The CDF documentation set consists of the following: - cdf363ug.pdf (CDF User's Guide) - cdf363crm.pdf (CDF C Reference Manual) - cdf363frm.pdf (CDF Fortran Reference Manual) - cdf363prm.pdf (CDF Perl Reference Manual) - cdf363jrm.pdf (CDF Java Reference Manual) - cdf363csrm.pdf (CDF C# Reference Manual) - cdf363vbrm.pdf (CDF Visual Basic Reference Manual) - cdf36ifd.pdf (CDF Internal Format Description) + cdf381ug.pdf (CDF User's Guide) + cdf381crm.pdf (CDF C Reference Manual) + cdf381frm.pdf (CDF Fortran Reference Manual) + cdf381prm.pdf (CDF Perl Reference Manual) + cdf381jrm.pdf (CDF Java Reference Manual) + cdf381csrm.pdf (CDF C# Reference Manual) + cdf381vbrm.pdf (CDF Visual Basic Reference Manual) + cdf38ifd.pdf (CDF Internal Format Description) These documents are available from the CDF home page (http://cdf.gsfc.nasa.gov). We have a user support office for CDF that you can contact when you need an assistance. For requests, please send emails to: - Internet -- gsfc-cdf-support@lists.nasa.gov + Internet -- NASA-CDF-Support@nasa.onmicrosoft.com Please let us know (via an email to CDFSUPPORT) if you get the distribution. We would like to know who has the distribution so we know who to contact diff --git a/cdf36_3-dist/Welcome.txt b/cdf38_1-dist/Welcome.txt similarity index 70% rename from cdf36_3-dist/Welcome.txt rename to cdf38_1-dist/Welcome.txt index e8ec02b..5ed4524 100644 --- a/cdf36_3-dist/Welcome.txt +++ b/cdf38_1-dist/Welcome.txt @@ -1,4 +1,4 @@ -This is the latest CDF V3.6.3 distribution package that contains everything +This is the latest CDF V3.8.1 distribution package that contains everything CDF offers except for the CDF Perl and C# APIs, and it contains the following items: @@ -6,5 +6,5 @@ items: - C and Java version of the CDF tools. If you have any questions or comments, please send an email to -gsfc-cdf-support@lists.nasa.gov. +NASA-CDF-Support@nasa.onmicrosoft.com diff --git a/cdf36_3-dist/cdfjava/JavaAPIs.txt b/cdf38_1-dist/cdfjava/JavaAPIs.txt similarity index 51% rename from cdf36_3-dist/cdfjava/JavaAPIs.txt rename to cdf38_1-dist/cdfjava/JavaAPIs.txt index ad78645..f18cfb1 100644 --- a/cdf36_3-dist/cdfjava/JavaAPIs.txt +++ b/cdf38_1-dist/cdfjava/JavaAPIs.txt @@ -1,2 +1,2 @@ Documentation for the CDF Java APIs can be found at -http://cdf.gsfc.nasa.gov/cdfjava_doc/index.html +https://cdf.gsfc.nasa.gov/cdfjava_doc/index.html diff --git a/cdf38_1-dist/cdfjava/cdfjson/AAREADME.1ST b/cdf38_1-dist/cdfjava/cdfjson/AAREADME.1ST new file mode 100644 index 0000000..c7bd2d9 --- /dev/null +++ b/cdf38_1-dist/cdfjava/cdfjson/AAREADME.1ST @@ -0,0 +1,12 @@ +Files in the cdfjson.tar archive... +----------------------------------------------------------- + +cdfjson.jar: The Java archive file that contains CDF2Json, Json2CDF and + CDFJsonReader Java tool programs. This file is located in + lib directory. + +AAREADME.1ST: This is file that you are browsing. + +Readme.txt: This file contains the information on how to install and + run the Java-based CDF-Json conveter programs. + diff --git a/cdf38_1-dist/cdfjava/cdfjson/CDF2Json.java b/cdf38_1-dist/cdfjava/cdfjson/CDF2Json.java new file mode 100644 index 0000000..5c23a46 --- /dev/null +++ b/cdf38_1-dist/cdfjava/cdfjson/CDF2Json.java @@ -0,0 +1,2075 @@ +/***************************************************************************** +* Copyright 1996-2013 United States Government as represented by the +* Administrator of the National Aeronautics and Space Administration. +* All Rights Reserved. +******************************************************************************/ + +import java.io.*; +import java.text.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import gsfc.nssdc.cdf.*; +import gsfc.nssdc.cdf.util.*; +import javax.json.*; + +/**************************************************************************** + Description: + This program exports the contents of a CDF file(s) into a Json file + + For single CDF file, the file is specified at the last of the auguments. + The name of the input CDF file is used as the default output file name. + Alternatively, use "fileNames" option to specify the CDf file(s) for + conversions. + + Usage: java CDF2Json [Options] [cdfFileName] + + Options: + + -fileNames:fileNames + fileNames: specifies a text file that contains the names of CDF files + for converting into a single Json file. + If this option is used, there is no need for entering + cdfFileName + + -globalAttrs:[yes | no] -globalAttrs:yes is the default. + -globalAttrs:yes extracts all global attributes + -globalAttrs:no doesn't extract global attributes + + -varAttrs:[yes | no] -varAttrs:yes is the default. + -varAttrs:yes extracts each variable's attributes + -varAttrs:no doesn't extract each variable's attributes + + -vars:var1,var2,... + -vars:var1,var2,... extracts only the specified variables with + variable names separated by a single comma + + -varData:[yes | no] -varData:yes is the default. + -varData:yes extracts each variable's data + -varData:no doesn't extract each record-varying variable's data + + -output:[outputFileName | STDOUT] + outputFileName: The output Json file name. An extension of ".json" + is appended if it is not specified. If this option is + not specified, the input cdfFileName for a single file + or fileNmaes for a group of files is used for the + output Json file name. + -output:STDOUT displays the Json output on the screen. + + -format:[yes | no | prefer] -format:prefer is the default. + -format:yes uses the variable's FORMAT attribute to encode the data + -format:prefer uses the variable's FORMAT attribute to encode the data + However, if the FORMAT is not properly defined, it is + not used. + -format:no uses the general Java data encoding form + + -encodeepoch:[yes | no] -encodeepoch:yes is the default. + -encodeepoch:yes encodes the CDF epoch data + -encodeepoch:no shows the CDF epoch data in its original form + + -[showProgress | Progress] + This option displays the processing progress on the screen. + It shows how many CDF variables are there to process and which + variable is being processed. + + -withZ + This option works with CDF epoch data by adding an extra "Z" to + the end of date/time of ISO 8601 form. + + -delete + Over-ride the existing Json file. + + -debug + Display the specifications to run the application. + + -nofullpath + Specifies to use only the file name portion of the entered path name + for each CDF in the Json file. + + -showfile + Specifies to display the CDF file name(s) being processed. + + The Json file, produced from CDF2Json class, has the following form. It + differs slightly from the origial converter, which only handled a single + CDF. The CDFname is a part in CDFFileInfo attribute. + +
 
+ CDFname1:    <== CDF file name key
+   CDFFileInfo:
+     FileVersion:.....
+     Format:.....
+     Majority:...
+     Encoding:.....
+   CDFglobalAttributes:
+     Gattr_name1:
+       entry#:value
+       ...
+       ...
+     Gattr_name2:
+       entry#:value
+       ...
+       ...
+   ...
+   ...
+   CDFVariables:
+     VarName1:  <== Variable name key
+       VarDescription:
+         DataType:....
+         ...
+         ...
+       VarAttributes:
+         VALIDMIN:....
+         VALIDMAX:....
+         ...
+         ...
+       VarData:
+       ...
+     VarName2:
+       VarDescription:
+         DataType:....
+         ...
+         ...
+       VarAttributes:
+         VALIDMIN:....
+         VALIDMAX:....
+         ...
+         ...
+       VarData:
+         ...
+   EmptyAttributes:  <== Exists if there are defined attributes but no values
+     GlobalAttributes: [...]
+     VariableAttributes: [...]
+
+ CDFname2:
+   ...
+   ...
+ ... 
+ ...
+ 
+ + This class is based on JNI-based cdfjava.jar and javax.json.jar. + + HISTORY: + Jan 30, 2022 Mike Liu Initial version. + *****************************************************************************/ + +public class CDF2Json implements CDFConstants { + + private static CDF cdf = null; + private static boolean debug = false; + + private static String inFile = null, /* Input file name */ + outFile = null, /* Output file name */ + varData = "yes", /* Extract variable data */ + globalAttrs = "yes",/* Extract global attributes */ + format = "prefer", /* Use FORMAT attribute */ + encodeEpoch = "yes",/* Encode epoch data */ + varAttrs = "yes"; /* Extract variable attributes */ + + private static boolean showProgress = false; + private static boolean withz = false; + private static boolean delete = false; + private static boolean fullpath = true; + private static boolean encodeEp = true; + private static boolean showfile = false; + private static JsonObjectBuilder CDFJsonObject0 = Json.createObjectBuilder(); + private static JsonObjectBuilder CDFJsonObject = null; + private static int varCount = -1; + private static String[] varNames; + private static String[] fileNames = null; + private static int numFiles = 0; + private static String item0 = "CDF"; + private static String item1 = "CDFFileInfo"; + private static String item2 = "CDFglobalAttributes"; + private static String item3 = "CDFVariables"; + private static String item4 = "VarDescription"; + private static String item5 = "VarAttributes"; + private static String item6 = "VarData"; + private static String item7 = "EmptyAttributes"; + private static String item8 = "GlobalAttributes"; + private static String item9 = "VariableAttributes"; + private static String separator = System.getProperty("file.separator"); +private static long numDimsN; + public static void main(String[] args) throws Exception { + + try { + parseCmdLine(args); + + if (outFile == null) + outFile = getDefaultOutputFileName(); + + if (!delete) { + if (new File(outFile).exists()) { + System.out.println("ERROR... output file:"+outFile+ + " already exists. "); + System.exit(1); + } + } + int ix; + for (ix = 0; ix < numFiles; ++ix) { + String originalInputFilename = fileNames[ix]; + if (showfile) System.out.println(fileNames[ix]); + cdf = CDF.open(originalInputFilename, READONLYoff); + + CDFJsonObject = Json.createObjectBuilder(); + JsonArrayBuilder two = printCDFFileInfo(originalInputFilename); + if (two != null) + CDFJsonObject.add (item1, two); + + if (globalAttrs.equalsIgnoreCase("yes")) { + JsonArrayBuilder three = printGlobalAttributes(); + + if (three != null) + CDFJsonObject.add (item2, three); + } + + JsonArrayBuilder four = printVariables(); + if (four != null) + CDFJsonObject.add (item3, four); + + JsonArrayBuilder five = printEmptyAttributes(); + if (five != null) + CDFJsonObject.add (item7, five); + + cdf.close(); + + String cdfnameKey = null; + if (fullpath) + cdfnameKey = (!originalInputFilename.endsWith(".cdf") && + !originalInputFilename.endsWith(".CDF")) ? + originalInputFilename+".cdf" : + originalInputFilename; + else { + int loc = originalInputFilename.lastIndexOf(separator); + if (loc == -1) + cdfnameKey = (!originalInputFilename.endsWith(".cdf") && + !originalInputFilename.endsWith(".CDF")) ? + originalInputFilename+".cdf" : + originalInputFilename; + else { + String filenamex = originalInputFilename.substring(loc+1); + cdfnameKey = (!filenamex.endsWith(".cdf") && + !filenamex.endsWith(".CDF")) ? + filenamex+".cdf" : filenamex; + } + } + CDFJsonObject0.add (cdfnameKey, CDFJsonObject); + } + OutputStream os = new FileOutputStream(outFile); + JsonWriter jsonWriter = Json.createWriter(os); + jsonWriter.writeObject(CDFJsonObject0.build()); + jsonWriter.close(); + + } catch (Exception e) { + if (cdf != null) cdf.close(); + System.out.println ("Exception occurred in main.\n"+e); + } + } + + + /*********************************************************/ + /* Parse the command line input that is in the form of */ + /* java CDF2Json [Options] cdfFileName */ + /* */ + /* See the top of this file for a detailed description */ + /* of the Options. */ + /*********************************************************/ + private static void parseCmdLine (String[] args) { + String numSpaces = null; + int which = 0; + String[] tmpArr = new String[100]; + + if (args.length == 0) // No input is given (i.e. java CDF2Json) + exit(""); + + else { // Process options + for (int i=0; i < args.length; i++) { + if (args[i].indexOf(":") == -1 && + args[i].charAt(0) != '-') { + if (which == 0) which = 1; + if (which == 1) { + tmpArr[numFiles] = args[i]; + ++numFiles; + if (!CDFUtils.cdfFileExists(args[i])) { + System.out.println ("** Error: file '"+args[i]+ + "' does not exist **"); + System.exit (1); + } + if (numFiles == 1) inFile = args[i]; + continue; + } else { + System.out.println("** Error: File(s) already specified"+ + " in option \"fileNames\"..."); + System.exit(1); + } + } + int loc = args[i].indexOf(":"); + if (args[i].toLowerCase().startsWith("-filenames:")) { + if (which == 0) which = 2; + if (which == 2) { + String fileTxt = args[i].substring(loc+1); + if (fileTxt.toLowerCase().endsWith(".txt")) + inFile = fileTxt.substring(0, fileTxt.length()-4); + else if (fileTxt.toLowerCase().endsWith(".text")) + inFile = fileTxt.substring(0, fileTxt.length()-5); + else + inFile = fileTxt; + readFileNames (fileTxt); + } else { + System.out.println("** Error: File(s) already "+ + "specified in the command line..."); + System.exit(1); + } + } + else if (args[i].toLowerCase().startsWith("-vardata:")) { + varData = args[i].substring(loc+1); + if (!varData.equalsIgnoreCase("yes") && + !varData.equalsIgnoreCase("no")) + exit("** Error: Invalid -varData entered **"); + } + else if (args[i].toLowerCase().startsWith("-globalattrs:")) { + globalAttrs = args[i].substring(loc+1); + if (!globalAttrs.equalsIgnoreCase("yes") && + !globalAttrs.equalsIgnoreCase("no")) + exit("** Error: Invalid -globalattrs entered **"); + } + else if (args[i].toLowerCase().startsWith("-varattrs:")) { + varAttrs = args[i].substring(loc+1); + if (!varAttrs.equalsIgnoreCase("yes") && + !varAttrs.equalsIgnoreCase("no")) + exit("** Error: Invalid -varattrs entered **"); + } + else if (args[i].toLowerCase().startsWith("-format:")) { + format = args[i].substring(loc+1); + if (!format.equalsIgnoreCase("yes") && + !format.equalsIgnoreCase("no") && + !format.equalsIgnoreCase("prefer")) + exit("** Error: Invalid -format entered **"); + } + else if (args[i].toLowerCase().startsWith("-encodeepoch:")) { + encodeEpoch = args[i].substring(loc+1); + if (!encodeEpoch.equalsIgnoreCase("yes") && + !encodeEpoch.equalsIgnoreCase("no")) + exit("** Error: Invalid -encodeepoch entered **"); + else { + if (encodeEpoch.equalsIgnoreCase("no")) + encodeEp = false; + } + } + else if (args[i].toLowerCase().startsWith("-vars:")) { + String names = args[i].substring(6); + int e; + varCount = 1; + for (e = 0; e < names.length(); e++) { + if (names.charAt(e) == ',') varCount++; + } + varNames = new String[varCount]; + StringBuffer tmp = new StringBuffer(names); + for (e = 0; e < varCount; ++e) { + int dstr = tmp.indexOf(","); + if (dstr != -1) { + varNames[e] = tmp.substring(0, dstr).toString(); + tmp = new StringBuffer(tmp.substring(dstr+1)); + } else { + varNames[e] = new String(tmp); + } + } + } + else if (args[i].toLowerCase().startsWith("-output:") || + args[i].toLowerCase().startsWith("-json:")) { + outFile = args[i].substring(loc+1); + if (outFile.equalsIgnoreCase("stdout")) + outFile = "STDOUT"; + else { + if (!outFile.toLowerCase().endsWith(".json")) + outFile = outFile + ".json"; + } + } + else if (args[i].equalsIgnoreCase("-showprogress") || + args[i].equalsIgnoreCase("-progress")) { + showProgress = true; + } + else if (args[i].equalsIgnoreCase("-withz")) { + withz = true; + } + else if (args[i].toLowerCase().startsWith("-debug")) { + debug = true; + } + else if (args[i].equalsIgnoreCase("-delete")) { + delete = true; + } + else if (args[i].equalsIgnoreCase("-nofullpath")) { + fullpath = false; + } + else if (args[i].equalsIgnoreCase("-showfile")) { + showfile = true; + } + else { + exit ("** Error: Invalid option entered **"); + } + } + } + if (debug) { + for (int i=0; i < args.length; i++) + System.out.println ("args["+i+"] = "+args[i]); + System.out.println ("inFile="+inFile+", outputFile="+outFile+ + ", globalattrs= "+globalAttrs+ + ", varAttrs= "+varAttrs+ + ", vars= all"+ + ", vardata= "+varData+ + ", showProgress="+showProgress+ + ", withz="+withz+ + ", showfile="+showfile+ + ", delete="+delete); + } + + if (inFile == null) exit ("** Error: CDF file name not specified **"); + + if (which == 1) { + fileNames = new String[numFiles]; + System.arraycopy(tmpArr, 0, fileNames, 0, numFiles); + } + + } + + + /************************************************************************ + * If a compression is specified, print the compression type and its + * compression level. The compression level is printed only if + * the compression method is GZIP. + ************************************************************************/ + private static String printCompression (long cType, + long[] compressionLevel) { + if (cType != CDFConstants.NO_COMPRESSION) { + String compression = CDFUtils.getStringCompressionType(cType); + if (cType != CDFConstants.GZIP_COMPRESSION) + return compression; + else + return compression+"."+compressionLevel[0]; + } else + return null; + } + + + /************************************/ + /* Print the CDF file information */ + /************************************/ + private static JsonArrayBuilder printCDFFileInfo (String theFile) { + try { + String version = cdf.getVersion(); + String fileFormat = CDFUtils.getStringFormat(cdf); + String majority = CDFUtils.getStringMajority(cdf); + String encoding = CDFUtils.getStringEncoding(cdf); + String checksum = CDFUtils.getStringChecksum(cdf); + long lastUpdated = CDFUtils.getLeapSecondLastUpdated(cdf); + + JsonArrayBuilder infos = Json.createArrayBuilder(); + + JsonObjectBuilder versionO = Json.createObjectBuilder(). + add("FileVersion", version); + infos.add(versionO.build()); + + JsonObjectBuilder formatx = Json.createObjectBuilder().add("Format", + fileFormat); + infos.add(formatx.build()); + + long cType = cdf.getCompressionType(); + long[] compressionLevel = cdf.getCompressionParms(); + String comp = printCompression(cType, compressionLevel); + if (comp != null) { + JsonObjectBuilder compress = Json.createObjectBuilder(). + add("Compression", comp); + infos.add(compress.build()); + } + + JsonObjectBuilder majorityO = Json.createObjectBuilder(). + add("Majority", majority); + infos.add(majorityO.build()); + + JsonObjectBuilder encodingO = Json.createObjectBuilder(). + add("Encoding", encoding); + infos.add(encodingO.build()); +/* + long negToPosFp0 = cdf.confirmNegtoPosfp0(); + String enable; + if (negToPosFp0 == CDFConstants.NEGtoPOSfp0on) + enable = "ENABLE"; + else + enable = "DISABLE"; + JsonObjectBuilder negToPosFp = Json.createObjectBuilder(). + add("NegToPosFp0", enable); + infos.add(negToPosFp.build()); + + if (!checksum.equalsIgnoreCase("none") && + !checksum.equalsIgnoreCase("other")) { + JsonObjectBuilder chksum = Json.createObjectBuilder(). + add("checksum", checksum); + infos.add(chksum.build()); + } + + if (lastUpdated > -1) { + long yy, mm, dd; + yy = (long) (lastUpdated / 10000); + mm = (long) ((lastUpdated - yy * 10000) / 100); + dd = lastUpdated - yy * 10000 - mm * 100; + JsonObjectBuilder leap = Json.createObjectBuilder().add( + "LeapsecondLastUpdated",yy+"-"+ + (mm<10?"0":"")+mm+"-"+(dd<10?"0":"")+dd); + infos.add(leap.build()); + } +*/ + return infos; + + } catch (Exception e) { + System.out.println ("** Error occurred in printCDFFileInfo"); + System.out.println (e); + System.exit (1); + } + return null; + } + + + /*************************************/ + /* Print the CDF global attributes */ + /*************************************/ + private static JsonArrayBuilder printGlobalAttributes () { + try { + Attribute a = null; + String attrName = null; + int i; + long numAttrs = cdf.getNumGattrs(); + Vector ga = cdf.getGlobalAttributes(); + + if (numAttrs > 0) { + JsonArrayBuilder entries = Json.createArrayBuilder(); + JsonArrayBuilder globals = Json.createArrayBuilder(); + for (Enumeration e = ga.elements() ; e.hasMoreElements() ;) { + a = (Attribute) e.nextElement(); + attrName = a.getName(); + long n = a.getNumEntries(); + if (n == 0) continue; + Vector ent = a.getEntries(); + int iflag; + for (Enumeration e1=ent.elements(); e1.hasMoreElements();) { + Entry entry = (Entry) e1.nextElement(); + if (entry != null) { + long eDataType = entry.getDataType(); + long eNumElems = entry.getNumElements(); + Object data = entry.getData(); + if (eDataType == CDF_EPOCH) iflag = 1; + else if (eDataType == CDF_EPOCH16) iflag = 2; + else if (eDataType == CDF_TIME_TT2000) iflag = 3; + else iflag = 0; + String entryID = String.valueOf(entry.getID()); + JsonObjectBuilder entryO = Json.createObjectBuilder(); + entryO = (JsonObjectBuilder) printSingleData ( + (Object) entryO, entryID, data, + eDataType, eNumElems, -1, + (withz?"Z":""), null, null, false); + entries.add(entryO.build()); + } + } + JsonObjectBuilder global1 = Json.createObjectBuilder(). + add(attrName, entries); + globals.add(global1.build()); + } + return globals; + } + + } catch (Exception e) { + System.out.println ("** Error occurred in printGlobalAttributes"); + System.out.println (e); + System.exit (1); + } + return null; + } + + + /************************************************************************* + * Print the following information for each variable in a CDF file: + * - variable information (e.g. dimensionality, dimesnion sizes, etc.) + * - variable attributes + * - variable data + ************************************************************************/ + private static JsonArrayBuilder printVariables () { + + long numVars = 0; + Variable v = null; + + try { + int i = 1; + numVars = cdf.getNumVars(); + + if (numVars > 0) { + JsonArrayBuilder variables = Json.createArrayBuilder(); + + Vector vars = cdf.getVariables(); + String cFormat = null; + + for (Enumeration e = vars.elements() ; e.hasMoreElements() ;) { + v = (Variable) e.nextElement(); + String varName = v.getName(); + Object fillVal = null; + if (!format.toLowerCase().equals("no")) { + String formatA; + try { + String format0 = (String) v.getEntryData("FORMAT"); + if (format0.trim().length() == 0) formatA = null; + else formatA = format0.trim(); + } catch (CDFException xx) { + formatA = null; + } + if (formatA != null) cFormat = toCformat(formatA); + } + try { + fillVal = v.getEntryData("FILLVAL"); + } catch (CDFException xx) { + try { + fillVal = v.getPadValue(); + } catch (CDFException xy) { + fillVal = null; + } + } + boolean toPrint = true; + if (varCount > 0) { + toPrint = false; + for (int jj = 0; jj < varCount; ++jj) { + if (varName.equals(varNames[jj])) { + toPrint = true; + break; + } + } + } + if (toPrint) { + if (showProgress) { + long maxRec = v.getMaxWrittenRecord() + 1; + System.out.print ("Variable "+i+": "+varName+" of "+ + (varCount>0?varCount:numVars)+ + " ("+(maxRec<10?" ":"")+maxRec+ + " records): "); + i++; + } + JsonArrayBuilder variable = Json.createArrayBuilder(); + JsonObjectBuilder variableO = Json.createObjectBuilder(); + JsonArrayBuilder one = printVarInfo(v, cFormat); + if (one != null) + variable.add(Json.createObjectBuilder(). + add(item4, one).build()); + if (varAttrs.equalsIgnoreCase("yes")) { + JsonArrayBuilder two = printVarAttributes(v, cFormat, + fillVal); + if (two != null) + variable.add(Json.createObjectBuilder(). + add(item5, two).build()); + } + if (varData.equalsIgnoreCase("yes") || + !(v.getRecVariance())) { + JsonArrayBuilder three = printVarData(v, cFormat, + fillVal); + if (three != null) + variable.add(Json.createObjectBuilder(). + add(item6, three).build()); + } +// variableO.add("Variable", variable); + variableO.add(varName, variable); + variables.add(variableO); + } + } + return variables; + } + + } catch (Exception e) { + System.out.println ("** Error occurred in printVariables"); + System.out.println ("** # of variables: "+numVars); + System.out.println ("** variable: "+v.getName()); + System.out.println (e); + System.exit (1); + } + return null; + } + + + /************************************************************************* + * Print the CDF variable information. + ************************************************************************/ + private static JsonArrayBuilder printVarInfo (Variable v, String formatV) { + try { + String recVariance, sparseRecord, variance; + int i; + long dataType, numDims, numElements, blockingFactor; + long numRecords, maxWrittenRec; + long[] dimSizes = {1L}, dimVariances; + Object padValue = null; + String varName, strDataType; + + JsonArrayBuilder infos = Json.createArrayBuilder(); +/* + varName = v.getName(); + JsonObjectBuilder vn = Json.createObjectBuilder(). + add("VarName",varName); + infos.add (vn.build()); + if (showProgress) { + System.out.print (varName); + } +*/ + dataType = v.getDataType(); + strDataType = CDFUtils.getStringDataType(dataType); + JsonObjectBuilder vd = Json.createObjectBuilder(). + add("DataType",strDataType); + infos.add (vd.build()); + if (showProgress) { + if (v.getName().length() < 9) + System.out.print ("\t\t"+strDataType+"/"); + else + System.out.print ("\t"+strDataType+"/"); + } + + numElements = v.getNumElements(); + JsonObjectBuilder ne = Json.createObjectBuilder(). + add("NumElements",numElements); + infos.add (ne.build()); + if (showProgress) { + System.out.print (numElements); + if (dataType == CDF_TIME_TT2000) System.out.print (" "); + else System.out.print ("\t"); + } + + numDims = v.getNumDims(); + dimSizes = v.getDimSizes(); + dimVariances = v.getDimVariances(); + +// long numDimsN; + long[] dimSizesN = new long[(int)CDF_MAX_DIMS]; + numDimsN = 0; + for (i = 0; i < numDims; i++) { + if (dimVariances[i] == CDFConstants.VARY && + dimSizes[i] > 1) { + dimSizesN[(int)numDimsN] = dimSizes[i]; + ++numDimsN; + } + } + JsonObjectBuilder nd = Json.createObjectBuilder(). + add("NumDims",numDimsN); + infos.add (nd.build()); + if (showProgress) + System.out.print (numDimsN+":["); + if (numDimsN > 0) { + JsonObjectBuilder ds = Json.createObjectBuilder(); + JsonArrayBuilder dsO = Json.createArrayBuilder(); + for (i=0; i < numDimsN; i++) { + if (i > 0) { + if (showProgress) + System.out.print (","); + } + dsO.add(dimSizesN[i]); + if (showProgress) + System.out.print (dimSizesN[i]); + } + ds.add("DimSizes",dsO); + infos.add (ds.build()); + } + if (showProgress) + System.out.print ("] "+(numDims==0?" ":"")); + + recVariance = v.getRecVariance() ? "VARY" : "NOVARY"; + JsonObjectBuilder rv = Json.createObjectBuilder(). + add("RecVariance",recVariance); + infos.add (rv.build()); + if (showProgress) { + if (recVariance.equalsIgnoreCase("vary")) + System.out.print ("T/"); + else + System.out.print ("F/"); + } + + if (numDimsN > 0) { + JsonObjectBuilder dv = Json.createObjectBuilder(); + JsonArrayBuilder dvO = Json.createArrayBuilder(); + for (i=0; i < numDimsN; i++) { + dvO.add("VARY"); + if (showProgress) { + System.out.print ("T"); + } + } + dv.add("DimVariances",dvO); + infos.add (dv.build()); + } + + if (showProgress) System.out.println (""); + + long cType = v.getCompressionType(); + long[] compressionLevel = v.getCompressionParms(); + String comp = printCompression (cType, compressionLevel); + if (comp != null) { + JsonObjectBuilder compO = Json.createObjectBuilder(). + add("Compression",comp); + infos.add (compO.build()); + } + + numRecords = v.getNumWrittenRecords(); + sparseRecord = CDFUtils.getStringSparseRecord(v); + if (sparseRecord.equalsIgnoreCase("none")) { + if (numRecords > 0) { + JsonObjectBuilder nw = Json.createObjectBuilder(). + add("NumWrittenRecords", + numRecords); + infos.add (nw.build()); + } + } + else { + maxWrittenRec = v.getMaxWrittenRecord(); + JsonObjectBuilder sr = Json.createObjectBuilder(). + add("SparseRecords",sparseRecord); + infos.add (sr.build()); + JsonObjectBuilder nw = Json.createObjectBuilder(). + add("NumWrittenRecords",numRecords); + infos.add (nw.build()); + JsonObjectBuilder mw = Json.createObjectBuilder(). + add("MaxWrittenRec",maxWrittenRec); + infos.add (mw.build()); + + } + + if (v.checkPadValueExistence()) { // Pad value has been defined + JsonObjectBuilder pv = Json.createObjectBuilder(); + padValue = v.getPadValue(); + pv = (JsonObjectBuilder) printSingleData ((Object)pv, + "PadValue", padValue, dataType, + numElements, -1, (withz?"Z":""), + formatV, null, false); + infos.add (pv.build()); + } + + blockingFactor = v.getBlockingFactor(); + if (blockingFactor > 0) { + JsonObjectBuilder bf = Json.createObjectBuilder(). + add("BlockingFactor",blockingFactor); + infos.add (bf.build()); + } + return infos; + + } catch (Exception e) { + System.out.println ("** Error occurred in printVariables"); + System.out.println (e); + System.exit (1); + } + return null; + } + + + /************************************************************************* + * Print the CDF variable attributes + ************************************************************************/ + private static JsonArrayBuilder printVarAttributes (Variable v, + String formatT, + Object fillVal) { + Attribute a = null; + Entry entry = null; + String attrName = null; + + try { + /************************************************************** + Check and see if there are any variable attributes that + are associated with the passed Variable. + **************************************************************/ + Vector va = v.getAttributes(); + if (va.size() == 0) return null; + long vDataType = v.getDataType(); + /*******************************************/ + /* Process and print variable attributes */ + /*******************************************/ + JsonArrayBuilder entries = Json.createArrayBuilder(); + for (Enumeration e=va.elements(); e.hasMoreElements();) { + a = (Attribute) e.nextElement(); + attrName = a.getName(); + try { + entry = a.getEntry(v); + if (entry != null) { + long eDataType = entry.getDataType(); + long eNumElements = entry.getNumElements(); + Object data = entry.getData(); + JsonObjectBuilder entryO = Json.createObjectBuilder(); + entryO = (JsonObjectBuilder) printSingleData ( + (Object)entryO, attrName, data, + eDataType, eNumElements, vDataType, + (withz?"Z":""), formatT, fillVal, + false); + entries.add (entryO.build()); + } + } catch (CDFException ex) { + } + } + return entries; + + + } catch (Exception e) { + System.out.println ("** Error occurred in printVarAttributes"); + System.out.println ("attr= "+attrName+" entry ="+entry.getName()); + System.out.println (e); + System.exit (1); + } + return null; + } + + + /************************************************************************* + * Print the empty attributes. + ************************************************************************/ + private static JsonArrayBuilder printEmptyAttributes () { + + Vector gAttributes = cdf.getGlobalAttributes(); + Vector vAttributes = cdf.getVariableAttributes(); + JsonArrayBuilder eattrs = null; + JsonArrayBuilder gattrs = null; + JsonArrayBuilder vattrs = null; + + int ix; + ix = 0; + for (Enumeration e=gAttributes.elements(); e.hasMoreElements();) { + Attribute a = (Attribute)e.nextElement(); + long num = a.getNumEntries(); + if (num != 0) continue; + ++ix; + if (ix == 1) { + gattrs = Json.createArrayBuilder(); + } +// JsonObjectBuilder eg = Json.createObjectBuilder(). +// add(a.getName(),null); + gattrs.add(a.getName()); + } + if (ix != 0) { + eattrs = Json.createArrayBuilder(); + eattrs.add(Json.createObjectBuilder().add("GlobalAttributes", + gattrs).build()); + } + + ix = 0; + for (Enumeration e=vAttributes.elements(); e.hasMoreElements();) { + Attribute a = (Attribute)e.nextElement(); + long num = a.getNumEntries(); + if (num != 0) continue; + ++ix; + if (ix == 1) { + vattrs = Json.createArrayBuilder(); + } +// JsonObjectBuilder eg = Json.createObjectBuilder(). +// add(a.getName(),null); + vattrs.add(a.getName()); + } + if (ix != 0) { + if (eattrs == null) + eattrs = Json.createArrayBuilder(); + eattrs.add(Json.createObjectBuilder().add("VariableAttributes", + vattrs).build()); + } + + return eattrs; + } + + /************************************************************************* + * Print the variable data. + ************************************************************************/ + private static JsonArrayBuilder printVarData (Variable v, String formatT, + Object fillVal) { + try { + long maxRec, numDims, numElements, numValuesToRead, dataType; + long recCount; + boolean recVary; + long[] dimSizes = {1L}, dimVariances; + long[] dimIndices = {0L}; + long[] dimIntervals = {1L}; +// long numDimsN = 0; + long[] dimSizesN = null; + maxRec = v.getMaxWrittenRecord(); + + /******************************************************* + if varData = "no", do not extract variable data. + if maxRec < 0, then the variable doesn't have data. + ********************************************************/ + if (maxRec < 0) { + return null; + } + + recVary = v.getRecVariance(); + numDims = v.getNumDims(); + dimSizes = v.getDimSizes(); + numElements = v.getNumElements(); + dataType = v.getDataType(); + dimVariances = v.getDimVariances(); + numValuesToRead = 1; +/* + if (numDims > 0) { + dimIntervals = new long[dimSizes.length]; + dimIndices = new long[dimSizes.length]; + dimSizesN = new long[dimSizes.length]; + int j = 0; + numDimsN = 0; + for (int i=0; i < dimSizes.length; i++) { + if (dimVariances[i] == VARY) { + ++numDimsN; + dimSizesN[j] = dimSizes[i]; + ++j; + } + dimIntervals[i] = 1; + dimIndices[i] = 0; + numValuesToRead *= dimSizes[i]; + } + } +*/ + if (numDimsN > 0) { + dimIntervals = new long[(int)numDimsN]; + dimIndices = new long[(int)numDimsN]; + dimSizesN = new long[(int)numDimsN]; + int j = 0; +// numDimsN = 0; + for (int i=0; i < numDimsN; i++) { + if (dimVariances[i] == VARY) { +// ++numDimsN; + dimSizesN[j] = dimSizes[i]; + ++j; + } + dimIntervals[i] = 1; + dimIndices[i] = 0; + numValuesToRead *= dimSizes[i]; + } + } + + JsonArrayBuilder records = Json.createArrayBuilder(); + + /********************************************************/ + /* maxRec represents the last record number for this */ + /* variable, not the number of records. */ + /* */ + /* NOTE: maxRec starts at 0, so if the value of maxRec */ + /* is 2, the actual number of records is 3. */ + /* If there are no records exists, the value of */ + /* maxRec is -1. */ + /********************************************************/ + long incrementCounter, numRecordsToRead, recNo; + long sparseRecord = v.getSparseRecords(); + + if (sparseRecord == NO_SPARSERECORDS) + incrementCounter = (numDimsN == 0 ? 1000 : 200); + else + incrementCounter = 1; + CDFData cdfdata; + for (int i=0; i <= maxRec; i+=incrementCounter) { + if ((i+incrementCounter) > maxRec) + numRecordsToRead = maxRec - i + 1; + else + numRecordsToRead = incrementCounter; + if (numDimsN > 0) { + cdfdata = v.getHyperDataObject((long) i, + numRecordsToRead, 1L, + dimIndices, + dimSizes, + dimIntervals); + } else { + cdfdata = v.getRecordsObject((long) i, + numRecordsToRead); + } + // Get the status of the last CDF call + long status = cdf.getStatus(); + Object dataArray = cdfdata.getData(); + for (int j=0; j < numRecordsToRead; j++) { + Object datum; + if (numRecordsToRead > 1) { + if (dataType != CDF_EPOCH16) + datum = Array.get(dataArray, j); + else { + double[] epoch16 = new double[2]; + epoch16[0] = ((Double) Array.get(dataArray, 2*j)). + doubleValue(); + epoch16[1] = ((Double) Array.get(dataArray, 2*j+1)). + doubleValue(); + datum = (Object) epoch16; + } + } else + datum = dataArray; + + if (numDimsN > 0 && numDims != numDimsN) { + // Filled data for non-varying dimension(s) + long iz; + iz = numDims; + while (iz != numDimsN) { + datum = Array.get(datum, 0); + --iz; + } + } + + if (numDimsN < 2) { + boolean single = false; + if (!recVary || maxRec == 0) single = true; + records = (JsonArrayBuilder) printSingleData ( + (Object)records, null, + datum, dataType, numDimsN, + -1, (withz?"Z":""), formatT, + fillVal, single); + } else { + JsonArrayBuilder oData = printMultipleData (datum, + dataType, (int)numDimsN, + dimSizes, + (withz?"Z":""), formatT, + fillVal); + if (!recVary || maxRec == 0) return oData; + else records.add (oData); + } + } // end of for (int j=0; j < numRecordsToRead; j++) + + } // end of "for (int i=0; i <= maxRec; i++)" + return records; + + } catch (Exception e) { + System.out.println ("** Error occurred in printVarData"); + System.out.println ("variable: "+v.getName()); + System.out.println (e); + System.exit (1); + } + return null; + } + + + /************************************************************************* + * This method returns the output file name if one is not provided + * through the -output option from the command line. + ************************************************************************/ + private static String getDefaultOutputFileName () { + String fileName; + int loc1 = inFile.lastIndexOf(".cdf"); + int loc2 = inFile.lastIndexOf(".CDF"); + boolean extCDF = inFile.endsWith(".cdf") || + inFile.endsWith(".CDF"); + + // Input file name given from the command line doesn't have + // .cdf or .CDF extension in it. + if (!extCDF) + fileName = inFile + ".json"; + + else { // Remove the .cdf or .CDF extension + if (loc1 != -1) { + fileName = inFile.substring(0,loc1); + fileName = fileName + ".json"; + } + else { + fileName = inFile.substring(0,loc2); + fileName = fileName + ".json"; + } + } + if (!fullpath) { + int loc = fileName.lastIndexOf(separator); + if (loc != -1) + fileName = fileName.substring(loc+1); + } + return fileName; + } + + + /************************************************************************* + * This method removes the file path from the given file name and + * returns the file name. + ************************************************************************/ + private static String removeFilePath (String fileName) { + int loc = fileName.lastIndexOf(separator); + fileName = fileName.substring(loc+1); + + return fileName; + } + + + /************************************************************************* + * If an invalid option is entered from the command line, this routine + * is invoked to print an appropriate message followed by its proper + * syntax. + ************************************************************************/ + private static void exit (String msg) { + if (!msg.equals("")) System.out.println (msg); + usage(); + System.exit(1); + } + + + /************************************************************************* + * Print the proper syntax for invoking this program. + ************************************************************************/ + private static void usage() { + System.out.println ("\nDescription:"); + System.out.println (" This program exports the contents of a CDF "+ + "file(s) into a single Json file."); + System.out.println (" The Json file will have an \".json\" extension"+ + " if it is not specified. "); + System.out.println (" "); + System.out.println ("Usage: java CDF2Json [Options] [cdfFile1 "+ + "cdfFile2 ...]"); + System.out.println (""); + System.out.println (" cdfFile1 cdfFile2 .... "); + System.out.println (" Command line input CDF file(s) for "+ + "conversion. A maximum of 100 "); + System.out.println (" files can be specified."); + System.out.println (" If the \"output\" option is not specified,"+ + " the first file in the list is"); + System.out.println (" used as the the output Json file name."); + System.out.println (" Alternatively, use \"fileNames\" option "+ + "to specify a text file"); + System.out.println (" that contains the CDF name(s) for "+ + "conversion. Command line file(s) and"); + System.out.println (" fileNames option are mutually exclusive."); + System.out.println (" "); + System.out.println ("Options:"); + System.out.println (" "); + System.out.println (" -fileNames:fileNames"); + System.out.println (" fileNames is a text file that contains the "+ + "input CDF file name(s)"); + System.out.println (" for converting into a Json file. With this "+ + "option, there is no need to"); + System.out.println (" enter the file(s) in the command line."+ + "If the output Json file is not"); + System.out.println (" specified, this file is used as the name "+ + "of the Json output."); + System.out.println (" "); + System.out.println (" -globalAttrs:[yes | no]. -globalAttrs:yes is "+ + "the default."); + System.out.println (" -globalAttrs:yes extracts all global "+ + "attributes."); + System.out.println (" -globalAttrs:no doesn't extract global "+ + "attributes."); + System.out.println (" "); + System.out.println (" -varAttrs:[yes | no]. -varAttrs:yes is "+ + "the default."); + System.out.println (" -varAttrs:yes extracts each variable's "+ + "attributes."); + System.out.println (" -varAttrs:no doesn't extract variable's "+ + "attributes."); + System.out.println (" "); + System.out.println (" -vars:var1,var2,...."); + System.out.println (" -vars:var1,var2,... extracts only the "+ + "specified variables with"); + System.out.println (" variable names "+ + "separated by a single ','."); + System.out.println (" "); + System.out.println (" -varData:[yes | no]. -varData:yes is "+ + "the default."); + System.out.println (" -varData:yes extracts each variable's data"); + System.out.println (" -varData:no doesn't extract record-varying "+ + "variable's data"); + System.out.println (" "); + System.out.println (" -format:[yes | no | prefer]. -format:prefer "+ + "is the default."); + System.out.println (" -format:yes uses variable attribute FORMAT "+ + "to encode data"); + System.out.println (" -format:prefer uses variable attribute "+ + "FORMAT to encode data."); + System.out.println (" However, if its FORMAT is not"+ + " properly defined, it"); + System.out.println (" is treated as \"no\"."); + System.out.println (" -format:no uses Java internal encoding to "+ + "encode data"); + System.out.println (" Note: The format is only relevant to "+ + "floating-point values."); + System.out.println (" "); + System.out.println (" -encodeepoch:[yes | no]. -encodeepoch:yes is "+ + "the default."); + System.out.println (" -encodeepoch:yes encodes CDF epoch data "+ + "values in time string"); + System.out.println (" -encodeepoch:no shows CDF epoch values in "+ + "their original data form"); + System.out.println (" "); + System.out.println (" -[output | json]:outputFileName"); + System.out.println (" The name of the input CDF file is used "+ + "as the default output file"); + System.out.println (" name. Use this option to specify a "+ + "different output file name."); + System.out.println (" "); + System.out.println (" -[showProgress | Progress]"); + System.out.println (" This option displays the processing "+ + "progress on the screen."); + System.out.println (" It shows how many CDF variables are there "+ + "to process and which"); + System.out.println (" variable is being processed."); + System.out.println (" "); + System.out.println (" -debug"); + System.out.println (" Displays the specifications to "+ + "run the application."); + System.out.println (" "); + System.out.println (" -withZ"); + System.out.println (" Adding \"Z\" to the encoded CDF epoch data "+ + "of ISO 8601 form."); + System.out.println (""); + System.out.println (" -delete"); + System.out.println (" Over-ride the existing Json file."); + System.out.println (""); + System.out.println (" -nofullpath"); + System.out.println (" Only use the file name portion of the "+ + "entered full path name as"); + System.out.println (" the key to each CDF in the Json output. "); + System.out.println (""); + System.out.println (" -showfile"); + System.out.println (" Display the file name(s) being processed."); + System.out.println (""); + System.out.println ("NOTE:"); + System.out.println (""); + System.out.println (" 1. Variable's non-varying dimension(s) is "+ + "ignored. A varying dimension"); + System.out.println (" with a size of only 1 is also considered a "+ + "non-varying dimension."); + System.out.println (" 2. NaN|-NaN and INF|-INF, valid floating-point "+ + "values in CDF, but are not"); + System.out.println (" allowed in Json. They are replaced by strings"+ + " \"NaN\"|\"-NaN\" and "); + System.out.println (" \"INF\"|\"-INF\". Try to avoid using any of"+ + " these as it might cause"); + System.out.println (" unexpected results if such Json file is"+ + " converted back to CDF."); + System.out.println (" 3. Only value, without the data type, from "+ + "meta-data is presented in the"); + System.out.println (" Json output."); + System.out.println (" 4. Use CDFJsonReader to display the Json file "+ + "in a easy to read form."); + System.out.println (""); + System.out.println ("Examples: "); + + System.out.println (" java CDF2Json test.cdf (same as "+ + "java CDF2Json -json:test.json test.cdf)"); + System.out.println (" java CDFJsonReader test.json "); + System.out.println (" "); + System.out.println ("The CDF's Json file has the following form: "); + System.out.println (" "); + System.out.println (" CDFname1: <== CDF file name key\n"+ + " CDFFileInfo:\n"+ + " FileVersion:.....\n"+ + " Format:.....\n"+ + " Majority:...\n"+ + " Encoding:.....\n"+ + " CDFglobalAttributes:\n"+ + " Gattr_name1:\n"+ + " entry#:value\n"+ + " ...\n"+ + " ...\n"+ + " Gattr_name2:\n"+ + " entry#:value\n"+ + " ...\n"+ + " ...\n"+ + " ...\n"+ + " ...\n"+ + " CDFVariables:\n"+ + " VarName1: <== Variable name key\n"+ + " VarDescription:\n"+ + " DataType:....\n"+ + " ...\n"+ + " ...\n"+ + " VarAttributes:\n"+ + " VALIDMIN:....\n"+ + " VALIDMAX:....\n"+ + " ...\n"+ + " ...\n"+ + " VarData:\n"+ + " ...\n"+ + " VarName2:\n"+ + " VarDescription:\n"+ + " DataType:....\n"+ + " ...\n"+ + " ...\n"+ + " VarAttributes:\n"+ + " VALIDMIN:....\n"+ + " VALIDMAX:....\n"+ + " ...\n"+ + " ...\n"+ + " VarData:\n"+ + " ...\n"+ + " EmptyAttributes: <== Exists if there are "+ + "attributes defined but no values\n"+ + " GlobalAttributes: [...]\n"+ + " VariableAttributes: [...]\n"+ + " \n"+ + " CDFname2:\n"+ + " ...\n"+ + " ...\n"+ + " ...\n"+ + " ...\n"+ + " "); + } + + /************************************************************************* + * Output a record object with multi-dimensional data values to a + * JsonArray (called by printVarData). + ************************************************************************/ + + private static JsonArrayBuilder printMultipleData (Object data, + long dataType, + int nDims, + long[] dimSizesL, + String addZ, + String formatT, + Object fillVal) { + + int[] dimSizes = new int[nDims]; + for (int i=0; i<(int)nDims;i++) { + dimSizes[i] = (int) dimSizesL[i]; + } + Object aRow = null; + Object [] subArrays = new Object[(int)nDims-1]; + int [] cIndex = new int[(int)nDims-1]; + long [] boundary = new long[(int)nDims-1]; + JsonArrayBuilder jArray = Json.createArrayBuilder(); + subArrays[0] = data; + cIndex[0] = 0; + boundary[0] = product(dimSizes,0,(int)nDims); + for (int i=1; i<(int)nDims-1;i++) { + subArrays[i] = Array.get(subArrays[i-1], 0); + boundary[i] = product(dimSizes,i,(int)nDims); + cIndex[i] = 0; + } + int n = 0; // The current element in the _data + Object cObject = data; // A temp object to hold a subarray + boolean boundaryCrossed; + while (n < boundary[0]) { + // Get the correct 2D subarray to print + if (n != 0) { + for (int i = 0; i < (int)nDims-1; i++) { + boundaryCrossed = ((n % boundary[i]) == 0); + if (boundaryCrossed) { + // Get the next sub array + cIndex[i]+=1; + cObject = Array.get(cObject, cIndex[i]); + subArrays[i] = cObject; + + // Get the first element of each + // subsequent subarray + for (int j=i+1;j<(int)nDims-1;j++) { + cIndex[j] = 0; + subArrays[j] = + Array.get(subArrays[j-1],cIndex[j]); + } + break; + } else { + cObject = subArrays[i]; + } + } + } + + // Fill the correct elements of data + for (int i=0;i=0) + jArray.add(new Short(((short [])aRow)[j]).intValue()); + else { + short tmp = (short) (((short [])aRow)[j] + 256); + jArray.add((int)tmp); + } + } + break; + case (int)CDF_INT4: + aRow = (int [])Array.get(subArrays[(int)nDims - 2], i); + for (int j=0; j=0) + jArray.add(((int [])aRow)[j]); + else { + int tmp = (int) (((int [])aRow)[j] + 65536); + jArray.add(tmp); + } + } + break; + case (int)CDF_UINT4: + aRow = (long [])Array.get(subArrays[(int)nDims - 2], i); + for (int j=0; j=0) + jArray.add(((long [])aRow)[j]); + else { + long tmp = (long) (((long [])aRow)[j]+ 4294967296L); + jArray.add(tmp); + } + } + break; + case (int)CDF_INT8: + case (int)CDF_TIME_TT2000: + aRow = (long [])Array.get(subArrays[(int)nDims - 2], i); + for (int j=0; j 1) product *= array[i]; + + return product; + } + + private static boolean validORscaleORfill (String name) { + + if (name == null) return false; + name = name.toLowerCase(); + if (name.equals("validmin") || name.equals("validmax") || + name.equals("scalemin") || name.equals("scalemax") || + name.equals("fillval")) return true; + else return false; + } + + private static boolean isEpochDataType (long dataType) { + + if (dataType == CDF_EPOCH || dataType == CDF_EPOCH || + dataType == CDF_TIME_TT2000) return true; + else return false; + } + + /************************************************************************* + * Output an object with a single data value or an array of values to + * a JsonObject (called by printGlobalAttributes and printVarAttributes) + * or JsonArray (called by printVarData). + ************************************************************************/ + + private static Object printSingleData (Object jsonObject, String name, + Object data, long dataType, + long numDims, long dataType2, + String addZ, String formatT, + Object fillVal, boolean single) { + + int iflag; + boolean isArray = false; + if (dataType == CDF_EPOCH) iflag = 1; + else if (dataType == CDF_EPOCH16) iflag = 2; + else if (dataType == CDF_TIME_TT2000) iflag = 3; + else iflag = 0; + int i, arrayLength, jj = 1; + if (iflag == 2) jj = 2; + boolean multi = false; + + String signature = CDFUtils.getSignature(data); + JsonObjectBuilder jObject = Json.createObjectBuilder(); + JsonArrayBuilder jArray = Json.createArrayBuilder(); + if (jsonObject instanceof JsonObjectBuilder) + jObject = (JsonObjectBuilder) jsonObject; + else + jArray = (JsonArrayBuilder) jsonObject; + if (signature.charAt(0) == '[') { + arrayLength = Array.getLength(data); + if (iflag == 2) arrayLength = arrayLength / 2; + if (arrayLength > 1) multi = true; + if (iflag != 2) isArray = true; + } + if (multi) { + JsonArrayBuilder jArray2 = Json.createArrayBuilder(); + arrayLength = Array.getLength(data); + for (i=0; i < arrayLength; i=i+jj) { + if (signature.charAt(1) == 'B') + jArray2.add (Array.getByte(data,i)); + + else if (signature.charAt(1) == 'S') + jArray2.add (Array.getShort(data,i)); + + else if (signature.charAt(1) == 'I') + jArray2.add (Array.getInt(data,i)); + + else if (signature.charAt(1) == 'J') + if (iflag == 3 || (isEpochDataType(dataType2) && + validORscaleORfill(name))) { + if (encodeEp) + jArray2.add (CDFTT2000.encode(Array.getLong(data,i))+ + addZ); + else + jArray2.add (Array.getLong(data,i)); + } else + jArray2.add (Array.getLong(data,i)); + + else if (signature.charAt(1) == 'F') { + float ff = Array.getFloat(data,i); + double dd; + if (Float.isNaN(ff)) + jArray2.add ("NaN"); // jArray2.add (Float.NaN); + else if (Float.isNaN(-ff)) + jArray2.add ("-NaN"); // jArray2.add (-Float.NaN); + else if (Float.isInfinite(ff)) + jArray2.add ("INF"); // jArray2.add (Float.POSITIVE_INFINITY); + else if (Float.isInfinite(-ff)) + jArray2.add ("-INF"); // jArray2.add (Float.NEGATIVE_INFINITY); + else { + if (ff == -1.0E30f) dd = -1.0E30; + else if (ff == -1.0E31f) dd = -1.0E31; + else if (ff == 1.0E30f) dd = 1.0E30; + else if (ff == 1.0E31f) dd = 1.0E31; + else dd = (double) ff; + if (formatT == null) + jArray2.add (dd); + else { + try { + String sd = String.format(formatT, dd); + jArray2.add (new Double(sd).doubleValue()); + } catch (Exception ex) { + jArray2.add (dd); + } + } + } + } else if (signature.charAt(1) == 'D') { + double dd = Array.getDouble(data,i); + if (iflag == 1 || (isEpochDataType(dataType2) && + validORscaleORfill(name))) { + if (encodeEp) + jArray2.add (Epoch.encode4(dd)+addZ); + else + jArray2.add (dd); + } else if (iflag == 2 || (isEpochDataType(dataType2) && + validORscaleORfill(name))) { + double[] mmm = new double[2]; + mmm[0] = Array.getDouble(data,i); + mmm[1] = Array.getDouble(data,i+1); + if (encodeEp) + jArray2.add (Epoch16.encode4(mmm)+addZ); + else { + JsonArrayBuilder epoch16 = Json.createArrayBuilder(); + epoch16.add (mmm[0]); + epoch16.add (mmm[1]); + jArray2.add (epoch16.build()); + } + } else { + if (Double.isNaN(dd)) + jArray2.add ("NaN"); // jArray2.add (Double.NaN); + else if (Double.isNaN(-dd)) + jArray2.add ("-NaN"); // jArray2.add (-Double.NaN); + else if (Double.isInfinite(dd)) + jArray2.add ("INF"); // jArray2.add (Double.POSITIVE_INFINITY); + else if (Double.isInfinite(-dd)) + jArray2.add ("-INF"); // jArray2.add (Double.NEGATIVE_INFINITY); + else { + if (formatT == null) { + jArray2.add (dd); + } else { + try { + String sd = String.format(formatT, dd); + jArray2.add (new Double(sd).doubleValue()); + } catch (Exception ex) { + jArray2.add (dd); + } + } + } + } + } + else if (signature.indexOf("String") != -1) + jArray2.add (((String[])data)[i]); + } + if (name != null) + return jObject.add(name, jArray2); + else { + if (single) return jArray2; + else return jArray.add(jArray2); + } + } else { + if (signature.charAt(0) == '[' && iflag != 2) + data = Array.get(data, 0); + if (iflag == 1) { + if (name != null) { + if (encodeEp) + return jObject.add(name, + Epoch.encode4(((Double)data).doubleValue())+ + addZ); + else + return jObject.add(name, ((Double)data).doubleValue()); + } else { + if (encodeEp) + return jArray.add(Epoch.encode4(((Double)data).doubleValue())+ + addZ); + else + return jArray.add(((Double)data).doubleValue()); + } + } else if (iflag == 2) { + if (name != null) { + if (encodeEp) + return jObject.add(name, Epoch16.encode4((double[])data)+addZ); + else { + JsonArrayBuilder epoch16 = Json.createArrayBuilder(); + epoch16.add(((double[])data)[0]); + epoch16.add(((double[])data)[1]); + return jObject.add(name, epoch16.build()); + } + } else { + if (encodeEp) + return jArray.add(Epoch16.encode4(((double[])data))+addZ); + else { + JsonArrayBuilder epoch16 = Json.createArrayBuilder(); + epoch16.add(((double[])data)[0]); + epoch16.add(((double[])data)[1]); + return jArray.add(epoch16.build()); + } + } + } else if (iflag == 3) { + if (name != null) { + if (encodeEp) + return jObject.add(name, + CDFTT2000.encode(((Long)data).longValue())+ + addZ); + else + return jObject.add(name, ((Long)data).longValue()); + } else { + if (encodeEp) + return jArray.add(CDFTT2000.encode(((Long)data).longValue())+ + addZ); + else + return jArray.add(((Long)data).longValue()); + } + } else { + if (signature.indexOf("Byte") != -1) { + int value; + value = ((Byte)data).intValue(); + if (name != null) + return jObject.add(name, value); + else + return jArray.add(value); + } else if (signature.indexOf("Short") != -1) { + int value; + value = ((Short)data).intValue(); + if (name != null) + return jObject.add(name, value); + else + return jArray.add(value); + } else if (signature.indexOf("Int") != -1) { + int value; + value = ((Integer)data).intValue(); + if (name != null) + return jObject.add(name, value); + else + return jArray.add(value); + } else if (signature.indexOf("Long") != -1) { + long value; + value = ((Long)data).longValue(); + if (name != null) { + if (isEpochDataType(dataType2) && validORscaleORfill(name)) + return jObject.add(name, CDFTT2000.encode(value)+addZ); + else + return jObject.add(name, value); + } else { + if (isEpochDataType(dataType2) && validORscaleORfill(name)) + return jArray.add(CDFTT2000.encode(value)+addZ); + else + return jArray.add(value); + } + } else if (signature.indexOf("Float") != -1) { + float ff; + ff = ((Float)data).floatValue(); + if (Float.isNaN(ff)) { + if (name != null) + return jObject.add (name, "NaN"); // jObject.add (name, Float.NaN); + else + return jArray.add ("NaN"); // jArray.add (Float.NaN); + } else if (Float.isNaN(-ff)) { + if (name != null) + return jObject.add (name, "-NaN"); // jObject.add (name, -Float.NaN); + else + return jArray.add ("-NaN"); // jArray.add (-Float.NaN); + } else if (Float.isInfinite(ff)) { + if (name != null) + return jObject.add (name, "INF"); // jObject.add (name, Float.POSITIVE_INFINITY); + else + return jArray.add ("INF"); // jArray.add (Float.POSITIVE_INFINITY); + } else if (Float.isInfinite(-ff)) { + if (name != null) + return jObject.add (name, "-INF"); // jObject.add (name, Float.NEGATIVE_INFINITY); + else + return jArray.add ("-INF"); // jArray.add (Float.NEGATIVE_INFINITY); + } else { + double dd; + if (ff == -1.0E30f) dd = -1.0E30; + else if (ff == -1.0E31f) dd = -1.0E31; + else if (ff == 1.0E30f) dd = 1.0E30; + else if (ff == 1.0E31f) dd = 1.0E31; + else dd = (double) ff; + if (name != null) { + if (formatT == null) { + return jObject.add(name, dd); + } else { + try { + String sd = String.format(formatT, dd); + return jObject.add(name, new Double(sd).doubleValue()); + } catch (Exception ex) { + return jObject.add (name, dd); + } + } + } else { + if (formatT == null) { + return jArray.add(dd); + } else { + try { + String sd = String.format(formatT, dd); + return jArray.add(new Double(sd).doubleValue()); + } catch (Exception ex) { + return jArray.add (dd); + } + } + } + } + } else if (signature.indexOf("Double") != -1) { + double dd; + dd = ((Double)data).doubleValue(); + if (Double.isNaN(dd)) { + if (name != null) + return jObject.add (name, "NaN"); // jObject.add (name, Double.NaN); + else + return jArray.add ("NaN"); // jArray.add (Double.NaN); + } else if (Double.isNaN(-dd)) { + if (name != null) + return jObject.add (name, "NaN"); // jObject.add (name, -Double.NaN); + else + return jArray.add ("-NaN"); // jArray.add (-Double.NaN); + } else if (Double.isInfinite(dd)) { + if (name != null) + return jObject.add (name, "INF"); // jObject.add (name, Double.POSITIVE_INFINITY); + else + return jArray.add ("INF"); // jArray.add (Double.POSITIVE_INFINITY); + } else if (Double.isInfinite(-dd)) { + if (name != null) + return jObject.add (name, "-INF"); // jObject.add (name, Double.NEGATIVE_INFINITY); + else + return jArray.add ("-INF"); // jArray.add (Double.NEGATIVE_INFINITY); + } else { + if (name != null) { + if (formatT == null) { + if (isEpochDataType(dataType2) && validORscaleORfill(name)) + return jObject.add(name, Epoch.encode4(dd)+addZ); + else + return jObject.add(name, dd); + } else { + try { + String sd = String.format(formatT, dd); + if (isEpochDataType(dataType2) && validORscaleORfill(name)) + return jObject.add(name, Epoch.encode4( + new Double(sd).doubleValue())+ + addZ); + else + return jObject.add(name, new Double(sd).doubleValue()); + } catch (Exception ec) { + if (isEpochDataType(dataType2) && validORscaleORfill(name)) + return jObject.add(name, Epoch.encode4(dd)+addZ); + else + return jObject.add(name, dd); + } + } + } else { + if (formatT == null) { + return jArray.add(dd); + } else { + try { + String sd = String.format(formatT, dd); + return jArray.add(new Double(sd).doubleValue()); + } catch (Exception es) { + return jArray.add(dd); + } + } + } + } + } else if (signature.indexOf("String") != -1) { + if (name != null) + return jObject.add(name, (String)data); + else + return jArray.add((String)data); + } + } + } + return null; + } + + private static String toCformat (String oFormat) { + if (oFormat.charAt(0) == '%') return oFormat; + /*********************************************************************** + * FORTRAN format form + * Change `oformat' to point to first non-blank, non-digit, non-`(' + * character. This will skip over a Fortran repeat count (eg. the `20' + * in `20F8.4' or `20(F8.4)'). + ***********************************************************************/ + oFormat = oFormat.trim(); + if (oFormat == null) return null; + int len = oFormat.length(); + String formatY = null; + for (int i = 0; i < len; ++i) { + char a = oFormat.charAt(i); + if (Character.isDigit(a) || a == '(') continue; + formatY = oFormat.substring(i); + if (formatY.endsWith(")")) formatY = formatY.substring(0, + formatY.length()-1); + break; + } + if (formatY == null) return null; + String cformat; + /*********************************************************************** + * Encode C format specification. + ***********************************************************************/ + switch (formatY.charAt(0)) { + /********************************************************************* + * Integer/decimal. + *********************************************************************/ + case 'I': + case 'i': + cformat = formatY.substring(1); + return "%"+cformat+"d"; + /********************************************************************* + * Floating-point/non-scientific notation (which is called... + *********************************************************************/ + case 'F': + case 'f': + cformat = formatY.substring(1); + return "%"+cformat+"f"; + /********************************************************************* + * Floating-point/scientific notation. + *********************************************************************/ + case 'E': + case 'e': + cformat = formatY.substring(1); + return "%"+cformat+"e"; + } + return null; + } + + private static void readFileNames (String fileTxt) { + FileInputStream fIn = null; + BufferedReader br = null; + String line; + int i; + try { + numFiles = 0; + fIn = new FileInputStream(fileTxt);; + br = new BufferedReader(new InputStreamReader(fIn)); + line = br.readLine(); + while (line != null) { + if (CDFUtils.cdfFileExists(line)) ++numFiles; + line = br.readLine(); + } + if (numFiles == 0) { + System.out.println("*** No CDF file(s) is found... "); + System.exit(1); + } + fileNames = new String[numFiles]; + i = 0; + fIn.getChannel().position(0); + br = new BufferedReader(new InputStreamReader(fIn)); + line = br.readLine(); + while (line != null) { + if (CDFUtils.cdfFileExists(line)) { + fileNames[i] = line; + ++i; + } + line = br.readLine(); + } + } catch (Exception ex) { + System.out.println("error: "+ex); + } finally { + try { + if (fIn != null) fIn.close(); + } catch (Exception ey) {} + } + } + +} diff --git a/cdf38_1-dist/cdfjava/cdfjson/CDFJsonReader.java b/cdf38_1-dist/cdfjava/cdfjson/CDFJsonReader.java new file mode 100644 index 0000000..8607992 --- /dev/null +++ b/cdf38_1-dist/cdfjava/cdfjson/CDFJsonReader.java @@ -0,0 +1,388 @@ +import java.io.*; +import java.text.*; +import java.util.*; +import java.lang.reflect.*; +import java.lang.*; +import javax.json.*; +import gsfc.nssdc.cdf.*; +import gsfc.nssdc.cdf.util.*; + +public class CDFJsonReader implements CDFConstants { + + private static boolean toGlobal = true; + private static boolean toVarAttrs = true; + private static boolean toVarDesc = true; + private static boolean toVarData = false; + private static String[] varNames = null; + private static String inFile = null; + private static int varCount = 0; + private static boolean toShow = true; + private static String item1 = "CDFFileInfo"; + private static String item2 = "CDFglobalAttributes"; + private static String item3 = "CDFVariables"; + private static String item4 = "VarDescription"; + private static String item5 = "VarAttributes"; + private static String item6 = "VarData"; + private static String item7 = "EmptyAttributes"; + + public static void main(String[] args) throws IOException { + + parseCmdLine(args); + + InputStream fis = new FileInputStream(inFile); + + JsonReader jsonReader = Json.createReader(fis); + + JsonObject jsonObject = jsonReader.readObject(); + + jsonReader.close(); + fis.close(); + + JsonArray singleFile = jsonObject.getJsonArray(item1); + if (singleFile != null) { + // old CDF Json form (good for single file) + printJsonObject(jsonObject); + } else { + // new CDF Json form + for (String cdfName: jsonObject.keySet()) { + JsonValue cdf = jsonObject.getJsonObject(cdfName); + System.out.println(cdfName+":"); + printJsonObject((JsonObject)jsonObject.getJsonObject(cdfName)); + } + } + } + + private static void printJsonObject (JsonObject jsonObject1) { + // Retrieve data from "CDFFileInfo" JsonArray + JsonArray fileInfoArray = jsonObject1.getJsonArray(item1); + if (fileInfoArray != null) { + System.out.println(" "+item1+":"); + for (JsonValue fileInfo : fileInfoArray) { + for (String key: ((JsonObject)fileInfo).keySet()) { + System.out.println(" "+key+":"+((JsonObject)fileInfo). + getString(key)); + } + } + } + + // Retrieve data from "CDFglobalAttributes" JsonArray + if (toGlobal) { + JsonArray globalAttrArray = jsonObject1.getJsonArray(item2); + if (globalAttrArray != null) { + System.out.println(" "+item2+":"); + for (JsonValue attrInfo : globalAttrArray) { + for (String key: ((JsonObject)attrInfo).keySet()) { + System.out.println(" "+key+":"); + JsonArray entries = ((JsonObject)attrInfo).getJsonArray(key); + for (int ii = 0; ii < entries.size(); ++ii) { + JsonObject entry = entries.getJsonObject(ii); + for (String entryID: entry.keySet()) { + Object value = entry.get(entryID); + System.out.println(" "+entryID+":"+value); + } + } + } + } + } + } + + boolean toVar = false; + // Retrieve data from "CDFVariables" JsonArray + JsonArray cdfVariables = jsonObject1.getJsonArray(item3); + String format = null; + long dataType = 0; + if (cdfVariables != null) { + System.out.println(" "+item3+":"); + format = null; + dataType = 0; + for (JsonValue varInfo : cdfVariables) { + for (String key: ((JsonObject)varInfo).keySet()) { + JsonArray var = ((JsonObject)varInfo).getJsonArray(key); + JsonObject varItem = var.getJsonObject(0); + if (varCount > 0) toShow = checkVar (varItem); + if (!toShow) continue; + System.out.println(" "+key+":"); // Variable name + for (int ii = 0; ii < var.size(); ++ii) { // VarDescription | + // VarAttributes | + // VarData + varItem = var.getJsonObject(ii); + for (String varKey: varItem.keySet()) { + if (varKey.equals("VarDescription")) toVar = false; + if (varKey.equals(item5) && !toVarAttrs) break; + if (varKey.equals(item6) && (!toVarData && !toVar)) break; + Object value = varItem.get(varKey); + if (value instanceof JsonString) { + // VarDescription: + System.out.println(" "+varKey+":"+value); + } else if (value instanceof JsonArray) { + // VarDescription: | VarAttributes: | VarData: + System.out.println(" "+varKey+":"); + int valueN = ((JsonArray)value).size(); + boolean breakout = false; + for (int jj = 0; jj < valueN; ++jj) { + Object data = (Object) ((JsonArray)value).get(jj); + if (data instanceof JsonObject) { + for (String keyx: ((JsonObject)data).keySet()) { + Object des = ((JsonObject)data).get(keyx); + // DataType: | VALIDMIN: + System.out.println(" "+keyx+":"+des); + if (!toVarDesc && keyx.equalsIgnoreCase("varname")) + breakout = true; + if (keyx.equals("RecVariance")) { + if (des.toString().equals("\"NOVARY\"")) toVar= true; + } + if (keyx.equalsIgnoreCase("format")) { + format = toCformat(des.toString(). + replaceAll("^\"|\"$", "")); + } + if (keyx.equalsIgnoreCase("datatype")) { + dataType = CDFUtils.getDataTypeValue( + des.toString().replaceAll("^\"|\"$", "")); + } + } + } else if (data instanceof JsonArray) { + System.out.print(" ["); + int sizex = ((JsonArray)data).size(); + for (int kk = 0; kk < sizex; ++kk) { + Object data1 = ((JsonArray)data).get(kk); + System.out.print(data1+(kk<(sizex-1)?", ":"]")); + } + System.out.println(""); + } else if (data instanceof JsonNumber || + data instanceof JsonString) { + if (jj == 0) System.out.print(" ["); + if (data instanceof JsonString || format == null || + (dataType != CDF_REAL4 && dataType != CDF_REAL8 && + dataType != CDF_FLOAT && dataType != CDF_DOUBLE)) + System.out.print(data+(jj<(valueN-1)?", ":"")); + else + System.out.print( + String.format(format,((JsonNumber)data). + doubleValue())+ + (jj<(valueN-1)?", ":"")); + if (jj == (valueN - 1)) System.out.println("]"); + } else { + System.out.println(" "+data); + } + if (breakout) break; + } + } else if (value instanceof JsonObject) + System.out.println(" :a jsonObject: "+value); + else System.out.println(" :unknown"); + } + } + } + } + + // Retrieve data from "CDFFileInfo" JsonArray + JsonArray emptyAttrs = jsonObject1.getJsonArray(item7); + if (emptyAttrs != null) { + System.out.println(" "+item7+":"); + for (JsonValue attrs : emptyAttrs) { + for (String key: ((JsonObject)attrs).keySet()) { + System.out.println(" "+key+":"+((JsonObject)attrs).get(key)); + } + } + } + } + + } + + private static void parseCmdLine (String[] args) { + String numSpaces = null; + + if (args.length == 0) // No input is given (i.e. java CDFJsonReader) + exit(""); + + else { // Process options + for (int i=0; i < args.length; i++) { + if (i == (args.length-1)) { // Get the Json file name + inFile = args[i]; + if (!(new File(inFile).exists())) { + System.out.println ("** Error: file '"+inFile+ + "' does not exist **"); + System.exit (1); + } + } + else { + int loc = args[i].indexOf(":"); + if (args[i].toLowerCase().startsWith("-vardata:")) { + String varData = args[i].substring(loc+1); + if (!varData.equalsIgnoreCase("yes") && + !varData.equalsIgnoreCase("no")) + exit("** Error: Invalid -vardata entered **"); + if (varData.equalsIgnoreCase("yes")) + toVarData = true; + } + else if (args[i].toLowerCase().startsWith("-globalmetadata:")) { + String globalAttrs = args[i].substring(loc+1); + if (!globalAttrs.equalsIgnoreCase("yes") && + !globalAttrs.equalsIgnoreCase("no")) + exit("** Error: Invalid -globalmetadata entered **"); + if (globalAttrs.equalsIgnoreCase("no")) + toGlobal = false; + } + else if (args[i].toLowerCase().startsWith("-vardesc:")) { + String varDesc = args[i].substring(loc+1); + if (!varDesc.equalsIgnoreCase("yes") && + !varDesc.equalsIgnoreCase("no")) + exit("** Error: Invalid -vardesc entered **"); + if (varDesc.equalsIgnoreCase("no")) + toVarDesc = false; + } + else if (args[i].toLowerCase().startsWith("-varmetadata:")) { + String varAttrs = args[i].substring(loc+1); + if (!varAttrs.equalsIgnoreCase("yes") && + !varAttrs.equalsIgnoreCase("no")) + exit("** Error: Invalid -varmetadata entered **"); + if (varAttrs.equalsIgnoreCase("no")) + toVarAttrs = false; + } + else if (args[i].toLowerCase().startsWith("-vars:")) { + String names = args[i].substring(6); + int e; + varCount = 1; + for (e = 0; e < names.length(); e++) { + if (names.charAt(e) == ',') varCount++; + } + varNames = new String[varCount]; + StringBuffer tmp = new StringBuffer(names); + for (e = 0; e < varCount; ++e) { + int dstr = tmp.indexOf(","); + if (dstr != -1) { + varNames[e] = tmp.substring(0, dstr).toString(); + tmp = new StringBuffer(tmp.substring(dstr+1)); + } else { + varNames[e] = new String(tmp); + } + } + } + } + } + } + } + + private static boolean checkVar (JsonObject varInfo) { + + for (String varKey: varInfo.keySet()) { + JsonArray varItems = varInfo.getJsonArray(varKey); + JsonObject value = (JsonObject) varItems.getJsonObject(0); + for (String key: value.keySet()) { + Object des = value.get(key); + if (key.equalsIgnoreCase("varname")) { + toShow = false; + String varname = ((JsonString)des).getString(); + for (int ll = 0; ll < varCount; ++ll) { + if (varname.equals(varNames[ll])) { + toShow = true; + break; + } + } + } + } + } + return toShow; + } + + private static void exit (String msg) { + if (!msg.equals("")) System.out.println (msg); + usage(); + System.exit(1); + } + + private static void usage() { + System.out.println ("\nDescription:"); + System.out.println (" This program displays the contents of a Json "+ + "file."); + System.out.println (""); + System.out.println ("Usage: java CDFJsonReader [Options] JsonFileName "); + System.out.println (" "); + System.out.println ("Options: "); + System.out.println (" "); + System.out.println (" -globalmetadata:[yes | no]. -globalmetadata:yes"+ + "is the default."); + System.out.println (" -globalmetadata:yes shows all global "+ + "attributes."); + System.out.println (" -globalmetadata:no doesn't show all global "+ + "attributes."); + System.out.println (" "); + System.out.println (" -vardesc:[yes | no]. -vardesc:yes is "+ + "the default."); + System.out.println (" -vardesc:yes shows each variable's name and "+ + "its specification."); + System.out.println (" -vardesc:no shows the variable name only."); + System.out.println (" "); + System.out.println (" -varmetadata:[yes | no]. -varmetadata:yes is "+ + "the default."); + System.out.println (" -varmetadata:yes shows each variable's "+ + "attributes."); + System.out.println (" -varmetadata:no doesn't show each "+ + "variable's attributes."); + System.out.println (" "); + System.out.println (" -vars:var1,var2,.... shows only the "+ + "specified variables with"); + System.out.println (" variable names "+ + "separated by a single ','."); + System.out.println (" Otherwise, all variables "+ + "are shown."); + System.out.println (" "); + System.out.println (" -vardata:[yes | no]. -vardata:no is "+ + "the default."); + System.out.println (" -vardata:yes shows the variable data"); + System.out.println (" -vardata:no doesn't show any record varying "+ + "variable data"); + System.out.println (" "); + } + + private static String toCformat (String oFormat) { + if (oFormat.charAt(0) == '%') return oFormat; + /*********************************************************************** + * FORTRAN format form + * Change `oformat' to point to first non-blank, non-digit, non-`(' + * character. This will skip over a Fortran repeat count (eg. the `20' + * in `20F8.4' or `20(F8.4)'). + ***********************************************************************/ + oFormat = oFormat.trim(); + if (oFormat == null) return null; + int len = oFormat.length(); + String formatY = null; + for (int i = 0; i < len; ++i) { + char a = oFormat.charAt(i); + if (Character.isDigit(a) || a == '(') continue; + formatY = oFormat.substring(i); + if (formatY.endsWith(")")) + formatY = formatY.substring(0, formatY.length()-1); + break; + } + if (formatY == null) return null; + String cformat; + /*********************************************************************** + * Encode C format specification. + ***********************************************************************/ + switch (formatY.charAt(0)) { + /********************************************************************* + * Integer/decimal. + *********************************************************************/ + case 'I': + case 'i': + cformat = formatY.substring(1); + return "%"+cformat+"d"; + /********************************************************************* + * Floating-point/non-scientific notation (which is called... + *********************************************************************/ + case 'F': + case 'f': + cformat = formatY.substring(1); + return "%"+cformat+"f"; + /********************************************************************* + * Floating-point/scientific notation. + *********************************************************************/ + case 'E': + case 'e': + cformat = formatY.substring(1); + return "%"+cformat+"e"; + } + return null; + } + +} diff --git a/cdf38_1-dist/cdfjava/cdfjson/Json2CDF.java b/cdf38_1-dist/cdfjava/cdfjson/Json2CDF.java new file mode 100644 index 0000000..71d99d1 --- /dev/null +++ b/cdf38_1-dist/cdfjava/cdfjson/Json2CDF.java @@ -0,0 +1,1416 @@ +import java.io.*; +import java.text.*; +import java.util.*; +import java.lang.reflect.*; +import java.lang.*; +import javax.json.*; +import gsfc.nssdc.cdf.*; +import gsfc.nssdc.cdf.util.*; + +/** + * The Json2CDF class is the converter to convert a Json file back to a CDF. + * The Json file is produced from CDF2Json class. The Json file has the + * following form: + *
+ *CDFname1:
+ *  CDFFileInfo:
+ *    FileVersion:.....
+ *    Format:.....
+ *    Majority:...
+ *    Encoding:.....
+ *  CDFglobalAttributes:
+ *    Gattr_name1:
+ *     entry#:value
+ *       ...
+ *       ...
+ *    Gattr_name2:
+ *     entry#:value
+ *       ...
+ *       ...
+ *    ...
+ *    ...
+ *  CDFVariables:
+ *    VarName1:
+ *     VarDescription:
+ *       DataType:....
+ *       ...
+ *       ...
+ *     VarAttributes:
+ *       VALIDMIN:....
+ *       VALIDMAX:....
+ *       ...
+ *       ...
+ *     VarData:
+ *       ...
+ *    VarName2:
+ *     VarDescription:
+ *       DataType:....
+ *       ...
+ *       ...
+ *     VarAttributes:
+ *       VALIDMIN:....
+ *       VALIDMAX:....
+ *       ...
+ *       ...
+ *     VarData:
+ *       ...
+ *  EmptyAttributes:        <== If attribute(s) defined but not assign value(s)
+ *     GlobalAttributes:    <== If global attribute(s) is not assigned value
+ *     VariableAttributes:  <== If variable attribute(s) is not assigned value
+ *
+ *CDFname2:
+ *  CDFFileInfo:
+ *   .....
+ *   .....
+ *  CDFglobalAttributes:
+ *    Gattr_name1:
+ *       ...
+ *       ...
+ *    Gattr_name2:
+ *       ...
+ *       ...
+ *    ...
+ *    ...
+ *  CDFVariables:
+ *    VarName1:
+ *     VarDescription:
+ *       ....
+ *...
+ *...
+ *
+ * + * + * This class is based on JNI-based cdfjava.jar and javax.json.jar. + * + * @version 2.0 02/20/2022 + * @author Mike Liu, ADNET Systems + */ + +public class Json2CDF implements CDFConstants { + + private static boolean progress = false, + delete = false, + showfile = false, + toCompress = true, + checksum = false; + private static String inFile = null, + assignedFile = null, + outDir = null; + private static int numFiles = 0; + private static long dataType, numElements; + private static boolean varData = true; + private static long varDataType, varNumElems, varNumDims; + private static long varSparseRec = NO_SPARSERECORDS; + private static long varNumWritten = 0, varMaxWritten = -1; + private static long[] varDimSizes = new long[(int)CDF_MAX_DIMS]; + private static long[] varDimVariances = new long[(int)CDF_MAX_DIMS]; + private static String varName = null; + private static Object varPadValue = null; + private static Object varFillVal = null; + private static long varRecVary = VARY; + private static String separator = System.getProperty("file.separator"); + private static String item1 = "CDFFileInfo"; + private static String item2 = "CDFglobalAttributes"; + private static String item3 = "CDFVariables"; + private static String item4 = "VarDescription"; + private static String item5 = "VarAttributes"; + private static String item6 = "VarData"; + private static String item7 = "EmptyAttributes"; + + public static void main(String[] args) throws IOException { + try { + parseCmdLine(args); + if (showfile) System.out.println(inFile); + InputStream fis = new FileInputStream(inFile); + JsonReader jsonReader = Json.createReader(fis); + JsonObject jsonObject = jsonReader.readObject(); + jsonReader.close(); + fis.close(); + + numFiles = jsonObject.keySet().size(); + + for (String cdfName: jsonObject.keySet()) { + outPutJsonObject(cdfName, + (JsonObject)jsonObject.getJsonObject(cdfName)); + } + + } catch (Exception ep) { + System.out.println("Exception... "+ep); + } + } + + private static void outPutJsonObject (String cdfName, + JsonObject jsonObject1) { + long format = -1, majority = -1, encoding = -1; + CDF cdf = null; + Variable va = null; + String createdCDF = null; + + try { + JsonArray fileInfoArray = jsonObject1.getJsonArray(item1); + if (fileInfoArray != null) { + if (progress) System.out.println(item1+":"); + for (JsonValue fileInfo : fileInfoArray) { + for (String key: ((JsonObject)fileInfo).keySet()) { + String value = ((JsonObject)fileInfo).getString(key); + if (progress) System.out.println(" "+key+":"+value); + if (key.equalsIgnoreCase("filename")) { + cdfName = value; + } else if (key.equalsIgnoreCase("format")) { + format = CDFUtils.getLongFormat (value); + } else if (key.equalsIgnoreCase("majority")) { + majority = CDFUtils.getLongMajority (value); + } else if (key.equalsIgnoreCase("encoding")) { + encoding = CDFUtils.getLongEncoding (value); + } + } + } + String toDelete = null; + if (delete) { + File cdfFile; + if (outDir == null) { + if (numFiles == 1 && assignedFile != null) + toDelete = assignedFile; + else + toDelete = cdfName; + } else { + int loc; + if (numFiles == 1 && assignedFile != null) + toDelete = outDir + separator + assignedFile; + else { + loc = cdfName.lastIndexOf(separator); + if (loc != -1) + toDelete = outDir + separator + cdfName.substring(loc+1); + else + toDelete = outDir + separator + cdfName; + } + } + cdfFile = new File(toDelete); + if (cdfFile.exists()) cdfFile.delete(); + } + + if (outDir == null) + if (numFiles == 1 && assignedFile != null) + createdCDF = assignedFile; + else + createdCDF = cdfName; + else { + if (numFiles == 1 && assignedFile != null) + createdCDF = outDir+separator+assignedFile; + else { + int loc = cdfName.lastIndexOf(separator); + if (loc != -1) + createdCDF = outDir+separator+cdfName.substring(loc+1); + else + createdCDF = outDir+separator+cdfName; + } + } + cdf = CDF.create(createdCDF); + cdf.setFormat(format); + cdf.setMajority(majority); + cdf.setEncoding(encoding); + if (checksum) + cdf.setChecksum(MD5_CHECKSUM); + } + + // Retrieve data from "CDFglobalAttributes" JsonArray + JsonArray globalAttrArray = jsonObject1.getJsonArray(item2); + if (globalAttrArray != null) { + if (progress) System.out.println(item2+":"); + processGlobalAttributes (cdf, globalAttrArray); + } + + // Retrieve data from "CDFVariables" JsonArray + JsonArray cdfVariables = jsonObject1.getJsonArray(item3); + if (cdfVariables != null) { + if (progress) System.out.println(item3+":"); + for (JsonValue varInfo : cdfVariables) { + for (String varName: ((JsonObject)varInfo).keySet()) { + if (progress) System.out.println(" "+varName+":"); + JsonArray varItems = ((JsonObject)varInfo).getJsonArray(varName); + for (int ii = 0; ii < varItems.size(); ++ii) { + JsonObject varItem = varItems.getJsonObject(ii); + for (String itemName: varItem.keySet()) { + if (itemName.equalsIgnoreCase(item4)) { + Object values = varItem.get(itemName); + if (progress) System.out.println(" "+itemName+":"); + va = processVariableSpec (cdf, varName, values); + } else if (itemName.equalsIgnoreCase(item5)) { + if (va != null) { + Object values = varItem.get(itemName); + if (progress) System.out.println(" "+itemName+":"); + processVariableAttributes (cdf, va, values); + } + } else if (itemName.equalsIgnoreCase(item6)) { + if (varData || (varRecVary == NOVARY)) { + if (va != null) { + if (progress) System.out.println(" Doing VarData...."); + Object varData = varItem.get(itemName); + processVariableData (va, varData); + } + } + } else + System.out.println("***** Unknown item...: "+itemName); + } + } + } + } + } + + JsonArray emptyAttrs = jsonObject1.getJsonArray(item7); + if (emptyAttrs != null) { + if (progress) System.out.println(item7+":"); + for (JsonValue groupAttrs : emptyAttrs) { + for (String key: ((JsonObject)groupAttrs).keySet()) { + JsonArray values = ((JsonObject)groupAttrs).getJsonArray(key); + if (progress) System.out.println(" "+key+":"+values); + if (key.equals("GlobalAttributes")) { + for (int ii=0; ii < values.size(); ++ii) { + String attrName = values.getString(ii); + Attribute.create(cdf, attrName, GLOBAL_SCOPE); + } + } else { + for (int ii=0; ii < values.size(); ++ii) { + String attrName = values.getString(ii); + Attribute.create(cdf, attrName, VARIABLE_SCOPE); + } + } + } + } + } + cdf.close(); + } catch (Exception ex) { + System.out.println("***** Error: "+ex+" for file: "+createdCDF); + } + } + + /*********************************************************/ + /* Parse the command line input that is in the form of */ + /* java Json2CDF [Options] cdfFileName */ + /* */ + /* See the top of this file for a detailed description */ + /* of the Options. */ + /*********************************************************/ + private static void parseCmdLine (String[] args) { + String numSpaces = null; + + if (args.length == 0) // No input is given (i.e. java Json2CDF) + exit(""); + else { // Process options + for (int i=0; i < args.length; i++) { + if (i == (args.length-1)) { // Get the CDF file name + inFile = args[i]; + } + else { + int loc = args[i].indexOf(":"); + if (args[i].toLowerCase().startsWith("-output:")) { + assignedFile = args[i].substring(loc+1); + if (!assignedFile.toLowerCase().endsWith(".cdf")) + assignedFile = assignedFile + ".cdf"; + } + else if (args[i].toLowerCase().startsWith("-vardata:")) { + String toData = args[i].substring(loc+1); + if (toData.equalsIgnoreCase("yes")) + varData = true; + else if (toData.equalsIgnoreCase("no")) + varData = false; + else + exit ("** Error: Invalid -vardata option entered **"); + } + else if (args[i].equalsIgnoreCase("-showprogress") || + args[i].equalsIgnoreCase("-progress")) { + progress = true; + } + else if (args[i].equalsIgnoreCase("-delete")) { + delete = true; + } + else if (args[i].equalsIgnoreCase("-showfile")) { + showfile = true; + } + else if (args[i].equalsIgnoreCase("-checksum")) { + checksum = true; + } + else if (args[i].equalsIgnoreCase("-nocompress")) { + toCompress = false; + } + else if (args[i].toLowerCase().startsWith("-outdir:")) { + outDir = args[i].substring(loc+1); + } + else { + exit ("** Error: Invalid option entered **"); + } + } + } + } + } + + private static boolean equivalentDataTypes (long dataType1, long dataType2) { + long realDataType[] = { + 0,1,2,0,3,0,0,0,4,0, + 0,5,6,0,7,0,0,0,0,0, + 0,8,9,0,0,0,0,0,0,0, + 0,9,0,4,0,0,0,0,0,0, + 0,1,0,0,8,9,0,0,0,0, + 0,10,10,0,0,0,0,0,0,0 + }; + return (realDataType[(int)dataType1] == realDataType[(int)dataType2]); + } + + private static Object handleSpecial (long dt, String str) { + + if (str.equals("-nan")) { + if (dt == CDF_DOUBLE || dt == CDF_REAL8) + return new Double(-Double.NaN); + if (dt == CDF_FLOAT || dt == CDF_REAL4) + return new Float(-Float.NaN); + return new Double(-Double.NaN); + } else if (str.equals("nan")) { + if (dt == CDF_DOUBLE || dt == CDF_REAL8) + return new Double(Double.NaN); + if (dt == CDF_FLOAT || dt == CDF_REAL4) + return new Float(Float.NaN); + return new Double(Double.NaN); + } else if (str.equals("-inf")) { + if (dt == CDF_DOUBLE || dt == CDF_REAL8) + return new Double(Double.NEGATIVE_INFINITY); + if (dt == CDF_FLOAT || dt == CDF_REAL4) + return new Float(Float.NEGATIVE_INFINITY); + return new Double(Double.NEGATIVE_INFINITY); + } else if (str.equals("inf")) { + if (dt == CDF_DOUBLE || dt == CDF_REAL8) + return new Double(Double.POSITIVE_INFINITY); + if (dt == CDF_FLOAT || dt == CDF_REAL4) + return new Float(Float.POSITIVE_INFINITY); + return new Double(Double.POSITIVE_INFINITY); + } + return str; + } + + private static Object changeData (long dt1, long dt2, Object data) { + + String signature = CDFUtils.getSignature(data); + if (signature.indexOf("String") != -1) { + if (signature.charAt(0) != '[') { + String str = (String) data; + String str2 = specialString(str); + if (str2 != null) + return handleSpecial (dt2, str2); + else + return data; + } else { + int items = ((String[])data).length; + String str = null, str2 = null; + if (dt2 == CDF_REAL4 || dt2 == CDF_FLOAT) { + float[] nd = new float[items]; + for (int i = 0; i < items; ++i) { + str = ((String[]) data)[i]; + str2 = specialString(str); + if (str2 != null) + nd[i] = ((Float) handleSpecial (dt2, str2)).floatValue(); + else + nd[i] = new Float(str).floatValue(); + } + return nd; + } else if (dt2 == CDF_REAL8 || dt2 == CDF_DOUBLE) { + double[] nd = new double[items]; + for (int i = 0; i < items; ++i) { + str = ((String[]) data)[i]; + str2 = specialString(str); + if (str2 != null) + nd[i] = ((Double) handleSpecial (dt2, str2)).doubleValue(); + else + nd[i] = new Double(str).doubleValue(); + } + return nd; + } else + return data; + } + } + if (equivalentDataTypes(dt1, dt2)) return data; + if (data instanceof Double) { + return new Float(((Double)data).floatValue()); + } else if (data instanceof Integer) { + if (dt1 == CDF_INT1 || dt1 == CDF_BYTE) + return new Byte(((Integer)data).byteValue()); + else if (dt1 == CDF_INT2 || dt1 == CDF_UINT1) + return new Short(((Integer)data).shortValue()); + } else { + if (signature.charAt(0) == '[') { + if (signature.charAt(1) == 'D') { + int items = ((double[])data).length; + float[] nd = new float[items]; + for (int i = 0; i < items; ++i) + nd[i] = (float) ((double[])data)[i]; + return nd; + } else { + if (dt1 == CDF_INT1 || dt1 == CDF_BYTE) { + int items = ((int[])data).length; + byte[] nd = new byte[items]; + for (int i = 0; i < items; ++i) + nd[i] = (byte) ((int[])data)[i]; + return nd; + } else if (dt1 == CDF_INT2 || dt1 == CDF_UINT1) { + int items = ((int[])data).length; + short[] nd = new short[items]; + for (int i = 0; i < items; ++i) + nd[i] = (short) ((int[])data)[i]; + return nd; + } else + return data; + } + } + } + return data; + } + + private static Object handleMixed (int items, Object data) { + + int ix; + int iz = 0; + for (ix = 0; ix < items; ++ix) { + Object one = ((JsonArray)data).get(ix); + if (one instanceof JsonString) { + String str = ((JsonString)one).getString(); + if (specialString(str) == null) { + ++iz; + } + } + } + if (iz != 0) { + System.out.println("???? mixed number & string ?????"); + return null; + } else { + Object outs; + if (dataType == CDF_REAL4 || dataType == CDF_FLOAT) + outs = new double[items]; + else + outs = new double[items]; + for (ix = 0; ix < items; ++ix) { + Object one = ((JsonArray)data).get(ix); + if (one instanceof JsonString) { + String str = ((JsonString)one).getString(); + String str2 = specialString(str); + Object out1 = handleSpecial (dataType, str2); + if (dataType == CDF_REAL4 || dataType == CDF_FLOAT) + ((float[])outs)[ix] = ((Float)out1).floatValue(); + else + ((double[])outs)[ix] = ((Double)out1).doubleValue(); + } else { + if (dataType == CDF_REAL4 || dataType == CDF_FLOAT) + ((float[])outs)[ix] = Float.parseFloat(((JsonNumber)one).toString()); + else + ((double[])outs)[ix] = Double.parseDouble(((JsonNumber)one).toString()); + } + } + return outs; + } + } + + private static Object getData (Object data) { + + String signature = CDFUtils.getSignature(data); + if (data instanceof JsonString) { + String value = ((JsonString)data).toString(); + if (value.charAt(0) == '"') + value = value.substring(1, value.length()-1); + int len = value.length(); + if (len < 14 || value.charAt(4) != '-' || value.charAt(7) != '-' || + value.charAt(10) != 'T' || value.charAt(13) != ':') { + dataType = CDF_CHAR; + return value; + } else { + numElements = 1; + try { + if (value.length() == 23 || value.length() == 24) { // CDF_EPOCH + dataType = CDF_EPOCH; + return new Double(Epoch.toParse(value)); + } else if (value.length() == 29 || value.length() == 30) {//TT2000 + dataType = CDF_TIME_TT2000; + return new Long(CDFTT2000.toParse(value)); + } else { // CDF_EPOCH16 + dataType = CDF_EPOCH16; + double[] epoch16 = Epoch16.toParse(value); + return epoch16; + } + } catch (Exception ee) { + return value; + } + } + } else if (data instanceof JsonNumber) { + numElements = 1; + if (((JsonNumber)data).isIntegral()) { + try { + int aa = Integer.parseInt(((JsonNumber)data).toString()); + dataType = CDF_INT4; + return new Integer(aa); + } catch (Exception ee) { + long bb = Long.parseLong(((JsonNumber)data).toString()); + dataType = CDF_INT8; + return new Long(bb); + } + } else { + double bb = Double.parseDouble(((JsonNumber)data).toString()); + dataType = CDF_DOUBLE; + return new Double(bb); + } + } else if (data instanceof JsonArray) { + Object one = ((JsonArray)data).get(0); + int items = ((JsonArray)data).size(); + int ix, iy, iz; + iy = iz = 0; + for (ix = 0; ix < items; ++ix) { + Object one1 = ((JsonArray)data).get(ix); + if (one1 instanceof JsonString) { + ++iy; + String stri = ((JsonString)one1).getString(); + String stri2 = specialString(stri); + if (stri2 != null) + ++iz; + } + } + + if ((iy != 0 && iy != items) || (iz == items)) { + dataType = CDF_DOUBLE; + return handleMixed (items, data); + } + + if (iy == items) { + String oneS = ((JsonString)one).toString(); + if (oneS.length() < 10 || oneS.charAt(10) != 'T') { + dataType = CDF_CHAR; + String[] outs = new String[items]; + for (int ii = 0; ii < items; ++ii) { + outs[ii] = ((JsonString)((JsonArray)data).get(ii)).toString(); + } + return outs; + } else { // CDF epoch data + double[] outs1 = null; + long[] outs2 = null; + for (int ii = 0; ii < items; ++ii) { + Object aa = getData((Object)(((JsonArray)data).get(ii))); + if (ii == 0) { + if (dataType == CDF_EPOCH) outs1 = new double[items]; + else if (dataType == CDF_EPOCH) outs1 = new double[2*items]; + else outs2 = new long[items]; + } + if (dataType == CDF_EPOCH) + outs1[ii] = ((Double)aa).doubleValue(); + else if (dataType == CDF_EPOCH) + outs2[ii] = ((Long)aa).longValue(); + else { + outs1[2*ii] = ((double[])aa)[0]; + outs1[2*ii+1] = ((double[])aa)[1]; + } + } + if (dataType == CDF_EPOCH || dataType == CDF_EPOCH16) + return outs1; + else + return outs2; + } + } else if (iy == 0) { + if (((JsonNumber)one).isIntegral()) { + try { + dataType = CDF_INT4; + int[] outs1 = new int[items]; + for (int ii = 0; ii < items; ++ii) { + outs1[ii] = Integer.parseInt( + ((JsonNumber)((JsonArray)data).get(ii)). + toString()); + } + return outs1; + } catch (Exception ee) { + dataType = CDF_INT8; + long[] outs2 = new long[items]; + for (int ii = 0; ii < items; ++ii) { + outs2[ii] = Long.parseLong( + ((JsonNumber)((JsonArray)data).get(ii)). + toString()); + } + return outs2; + } + } else { + dataType = CDF_DOUBLE; + double[] outs1 = new double[items]; + for (int ii = 0; ii < items; ++ii) { + outs1[ii] = Double.parseDouble( + ((JsonNumber)((JsonArray)data).get(ii)). + toString()); + } + return outs1; + } + } else { + System.out.println(" ?????"); + } + } else + System.out.println(" NONE"); + return null; + } + + private static String specialString (String string) { + String str = string.toLowerCase(); + if (str.startsWith("\"")) + str = str.substring(1, str.length()-1); + if (str.equals("nan") || str.equals("-nan") || + str.equals("inf") || str.equals("-inf")) + return str; + else + return null; + } + + private static Object setData (Object values, Object buf, int items, + int recNum) throws CDFException { + + int count = 0; + for (int jj = 0; jj < recNum; ++jj) { + Object data = (Object) ((JsonArray)values).get(jj); + String signature = CDFUtils.getSignature(data); + Object newObj = null; + if (data instanceof JsonString) { + String str = ((JsonString)data).getString(); + String str2 = specialString(str); + if (str2 != null) { + newObj = handleSpecial (varDataType, str2); + if (varDataType == CDF_REAL4 || varDataType == CDF_FLOAT) { + if (items == 1) + return newObj; + else + ((float[])buf)[jj] = ((Float)newObj).floatValue(); + } + if (varDataType == CDF_REAL8 || varDataType == CDF_DOUBLE) { + if (items == 1) + return newObj; + else + ((double[])buf)[jj] = ((Double)newObj).doubleValue(); + } + continue; + } else + newObj = setData1 (data); + if (items == 1) + return newObj; + else { + if (varDataType == CDF_EPOCH) { + ((double[])buf)[jj] = ((Double)newObj).doubleValue(); + } else if (varDataType == CDF_TIME_TT2000) { + ((long[])buf)[jj] = ((Long)newObj).longValue(); + } else if (varDataType == CDF_EPOCH16) { + ((double[])buf)[2*jj] = ((double[])newObj)[0]; + ((double[])buf)[2*jj+1] = ((double[])newObj)[1]; + } else { + byte[] by = ((String)newObj).getBytes(); + int len = ((String)newObj).length(); + for (int xy = 0; xy < len; ++xy) + ((byte[])buf)[count+xy] = by[xy]; + for (int xy = len; xy < varNumElems; ++xy) + ((byte[])buf)[count+xy] = (byte) 0; + count += varNumElems; + } + } + } else if (data instanceof JsonNumber) { + newObj = setData1 (data); + if (items == 1) + return newObj; + else { + switch ((int)varDataType) { + case (int)CDF_BYTE: + case (int)CDF_INT1: + ((byte[])buf)[jj] = ((Byte)newObj).byteValue(); + break; + case (int)CDF_INT2: + case (int)CDF_UINT1: + ((short[])buf)[jj] = (short)((JsonNumber)data).intValue(); + break; + case (int)CDF_INT4: + case (int)CDF_UINT2: + ((int[])buf)[jj] = ((JsonNumber)data).intValue(); + break; + case (int)CDF_UINT4: + case (int)CDF_INT8: + ((long[])buf)[jj] = ((JsonNumber)data).longValue(); + break; + case (int)CDF_REAL4: + case (int)CDF_FLOAT: + ((float[])buf)[jj] = (float)((JsonNumber)data).doubleValue(); + break; + case (int)CDF_REAL8: + case (int)CDF_DOUBLE: + ((double[])buf)[jj] = ((JsonNumber)data).doubleValue(); + break; + default: + break; + } + } + } else if (data instanceof JsonArray) { + int items2 = ((JsonArray)data).size(); + Object one = ((JsonArray)data).get(0); + if (one instanceof JsonString) { + for (int ii = 0; ii < items2; ++ii) { + String str = ((JsonString)((JsonArray)data).get(ii)).toString(); + Object oneObj = setData1 (str); + if (varDataType == CDF_CHAR || varDataType == CDF_UCHAR) { + int lenx = ((String)oneObj).length(); + byte[] by = ((String)oneObj).getBytes(); + for (int xy = 0; xy < lenx; ++xy) + ((byte[])buf)[count+xy] = by[xy]; + for (int xy = lenx; xy < varNumElems; ++xy) + ((byte[])buf)[count+xy] = (byte) 0; + count += varNumElems; + } else if (varDataType == CDF_EPOCH) { // CDF epoch data + ((double[])buf)[count++] = ((Double)oneObj).doubleValue(); + } else if (varDataType == CDF_TIME_TT2000) { // CDF epoch data + ((long[])buf)[count++] = ((Long)oneObj).longValue(); + } else if (varDataType == CDF_EPOCH16) { // CDF epoch data + ((double[])buf)[count] = ((double[])oneObj)[0]; + ((double[])buf)[count+1] = ((double[])oneObj)[1]; + count += 2; + } + } + } else if (one instanceof JsonNumber) { + for (int ii = 0; ii < items2; ++ii) { + Object single = (Object) ((JsonArray)data).get(ii); + Object oneObj = setData1 (single); + switch ((int)varDataType) { + case (int)CDF_BYTE: + case (int)CDF_INT1: + ((byte[])buf)[count++] = ((Byte)oneObj).byteValue(); + break; + case (int)CDF_INT2: + case (int)CDF_UINT1: + ((short[])buf)[count++] = ((Short)oneObj).shortValue(); + break; + case (int)CDF_INT4: + case (int)CDF_UINT2: + ((int[])buf)[count++] = ((Integer)oneObj).intValue(); + break; + case (int)CDF_UINT4: + case (int)CDF_INT8: + ((long[])buf)[count++] = ((Long)oneObj).longValue(); + break; + case (int)CDF_REAL4: + case (int)CDF_FLOAT: + ((float[])buf)[count++] = ((Float)oneObj).floatValue(); + break; + case (int)CDF_REAL8: + case (int)CDF_DOUBLE: + ((double[])buf)[count++] = ((Double)oneObj).doubleValue(); + break; + default: + break; + } // switch + } // end of array + } + } else { + System.out.println(" ?????"); + return null; + } + } + return buf; + } + + private static Object setData1 (Object data) throws CDFException { + + String value; + if (data instanceof JsonString || data instanceof String) { + if (data instanceof JsonString) + value = ((JsonString)data).toString(); + else + value = (String) data; + if (value.charAt(0) == '"') + value = value.substring(1, value.length()-1); + if (varDataType == CDF_EPOCH) { + return new Double(Epoch.toParse(value)); + } else if (varDataType == CDF_TIME_TT2000) { + return new Long(CDFTT2000.toParse(value)); + } else if (varDataType == CDF_EPOCH16) { + double[] epoch16 = Epoch16.toParse(value); + return epoch16; + } else + return value; + } else if (data instanceof JsonNumber) { + switch ((int)varDataType) { + case (int)CDF_BYTE: + case (int)CDF_INT1: + return new Byte((byte)((JsonNumber)data).intValue()); + case (int)CDF_INT2: + case (int)CDF_UINT1: + return new Short((short)((JsonNumber)data).intValue()); + case (int)CDF_INT4: + case (int)CDF_UINT2: + return new Integer(((JsonNumber)data).intValue()); + case (int)CDF_UINT4: + case (int)CDF_INT8: + return new Long(((JsonNumber)data).longValue()); + case (int)CDF_REAL4: + case (int)CDF_FLOAT: + return new Float(((JsonNumber)data).doubleValue()); + case (int)CDF_REAL8: + case (int)CDF_DOUBLE: + return new Double(((JsonNumber)data).doubleValue()); + default: + return null; + } + } + return null; + } + + private static void exit (String msg) { + if (!msg.equals("")) System.out.println (msg); + usage(); + System.exit(1); + } + + /************************************************************************* + * Print the proper syntax for invoking this program. + ************************************************************************/ + private static void usage() { + System.out.println ("\nDescription:"); + System.out.println (" This program exports the contents of a Json "+ + "file into a CDF file(s)."); + System.out.println (""); + System.out.println ("Usage: java Json2CDF [Options] JsonFileName "); + System.out.println (" JsonFileName: The name of the Json file used "+ + "to create a CDF(s)."); + System.out.println (" "); + System.out.println ("Options: "); + System.out.println (" "); + System.out.println (" -output:outputFileName"); + System.out.println (" Use this option to specify a different "+ + "output file name for the CDF."); + System.out.println (" It is only applicable to a single CDF file "+ + "output."); + System.out.println (" "); + System.out.println (" -outdir:outputDir"); + System.out.println (" Specifies a directory to hold the output "+ + "CDF file(s). Make sure the"); + System.out.println (" directory exists and is writeable."); + System.out.println (" "); + System.out.println (" -vardata:[yes | no]. -vardata:yes is the "+ + "default."); + System.out.println (" Whether to extract var data in the Json "+ + "file if it is there. If \"no\""); + System.out.println (" is specified, non-record varying variables' "+ + "data will not be extracted."); + System.out.println (" "); + System.out.println (" -[showProgress | Progress]"); + System.out.println (" This option displays the processing "+ + "progress on the screen."); + System.out.println (" It shows how many CDF variables are there "+ + "to process and which"); + System.out.println (" variable is being processed."); + System.out.println (" "); + System.out.println (" -checksum"); + System.out.println (" This option adds checksum to the file."); + System.out.println (" "); + System.out.println (" -nocompress"); + System.out.println (" This option forces no compression for "+ + "variable data. By default, a"); + System.out.println (" variable with large enough size (>1K) will "+ + "be compressed, no matter if"); + System.out.println (" defined by its specification or not."); + System.out.println (" "); + System.out.println (" -delete"); + System.out.println (" Over-ride the CDF file(s) if it already"+ + "exists."); + System.out.println (""); + System.out.println (" -showfile"); + System.out.println (" Display the Json file being processed."); + System.out.println (""); + System.out.println ("NOTE:"); + System.out.println (" 1. All integral values are converted into 4-byte"+ + " integer, if they can fill. "); + System.out.println (" Otherwise, 8-byte long are used. All floating"+ + "-values are converted into "); + System.out.println (" 8-byte doubles."); + System.out.println (" 2. A varying dimension with size of 1 is "+ + "considered as non-varying."); + System.out.println (" Its dimension is removed and NOT shown."); + System.out.println (" 3. Values for variable attributes: VALIDMIN/"+ + "VALIDMAX/SCALEMIN/SCALEMAX/FILLVAL"); + System.out.println (" will have the same data type as the variable's."); + System.out.println (" 4. All variables are zVariables."); + System.out.println (" 5. All \"NaN\"|\"-NaN\" and \"INF\"|\"-INF\" "+ + "strings are converted into"); + System.out.println (" floating-point values. "); + System.out.println (""); + System.out.println ("Examples: "); + + System.out.println (" java Json2CDF test.json (same as "+ + "java Json2CDF -json:test.cdf test.json)"); + System.out.println (""); + System.out.println ("The Json file should have the following form: "+ + "(made from CDF2Json):\n"+ + "CDFname1: \n"+ + " CDFFileInfo: \n"+ + " FileVersion:..... \n"+ + " Format:..... \n"+ + " Majority:... \n"+ + " Encoding:..... \n"+ + " CDFglobalAttributes: \n"+ + " Gattr_name1: \n"+ + " entry#:value \n"+ + " ... \n"+ + " Gattr_name2: \n"+ + " entry#:value \n"+ + " ... \n"+ + " ... \n"+ + " ... \n"+ + " CDFVariables: \n"+ + " VarName1: \n"+ + " VarDescription: \n"+ + " DataType:.... \n"+ + " ... \n"+ + " ... \n"+ + " VarAttributes: \n"+ + " VALIDMIN:.... \n"+ + " ... \n"+ + " ... \n"+ + " VarData: \n"+ + " ... \n"+ + " VarName2: \n"+ + " VarDescription: \n"+ + " DataType:.... \n"+ + " ... \n"+ + " ... \n"+ + " VarAttributes: \n"+ + " ... \n"+ + " ... \n"+ + " VarData: \n"+ + " ... \n"+ + " EmptyAttributes: <== If attribute(s) defined but not assign value(s) \n"+ + " GlobalAttributes: <== If global attribute(s) is not assigned value \n"+ + " VariableAttributes: <== If variable attribute(s) is not assigned value \n"+ + " \n"+ + "CDFname2: \n"+ + " CDFFileInfo: \n"+ + " ..... \n"+ + " ..... \n"+ + " CDFglobalAttributes: \n"+ + " Gattr_name1: \n"+ + " ... \n"+ + " Gattr_name2: \n"+ + " ... \n"+ + " ... \n"+ + " ... \n"+ + " CDFVariables: \n"+ + " VarName1: \n"+ + " VarDescription: \n"+ + " .... \n"+ + " ...."); + + System.out.println (" "); + } + + private static void processGlobalAttributes (CDF cdf, + JsonArray globalAttrArray) + throws CDFException { + + for (JsonValue attrInfo : globalAttrArray) { + for (String attrName: ((JsonObject)attrInfo).keySet()) { + if (progress) System.out.println(" "+attrName); + Attribute attr = Attribute.create(cdf, attrName, GLOBAL_SCOPE); + JsonArray entries = ((JsonObject)attrInfo).getJsonArray(attrName); + for (int ii = 0; ii < entries.size(); ++ii) { + JsonObject entry = entries.getJsonObject(ii); + for (String entryID: entry.keySet()) { + Object value = getData ((Object)(entry.get(entryID))); + if (progress) System.out.println(" "+entryID+":"+value); + Entry.create(attr, new Integer(entryID).intValue(), + dataType, value); + } + } + } + } + } + + private static Variable processVariableSpec (CDF cdf, String varName, + Object values) + throws CDFException { + + Object padValue = null; + varPadValue = null; + varSparseRec = NO_SPARSERECORDS; + long compression = -1, compLvl = 0; + long blockingFactor = -1; + int items = ((JsonArray)values).size(); + varDataType = varNumElems = varNumDims = varMaxWritten = -1; + for (int jj = 0; jj < items; ++jj) { + Object data = (Object) ((JsonArray)values).get(jj); + if (data instanceof JsonObject) { + for (String keyx: ((JsonObject)data).keySet()) { + Object des = ((JsonObject)data).get(keyx); + if (progress) System.out.println(" "+keyx+":"+des); + if (keyx.equalsIgnoreCase("varname")) { + } else if (keyx.equalsIgnoreCase("datatype")) { + String dt = ((JsonObject)data).getString(keyx); + varDataType = CDFUtils.getDataTypeValue(dt); + } else if (keyx.equalsIgnoreCase("numelements")) { + varNumElems = (long) ((JsonObject)data).getInt(keyx); + } else if (keyx.equalsIgnoreCase("numdims")) { + varNumDims = (long) ((JsonObject)data).getInt(keyx); + } else if (keyx.equalsIgnoreCase("dimsizes")) { + JsonArray ds = ((JsonObject)data).getJsonArray(keyx); + for (int j = 0; j < (int)varNumDims; ++j) { + varDimSizes[j] = (long) ds.getInt(j); + } + } else if (keyx.equalsIgnoreCase("recvariance")) { + String rv = ((JsonObject)data).getString(keyx); + if (rv.equalsIgnoreCase("vary")) varRecVary = VARY; + else varRecVary = NOVARY; + } else if (keyx.equalsIgnoreCase("dimvariances")) { + JsonArray dv = ((JsonObject)data).getJsonArray(keyx); + for (int j = 0; j < (int)varNumDims; ++j) { + String dv1 = dv.getString(j); + if (dv1.equalsIgnoreCase("vary")) + varDimVariances[j] = VARY; + else + varDimVariances[j] = NOVARY; + } + } else if (keyx.equalsIgnoreCase("compression")) { + String cp = ((JsonObject)data).getString(keyx); + String cType = cp.substring(0, cp.indexOf('.')); + String cLvl = cp.substring(cp.indexOf('.')+1); + compression = CDFUtils.getLongCompressionType(cType); + compLvl = new Long(cLvl).longValue(); + } else if (keyx.equalsIgnoreCase("blockingfactor")) { + blockingFactor = (long) ((JsonObject)data).getInt(keyx); + } else if (keyx.equalsIgnoreCase("sparserecords")) { + String sr = ((JsonObject)data).getString(keyx); + varSparseRec = CDFUtils.getLongSparseRecord(sr); + } else if (keyx.equalsIgnoreCase("numwrittenrecords")) { + varNumWritten = (long) ((JsonObject)data).getInt(keyx); + } else if (keyx.equalsIgnoreCase("maxwrittenrec")) { + varMaxWritten = (long) ((JsonObject)data).getInt(keyx); + } else if (keyx.equalsIgnoreCase("padvalue")) { + padValue = (Object) ((JsonObject)data).get(keyx); + } else + System.out.println("NOT handling... "+keyx); + } + } + } + + if (progress) { + System.out.print("***** Creating... var:"+varName+" "+" type:"+ + CDFUtils.getStringDataType(varDataType)+ + " numElms="+varNumElems+" numDims="+varNumDims+" "); + if (varNumDims > 0) { + System.out.print("dimSize=["); + for (int ll= 0; ll < (int)varNumDims; ++ll) { + System.out.print(varDimSizes[ll]); + if (ll < (varNumDims-1)) System.out.print(","); + if (ll == (varNumDims-1)) System.out.print("] "); + } + } + System.out.println("RecVary="+(varRecVary==-1?"T":"F")); + } + + if (varDataType == -1 || varNumElems == -1 || varNumDims == -1) + return null; + Variable va = Variable.create(cdf, varName, varDataType, varNumElems, + varNumDims, varDimSizes, varRecVary, + varDimVariances); + varFillVal = null; + if (padValue != null) { + varPadValue = setData1 (padValue); + va.setPadValue(varPadValue); + } + if (toCompress && varSparseRec == NO_SPARSERECORDS) { + if (compression != -1) + va.setCompression(compression, new long[] {compLvl}); + else { + long nValues = (varMaxWritten==-1?0:varMaxWritten) + 1; + for (int ll = 0; ll < (int)varNumDims; ++ll) + nValues *= varDimSizes[ll]; + nValues *= varNumElems; + nValues *= getDataTypeSize(varDataType); + if (nValues > 1000) { + compression = GZIP_COMPRESSION; + compLvl = 6; + va.setCompression(compression, new long[] {compLvl}); + } + } + } + if (blockingFactor != -1) + va.setBlockingFactor(blockingFactor); + if (varSparseRec != NO_SPARSERECORDS) + va.setSparseRecords(varSparseRec); + return va; + } + + private static void processVariableAttributes (CDF cdf, Variable va, + Object values) + throws CDFException { + int items = ((JsonArray)values).size(); + for (int jj = 0; jj < items; ++jj) { + Attribute attr = null; + Object data = (Object) ((JsonArray)values).get(jj); + if (data instanceof JsonObject) { + for (String keyx: ((JsonObject)data).keySet()) { + Object des = ((JsonObject)data).get(keyx); + if (progress) System.out.println(" "+keyx+":"+des); + Object outs = getData(des); + try { + attr = Attribute.create(cdf, keyx, VARIABLE_SCOPE); + } catch (CDFException ss) { + attr = cdf.getAttribute(keyx); + } + if (keyx.equalsIgnoreCase("validmin") || + keyx.equalsIgnoreCase("validmax") || + keyx.equalsIgnoreCase("scalemin") || + keyx.equalsIgnoreCase("scalemax") || + keyx.equalsIgnoreCase("fillval")) { + outs = changeData(dataType, varDataType, outs); + dataType = varDataType; + if (keyx.equalsIgnoreCase("fillval")) + varFillVal = outs; + } + va.putEntry(attr, dataType, outs); + } + } + } + } + + private static void processVariableData (Variable va, Object varData) + throws CDFException { + int recNum, items, nItems = 1; + recNum = 1; + items = 1; + for (int ii = 0; ii < varNumDims; ++ii) items *= varDimSizes[ii]; + if (varData instanceof JsonArray) { + nItems = ((JsonArray)varData).size(); + } + if (varRecVary == VARY) { + if ((((JsonArray)varData).get(0)) instanceof JsonArray) + recNum = nItems; + else + recNum = nItems / items; + } + String signature = CDFUtils.getSignature(varData); + int nBytes = 1; + Object realData = null; + Object outs = null; + if (varDataType == CDF_CHAR || varDataType == CDF_UCHAR) + nBytes = items * (int) varNumElems * recNum; + if (varSparseRec == NO_SPARSERECORDS) + items *= recNum; + if (items > 1) { + if (varDataType == CDF_INT1 || varDataType == CDF_BYTE) { + outs = (Object) new byte[items]; + } else if (varDataType == CDF_INT2 || varDataType == CDF_UINT1) { + outs = (Object) new short[items]; + } else if (varDataType == CDF_INT4 || varDataType == CDF_UINT2) { + outs = (Object) new int[items]; + } else if (varDataType == CDF_INT8 || varDataType == CDF_UINT4 || + varDataType == CDF_TIME_TT2000) { + outs = (Object) new long[items]; + } else if (varDataType == CDF_REAL4 || varDataType == CDF_FLOAT) { + outs = (Object) new float[items]; + } else if (varDataType == CDF_REAL8 || varDataType == CDF_DOUBLE || + varDataType == CDF_EPOCH) { + outs = (Object) new double[items]; + } else if (varDataType == CDF_EPOCH16) { + outs = (Object) new double[items*2]; + } else if (varDataType == CDF_CHAR || varDataType == CDF_UCHAR) { + outs = (Object) new byte[nBytes]; + } + } + if (varSparseRec == NO_SPARSERECORDS) { + if (varData instanceof JsonArray) + realData = setData((Object) varData, + (items==1?null:(Object)outs), items, + (recNum==1?items:recNum)); + else + realData = setData1(varData); + va.putRecords(0L, (long) recNum, realData); + } else { + Object filledData = null; + if (varSparseRec == PAD_SPARSERECORDS) { + if (varFillVal != null) filledData = varFillVal; + else filledData = varPadValue; + } + for (int ii = 0; ii < recNum; ++ii) { + Object data = (Object) ((JsonArray)varData).get(ii); + if (data instanceof JsonArray) + realData = setData(data, (items==1?null:(Object)outs), items, + items); + else + realData = setData1(data); + boolean virtual = checkForVirtual (realData, filledData); + if (!virtual) { + va.putRecord((long)ii, realData); + if (varSparseRec == PREV_SPARSERECORDS) + filledData = realData; + } + } + } + } + + private static boolean checkForVirtual (Object data, Object filledData) { + + if (filledData == null) return false; + String signature = CDFUtils.getSignature(data); + String sig2 = CDFUtils.getSignature(filledData); + if (signature.charAt(0) == '[') { + if (varDataType == CDF_INT1 || varDataType == CDF_BYTE) { + int itemN = ((byte[])data).length; + for (int ik = 0; ik < itemN; ++ik) { + if (sig2.charAt(0) == '[') { + if (((byte[])data)[ik] != ((byte[])filledData)[ik]) + return false; + } else { + if (((byte[])data)[ik] != ((Byte)filledData).byteValue()) + return false; + } + } + return true; + } else if (varDataType == CDF_INT2 || varDataType == CDF_UINT1) { + int itemN = ((short[])data).length; + for (int ik = 0; ik < itemN; ++ik) { + if (sig2.charAt(0) == '[') { + if (((short[])data)[ik] != ((short[])filledData)[ik]) + return false; + } else { + if (((short[])data)[ik] != ((Short)filledData).shortValue()) + return false; + } + } + return true; + } else if (varDataType == CDF_INT4 || varDataType == CDF_UINT2) { + int itemN = ((int[])data).length; + for (int ik = 0; ik < itemN; ++ik) { + if (sig2.charAt(0) == '[') { + if (((int[])data)[ik] != ((int[])filledData)[ik]) + return false; + } else { + if (((int[])data)[ik] != ((Integer)filledData).intValue()) + return false; + } + } + return true; + } else if (varDataType == CDF_INT8 || varDataType == CDF_UINT4 || + varDataType == CDF_TIME_TT2000) { + int itemN = ((long[])data).length; + for (int ik = 0; ik < itemN; ++ik) { + if (sig2.charAt(0) == '[') { + if (((long[])data)[ik] != ((long[])filledData)[ik]) + return false; + } else { + if (((long[])data)[ik] != ((Long)filledData).longValue()) + return false; + } + } + return true; + } else if (varDataType == CDF_REAL4 || varDataType == CDF_FLOAT) { + int itemN = ((float[])data).length; + for (int ik = 0; ik < itemN; ++ik) { + if (sig2.charAt(0) == '[') { + if (((float[])data)[ik] != ((float[])filledData)[ik]) + return false; + } else { + if (((float[])data)[ik] != ((Float)filledData).floatValue()) + return false; + } + } + return true; + } else if (varDataType == CDF_REAL8 || varDataType == CDF_DOUBLE || + varDataType == CDF_EPOCH) { + int itemN = ((double[])data).length; + for (int ik = 0; ik < itemN; ++ik) { + if (sig2.charAt(0) == '[') { + if (((double[])data)[ik] != ((double[])filledData)[ik]) + return false; + } else { + if (((double[])data)[ik] != ((Double)filledData).doubleValue()) + return false; + } + } + return true; + } + } else { + if (varDataType == CDF_INT1 || varDataType == CDF_BYTE) { + if (((Byte)data).byteValue() != ((Byte)filledData).byteValue()) + return false; + else + return true; + } else if (varDataType == CDF_INT2 || varDataType == CDF_UINT1) { + if (((Short)data).shortValue() != ((Short)filledData).shortValue()) + return false; + else + return true; + } else if (varDataType == CDF_INT4 || varDataType == CDF_UINT2) { + if (((Integer)data).intValue() != ((Integer)filledData).intValue()) + return false; + else + return true; + } else if (varDataType == CDF_INT8 || varDataType == CDF_UINT4 || + varDataType == CDF_TIME_TT2000) { + if (((Long)data).longValue() != ((Long)filledData).longValue()) + return false; + else + return true; + } else if (varDataType == CDF_REAL4 || varDataType == CDF_FLOAT) { + if (((Float)data).floatValue() != ((Float)filledData).floatValue()) + return false; + else + return true; + } else if (varDataType == CDF_REAL8 || varDataType == CDF_DOUBLE || + varDataType == CDF_EPOCH) { + if (((Double)data).doubleValue() != ((Double)filledData).doubleValue()) + return false; + else + return true; + } else + return false; + } + return false; + } + + private static int getDimSize (Object obj) { + String sig = CDFUtils.getSignature(obj); + String what = sig.substring(0,2); + if (what.equals("[I")) return ((int[])obj).length; + else if (what.equals("[B")) return ((byte[])obj).length; + else if (what.equals("[J")) return ((long[])obj).length; + else if (what.equals("[S")) return ((short[])obj).length; + else if (what.equals("[F")) return ((float[])obj).length; + else if (what.equals("[D")) return ((double[])obj).length; + return 1; + } + + private static int getDataTypeSize (long dataType) { + int size; + switch ((int)dataType) { + case (int)CDF_BYTE: + case (int)CDF_INT1: + case (int)CDF_UINT1: + case (int)CDF_CHAR: + case (int)CDF_UCHAR: + size = 1; + break; + case (int)CDF_INT2: + case (int)CDF_UINT2: + size = 2; + break; + case (int)CDF_INT4: + case (int)CDF_UINT4: + case (int)CDF_REAL4: + case (int)CDF_FLOAT: + size = 4; + break; + case (int)CDF_INT8: + case (int)CDF_TIME_TT2000: + case (int)CDF_REAL8: + case (int)CDF_DOUBLE: + case (int)CDF_EPOCH: + size = 8; + break; + case (int)CDF_EPOCH16: + size = 16; + break; + default: + size = 1; + break; + } + return size; + } + +} + diff --git a/cdf38_1-dist/cdfjava/cdfjson/Readme.txt b/cdf38_1-dist/cdfjava/cdfjson/Readme.txt new file mode 100755 index 0000000..8c40d8f --- /dev/null +++ b/cdf38_1-dist/cdfjava/cdfjson/Readme.txt @@ -0,0 +1,50 @@ +*************************************************************************** +* Please make sure that you have done the following before proceeding * +* with the CDF Json utilities: * +* * +* - Installed JDK 1.7 or later. * +* - Installed/built the CDF distribution package. * +* - On Windows, executed the setenv.bat located in the top * +* distribution to set up proper environment variables. On other * +* platforms, run the similar script in bin directory once the * +* distribution is built/installed. * +*************************************************************************** + +Instructions for using the CDF's Json programs +----------------------------------------------- + +1. Make sure that CDF distribution is installed. If downloading the source, + the CDF-JNI library needs to be built. + +2. Set the CLASSPATH environment variable to the directory that contains + cdfjava.jsr, cdfjson.jar and other jar files that comes from the CDF + distribution. + +3. CDF2Json: convert a CDF file into a CDF-specific Json form. + + To get the help information and valid arguments/options, enter: + + java CDF2Json + + Use the proper options to run the converter. + +4. Json2CDF: convert a CDF-specific Json file into a CDF file. + + To get the instructions and valid arguments/options, enter: + + java Json2CDF + + Use the proper options to run the converter. + +5. CDFJsonReader: display the data contents from a CDF-specific Json file + + To get the instructions and valid arguments/options, enter: + + java CDFJsonReader + + Use the proper options to run the reader. + +Please send any comments or questions to: + + NASA-CDF-Support@nasa.onmicrosoft.com + diff --git a/cdf38_1-dist/cdfjava/cdfjson/ShowCDFJson.java b/cdf38_1-dist/cdfjava/cdfjson/ShowCDFJson.java new file mode 100644 index 0000000..6613eb3 --- /dev/null +++ b/cdf38_1-dist/cdfjava/cdfjson/ShowCDFJson.java @@ -0,0 +1,66 @@ +import java.io.*; +import java.text.*; +import java.util.*; +import java.lang.*; +import java.lang.reflect.*; +import gsfc.nssdc.cdf.*; +import gsfc.nssdc.cdf.util.*; +import com.google.gson.*; + +/** + * This program demonstrates how to read the contents of a CDF file. + */ + +public class ShowCDFJson implements CDFConstants{ + + public static void main(String[] args) { + if (args.length == 0) { + System.out.println ("Java ShowCDFJson a_cdf_file "); + System.exit(1); + } + try { + CDF cdf = CDF.open(args[0]); + + Map acdf = cdf.readCDF(); + System.out.println("Total cdf size: " + acdf.size()); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + System.out.println(gson.toJson(acdf)); +/* + Map basic = cdf.readCDFInfo(); + System.out.println(gson.toJson(basic)); + + Map globals = cdf.readCDFGlobalAttributes(); + System.out.println(gson.toJson(globals)); + + Map spec = cdf.readCDFVariablesSpec(); + System.out.println(gson.toJson(spec)); + + Map meta = cdf.readCDFVariablesMetaData(); + System.out.println(gson.toJson(meta)); + + Map data = cdf.readCDFVariablesData(); + System.out.println(gson.toJson(data)); + + for (Object key : acdf.keySet()) { + if (((String)key).equals("Variables")) { + Map vars = (Map) acdf.get(key); + for (Object varName : vars.keySet()) { + System.out.println("****** Variable=>"+varName); + Map var = (Map) vars.get(varName); + System.out.println(" meta=>"+var.get("VarMetaData")); + System.out.println(" data=>"); + CDFUtils.printData(var.get("VarData")); + } + } else { + System.out.println(key + " - " + acdf.get(key)); + } + } + System.out.println(); +*/ + cdf.close(); + } catch (Exception ex) { + System.out.println("**** error: "+ex); + } + } + +} diff --git a/cdf38_1-dist/cdfjava/cdfjson/po.txt b/cdf38_1-dist/cdfjava/cdfjson/po.txt new file mode 100644 index 0000000..af9b337 --- /dev/null +++ b/cdf38_1-dist/cdfjava/cdfjson/po.txt @@ -0,0 +1,745 @@ +po_h7_pwi_00000000_v01.cdf: + CDFFileInfo: + FileVersion:3.8.0 + Format:SINGLE + Majority:ROW + Encoding:NETWORK + CDFglobalAttributes: + TITLE: + 0:"POLAR PWI HFWR" + Project: + 0:"ISTP>International Solar-Terrestrial Physics" + Discipline: + 0:"Space Physics>Magnetospheric Science" + Source_name: + 0:"PO>Polar Plasma Laboratory" + Data_type: + 0:"H7>High Resolution Data" + Descriptor: + 0:"PWI>Plasma Wave Instrument" + Data_version: + 0:" " + TEXT: + 0:"Reference:..Gurnett, D.A. et al, The Polar plasma wave instrument, Space Science Reviews, Vol. 71, pp. 597-622, 1995.GURNETT@IOWAVE.physics.uiowa.edu" + 1:"An FFT on 1024 values was used in calibrating the data; i.e., perform FFT, calibrate in frequency domain, perform inverse FFT to get calibrated time series." + 2:"Coordinate System Used: local magnetic field-aligned, a spacecraft centered coordinate system where Z is parallel to the local B-field determined from Polar MFE, X points outward and lies in the plane defined by the Z-axis and the radial vector from the earth to the spacecraft, and Y completes a right-handed system and points eastward. The X- and Z-axes are contained in the north-south plane." + 3:"Effective Bandwidth is 1.5*delta_f, where delta_f depends on the size of the FFT used to convert to the frequency domain, and delta_t." + 4:"This data comes is in snapshots of 31816 points per channel, every 9.2 seconds, where the duration of each snapshot is 0.045 seconds. Since Epoch time is in milliseconds, the times for the data points will not be unique unless the Delta_T in milliseconds is added to the Epoch time for the snapshot." + 5:"The data in this file will be in sets of 31744 (31*1024) points per channel because the FFT size does not come out even within the number of points per snapshot. To obtain the time for each point in the snapshot, increment each Epoch time after the first with Delta_T (in ms)." + MODS: + 0:"New versioned v04 data files were delivered to SPDF starting 2012/12/20" + ADID_ref: + 0:"NSSD0171" + Logical_file_id: + 0:"po_h7_pwi_00000000_v01" + Logical_source: + 0:"po_h7_pwi" + Logical_source_description: + 0:"Polar Plasma Wave Instrument, High Frequency Waveform Receiver, 6-channel (~1.5 usec resolution) fields" + PI_name: + 0:"D. Gurnett" + PI_affiliation: + 0:"U. Iowa" + Mission_group: + 0:"Polar" + Instrument_type: + 0:"Radio and Plasma Waves (space)" + TEXT_supplement_1: + 0:" " + spase_DatasetResourceID: + 0:"spase://NASA/NumericalData/POLAR/PWI/HFWR/25kHz/PT0.000014S" + CDFVariables: + Epoch: + VarDescription: + DataType:"CDF_EPOCH" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + VarAttributes: + FIELDNAM:"Time" + CATDESC:"Time, start time of HFWR snapshot" + VAR_TYPE:"support_data" + VALIDMIN:"1996-02-27T00:00:00.000" + VALIDMAX:"2020-12-31T00:00:00.000" + MONOTON:"INCREASE" + UNITS:"ms" + LABLAXIS:"Epoch" + FILLVAL:"9999-12-31T23:59:59.999" + AVG_TYPE:" " + DICT_KEY:"time>epoch" + DISPLAY_TYPE:" " + VAR_NOTES:" Gain changes may occur at these times" + Delta_T: + VarDescription: + DataType:"CDF_REAL8" + NumElements:1 + NumDims:0 + RecVariance:"NOVARY" + NumWrittenRecords:1 + VarAttributes: + FIELDNAM:"Delta_T" + CATDESC:"Time, time between points" + VAR_TYPE:"support_data" + UNITS:"ms" + FORMAT:"E8.1" + DICT_KEY:"time" + VAR_NOTES:" " + VarData: + [0.014] + FilterMode: + VarDescription: + DataType:"CDF_INT4" + NumElements:1 + NumDims:0 + RecVariance:"NOVARY" + NumWrittenRecords:1 + VarAttributes: + FIELDNAM:"Filter Mode" + CATDESC:"Filter Mode (1 = 25 kHz, 2 = 16 kHz, 4 = 2 kHz, 8 = 250 Hz)" + VAR_TYPE:"support_data" + VALIDMIN:1 + VALIDMAX:8 + UNITS:" " + FORMAT:"I2" + FILLVAL:-2147483648 + AVG_TYPE:" " + DISPLAY_TYPE:" " + VAR_NOTES:" " + VarData: + [1] + FFT_size: + VarDescription: + DataType:"CDF_INT4" + NumElements:1 + NumDims:0 + RecVariance:"NOVARY" + NumWrittenRecords:1 + VarAttributes: + FIELDNAM:"FFT Size" + CATDESC:"Size of FFT used in calibration" + VAR_TYPE:"support_data" + VALIDMIN:0 + VALIDMAX:1024 + UNITS:" " + FORMAT:"I5" + FILLVAL:-2147483648 + AVG_TYPE:" " + DICT_KEY:"number" + DISPLAY_TYPE:" " + VAR_NOTES:" " + VarData: + [1024] + NUM_FFT: + VarDescription: + DataType:"CDF_INT4" + NumElements:1 + NumDims:0 + RecVariance:"NOVARY" + NumWrittenRecords:1 + VarAttributes: + FIELDNAM:"Num_Snap" + CATDESC:"Number of FFTs of size 1024 that were processed for one snapshot" + VAR_TYPE:"support_data" + VALIDMIN:0 + VALIDMAX:31 + UNITS:" " + FORMAT:"I4" + FILLVAL:-2147483648 + AVG_TYPE:" " + DICT_KEY:"number" + DISPLAY_TYPE:" " + VAR_NOTES:"NUM_FFT*FFT_size = #HFWR points for each channel" + VarData: + [31] + NUM_SNAP: + VarDescription: + DataType:"CDF_INT4" + NumElements:1 + NumDims:0 + RecVariance:"NOVARY" + NumWrittenRecords:1 + VarAttributes: + FIELDNAM:"Num_Snap" + CATDESC:"Number of snapshots of size 31816 that were processed for this file" + VAR_TYPE:"support_data" + VALIDMIN:0 + VALIDMAX:9392 + UNITS:" " + FORMAT:"I4" + FILLVAL:-2147483648 + AVG_TYPE:" " + DICT_KEY:"number" + DISPLAY_TYPE:" " + VAR_NOTES:" " + VarData: + [389] + Gain1: + VarDescription: + DataType:"CDF_BYTE" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + VarAttributes: + FIELDNAM:"Gain for HFWR Channel 1 (Ex)" + CATDESC:"Channel 1 Gain (HFWR) " + VAR_TYPE:"data" + VALIDMIN:0 + VALIDMAX:30 + UNITS:" " + LABLAXIS:"Ex_Gain" + DEPEND_0:"Epoch" + FORMAT:"I2" + FILLVAL:-1 + AVG_TYPE:" " + DISPLAY_TYPE:"time_series" + VAR_NOTES:" " + Gain2: + VarDescription: + DataType:"CDF_BYTE" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + VarAttributes: + FIELDNAM:"Gain for HFWR Channel 2 (Ey)" + CATDESC:"Channel 2 Gain (HFWR) " + VAR_TYPE:"data" + VALIDMIN:0 + VALIDMAX:30 + UNITS:" " + LABLAXIS:"Ey_Gain" + DEPEND_0:"Epoch" + FORMAT:"I3" + FILLVAL:-1 + AVG_TYPE:" " + DISPLAY_TYPE:"time_series" + VAR_NOTES:" " + Gain3: + VarDescription: + DataType:"CDF_BYTE" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + VarAttributes: + FIELDNAM:"Gain for HFWR Channel 3 (Ez)" + CATDESC:"Channel 3 Gain (HFWR) " + VAR_TYPE:"data" + VALIDMIN:0 + VALIDMAX:30 + UNITS:" " + LABLAXIS:"Ez_Gain" + DEPEND_0:"Epoch" + FORMAT:"I3" + FILLVAL:-1 + AVG_TYPE:" " + DISPLAY_TYPE:"time_series" + VAR_NOTES:" " + MGain: + VarDescription: + DataType:"CDF_BYTE" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + VarAttributes: + FIELDNAM:"Gain for HFWR M-Field (Bx, By, Bz)" + CATDESC:"M Gain (HFWR) " + VAR_TYPE:"data" + VALIDMIN:0 + VALIDMAX:30 + UNITS:" " + LABLAXIS:"HFWR_MGain" + DEPEND_0:"Epoch" + FORMAT:"I3" + FILLVAL:-1 + AVG_TYPE:" " + DISPLAY_TYPE:"time_series" + VAR_NOTES:"Applies to all 3 Magnetic Channels" + HFWR_Ex: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"HFWR Elec. Field Antenna Ex" + CATDESC:"[NO LIST] HFWR Elec Field Antenna Ex (perp and outward in Local-Field Aligned/LFA coords)" + VAR_TYPE:"data" + VALIDMIN:-10.0 + VALIDMAX:10.0 + UNITS:"mV/M" + LABLAXIS:"HFWR_Ex (LFA)" + DEPEND_0:"Epoch" + FORMAT:"E12.4" + FILLVAL:-1.0E+31 + AVG_TYPE:" " + DICT_KEY:"electric_field" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:"When FFT is applied, Filter Rolls off at 25 kHz" + DEPEND_1:"Data_No" + HFWR_Ey: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"HFWR Elec. Field Antenna Ey" + CATDESC:"[NO LIST] HFWR Elec Field Antenna Ey (perp and eastward in Local-Field Aligned/LFA coords)" + VAR_TYPE:"data" + VALIDMIN:-10.0 + VALIDMAX:10.0 + UNITS:"mV/M" + LABLAXIS:"HFWR_Ey (LFA)" + DEPEND_0:"Epoch" + FORMAT:"E12.4" + FILLVAL:-1.0E+31 + AVG_TYPE:" " + DICT_KEY:"electric_field" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:"When FFT is applied, Filter Rolls off at 25 kHz" + DEPEND_1:"Data_No" + HFWR_Ez: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"HFWR Elec. Field Antenna Ez" + CATDESC:"[NO LIST] HFWR Elec Field Antenna Ez (parallel in Local-Field Aligned/LFA coords)" + VAR_TYPE:"data" + VALIDMIN:-10.0 + VALIDMAX:10.0 + UNITS:"mV/M" + LABLAXIS:"HFWR_Ez (LFA)" + DEPEND_0:"Epoch" + FORMAT:"E12.4" + FILLVAL:-1.0E+31 + AVG_TYPE:" " + DICT_KEY:"electric_field" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:"When FFT is applied, Filter Rolls off at 25 kHz" + DEPEND_1:"Data_No" + HFWR_Bx: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"HFWR Mag. Field Antenna Bx" + CATDESC:"[NO LIST] HFWR Mag Field Antenna Bx (perp and outward in Local-Field Aligned/LFA coords)" + VAR_TYPE:"data" + VALIDMIN:-10.0 + VALIDMAX:10.0 + UNITS:"nT" + LABLAXIS:"HFWR_Bx (LFA)" + DEPEND_0:"Epoch" + FORMAT:"E12.4" + FILLVAL:-1.0E+31 + AVG_TYPE:" " + DICT_KEY:"magnetic_field" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:"When FFT is applied, Filter Rolls off at 25 kHz" + DEPEND_1:"Data_No" + HFWR_By: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"HFWR Mag. Field Antenna By" + CATDESC:"[NO LIST] HFWR Mag Field Antenna By (perp and eastward in Local-Field Aligned/LFA coords)" + VAR_TYPE:"data" + VALIDMIN:-10.0 + VALIDMAX:10.0 + UNITS:"nT" + LABLAXIS:"HFWR_By (LFA)" + DEPEND_0:"Epoch" + FORMAT:"E12.4" + FILLVAL:-1.0E+31 + AVG_TYPE:" " + DICT_KEY:"magnetic_field" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:"When FFT is applied, Filter Rolls off at 25 kHz" + DEPEND_1:"Data_No" + HFWR_Bz: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"HFWR Mag. Field Antenna Bz" + CATDESC:"[NO LIST] HFWR Mag Field Antenna Bz (parallel in Local-Field Aligned/LFA coords)" + VAR_TYPE:"data" + VALIDMIN:-10.0 + VALIDMAX:10.0 + UNITS:"nT" + LABLAXIS:"HFWR_Bz (LFA)" + DEPEND_0:"Epoch" + FORMAT:"E12.4" + FILLVAL:-1.0E+31 + AVG_TYPE:" " + DICT_KEY:"magnetic_field" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:"When FFT is applied, Filter Rolls off at 25 kHz" + DEPEND_1:"Data_No" + DATA_Q_Ex: + VarDescription: + DataType:"CDF_BYTE" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"DATA_QUALITY Ex" + CATDESC:"[NO LIST] Data Quality for Ex components(0 = OK, 1 = clipped or questionable)" + VAR_TYPE:"data" + VALIDMIN:0 + VALIDMAX:1 + UNITS:"(0=OK,1=Other)" + LABLAXIS:"Ex DQ" + DEPEND_0:"Epoch" + FORMAT:"I2" + FILLVAL:-1 + AVG_TYPE:" " + DICT_KEY:"flag" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:" " + DEPEND_1:"Data_No" + DATA_Q_Ey: + VarDescription: + DataType:"CDF_BYTE" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"DATA_QUALITY Ey" + CATDESC:"[NO LIST] Data Quality for Ey components(0 = OK, 1 = clipped or questionable)" + VAR_TYPE:"data" + VALIDMIN:0 + VALIDMAX:1 + UNITS:"(0=OK,1=Other)" + LABLAXIS:"Ey DQ" + DEPEND_0:"Epoch" + FORMAT:"I2" + FILLVAL:-1 + AVG_TYPE:" " + DICT_KEY:"flag" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:" " + DEPEND_1:"Data_No" + DATA_Q_Ez: + VarDescription: + DataType:"CDF_BYTE" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"DATA_QUALITY Ez" + CATDESC:"[NO LIST] Data Quality for Ez components(0 = OK, 1 = clipped or questionable)" + VAR_TYPE:"data" + VALIDMIN:0 + VALIDMAX:1 + UNITS:"(0=OK,1=Other)" + LABLAXIS:"Ez DQ" + DEPEND_0:"Epoch" + FORMAT:"I2" + FILLVAL:-1 + AVG_TYPE:" " + DICT_KEY:"flag" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:" " + DEPEND_1:"Data_No" + DATA_Q_Bx: + VarDescription: + DataType:"CDF_BYTE" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"DATA_QUALITY Bx" + CATDESC:"[NO LIST] Data Quality for Bx components(0 = OK, 1 = clipped or questionable)" + VAR_TYPE:"data" + VALIDMIN:0 + VALIDMAX:1 + UNITS:"(0=OK,1=Other)" + LABLAXIS:"Bx DQ" + DEPEND_0:"Epoch" + FORMAT:"I2" + FILLVAL:-1 + AVG_TYPE:" " + DICT_KEY:"flag" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:" " + DEPEND_1:"Data_No" + DATA_Q_By: + VarDescription: + DataType:"CDF_BYTE" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"DATA_QUALITY By" + CATDESC:"[NO LIST] Data Quality for By components(0 = OK, 1 = clipped or questionable)" + VAR_TYPE:"data" + VALIDMIN:0 + VALIDMAX:1 + UNITS:"(0=OK,1=Other)" + LABLAXIS:"By DQ" + DEPEND_0:"Epoch" + FORMAT:"I2" + FILLVAL:-1 + AVG_TYPE:" " + DICT_KEY:"flag" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:" " + DEPEND_1:"Data_No" + DATA_Q_Bz: + VarDescription: + DataType:"CDF_BYTE" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"DATA_QUALITY Bz" + CATDESC:"[NO LIST] Data Quality for Bz components(0 = OK, 1 = clipped or questionable)" + VAR_TYPE:"data" + VALIDMIN:0 + VALIDMAX:1 + UNITS:"(0=OK,1=Other)" + LABLAXIS:"Bz DQ" + DEPEND_0:"Epoch" + FORMAT:"I2" + FILLVAL:-1 + AVG_TYPE:" " + DICT_KEY:"flag" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:" " + DEPEND_1:"Data_No" + HFWR_Ex_Spec: + VarDescription: + DataType:"CDF_FLOAT" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"HFWR_Ex_Spec" + CATDESC:"[TEST-DO NOT USE] Ex Spectrogram from 512-element FFT" + VAR_TYPE:"data" + VALIDMIN:1.0E-20 + VALIDMAX:0.01 + SCALEMIN:1.0E-18 + SCALEMAX:0.00010 + UNITS:"(V/m)^2/Hz" + LABLAXIS:"Ex Spec" + DEPEND_0:"Epoch" + FORMAT:"E12.4" + FILLVAL:-1 + AVG_TYPE:" " + DICT_KEY:"flag" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:" " + VIRTUAL:"true" + FUNCTION:"fftPowerDelta512" + COMPONENT_0:"HFWR_Ex" + COMPONENT_1:"Delta_T" + HFWR_Ey_Spec: + VarDescription: + DataType:"CDF_FLOAT" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"HFWR_Ey_Spec" + CATDESC:"[TEST-DO NOT USE] Ey Spectrogram from 512-element FFT" + VAR_TYPE:"data" + VALIDMIN:1.0E-20 + VALIDMAX:0.01 + SCALEMIN:1.0E-18 + SCALEMAX:0.00010 + UNITS:"(V/m)^2/Hz" + LABLAXIS:"Ey Spec" + DEPEND_0:"Epoch" + FORMAT:"E12.4" + FILLVAL:-1.0E+31 + AVG_TYPE:" " + DICT_KEY:"flag" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:" " + VIRTUAL:"true" + FUNCTION:"fftPowerDelta512" + COMPONENT_0:"HFWR_Ey" + COMPONENT_1:"Delta_T" + HFWR_Ez_Spec: + VarDescription: + DataType:"CDF_FLOAT" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"HFWR_Ez_Spec" + CATDESC:"[TEST-DO NOT USE] Ez Spectrogram from 512-element FFT" + VAR_TYPE:"data" + VALIDMIN:1.0E-20 + VALIDMAX:0.01 + SCALEMIN:1.0E-18 + SCALEMAX:0.00010 + UNITS:"(V/m)^2/Hz" + LABLAXIS:"Ez Spec" + DEPEND_0:"Epoch" + FORMAT:"E12.4" + FILLVAL:-1.0E+31 + AVG_TYPE:" " + DICT_KEY:"flag" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:" " + DEPEND_1:"Data_No" + VIRTUAL:"true" + FUNCTION:"fftPowerDelta512" + COMPONENT_0:"HFWR_Ez" + COMPONENT_1:"Delta_T" + HFWR_Bx_Spec: + VarDescription: + DataType:"CDF_FLOAT" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"HFWR_Bx_Spec" + CATDESC:"[TEST-DO NOT USE] Bx Spectrogram from 512-element FFT" + VAR_TYPE:"data" + VALIDMIN:1.0E-16 + VALIDMAX:100.0 + SCALEMIN:1.0E-14 + SCALEMAX:1.0 + UNITS:"nT^2/Hz" + LABLAXIS:"Bx Spec" + DEPEND_0:"Epoch" + FORMAT:"E12.4" + FILLVAL:-1.0E+31 + AVG_TYPE:" " + DICT_KEY:"flag" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:" " + VIRTUAL:"true" + FUNCTION:"fftPowerDelta512" + COMPONENT_0:"HFWR_Bx" + COMPONENT_1:"Delta_T" + HFWR_By_Spec: + VarDescription: + DataType:"CDF_FLOAT" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"HFWR_By_Spec" + CATDESC:"[TEST-DO NOT USE] By Spectrogram from 512-element FFT" + VAR_TYPE:"data" + VALIDMIN:1.0E-16 + VALIDMAX:100.0 + SCALEMIN:1.0E-14 + SCALEMAX:1.0 + UNITS:"nT^2/Hz" + LABLAXIS:"By Spec" + DEPEND_0:"Epoch" + FORMAT:"E12.4" + FILLVAL:-1.0E+31 + AVG_TYPE:" " + DICT_KEY:"flag" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:" " + VIRTUAL:"true" + FUNCTION:"fftPowerDelta512" + COMPONENT_0:"HFWR_By" + COMPONENT_1:"Delta_T" + HFWR_Bz_Spec: + VarDescription: + DataType:"CDF_FLOAT" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"VARY" + DimVariances:["VARY"] + VarAttributes: + FIELDNAM:"HFWR_Bz_Spec" + CATDESC:"[TEST-DO NOT USE] Bz Spectrogram from 512-element FFT" + VAR_TYPE:"data" + VALIDMIN:1.0E-16 + VALIDMAX:100.0 + SCALEMIN:1.0E-14 + SCALEMAX:1.0 + UNITS:"nT^2/Hz" + LABLAXIS:"Bz Spec" + DEPEND_0:"Epoch" + FORMAT:"E12.4" + FILLVAL:-1.0E+31 + AVG_TYPE:" " + DICT_KEY:"flag" + DISPLAY_TYPE:"spectrogram" + VAR_NOTES:" " + DEPEND_1:"Data_No" + VIRTUAL:"true" + FUNCTION:"fftPowerDelta512" + COMPONENT_0:"HFWR_Bz" + COMPONENT_1:"Delta_T" + Data_No: + VarDescription: + DataType:"CDF_INT4" + NumElements:1 + NumDims:1 + DimSizes:[31744] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + VarAttributes: + FIELDNAM:"Data_No" + CATDESC:"Data_No: index of data in snapshot for HFWR and DQ values" + VAR_TYPE:"support_data" + VALIDMIN:0 + VALIDMAX:32000 + UNITS:"(31744 pts in 0.045s @ 9.2s)" + LABLAXIS:"Snapshot Point No" + FORMAT:"i6" + FILLVAL:-128 + DICT_KEY:"number" + SCALETYP:"linear" + VarData: + [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1126, 1127, 1128, 1129, 1130, 1131, 1132, 1133, 1134, 1135, 1136, 1137, 1138, 1139, 1140, 1141, 1142, 1143, 1144, 1145, 1146, 1147, 1148, 1149, 1150, 1151, 1152, 1153, 1154, 1155, 1156, 1157, 1158, 1159, 1160, 1161, 1162, 1163, 1164, 1165, 1166, 1167, 1168, 1169, 1170, 1171, 1172, 1173, 1174, 1175, 1176, 1177, 1178, 1179, 1180, 1181, 1182, 1183, 1184, 1185, 1186, 1187, 1188, 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199, 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224, 1225, 1226, 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236, 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246, 1247, 1248, 1249, 1250, 1251, 1252, 1253, 1254, 1255, 1256, 1257, 1258, 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268, 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278, 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288, 1289, 1290, 1291, 1292, 1293, 1294, 1295, 1296, 1297, 1298, 1299, 1300, 1301, 1302, 1303, 1304, 1305, 1306, 1307, 1308, 1309, 1310, 1311, 1312, 1313, 1314, 1315, 1316, 1317, 1318, 1319, 1320, 1321, 1322, 1323, 1324, 1325, 1326, 1327, 1328, 1329, 1330, 1331, 1332, 1333, 1334, 1335, 1336, 1337, 1338, 1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349, 1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359, 1360, 1361, 1362, 1363, 1364, 1365, 1366, 1367, 1368, 1369, 1370, 1371, 1372, 1373, 1374, 1375, 1376, 1377, 1378, 1379, 1380, 1381, 1382, 1383, 1384, 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399, 1400, 1401, 1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1410, 1411, 1412, 1413, 1414, 1415, 1416, 1417, 1418, 1419, 1420, 1421, 1422, 1423, 1424, 1425, 1426, 1427, 1428, 1429, 1430, 1431, 1432, 1433, 1434, 1435, 1436, 1437, 1438, 1439, 1440, 1441, 1442, 1443, 1444, 1445, 1446, 1447, 1448, 1449, 1450, 1451, 1452, 1453, 1454, 1455, 1456, 1457, 1458, 1459, 1460, 1461, 1462, 1463, 1464, 1465, 1466, 1467, 1468, 1469, 1470, 1471, 1472, 1473, 1474, 1475, 1476, 1477, 1478, 1479, 1480, 1481, 1482, 1483, 1484, 1485, 1486, 1487, 1488, 1489, 1490, 1491, 1492, 1493, 1494, 1495, 1496, 1497, 1498, 1499, 1500, 1501, 1502, 1503, 1504, 1505, 1506, 1507, 1508, 1509, 1510, 1511, 1512, 1513, 1514, 1515, 1516, 1517, 1518, 1519, 1520, 1521, 1522, 1523, 1524, 1525, 1526, 1527, 1528, 1529, 1530, 1531, 1532, 1533, 1534, 1535, 1536, 1537, 1538, 1539, 1540, 1541, 1542, 1543, 1544, 1545, 1546, 1547, 1548, 1549, 1550, 1551, 1552, 1553, 1554, 1555, 1556, 1557, 1558, 1559, 1560, 1561, 1562, 1563, 1564, 1565, 1566, 1567, 1568, 1569, 1570, 1571, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579, 1580, 1581, 1582, 1583, 1584, 1585, 1586, 1587, 1588, 1589, 1590, 1591, 1592, 1593, 1594, 1595, 1596, 1597, 1598, 1599, 1600, 1601, 1602, 1603, 1604, 1605, 1606, 1607, 1608, 1609, 1610, 1611, 1612, 1613, 1614, 1615, 1616, 1617, 1618, 1619, 1620, 1621, 1622, 1623, 1624, 1625, 1626, 1627, 1628, 1629, 1630, 1631, 1632, 1633, 1634, 1635, 1636, 1637, 1638, 1639, 1640, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 1648, 1649, 1650, 1651, 1652, 1653, 1654, 1655, 1656, 1657, 1658, 1659, 1660, 1661, 1662, 1663, 1664, 1665, 1666, 1667, 1668, 1669, 1670, 1671, 1672, 1673, 1674, 1675, 1676, 1677, 1678, 1679, 1680, 1681, 1682, 1683, 1684, 1685, 1686, 1687, 1688, 1689, 1690, 1691, 1692, 1693, 1694, 1695, 1696, 1697, 1698, 1699, 1700, 1701, 1702, 1703, 1704, 1705, 1706, 1707, 1708, 1709, 1710, 1711, 1712, 1713, 1714, 1715, 1716, 1717, 1718, 1719, 1720, 1721, 1722, 1723, 1724, 1725, 1726, 1727, 1728, 1729, 1730, 1731, 1732, 1733, 1734, 1735, 1736, 1737, 1738, 1739, 1740, 1741, 1742, 1743, 1744, 1745, 1746, 1747, 1748, 1749, 1750, 1751, 1752, 1753, 1754, 1755, 1756, 1757, 1758, 1759, 1760, 1761, 1762, 1763, 1764, 1765, 1766, 1767, 1768, 1769, 1770, 1771, 1772, 1773, 1774, 1775, 1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789, 1790, 1791, 1792, 1793, 1794, 1795, 1796, 1797, 1798, 1799, 1800, 1801, 1802, 1803, 1804, 1805, 1806, 1807, 1808, 1809, 1810, 1811, 1812, 1813, 1814, 1815, 1816, 1817, 1818, 1819, 1820, 1821, 1822, 1823, 1824, 1825, 1826, 1827, 1828, 1829, 1830, 1831, 1832, 1833, 1834, 1835, 1836, 1837, 1838, 1839, 1840, 1841, 1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849, 1850, 1851, 1852, 1853, 1854, 1855, 1856, 1857, 1858, 1859, 1860, 1861, 1862, 1863, 1864, 1865, 1866, 1867, 1868, 1869, 1870, 1871, 1872, 1873, 1874, 1875, 1876, 1877, 1878, 1879, 1880, 1881, 1882, 1883, 1884, 1885, 1886, 1887, 1888, 1889, 1890, 1891, 1892, 1893, 1894, 1895, 1896, 1897, 1898, 1899, 1900, 1901, 1902, 1903, 1904, 1905, 1906, 1907, 1908, 1909, 1910, 1911, 1912, 1913, 1914, 1915, 1916, 1917, 1918, 1919, 1920, 1921, 1922, 1923, 1924, 1925, 1926, 1927, 1928, 1929, 1930, 1931, 1932, 1933, 1934, 1935, 1936, 1937, 1938, 1939, 1940, 1941, 1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949, 1950, 1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959, 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 2032, 2033, 2034, 2035, 2036, 2037, 2038, 2039, 2040, 2041, 2042, 2043, 2044, 2045, 2046, 2047, 2048, 2049, 2050, 2051, 2052, 2053, 2054, 2055, 2056, 2057, 2058, 2059, 2060, 2061, 2062, 2063, 2064, 2065, 2066, 2067, 2068, 2069, 2070, 2071, 2072, 2073, 2074, 2075, 2076, 2077, 2078, 2079, 2080, 2081, 2082, 2083, 2084, 2085, 2086, 2087, 2088, 2089, 2090, 2091, 2092, 2093, 2094, 2095, 2096, 2097, 2098, 2099, 2100, 2101, 2102, 2103, 2104, 2105, 2106, 2107, 2108, 2109, 2110, 2111, 2112, 2113, 2114, 2115, 2116, 2117, 2118, 2119, 2120, 2121, 2122, 2123, 2124, 2125, 2126, 2127, 2128, 2129, 2130, 2131, 2132, 2133, 2134, 2135, 2136, 2137, 2138, 2139, 2140, 2141, 2142, 2143, 2144, 2145, 2146, 2147, 2148, 2149, 2150, 2151, 2152, 2153, 2154, 2155, 2156, 2157, 2158, 2159, 2160, 2161, 2162, 2163, 2164, 2165, 2166, 2167, 2168, 2169, 2170, 2171, 2172, 2173, 2174, 2175, 2176, 2177, 2178, 2179, 2180, 2181, 2182, 2183, 2184, 2185, 2186, 2187, 2188, 2189, 2190, 2191, 2192, 2193, 2194, 2195, 2196, 2197, 2198, 2199, 2200, 2201, 2202, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210, 2211, 2212, 2213, 2214, 2215, 2216, 2217, 2218, 2219, 2220, 2221, 2222, 2223, 2224, 2225, 2226, 2227, 2228, 2229, 2230, 2231, 2232, 2233, 2234, 2235, 2236, 2237, 2238, 2239, 2240, 2241, 2242, 2243, 2244, 2245, 2246, 2247, 2248, 2249, 2250, 2251, 2252, 2253, 2254, 2255, 2256, 2257, 2258, 2259, 2260, 2261, 2262, 2263, 2264, 2265, 2266, 2267, 2268, 2269, 2270, 2271, 2272, 2273, 2274, 2275, 2276, 2277, 2278, 2279, 2280, 2281, 2282, 2283, 2284, 2285, 2286, 2287, 2288, 2289, 2290, 2291, 2292, 2293, 2294, 2295, 2296, 2297, 2298, 2299, 2300, 2301, 2302, 2303, 2304, 2305, 2306, 2307, 2308, 2309, 2310, 2311, 2312, 2313, 2314, 2315, 2316, 2317, 2318, 2319, 2320, 2321, 2322, 2323, 2324, 2325, 2326, 2327, 2328, 2329, 2330, 2331, 2332, 2333, 2334, 2335, 2336, 2337, 2338, 2339, 2340, 2341, 2342, 2343, 2344, 2345, 2346, 2347, 2348, 2349, 2350, 2351, 2352, 2353, 2354, 2355, 2356, 2357, 2358, 2359, 2360, 2361, 2362, 2363, 2364, 2365, 2366, 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379, 2380, 2381, 2382, 2383, 2384, 2385, 2386, 2387, 2388, 2389, 2390, 2391, 2392, 2393, 2394, 2395, 2396, 2397, 2398, 2399, 2400, 2401, 2402, 2403, 2404, 2405, 2406, 2407, 2408, 2409, 2410, 2411, 2412, 2413, 2414, 2415, 2416, 2417, 2418, 2419, 2420, 2421, 2422, 2423, 2424, 2425, 2426, 2427, 2428, 2429, 2430, 2431, 2432, 2433, 2434, 2435, 2436, 2437, 2438, 2439, 2440, 2441, 2442, 2443, 2444, 2445, 2446, 2447, 2448, 2449, 2450, 2451, 2452, 2453, 2454, 2455, 2456, 2457, 2458, 2459, 2460, 2461, 2462, 2463, 2464, 2465, 2466, 2467, 2468, 2469, 2470, 2471, 2472, 2473, 2474, 2475, 2476, 2477, 2478, 2479, 2480, 2481, 2482, 2483, 2484, 2485, 2486, 2487, 2488, 2489, 2490, 2491, 2492, 2493, 2494, 2495, 2496, 2497, 2498, 2499, 2500, 2501, 2502, 2503, 2504, 2505, 2506, 2507, 2508, 2509, 2510, 2511, 2512, 2513, 2514, 2515, 2516, 2517, 2518, 2519, 2520, 2521, 2522, 2523, 2524, 2525, 2526, 2527, 2528, 2529, 2530, 2531, 2532, 2533, 2534, 2535, 2536, 2537, 2538, 2539, 2540, 2541, 2542, 2543, 2544, 2545, 2546, 2547, 2548, 2549, 2550, 2551, 2552, 2553, 2554, 2555, 2556, 2557, 2558, 2559, 2560, 2561, 2562, 2563, 2564, 2565, 2566, 2567, 2568, 2569, 2570, 2571, 2572, 2573, 2574, 2575, 2576, 2577, 2578, 2579, 2580, 2581, 2582, 2583, 2584, 2585, 2586, 2587, 2588, 2589, 2590, 2591, 2592, 2593, 2594, 2595, 2596, 2597, 2598, 2599, 2600, 2601, 2602, 2603, 2604, 2605, 2606, 2607, 2608, 2609, 2610, 2611, 2612, 2613, 2614, 2615, 2616, 2617, 2618, 2619, 2620, 2621, 2622, 2623, 2624, 2625, 2626, 2627, 2628, 2629, 2630, 2631, 2632, 2633, 2634, 2635, 2636, 2637, 2638, 2639, 2640, 2641, 2642, 2643, 2644, 2645, 2646, 2647, 2648, 2649, 2650, 2651, 2652, 2653, 2654, 2655, 2656, 2657, 2658, 2659, 2660, 2661, 2662, 2663, 2664, 2665, 2666, 2667, 2668, 2669, 2670, 2671, 2672, 2673, 2674, 2675, 2676, 2677, 2678, 2679, 2680, 2681, 2682, 2683, 2684, 2685, 2686, 2687, 2688, 2689, 2690, 2691, 2692, 2693, 2694, 2695, 2696, 2697, 2698, 2699, 2700, 2701, 2702, 2703, 2704, 2705, 2706, 2707, 2708, 2709, 2710, 2711, 2712, 2713, 2714, 2715, 2716, 2717, 2718, 2719, 2720, 2721, 2722, 2723, 2724, 2725, 2726, 2727, 2728, 2729, 2730, 2731, 2732, 2733, 2734, 2735, 2736, 2737, 2738, 2739, 2740, 2741, 2742, 2743, 2744, 2745, 2746, 2747, 2748, 2749, 2750, 2751, 2752, 2753, 2754, 2755, 2756, 2757, 2758, 2759, 2760, 2761, 2762, 2763, 2764, 2765, 2766, 2767, 2768, 2769, 2770, 2771, 2772, 2773, 2774, 2775, 2776, 2777, 2778, 2779, 2780, 2781, 2782, 2783, 2784, 2785, 2786, 2787, 2788, 2789, 2790, 2791, 2792, 2793, 2794, 2795, 2796, 2797, 2798, 2799, 2800, 2801, 2802, 2803, 2804, 2805, 2806, 2807, 2808, 2809, 2810, 2811, 2812, 2813, 2814, 2815, 2816, 2817, 2818, 2819, 2820, 2821, 2822, 2823, 2824, 2825, 2826, 2827, 2828, 2829, 2830, 2831, 2832, 2833, 2834, 2835, 2836, 2837, 2838, 2839, 2840, 2841, 2842, 2843, 2844, 2845, 2846, 2847, 2848, 2849, 2850, 2851, 2852, 2853, 2854, 2855, 2856, 2857, 2858, 2859, 2860, 2861, 2862, 2863, 2864, 2865, 2866, 2867, 2868, 2869, 2870, 2871, 2872, 2873, 2874, 2875, 2876, 2877, 2878, 2879, 2880, 2881, 2882, 2883, 2884, 2885, 2886, 2887, 2888, 2889, 2890, 2891, 2892, 2893, 2894, 2895, 2896, 2897, 2898, 2899, 2900, 2901, 2902, 2903, 2904, 2905, 2906, 2907, 2908, 2909, 2910, 2911, 2912, 2913, 2914, 2915, 2916, 2917, 2918, 2919, 2920, 2921, 2922, 2923, 2924, 2925, 2926, 2927, 2928, 2929, 2930, 2931, 2932, 2933, 2934, 2935, 2936, 2937, 2938, 2939, 2940, 2941, 2942, 2943, 2944, 2945, 2946, 2947, 2948, 2949, 2950, 2951, 2952, 2953, 2954, 2955, 2956, 2957, 2958, 2959, 2960, 2961, 2962, 2963, 2964, 2965, 2966, 2967, 2968, 2969, 2970, 2971, 2972, 2973, 2974, 2975, 2976, 2977, 2978, 2979, 2980, 2981, 2982, 2983, 2984, 2985, 2986, 2987, 2988, 2989, 2990, 2991, 2992, 2993, 2994, 2995, 2996, 2997, 2998, 2999, 3000, 3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009, 3010, 3011, 3012, 3013, 3014, 3015, 3016, 3017, 3018, 3019, 3020, 3021, 3022, 3023, 3024, 3025, 3026, 3027, 3028, 3029, 3030, 3031, 3032, 3033, 3034, 3035, 3036, 3037, 3038, 3039, 3040, 3041, 3042, 3043, 3044, 3045, 3046, 3047, 3048, 3049, 3050, 3051, 3052, 3053, 3054, 3055, 3056, 3057, 3058, 3059, 3060, 3061, 3062, 3063, 3064, 3065, 3066, 3067, 3068, 3069, 3070, 3071, 3072, 3073, 3074, 3075, 3076, 3077, 3078, 3079, 3080, 3081, 3082, 3083, 3084, 3085, 3086, 3087, 3088, 3089, 3090, 3091, 3092, 3093, 3094, 3095, 3096, 3097, 3098, 3099, 3100, 3101, 3102, 3103, 3104, 3105, 3106, 3107, 3108, 3109, 3110, 3111, 3112, 3113, 3114, 3115, 3116, 3117, 3118, 3119, 3120, 3121, 3122, 3123, 3124, 3125, 3126, 3127, 3128, 3129, 3130, 3131, 3132, 3133, 3134, 3135, 3136, 3137, 3138, 3139, 3140, 3141, 3142, 3143, 3144, 3145, 3146, 3147, 3148, 3149, 3150, 3151, 3152, 3153, 3154, 3155, 3156, 3157, 3158, 3159, 3160, 3161, 3162, 3163, 3164, 3165, 3166, 3167, 3168, 3169, 3170, 3171, 3172, 3173, 3174, 3175, 3176, 3177, 3178, 3179, 3180, 3181, 3182, 3183, 3184, 3185, 3186, 3187, 3188, 3189, 3190, 3191, 3192, 3193, 3194, 3195, 3196, 3197, 3198, 3199, 3200, 3201, 3202, 3203, 3204, 3205, 3206, 3207, 3208, 3209, 3210, 3211, 3212, 3213, 3214, 3215, 3216, 3217, 3218, 3219, 3220, 3221, 3222, 3223, 3224, 3225, 3226, 3227, 3228, 3229, 3230, 3231, 3232, 3233, 3234, 3235, 3236, 3237, 3238, 3239, 3240, 3241, 3242, 3243, 3244, 3245, 3246, 3247, 3248, 3249, 3250, 3251, 3252, 3253, 3254, 3255, 3256, 3257, 3258, 3259, 3260, 3261, 3262, 3263, 3264, 3265, 3266, 3267, 3268, 3269, 3270, 3271, 3272, 3273, 3274, 3275, 3276, 3277, 3278, 3279, 3280, 3281, 3282, 3283, 3284, 3285, 3286, 3287, 3288, 3289, 3290, 3291, 3292, 3293, 3294, 3295, 3296, 3297, 3298, 3299, 3300, 3301, 3302, 3303, 3304, 3305, 3306, 3307, 3308, 3309, 3310, 3311, 3312, 3313, 3314, 3315, 3316, 3317, 3318, 3319, 3320, 3321, 3322, 3323, 3324, 3325, 3326, 3327, 3328, 3329, 3330, 3331, 3332, 3333, 3334, 3335, 3336, 3337, 3338, 3339, 3340, 3341, 3342, 3343, 3344, 3345, 3346, 3347, 3348, 3349, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3357, 3358, 3359, 3360, 3361, 3362, 3363, 3364, 3365, 3366, 3367, 3368, 3369, 3370, 3371, 3372, 3373, 3374, 3375, 3376, 3377, 3378, 3379, 3380, 3381, 3382, 3383, 3384, 3385, 3386, 3387, 3388, 3389, 3390, 3391, 3392, 3393, 3394, 3395, 3396, 3397, 3398, 3399, 3400, 3401, 3402, 3403, 3404, 3405, 3406, 3407, 3408, 3409, 3410, 3411, 3412, 3413, 3414, 3415, 3416, 3417, 3418, 3419, 3420, 3421, 3422, 3423, 3424, 3425, 3426, 3427, 3428, 3429, 3430, 3431, 3432, 3433, 3434, 3435, 3436, 3437, 3438, 3439, 3440, 3441, 3442, 3443, 3444, 3445, 3446, 3447, 3448, 3449, 3450, 3451, 3452, 3453, 3454, 3455, 3456, 3457, 3458, 3459, 3460, 3461, 3462, 3463, 3464, 3465, 3466, 3467, 3468, 3469, 3470, 3471, 3472, 3473, 3474, 3475, 3476, 3477, 3478, 3479, 3480, 3481, 3482, 3483, 3484, 3485, 3486, 3487, 3488, 3489, 3490, 3491, 3492, 3493, 3494, 3495, 3496, 3497, 3498, 3499, 3500, 3501, 3502, 3503, 3504, 3505, 3506, 3507, 3508, 3509, 3510, 3511, 3512, 3513, 3514, 3515, 3516, 3517, 3518, 3519, 3520, 3521, 3522, 3523, 3524, 3525, 3526, 3527, 3528, 3529, 3530, 3531, 3532, 3533, 3534, 3535, 3536, 3537, 3538, 3539, 3540, 3541, 3542, 3543, 3544, 3545, 3546, 3547, 3548, 3549, 3550, 3551, 3552, 3553, 3554, 3555, 3556, 3557, 3558, 3559, 3560, 3561, 3562, 3563, 3564, 3565, 3566, 3567, 3568, 3569, 3570, 3571, 3572, 3573, 3574, 3575, 3576, 3577, 3578, 3579, 3580, 3581, 3582, 3583, 3584, 3585, 3586, 3587, 3588, 3589, 3590, 3591, 3592, 3593, 3594, 3595, 3596, 3597, 3598, 3599, 3600, 3601, 3602, 3603, 3604, 3605, 3606, 3607, 3608, 3609, 3610, 3611, 3612, 3613, 3614, 3615, 3616, 3617, 3618, 3619, 3620, 3621, 3622, 3623, 3624, 3625, 3626, 3627, 3628, 3629, 3630, 3631, 3632, 3633, 3634, 3635, 3636, 3637, 3638, 3639, 3640, 3641, 3642, 3643, 3644, 3645, 3646, 3647, 3648, 3649, 3650, 3651, 3652, 3653, 3654, 3655, 3656, 3657, 3658, 3659, 3660, 3661, 3662, 3663, 3664, 3665, 3666, 3667, 3668, 3669, 3670, 3671, 3672, 3673, 3674, 3675, 3676, 3677, 3678, 3679, 3680, 3681, 3682, 3683, 3684, 3685, 3686, 3687, 3688, 3689, 3690, 3691, 3692, 3693, 3694, 3695, 3696, 3697, 3698, 3699, 3700, 3701, 3702, 3703, 3704, 3705, 3706, 3707, 3708, 3709, 3710, 3711, 3712, 3713, 3714, 3715, 3716, 3717, 3718, 3719, 3720, 3721, 3722, 3723, 3724, 3725, 3726, 3727, 3728, 3729, 3730, 3731, 3732, 3733, 3734, 3735, 3736, 3737, 3738, 3739, 3740, 3741, 3742, 3743, 3744, 3745, 3746, 3747, 3748, 3749, 3750, 3751, 3752, 3753, 3754, 3755, 3756, 3757, 3758, 3759, 3760, 3761, 3762, 3763, 3764, 3765, 3766, 3767, 3768, 3769, 3770, 3771, 3772, 3773, 3774, 3775, 3776, 3777, 3778, 3779, 3780, 3781, 3782, 3783, 3784, 3785, 3786, 3787, 3788, 3789, 3790, 3791, 3792, 3793, 3794, 3795, 3796, 3797, 3798, 3799, 3800, 3801, 3802, 3803, 3804, 3805, 3806, 3807, 3808, 3809, 3810, 3811, 3812, 3813, 3814, 3815, 3816, 3817, 3818, 3819, 3820, 3821, 3822, 3823, 3824, 3825, 3826, 3827, 3828, 3829, 3830, 3831, 3832, 3833, 3834, 3835, 3836, 3837, 3838, 3839, 3840, 3841, 3842, 3843, 3844, 3845, 3846, 3847, 3848, 3849, 3850, 3851, 3852, 3853, 3854, 3855, 3856, 3857, 3858, 3859, 3860, 3861, 3862, 3863, 3864, 3865, 3866, 3867, 3868, 3869, 3870, 3871, 3872, 3873, 3874, 3875, 3876, 3877, 3878, 3879, 3880, 3881, 3882, 3883, 3884, 3885, 3886, 3887, 3888, 3889, 3890, 3891, 3892, 3893, 3894, 3895, 3896, 3897, 3898, 3899, 3900, 3901, 3902, 3903, 3904, 3905, 3906, 3907, 3908, 3909, 3910, 3911, 3912, 3913, 3914, 3915, 3916, 3917, 3918, 3919, 3920, 3921, 3922, 3923, 3924, 3925, 3926, 3927, 3928, 3929, 3930, 3931, 3932, 3933, 3934, 3935, 3936, 3937, 3938, 3939, 3940, 3941, 3942, 3943, 3944, 3945, 3946, 3947, 3948, 3949, 3950, 3951, 3952, 3953, 3954, 3955, 3956, 3957, 3958, 3959, 3960, 3961, 3962, 3963, 3964, 3965, 3966, 3967, 3968, 3969, 3970, 3971, 3972, 3973, 3974, 3975, 3976, 3977, 3978, 3979, 3980, 3981, 3982, 3983, 3984, 3985, 3986, 3987, 3988, 3989, 3990, 3991, 3992, 3993, 3994, 3995, 3996, 3997, 3998, 3999, 4000, 4001, 4002, 4003, 4004, 4005, 4006, 4007, 4008, 4009, 4010, 4011, 4012, 4013, 4014, 4015, 4016, 4017, 4018, 4019, 4020, 4021, 4022, 4023, 4024, 4025, 4026, 4027, 4028, 4029, 4030, 4031, 4032, 4033, 4034, 4035, 4036, 4037, 4038, 4039, 4040, 4041, 4042, 4043, 4044, 4045, 4046, 4047, 4048, 4049, 4050, 4051, 4052, 4053, 4054, 4055, 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, 4068, 4069, 4070, 4071, 4072, 4073, 4074, 4075, 4076, 4077, 4078, 4079, 4080, 4081, 4082, 4083, 4084, 4085, 4086, 4087, 4088, 4089, 4090, 4091, 4092, 4093, 4094, 4095, 4096, 4097, 4098, 4099, 4100, 4101, 4102, 4103, 4104, 4105, 4106, 4107, 4108, 4109, 4110, 4111, 4112, 4113, 4114, 4115, 4116, 4117, 4118, 4119, 4120, 4121, 4122, 4123, 4124, 4125, 4126, 4127, 4128, 4129, 4130, 4131, 4132, 4133, 4134, 4135, 4136, 4137, 4138, 4139, 4140, 4141, 4142, 4143, 4144, 4145, 4146, 4147, 4148, 4149, 4150, 4151, 4152, 4153, 4154, 4155, 4156, 4157, 4158, 4159, 4160, 4161, 4162, 4163, 4164, 4165, 4166, 4167, 4168, 4169, 4170, 4171, 4172, 4173, 4174, 4175, 4176, 4177, 4178, 4179, 4180, 4181, 4182, 4183, 4184, 4185, 4186, 4187, 4188, 4189, 4190, 4191, 4192, 4193, 4194, 4195, 4196, 4197, 4198, 4199, 4200, 4201, 4202, 4203, 4204, 4205, 4206, 4207, 4208, 4209, 4210, 4211, 4212, 4213, 4214, 4215, 4216, 4217, 4218, 4219, 4220, 4221, 4222, 4223, 4224, 4225, 4226, 4227, 4228, 4229, 4230, 4231, 4232, 4233, 4234, 4235, 4236, 4237, 4238, 4239, 4240, 4241, 4242, 4243, 4244, 4245, 4246, 4247, 4248, 4249, 4250, 4251, 4252, 4253, 4254, 4255, 4256, 4257, 4258, 4259, 4260, 4261, 4262, 4263, 4264, 4265, 4266, 4267, 4268, 4269, 4270, 4271, 4272, 4273, 4274, 4275, 4276, 4277, 4278, 4279, 4280, 4281, 4282, 4283, 4284, 4285, 4286, 4287, 4288, 4289, 4290, 4291, 4292, 4293, 4294, 4295, 4296, 4297, 4298, 4299, 4300, 4301, 4302, 4303, 4304, 4305, 4306, 4307, 4308, 4309, 4310, 4311, 4312, 4313, 4314, 4315, 4316, 4317, 4318, 4319, 4320, 4321, 4322, 4323, 4324, 4325, 4326, 4327, 4328, 4329, 4330, 4331, 4332, 4333, 4334, 4335, 4336, 4337, 4338, 4339, 4340, 4341, 4342, 4343, 4344, 4345, 4346, 4347, 4348, 4349, 4350, 4351, 4352, 4353, 4354, 4355, 4356, 4357, 4358, 4359, 4360, 4361, 4362, 4363, 4364, 4365, 4366, 4367, 4368, 4369, 4370, 4371, 4372, 4373, 4374, 4375, 4376, 4377, 4378, 4379, 4380, 4381, 4382, 4383, 4384, 4385, 4386, 4387, 4388, 4389, 4390, 4391, 4392, 4393, 4394, 4395, 4396, 4397, 4398, 4399, 4400, 4401, 4402, 4403, 4404, 4405, 4406, 4407, 4408, 4409, 4410, 4411, 4412, 4413, 4414, 4415, 4416, 4417, 4418, 4419, 4420, 4421, 4422, 4423, 4424, 4425, 4426, 4427, 4428, 4429, 4430, 4431, 4432, 4433, 4434, 4435, 4436, 4437, 4438, 4439, 4440, 4441, 4442, 4443, 4444, 4445, 4446, 4447, 4448, 4449, 4450, 4451, 4452, 4453, 4454, 4455, 4456, 4457, 4458, 4459, 4460, 4461, 4462, 4463, 4464, 4465, 4466, 4467, 4468, 4469, 4470, 4471, 4472, 4473, 4474, 4475, 4476, 4477, 4478, 4479, 4480, 4481, 4482, 4483, 4484, 4485, 4486, 4487, 4488, 4489, 4490, 4491, 4492, 4493, 4494, 4495, 4496, 4497, 4498, 4499, 4500, 4501, 4502, 4503, 4504, 4505, 4506, 4507, 4508, 4509, 4510, 4511, 4512, 4513, 4514, 4515, 4516, 4517, 4518, 4519, 4520, 4521, 4522, 4523, 4524, 4525, 4526, 4527, 4528, 4529, 4530, 4531, 4532, 4533, 4534, 4535, 4536, 4537, 4538, 4539, 4540, 4541, 4542, 4543, 4544, 4545, 4546, 4547, 4548, 4549, 4550, 4551, 4552, 4553, 4554, 4555, 4556, 4557, 4558, 4559, 4560, 4561, 4562, 4563, 4564, 4565, 4566, 4567, 4568, 4569, 4570, 4571, 4572, 4573, 4574, 4575, 4576, 4577, 4578, 4579, 4580, 4581, 4582, 4583, 4584, 4585, 4586, 4587, 4588, 4589, 4590, 4591, 4592, 4593, 4594, 4595, 4596, 4597, 4598, 4599, 4600, 4601, 4602, 4603, 4604, 4605, 4606, 4607, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 4626, 4627, 4628, 4629, 4630, 4631, 4632, 4633, 4634, 4635, 4636, 4637, 4638, 4639, 4640, 4641, 4642, 4643, 4644, 4645, 4646, 4647, 4648, 4649, 4650, 4651, 4652, 4653, 4654, 4655, 4656, 4657, 4658, 4659, 4660, 4661, 4662, 4663, 4664, 4665, 4666, 4667, 4668, 4669, 4670, 4671, 4672, 4673, 4674, 4675, 4676, 4677, 4678, 4679, 4680, 4681, 4682, 4683, 4684, 4685, 4686, 4687, 4688, 4689, 4690, 4691, 4692, 4693, 4694, 4695, 4696, 4697, 4698, 4699, 4700, 4701, 4702, 4703, 4704, 4705, 4706, 4707, 4708, 4709, 4710, 4711, 4712, 4713, 4714, 4715, 4716, 4717, 4718, 4719, 4720, 4721, 4722, 4723, 4724, 4725, 4726, 4727, 4728, 4729, 4730, 4731, 4732, 4733, 4734, 4735, 4736, 4737, 4738, 4739, 4740, 4741, 4742, 4743, 4744, 4745, 4746, 4747, 4748, 4749, 4750, 4751, 4752, 4753, 4754, 4755, 4756, 4757, 4758, 4759, 4760, 4761, 4762, 4763, 4764, 4765, 4766, 4767, 4768, 4769, 4770, 4771, 4772, 4773, 4774, 4775, 4776, 4777, 4778, 4779, 4780, 4781, 4782, 4783, 4784, 4785, 4786, 4787, 4788, 4789, 4790, 4791, 4792, 4793, 4794, 4795, 4796, 4797, 4798, 4799, 4800, 4801, 4802, 4803, 4804, 4805, 4806, 4807, 4808, 4809, 4810, 4811, 4812, 4813, 4814, 4815, 4816, 4817, 4818, 4819, 4820, 4821, 4822, 4823, 4824, 4825, 4826, 4827, 4828, 4829, 4830, 4831, 4832, 4833, 4834, 4835, 4836, 4837, 4838, 4839, 4840, 4841, 4842, 4843, 4844, 4845, 4846, 4847, 4848, 4849, 4850, 4851, 4852, 4853, 4854, 4855, 4856, 4857, 4858, 4859, 4860, 4861, 4862, 4863, 4864, 4865, 4866, 4867, 4868, 4869, 4870, 4871, 4872, 4873, 4874, 4875, 4876, 4877, 4878, 4879, 4880, 4881, 4882, 4883, 4884, 4885, 4886, 4887, 4888, 4889, 4890, 4891, 4892, 4893, 4894, 4895, 4896, 4897, 4898, 4899, 4900, 4901, 4902, 4903, 4904, 4905, 4906, 4907, 4908, 4909, 4910, 4911, 4912, 4913, 4914, 4915, 4916, 4917, 4918, 4919, 4920, 4921, 4922, 4923, 4924, 4925, 4926, 4927, 4928, 4929, 4930, 4931, 4932, 4933, 4934, 4935, 4936, 4937, 4938, 4939, 4940, 4941, 4942, 4943, 4944, 4945, 4946, 4947, 4948, 4949, 4950, 4951, 4952, 4953, 4954, 4955, 4956, 4957, 4958, 4959, 4960, 4961, 4962, 4963, 4964, 4965, 4966, 4967, 4968, 4969, 4970, 4971, 4972, 4973, 4974, 4975, 4976, 4977, 4978, 4979, 4980, 4981, 4982, 4983, 4984, 4985, 4986, 4987, 4988, 4989, 4990, 4991, 4992, 4993, 4994, 4995, 4996, 4997, 4998, 4999, 5000, 5001, 5002, 5003, 5004, 5005, 5006, 5007, 5008, 5009, 5010, 5011, 5012, 5013, 5014, 5015, 5016, 5017, 5018, 5019, 5020, 5021, 5022, 5023, 5024, 5025, 5026, 5027, 5028, 5029, 5030, 5031, 5032, 5033, 5034, 5035, 5036, 5037, 5038, 5039, 5040, 5041, 5042, 5043, 5044, 5045, 5046, 5047, 5048, 5049, 5050, 5051, 5052, 5053, 5054, 5055, 5056, 5057, 5058, 5059, 5060, 5061, 5062, 5063, 5064, 5065, 5066, 5067, 5068, 5069, 5070, 5071, 5072, 5073, 5074, 5075, 5076, 5077, 5078, 5079, 5080, 5081, 5082, 5083, 5084, 5085, 5086, 5087, 5088, 5089, 5090, 5091, 5092, 5093, 5094, 5095, 5096, 5097, 5098, 5099, 5100, 5101, 5102, 5103, 5104, 5105, 5106, 5107, 5108, 5109, 5110, 5111, 5112, 5113, 5114, 5115, 5116, 5117, 5118, 5119, 5120, 5121, 5122, 5123, 5124, 5125, 5126, 5127, 5128, 5129, 5130, 5131, 5132, 5133, 5134, 5135, 5136, 5137, 5138, 5139, 5140, 5141, 5142, 5143, 5144, 5145, 5146, 5147, 5148, 5149, 5150, 5151, 5152, 5153, 5154, 5155, 5156, 5157, 5158, 5159, 5160, 5161, 5162, 5163, 5164, 5165, 5166, 5167, 5168, 5169, 5170, 5171, 5172, 5173, 5174, 5175, 5176, 5177, 5178, 5179, 5180, 5181, 5182, 5183, 5184, 5185, 5186, 5187, 5188, 5189, 5190, 5191, 5192, 5193, 5194, 5195, 5196, 5197, 5198, 5199, 5200, 5201, 5202, 5203, 5204, 5205, 5206, 5207, 5208, 5209, 5210, 5211, 5212, 5213, 5214, 5215, 5216, 5217, 5218, 5219, 5220, 5221, 5222, 5223, 5224, 5225, 5226, 5227, 5228, 5229, 5230, 5231, 5232, 5233, 5234, 5235, 5236, 5237, 5238, 5239, 5240, 5241, 5242, 5243, 5244, 5245, 5246, 5247, 5248, 5249, 5250, 5251, 5252, 5253, 5254, 5255, 5256, 5257, 5258, 5259, 5260, 5261, 5262, 5263, 5264, 5265, 5266, 5267, 5268, 5269, 5270, 5271, 5272, 5273, 5274, 5275, 5276, 5277, 5278, 5279, 5280, 5281, 5282, 5283, 5284, 5285, 5286, 5287, 5288, 5289, 5290, 5291, 5292, 5293, 5294, 5295, 5296, 5297, 5298, 5299, 5300, 5301, 5302, 5303, 5304, 5305, 5306, 5307, 5308, 5309, 5310, 5311, 5312, 5313, 5314, 5315, 5316, 5317, 5318, 5319, 5320, 5321, 5322, 5323, 5324, 5325, 5326, 5327, 5328, 5329, 5330, 5331, 5332, 5333, 5334, 5335, 5336, 5337, 5338, 5339, 5340, 5341, 5342, 5343, 5344, 5345, 5346, 5347, 5348, 5349, 5350, 5351, 5352, 5353, 5354, 5355, 5356, 5357, 5358, 5359, 5360, 5361, 5362, 5363, 5364, 5365, 5366, 5367, 5368, 5369, 5370, 5371, 5372, 5373, 5374, 5375, 5376, 5377, 5378, 5379, 5380, 5381, 5382, 5383, 5384, 5385, 5386, 5387, 5388, 5389, 5390, 5391, 5392, 5393, 5394, 5395, 5396, 5397, 5398, 5399, 5400, 5401, 5402, 5403, 5404, 5405, 5406, 5407, 5408, 5409, 5410, 5411, 5412, 5413, 5414, 5415, 5416, 5417, 5418, 5419, 5420, 5421, 5422, 5423, 5424, 5425, 5426, 5427, 5428, 5429, 5430, 5431, 5432, 5433, 5434, 5435, 5436, 5437, 5438, 5439, 5440, 5441, 5442, 5443, 5444, 5445, 5446, 5447, 5448, 5449, 5450, 5451, 5452, 5453, 5454, 5455, 5456, 5457, 5458, 5459, 5460, 5461, 5462, 5463, 5464, 5465, 5466, 5467, 5468, 5469, 5470, 5471, 5472, 5473, 5474, 5475, 5476, 5477, 5478, 5479, 5480, 5481, 5482, 5483, 5484, 5485, 5486, 5487, 5488, 5489, 5490, 5491, 5492, 5493, 5494, 5495, 5496, 5497, 5498, 5499, 5500, 5501, 5502, 5503, 5504, 5505, 5506, 5507, 5508, 5509, 5510, 5511, 5512, 5513, 5514, 5515, 5516, 5517, 5518, 5519, 5520, 5521, 5522, 5523, 5524, 5525, 5526, 5527, 5528, 5529, 5530, 5531, 5532, 5533, 5534, 5535, 5536, 5537, 5538, 5539, 5540, 5541, 5542, 5543, 5544, 5545, 5546, 5547, 5548, 5549, 5550, 5551, 5552, 5553, 5554, 5555, 5556, 5557, 5558, 5559, 5560, 5561, 5562, 5563, 5564, 5565, 5566, 5567, 5568, 5569, 5570, 5571, 5572, 5573, 5574, 5575, 5576, 5577, 5578, 5579, 5580, 5581, 5582, 5583, 5584, 5585, 5586, 5587, 5588, 5589, 5590, 5591, 5592, 5593, 5594, 5595, 5596, 5597, 5598, 5599, 5600, 5601, 5602, 5603, 5604, 5605, 5606, 5607, 5608, 5609, 5610, 5611, 5612, 5613, 5614, 5615, 5616, 5617, 5618, 5619, 5620, 5621, 5622, 5623, 5624, 5625, 5626, 5627, 5628, 5629, 5630, 5631, 5632, 5633, 5634, 5635, 5636, 5637, 5638, 5639, 5640, 5641, 5642, 5643, 5644, 5645, 5646, 5647, 5648, 5649, 5650, 5651, 5652, 5653, 5654, 5655, 5656, 5657, 5658, 5659, 5660, 5661, 5662, 5663, 5664, 5665, 5666, 5667, 5668, 5669, 5670, 5671, 5672, 5673, 5674, 5675, 5676, 5677, 5678, 5679, 5680, 5681, 5682, 5683, 5684, 5685, 5686, 5687, 5688, 5689, 5690, 5691, 5692, 5693, 5694, 5695, 5696, 5697, 5698, 5699, 5700, 5701, 5702, 5703, 5704, 5705, 5706, 5707, 5708, 5709, 5710, 5711, 5712, 5713, 5714, 5715, 5716, 5717, 5718, 5719, 5720, 5721, 5722, 5723, 5724, 5725, 5726, 5727, 5728, 5729, 5730, 5731, 5732, 5733, 5734, 5735, 5736, 5737, 5738, 5739, 5740, 5741, 5742, 5743, 5744, 5745, 5746, 5747, 5748, 5749, 5750, 5751, 5752, 5753, 5754, 5755, 5756, 5757, 5758, 5759, 5760, 5761, 5762, 5763, 5764, 5765, 5766, 5767, 5768, 5769, 5770, 5771, 5772, 5773, 5774, 5775, 5776, 5777, 5778, 5779, 5780, 5781, 5782, 5783, 5784, 5785, 5786, 5787, 5788, 5789, 5790, 5791, 5792, 5793, 5794, 5795, 5796, 5797, 5798, 5799, 5800, 5801, 5802, 5803, 5804, 5805, 5806, 5807, 5808, 5809, 5810, 5811, 5812, 5813, 5814, 5815, 5816, 5817, 5818, 5819, 5820, 5821, 5822, 5823, 5824, 5825, 5826, 5827, 5828, 5829, 5830, 5831, 5832, 5833, 5834, 5835, 5836, 5837, 5838, 5839, 5840, 5841, 5842, 5843, 5844, 5845, 5846, 5847, 5848, 5849, 5850, 5851, 5852, 5853, 5854, 5855, 5856, 5857, 5858, 5859, 5860, 5861, 5862, 5863, 5864, 5865, 5866, 5867, 5868, 5869, 5870, 5871, 5872, 5873, 5874, 5875, 5876, 5877, 5878, 5879, 5880, 5881, 5882, 5883, 5884, 5885, 5886, 5887, 5888, 5889, 5890, 5891, 5892, 5893, 5894, 5895, 5896, 5897, 5898, 5899, 5900, 5901, 5902, 5903, 5904, 5905, 5906, 5907, 5908, 5909, 5910, 5911, 5912, 5913, 5914, 5915, 5916, 5917, 5918, 5919, 5920, 5921, 5922, 5923, 5924, 5925, 5926, 5927, 5928, 5929, 5930, 5931, 5932, 5933, 5934, 5935, 5936, 5937, 5938, 5939, 5940, 5941, 5942, 5943, 5944, 5945, 5946, 5947, 5948, 5949, 5950, 5951, 5952, 5953, 5954, 5955, 5956, 5957, 5958, 5959, 5960, 5961, 5962, 5963, 5964, 5965, 5966, 5967, 5968, 5969, 5970, 5971, 5972, 5973, 5974, 5975, 5976, 5977, 5978, 5979, 5980, 5981, 5982, 5983, 5984, 5985, 5986, 5987, 5988, 5989, 5990, 5991, 5992, 5993, 5994, 5995, 5996, 5997, 5998, 5999, 6000, 6001, 6002, 6003, 6004, 6005, 6006, 6007, 6008, 6009, 6010, 6011, 6012, 6013, 6014, 6015, 6016, 6017, 6018, 6019, 6020, 6021, 6022, 6023, 6024, 6025, 6026, 6027, 6028, 6029, 6030, 6031, 6032, 6033, 6034, 6035, 6036, 6037, 6038, 6039, 6040, 6041, 6042, 6043, 6044, 6045, 6046, 6047, 6048, 6049, 6050, 6051, 6052, 6053, 6054, 6055, 6056, 6057, 6058, 6059, 6060, 6061, 6062, 6063, 6064, 6065, 6066, 6067, 6068, 6069, 6070, 6071, 6072, 6073, 6074, 6075, 6076, 6077, 6078, 6079, 6080, 6081, 6082, 6083, 6084, 6085, 6086, 6087, 6088, 6089, 6090, 6091, 6092, 6093, 6094, 6095, 6096, 6097, 6098, 6099, 6100, 6101, 6102, 6103, 6104, 6105, 6106, 6107, 6108, 6109, 6110, 6111, 6112, 6113, 6114, 6115, 6116, 6117, 6118, 6119, 6120, 6121, 6122, 6123, 6124, 6125, 6126, 6127, 6128, 6129, 6130, 6131, 6132, 6133, 6134, 6135, 6136, 6137, 6138, 6139, 6140, 6141, 6142, 6143, 6144, 6145, 6146, 6147, 6148, 6149, 6150, 6151, 6152, 6153, 6154, 6155, 6156, 6157, 6158, 6159, 6160, 6161, 6162, 6163, 6164, 6165, 6166, 6167, 6168, 6169, 6170, 6171, 6172, 6173, 6174, 6175, 6176, 6177, 6178, 6179, 6180, 6181, 6182, 6183, 6184, 6185, 6186, 6187, 6188, 6189, 6190, 6191, 6192, 6193, 6194, 6195, 6196, 6197, 6198, 6199, 6200, 6201, 6202, 6203, 6204, 6205, 6206, 6207, 6208, 6209, 6210, 6211, 6212, 6213, 6214, 6215, 6216, 6217, 6218, 6219, 6220, 6221, 6222, 6223, 6224, 6225, 6226, 6227, 6228, 6229, 6230, 6231, 6232, 6233, 6234, 6235, 6236, 6237, 6238, 6239, 6240, 6241, 6242, 6243, 6244, 6245, 6246, 6247, 6248, 6249, 6250, 6251, 6252, 6253, 6254, 6255, 6256, 6257, 6258, 6259, 6260, 6261, 6262, 6263, 6264, 6265, 6266, 6267, 6268, 6269, 6270, 6271, 6272, 6273, 6274, 6275, 6276, 6277, 6278, 6279, 6280, 6281, 6282, 6283, 6284, 6285, 6286, 6287, 6288, 6289, 6290, 6291, 6292, 6293, 6294, 6295, 6296, 6297, 6298, 6299, 6300, 6301, 6302, 6303, 6304, 6305, 6306, 6307, 6308, 6309, 6310, 6311, 6312, 6313, 6314, 6315, 6316, 6317, 6318, 6319, 6320, 6321, 6322, 6323, 6324, 6325, 6326, 6327, 6328, 6329, 6330, 6331, 6332, 6333, 6334, 6335, 6336, 6337, 6338, 6339, 6340, 6341, 6342, 6343, 6344, 6345, 6346, 6347, 6348, 6349, 6350, 6351, 6352, 6353, 6354, 6355, 6356, 6357, 6358, 6359, 6360, 6361, 6362, 6363, 6364, 6365, 6366, 6367, 6368, 6369, 6370, 6371, 6372, 6373, 6374, 6375, 6376, 6377, 6378, 6379, 6380, 6381, 6382, 6383, 6384, 6385, 6386, 6387, 6388, 6389, 6390, 6391, 6392, 6393, 6394, 6395, 6396, 6397, 6398, 6399, 6400, 6401, 6402, 6403, 6404, 6405, 6406, 6407, 6408, 6409, 6410, 6411, 6412, 6413, 6414, 6415, 6416, 6417, 6418, 6419, 6420, 6421, 6422, 6423, 6424, 6425, 6426, 6427, 6428, 6429, 6430, 6431, 6432, 6433, 6434, 6435, 6436, 6437, 6438, 6439, 6440, 6441, 6442, 6443, 6444, 6445, 6446, 6447, 6448, 6449, 6450, 6451, 6452, 6453, 6454, 6455, 6456, 6457, 6458, 6459, 6460, 6461, 6462, 6463, 6464, 6465, 6466, 6467, 6468, 6469, 6470, 6471, 6472, 6473, 6474, 6475, 6476, 6477, 6478, 6479, 6480, 6481, 6482, 6483, 6484, 6485, 6486, 6487, 6488, 6489, 6490, 6491, 6492, 6493, 6494, 6495, 6496, 6497, 6498, 6499, 6500, 6501, 6502, 6503, 6504, 6505, 6506, 6507, 6508, 6509, 6510, 6511, 6512, 6513, 6514, 6515, 6516, 6517, 6518, 6519, 6520, 6521, 6522, 6523, 6524, 6525, 6526, 6527, 6528, 6529, 6530, 6531, 6532, 6533, 6534, 6535, 6536, 6537, 6538, 6539, 6540, 6541, 6542, 6543, 6544, 6545, 6546, 6547, 6548, 6549, 6550, 6551, 6552, 6553, 6554, 6555, 6556, 6557, 6558, 6559, 6560, 6561, 6562, 6563, 6564, 6565, 6566, 6567, 6568, 6569, 6570, 6571, 6572, 6573, 6574, 6575, 6576, 6577, 6578, 6579, 6580, 6581, 6582, 6583, 6584, 6585, 6586, 6587, 6588, 6589, 6590, 6591, 6592, 6593, 6594, 6595, 6596, 6597, 6598, 6599, 6600, 6601, 6602, 6603, 6604, 6605, 6606, 6607, 6608, 6609, 6610, 6611, 6612, 6613, 6614, 6615, 6616, 6617, 6618, 6619, 6620, 6621, 6622, 6623, 6624, 6625, 6626, 6627, 6628, 6629, 6630, 6631, 6632, 6633, 6634, 6635, 6636, 6637, 6638, 6639, 6640, 6641, 6642, 6643, 6644, 6645, 6646, 6647, 6648, 6649, 6650, 6651, 6652, 6653, 6654, 6655, 6656, 6657, 6658, 6659, 6660, 6661, 6662, 6663, 6664, 6665, 6666, 6667, 6668, 6669, 6670, 6671, 6672, 6673, 6674, 6675, 6676, 6677, 6678, 6679, 6680, 6681, 6682, 6683, 6684, 6685, 6686, 6687, 6688, 6689, 6690, 6691, 6692, 6693, 6694, 6695, 6696, 6697, 6698, 6699, 6700, 6701, 6702, 6703, 6704, 6705, 6706, 6707, 6708, 6709, 6710, 6711, 6712, 6713, 6714, 6715, 6716, 6717, 6718, 6719, 6720, 6721, 6722, 6723, 6724, 6725, 6726, 6727, 6728, 6729, 6730, 6731, 6732, 6733, 6734, 6735, 6736, 6737, 6738, 6739, 6740, 6741, 6742, 6743, 6744, 6745, 6746, 6747, 6748, 6749, 6750, 6751, 6752, 6753, 6754, 6755, 6756, 6757, 6758, 6759, 6760, 6761, 6762, 6763, 6764, 6765, 6766, 6767, 6768, 6769, 6770, 6771, 6772, 6773, 6774, 6775, 6776, 6777, 6778, 6779, 6780, 6781, 6782, 6783, 6784, 6785, 6786, 6787, 6788, 6789, 6790, 6791, 6792, 6793, 6794, 6795, 6796, 6797, 6798, 6799, 6800, 6801, 6802, 6803, 6804, 6805, 6806, 6807, 6808, 6809, 6810, 6811, 6812, 6813, 6814, 6815, 6816, 6817, 6818, 6819, 6820, 6821, 6822, 6823, 6824, 6825, 6826, 6827, 6828, 6829, 6830, 6831, 6832, 6833, 6834, 6835, 6836, 6837, 6838, 6839, 6840, 6841, 6842, 6843, 6844, 6845, 6846, 6847, 6848, 6849, 6850, 6851, 6852, 6853, 6854, 6855, 6856, 6857, 6858, 6859, 6860, 6861, 6862, 6863, 6864, 6865, 6866, 6867, 6868, 6869, 6870, 6871, 6872, 6873, 6874, 6875, 6876, 6877, 6878, 6879, 6880, 6881, 6882, 6883, 6884, 6885, 6886, 6887, 6888, 6889, 6890, 6891, 6892, 6893, 6894, 6895, 6896, 6897, 6898, 6899, 6900, 6901, 6902, 6903, 6904, 6905, 6906, 6907, 6908, 6909, 6910, 6911, 6912, 6913, 6914, 6915, 6916, 6917, 6918, 6919, 6920, 6921, 6922, 6923, 6924, 6925, 6926, 6927, 6928, 6929, 6930, 6931, 6932, 6933, 6934, 6935, 6936, 6937, 6938, 6939, 6940, 6941, 6942, 6943, 6944, 6945, 6946, 6947, 6948, 6949, 6950, 6951, 6952, 6953, 6954, 6955, 6956, 6957, 6958, 6959, 6960, 6961, 6962, 6963, 6964, 6965, 6966, 6967, 6968, 6969, 6970, 6971, 6972, 6973, 6974, 6975, 6976, 6977, 6978, 6979, 6980, 6981, 6982, 6983, 6984, 6985, 6986, 6987, 6988, 6989, 6990, 6991, 6992, 6993, 6994, 6995, 6996, 6997, 6998, 6999, 7000, 7001, 7002, 7003, 7004, 7005, 7006, 7007, 7008, 7009, 7010, 7011, 7012, 7013, 7014, 7015, 7016, 7017, 7018, 7019, 7020, 7021, 7022, 7023, 7024, 7025, 7026, 7027, 7028, 7029, 7030, 7031, 7032, 7033, 7034, 7035, 7036, 7037, 7038, 7039, 7040, 7041, 7042, 7043, 7044, 7045, 7046, 7047, 7048, 7049, 7050, 7051, 7052, 7053, 7054, 7055, 7056, 7057, 7058, 7059, 7060, 7061, 7062, 7063, 7064, 7065, 7066, 7067, 7068, 7069, 7070, 7071, 7072, 7073, 7074, 7075, 7076, 7077, 7078, 7079, 7080, 7081, 7082, 7083, 7084, 7085, 7086, 7087, 7088, 7089, 7090, 7091, 7092, 7093, 7094, 7095, 7096, 7097, 7098, 7099, 7100, 7101, 7102, 7103, 7104, 7105, 7106, 7107, 7108, 7109, 7110, 7111, 7112, 7113, 7114, 7115, 7116, 7117, 7118, 7119, 7120, 7121, 7122, 7123, 7124, 7125, 7126, 7127, 7128, 7129, 7130, 7131, 7132, 7133, 7134, 7135, 7136, 7137, 7138, 7139, 7140, 7141, 7142, 7143, 7144, 7145, 7146, 7147, 7148, 7149, 7150, 7151, 7152, 7153, 7154, 7155, 7156, 7157, 7158, 7159, 7160, 7161, 7162, 7163, 7164, 7165, 7166, 7167, 7168, 7169, 7170, 7171, 7172, 7173, 7174, 7175, 7176, 7177, 7178, 7179, 7180, 7181, 7182, 7183, 7184, 7185, 7186, 7187, 7188, 7189, 7190, 7191, 7192, 7193, 7194, 7195, 7196, 7197, 7198, 7199, 7200, 7201, 7202, 7203, 7204, 7205, 7206, 7207, 7208, 7209, 7210, 7211, 7212, 7213, 7214, 7215, 7216, 7217, 7218, 7219, 7220, 7221, 7222, 7223, 7224, 7225, 7226, 7227, 7228, 7229, 7230, 7231, 7232, 7233, 7234, 7235, 7236, 7237, 7238, 7239, 7240, 7241, 7242, 7243, 7244, 7245, 7246, 7247, 7248, 7249, 7250, 7251, 7252, 7253, 7254, 7255, 7256, 7257, 7258, 7259, 7260, 7261, 7262, 7263, 7264, 7265, 7266, 7267, 7268, 7269, 7270, 7271, 7272, 7273, 7274, 7275, 7276, 7277, 7278, 7279, 7280, 7281, 7282, 7283, 7284, 7285, 7286, 7287, 7288, 7289, 7290, 7291, 7292, 7293, 7294, 7295, 7296, 7297, 7298, 7299, 7300, 7301, 7302, 7303, 7304, 7305, 7306, 7307, 7308, 7309, 7310, 7311, 7312, 7313, 7314, 7315, 7316, 7317, 7318, 7319, 7320, 7321, 7322, 7323, 7324, 7325, 7326, 7327, 7328, 7329, 7330, 7331, 7332, 7333, 7334, 7335, 7336, 7337, 7338, 7339, 7340, 7341, 7342, 7343, 7344, 7345, 7346, 7347, 7348, 7349, 7350, 7351, 7352, 7353, 7354, 7355, 7356, 7357, 7358, 7359, 7360, 7361, 7362, 7363, 7364, 7365, 7366, 7367, 7368, 7369, 7370, 7371, 7372, 7373, 7374, 7375, 7376, 7377, 7378, 7379, 7380, 7381, 7382, 7383, 7384, 7385, 7386, 7387, 7388, 7389, 7390, 7391, 7392, 7393, 7394, 7395, 7396, 7397, 7398, 7399, 7400, 7401, 7402, 7403, 7404, 7405, 7406, 7407, 7408, 7409, 7410, 7411, 7412, 7413, 7414, 7415, 7416, 7417, 7418, 7419, 7420, 7421, 7422, 7423, 7424, 7425, 7426, 7427, 7428, 7429, 7430, 7431, 7432, 7433, 7434, 7435, 7436, 7437, 7438, 7439, 7440, 7441, 7442, 7443, 7444, 7445, 7446, 7447, 7448, 7449, 7450, 7451, 7452, 7453, 7454, 7455, 7456, 7457, 7458, 7459, 7460, 7461, 7462, 7463, 7464, 7465, 7466, 7467, 7468, 7469, 7470, 7471, 7472, 7473, 7474, 7475, 7476, 7477, 7478, 7479, 7480, 7481, 7482, 7483, 7484, 7485, 7486, 7487, 7488, 7489, 7490, 7491, 7492, 7493, 7494, 7495, 7496, 7497, 7498, 7499, 7500, 7501, 7502, 7503, 7504, 7505, 7506, 7507, 7508, 7509, 7510, 7511, 7512, 7513, 7514, 7515, 7516, 7517, 7518, 7519, 7520, 7521, 7522, 7523, 7524, 7525, 7526, 7527, 7528, 7529, 7530, 7531, 7532, 7533, 7534, 7535, 7536, 7537, 7538, 7539, 7540, 7541, 7542, 7543, 7544, 7545, 7546, 7547, 7548, 7549, 7550, 7551, 7552, 7553, 7554, 7555, 7556, 7557, 7558, 7559, 7560, 7561, 7562, 7563, 7564, 7565, 7566, 7567, 7568, 7569, 7570, 7571, 7572, 7573, 7574, 7575, 7576, 7577, 7578, 7579, 7580, 7581, 7582, 7583, 7584, 7585, 7586, 7587, 7588, 7589, 7590, 7591, 7592, 7593, 7594, 7595, 7596, 7597, 7598, 7599, 7600, 7601, 7602, 7603, 7604, 7605, 7606, 7607, 7608, 7609, 7610, 7611, 7612, 7613, 7614, 7615, 7616, 7617, 7618, 7619, 7620, 7621, 7622, 7623, 7624, 7625, 7626, 7627, 7628, 7629, 7630, 7631, 7632, 7633, 7634, 7635, 7636, 7637, 7638, 7639, 7640, 7641, 7642, 7643, 7644, 7645, 7646, 7647, 7648, 7649, 7650, 7651, 7652, 7653, 7654, 7655, 7656, 7657, 7658, 7659, 7660, 7661, 7662, 7663, 7664, 7665, 7666, 7667, 7668, 7669, 7670, 7671, 7672, 7673, 7674, 7675, 7676, 7677, 7678, 7679, 7680, 7681, 7682, 7683, 7684, 7685, 7686, 7687, 7688, 7689, 7690, 7691, 7692, 7693, 7694, 7695, 7696, 7697, 7698, 7699, 7700, 7701, 7702, 7703, 7704, 7705, 7706, 7707, 7708, 7709, 7710, 7711, 7712, 7713, 7714, 7715, 7716, 7717, 7718, 7719, 7720, 7721, 7722, 7723, 7724, 7725, 7726, 7727, 7728, 7729, 7730, 7731, 7732, 7733, 7734, 7735, 7736, 7737, 7738, 7739, 7740, 7741, 7742, 7743, 7744, 7745, 7746, 7747, 7748, 7749, 7750, 7751, 7752, 7753, 7754, 7755, 7756, 7757, 7758, 7759, 7760, 7761, 7762, 7763, 7764, 7765, 7766, 7767, 7768, 7769, 7770, 7771, 7772, 7773, 7774, 7775, 7776, 7777, 7778, 7779, 7780, 7781, 7782, 7783, 7784, 7785, 7786, 7787, 7788, 7789, 7790, 7791, 7792, 7793, 7794, 7795, 7796, 7797, 7798, 7799, 7800, 7801, 7802, 7803, 7804, 7805, 7806, 7807, 7808, 7809, 7810, 7811, 7812, 7813, 7814, 7815, 7816, 7817, 7818, 7819, 7820, 7821, 7822, 7823, 7824, 7825, 7826, 7827, 7828, 7829, 7830, 7831, 7832, 7833, 7834, 7835, 7836, 7837, 7838, 7839, 7840, 7841, 7842, 7843, 7844, 7845, 7846, 7847, 7848, 7849, 7850, 7851, 7852, 7853, 7854, 7855, 7856, 7857, 7858, 7859, 7860, 7861, 7862, 7863, 7864, 7865, 7866, 7867, 7868, 7869, 7870, 7871, 7872, 7873, 7874, 7875, 7876, 7877, 7878, 7879, 7880, 7881, 7882, 7883, 7884, 7885, 7886, 7887, 7888, 7889, 7890, 7891, 7892, 7893, 7894, 7895, 7896, 7897, 7898, 7899, 7900, 7901, 7902, 7903, 7904, 7905, 7906, 7907, 7908, 7909, 7910, 7911, 7912, 7913, 7914, 7915, 7916, 7917, 7918, 7919, 7920, 7921, 7922, 7923, 7924, 7925, 7926, 7927, 7928, 7929, 7930, 7931, 7932, 7933, 7934, 7935, 7936, 7937, 7938, 7939, 7940, 7941, 7942, 7943, 7944, 7945, 7946, 7947, 7948, 7949, 7950, 7951, 7952, 7953, 7954, 7955, 7956, 7957, 7958, 7959, 7960, 7961, 7962, 7963, 7964, 7965, 7966, 7967, 7968, 7969, 7970, 7971, 7972, 7973, 7974, 7975, 7976, 7977, 7978, 7979, 7980, 7981, 7982, 7983, 7984, 7985, 7986, 7987, 7988, 7989, 7990, 7991, 7992, 7993, 7994, 7995, 7996, 7997, 7998, 7999, 8000, 8001, 8002, 8003, 8004, 8005, 8006, 8007, 8008, 8009, 8010, 8011, 8012, 8013, 8014, 8015, 8016, 8017, 8018, 8019, 8020, 8021, 8022, 8023, 8024, 8025, 8026, 8027, 8028, 8029, 8030, 8031, 8032, 8033, 8034, 8035, 8036, 8037, 8038, 8039, 8040, 8041, 8042, 8043, 8044, 8045, 8046, 8047, 8048, 8049, 8050, 8051, 8052, 8053, 8054, 8055, 8056, 8057, 8058, 8059, 8060, 8061, 8062, 8063, 8064, 8065, 8066, 8067, 8068, 8069, 8070, 8071, 8072, 8073, 8074, 8075, 8076, 8077, 8078, 8079, 8080, 8081, 8082, 8083, 8084, 8085, 8086, 8087, 8088, 8089, 8090, 8091, 8092, 8093, 8094, 8095, 8096, 8097, 8098, 8099, 8100, 8101, 8102, 8103, 8104, 8105, 8106, 8107, 8108, 8109, 8110, 8111, 8112, 8113, 8114, 8115, 8116, 8117, 8118, 8119, 8120, 8121, 8122, 8123, 8124, 8125, 8126, 8127, 8128, 8129, 8130, 8131, 8132, 8133, 8134, 8135, 8136, 8137, 8138, 8139, 8140, 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 8157, 8158, 8159, 8160, 8161, 8162, 8163, 8164, 8165, 8166, 8167, 8168, 8169, 8170, 8171, 8172, 8173, 8174, 8175, 8176, 8177, 8178, 8179, 8180, 8181, 8182, 8183, 8184, 8185, 8186, 8187, 8188, 8189, 8190, 8191, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200, 8201, 8202, 8203, 8204, 8205, 8206, 8207, 8208, 8209, 8210, 8211, 8212, 8213, 8214, 8215, 8216, 8217, 8218, 8219, 8220, 8221, 8222, 8223, 8224, 8225, 8226, 8227, 8228, 8229, 8230, 8231, 8232, 8233, 8234, 8235, 8236, 8237, 8238, 8239, 8240, 8241, 8242, 8243, 8244, 8245, 8246, 8247, 8248, 8249, 8250, 8251, 8252, 8253, 8254, 8255, 8256, 8257, 8258, 8259, 8260, 8261, 8262, 8263, 8264, 8265, 8266, 8267, 8268, 8269, 8270, 8271, 8272, 8273, 8274, 8275, 8276, 8277, 8278, 8279, 8280, 8281, 8282, 8283, 8284, 8285, 8286, 8287, 8288, 8289, 8290, 8291, 8292, 8293, 8294, 8295, 8296, 8297, 8298, 8299, 8300, 8301, 8302, 8303, 8304, 8305, 8306, 8307, 8308, 8309, 8310, 8311, 8312, 8313, 8314, 8315, 8316, 8317, 8318, 8319, 8320, 8321, 8322, 8323, 8324, 8325, 8326, 8327, 8328, 8329, 8330, 8331, 8332, 8333, 8334, 8335, 8336, 8337, 8338, 8339, 8340, 8341, 8342, 8343, 8344, 8345, 8346, 8347, 8348, 8349, 8350, 8351, 8352, 8353, 8354, 8355, 8356, 8357, 8358, 8359, 8360, 8361, 8362, 8363, 8364, 8365, 8366, 8367, 8368, 8369, 8370, 8371, 8372, 8373, 8374, 8375, 8376, 8377, 8378, 8379, 8380, 8381, 8382, 8383, 8384, 8385, 8386, 8387, 8388, 8389, 8390, 8391, 8392, 8393, 8394, 8395, 8396, 8397, 8398, 8399, 8400, 8401, 8402, 8403, 8404, 8405, 8406, 8407, 8408, 8409, 8410, 8411, 8412, 8413, 8414, 8415, 8416, 8417, 8418, 8419, 8420, 8421, 8422, 8423, 8424, 8425, 8426, 8427, 8428, 8429, 8430, 8431, 8432, 8433, 8434, 8435, 8436, 8437, 8438, 8439, 8440, 8441, 8442, 8443, 8444, 8445, 8446, 8447, 8448, 8449, 8450, 8451, 8452, 8453, 8454, 8455, 8456, 8457, 8458, 8459, 8460, 8461, 8462, 8463, 8464, 8465, 8466, 8467, 8468, 8469, 8470, 8471, 8472, 8473, 8474, 8475, 8476, 8477, 8478, 8479, 8480, 8481, 8482, 8483, 8484, 8485, 8486, 8487, 8488, 8489, 8490, 8491, 8492, 8493, 8494, 8495, 8496, 8497, 8498, 8499, 8500, 8501, 8502, 8503, 8504, 8505, 8506, 8507, 8508, 8509, 8510, 8511, 8512, 8513, 8514, 8515, 8516, 8517, 8518, 8519, 8520, 8521, 8522, 8523, 8524, 8525, 8526, 8527, 8528, 8529, 8530, 8531, 8532, 8533, 8534, 8535, 8536, 8537, 8538, 8539, 8540, 8541, 8542, 8543, 8544, 8545, 8546, 8547, 8548, 8549, 8550, 8551, 8552, 8553, 8554, 8555, 8556, 8557, 8558, 8559, 8560, 8561, 8562, 8563, 8564, 8565, 8566, 8567, 8568, 8569, 8570, 8571, 8572, 8573, 8574, 8575, 8576, 8577, 8578, 8579, 8580, 8581, 8582, 8583, 8584, 8585, 8586, 8587, 8588, 8589, 8590, 8591, 8592, 8593, 8594, 8595, 8596, 8597, 8598, 8599, 8600, 8601, 8602, 8603, 8604, 8605, 8606, 8607, 8608, 8609, 8610, 8611, 8612, 8613, 8614, 8615, 8616, 8617, 8618, 8619, 8620, 8621, 8622, 8623, 8624, 8625, 8626, 8627, 8628, 8629, 8630, 8631, 8632, 8633, 8634, 8635, 8636, 8637, 8638, 8639, 8640, 8641, 8642, 8643, 8644, 8645, 8646, 8647, 8648, 8649, 8650, 8651, 8652, 8653, 8654, 8655, 8656, 8657, 8658, 8659, 8660, 8661, 8662, 8663, 8664, 8665, 8666, 8667, 8668, 8669, 8670, 8671, 8672, 8673, 8674, 8675, 8676, 8677, 8678, 8679, 8680, 8681, 8682, 8683, 8684, 8685, 8686, 8687, 8688, 8689, 8690, 8691, 8692, 8693, 8694, 8695, 8696, 8697, 8698, 8699, 8700, 8701, 8702, 8703, 8704, 8705, 8706, 8707, 8708, 8709, 8710, 8711, 8712, 8713, 8714, 8715, 8716, 8717, 8718, 8719, 8720, 8721, 8722, 8723, 8724, 8725, 8726, 8727, 8728, 8729, 8730, 8731, 8732, 8733, 8734, 8735, 8736, 8737, 8738, 8739, 8740, 8741, 8742, 8743, 8744, 8745, 8746, 8747, 8748, 8749, 8750, 8751, 8752, 8753, 8754, 8755, 8756, 8757, 8758, 8759, 8760, 8761, 8762, 8763, 8764, 8765, 8766, 8767, 8768, 8769, 8770, 8771, 8772, 8773, 8774, 8775, 8776, 8777, 8778, 8779, 8780, 8781, 8782, 8783, 8784, 8785, 8786, 8787, 8788, 8789, 8790, 8791, 8792, 8793, 8794, 8795, 8796, 8797, 8798, 8799, 8800, 8801, 8802, 8803, 8804, 8805, 8806, 8807, 8808, 8809, 8810, 8811, 8812, 8813, 8814, 8815, 8816, 8817, 8818, 8819, 8820, 8821, 8822, 8823, 8824, 8825, 8826, 8827, 8828, 8829, 8830, 8831, 8832, 8833, 8834, 8835, 8836, 8837, 8838, 8839, 8840, 8841, 8842, 8843, 8844, 8845, 8846, 8847, 8848, 8849, 8850, 8851, 8852, 8853, 8854, 8855, 8856, 8857, 8858, 8859, 8860, 8861, 8862, 8863, 8864, 8865, 8866, 8867, 8868, 8869, 8870, 8871, 8872, 8873, 8874, 8875, 8876, 8877, 8878, 8879, 8880, 8881, 8882, 8883, 8884, 8885, 8886, 8887, 8888, 8889, 8890, 8891, 8892, 8893, 8894, 8895, 8896, 8897, 8898, 8899, 8900, 8901, 8902, 8903, 8904, 8905, 8906, 8907, 8908, 8909, 8910, 8911, 8912, 8913, 8914, 8915, 8916, 8917, 8918, 8919, 8920, 8921, 8922, 8923, 8924, 8925, 8926, 8927, 8928, 8929, 8930, 8931, 8932, 8933, 8934, 8935, 8936, 8937, 8938, 8939, 8940, 8941, 8942, 8943, 8944, 8945, 8946, 8947, 8948, 8949, 8950, 8951, 8952, 8953, 8954, 8955, 8956, 8957, 8958, 8959, 8960, 8961, 8962, 8963, 8964, 8965, 8966, 8967, 8968, 8969, 8970, 8971, 8972, 8973, 8974, 8975, 8976, 8977, 8978, 8979, 8980, 8981, 8982, 8983, 8984, 8985, 8986, 8987, 8988, 8989, 8990, 8991, 8992, 8993, 8994, 8995, 8996, 8997, 8998, 8999, 9000, 9001, 9002, 9003, 9004, 9005, 9006, 9007, 9008, 9009, 9010, 9011, 9012, 9013, 9014, 9015, 9016, 9017, 9018, 9019, 9020, 9021, 9022, 9023, 9024, 9025, 9026, 9027, 9028, 9029, 9030, 9031, 9032, 9033, 9034, 9035, 9036, 9037, 9038, 9039, 9040, 9041, 9042, 9043, 9044, 9045, 9046, 9047, 9048, 9049, 9050, 9051, 9052, 9053, 9054, 9055, 9056, 9057, 9058, 9059, 9060, 9061, 9062, 9063, 9064, 9065, 9066, 9067, 9068, 9069, 9070, 9071, 9072, 9073, 9074, 9075, 9076, 9077, 9078, 9079, 9080, 9081, 9082, 9083, 9084, 9085, 9086, 9087, 9088, 9089, 9090, 9091, 9092, 9093, 9094, 9095, 9096, 9097, 9098, 9099, 9100, 9101, 9102, 9103, 9104, 9105, 9106, 9107, 9108, 9109, 9110, 9111, 9112, 9113, 9114, 9115, 9116, 9117, 9118, 9119, 9120, 9121, 9122, 9123, 9124, 9125, 9126, 9127, 9128, 9129, 9130, 9131, 9132, 9133, 9134, 9135, 9136, 9137, 9138, 9139, 9140, 9141, 9142, 9143, 9144, 9145, 9146, 9147, 9148, 9149, 9150, 9151, 9152, 9153, 9154, 9155, 9156, 9157, 9158, 9159, 9160, 9161, 9162, 9163, 9164, 9165, 9166, 9167, 9168, 9169, 9170, 9171, 9172, 9173, 9174, 9175, 9176, 9177, 9178, 9179, 9180, 9181, 9182, 9183, 9184, 9185, 9186, 9187, 9188, 9189, 9190, 9191, 9192, 9193, 9194, 9195, 9196, 9197, 9198, 9199, 9200, 9201, 9202, 9203, 9204, 9205, 9206, 9207, 9208, 9209, 9210, 9211, 9212, 9213, 9214, 9215, 9216, 9217, 9218, 9219, 9220, 9221, 9222, 9223, 9224, 9225, 9226, 9227, 9228, 9229, 9230, 9231, 9232, 9233, 9234, 9235, 9236, 9237, 9238, 9239, 9240, 9241, 9242, 9243, 9244, 9245, 9246, 9247, 9248, 9249, 9250, 9251, 9252, 9253, 9254, 9255, 9256, 9257, 9258, 9259, 9260, 9261, 9262, 9263, 9264, 9265, 9266, 9267, 9268, 9269, 9270, 9271, 9272, 9273, 9274, 9275, 9276, 9277, 9278, 9279, 9280, 9281, 9282, 9283, 9284, 9285, 9286, 9287, 9288, 9289, 9290, 9291, 9292, 9293, 9294, 9295, 9296, 9297, 9298, 9299, 9300, 9301, 9302, 9303, 9304, 9305, 9306, 9307, 9308, 9309, 9310, 9311, 9312, 9313, 9314, 9315, 9316, 9317, 9318, 9319, 9320, 9321, 9322, 9323, 9324, 9325, 9326, 9327, 9328, 9329, 9330, 9331, 9332, 9333, 9334, 9335, 9336, 9337, 9338, 9339, 9340, 9341, 9342, 9343, 9344, 9345, 9346, 9347, 9348, 9349, 9350, 9351, 9352, 9353, 9354, 9355, 9356, 9357, 9358, 9359, 9360, 9361, 9362, 9363, 9364, 9365, 9366, 9367, 9368, 9369, 9370, 9371, 9372, 9373, 9374, 9375, 9376, 9377, 9378, 9379, 9380, 9381, 9382, 9383, 9384, 9385, 9386, 9387, 9388, 9389, 9390, 9391, 9392, 9393, 9394, 9395, 9396, 9397, 9398, 9399, 9400, 9401, 9402, 9403, 9404, 9405, 9406, 9407, 9408, 9409, 9410, 9411, 9412, 9413, 9414, 9415, 9416, 9417, 9418, 9419, 9420, 9421, 9422, 9423, 9424, 9425, 9426, 9427, 9428, 9429, 9430, 9431, 9432, 9433, 9434, 9435, 9436, 9437, 9438, 9439, 9440, 9441, 9442, 9443, 9444, 9445, 9446, 9447, 9448, 9449, 9450, 9451, 9452, 9453, 9454, 9455, 9456, 9457, 9458, 9459, 9460, 9461, 9462, 9463, 9464, 9465, 9466, 9467, 9468, 9469, 9470, 9471, 9472, 9473, 9474, 9475, 9476, 9477, 9478, 9479, 9480, 9481, 9482, 9483, 9484, 9485, 9486, 9487, 9488, 9489, 9490, 9491, 9492, 9493, 9494, 9495, 9496, 9497, 9498, 9499, 9500, 9501, 9502, 9503, 9504, 9505, 9506, 9507, 9508, 9509, 9510, 9511, 9512, 9513, 9514, 9515, 9516, 9517, 9518, 9519, 9520, 9521, 9522, 9523, 9524, 9525, 9526, 9527, 9528, 9529, 9530, 9531, 9532, 9533, 9534, 9535, 9536, 9537, 9538, 9539, 9540, 9541, 9542, 9543, 9544, 9545, 9546, 9547, 9548, 9549, 9550, 9551, 9552, 9553, 9554, 9555, 9556, 9557, 9558, 9559, 9560, 9561, 9562, 9563, 9564, 9565, 9566, 9567, 9568, 9569, 9570, 9571, 9572, 9573, 9574, 9575, 9576, 9577, 9578, 9579, 9580, 9581, 9582, 9583, 9584, 9585, 9586, 9587, 9588, 9589, 9590, 9591, 9592, 9593, 9594, 9595, 9596, 9597, 9598, 9599, 9600, 9601, 9602, 9603, 9604, 9605, 9606, 9607, 9608, 9609, 9610, 9611, 9612, 9613, 9614, 9615, 9616, 9617, 9618, 9619, 9620, 9621, 9622, 9623, 9624, 9625, 9626, 9627, 9628, 9629, 9630, 9631, 9632, 9633, 9634, 9635, 9636, 9637, 9638, 9639, 9640, 9641, 9642, 9643, 9644, 9645, 9646, 9647, 9648, 9649, 9650, 9651, 9652, 9653, 9654, 9655, 9656, 9657, 9658, 9659, 9660, 9661, 9662, 9663, 9664, 9665, 9666, 9667, 9668, 9669, 9670, 9671, 9672, 9673, 9674, 9675, 9676, 9677, 9678, 9679, 9680, 9681, 9682, 9683, 9684, 9685, 9686, 9687, 9688, 9689, 9690, 9691, 9692, 9693, 9694, 9695, 9696, 9697, 9698, 9699, 9700, 9701, 9702, 9703, 9704, 9705, 9706, 9707, 9708, 9709, 9710, 9711, 9712, 9713, 9714, 9715, 9716, 9717, 9718, 9719, 9720, 9721, 9722, 9723, 9724, 9725, 9726, 9727, 9728, 9729, 9730, 9731, 9732, 9733, 9734, 9735, 9736, 9737, 9738, 9739, 9740, 9741, 9742, 9743, 9744, 9745, 9746, 9747, 9748, 9749, 9750, 9751, 9752, 9753, 9754, 9755, 9756, 9757, 9758, 9759, 9760, 9761, 9762, 9763, 9764, 9765, 9766, 9767, 9768, 9769, 9770, 9771, 9772, 9773, 9774, 9775, 9776, 9777, 9778, 9779, 9780, 9781, 9782, 9783, 9784, 9785, 9786, 9787, 9788, 9789, 9790, 9791, 9792, 9793, 9794, 9795, 9796, 9797, 9798, 9799, 9800, 9801, 9802, 9803, 9804, 9805, 9806, 9807, 9808, 9809, 9810, 9811, 9812, 9813, 9814, 9815, 9816, 9817, 9818, 9819, 9820, 9821, 9822, 9823, 9824, 9825, 9826, 9827, 9828, 9829, 9830, 9831, 9832, 9833, 9834, 9835, 9836, 9837, 9838, 9839, 9840, 9841, 9842, 9843, 9844, 9845, 9846, 9847, 9848, 9849, 9850, 9851, 9852, 9853, 9854, 9855, 9856, 9857, 9858, 9859, 9860, 9861, 9862, 9863, 9864, 9865, 9866, 9867, 9868, 9869, 9870, 9871, 9872, 9873, 9874, 9875, 9876, 9877, 9878, 9879, 9880, 9881, 9882, 9883, 9884, 9885, 9886, 9887, 9888, 9889, 9890, 9891, 9892, 9893, 9894, 9895, 9896, 9897, 9898, 9899, 9900, 9901, 9902, 9903, 9904, 9905, 9906, 9907, 9908, 9909, 9910, 9911, 9912, 9913, 9914, 9915, 9916, 9917, 9918, 9919, 9920, 9921, 9922, 9923, 9924, 9925, 9926, 9927, 9928, 9929, 9930, 9931, 9932, 9933, 9934, 9935, 9936, 9937, 9938, 9939, 9940, 9941, 9942, 9943, 9944, 9945, 9946, 9947, 9948, 9949, 9950, 9951, 9952, 9953, 9954, 9955, 9956, 9957, 9958, 9959, 9960, 9961, 9962, 9963, 9964, 9965, 9966, 9967, 9968, 9969, 9970, 9971, 9972, 9973, 9974, 9975, 9976, 9977, 9978, 9979, 9980, 9981, 9982, 9983, 9984, 9985, 9986, 9987, 9988, 9989, 9990, 9991, 9992, 9993, 9994, 9995, 9996, 9997, 9998, 9999, 10000, 10001, 10002, 10003, 10004, 10005, 10006, 10007, 10008, 10009, 10010, 10011, 10012, 10013, 10014, 10015, 10016, 10017, 10018, 10019, 10020, 10021, 10022, 10023, 10024, 10025, 10026, 10027, 10028, 10029, 10030, 10031, 10032, 10033, 10034, 10035, 10036, 10037, 10038, 10039, 10040, 10041, 10042, 10043, 10044, 10045, 10046, 10047, 10048, 10049, 10050, 10051, 10052, 10053, 10054, 10055, 10056, 10057, 10058, 10059, 10060, 10061, 10062, 10063, 10064, 10065, 10066, 10067, 10068, 10069, 10070, 10071, 10072, 10073, 10074, 10075, 10076, 10077, 10078, 10079, 10080, 10081, 10082, 10083, 10084, 10085, 10086, 10087, 10088, 10089, 10090, 10091, 10092, 10093, 10094, 10095, 10096, 10097, 10098, 10099, 10100, 10101, 10102, 10103, 10104, 10105, 10106, 10107, 10108, 10109, 10110, 10111, 10112, 10113, 10114, 10115, 10116, 10117, 10118, 10119, 10120, 10121, 10122, 10123, 10124, 10125, 10126, 10127, 10128, 10129, 10130, 10131, 10132, 10133, 10134, 10135, 10136, 10137, 10138, 10139, 10140, 10141, 10142, 10143, 10144, 10145, 10146, 10147, 10148, 10149, 10150, 10151, 10152, 10153, 10154, 10155, 10156, 10157, 10158, 10159, 10160, 10161, 10162, 10163, 10164, 10165, 10166, 10167, 10168, 10169, 10170, 10171, 10172, 10173, 10174, 10175, 10176, 10177, 10178, 10179, 10180, 10181, 10182, 10183, 10184, 10185, 10186, 10187, 10188, 10189, 10190, 10191, 10192, 10193, 10194, 10195, 10196, 10197, 10198, 10199, 10200, 10201, 10202, 10203, 10204, 10205, 10206, 10207, 10208, 10209, 10210, 10211, 10212, 10213, 10214, 10215, 10216, 10217, 10218, 10219, 10220, 10221, 10222, 10223, 10224, 10225, 10226, 10227, 10228, 10229, 10230, 10231, 10232, 10233, 10234, 10235, 10236, 10237, 10238, 10239, 10240, 10241, 10242, 10243, 10244, 10245, 10246, 10247, 10248, 10249, 10250, 10251, 10252, 10253, 10254, 10255, 10256, 10257, 10258, 10259, 10260, 10261, 10262, 10263, 10264, 10265, 10266, 10267, 10268, 10269, 10270, 10271, 10272, 10273, 10274, 10275, 10276, 10277, 10278, 10279, 10280, 10281, 10282, 10283, 10284, 10285, 10286, 10287, 10288, 10289, 10290, 10291, 10292, 10293, 10294, 10295, 10296, 10297, 10298, 10299, 10300, 10301, 10302, 10303, 10304, 10305, 10306, 10307, 10308, 10309, 10310, 10311, 10312, 10313, 10314, 10315, 10316, 10317, 10318, 10319, 10320, 10321, 10322, 10323, 10324, 10325, 10326, 10327, 10328, 10329, 10330, 10331, 10332, 10333, 10334, 10335, 10336, 10337, 10338, 10339, 10340, 10341, 10342, 10343, 10344, 10345, 10346, 10347, 10348, 10349, 10350, 10351, 10352, 10353, 10354, 10355, 10356, 10357, 10358, 10359, 10360, 10361, 10362, 10363, 10364, 10365, 10366, 10367, 10368, 10369, 10370, 10371, 10372, 10373, 10374, 10375, 10376, 10377, 10378, 10379, 10380, 10381, 10382, 10383, 10384, 10385, 10386, 10387, 10388, 10389, 10390, 10391, 10392, 10393, 10394, 10395, 10396, 10397, 10398, 10399, 10400, 10401, 10402, 10403, 10404, 10405, 10406, 10407, 10408, 10409, 10410, 10411, 10412, 10413, 10414, 10415, 10416, 10417, 10418, 10419, 10420, 10421, 10422, 10423, 10424, 10425, 10426, 10427, 10428, 10429, 10430, 10431, 10432, 10433, 10434, 10435, 10436, 10437, 10438, 10439, 10440, 10441, 10442, 10443, 10444, 10445, 10446, 10447, 10448, 10449, 10450, 10451, 10452, 10453, 10454, 10455, 10456, 10457, 10458, 10459, 10460, 10461, 10462, 10463, 10464, 10465, 10466, 10467, 10468, 10469, 10470, 10471, 10472, 10473, 10474, 10475, 10476, 10477, 10478, 10479, 10480, 10481, 10482, 10483, 10484, 10485, 10486, 10487, 10488, 10489, 10490, 10491, 10492, 10493, 10494, 10495, 10496, 10497, 10498, 10499, 10500, 10501, 10502, 10503, 10504, 10505, 10506, 10507, 10508, 10509, 10510, 10511, 10512, 10513, 10514, 10515, 10516, 10517, 10518, 10519, 10520, 10521, 10522, 10523, 10524, 10525, 10526, 10527, 10528, 10529, 10530, 10531, 10532, 10533, 10534, 10535, 10536, 10537, 10538, 10539, 10540, 10541, 10542, 10543, 10544, 10545, 10546, 10547, 10548, 10549, 10550, 10551, 10552, 10553, 10554, 10555, 10556, 10557, 10558, 10559, 10560, 10561, 10562, 10563, 10564, 10565, 10566, 10567, 10568, 10569, 10570, 10571, 10572, 10573, 10574, 10575, 10576, 10577, 10578, 10579, 10580, 10581, 10582, 10583, 10584, 10585, 10586, 10587, 10588, 10589, 10590, 10591, 10592, 10593, 10594, 10595, 10596, 10597, 10598, 10599, 10600, 10601, 10602, 10603, 10604, 10605, 10606, 10607, 10608, 10609, 10610, 10611, 10612, 10613, 10614, 10615, 10616, 10617, 10618, 10619, 10620, 10621, 10622, 10623, 10624, 10625, 10626, 10627, 10628, 10629, 10630, 10631, 10632, 10633, 10634, 10635, 10636, 10637, 10638, 10639, 10640, 10641, 10642, 10643, 10644, 10645, 10646, 10647, 10648, 10649, 10650, 10651, 10652, 10653, 10654, 10655, 10656, 10657, 10658, 10659, 10660, 10661, 10662, 10663, 10664, 10665, 10666, 10667, 10668, 10669, 10670, 10671, 10672, 10673, 10674, 10675, 10676, 10677, 10678, 10679, 10680, 10681, 10682, 10683, 10684, 10685, 10686, 10687, 10688, 10689, 10690, 10691, 10692, 10693, 10694, 10695, 10696, 10697, 10698, 10699, 10700, 10701, 10702, 10703, 10704, 10705, 10706, 10707, 10708, 10709, 10710, 10711, 10712, 10713, 10714, 10715, 10716, 10717, 10718, 10719, 10720, 10721, 10722, 10723, 10724, 10725, 10726, 10727, 10728, 10729, 10730, 10731, 10732, 10733, 10734, 10735, 10736, 10737, 10738, 10739, 10740, 10741, 10742, 10743, 10744, 10745, 10746, 10747, 10748, 10749, 10750, 10751, 10752, 10753, 10754, 10755, 10756, 10757, 10758, 10759, 10760, 10761, 10762, 10763, 10764, 10765, 10766, 10767, 10768, 10769, 10770, 10771, 10772, 10773, 10774, 10775, 10776, 10777, 10778, 10779, 10780, 10781, 10782, 10783, 10784, 10785, 10786, 10787, 10788, 10789, 10790, 10791, 10792, 10793, 10794, 10795, 10796, 10797, 10798, 10799, 10800, 10801, 10802, 10803, 10804, 10805, 10806, 10807, 10808, 10809, 10810, 10811, 10812, 10813, 10814, 10815, 10816, 10817, 10818, 10819, 10820, 10821, 10822, 10823, 10824, 10825, 10826, 10827, 10828, 10829, 10830, 10831, 10832, 10833, 10834, 10835, 10836, 10837, 10838, 10839, 10840, 10841, 10842, 10843, 10844, 10845, 10846, 10847, 10848, 10849, 10850, 10851, 10852, 10853, 10854, 10855, 10856, 10857, 10858, 10859, 10860, 10861, 10862, 10863, 10864, 10865, 10866, 10867, 10868, 10869, 10870, 10871, 10872, 10873, 10874, 10875, 10876, 10877, 10878, 10879, 10880, 10881, 10882, 10883, 10884, 10885, 10886, 10887, 10888, 10889, 10890, 10891, 10892, 10893, 10894, 10895, 10896, 10897, 10898, 10899, 10900, 10901, 10902, 10903, 10904, 10905, 10906, 10907, 10908, 10909, 10910, 10911, 10912, 10913, 10914, 10915, 10916, 10917, 10918, 10919, 10920, 10921, 10922, 10923, 10924, 10925, 10926, 10927, 10928, 10929, 10930, 10931, 10932, 10933, 10934, 10935, 10936, 10937, 10938, 10939, 10940, 10941, 10942, 10943, 10944, 10945, 10946, 10947, 10948, 10949, 10950, 10951, 10952, 10953, 10954, 10955, 10956, 10957, 10958, 10959, 10960, 10961, 10962, 10963, 10964, 10965, 10966, 10967, 10968, 10969, 10970, 10971, 10972, 10973, 10974, 10975, 10976, 10977, 10978, 10979, 10980, 10981, 10982, 10983, 10984, 10985, 10986, 10987, 10988, 10989, 10990, 10991, 10992, 10993, 10994, 10995, 10996, 10997, 10998, 10999, 11000, 11001, 11002, 11003, 11004, 11005, 11006, 11007, 11008, 11009, 11010, 11011, 11012, 11013, 11014, 11015, 11016, 11017, 11018, 11019, 11020, 11021, 11022, 11023, 11024, 11025, 11026, 11027, 11028, 11029, 11030, 11031, 11032, 11033, 11034, 11035, 11036, 11037, 11038, 11039, 11040, 11041, 11042, 11043, 11044, 11045, 11046, 11047, 11048, 11049, 11050, 11051, 11052, 11053, 11054, 11055, 11056, 11057, 11058, 11059, 11060, 11061, 11062, 11063, 11064, 11065, 11066, 11067, 11068, 11069, 11070, 11071, 11072, 11073, 11074, 11075, 11076, 11077, 11078, 11079, 11080, 11081, 11082, 11083, 11084, 11085, 11086, 11087, 11088, 11089, 11090, 11091, 11092, 11093, 11094, 11095, 11096, 11097, 11098, 11099, 11100, 11101, 11102, 11103, 11104, 11105, 11106, 11107, 11108, 11109, 11110, 11111, 11112, 11113, 11114, 11115, 11116, 11117, 11118, 11119, 11120, 11121, 11122, 11123, 11124, 11125, 11126, 11127, 11128, 11129, 11130, 11131, 11132, 11133, 11134, 11135, 11136, 11137, 11138, 11139, 11140, 11141, 11142, 11143, 11144, 11145, 11146, 11147, 11148, 11149, 11150, 11151, 11152, 11153, 11154, 11155, 11156, 11157, 11158, 11159, 11160, 11161, 11162, 11163, 11164, 11165, 11166, 11167, 11168, 11169, 11170, 11171, 11172, 11173, 11174, 11175, 11176, 11177, 11178, 11179, 11180, 11181, 11182, 11183, 11184, 11185, 11186, 11187, 11188, 11189, 11190, 11191, 11192, 11193, 11194, 11195, 11196, 11197, 11198, 11199, 11200, 11201, 11202, 11203, 11204, 11205, 11206, 11207, 11208, 11209, 11210, 11211, 11212, 11213, 11214, 11215, 11216, 11217, 11218, 11219, 11220, 11221, 11222, 11223, 11224, 11225, 11226, 11227, 11228, 11229, 11230, 11231, 11232, 11233, 11234, 11235, 11236, 11237, 11238, 11239, 11240, 11241, 11242, 11243, 11244, 11245, 11246, 11247, 11248, 11249, 11250, 11251, 11252, 11253, 11254, 11255, 11256, 11257, 11258, 11259, 11260, 11261, 11262, 11263, 11264, 11265, 11266, 11267, 11268, 11269, 11270, 11271, 11272, 11273, 11274, 11275, 11276, 11277, 11278, 11279, 11280, 11281, 11282, 11283, 11284, 11285, 11286, 11287, 11288, 11289, 11290, 11291, 11292, 11293, 11294, 11295, 11296, 11297, 11298, 11299, 11300, 11301, 11302, 11303, 11304, 11305, 11306, 11307, 11308, 11309, 11310, 11311, 11312, 11313, 11314, 11315, 11316, 11317, 11318, 11319, 11320, 11321, 11322, 11323, 11324, 11325, 11326, 11327, 11328, 11329, 11330, 11331, 11332, 11333, 11334, 11335, 11336, 11337, 11338, 11339, 11340, 11341, 11342, 11343, 11344, 11345, 11346, 11347, 11348, 11349, 11350, 11351, 11352, 11353, 11354, 11355, 11356, 11357, 11358, 11359, 11360, 11361, 11362, 11363, 11364, 11365, 11366, 11367, 11368, 11369, 11370, 11371, 11372, 11373, 11374, 11375, 11376, 11377, 11378, 11379, 11380, 11381, 11382, 11383, 11384, 11385, 11386, 11387, 11388, 11389, 11390, 11391, 11392, 11393, 11394, 11395, 11396, 11397, 11398, 11399, 11400, 11401, 11402, 11403, 11404, 11405, 11406, 11407, 11408, 11409, 11410, 11411, 11412, 11413, 11414, 11415, 11416, 11417, 11418, 11419, 11420, 11421, 11422, 11423, 11424, 11425, 11426, 11427, 11428, 11429, 11430, 11431, 11432, 11433, 11434, 11435, 11436, 11437, 11438, 11439, 11440, 11441, 11442, 11443, 11444, 11445, 11446, 11447, 11448, 11449, 11450, 11451, 11452, 11453, 11454, 11455, 11456, 11457, 11458, 11459, 11460, 11461, 11462, 11463, 11464, 11465, 11466, 11467, 11468, 11469, 11470, 11471, 11472, 11473, 11474, 11475, 11476, 11477, 11478, 11479, 11480, 11481, 11482, 11483, 11484, 11485, 11486, 11487, 11488, 11489, 11490, 11491, 11492, 11493, 11494, 11495, 11496, 11497, 11498, 11499, 11500, 11501, 11502, 11503, 11504, 11505, 11506, 11507, 11508, 11509, 11510, 11511, 11512, 11513, 11514, 11515, 11516, 11517, 11518, 11519, 11520, 11521, 11522, 11523, 11524, 11525, 11526, 11527, 11528, 11529, 11530, 11531, 11532, 11533, 11534, 11535, 11536, 11537, 11538, 11539, 11540, 11541, 11542, 11543, 11544, 11545, 11546, 11547, 11548, 11549, 11550, 11551, 11552, 11553, 11554, 11555, 11556, 11557, 11558, 11559, 11560, 11561, 11562, 11563, 11564, 11565, 11566, 11567, 11568, 11569, 11570, 11571, 11572, 11573, 11574, 11575, 11576, 11577, 11578, 11579, 11580, 11581, 11582, 11583, 11584, 11585, 11586, 11587, 11588, 11589, 11590, 11591, 11592, 11593, 11594, 11595, 11596, 11597, 11598, 11599, 11600, 11601, 11602, 11603, 11604, 11605, 11606, 11607, 11608, 11609, 11610, 11611, 11612, 11613, 11614, 11615, 11616, 11617, 11618, 11619, 11620, 11621, 11622, 11623, 11624, 11625, 11626, 11627, 11628, 11629, 11630, 11631, 11632, 11633, 11634, 11635, 11636, 11637, 11638, 11639, 11640, 11641, 11642, 11643, 11644, 11645, 11646, 11647, 11648, 11649, 11650, 11651, 11652, 11653, 11654, 11655, 11656, 11657, 11658, 11659, 11660, 11661, 11662, 11663, 11664, 11665, 11666, 11667, 11668, 11669, 11670, 11671, 11672, 11673, 11674, 11675, 11676, 11677, 11678, 11679, 11680, 11681, 11682, 11683, 11684, 11685, 11686, 11687, 11688, 11689, 11690, 11691, 11692, 11693, 11694, 11695, 11696, 11697, 11698, 11699, 11700, 11701, 11702, 11703, 11704, 11705, 11706, 11707, 11708, 11709, 11710, 11711, 11712, 11713, 11714, 11715, 11716, 11717, 11718, 11719, 11720, 11721, 11722, 11723, 11724, 11725, 11726, 11727, 11728, 11729, 11730, 11731, 11732, 11733, 11734, 11735, 11736, 11737, 11738, 11739, 11740, 11741, 11742, 11743, 11744, 11745, 11746, 11747, 11748, 11749, 11750, 11751, 11752, 11753, 11754, 11755, 11756, 11757, 11758, 11759, 11760, 11761, 11762, 11763, 11764, 11765, 11766, 11767, 11768, 11769, 11770, 11771, 11772, 11773, 11774, 11775, 11776, 11777, 11778, 11779, 11780, 11781, 11782, 11783, 11784, 11785, 11786, 11787, 11788, 11789, 11790, 11791, 11792, 11793, 11794, 11795, 11796, 11797, 11798, 11799, 11800, 11801, 11802, 11803, 11804, 11805, 11806, 11807, 11808, 11809, 11810, 11811, 11812, 11813, 11814, 11815, 11816, 11817, 11818, 11819, 11820, 11821, 11822, 11823, 11824, 11825, 11826, 11827, 11828, 11829, 11830, 11831, 11832, 11833, 11834, 11835, 11836, 11837, 11838, 11839, 11840, 11841, 11842, 11843, 11844, 11845, 11846, 11847, 11848, 11849, 11850, 11851, 11852, 11853, 11854, 11855, 11856, 11857, 11858, 11859, 11860, 11861, 11862, 11863, 11864, 11865, 11866, 11867, 11868, 11869, 11870, 11871, 11872, 11873, 11874, 11875, 11876, 11877, 11878, 11879, 11880, 11881, 11882, 11883, 11884, 11885, 11886, 11887, 11888, 11889, 11890, 11891, 11892, 11893, 11894, 11895, 11896, 11897, 11898, 11899, 11900, 11901, 11902, 11903, 11904, 11905, 11906, 11907, 11908, 11909, 11910, 11911, 11912, 11913, 11914, 11915, 11916, 11917, 11918, 11919, 11920, 11921, 11922, 11923, 11924, 11925, 11926, 11927, 11928, 11929, 11930, 11931, 11932, 11933, 11934, 11935, 11936, 11937, 11938, 11939, 11940, 11941, 11942, 11943, 11944, 11945, 11946, 11947, 11948, 11949, 11950, 11951, 11952, 11953, 11954, 11955, 11956, 11957, 11958, 11959, 11960, 11961, 11962, 11963, 11964, 11965, 11966, 11967, 11968, 11969, 11970, 11971, 11972, 11973, 11974, 11975, 11976, 11977, 11978, 11979, 11980, 11981, 11982, 11983, 11984, 11985, 11986, 11987, 11988, 11989, 11990, 11991, 11992, 11993, 11994, 11995, 11996, 11997, 11998, 11999, 12000, 12001, 12002, 12003, 12004, 12005, 12006, 12007, 12008, 12009, 12010, 12011, 12012, 12013, 12014, 12015, 12016, 12017, 12018, 12019, 12020, 12021, 12022, 12023, 12024, 12025, 12026, 12027, 12028, 12029, 12030, 12031, 12032, 12033, 12034, 12035, 12036, 12037, 12038, 12039, 12040, 12041, 12042, 12043, 12044, 12045, 12046, 12047, 12048, 12049, 12050, 12051, 12052, 12053, 12054, 12055, 12056, 12057, 12058, 12059, 12060, 12061, 12062, 12063, 12064, 12065, 12066, 12067, 12068, 12069, 12070, 12071, 12072, 12073, 12074, 12075, 12076, 12077, 12078, 12079, 12080, 12081, 12082, 12083, 12084, 12085, 12086, 12087, 12088, 12089, 12090, 12091, 12092, 12093, 12094, 12095, 12096, 12097, 12098, 12099, 12100, 12101, 12102, 12103, 12104, 12105, 12106, 12107, 12108, 12109, 12110, 12111, 12112, 12113, 12114, 12115, 12116, 12117, 12118, 12119, 12120, 12121, 12122, 12123, 12124, 12125, 12126, 12127, 12128, 12129, 12130, 12131, 12132, 12133, 12134, 12135, 12136, 12137, 12138, 12139, 12140, 12141, 12142, 12143, 12144, 12145, 12146, 12147, 12148, 12149, 12150, 12151, 12152, 12153, 12154, 12155, 12156, 12157, 12158, 12159, 12160, 12161, 12162, 12163, 12164, 12165, 12166, 12167, 12168, 12169, 12170, 12171, 12172, 12173, 12174, 12175, 12176, 12177, 12178, 12179, 12180, 12181, 12182, 12183, 12184, 12185, 12186, 12187, 12188, 12189, 12190, 12191, 12192, 12193, 12194, 12195, 12196, 12197, 12198, 12199, 12200, 12201, 12202, 12203, 12204, 12205, 12206, 12207, 12208, 12209, 12210, 12211, 12212, 12213, 12214, 12215, 12216, 12217, 12218, 12219, 12220, 12221, 12222, 12223, 12224, 12225, 12226, 12227, 12228, 12229, 12230, 12231, 12232, 12233, 12234, 12235, 12236, 12237, 12238, 12239, 12240, 12241, 12242, 12243, 12244, 12245, 12246, 12247, 12248, 12249, 12250, 12251, 12252, 12253, 12254, 12255, 12256, 12257, 12258, 12259, 12260, 12261, 12262, 12263, 12264, 12265, 12266, 12267, 12268, 12269, 12270, 12271, 12272, 12273, 12274, 12275, 12276, 12277, 12278, 12279, 12280, 12281, 12282, 12283, 12284, 12285, 12286, 12287, 12288, 12289, 12290, 12291, 12292, 12293, 12294, 12295, 12296, 12297, 12298, 12299, 12300, 12301, 12302, 12303, 12304, 12305, 12306, 12307, 12308, 12309, 12310, 12311, 12312, 12313, 12314, 12315, 12316, 12317, 12318, 12319, 12320, 12321, 12322, 12323, 12324, 12325, 12326, 12327, 12328, 12329, 12330, 12331, 12332, 12333, 12334, 12335, 12336, 12337, 12338, 12339, 12340, 12341, 12342, 12343, 12344, 12345, 12346, 12347, 12348, 12349, 12350, 12351, 12352, 12353, 12354, 12355, 12356, 12357, 12358, 12359, 12360, 12361, 12362, 12363, 12364, 12365, 12366, 12367, 12368, 12369, 12370, 12371, 12372, 12373, 12374, 12375, 12376, 12377, 12378, 12379, 12380, 12381, 12382, 12383, 12384, 12385, 12386, 12387, 12388, 12389, 12390, 12391, 12392, 12393, 12394, 12395, 12396, 12397, 12398, 12399, 12400, 12401, 12402, 12403, 12404, 12405, 12406, 12407, 12408, 12409, 12410, 12411, 12412, 12413, 12414, 12415, 12416, 12417, 12418, 12419, 12420, 12421, 12422, 12423, 12424, 12425, 12426, 12427, 12428, 12429, 12430, 12431, 12432, 12433, 12434, 12435, 12436, 12437, 12438, 12439, 12440, 12441, 12442, 12443, 12444, 12445, 12446, 12447, 12448, 12449, 12450, 12451, 12452, 12453, 12454, 12455, 12456, 12457, 12458, 12459, 12460, 12461, 12462, 12463, 12464, 12465, 12466, 12467, 12468, 12469, 12470, 12471, 12472, 12473, 12474, 12475, 12476, 12477, 12478, 12479, 12480, 12481, 12482, 12483, 12484, 12485, 12486, 12487, 12488, 12489, 12490, 12491, 12492, 12493, 12494, 12495, 12496, 12497, 12498, 12499, 12500, 12501, 12502, 12503, 12504, 12505, 12506, 12507, 12508, 12509, 12510, 12511, 12512, 12513, 12514, 12515, 12516, 12517, 12518, 12519, 12520, 12521, 12522, 12523, 12524, 12525, 12526, 12527, 12528, 12529, 12530, 12531, 12532, 12533, 12534, 12535, 12536, 12537, 12538, 12539, 12540, 12541, 12542, 12543, 12544, 12545, 12546, 12547, 12548, 12549, 12550, 12551, 12552, 12553, 12554, 12555, 12556, 12557, 12558, 12559, 12560, 12561, 12562, 12563, 12564, 12565, 12566, 12567, 12568, 12569, 12570, 12571, 12572, 12573, 12574, 12575, 12576, 12577, 12578, 12579, 12580, 12581, 12582, 12583, 12584, 12585, 12586, 12587, 12588, 12589, 12590, 12591, 12592, 12593, 12594, 12595, 12596, 12597, 12598, 12599, 12600, 12601, 12602, 12603, 12604, 12605, 12606, 12607, 12608, 12609, 12610, 12611, 12612, 12613, 12614, 12615, 12616, 12617, 12618, 12619, 12620, 12621, 12622, 12623, 12624, 12625, 12626, 12627, 12628, 12629, 12630, 12631, 12632, 12633, 12634, 12635, 12636, 12637, 12638, 12639, 12640, 12641, 12642, 12643, 12644, 12645, 12646, 12647, 12648, 12649, 12650, 12651, 12652, 12653, 12654, 12655, 12656, 12657, 12658, 12659, 12660, 12661, 12662, 12663, 12664, 12665, 12666, 12667, 12668, 12669, 12670, 12671, 12672, 12673, 12674, 12675, 12676, 12677, 12678, 12679, 12680, 12681, 12682, 12683, 12684, 12685, 12686, 12687, 12688, 12689, 12690, 12691, 12692, 12693, 12694, 12695, 12696, 12697, 12698, 12699, 12700, 12701, 12702, 12703, 12704, 12705, 12706, 12707, 12708, 12709, 12710, 12711, 12712, 12713, 12714, 12715, 12716, 12717, 12718, 12719, 12720, 12721, 12722, 12723, 12724, 12725, 12726, 12727, 12728, 12729, 12730, 12731, 12732, 12733, 12734, 12735, 12736, 12737, 12738, 12739, 12740, 12741, 12742, 12743, 12744, 12745, 12746, 12747, 12748, 12749, 12750, 12751, 12752, 12753, 12754, 12755, 12756, 12757, 12758, 12759, 12760, 12761, 12762, 12763, 12764, 12765, 12766, 12767, 12768, 12769, 12770, 12771, 12772, 12773, 12774, 12775, 12776, 12777, 12778, 12779, 12780, 12781, 12782, 12783, 12784, 12785, 12786, 12787, 12788, 12789, 12790, 12791, 12792, 12793, 12794, 12795, 12796, 12797, 12798, 12799, 12800, 12801, 12802, 12803, 12804, 12805, 12806, 12807, 12808, 12809, 12810, 12811, 12812, 12813, 12814, 12815, 12816, 12817, 12818, 12819, 12820, 12821, 12822, 12823, 12824, 12825, 12826, 12827, 12828, 12829, 12830, 12831, 12832, 12833, 12834, 12835, 12836, 12837, 12838, 12839, 12840, 12841, 12842, 12843, 12844, 12845, 12846, 12847, 12848, 12849, 12850, 12851, 12852, 12853, 12854, 12855, 12856, 12857, 12858, 12859, 12860, 12861, 12862, 12863, 12864, 12865, 12866, 12867, 12868, 12869, 12870, 12871, 12872, 12873, 12874, 12875, 12876, 12877, 12878, 12879, 12880, 12881, 12882, 12883, 12884, 12885, 12886, 12887, 12888, 12889, 12890, 12891, 12892, 12893, 12894, 12895, 12896, 12897, 12898, 12899, 12900, 12901, 12902, 12903, 12904, 12905, 12906, 12907, 12908, 12909, 12910, 12911, 12912, 12913, 12914, 12915, 12916, 12917, 12918, 12919, 12920, 12921, 12922, 12923, 12924, 12925, 12926, 12927, 12928, 12929, 12930, 12931, 12932, 12933, 12934, 12935, 12936, 12937, 12938, 12939, 12940, 12941, 12942, 12943, 12944, 12945, 12946, 12947, 12948, 12949, 12950, 12951, 12952, 12953, 12954, 12955, 12956, 12957, 12958, 12959, 12960, 12961, 12962, 12963, 12964, 12965, 12966, 12967, 12968, 12969, 12970, 12971, 12972, 12973, 12974, 12975, 12976, 12977, 12978, 12979, 12980, 12981, 12982, 12983, 12984, 12985, 12986, 12987, 12988, 12989, 12990, 12991, 12992, 12993, 12994, 12995, 12996, 12997, 12998, 12999, 13000, 13001, 13002, 13003, 13004, 13005, 13006, 13007, 13008, 13009, 13010, 13011, 13012, 13013, 13014, 13015, 13016, 13017, 13018, 13019, 13020, 13021, 13022, 13023, 13024, 13025, 13026, 13027, 13028, 13029, 13030, 13031, 13032, 13033, 13034, 13035, 13036, 13037, 13038, 13039, 13040, 13041, 13042, 13043, 13044, 13045, 13046, 13047, 13048, 13049, 13050, 13051, 13052, 13053, 13054, 13055, 13056, 13057, 13058, 13059, 13060, 13061, 13062, 13063, 13064, 13065, 13066, 13067, 13068, 13069, 13070, 13071, 13072, 13073, 13074, 13075, 13076, 13077, 13078, 13079, 13080, 13081, 13082, 13083, 13084, 13085, 13086, 13087, 13088, 13089, 13090, 13091, 13092, 13093, 13094, 13095, 13096, 13097, 13098, 13099, 13100, 13101, 13102, 13103, 13104, 13105, 13106, 13107, 13108, 13109, 13110, 13111, 13112, 13113, 13114, 13115, 13116, 13117, 13118, 13119, 13120, 13121, 13122, 13123, 13124, 13125, 13126, 13127, 13128, 13129, 13130, 13131, 13132, 13133, 13134, 13135, 13136, 13137, 13138, 13139, 13140, 13141, 13142, 13143, 13144, 13145, 13146, 13147, 13148, 13149, 13150, 13151, 13152, 13153, 13154, 13155, 13156, 13157, 13158, 13159, 13160, 13161, 13162, 13163, 13164, 13165, 13166, 13167, 13168, 13169, 13170, 13171, 13172, 13173, 13174, 13175, 13176, 13177, 13178, 13179, 13180, 13181, 13182, 13183, 13184, 13185, 13186, 13187, 13188, 13189, 13190, 13191, 13192, 13193, 13194, 13195, 13196, 13197, 13198, 13199, 13200, 13201, 13202, 13203, 13204, 13205, 13206, 13207, 13208, 13209, 13210, 13211, 13212, 13213, 13214, 13215, 13216, 13217, 13218, 13219, 13220, 13221, 13222, 13223, 13224, 13225, 13226, 13227, 13228, 13229, 13230, 13231, 13232, 13233, 13234, 13235, 13236, 13237, 13238, 13239, 13240, 13241, 13242, 13243, 13244, 13245, 13246, 13247, 13248, 13249, 13250, 13251, 13252, 13253, 13254, 13255, 13256, 13257, 13258, 13259, 13260, 13261, 13262, 13263, 13264, 13265, 13266, 13267, 13268, 13269, 13270, 13271, 13272, 13273, 13274, 13275, 13276, 13277, 13278, 13279, 13280, 13281, 13282, 13283, 13284, 13285, 13286, 13287, 13288, 13289, 13290, 13291, 13292, 13293, 13294, 13295, 13296, 13297, 13298, 13299, 13300, 13301, 13302, 13303, 13304, 13305, 13306, 13307, 13308, 13309, 13310, 13311, 13312, 13313, 13314, 13315, 13316, 13317, 13318, 13319, 13320, 13321, 13322, 13323, 13324, 13325, 13326, 13327, 13328, 13329, 13330, 13331, 13332, 13333, 13334, 13335, 13336, 13337, 13338, 13339, 13340, 13341, 13342, 13343, 13344, 13345, 13346, 13347, 13348, 13349, 13350, 13351, 13352, 13353, 13354, 13355, 13356, 13357, 13358, 13359, 13360, 13361, 13362, 13363, 13364, 13365, 13366, 13367, 13368, 13369, 13370, 13371, 13372, 13373, 13374, 13375, 13376, 13377, 13378, 13379, 13380, 13381, 13382, 13383, 13384, 13385, 13386, 13387, 13388, 13389, 13390, 13391, 13392, 13393, 13394, 13395, 13396, 13397, 13398, 13399, 13400, 13401, 13402, 13403, 13404, 13405, 13406, 13407, 13408, 13409, 13410, 13411, 13412, 13413, 13414, 13415, 13416, 13417, 13418, 13419, 13420, 13421, 13422, 13423, 13424, 13425, 13426, 13427, 13428, 13429, 13430, 13431, 13432, 13433, 13434, 13435, 13436, 13437, 13438, 13439, 13440, 13441, 13442, 13443, 13444, 13445, 13446, 13447, 13448, 13449, 13450, 13451, 13452, 13453, 13454, 13455, 13456, 13457, 13458, 13459, 13460, 13461, 13462, 13463, 13464, 13465, 13466, 13467, 13468, 13469, 13470, 13471, 13472, 13473, 13474, 13475, 13476, 13477, 13478, 13479, 13480, 13481, 13482, 13483, 13484, 13485, 13486, 13487, 13488, 13489, 13490, 13491, 13492, 13493, 13494, 13495, 13496, 13497, 13498, 13499, 13500, 13501, 13502, 13503, 13504, 13505, 13506, 13507, 13508, 13509, 13510, 13511, 13512, 13513, 13514, 13515, 13516, 13517, 13518, 13519, 13520, 13521, 13522, 13523, 13524, 13525, 13526, 13527, 13528, 13529, 13530, 13531, 13532, 13533, 13534, 13535, 13536, 13537, 13538, 13539, 13540, 13541, 13542, 13543, 13544, 13545, 13546, 13547, 13548, 13549, 13550, 13551, 13552, 13553, 13554, 13555, 13556, 13557, 13558, 13559, 13560, 13561, 13562, 13563, 13564, 13565, 13566, 13567, 13568, 13569, 13570, 13571, 13572, 13573, 13574, 13575, 13576, 13577, 13578, 13579, 13580, 13581, 13582, 13583, 13584, 13585, 13586, 13587, 13588, 13589, 13590, 13591, 13592, 13593, 13594, 13595, 13596, 13597, 13598, 13599, 13600, 13601, 13602, 13603, 13604, 13605, 13606, 13607, 13608, 13609, 13610, 13611, 13612, 13613, 13614, 13615, 13616, 13617, 13618, 13619, 13620, 13621, 13622, 13623, 13624, 13625, 13626, 13627, 13628, 13629, 13630, 13631, 13632, 13633, 13634, 13635, 13636, 13637, 13638, 13639, 13640, 13641, 13642, 13643, 13644, 13645, 13646, 13647, 13648, 13649, 13650, 13651, 13652, 13653, 13654, 13655, 13656, 13657, 13658, 13659, 13660, 13661, 13662, 13663, 13664, 13665, 13666, 13667, 13668, 13669, 13670, 13671, 13672, 13673, 13674, 13675, 13676, 13677, 13678, 13679, 13680, 13681, 13682, 13683, 13684, 13685, 13686, 13687, 13688, 13689, 13690, 13691, 13692, 13693, 13694, 13695, 13696, 13697, 13698, 13699, 13700, 13701, 13702, 13703, 13704, 13705, 13706, 13707, 13708, 13709, 13710, 13711, 13712, 13713, 13714, 13715, 13716, 13717, 13718, 13719, 13720, 13721, 13722, 13723, 13724, 13725, 13726, 13727, 13728, 13729, 13730, 13731, 13732, 13733, 13734, 13735, 13736, 13737, 13738, 13739, 13740, 13741, 13742, 13743, 13744, 13745, 13746, 13747, 13748, 13749, 13750, 13751, 13752, 13753, 13754, 13755, 13756, 13757, 13758, 13759, 13760, 13761, 13762, 13763, 13764, 13765, 13766, 13767, 13768, 13769, 13770, 13771, 13772, 13773, 13774, 13775, 13776, 13777, 13778, 13779, 13780, 13781, 13782, 13783, 13784, 13785, 13786, 13787, 13788, 13789, 13790, 13791, 13792, 13793, 13794, 13795, 13796, 13797, 13798, 13799, 13800, 13801, 13802, 13803, 13804, 13805, 13806, 13807, 13808, 13809, 13810, 13811, 13812, 13813, 13814, 13815, 13816, 13817, 13818, 13819, 13820, 13821, 13822, 13823, 13824, 13825, 13826, 13827, 13828, 13829, 13830, 13831, 13832, 13833, 13834, 13835, 13836, 13837, 13838, 13839, 13840, 13841, 13842, 13843, 13844, 13845, 13846, 13847, 13848, 13849, 13850, 13851, 13852, 13853, 13854, 13855, 13856, 13857, 13858, 13859, 13860, 13861, 13862, 13863, 13864, 13865, 13866, 13867, 13868, 13869, 13870, 13871, 13872, 13873, 13874, 13875, 13876, 13877, 13878, 13879, 13880, 13881, 13882, 13883, 13884, 13885, 13886, 13887, 13888, 13889, 13890, 13891, 13892, 13893, 13894, 13895, 13896, 13897, 13898, 13899, 13900, 13901, 13902, 13903, 13904, 13905, 13906, 13907, 13908, 13909, 13910, 13911, 13912, 13913, 13914, 13915, 13916, 13917, 13918, 13919, 13920, 13921, 13922, 13923, 13924, 13925, 13926, 13927, 13928, 13929, 13930, 13931, 13932, 13933, 13934, 13935, 13936, 13937, 13938, 13939, 13940, 13941, 13942, 13943, 13944, 13945, 13946, 13947, 13948, 13949, 13950, 13951, 13952, 13953, 13954, 13955, 13956, 13957, 13958, 13959, 13960, 13961, 13962, 13963, 13964, 13965, 13966, 13967, 13968, 13969, 13970, 13971, 13972, 13973, 13974, 13975, 13976, 13977, 13978, 13979, 13980, 13981, 13982, 13983, 13984, 13985, 13986, 13987, 13988, 13989, 13990, 13991, 13992, 13993, 13994, 13995, 13996, 13997, 13998, 13999, 14000, 14001, 14002, 14003, 14004, 14005, 14006, 14007, 14008, 14009, 14010, 14011, 14012, 14013, 14014, 14015, 14016, 14017, 14018, 14019, 14020, 14021, 14022, 14023, 14024, 14025, 14026, 14027, 14028, 14029, 14030, 14031, 14032, 14033, 14034, 14035, 14036, 14037, 14038, 14039, 14040, 14041, 14042, 14043, 14044, 14045, 14046, 14047, 14048, 14049, 14050, 14051, 14052, 14053, 14054, 14055, 14056, 14057, 14058, 14059, 14060, 14061, 14062, 14063, 14064, 14065, 14066, 14067, 14068, 14069, 14070, 14071, 14072, 14073, 14074, 14075, 14076, 14077, 14078, 14079, 14080, 14081, 14082, 14083, 14084, 14085, 14086, 14087, 14088, 14089, 14090, 14091, 14092, 14093, 14094, 14095, 14096, 14097, 14098, 14099, 14100, 14101, 14102, 14103, 14104, 14105, 14106, 14107, 14108, 14109, 14110, 14111, 14112, 14113, 14114, 14115, 14116, 14117, 14118, 14119, 14120, 14121, 14122, 14123, 14124, 14125, 14126, 14127, 14128, 14129, 14130, 14131, 14132, 14133, 14134, 14135, 14136, 14137, 14138, 14139, 14140, 14141, 14142, 14143, 14144, 14145, 14146, 14147, 14148, 14149, 14150, 14151, 14152, 14153, 14154, 14155, 14156, 14157, 14158, 14159, 14160, 14161, 14162, 14163, 14164, 14165, 14166, 14167, 14168, 14169, 14170, 14171, 14172, 14173, 14174, 14175, 14176, 14177, 14178, 14179, 14180, 14181, 14182, 14183, 14184, 14185, 14186, 14187, 14188, 14189, 14190, 14191, 14192, 14193, 14194, 14195, 14196, 14197, 14198, 14199, 14200, 14201, 14202, 14203, 14204, 14205, 14206, 14207, 14208, 14209, 14210, 14211, 14212, 14213, 14214, 14215, 14216, 14217, 14218, 14219, 14220, 14221, 14222, 14223, 14224, 14225, 14226, 14227, 14228, 14229, 14230, 14231, 14232, 14233, 14234, 14235, 14236, 14237, 14238, 14239, 14240, 14241, 14242, 14243, 14244, 14245, 14246, 14247, 14248, 14249, 14250, 14251, 14252, 14253, 14254, 14255, 14256, 14257, 14258, 14259, 14260, 14261, 14262, 14263, 14264, 14265, 14266, 14267, 14268, 14269, 14270, 14271, 14272, 14273, 14274, 14275, 14276, 14277, 14278, 14279, 14280, 14281, 14282, 14283, 14284, 14285, 14286, 14287, 14288, 14289, 14290, 14291, 14292, 14293, 14294, 14295, 14296, 14297, 14298, 14299, 14300, 14301, 14302, 14303, 14304, 14305, 14306, 14307, 14308, 14309, 14310, 14311, 14312, 14313, 14314, 14315, 14316, 14317, 14318, 14319, 14320, 14321, 14322, 14323, 14324, 14325, 14326, 14327, 14328, 14329, 14330, 14331, 14332, 14333, 14334, 14335, 14336, 14337, 14338, 14339, 14340, 14341, 14342, 14343, 14344, 14345, 14346, 14347, 14348, 14349, 14350, 14351, 14352, 14353, 14354, 14355, 14356, 14357, 14358, 14359, 14360, 14361, 14362, 14363, 14364, 14365, 14366, 14367, 14368, 14369, 14370, 14371, 14372, 14373, 14374, 14375, 14376, 14377, 14378, 14379, 14380, 14381, 14382, 14383, 14384, 14385, 14386, 14387, 14388, 14389, 14390, 14391, 14392, 14393, 14394, 14395, 14396, 14397, 14398, 14399, 14400, 14401, 14402, 14403, 14404, 14405, 14406, 14407, 14408, 14409, 14410, 14411, 14412, 14413, 14414, 14415, 14416, 14417, 14418, 14419, 14420, 14421, 14422, 14423, 14424, 14425, 14426, 14427, 14428, 14429, 14430, 14431, 14432, 14433, 14434, 14435, 14436, 14437, 14438, 14439, 14440, 14441, 14442, 14443, 14444, 14445, 14446, 14447, 14448, 14449, 14450, 14451, 14452, 14453, 14454, 14455, 14456, 14457, 14458, 14459, 14460, 14461, 14462, 14463, 14464, 14465, 14466, 14467, 14468, 14469, 14470, 14471, 14472, 14473, 14474, 14475, 14476, 14477, 14478, 14479, 14480, 14481, 14482, 14483, 14484, 14485, 14486, 14487, 14488, 14489, 14490, 14491, 14492, 14493, 14494, 14495, 14496, 14497, 14498, 14499, 14500, 14501, 14502, 14503, 14504, 14505, 14506, 14507, 14508, 14509, 14510, 14511, 14512, 14513, 14514, 14515, 14516, 14517, 14518, 14519, 14520, 14521, 14522, 14523, 14524, 14525, 14526, 14527, 14528, 14529, 14530, 14531, 14532, 14533, 14534, 14535, 14536, 14537, 14538, 14539, 14540, 14541, 14542, 14543, 14544, 14545, 14546, 14547, 14548, 14549, 14550, 14551, 14552, 14553, 14554, 14555, 14556, 14557, 14558, 14559, 14560, 14561, 14562, 14563, 14564, 14565, 14566, 14567, 14568, 14569, 14570, 14571, 14572, 14573, 14574, 14575, 14576, 14577, 14578, 14579, 14580, 14581, 14582, 14583, 14584, 14585, 14586, 14587, 14588, 14589, 14590, 14591, 14592, 14593, 14594, 14595, 14596, 14597, 14598, 14599, 14600, 14601, 14602, 14603, 14604, 14605, 14606, 14607, 14608, 14609, 14610, 14611, 14612, 14613, 14614, 14615, 14616, 14617, 14618, 14619, 14620, 14621, 14622, 14623, 14624, 14625, 14626, 14627, 14628, 14629, 14630, 14631, 14632, 14633, 14634, 14635, 14636, 14637, 14638, 14639, 14640, 14641, 14642, 14643, 14644, 14645, 14646, 14647, 14648, 14649, 14650, 14651, 14652, 14653, 14654, 14655, 14656, 14657, 14658, 14659, 14660, 14661, 14662, 14663, 14664, 14665, 14666, 14667, 14668, 14669, 14670, 14671, 14672, 14673, 14674, 14675, 14676, 14677, 14678, 14679, 14680, 14681, 14682, 14683, 14684, 14685, 14686, 14687, 14688, 14689, 14690, 14691, 14692, 14693, 14694, 14695, 14696, 14697, 14698, 14699, 14700, 14701, 14702, 14703, 14704, 14705, 14706, 14707, 14708, 14709, 14710, 14711, 14712, 14713, 14714, 14715, 14716, 14717, 14718, 14719, 14720, 14721, 14722, 14723, 14724, 14725, 14726, 14727, 14728, 14729, 14730, 14731, 14732, 14733, 14734, 14735, 14736, 14737, 14738, 14739, 14740, 14741, 14742, 14743, 14744, 14745, 14746, 14747, 14748, 14749, 14750, 14751, 14752, 14753, 14754, 14755, 14756, 14757, 14758, 14759, 14760, 14761, 14762, 14763, 14764, 14765, 14766, 14767, 14768, 14769, 14770, 14771, 14772, 14773, 14774, 14775, 14776, 14777, 14778, 14779, 14780, 14781, 14782, 14783, 14784, 14785, 14786, 14787, 14788, 14789, 14790, 14791, 14792, 14793, 14794, 14795, 14796, 14797, 14798, 14799, 14800, 14801, 14802, 14803, 14804, 14805, 14806, 14807, 14808, 14809, 14810, 14811, 14812, 14813, 14814, 14815, 14816, 14817, 14818, 14819, 14820, 14821, 14822, 14823, 14824, 14825, 14826, 14827, 14828, 14829, 14830, 14831, 14832, 14833, 14834, 14835, 14836, 14837, 14838, 14839, 14840, 14841, 14842, 14843, 14844, 14845, 14846, 14847, 14848, 14849, 14850, 14851, 14852, 14853, 14854, 14855, 14856, 14857, 14858, 14859, 14860, 14861, 14862, 14863, 14864, 14865, 14866, 14867, 14868, 14869, 14870, 14871, 14872, 14873, 14874, 14875, 14876, 14877, 14878, 14879, 14880, 14881, 14882, 14883, 14884, 14885, 14886, 14887, 14888, 14889, 14890, 14891, 14892, 14893, 14894, 14895, 14896, 14897, 14898, 14899, 14900, 14901, 14902, 14903, 14904, 14905, 14906, 14907, 14908, 14909, 14910, 14911, 14912, 14913, 14914, 14915, 14916, 14917, 14918, 14919, 14920, 14921, 14922, 14923, 14924, 14925, 14926, 14927, 14928, 14929, 14930, 14931, 14932, 14933, 14934, 14935, 14936, 14937, 14938, 14939, 14940, 14941, 14942, 14943, 14944, 14945, 14946, 14947, 14948, 14949, 14950, 14951, 14952, 14953, 14954, 14955, 14956, 14957, 14958, 14959, 14960, 14961, 14962, 14963, 14964, 14965, 14966, 14967, 14968, 14969, 14970, 14971, 14972, 14973, 14974, 14975, 14976, 14977, 14978, 14979, 14980, 14981, 14982, 14983, 14984, 14985, 14986, 14987, 14988, 14989, 14990, 14991, 14992, 14993, 14994, 14995, 14996, 14997, 14998, 14999, 15000, 15001, 15002, 15003, 15004, 15005, 15006, 15007, 15008, 15009, 15010, 15011, 15012, 15013, 15014, 15015, 15016, 15017, 15018, 15019, 15020, 15021, 15022, 15023, 15024, 15025, 15026, 15027, 15028, 15029, 15030, 15031, 15032, 15033, 15034, 15035, 15036, 15037, 15038, 15039, 15040, 15041, 15042, 15043, 15044, 15045, 15046, 15047, 15048, 15049, 15050, 15051, 15052, 15053, 15054, 15055, 15056, 15057, 15058, 15059, 15060, 15061, 15062, 15063, 15064, 15065, 15066, 15067, 15068, 15069, 15070, 15071, 15072, 15073, 15074, 15075, 15076, 15077, 15078, 15079, 15080, 15081, 15082, 15083, 15084, 15085, 15086, 15087, 15088, 15089, 15090, 15091, 15092, 15093, 15094, 15095, 15096, 15097, 15098, 15099, 15100, 15101, 15102, 15103, 15104, 15105, 15106, 15107, 15108, 15109, 15110, 15111, 15112, 15113, 15114, 15115, 15116, 15117, 15118, 15119, 15120, 15121, 15122, 15123, 15124, 15125, 15126, 15127, 15128, 15129, 15130, 15131, 15132, 15133, 15134, 15135, 15136, 15137, 15138, 15139, 15140, 15141, 15142, 15143, 15144, 15145, 15146, 15147, 15148, 15149, 15150, 15151, 15152, 15153, 15154, 15155, 15156, 15157, 15158, 15159, 15160, 15161, 15162, 15163, 15164, 15165, 15166, 15167, 15168, 15169, 15170, 15171, 15172, 15173, 15174, 15175, 15176, 15177, 15178, 15179, 15180, 15181, 15182, 15183, 15184, 15185, 15186, 15187, 15188, 15189, 15190, 15191, 15192, 15193, 15194, 15195, 15196, 15197, 15198, 15199, 15200, 15201, 15202, 15203, 15204, 15205, 15206, 15207, 15208, 15209, 15210, 15211, 15212, 15213, 15214, 15215, 15216, 15217, 15218, 15219, 15220, 15221, 15222, 15223, 15224, 15225, 15226, 15227, 15228, 15229, 15230, 15231, 15232, 15233, 15234, 15235, 15236, 15237, 15238, 15239, 15240, 15241, 15242, 15243, 15244, 15245, 15246, 15247, 15248, 15249, 15250, 15251, 15252, 15253, 15254, 15255, 15256, 15257, 15258, 15259, 15260, 15261, 15262, 15263, 15264, 15265, 15266, 15267, 15268, 15269, 15270, 15271, 15272, 15273, 15274, 15275, 15276, 15277, 15278, 15279, 15280, 15281, 15282, 15283, 15284, 15285, 15286, 15287, 15288, 15289, 15290, 15291, 15292, 15293, 15294, 15295, 15296, 15297, 15298, 15299, 15300, 15301, 15302, 15303, 15304, 15305, 15306, 15307, 15308, 15309, 15310, 15311, 15312, 15313, 15314, 15315, 15316, 15317, 15318, 15319, 15320, 15321, 15322, 15323, 15324, 15325, 15326, 15327, 15328, 15329, 15330, 15331, 15332, 15333, 15334, 15335, 15336, 15337, 15338, 15339, 15340, 15341, 15342, 15343, 15344, 15345, 15346, 15347, 15348, 15349, 15350, 15351, 15352, 15353, 15354, 15355, 15356, 15357, 15358, 15359, 15360, 15361, 15362, 15363, 15364, 15365, 15366, 15367, 15368, 15369, 15370, 15371, 15372, 15373, 15374, 15375, 15376, 15377, 15378, 15379, 15380, 15381, 15382, 15383, 15384, 15385, 15386, 15387, 15388, 15389, 15390, 15391, 15392, 15393, 15394, 15395, 15396, 15397, 15398, 15399, 15400, 15401, 15402, 15403, 15404, 15405, 15406, 15407, 15408, 15409, 15410, 15411, 15412, 15413, 15414, 15415, 15416, 15417, 15418, 15419, 15420, 15421, 15422, 15423, 15424, 15425, 15426, 15427, 15428, 15429, 15430, 15431, 15432, 15433, 15434, 15435, 15436, 15437, 15438, 15439, 15440, 15441, 15442, 15443, 15444, 15445, 15446, 15447, 15448, 15449, 15450, 15451, 15452, 15453, 15454, 15455, 15456, 15457, 15458, 15459, 15460, 15461, 15462, 15463, 15464, 15465, 15466, 15467, 15468, 15469, 15470, 15471, 15472, 15473, 15474, 15475, 15476, 15477, 15478, 15479, 15480, 15481, 15482, 15483, 15484, 15485, 15486, 15487, 15488, 15489, 15490, 15491, 15492, 15493, 15494, 15495, 15496, 15497, 15498, 15499, 15500, 15501, 15502, 15503, 15504, 15505, 15506, 15507, 15508, 15509, 15510, 15511, 15512, 15513, 15514, 15515, 15516, 15517, 15518, 15519, 15520, 15521, 15522, 15523, 15524, 15525, 15526, 15527, 15528, 15529, 15530, 15531, 15532, 15533, 15534, 15535, 15536, 15537, 15538, 15539, 15540, 15541, 15542, 15543, 15544, 15545, 15546, 15547, 15548, 15549, 15550, 15551, 15552, 15553, 15554, 15555, 15556, 15557, 15558, 15559, 15560, 15561, 15562, 15563, 15564, 15565, 15566, 15567, 15568, 15569, 15570, 15571, 15572, 15573, 15574, 15575, 15576, 15577, 15578, 15579, 15580, 15581, 15582, 15583, 15584, 15585, 15586, 15587, 15588, 15589, 15590, 15591, 15592, 15593, 15594, 15595, 15596, 15597, 15598, 15599, 15600, 15601, 15602, 15603, 15604, 15605, 15606, 15607, 15608, 15609, 15610, 15611, 15612, 15613, 15614, 15615, 15616, 15617, 15618, 15619, 15620, 15621, 15622, 15623, 15624, 15625, 15626, 15627, 15628, 15629, 15630, 15631, 15632, 15633, 15634, 15635, 15636, 15637, 15638, 15639, 15640, 15641, 15642, 15643, 15644, 15645, 15646, 15647, 15648, 15649, 15650, 15651, 15652, 15653, 15654, 15655, 15656, 15657, 15658, 15659, 15660, 15661, 15662, 15663, 15664, 15665, 15666, 15667, 15668, 15669, 15670, 15671, 15672, 15673, 15674, 15675, 15676, 15677, 15678, 15679, 15680, 15681, 15682, 15683, 15684, 15685, 15686, 15687, 15688, 15689, 15690, 15691, 15692, 15693, 15694, 15695, 15696, 15697, 15698, 15699, 15700, 15701, 15702, 15703, 15704, 15705, 15706, 15707, 15708, 15709, 15710, 15711, 15712, 15713, 15714, 15715, 15716, 15717, 15718, 15719, 15720, 15721, 15722, 15723, 15724, 15725, 15726, 15727, 15728, 15729, 15730, 15731, 15732, 15733, 15734, 15735, 15736, 15737, 15738, 15739, 15740, 15741, 15742, 15743, 15744, 15745, 15746, 15747, 15748, 15749, 15750, 15751, 15752, 15753, 15754, 15755, 15756, 15757, 15758, 15759, 15760, 15761, 15762, 15763, 15764, 15765, 15766, 15767, 15768, 15769, 15770, 15771, 15772, 15773, 15774, 15775, 15776, 15777, 15778, 15779, 15780, 15781, 15782, 15783, 15784, 15785, 15786, 15787, 15788, 15789, 15790, 15791, 15792, 15793, 15794, 15795, 15796, 15797, 15798, 15799, 15800, 15801, 15802, 15803, 15804, 15805, 15806, 15807, 15808, 15809, 15810, 15811, 15812, 15813, 15814, 15815, 15816, 15817, 15818, 15819, 15820, 15821, 15822, 15823, 15824, 15825, 15826, 15827, 15828, 15829, 15830, 15831, 15832, 15833, 15834, 15835, 15836, 15837, 15838, 15839, 15840, 15841, 15842, 15843, 15844, 15845, 15846, 15847, 15848, 15849, 15850, 15851, 15852, 15853, 15854, 15855, 15856, 15857, 15858, 15859, 15860, 15861, 15862, 15863, 15864, 15865, 15866, 15867, 15868, 15869, 15870, 15871, 15872, 15873, 15874, 15875, 15876, 15877, 15878, 15879, 15880, 15881, 15882, 15883, 15884, 15885, 15886, 15887, 15888, 15889, 15890, 15891, 15892, 15893, 15894, 15895, 15896, 15897, 15898, 15899, 15900, 15901, 15902, 15903, 15904, 15905, 15906, 15907, 15908, 15909, 15910, 15911, 15912, 15913, 15914, 15915, 15916, 15917, 15918, 15919, 15920, 15921, 15922, 15923, 15924, 15925, 15926, 15927, 15928, 15929, 15930, 15931, 15932, 15933, 15934, 15935, 15936, 15937, 15938, 15939, 15940, 15941, 15942, 15943, 15944, 15945, 15946, 15947, 15948, 15949, 15950, 15951, 15952, 15953, 15954, 15955, 15956, 15957, 15958, 15959, 15960, 15961, 15962, 15963, 15964, 15965, 15966, 15967, 15968, 15969, 15970, 15971, 15972, 15973, 15974, 15975, 15976, 15977, 15978, 15979, 15980, 15981, 15982, 15983, 15984, 15985, 15986, 15987, 15988, 15989, 15990, 15991, 15992, 15993, 15994, 15995, 15996, 15997, 15998, 15999, 16000, 16001, 16002, 16003, 16004, 16005, 16006, 16007, 16008, 16009, 16010, 16011, 16012, 16013, 16014, 16015, 16016, 16017, 16018, 16019, 16020, 16021, 16022, 16023, 16024, 16025, 16026, 16027, 16028, 16029, 16030, 16031, 16032, 16033, 16034, 16035, 16036, 16037, 16038, 16039, 16040, 16041, 16042, 16043, 16044, 16045, 16046, 16047, 16048, 16049, 16050, 16051, 16052, 16053, 16054, 16055, 16056, 16057, 16058, 16059, 16060, 16061, 16062, 16063, 16064, 16065, 16066, 16067, 16068, 16069, 16070, 16071, 16072, 16073, 16074, 16075, 16076, 16077, 16078, 16079, 16080, 16081, 16082, 16083, 16084, 16085, 16086, 16087, 16088, 16089, 16090, 16091, 16092, 16093, 16094, 16095, 16096, 16097, 16098, 16099, 16100, 16101, 16102, 16103, 16104, 16105, 16106, 16107, 16108, 16109, 16110, 16111, 16112, 16113, 16114, 16115, 16116, 16117, 16118, 16119, 16120, 16121, 16122, 16123, 16124, 16125, 16126, 16127, 16128, 16129, 16130, 16131, 16132, 16133, 16134, 16135, 16136, 16137, 16138, 16139, 16140, 16141, 16142, 16143, 16144, 16145, 16146, 16147, 16148, 16149, 16150, 16151, 16152, 16153, 16154, 16155, 16156, 16157, 16158, 16159, 16160, 16161, 16162, 16163, 16164, 16165, 16166, 16167, 16168, 16169, 16170, 16171, 16172, 16173, 16174, 16175, 16176, 16177, 16178, 16179, 16180, 16181, 16182, 16183, 16184, 16185, 16186, 16187, 16188, 16189, 16190, 16191, 16192, 16193, 16194, 16195, 16196, 16197, 16198, 16199, 16200, 16201, 16202, 16203, 16204, 16205, 16206, 16207, 16208, 16209, 16210, 16211, 16212, 16213, 16214, 16215, 16216, 16217, 16218, 16219, 16220, 16221, 16222, 16223, 16224, 16225, 16226, 16227, 16228, 16229, 16230, 16231, 16232, 16233, 16234, 16235, 16236, 16237, 16238, 16239, 16240, 16241, 16242, 16243, 16244, 16245, 16246, 16247, 16248, 16249, 16250, 16251, 16252, 16253, 16254, 16255, 16256, 16257, 16258, 16259, 16260, 16261, 16262, 16263, 16264, 16265, 16266, 16267, 16268, 16269, 16270, 16271, 16272, 16273, 16274, 16275, 16276, 16277, 16278, 16279, 16280, 16281, 16282, 16283, 16284, 16285, 16286, 16287, 16288, 16289, 16290, 16291, 16292, 16293, 16294, 16295, 16296, 16297, 16298, 16299, 16300, 16301, 16302, 16303, 16304, 16305, 16306, 16307, 16308, 16309, 16310, 16311, 16312, 16313, 16314, 16315, 16316, 16317, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, 16336, 16337, 16338, 16339, 16340, 16341, 16342, 16343, 16344, 16345, 16346, 16347, 16348, 16349, 16350, 16351, 16352, 16353, 16354, 16355, 16356, 16357, 16358, 16359, 16360, 16361, 16362, 16363, 16364, 16365, 16366, 16367, 16368, 16369, 16370, 16371, 16372, 16373, 16374, 16375, 16376, 16377, 16378, 16379, 16380, 16381, 16382, 16383, 16384, 16385, 16386, 16387, 16388, 16389, 16390, 16391, 16392, 16393, 16394, 16395, 16396, 16397, 16398, 16399, 16400, 16401, 16402, 16403, 16404, 16405, 16406, 16407, 16408, 16409, 16410, 16411, 16412, 16413, 16414, 16415, 16416, 16417, 16418, 16419, 16420, 16421, 16422, 16423, 16424, 16425, 16426, 16427, 16428, 16429, 16430, 16431, 16432, 16433, 16434, 16435, 16436, 16437, 16438, 16439, 16440, 16441, 16442, 16443, 16444, 16445, 16446, 16447, 16448, 16449, 16450, 16451, 16452, 16453, 16454, 16455, 16456, 16457, 16458, 16459, 16460, 16461, 16462, 16463, 16464, 16465, 16466, 16467, 16468, 16469, 16470, 16471, 16472, 16473, 16474, 16475, 16476, 16477, 16478, 16479, 16480, 16481, 16482, 16483, 16484, 16485, 16486, 16487, 16488, 16489, 16490, 16491, 16492, 16493, 16494, 16495, 16496, 16497, 16498, 16499, 16500, 16501, 16502, 16503, 16504, 16505, 16506, 16507, 16508, 16509, 16510, 16511, 16512, 16513, 16514, 16515, 16516, 16517, 16518, 16519, 16520, 16521, 16522, 16523, 16524, 16525, 16526, 16527, 16528, 16529, 16530, 16531, 16532, 16533, 16534, 16535, 16536, 16537, 16538, 16539, 16540, 16541, 16542, 16543, 16544, 16545, 16546, 16547, 16548, 16549, 16550, 16551, 16552, 16553, 16554, 16555, 16556, 16557, 16558, 16559, 16560, 16561, 16562, 16563, 16564, 16565, 16566, 16567, 16568, 16569, 16570, 16571, 16572, 16573, 16574, 16575, 16576, 16577, 16578, 16579, 16580, 16581, 16582, 16583, 16584, 16585, 16586, 16587, 16588, 16589, 16590, 16591, 16592, 16593, 16594, 16595, 16596, 16597, 16598, 16599, 16600, 16601, 16602, 16603, 16604, 16605, 16606, 16607, 16608, 16609, 16610, 16611, 16612, 16613, 16614, 16615, 16616, 16617, 16618, 16619, 16620, 16621, 16622, 16623, 16624, 16625, 16626, 16627, 16628, 16629, 16630, 16631, 16632, 16633, 16634, 16635, 16636, 16637, 16638, 16639, 16640, 16641, 16642, 16643, 16644, 16645, 16646, 16647, 16648, 16649, 16650, 16651, 16652, 16653, 16654, 16655, 16656, 16657, 16658, 16659, 16660, 16661, 16662, 16663, 16664, 16665, 16666, 16667, 16668, 16669, 16670, 16671, 16672, 16673, 16674, 16675, 16676, 16677, 16678, 16679, 16680, 16681, 16682, 16683, 16684, 16685, 16686, 16687, 16688, 16689, 16690, 16691, 16692, 16693, 16694, 16695, 16696, 16697, 16698, 16699, 16700, 16701, 16702, 16703, 16704, 16705, 16706, 16707, 16708, 16709, 16710, 16711, 16712, 16713, 16714, 16715, 16716, 16717, 16718, 16719, 16720, 16721, 16722, 16723, 16724, 16725, 16726, 16727, 16728, 16729, 16730, 16731, 16732, 16733, 16734, 16735, 16736, 16737, 16738, 16739, 16740, 16741, 16742, 16743, 16744, 16745, 16746, 16747, 16748, 16749, 16750, 16751, 16752, 16753, 16754, 16755, 16756, 16757, 16758, 16759, 16760, 16761, 16762, 16763, 16764, 16765, 16766, 16767, 16768, 16769, 16770, 16771, 16772, 16773, 16774, 16775, 16776, 16777, 16778, 16779, 16780, 16781, 16782, 16783, 16784, 16785, 16786, 16787, 16788, 16789, 16790, 16791, 16792, 16793, 16794, 16795, 16796, 16797, 16798, 16799, 16800, 16801, 16802, 16803, 16804, 16805, 16806, 16807, 16808, 16809, 16810, 16811, 16812, 16813, 16814, 16815, 16816, 16817, 16818, 16819, 16820, 16821, 16822, 16823, 16824, 16825, 16826, 16827, 16828, 16829, 16830, 16831, 16832, 16833, 16834, 16835, 16836, 16837, 16838, 16839, 16840, 16841, 16842, 16843, 16844, 16845, 16846, 16847, 16848, 16849, 16850, 16851, 16852, 16853, 16854, 16855, 16856, 16857, 16858, 16859, 16860, 16861, 16862, 16863, 16864, 16865, 16866, 16867, 16868, 16869, 16870, 16871, 16872, 16873, 16874, 16875, 16876, 16877, 16878, 16879, 16880, 16881, 16882, 16883, 16884, 16885, 16886, 16887, 16888, 16889, 16890, 16891, 16892, 16893, 16894, 16895, 16896, 16897, 16898, 16899, 16900, 16901, 16902, 16903, 16904, 16905, 16906, 16907, 16908, 16909, 16910, 16911, 16912, 16913, 16914, 16915, 16916, 16917, 16918, 16919, 16920, 16921, 16922, 16923, 16924, 16925, 16926, 16927, 16928, 16929, 16930, 16931, 16932, 16933, 16934, 16935, 16936, 16937, 16938, 16939, 16940, 16941, 16942, 16943, 16944, 16945, 16946, 16947, 16948, 16949, 16950, 16951, 16952, 16953, 16954, 16955, 16956, 16957, 16958, 16959, 16960, 16961, 16962, 16963, 16964, 16965, 16966, 16967, 16968, 16969, 16970, 16971, 16972, 16973, 16974, 16975, 16976, 16977, 16978, 16979, 16980, 16981, 16982, 16983, 16984, 16985, 16986, 16987, 16988, 16989, 16990, 16991, 16992, 16993, 16994, 16995, 16996, 16997, 16998, 16999, 17000, 17001, 17002, 17003, 17004, 17005, 17006, 17007, 17008, 17009, 17010, 17011, 17012, 17013, 17014, 17015, 17016, 17017, 17018, 17019, 17020, 17021, 17022, 17023, 17024, 17025, 17026, 17027, 17028, 17029, 17030, 17031, 17032, 17033, 17034, 17035, 17036, 17037, 17038, 17039, 17040, 17041, 17042, 17043, 17044, 17045, 17046, 17047, 17048, 17049, 17050, 17051, 17052, 17053, 17054, 17055, 17056, 17057, 17058, 17059, 17060, 17061, 17062, 17063, 17064, 17065, 17066, 17067, 17068, 17069, 17070, 17071, 17072, 17073, 17074, 17075, 17076, 17077, 17078, 17079, 17080, 17081, 17082, 17083, 17084, 17085, 17086, 17087, 17088, 17089, 17090, 17091, 17092, 17093, 17094, 17095, 17096, 17097, 17098, 17099, 17100, 17101, 17102, 17103, 17104, 17105, 17106, 17107, 17108, 17109, 17110, 17111, 17112, 17113, 17114, 17115, 17116, 17117, 17118, 17119, 17120, 17121, 17122, 17123, 17124, 17125, 17126, 17127, 17128, 17129, 17130, 17131, 17132, 17133, 17134, 17135, 17136, 17137, 17138, 17139, 17140, 17141, 17142, 17143, 17144, 17145, 17146, 17147, 17148, 17149, 17150, 17151, 17152, 17153, 17154, 17155, 17156, 17157, 17158, 17159, 17160, 17161, 17162, 17163, 17164, 17165, 17166, 17167, 17168, 17169, 17170, 17171, 17172, 17173, 17174, 17175, 17176, 17177, 17178, 17179, 17180, 17181, 17182, 17183, 17184, 17185, 17186, 17187, 17188, 17189, 17190, 17191, 17192, 17193, 17194, 17195, 17196, 17197, 17198, 17199, 17200, 17201, 17202, 17203, 17204, 17205, 17206, 17207, 17208, 17209, 17210, 17211, 17212, 17213, 17214, 17215, 17216, 17217, 17218, 17219, 17220, 17221, 17222, 17223, 17224, 17225, 17226, 17227, 17228, 17229, 17230, 17231, 17232, 17233, 17234, 17235, 17236, 17237, 17238, 17239, 17240, 17241, 17242, 17243, 17244, 17245, 17246, 17247, 17248, 17249, 17250, 17251, 17252, 17253, 17254, 17255, 17256, 17257, 17258, 17259, 17260, 17261, 17262, 17263, 17264, 17265, 17266, 17267, 17268, 17269, 17270, 17271, 17272, 17273, 17274, 17275, 17276, 17277, 17278, 17279, 17280, 17281, 17282, 17283, 17284, 17285, 17286, 17287, 17288, 17289, 17290, 17291, 17292, 17293, 17294, 17295, 17296, 17297, 17298, 17299, 17300, 17301, 17302, 17303, 17304, 17305, 17306, 17307, 17308, 17309, 17310, 17311, 17312, 17313, 17314, 17315, 17316, 17317, 17318, 17319, 17320, 17321, 17322, 17323, 17324, 17325, 17326, 17327, 17328, 17329, 17330, 17331, 17332, 17333, 17334, 17335, 17336, 17337, 17338, 17339, 17340, 17341, 17342, 17343, 17344, 17345, 17346, 17347, 17348, 17349, 17350, 17351, 17352, 17353, 17354, 17355, 17356, 17357, 17358, 17359, 17360, 17361, 17362, 17363, 17364, 17365, 17366, 17367, 17368, 17369, 17370, 17371, 17372, 17373, 17374, 17375, 17376, 17377, 17378, 17379, 17380, 17381, 17382, 17383, 17384, 17385, 17386, 17387, 17388, 17389, 17390, 17391, 17392, 17393, 17394, 17395, 17396, 17397, 17398, 17399, 17400, 17401, 17402, 17403, 17404, 17405, 17406, 17407, 17408, 17409, 17410, 17411, 17412, 17413, 17414, 17415, 17416, 17417, 17418, 17419, 17420, 17421, 17422, 17423, 17424, 17425, 17426, 17427, 17428, 17429, 17430, 17431, 17432, 17433, 17434, 17435, 17436, 17437, 17438, 17439, 17440, 17441, 17442, 17443, 17444, 17445, 17446, 17447, 17448, 17449, 17450, 17451, 17452, 17453, 17454, 17455, 17456, 17457, 17458, 17459, 17460, 17461, 17462, 17463, 17464, 17465, 17466, 17467, 17468, 17469, 17470, 17471, 17472, 17473, 17474, 17475, 17476, 17477, 17478, 17479, 17480, 17481, 17482, 17483, 17484, 17485, 17486, 17487, 17488, 17489, 17490, 17491, 17492, 17493, 17494, 17495, 17496, 17497, 17498, 17499, 17500, 17501, 17502, 17503, 17504, 17505, 17506, 17507, 17508, 17509, 17510, 17511, 17512, 17513, 17514, 17515, 17516, 17517, 17518, 17519, 17520, 17521, 17522, 17523, 17524, 17525, 17526, 17527, 17528, 17529, 17530, 17531, 17532, 17533, 17534, 17535, 17536, 17537, 17538, 17539, 17540, 17541, 17542, 17543, 17544, 17545, 17546, 17547, 17548, 17549, 17550, 17551, 17552, 17553, 17554, 17555, 17556, 17557, 17558, 17559, 17560, 17561, 17562, 17563, 17564, 17565, 17566, 17567, 17568, 17569, 17570, 17571, 17572, 17573, 17574, 17575, 17576, 17577, 17578, 17579, 17580, 17581, 17582, 17583, 17584, 17585, 17586, 17587, 17588, 17589, 17590, 17591, 17592, 17593, 17594, 17595, 17596, 17597, 17598, 17599, 17600, 17601, 17602, 17603, 17604, 17605, 17606, 17607, 17608, 17609, 17610, 17611, 17612, 17613, 17614, 17615, 17616, 17617, 17618, 17619, 17620, 17621, 17622, 17623, 17624, 17625, 17626, 17627, 17628, 17629, 17630, 17631, 17632, 17633, 17634, 17635, 17636, 17637, 17638, 17639, 17640, 17641, 17642, 17643, 17644, 17645, 17646, 17647, 17648, 17649, 17650, 17651, 17652, 17653, 17654, 17655, 17656, 17657, 17658, 17659, 17660, 17661, 17662, 17663, 17664, 17665, 17666, 17667, 17668, 17669, 17670, 17671, 17672, 17673, 17674, 17675, 17676, 17677, 17678, 17679, 17680, 17681, 17682, 17683, 17684, 17685, 17686, 17687, 17688, 17689, 17690, 17691, 17692, 17693, 17694, 17695, 17696, 17697, 17698, 17699, 17700, 17701, 17702, 17703, 17704, 17705, 17706, 17707, 17708, 17709, 17710, 17711, 17712, 17713, 17714, 17715, 17716, 17717, 17718, 17719, 17720, 17721, 17722, 17723, 17724, 17725, 17726, 17727, 17728, 17729, 17730, 17731, 17732, 17733, 17734, 17735, 17736, 17737, 17738, 17739, 17740, 17741, 17742, 17743, 17744, 17745, 17746, 17747, 17748, 17749, 17750, 17751, 17752, 17753, 17754, 17755, 17756, 17757, 17758, 17759, 17760, 17761, 17762, 17763, 17764, 17765, 17766, 17767, 17768, 17769, 17770, 17771, 17772, 17773, 17774, 17775, 17776, 17777, 17778, 17779, 17780, 17781, 17782, 17783, 17784, 17785, 17786, 17787, 17788, 17789, 17790, 17791, 17792, 17793, 17794, 17795, 17796, 17797, 17798, 17799, 17800, 17801, 17802, 17803, 17804, 17805, 17806, 17807, 17808, 17809, 17810, 17811, 17812, 17813, 17814, 17815, 17816, 17817, 17818, 17819, 17820, 17821, 17822, 17823, 17824, 17825, 17826, 17827, 17828, 17829, 17830, 17831, 17832, 17833, 17834, 17835, 17836, 17837, 17838, 17839, 17840, 17841, 17842, 17843, 17844, 17845, 17846, 17847, 17848, 17849, 17850, 17851, 17852, 17853, 17854, 17855, 17856, 17857, 17858, 17859, 17860, 17861, 17862, 17863, 17864, 17865, 17866, 17867, 17868, 17869, 17870, 17871, 17872, 17873, 17874, 17875, 17876, 17877, 17878, 17879, 17880, 17881, 17882, 17883, 17884, 17885, 17886, 17887, 17888, 17889, 17890, 17891, 17892, 17893, 17894, 17895, 17896, 17897, 17898, 17899, 17900, 17901, 17902, 17903, 17904, 17905, 17906, 17907, 17908, 17909, 17910, 17911, 17912, 17913, 17914, 17915, 17916, 17917, 17918, 17919, 17920, 17921, 17922, 17923, 17924, 17925, 17926, 17927, 17928, 17929, 17930, 17931, 17932, 17933, 17934, 17935, 17936, 17937, 17938, 17939, 17940, 17941, 17942, 17943, 17944, 17945, 17946, 17947, 17948, 17949, 17950, 17951, 17952, 17953, 17954, 17955, 17956, 17957, 17958, 17959, 17960, 17961, 17962, 17963, 17964, 17965, 17966, 17967, 17968, 17969, 17970, 17971, 17972, 17973, 17974, 17975, 17976, 17977, 17978, 17979, 17980, 17981, 17982, 17983, 17984, 17985, 17986, 17987, 17988, 17989, 17990, 17991, 17992, 17993, 17994, 17995, 17996, 17997, 17998, 17999, 18000, 18001, 18002, 18003, 18004, 18005, 18006, 18007, 18008, 18009, 18010, 18011, 18012, 18013, 18014, 18015, 18016, 18017, 18018, 18019, 18020, 18021, 18022, 18023, 18024, 18025, 18026, 18027, 18028, 18029, 18030, 18031, 18032, 18033, 18034, 18035, 18036, 18037, 18038, 18039, 18040, 18041, 18042, 18043, 18044, 18045, 18046, 18047, 18048, 18049, 18050, 18051, 18052, 18053, 18054, 18055, 18056, 18057, 18058, 18059, 18060, 18061, 18062, 18063, 18064, 18065, 18066, 18067, 18068, 18069, 18070, 18071, 18072, 18073, 18074, 18075, 18076, 18077, 18078, 18079, 18080, 18081, 18082, 18083, 18084, 18085, 18086, 18087, 18088, 18089, 18090, 18091, 18092, 18093, 18094, 18095, 18096, 18097, 18098, 18099, 18100, 18101, 18102, 18103, 18104, 18105, 18106, 18107, 18108, 18109, 18110, 18111, 18112, 18113, 18114, 18115, 18116, 18117, 18118, 18119, 18120, 18121, 18122, 18123, 18124, 18125, 18126, 18127, 18128, 18129, 18130, 18131, 18132, 18133, 18134, 18135, 18136, 18137, 18138, 18139, 18140, 18141, 18142, 18143, 18144, 18145, 18146, 18147, 18148, 18149, 18150, 18151, 18152, 18153, 18154, 18155, 18156, 18157, 18158, 18159, 18160, 18161, 18162, 18163, 18164, 18165, 18166, 18167, 18168, 18169, 18170, 18171, 18172, 18173, 18174, 18175, 18176, 18177, 18178, 18179, 18180, 18181, 18182, 18183, 18184, 18185, 18186, 18187, 18188, 18189, 18190, 18191, 18192, 18193, 18194, 18195, 18196, 18197, 18198, 18199, 18200, 18201, 18202, 18203, 18204, 18205, 18206, 18207, 18208, 18209, 18210, 18211, 18212, 18213, 18214, 18215, 18216, 18217, 18218, 18219, 18220, 18221, 18222, 18223, 18224, 18225, 18226, 18227, 18228, 18229, 18230, 18231, 18232, 18233, 18234, 18235, 18236, 18237, 18238, 18239, 18240, 18241, 18242, 18243, 18244, 18245, 18246, 18247, 18248, 18249, 18250, 18251, 18252, 18253, 18254, 18255, 18256, 18257, 18258, 18259, 18260, 18261, 18262, 18263, 18264, 18265, 18266, 18267, 18268, 18269, 18270, 18271, 18272, 18273, 18274, 18275, 18276, 18277, 18278, 18279, 18280, 18281, 18282, 18283, 18284, 18285, 18286, 18287, 18288, 18289, 18290, 18291, 18292, 18293, 18294, 18295, 18296, 18297, 18298, 18299, 18300, 18301, 18302, 18303, 18304, 18305, 18306, 18307, 18308, 18309, 18310, 18311, 18312, 18313, 18314, 18315, 18316, 18317, 18318, 18319, 18320, 18321, 18322, 18323, 18324, 18325, 18326, 18327, 18328, 18329, 18330, 18331, 18332, 18333, 18334, 18335, 18336, 18337, 18338, 18339, 18340, 18341, 18342, 18343, 18344, 18345, 18346, 18347, 18348, 18349, 18350, 18351, 18352, 18353, 18354, 18355, 18356, 18357, 18358, 18359, 18360, 18361, 18362, 18363, 18364, 18365, 18366, 18367, 18368, 18369, 18370, 18371, 18372, 18373, 18374, 18375, 18376, 18377, 18378, 18379, 18380, 18381, 18382, 18383, 18384, 18385, 18386, 18387, 18388, 18389, 18390, 18391, 18392, 18393, 18394, 18395, 18396, 18397, 18398, 18399, 18400, 18401, 18402, 18403, 18404, 18405, 18406, 18407, 18408, 18409, 18410, 18411, 18412, 18413, 18414, 18415, 18416, 18417, 18418, 18419, 18420, 18421, 18422, 18423, 18424, 18425, 18426, 18427, 18428, 18429, 18430, 18431, 18432, 18433, 18434, 18435, 18436, 18437, 18438, 18439, 18440, 18441, 18442, 18443, 18444, 18445, 18446, 18447, 18448, 18449, 18450, 18451, 18452, 18453, 18454, 18455, 18456, 18457, 18458, 18459, 18460, 18461, 18462, 18463, 18464, 18465, 18466, 18467, 18468, 18469, 18470, 18471, 18472, 18473, 18474, 18475, 18476, 18477, 18478, 18479, 18480, 18481, 18482, 18483, 18484, 18485, 18486, 18487, 18488, 18489, 18490, 18491, 18492, 18493, 18494, 18495, 18496, 18497, 18498, 18499, 18500, 18501, 18502, 18503, 18504, 18505, 18506, 18507, 18508, 18509, 18510, 18511, 18512, 18513, 18514, 18515, 18516, 18517, 18518, 18519, 18520, 18521, 18522, 18523, 18524, 18525, 18526, 18527, 18528, 18529, 18530, 18531, 18532, 18533, 18534, 18535, 18536, 18537, 18538, 18539, 18540, 18541, 18542, 18543, 18544, 18545, 18546, 18547, 18548, 18549, 18550, 18551, 18552, 18553, 18554, 18555, 18556, 18557, 18558, 18559, 18560, 18561, 18562, 18563, 18564, 18565, 18566, 18567, 18568, 18569, 18570, 18571, 18572, 18573, 18574, 18575, 18576, 18577, 18578, 18579, 18580, 18581, 18582, 18583, 18584, 18585, 18586, 18587, 18588, 18589, 18590, 18591, 18592, 18593, 18594, 18595, 18596, 18597, 18598, 18599, 18600, 18601, 18602, 18603, 18604, 18605, 18606, 18607, 18608, 18609, 18610, 18611, 18612, 18613, 18614, 18615, 18616, 18617, 18618, 18619, 18620, 18621, 18622, 18623, 18624, 18625, 18626, 18627, 18628, 18629, 18630, 18631, 18632, 18633, 18634, 18635, 18636, 18637, 18638, 18639, 18640, 18641, 18642, 18643, 18644, 18645, 18646, 18647, 18648, 18649, 18650, 18651, 18652, 18653, 18654, 18655, 18656, 18657, 18658, 18659, 18660, 18661, 18662, 18663, 18664, 18665, 18666, 18667, 18668, 18669, 18670, 18671, 18672, 18673, 18674, 18675, 18676, 18677, 18678, 18679, 18680, 18681, 18682, 18683, 18684, 18685, 18686, 18687, 18688, 18689, 18690, 18691, 18692, 18693, 18694, 18695, 18696, 18697, 18698, 18699, 18700, 18701, 18702, 18703, 18704, 18705, 18706, 18707, 18708, 18709, 18710, 18711, 18712, 18713, 18714, 18715, 18716, 18717, 18718, 18719, 18720, 18721, 18722, 18723, 18724, 18725, 18726, 18727, 18728, 18729, 18730, 18731, 18732, 18733, 18734, 18735, 18736, 18737, 18738, 18739, 18740, 18741, 18742, 18743, 18744, 18745, 18746, 18747, 18748, 18749, 18750, 18751, 18752, 18753, 18754, 18755, 18756, 18757, 18758, 18759, 18760, 18761, 18762, 18763, 18764, 18765, 18766, 18767, 18768, 18769, 18770, 18771, 18772, 18773, 18774, 18775, 18776, 18777, 18778, 18779, 18780, 18781, 18782, 18783, 18784, 18785, 18786, 18787, 18788, 18789, 18790, 18791, 18792, 18793, 18794, 18795, 18796, 18797, 18798, 18799, 18800, 18801, 18802, 18803, 18804, 18805, 18806, 18807, 18808, 18809, 18810, 18811, 18812, 18813, 18814, 18815, 18816, 18817, 18818, 18819, 18820, 18821, 18822, 18823, 18824, 18825, 18826, 18827, 18828, 18829, 18830, 18831, 18832, 18833, 18834, 18835, 18836, 18837, 18838, 18839, 18840, 18841, 18842, 18843, 18844, 18845, 18846, 18847, 18848, 18849, 18850, 18851, 18852, 18853, 18854, 18855, 18856, 18857, 18858, 18859, 18860, 18861, 18862, 18863, 18864, 18865, 18866, 18867, 18868, 18869, 18870, 18871, 18872, 18873, 18874, 18875, 18876, 18877, 18878, 18879, 18880, 18881, 18882, 18883, 18884, 18885, 18886, 18887, 18888, 18889, 18890, 18891, 18892, 18893, 18894, 18895, 18896, 18897, 18898, 18899, 18900, 18901, 18902, 18903, 18904, 18905, 18906, 18907, 18908, 18909, 18910, 18911, 18912, 18913, 18914, 18915, 18916, 18917, 18918, 18919, 18920, 18921, 18922, 18923, 18924, 18925, 18926, 18927, 18928, 18929, 18930, 18931, 18932, 18933, 18934, 18935, 18936, 18937, 18938, 18939, 18940, 18941, 18942, 18943, 18944, 18945, 18946, 18947, 18948, 18949, 18950, 18951, 18952, 18953, 18954, 18955, 18956, 18957, 18958, 18959, 18960, 18961, 18962, 18963, 18964, 18965, 18966, 18967, 18968, 18969, 18970, 18971, 18972, 18973, 18974, 18975, 18976, 18977, 18978, 18979, 18980, 18981, 18982, 18983, 18984, 18985, 18986, 18987, 18988, 18989, 18990, 18991, 18992, 18993, 18994, 18995, 18996, 18997, 18998, 18999, 19000, 19001, 19002, 19003, 19004, 19005, 19006, 19007, 19008, 19009, 19010, 19011, 19012, 19013, 19014, 19015, 19016, 19017, 19018, 19019, 19020, 19021, 19022, 19023, 19024, 19025, 19026, 19027, 19028, 19029, 19030, 19031, 19032, 19033, 19034, 19035, 19036, 19037, 19038, 19039, 19040, 19041, 19042, 19043, 19044, 19045, 19046, 19047, 19048, 19049, 19050, 19051, 19052, 19053, 19054, 19055, 19056, 19057, 19058, 19059, 19060, 19061, 19062, 19063, 19064, 19065, 19066, 19067, 19068, 19069, 19070, 19071, 19072, 19073, 19074, 19075, 19076, 19077, 19078, 19079, 19080, 19081, 19082, 19083, 19084, 19085, 19086, 19087, 19088, 19089, 19090, 19091, 19092, 19093, 19094, 19095, 19096, 19097, 19098, 19099, 19100, 19101, 19102, 19103, 19104, 19105, 19106, 19107, 19108, 19109, 19110, 19111, 19112, 19113, 19114, 19115, 19116, 19117, 19118, 19119, 19120, 19121, 19122, 19123, 19124, 19125, 19126, 19127, 19128, 19129, 19130, 19131, 19132, 19133, 19134, 19135, 19136, 19137, 19138, 19139, 19140, 19141, 19142, 19143, 19144, 19145, 19146, 19147, 19148, 19149, 19150, 19151, 19152, 19153, 19154, 19155, 19156, 19157, 19158, 19159, 19160, 19161, 19162, 19163, 19164, 19165, 19166, 19167, 19168, 19169, 19170, 19171, 19172, 19173, 19174, 19175, 19176, 19177, 19178, 19179, 19180, 19181, 19182, 19183, 19184, 19185, 19186, 19187, 19188, 19189, 19190, 19191, 19192, 19193, 19194, 19195, 19196, 19197, 19198, 19199, 19200, 19201, 19202, 19203, 19204, 19205, 19206, 19207, 19208, 19209, 19210, 19211, 19212, 19213, 19214, 19215, 19216, 19217, 19218, 19219, 19220, 19221, 19222, 19223, 19224, 19225, 19226, 19227, 19228, 19229, 19230, 19231, 19232, 19233, 19234, 19235, 19236, 19237, 19238, 19239, 19240, 19241, 19242, 19243, 19244, 19245, 19246, 19247, 19248, 19249, 19250, 19251, 19252, 19253, 19254, 19255, 19256, 19257, 19258, 19259, 19260, 19261, 19262, 19263, 19264, 19265, 19266, 19267, 19268, 19269, 19270, 19271, 19272, 19273, 19274, 19275, 19276, 19277, 19278, 19279, 19280, 19281, 19282, 19283, 19284, 19285, 19286, 19287, 19288, 19289, 19290, 19291, 19292, 19293, 19294, 19295, 19296, 19297, 19298, 19299, 19300, 19301, 19302, 19303, 19304, 19305, 19306, 19307, 19308, 19309, 19310, 19311, 19312, 19313, 19314, 19315, 19316, 19317, 19318, 19319, 19320, 19321, 19322, 19323, 19324, 19325, 19326, 19327, 19328, 19329, 19330, 19331, 19332, 19333, 19334, 19335, 19336, 19337, 19338, 19339, 19340, 19341, 19342, 19343, 19344, 19345, 19346, 19347, 19348, 19349, 19350, 19351, 19352, 19353, 19354, 19355, 19356, 19357, 19358, 19359, 19360, 19361, 19362, 19363, 19364, 19365, 19366, 19367, 19368, 19369, 19370, 19371, 19372, 19373, 19374, 19375, 19376, 19377, 19378, 19379, 19380, 19381, 19382, 19383, 19384, 19385, 19386, 19387, 19388, 19389, 19390, 19391, 19392, 19393, 19394, 19395, 19396, 19397, 19398, 19399, 19400, 19401, 19402, 19403, 19404, 19405, 19406, 19407, 19408, 19409, 19410, 19411, 19412, 19413, 19414, 19415, 19416, 19417, 19418, 19419, 19420, 19421, 19422, 19423, 19424, 19425, 19426, 19427, 19428, 19429, 19430, 19431, 19432, 19433, 19434, 19435, 19436, 19437, 19438, 19439, 19440, 19441, 19442, 19443, 19444, 19445, 19446, 19447, 19448, 19449, 19450, 19451, 19452, 19453, 19454, 19455, 19456, 19457, 19458, 19459, 19460, 19461, 19462, 19463, 19464, 19465, 19466, 19467, 19468, 19469, 19470, 19471, 19472, 19473, 19474, 19475, 19476, 19477, 19478, 19479, 19480, 19481, 19482, 19483, 19484, 19485, 19486, 19487, 19488, 19489, 19490, 19491, 19492, 19493, 19494, 19495, 19496, 19497, 19498, 19499, 19500, 19501, 19502, 19503, 19504, 19505, 19506, 19507, 19508, 19509, 19510, 19511, 19512, 19513, 19514, 19515, 19516, 19517, 19518, 19519, 19520, 19521, 19522, 19523, 19524, 19525, 19526, 19527, 19528, 19529, 19530, 19531, 19532, 19533, 19534, 19535, 19536, 19537, 19538, 19539, 19540, 19541, 19542, 19543, 19544, 19545, 19546, 19547, 19548, 19549, 19550, 19551, 19552, 19553, 19554, 19555, 19556, 19557, 19558, 19559, 19560, 19561, 19562, 19563, 19564, 19565, 19566, 19567, 19568, 19569, 19570, 19571, 19572, 19573, 19574, 19575, 19576, 19577, 19578, 19579, 19580, 19581, 19582, 19583, 19584, 19585, 19586, 19587, 19588, 19589, 19590, 19591, 19592, 19593, 19594, 19595, 19596, 19597, 19598, 19599, 19600, 19601, 19602, 19603, 19604, 19605, 19606, 19607, 19608, 19609, 19610, 19611, 19612, 19613, 19614, 19615, 19616, 19617, 19618, 19619, 19620, 19621, 19622, 19623, 19624, 19625, 19626, 19627, 19628, 19629, 19630, 19631, 19632, 19633, 19634, 19635, 19636, 19637, 19638, 19639, 19640, 19641, 19642, 19643, 19644, 19645, 19646, 19647, 19648, 19649, 19650, 19651, 19652, 19653, 19654, 19655, 19656, 19657, 19658, 19659, 19660, 19661, 19662, 19663, 19664, 19665, 19666, 19667, 19668, 19669, 19670, 19671, 19672, 19673, 19674, 19675, 19676, 19677, 19678, 19679, 19680, 19681, 19682, 19683, 19684, 19685, 19686, 19687, 19688, 19689, 19690, 19691, 19692, 19693, 19694, 19695, 19696, 19697, 19698, 19699, 19700, 19701, 19702, 19703, 19704, 19705, 19706, 19707, 19708, 19709, 19710, 19711, 19712, 19713, 19714, 19715, 19716, 19717, 19718, 19719, 19720, 19721, 19722, 19723, 19724, 19725, 19726, 19727, 19728, 19729, 19730, 19731, 19732, 19733, 19734, 19735, 19736, 19737, 19738, 19739, 19740, 19741, 19742, 19743, 19744, 19745, 19746, 19747, 19748, 19749, 19750, 19751, 19752, 19753, 19754, 19755, 19756, 19757, 19758, 19759, 19760, 19761, 19762, 19763, 19764, 19765, 19766, 19767, 19768, 19769, 19770, 19771, 19772, 19773, 19774, 19775, 19776, 19777, 19778, 19779, 19780, 19781, 19782, 19783, 19784, 19785, 19786, 19787, 19788, 19789, 19790, 19791, 19792, 19793, 19794, 19795, 19796, 19797, 19798, 19799, 19800, 19801, 19802, 19803, 19804, 19805, 19806, 19807, 19808, 19809, 19810, 19811, 19812, 19813, 19814, 19815, 19816, 19817, 19818, 19819, 19820, 19821, 19822, 19823, 19824, 19825, 19826, 19827, 19828, 19829, 19830, 19831, 19832, 19833, 19834, 19835, 19836, 19837, 19838, 19839, 19840, 19841, 19842, 19843, 19844, 19845, 19846, 19847, 19848, 19849, 19850, 19851, 19852, 19853, 19854, 19855, 19856, 19857, 19858, 19859, 19860, 19861, 19862, 19863, 19864, 19865, 19866, 19867, 19868, 19869, 19870, 19871, 19872, 19873, 19874, 19875, 19876, 19877, 19878, 19879, 19880, 19881, 19882, 19883, 19884, 19885, 19886, 19887, 19888, 19889, 19890, 19891, 19892, 19893, 19894, 19895, 19896, 19897, 19898, 19899, 19900, 19901, 19902, 19903, 19904, 19905, 19906, 19907, 19908, 19909, 19910, 19911, 19912, 19913, 19914, 19915, 19916, 19917, 19918, 19919, 19920, 19921, 19922, 19923, 19924, 19925, 19926, 19927, 19928, 19929, 19930, 19931, 19932, 19933, 19934, 19935, 19936, 19937, 19938, 19939, 19940, 19941, 19942, 19943, 19944, 19945, 19946, 19947, 19948, 19949, 19950, 19951, 19952, 19953, 19954, 19955, 19956, 19957, 19958, 19959, 19960, 19961, 19962, 19963, 19964, 19965, 19966, 19967, 19968, 19969, 19970, 19971, 19972, 19973, 19974, 19975, 19976, 19977, 19978, 19979, 19980, 19981, 19982, 19983, 19984, 19985, 19986, 19987, 19988, 19989, 19990, 19991, 19992, 19993, 19994, 19995, 19996, 19997, 19998, 19999, 20000, 20001, 20002, 20003, 20004, 20005, 20006, 20007, 20008, 20009, 20010, 20011, 20012, 20013, 20014, 20015, 20016, 20017, 20018, 20019, 20020, 20021, 20022, 20023, 20024, 20025, 20026, 20027, 20028, 20029, 20030, 20031, 20032, 20033, 20034, 20035, 20036, 20037, 20038, 20039, 20040, 20041, 20042, 20043, 20044, 20045, 20046, 20047, 20048, 20049, 20050, 20051, 20052, 20053, 20054, 20055, 20056, 20057, 20058, 20059, 20060, 20061, 20062, 20063, 20064, 20065, 20066, 20067, 20068, 20069, 20070, 20071, 20072, 20073, 20074, 20075, 20076, 20077, 20078, 20079, 20080, 20081, 20082, 20083, 20084, 20085, 20086, 20087, 20088, 20089, 20090, 20091, 20092, 20093, 20094, 20095, 20096, 20097, 20098, 20099, 20100, 20101, 20102, 20103, 20104, 20105, 20106, 20107, 20108, 20109, 20110, 20111, 20112, 20113, 20114, 20115, 20116, 20117, 20118, 20119, 20120, 20121, 20122, 20123, 20124, 20125, 20126, 20127, 20128, 20129, 20130, 20131, 20132, 20133, 20134, 20135, 20136, 20137, 20138, 20139, 20140, 20141, 20142, 20143, 20144, 20145, 20146, 20147, 20148, 20149, 20150, 20151, 20152, 20153, 20154, 20155, 20156, 20157, 20158, 20159, 20160, 20161, 20162, 20163, 20164, 20165, 20166, 20167, 20168, 20169, 20170, 20171, 20172, 20173, 20174, 20175, 20176, 20177, 20178, 20179, 20180, 20181, 20182, 20183, 20184, 20185, 20186, 20187, 20188, 20189, 20190, 20191, 20192, 20193, 20194, 20195, 20196, 20197, 20198, 20199, 20200, 20201, 20202, 20203, 20204, 20205, 20206, 20207, 20208, 20209, 20210, 20211, 20212, 20213, 20214, 20215, 20216, 20217, 20218, 20219, 20220, 20221, 20222, 20223, 20224, 20225, 20226, 20227, 20228, 20229, 20230, 20231, 20232, 20233, 20234, 20235, 20236, 20237, 20238, 20239, 20240, 20241, 20242, 20243, 20244, 20245, 20246, 20247, 20248, 20249, 20250, 20251, 20252, 20253, 20254, 20255, 20256, 20257, 20258, 20259, 20260, 20261, 20262, 20263, 20264, 20265, 20266, 20267, 20268, 20269, 20270, 20271, 20272, 20273, 20274, 20275, 20276, 20277, 20278, 20279, 20280, 20281, 20282, 20283, 20284, 20285, 20286, 20287, 20288, 20289, 20290, 20291, 20292, 20293, 20294, 20295, 20296, 20297, 20298, 20299, 20300, 20301, 20302, 20303, 20304, 20305, 20306, 20307, 20308, 20309, 20310, 20311, 20312, 20313, 20314, 20315, 20316, 20317, 20318, 20319, 20320, 20321, 20322, 20323, 20324, 20325, 20326, 20327, 20328, 20329, 20330, 20331, 20332, 20333, 20334, 20335, 20336, 20337, 20338, 20339, 20340, 20341, 20342, 20343, 20344, 20345, 20346, 20347, 20348, 20349, 20350, 20351, 20352, 20353, 20354, 20355, 20356, 20357, 20358, 20359, 20360, 20361, 20362, 20363, 20364, 20365, 20366, 20367, 20368, 20369, 20370, 20371, 20372, 20373, 20374, 20375, 20376, 20377, 20378, 20379, 20380, 20381, 20382, 20383, 20384, 20385, 20386, 20387, 20388, 20389, 20390, 20391, 20392, 20393, 20394, 20395, 20396, 20397, 20398, 20399, 20400, 20401, 20402, 20403, 20404, 20405, 20406, 20407, 20408, 20409, 20410, 20411, 20412, 20413, 20414, 20415, 20416, 20417, 20418, 20419, 20420, 20421, 20422, 20423, 20424, 20425, 20426, 20427, 20428, 20429, 20430, 20431, 20432, 20433, 20434, 20435, 20436, 20437, 20438, 20439, 20440, 20441, 20442, 20443, 20444, 20445, 20446, 20447, 20448, 20449, 20450, 20451, 20452, 20453, 20454, 20455, 20456, 20457, 20458, 20459, 20460, 20461, 20462, 20463, 20464, 20465, 20466, 20467, 20468, 20469, 20470, 20471, 20472, 20473, 20474, 20475, 20476, 20477, 20478, 20479, 20480, 20481, 20482, 20483, 20484, 20485, 20486, 20487, 20488, 20489, 20490, 20491, 20492, 20493, 20494, 20495, 20496, 20497, 20498, 20499, 20500, 20501, 20502, 20503, 20504, 20505, 20506, 20507, 20508, 20509, 20510, 20511, 20512, 20513, 20514, 20515, 20516, 20517, 20518, 20519, 20520, 20521, 20522, 20523, 20524, 20525, 20526, 20527, 20528, 20529, 20530, 20531, 20532, 20533, 20534, 20535, 20536, 20537, 20538, 20539, 20540, 20541, 20542, 20543, 20544, 20545, 20546, 20547, 20548, 20549, 20550, 20551, 20552, 20553, 20554, 20555, 20556, 20557, 20558, 20559, 20560, 20561, 20562, 20563, 20564, 20565, 20566, 20567, 20568, 20569, 20570, 20571, 20572, 20573, 20574, 20575, 20576, 20577, 20578, 20579, 20580, 20581, 20582, 20583, 20584, 20585, 20586, 20587, 20588, 20589, 20590, 20591, 20592, 20593, 20594, 20595, 20596, 20597, 20598, 20599, 20600, 20601, 20602, 20603, 20604, 20605, 20606, 20607, 20608, 20609, 20610, 20611, 20612, 20613, 20614, 20615, 20616, 20617, 20618, 20619, 20620, 20621, 20622, 20623, 20624, 20625, 20626, 20627, 20628, 20629, 20630, 20631, 20632, 20633, 20634, 20635, 20636, 20637, 20638, 20639, 20640, 20641, 20642, 20643, 20644, 20645, 20646, 20647, 20648, 20649, 20650, 20651, 20652, 20653, 20654, 20655, 20656, 20657, 20658, 20659, 20660, 20661, 20662, 20663, 20664, 20665, 20666, 20667, 20668, 20669, 20670, 20671, 20672, 20673, 20674, 20675, 20676, 20677, 20678, 20679, 20680, 20681, 20682, 20683, 20684, 20685, 20686, 20687, 20688, 20689, 20690, 20691, 20692, 20693, 20694, 20695, 20696, 20697, 20698, 20699, 20700, 20701, 20702, 20703, 20704, 20705, 20706, 20707, 20708, 20709, 20710, 20711, 20712, 20713, 20714, 20715, 20716, 20717, 20718, 20719, 20720, 20721, 20722, 20723, 20724, 20725, 20726, 20727, 20728, 20729, 20730, 20731, 20732, 20733, 20734, 20735, 20736, 20737, 20738, 20739, 20740, 20741, 20742, 20743, 20744, 20745, 20746, 20747, 20748, 20749, 20750, 20751, 20752, 20753, 20754, 20755, 20756, 20757, 20758, 20759, 20760, 20761, 20762, 20763, 20764, 20765, 20766, 20767, 20768, 20769, 20770, 20771, 20772, 20773, 20774, 20775, 20776, 20777, 20778, 20779, 20780, 20781, 20782, 20783, 20784, 20785, 20786, 20787, 20788, 20789, 20790, 20791, 20792, 20793, 20794, 20795, 20796, 20797, 20798, 20799, 20800, 20801, 20802, 20803, 20804, 20805, 20806, 20807, 20808, 20809, 20810, 20811, 20812, 20813, 20814, 20815, 20816, 20817, 20818, 20819, 20820, 20821, 20822, 20823, 20824, 20825, 20826, 20827, 20828, 20829, 20830, 20831, 20832, 20833, 20834, 20835, 20836, 20837, 20838, 20839, 20840, 20841, 20842, 20843, 20844, 20845, 20846, 20847, 20848, 20849, 20850, 20851, 20852, 20853, 20854, 20855, 20856, 20857, 20858, 20859, 20860, 20861, 20862, 20863, 20864, 20865, 20866, 20867, 20868, 20869, 20870, 20871, 20872, 20873, 20874, 20875, 20876, 20877, 20878, 20879, 20880, 20881, 20882, 20883, 20884, 20885, 20886, 20887, 20888, 20889, 20890, 20891, 20892, 20893, 20894, 20895, 20896, 20897, 20898, 20899, 20900, 20901, 20902, 20903, 20904, 20905, 20906, 20907, 20908, 20909, 20910, 20911, 20912, 20913, 20914, 20915, 20916, 20917, 20918, 20919, 20920, 20921, 20922, 20923, 20924, 20925, 20926, 20927, 20928, 20929, 20930, 20931, 20932, 20933, 20934, 20935, 20936, 20937, 20938, 20939, 20940, 20941, 20942, 20943, 20944, 20945, 20946, 20947, 20948, 20949, 20950, 20951, 20952, 20953, 20954, 20955, 20956, 20957, 20958, 20959, 20960, 20961, 20962, 20963, 20964, 20965, 20966, 20967, 20968, 20969, 20970, 20971, 20972, 20973, 20974, 20975, 20976, 20977, 20978, 20979, 20980, 20981, 20982, 20983, 20984, 20985, 20986, 20987, 20988, 20989, 20990, 20991, 20992, 20993, 20994, 20995, 20996, 20997, 20998, 20999, 21000, 21001, 21002, 21003, 21004, 21005, 21006, 21007, 21008, 21009, 21010, 21011, 21012, 21013, 21014, 21015, 21016, 21017, 21018, 21019, 21020, 21021, 21022, 21023, 21024, 21025, 21026, 21027, 21028, 21029, 21030, 21031, 21032, 21033, 21034, 21035, 21036, 21037, 21038, 21039, 21040, 21041, 21042, 21043, 21044, 21045, 21046, 21047, 21048, 21049, 21050, 21051, 21052, 21053, 21054, 21055, 21056, 21057, 21058, 21059, 21060, 21061, 21062, 21063, 21064, 21065, 21066, 21067, 21068, 21069, 21070, 21071, 21072, 21073, 21074, 21075, 21076, 21077, 21078, 21079, 21080, 21081, 21082, 21083, 21084, 21085, 21086, 21087, 21088, 21089, 21090, 21091, 21092, 21093, 21094, 21095, 21096, 21097, 21098, 21099, 21100, 21101, 21102, 21103, 21104, 21105, 21106, 21107, 21108, 21109, 21110, 21111, 21112, 21113, 21114, 21115, 21116, 21117, 21118, 21119, 21120, 21121, 21122, 21123, 21124, 21125, 21126, 21127, 21128, 21129, 21130, 21131, 21132, 21133, 21134, 21135, 21136, 21137, 21138, 21139, 21140, 21141, 21142, 21143, 21144, 21145, 21146, 21147, 21148, 21149, 21150, 21151, 21152, 21153, 21154, 21155, 21156, 21157, 21158, 21159, 21160, 21161, 21162, 21163, 21164, 21165, 21166, 21167, 21168, 21169, 21170, 21171, 21172, 21173, 21174, 21175, 21176, 21177, 21178, 21179, 21180, 21181, 21182, 21183, 21184, 21185, 21186, 21187, 21188, 21189, 21190, 21191, 21192, 21193, 21194, 21195, 21196, 21197, 21198, 21199, 21200, 21201, 21202, 21203, 21204, 21205, 21206, 21207, 21208, 21209, 21210, 21211, 21212, 21213, 21214, 21215, 21216, 21217, 21218, 21219, 21220, 21221, 21222, 21223, 21224, 21225, 21226, 21227, 21228, 21229, 21230, 21231, 21232, 21233, 21234, 21235, 21236, 21237, 21238, 21239, 21240, 21241, 21242, 21243, 21244, 21245, 21246, 21247, 21248, 21249, 21250, 21251, 21252, 21253, 21254, 21255, 21256, 21257, 21258, 21259, 21260, 21261, 21262, 21263, 21264, 21265, 21266, 21267, 21268, 21269, 21270, 21271, 21272, 21273, 21274, 21275, 21276, 21277, 21278, 21279, 21280, 21281, 21282, 21283, 21284, 21285, 21286, 21287, 21288, 21289, 21290, 21291, 21292, 21293, 21294, 21295, 21296, 21297, 21298, 21299, 21300, 21301, 21302, 21303, 21304, 21305, 21306, 21307, 21308, 21309, 21310, 21311, 21312, 21313, 21314, 21315, 21316, 21317, 21318, 21319, 21320, 21321, 21322, 21323, 21324, 21325, 21326, 21327, 21328, 21329, 21330, 21331, 21332, 21333, 21334, 21335, 21336, 21337, 21338, 21339, 21340, 21341, 21342, 21343, 21344, 21345, 21346, 21347, 21348, 21349, 21350, 21351, 21352, 21353, 21354, 21355, 21356, 21357, 21358, 21359, 21360, 21361, 21362, 21363, 21364, 21365, 21366, 21367, 21368, 21369, 21370, 21371, 21372, 21373, 21374, 21375, 21376, 21377, 21378, 21379, 21380, 21381, 21382, 21383, 21384, 21385, 21386, 21387, 21388, 21389, 21390, 21391, 21392, 21393, 21394, 21395, 21396, 21397, 21398, 21399, 21400, 21401, 21402, 21403, 21404, 21405, 21406, 21407, 21408, 21409, 21410, 21411, 21412, 21413, 21414, 21415, 21416, 21417, 21418, 21419, 21420, 21421, 21422, 21423, 21424, 21425, 21426, 21427, 21428, 21429, 21430, 21431, 21432, 21433, 21434, 21435, 21436, 21437, 21438, 21439, 21440, 21441, 21442, 21443, 21444, 21445, 21446, 21447, 21448, 21449, 21450, 21451, 21452, 21453, 21454, 21455, 21456, 21457, 21458, 21459, 21460, 21461, 21462, 21463, 21464, 21465, 21466, 21467, 21468, 21469, 21470, 21471, 21472, 21473, 21474, 21475, 21476, 21477, 21478, 21479, 21480, 21481, 21482, 21483, 21484, 21485, 21486, 21487, 21488, 21489, 21490, 21491, 21492, 21493, 21494, 21495, 21496, 21497, 21498, 21499, 21500, 21501, 21502, 21503, 21504, 21505, 21506, 21507, 21508, 21509, 21510, 21511, 21512, 21513, 21514, 21515, 21516, 21517, 21518, 21519, 21520, 21521, 21522, 21523, 21524, 21525, 21526, 21527, 21528, 21529, 21530, 21531, 21532, 21533, 21534, 21535, 21536, 21537, 21538, 21539, 21540, 21541, 21542, 21543, 21544, 21545, 21546, 21547, 21548, 21549, 21550, 21551, 21552, 21553, 21554, 21555, 21556, 21557, 21558, 21559, 21560, 21561, 21562, 21563, 21564, 21565, 21566, 21567, 21568, 21569, 21570, 21571, 21572, 21573, 21574, 21575, 21576, 21577, 21578, 21579, 21580, 21581, 21582, 21583, 21584, 21585, 21586, 21587, 21588, 21589, 21590, 21591, 21592, 21593, 21594, 21595, 21596, 21597, 21598, 21599, 21600, 21601, 21602, 21603, 21604, 21605, 21606, 21607, 21608, 21609, 21610, 21611, 21612, 21613, 21614, 21615, 21616, 21617, 21618, 21619, 21620, 21621, 21622, 21623, 21624, 21625, 21626, 21627, 21628, 21629, 21630, 21631, 21632, 21633, 21634, 21635, 21636, 21637, 21638, 21639, 21640, 21641, 21642, 21643, 21644, 21645, 21646, 21647, 21648, 21649, 21650, 21651, 21652, 21653, 21654, 21655, 21656, 21657, 21658, 21659, 21660, 21661, 21662, 21663, 21664, 21665, 21666, 21667, 21668, 21669, 21670, 21671, 21672, 21673, 21674, 21675, 21676, 21677, 21678, 21679, 21680, 21681, 21682, 21683, 21684, 21685, 21686, 21687, 21688, 21689, 21690, 21691, 21692, 21693, 21694, 21695, 21696, 21697, 21698, 21699, 21700, 21701, 21702, 21703, 21704, 21705, 21706, 21707, 21708, 21709, 21710, 21711, 21712, 21713, 21714, 21715, 21716, 21717, 21718, 21719, 21720, 21721, 21722, 21723, 21724, 21725, 21726, 21727, 21728, 21729, 21730, 21731, 21732, 21733, 21734, 21735, 21736, 21737, 21738, 21739, 21740, 21741, 21742, 21743, 21744, 21745, 21746, 21747, 21748, 21749, 21750, 21751, 21752, 21753, 21754, 21755, 21756, 21757, 21758, 21759, 21760, 21761, 21762, 21763, 21764, 21765, 21766, 21767, 21768, 21769, 21770, 21771, 21772, 21773, 21774, 21775, 21776, 21777, 21778, 21779, 21780, 21781, 21782, 21783, 21784, 21785, 21786, 21787, 21788, 21789, 21790, 21791, 21792, 21793, 21794, 21795, 21796, 21797, 21798, 21799, 21800, 21801, 21802, 21803, 21804, 21805, 21806, 21807, 21808, 21809, 21810, 21811, 21812, 21813, 21814, 21815, 21816, 21817, 21818, 21819, 21820, 21821, 21822, 21823, 21824, 21825, 21826, 21827, 21828, 21829, 21830, 21831, 21832, 21833, 21834, 21835, 21836, 21837, 21838, 21839, 21840, 21841, 21842, 21843, 21844, 21845, 21846, 21847, 21848, 21849, 21850, 21851, 21852, 21853, 21854, 21855, 21856, 21857, 21858, 21859, 21860, 21861, 21862, 21863, 21864, 21865, 21866, 21867, 21868, 21869, 21870, 21871, 21872, 21873, 21874, 21875, 21876, 21877, 21878, 21879, 21880, 21881, 21882, 21883, 21884, 21885, 21886, 21887, 21888, 21889, 21890, 21891, 21892, 21893, 21894, 21895, 21896, 21897, 21898, 21899, 21900, 21901, 21902, 21903, 21904, 21905, 21906, 21907, 21908, 21909, 21910, 21911, 21912, 21913, 21914, 21915, 21916, 21917, 21918, 21919, 21920, 21921, 21922, 21923, 21924, 21925, 21926, 21927, 21928, 21929, 21930, 21931, 21932, 21933, 21934, 21935, 21936, 21937, 21938, 21939, 21940, 21941, 21942, 21943, 21944, 21945, 21946, 21947, 21948, 21949, 21950, 21951, 21952, 21953, 21954, 21955, 21956, 21957, 21958, 21959, 21960, 21961, 21962, 21963, 21964, 21965, 21966, 21967, 21968, 21969, 21970, 21971, 21972, 21973, 21974, 21975, 21976, 21977, 21978, 21979, 21980, 21981, 21982, 21983, 21984, 21985, 21986, 21987, 21988, 21989, 21990, 21991, 21992, 21993, 21994, 21995, 21996, 21997, 21998, 21999, 22000, 22001, 22002, 22003, 22004, 22005, 22006, 22007, 22008, 22009, 22010, 22011, 22012, 22013, 22014, 22015, 22016, 22017, 22018, 22019, 22020, 22021, 22022, 22023, 22024, 22025, 22026, 22027, 22028, 22029, 22030, 22031, 22032, 22033, 22034, 22035, 22036, 22037, 22038, 22039, 22040, 22041, 22042, 22043, 22044, 22045, 22046, 22047, 22048, 22049, 22050, 22051, 22052, 22053, 22054, 22055, 22056, 22057, 22058, 22059, 22060, 22061, 22062, 22063, 22064, 22065, 22066, 22067, 22068, 22069, 22070, 22071, 22072, 22073, 22074, 22075, 22076, 22077, 22078, 22079, 22080, 22081, 22082, 22083, 22084, 22085, 22086, 22087, 22088, 22089, 22090, 22091, 22092, 22093, 22094, 22095, 22096, 22097, 22098, 22099, 22100, 22101, 22102, 22103, 22104, 22105, 22106, 22107, 22108, 22109, 22110, 22111, 22112, 22113, 22114, 22115, 22116, 22117, 22118, 22119, 22120, 22121, 22122, 22123, 22124, 22125, 22126, 22127, 22128, 22129, 22130, 22131, 22132, 22133, 22134, 22135, 22136, 22137, 22138, 22139, 22140, 22141, 22142, 22143, 22144, 22145, 22146, 22147, 22148, 22149, 22150, 22151, 22152, 22153, 22154, 22155, 22156, 22157, 22158, 22159, 22160, 22161, 22162, 22163, 22164, 22165, 22166, 22167, 22168, 22169, 22170, 22171, 22172, 22173, 22174, 22175, 22176, 22177, 22178, 22179, 22180, 22181, 22182, 22183, 22184, 22185, 22186, 22187, 22188, 22189, 22190, 22191, 22192, 22193, 22194, 22195, 22196, 22197, 22198, 22199, 22200, 22201, 22202, 22203, 22204, 22205, 22206, 22207, 22208, 22209, 22210, 22211, 22212, 22213, 22214, 22215, 22216, 22217, 22218, 22219, 22220, 22221, 22222, 22223, 22224, 22225, 22226, 22227, 22228, 22229, 22230, 22231, 22232, 22233, 22234, 22235, 22236, 22237, 22238, 22239, 22240, 22241, 22242, 22243, 22244, 22245, 22246, 22247, 22248, 22249, 22250, 22251, 22252, 22253, 22254, 22255, 22256, 22257, 22258, 22259, 22260, 22261, 22262, 22263, 22264, 22265, 22266, 22267, 22268, 22269, 22270, 22271, 22272, 22273, 22274, 22275, 22276, 22277, 22278, 22279, 22280, 22281, 22282, 22283, 22284, 22285, 22286, 22287, 22288, 22289, 22290, 22291, 22292, 22293, 22294, 22295, 22296, 22297, 22298, 22299, 22300, 22301, 22302, 22303, 22304, 22305, 22306, 22307, 22308, 22309, 22310, 22311, 22312, 22313, 22314, 22315, 22316, 22317, 22318, 22319, 22320, 22321, 22322, 22323, 22324, 22325, 22326, 22327, 22328, 22329, 22330, 22331, 22332, 22333, 22334, 22335, 22336, 22337, 22338, 22339, 22340, 22341, 22342, 22343, 22344, 22345, 22346, 22347, 22348, 22349, 22350, 22351, 22352, 22353, 22354, 22355, 22356, 22357, 22358, 22359, 22360, 22361, 22362, 22363, 22364, 22365, 22366, 22367, 22368, 22369, 22370, 22371, 22372, 22373, 22374, 22375, 22376, 22377, 22378, 22379, 22380, 22381, 22382, 22383, 22384, 22385, 22386, 22387, 22388, 22389, 22390, 22391, 22392, 22393, 22394, 22395, 22396, 22397, 22398, 22399, 22400, 22401, 22402, 22403, 22404, 22405, 22406, 22407, 22408, 22409, 22410, 22411, 22412, 22413, 22414, 22415, 22416, 22417, 22418, 22419, 22420, 22421, 22422, 22423, 22424, 22425, 22426, 22427, 22428, 22429, 22430, 22431, 22432, 22433, 22434, 22435, 22436, 22437, 22438, 22439, 22440, 22441, 22442, 22443, 22444, 22445, 22446, 22447, 22448, 22449, 22450, 22451, 22452, 22453, 22454, 22455, 22456, 22457, 22458, 22459, 22460, 22461, 22462, 22463, 22464, 22465, 22466, 22467, 22468, 22469, 22470, 22471, 22472, 22473, 22474, 22475, 22476, 22477, 22478, 22479, 22480, 22481, 22482, 22483, 22484, 22485, 22486, 22487, 22488, 22489, 22490, 22491, 22492, 22493, 22494, 22495, 22496, 22497, 22498, 22499, 22500, 22501, 22502, 22503, 22504, 22505, 22506, 22507, 22508, 22509, 22510, 22511, 22512, 22513, 22514, 22515, 22516, 22517, 22518, 22519, 22520, 22521, 22522, 22523, 22524, 22525, 22526, 22527, 22528, 22529, 22530, 22531, 22532, 22533, 22534, 22535, 22536, 22537, 22538, 22539, 22540, 22541, 22542, 22543, 22544, 22545, 22546, 22547, 22548, 22549, 22550, 22551, 22552, 22553, 22554, 22555, 22556, 22557, 22558, 22559, 22560, 22561, 22562, 22563, 22564, 22565, 22566, 22567, 22568, 22569, 22570, 22571, 22572, 22573, 22574, 22575, 22576, 22577, 22578, 22579, 22580, 22581, 22582, 22583, 22584, 22585, 22586, 22587, 22588, 22589, 22590, 22591, 22592, 22593, 22594, 22595, 22596, 22597, 22598, 22599, 22600, 22601, 22602, 22603, 22604, 22605, 22606, 22607, 22608, 22609, 22610, 22611, 22612, 22613, 22614, 22615, 22616, 22617, 22618, 22619, 22620, 22621, 22622, 22623, 22624, 22625, 22626, 22627, 22628, 22629, 22630, 22631, 22632, 22633, 22634, 22635, 22636, 22637, 22638, 22639, 22640, 22641, 22642, 22643, 22644, 22645, 22646, 22647, 22648, 22649, 22650, 22651, 22652, 22653, 22654, 22655, 22656, 22657, 22658, 22659, 22660, 22661, 22662, 22663, 22664, 22665, 22666, 22667, 22668, 22669, 22670, 22671, 22672, 22673, 22674, 22675, 22676, 22677, 22678, 22679, 22680, 22681, 22682, 22683, 22684, 22685, 22686, 22687, 22688, 22689, 22690, 22691, 22692, 22693, 22694, 22695, 22696, 22697, 22698, 22699, 22700, 22701, 22702, 22703, 22704, 22705, 22706, 22707, 22708, 22709, 22710, 22711, 22712, 22713, 22714, 22715, 22716, 22717, 22718, 22719, 22720, 22721, 22722, 22723, 22724, 22725, 22726, 22727, 22728, 22729, 22730, 22731, 22732, 22733, 22734, 22735, 22736, 22737, 22738, 22739, 22740, 22741, 22742, 22743, 22744, 22745, 22746, 22747, 22748, 22749, 22750, 22751, 22752, 22753, 22754, 22755, 22756, 22757, 22758, 22759, 22760, 22761, 22762, 22763, 22764, 22765, 22766, 22767, 22768, 22769, 22770, 22771, 22772, 22773, 22774, 22775, 22776, 22777, 22778, 22779, 22780, 22781, 22782, 22783, 22784, 22785, 22786, 22787, 22788, 22789, 22790, 22791, 22792, 22793, 22794, 22795, 22796, 22797, 22798, 22799, 22800, 22801, 22802, 22803, 22804, 22805, 22806, 22807, 22808, 22809, 22810, 22811, 22812, 22813, 22814, 22815, 22816, 22817, 22818, 22819, 22820, 22821, 22822, 22823, 22824, 22825, 22826, 22827, 22828, 22829, 22830, 22831, 22832, 22833, 22834, 22835, 22836, 22837, 22838, 22839, 22840, 22841, 22842, 22843, 22844, 22845, 22846, 22847, 22848, 22849, 22850, 22851, 22852, 22853, 22854, 22855, 22856, 22857, 22858, 22859, 22860, 22861, 22862, 22863, 22864, 22865, 22866, 22867, 22868, 22869, 22870, 22871, 22872, 22873, 22874, 22875, 22876, 22877, 22878, 22879, 22880, 22881, 22882, 22883, 22884, 22885, 22886, 22887, 22888, 22889, 22890, 22891, 22892, 22893, 22894, 22895, 22896, 22897, 22898, 22899, 22900, 22901, 22902, 22903, 22904, 22905, 22906, 22907, 22908, 22909, 22910, 22911, 22912, 22913, 22914, 22915, 22916, 22917, 22918, 22919, 22920, 22921, 22922, 22923, 22924, 22925, 22926, 22927, 22928, 22929, 22930, 22931, 22932, 22933, 22934, 22935, 22936, 22937, 22938, 22939, 22940, 22941, 22942, 22943, 22944, 22945, 22946, 22947, 22948, 22949, 22950, 22951, 22952, 22953, 22954, 22955, 22956, 22957, 22958, 22959, 22960, 22961, 22962, 22963, 22964, 22965, 22966, 22967, 22968, 22969, 22970, 22971, 22972, 22973, 22974, 22975, 22976, 22977, 22978, 22979, 22980, 22981, 22982, 22983, 22984, 22985, 22986, 22987, 22988, 22989, 22990, 22991, 22992, 22993, 22994, 22995, 22996, 22997, 22998, 22999, 23000, 23001, 23002, 23003, 23004, 23005, 23006, 23007, 23008, 23009, 23010, 23011, 23012, 23013, 23014, 23015, 23016, 23017, 23018, 23019, 23020, 23021, 23022, 23023, 23024, 23025, 23026, 23027, 23028, 23029, 23030, 23031, 23032, 23033, 23034, 23035, 23036, 23037, 23038, 23039, 23040, 23041, 23042, 23043, 23044, 23045, 23046, 23047, 23048, 23049, 23050, 23051, 23052, 23053, 23054, 23055, 23056, 23057, 23058, 23059, 23060, 23061, 23062, 23063, 23064, 23065, 23066, 23067, 23068, 23069, 23070, 23071, 23072, 23073, 23074, 23075, 23076, 23077, 23078, 23079, 23080, 23081, 23082, 23083, 23084, 23085, 23086, 23087, 23088, 23089, 23090, 23091, 23092, 23093, 23094, 23095, 23096, 23097, 23098, 23099, 23100, 23101, 23102, 23103, 23104, 23105, 23106, 23107, 23108, 23109, 23110, 23111, 23112, 23113, 23114, 23115, 23116, 23117, 23118, 23119, 23120, 23121, 23122, 23123, 23124, 23125, 23126, 23127, 23128, 23129, 23130, 23131, 23132, 23133, 23134, 23135, 23136, 23137, 23138, 23139, 23140, 23141, 23142, 23143, 23144, 23145, 23146, 23147, 23148, 23149, 23150, 23151, 23152, 23153, 23154, 23155, 23156, 23157, 23158, 23159, 23160, 23161, 23162, 23163, 23164, 23165, 23166, 23167, 23168, 23169, 23170, 23171, 23172, 23173, 23174, 23175, 23176, 23177, 23178, 23179, 23180, 23181, 23182, 23183, 23184, 23185, 23186, 23187, 23188, 23189, 23190, 23191, 23192, 23193, 23194, 23195, 23196, 23197, 23198, 23199, 23200, 23201, 23202, 23203, 23204, 23205, 23206, 23207, 23208, 23209, 23210, 23211, 23212, 23213, 23214, 23215, 23216, 23217, 23218, 23219, 23220, 23221, 23222, 23223, 23224, 23225, 23226, 23227, 23228, 23229, 23230, 23231, 23232, 23233, 23234, 23235, 23236, 23237, 23238, 23239, 23240, 23241, 23242, 23243, 23244, 23245, 23246, 23247, 23248, 23249, 23250, 23251, 23252, 23253, 23254, 23255, 23256, 23257, 23258, 23259, 23260, 23261, 23262, 23263, 23264, 23265, 23266, 23267, 23268, 23269, 23270, 23271, 23272, 23273, 23274, 23275, 23276, 23277, 23278, 23279, 23280, 23281, 23282, 23283, 23284, 23285, 23286, 23287, 23288, 23289, 23290, 23291, 23292, 23293, 23294, 23295, 23296, 23297, 23298, 23299, 23300, 23301, 23302, 23303, 23304, 23305, 23306, 23307, 23308, 23309, 23310, 23311, 23312, 23313, 23314, 23315, 23316, 23317, 23318, 23319, 23320, 23321, 23322, 23323, 23324, 23325, 23326, 23327, 23328, 23329, 23330, 23331, 23332, 23333, 23334, 23335, 23336, 23337, 23338, 23339, 23340, 23341, 23342, 23343, 23344, 23345, 23346, 23347, 23348, 23349, 23350, 23351, 23352, 23353, 23354, 23355, 23356, 23357, 23358, 23359, 23360, 23361, 23362, 23363, 23364, 23365, 23366, 23367, 23368, 23369, 23370, 23371, 23372, 23373, 23374, 23375, 23376, 23377, 23378, 23379, 23380, 23381, 23382, 23383, 23384, 23385, 23386, 23387, 23388, 23389, 23390, 23391, 23392, 23393, 23394, 23395, 23396, 23397, 23398, 23399, 23400, 23401, 23402, 23403, 23404, 23405, 23406, 23407, 23408, 23409, 23410, 23411, 23412, 23413, 23414, 23415, 23416, 23417, 23418, 23419, 23420, 23421, 23422, 23423, 23424, 23425, 23426, 23427, 23428, 23429, 23430, 23431, 23432, 23433, 23434, 23435, 23436, 23437, 23438, 23439, 23440, 23441, 23442, 23443, 23444, 23445, 23446, 23447, 23448, 23449, 23450, 23451, 23452, 23453, 23454, 23455, 23456, 23457, 23458, 23459, 23460, 23461, 23462, 23463, 23464, 23465, 23466, 23467, 23468, 23469, 23470, 23471, 23472, 23473, 23474, 23475, 23476, 23477, 23478, 23479, 23480, 23481, 23482, 23483, 23484, 23485, 23486, 23487, 23488, 23489, 23490, 23491, 23492, 23493, 23494, 23495, 23496, 23497, 23498, 23499, 23500, 23501, 23502, 23503, 23504, 23505, 23506, 23507, 23508, 23509, 23510, 23511, 23512, 23513, 23514, 23515, 23516, 23517, 23518, 23519, 23520, 23521, 23522, 23523, 23524, 23525, 23526, 23527, 23528, 23529, 23530, 23531, 23532, 23533, 23534, 23535, 23536, 23537, 23538, 23539, 23540, 23541, 23542, 23543, 23544, 23545, 23546, 23547, 23548, 23549, 23550, 23551, 23552, 23553, 23554, 23555, 23556, 23557, 23558, 23559, 23560, 23561, 23562, 23563, 23564, 23565, 23566, 23567, 23568, 23569, 23570, 23571, 23572, 23573, 23574, 23575, 23576, 23577, 23578, 23579, 23580, 23581, 23582, 23583, 23584, 23585, 23586, 23587, 23588, 23589, 23590, 23591, 23592, 23593, 23594, 23595, 23596, 23597, 23598, 23599, 23600, 23601, 23602, 23603, 23604, 23605, 23606, 23607, 23608, 23609, 23610, 23611, 23612, 23613, 23614, 23615, 23616, 23617, 23618, 23619, 23620, 23621, 23622, 23623, 23624, 23625, 23626, 23627, 23628, 23629, 23630, 23631, 23632, 23633, 23634, 23635, 23636, 23637, 23638, 23639, 23640, 23641, 23642, 23643, 23644, 23645, 23646, 23647, 23648, 23649, 23650, 23651, 23652, 23653, 23654, 23655, 23656, 23657, 23658, 23659, 23660, 23661, 23662, 23663, 23664, 23665, 23666, 23667, 23668, 23669, 23670, 23671, 23672, 23673, 23674, 23675, 23676, 23677, 23678, 23679, 23680, 23681, 23682, 23683, 23684, 23685, 23686, 23687, 23688, 23689, 23690, 23691, 23692, 23693, 23694, 23695, 23696, 23697, 23698, 23699, 23700, 23701, 23702, 23703, 23704, 23705, 23706, 23707, 23708, 23709, 23710, 23711, 23712, 23713, 23714, 23715, 23716, 23717, 23718, 23719, 23720, 23721, 23722, 23723, 23724, 23725, 23726, 23727, 23728, 23729, 23730, 23731, 23732, 23733, 23734, 23735, 23736, 23737, 23738, 23739, 23740, 23741, 23742, 23743, 23744, 23745, 23746, 23747, 23748, 23749, 23750, 23751, 23752, 23753, 23754, 23755, 23756, 23757, 23758, 23759, 23760, 23761, 23762, 23763, 23764, 23765, 23766, 23767, 23768, 23769, 23770, 23771, 23772, 23773, 23774, 23775, 23776, 23777, 23778, 23779, 23780, 23781, 23782, 23783, 23784, 23785, 23786, 23787, 23788, 23789, 23790, 23791, 23792, 23793, 23794, 23795, 23796, 23797, 23798, 23799, 23800, 23801, 23802, 23803, 23804, 23805, 23806, 23807, 23808, 23809, 23810, 23811, 23812, 23813, 23814, 23815, 23816, 23817, 23818, 23819, 23820, 23821, 23822, 23823, 23824, 23825, 23826, 23827, 23828, 23829, 23830, 23831, 23832, 23833, 23834, 23835, 23836, 23837, 23838, 23839, 23840, 23841, 23842, 23843, 23844, 23845, 23846, 23847, 23848, 23849, 23850, 23851, 23852, 23853, 23854, 23855, 23856, 23857, 23858, 23859, 23860, 23861, 23862, 23863, 23864, 23865, 23866, 23867, 23868, 23869, 23870, 23871, 23872, 23873, 23874, 23875, 23876, 23877, 23878, 23879, 23880, 23881, 23882, 23883, 23884, 23885, 23886, 23887, 23888, 23889, 23890, 23891, 23892, 23893, 23894, 23895, 23896, 23897, 23898, 23899, 23900, 23901, 23902, 23903, 23904, 23905, 23906, 23907, 23908, 23909, 23910, 23911, 23912, 23913, 23914, 23915, 23916, 23917, 23918, 23919, 23920, 23921, 23922, 23923, 23924, 23925, 23926, 23927, 23928, 23929, 23930, 23931, 23932, 23933, 23934, 23935, 23936, 23937, 23938, 23939, 23940, 23941, 23942, 23943, 23944, 23945, 23946, 23947, 23948, 23949, 23950, 23951, 23952, 23953, 23954, 23955, 23956, 23957, 23958, 23959, 23960, 23961, 23962, 23963, 23964, 23965, 23966, 23967, 23968, 23969, 23970, 23971, 23972, 23973, 23974, 23975, 23976, 23977, 23978, 23979, 23980, 23981, 23982, 23983, 23984, 23985, 23986, 23987, 23988, 23989, 23990, 23991, 23992, 23993, 23994, 23995, 23996, 23997, 23998, 23999, 24000, 24001, 24002, 24003, 24004, 24005, 24006, 24007, 24008, 24009, 24010, 24011, 24012, 24013, 24014, 24015, 24016, 24017, 24018, 24019, 24020, 24021, 24022, 24023, 24024, 24025, 24026, 24027, 24028, 24029, 24030, 24031, 24032, 24033, 24034, 24035, 24036, 24037, 24038, 24039, 24040, 24041, 24042, 24043, 24044, 24045, 24046, 24047, 24048, 24049, 24050, 24051, 24052, 24053, 24054, 24055, 24056, 24057, 24058, 24059, 24060, 24061, 24062, 24063, 24064, 24065, 24066, 24067, 24068, 24069, 24070, 24071, 24072, 24073, 24074, 24075, 24076, 24077, 24078, 24079, 24080, 24081, 24082, 24083, 24084, 24085, 24086, 24087, 24088, 24089, 24090, 24091, 24092, 24093, 24094, 24095, 24096, 24097, 24098, 24099, 24100, 24101, 24102, 24103, 24104, 24105, 24106, 24107, 24108, 24109, 24110, 24111, 24112, 24113, 24114, 24115, 24116, 24117, 24118, 24119, 24120, 24121, 24122, 24123, 24124, 24125, 24126, 24127, 24128, 24129, 24130, 24131, 24132, 24133, 24134, 24135, 24136, 24137, 24138, 24139, 24140, 24141, 24142, 24143, 24144, 24145, 24146, 24147, 24148, 24149, 24150, 24151, 24152, 24153, 24154, 24155, 24156, 24157, 24158, 24159, 24160, 24161, 24162, 24163, 24164, 24165, 24166, 24167, 24168, 24169, 24170, 24171, 24172, 24173, 24174, 24175, 24176, 24177, 24178, 24179, 24180, 24181, 24182, 24183, 24184, 24185, 24186, 24187, 24188, 24189, 24190, 24191, 24192, 24193, 24194, 24195, 24196, 24197, 24198, 24199, 24200, 24201, 24202, 24203, 24204, 24205, 24206, 24207, 24208, 24209, 24210, 24211, 24212, 24213, 24214, 24215, 24216, 24217, 24218, 24219, 24220, 24221, 24222, 24223, 24224, 24225, 24226, 24227, 24228, 24229, 24230, 24231, 24232, 24233, 24234, 24235, 24236, 24237, 24238, 24239, 24240, 24241, 24242, 24243, 24244, 24245, 24246, 24247, 24248, 24249, 24250, 24251, 24252, 24253, 24254, 24255, 24256, 24257, 24258, 24259, 24260, 24261, 24262, 24263, 24264, 24265, 24266, 24267, 24268, 24269, 24270, 24271, 24272, 24273, 24274, 24275, 24276, 24277, 24278, 24279, 24280, 24281, 24282, 24283, 24284, 24285, 24286, 24287, 24288, 24289, 24290, 24291, 24292, 24293, 24294, 24295, 24296, 24297, 24298, 24299, 24300, 24301, 24302, 24303, 24304, 24305, 24306, 24307, 24308, 24309, 24310, 24311, 24312, 24313, 24314, 24315, 24316, 24317, 24318, 24319, 24320, 24321, 24322, 24323, 24324, 24325, 24326, 24327, 24328, 24329, 24330, 24331, 24332, 24333, 24334, 24335, 24336, 24337, 24338, 24339, 24340, 24341, 24342, 24343, 24344, 24345, 24346, 24347, 24348, 24349, 24350, 24351, 24352, 24353, 24354, 24355, 24356, 24357, 24358, 24359, 24360, 24361, 24362, 24363, 24364, 24365, 24366, 24367, 24368, 24369, 24370, 24371, 24372, 24373, 24374, 24375, 24376, 24377, 24378, 24379, 24380, 24381, 24382, 24383, 24384, 24385, 24386, 24387, 24388, 24389, 24390, 24391, 24392, 24393, 24394, 24395, 24396, 24397, 24398, 24399, 24400, 24401, 24402, 24403, 24404, 24405, 24406, 24407, 24408, 24409, 24410, 24411, 24412, 24413, 24414, 24415, 24416, 24417, 24418, 24419, 24420, 24421, 24422, 24423, 24424, 24425, 24426, 24427, 24428, 24429, 24430, 24431, 24432, 24433, 24434, 24435, 24436, 24437, 24438, 24439, 24440, 24441, 24442, 24443, 24444, 24445, 24446, 24447, 24448, 24449, 24450, 24451, 24452, 24453, 24454, 24455, 24456, 24457, 24458, 24459, 24460, 24461, 24462, 24463, 24464, 24465, 24466, 24467, 24468, 24469, 24470, 24471, 24472, 24473, 24474, 24475, 24476, 24477, 24478, 24479, 24480, 24481, 24482, 24483, 24484, 24485, 24486, 24487, 24488, 24489, 24490, 24491, 24492, 24493, 24494, 24495, 24496, 24497, 24498, 24499, 24500, 24501, 24502, 24503, 24504, 24505, 24506, 24507, 24508, 24509, 24510, 24511, 24512, 24513, 24514, 24515, 24516, 24517, 24518, 24519, 24520, 24521, 24522, 24523, 24524, 24525, 24526, 24527, 24528, 24529, 24530, 24531, 24532, 24533, 24534, 24535, 24536, 24537, 24538, 24539, 24540, 24541, 24542, 24543, 24544, 24545, 24546, 24547, 24548, 24549, 24550, 24551, 24552, 24553, 24554, 24555, 24556, 24557, 24558, 24559, 24560, 24561, 24562, 24563, 24564, 24565, 24566, 24567, 24568, 24569, 24570, 24571, 24572, 24573, 24574, 24575, 24576, 24577, 24578, 24579, 24580, 24581, 24582, 24583, 24584, 24585, 24586, 24587, 24588, 24589, 24590, 24591, 24592, 24593, 24594, 24595, 24596, 24597, 24598, 24599, 24600, 24601, 24602, 24603, 24604, 24605, 24606, 24607, 24608, 24609, 24610, 24611, 24612, 24613, 24614, 24615, 24616, 24617, 24618, 24619, 24620, 24621, 24622, 24623, 24624, 24625, 24626, 24627, 24628, 24629, 24630, 24631, 24632, 24633, 24634, 24635, 24636, 24637, 24638, 24639, 24640, 24641, 24642, 24643, 24644, 24645, 24646, 24647, 24648, 24649, 24650, 24651, 24652, 24653, 24654, 24655, 24656, 24657, 24658, 24659, 24660, 24661, 24662, 24663, 24664, 24665, 24666, 24667, 24668, 24669, 24670, 24671, 24672, 24673, 24674, 24675, 24676, 24677, 24678, 24679, 24680, 24681, 24682, 24683, 24684, 24685, 24686, 24687, 24688, 24689, 24690, 24691, 24692, 24693, 24694, 24695, 24696, 24697, 24698, 24699, 24700, 24701, 24702, 24703, 24704, 24705, 24706, 24707, 24708, 24709, 24710, 24711, 24712, 24713, 24714, 24715, 24716, 24717, 24718, 24719, 24720, 24721, 24722, 24723, 24724, 24725, 24726, 24727, 24728, 24729, 24730, 24731, 24732, 24733, 24734, 24735, 24736, 24737, 24738, 24739, 24740, 24741, 24742, 24743, 24744, 24745, 24746, 24747, 24748, 24749, 24750, 24751, 24752, 24753, 24754, 24755, 24756, 24757, 24758, 24759, 24760, 24761, 24762, 24763, 24764, 24765, 24766, 24767, 24768, 24769, 24770, 24771, 24772, 24773, 24774, 24775, 24776, 24777, 24778, 24779, 24780, 24781, 24782, 24783, 24784, 24785, 24786, 24787, 24788, 24789, 24790, 24791, 24792, 24793, 24794, 24795, 24796, 24797, 24798, 24799, 24800, 24801, 24802, 24803, 24804, 24805, 24806, 24807, 24808, 24809, 24810, 24811, 24812, 24813, 24814, 24815, 24816, 24817, 24818, 24819, 24820, 24821, 24822, 24823, 24824, 24825, 24826, 24827, 24828, 24829, 24830, 24831, 24832, 24833, 24834, 24835, 24836, 24837, 24838, 24839, 24840, 24841, 24842, 24843, 24844, 24845, 24846, 24847, 24848, 24849, 24850, 24851, 24852, 24853, 24854, 24855, 24856, 24857, 24858, 24859, 24860, 24861, 24862, 24863, 24864, 24865, 24866, 24867, 24868, 24869, 24870, 24871, 24872, 24873, 24874, 24875, 24876, 24877, 24878, 24879, 24880, 24881, 24882, 24883, 24884, 24885, 24886, 24887, 24888, 24889, 24890, 24891, 24892, 24893, 24894, 24895, 24896, 24897, 24898, 24899, 24900, 24901, 24902, 24903, 24904, 24905, 24906, 24907, 24908, 24909, 24910, 24911, 24912, 24913, 24914, 24915, 24916, 24917, 24918, 24919, 24920, 24921, 24922, 24923, 24924, 24925, 24926, 24927, 24928, 24929, 24930, 24931, 24932, 24933, 24934, 24935, 24936, 24937, 24938, 24939, 24940, 24941, 24942, 24943, 24944, 24945, 24946, 24947, 24948, 24949, 24950, 24951, 24952, 24953, 24954, 24955, 24956, 24957, 24958, 24959, 24960, 24961, 24962, 24963, 24964, 24965, 24966, 24967, 24968, 24969, 24970, 24971, 24972, 24973, 24974, 24975, 24976, 24977, 24978, 24979, 24980, 24981, 24982, 24983, 24984, 24985, 24986, 24987, 24988, 24989, 24990, 24991, 24992, 24993, 24994, 24995, 24996, 24997, 24998, 24999, 25000, 25001, 25002, 25003, 25004, 25005, 25006, 25007, 25008, 25009, 25010, 25011, 25012, 25013, 25014, 25015, 25016, 25017, 25018, 25019, 25020, 25021, 25022, 25023, 25024, 25025, 25026, 25027, 25028, 25029, 25030, 25031, 25032, 25033, 25034, 25035, 25036, 25037, 25038, 25039, 25040, 25041, 25042, 25043, 25044, 25045, 25046, 25047, 25048, 25049, 25050, 25051, 25052, 25053, 25054, 25055, 25056, 25057, 25058, 25059, 25060, 25061, 25062, 25063, 25064, 25065, 25066, 25067, 25068, 25069, 25070, 25071, 25072, 25073, 25074, 25075, 25076, 25077, 25078, 25079, 25080, 25081, 25082, 25083, 25084, 25085, 25086, 25087, 25088, 25089, 25090, 25091, 25092, 25093, 25094, 25095, 25096, 25097, 25098, 25099, 25100, 25101, 25102, 25103, 25104, 25105, 25106, 25107, 25108, 25109, 25110, 25111, 25112, 25113, 25114, 25115, 25116, 25117, 25118, 25119, 25120, 25121, 25122, 25123, 25124, 25125, 25126, 25127, 25128, 25129, 25130, 25131, 25132, 25133, 25134, 25135, 25136, 25137, 25138, 25139, 25140, 25141, 25142, 25143, 25144, 25145, 25146, 25147, 25148, 25149, 25150, 25151, 25152, 25153, 25154, 25155, 25156, 25157, 25158, 25159, 25160, 25161, 25162, 25163, 25164, 25165, 25166, 25167, 25168, 25169, 25170, 25171, 25172, 25173, 25174, 25175, 25176, 25177, 25178, 25179, 25180, 25181, 25182, 25183, 25184, 25185, 25186, 25187, 25188, 25189, 25190, 25191, 25192, 25193, 25194, 25195, 25196, 25197, 25198, 25199, 25200, 25201, 25202, 25203, 25204, 25205, 25206, 25207, 25208, 25209, 25210, 25211, 25212, 25213, 25214, 25215, 25216, 25217, 25218, 25219, 25220, 25221, 25222, 25223, 25224, 25225, 25226, 25227, 25228, 25229, 25230, 25231, 25232, 25233, 25234, 25235, 25236, 25237, 25238, 25239, 25240, 25241, 25242, 25243, 25244, 25245, 25246, 25247, 25248, 25249, 25250, 25251, 25252, 25253, 25254, 25255, 25256, 25257, 25258, 25259, 25260, 25261, 25262, 25263, 25264, 25265, 25266, 25267, 25268, 25269, 25270, 25271, 25272, 25273, 25274, 25275, 25276, 25277, 25278, 25279, 25280, 25281, 25282, 25283, 25284, 25285, 25286, 25287, 25288, 25289, 25290, 25291, 25292, 25293, 25294, 25295, 25296, 25297, 25298, 25299, 25300, 25301, 25302, 25303, 25304, 25305, 25306, 25307, 25308, 25309, 25310, 25311, 25312, 25313, 25314, 25315, 25316, 25317, 25318, 25319, 25320, 25321, 25322, 25323, 25324, 25325, 25326, 25327, 25328, 25329, 25330, 25331, 25332, 25333, 25334, 25335, 25336, 25337, 25338, 25339, 25340, 25341, 25342, 25343, 25344, 25345, 25346, 25347, 25348, 25349, 25350, 25351, 25352, 25353, 25354, 25355, 25356, 25357, 25358, 25359, 25360, 25361, 25362, 25363, 25364, 25365, 25366, 25367, 25368, 25369, 25370, 25371, 25372, 25373, 25374, 25375, 25376, 25377, 25378, 25379, 25380, 25381, 25382, 25383, 25384, 25385, 25386, 25387, 25388, 25389, 25390, 25391, 25392, 25393, 25394, 25395, 25396, 25397, 25398, 25399, 25400, 25401, 25402, 25403, 25404, 25405, 25406, 25407, 25408, 25409, 25410, 25411, 25412, 25413, 25414, 25415, 25416, 25417, 25418, 25419, 25420, 25421, 25422, 25423, 25424, 25425, 25426, 25427, 25428, 25429, 25430, 25431, 25432, 25433, 25434, 25435, 25436, 25437, 25438, 25439, 25440, 25441, 25442, 25443, 25444, 25445, 25446, 25447, 25448, 25449, 25450, 25451, 25452, 25453, 25454, 25455, 25456, 25457, 25458, 25459, 25460, 25461, 25462, 25463, 25464, 25465, 25466, 25467, 25468, 25469, 25470, 25471, 25472, 25473, 25474, 25475, 25476, 25477, 25478, 25479, 25480, 25481, 25482, 25483, 25484, 25485, 25486, 25487, 25488, 25489, 25490, 25491, 25492, 25493, 25494, 25495, 25496, 25497, 25498, 25499, 25500, 25501, 25502, 25503, 25504, 25505, 25506, 25507, 25508, 25509, 25510, 25511, 25512, 25513, 25514, 25515, 25516, 25517, 25518, 25519, 25520, 25521, 25522, 25523, 25524, 25525, 25526, 25527, 25528, 25529, 25530, 25531, 25532, 25533, 25534, 25535, 25536, 25537, 25538, 25539, 25540, 25541, 25542, 25543, 25544, 25545, 25546, 25547, 25548, 25549, 25550, 25551, 25552, 25553, 25554, 25555, 25556, 25557, 25558, 25559, 25560, 25561, 25562, 25563, 25564, 25565, 25566, 25567, 25568, 25569, 25570, 25571, 25572, 25573, 25574, 25575, 25576, 25577, 25578, 25579, 25580, 25581, 25582, 25583, 25584, 25585, 25586, 25587, 25588, 25589, 25590, 25591, 25592, 25593, 25594, 25595, 25596, 25597, 25598, 25599, 25600, 25601, 25602, 25603, 25604, 25605, 25606, 25607, 25608, 25609, 25610, 25611, 25612, 25613, 25614, 25615, 25616, 25617, 25618, 25619, 25620, 25621, 25622, 25623, 25624, 25625, 25626, 25627, 25628, 25629, 25630, 25631, 25632, 25633, 25634, 25635, 25636, 25637, 25638, 25639, 25640, 25641, 25642, 25643, 25644, 25645, 25646, 25647, 25648, 25649, 25650, 25651, 25652, 25653, 25654, 25655, 25656, 25657, 25658, 25659, 25660, 25661, 25662, 25663, 25664, 25665, 25666, 25667, 25668, 25669, 25670, 25671, 25672, 25673, 25674, 25675, 25676, 25677, 25678, 25679, 25680, 25681, 25682, 25683, 25684, 25685, 25686, 25687, 25688, 25689, 25690, 25691, 25692, 25693, 25694, 25695, 25696, 25697, 25698, 25699, 25700, 25701, 25702, 25703, 25704, 25705, 25706, 25707, 25708, 25709, 25710, 25711, 25712, 25713, 25714, 25715, 25716, 25717, 25718, 25719, 25720, 25721, 25722, 25723, 25724, 25725, 25726, 25727, 25728, 25729, 25730, 25731, 25732, 25733, 25734, 25735, 25736, 25737, 25738, 25739, 25740, 25741, 25742, 25743, 25744, 25745, 25746, 25747, 25748, 25749, 25750, 25751, 25752, 25753, 25754, 25755, 25756, 25757, 25758, 25759, 25760, 25761, 25762, 25763, 25764, 25765, 25766, 25767, 25768, 25769, 25770, 25771, 25772, 25773, 25774, 25775, 25776, 25777, 25778, 25779, 25780, 25781, 25782, 25783, 25784, 25785, 25786, 25787, 25788, 25789, 25790, 25791, 25792, 25793, 25794, 25795, 25796, 25797, 25798, 25799, 25800, 25801, 25802, 25803, 25804, 25805, 25806, 25807, 25808, 25809, 25810, 25811, 25812, 25813, 25814, 25815, 25816, 25817, 25818, 25819, 25820, 25821, 25822, 25823, 25824, 25825, 25826, 25827, 25828, 25829, 25830, 25831, 25832, 25833, 25834, 25835, 25836, 25837, 25838, 25839, 25840, 25841, 25842, 25843, 25844, 25845, 25846, 25847, 25848, 25849, 25850, 25851, 25852, 25853, 25854, 25855, 25856, 25857, 25858, 25859, 25860, 25861, 25862, 25863, 25864, 25865, 25866, 25867, 25868, 25869, 25870, 25871, 25872, 25873, 25874, 25875, 25876, 25877, 25878, 25879, 25880, 25881, 25882, 25883, 25884, 25885, 25886, 25887, 25888, 25889, 25890, 25891, 25892, 25893, 25894, 25895, 25896, 25897, 25898, 25899, 25900, 25901, 25902, 25903, 25904, 25905, 25906, 25907, 25908, 25909, 25910, 25911, 25912, 25913, 25914, 25915, 25916, 25917, 25918, 25919, 25920, 25921, 25922, 25923, 25924, 25925, 25926, 25927, 25928, 25929, 25930, 25931, 25932, 25933, 25934, 25935, 25936, 25937, 25938, 25939, 25940, 25941, 25942, 25943, 25944, 25945, 25946, 25947, 25948, 25949, 25950, 25951, 25952, 25953, 25954, 25955, 25956, 25957, 25958, 25959, 25960, 25961, 25962, 25963, 25964, 25965, 25966, 25967, 25968, 25969, 25970, 25971, 25972, 25973, 25974, 25975, 25976, 25977, 25978, 25979, 25980, 25981, 25982, 25983, 25984, 25985, 25986, 25987, 25988, 25989, 25990, 25991, 25992, 25993, 25994, 25995, 25996, 25997, 25998, 25999, 26000, 26001, 26002, 26003, 26004, 26005, 26006, 26007, 26008, 26009, 26010, 26011, 26012, 26013, 26014, 26015, 26016, 26017, 26018, 26019, 26020, 26021, 26022, 26023, 26024, 26025, 26026, 26027, 26028, 26029, 26030, 26031, 26032, 26033, 26034, 26035, 26036, 26037, 26038, 26039, 26040, 26041, 26042, 26043, 26044, 26045, 26046, 26047, 26048, 26049, 26050, 26051, 26052, 26053, 26054, 26055, 26056, 26057, 26058, 26059, 26060, 26061, 26062, 26063, 26064, 26065, 26066, 26067, 26068, 26069, 26070, 26071, 26072, 26073, 26074, 26075, 26076, 26077, 26078, 26079, 26080, 26081, 26082, 26083, 26084, 26085, 26086, 26087, 26088, 26089, 26090, 26091, 26092, 26093, 26094, 26095, 26096, 26097, 26098, 26099, 26100, 26101, 26102, 26103, 26104, 26105, 26106, 26107, 26108, 26109, 26110, 26111, 26112, 26113, 26114, 26115, 26116, 26117, 26118, 26119, 26120, 26121, 26122, 26123, 26124, 26125, 26126, 26127, 26128, 26129, 26130, 26131, 26132, 26133, 26134, 26135, 26136, 26137, 26138, 26139, 26140, 26141, 26142, 26143, 26144, 26145, 26146, 26147, 26148, 26149, 26150, 26151, 26152, 26153, 26154, 26155, 26156, 26157, 26158, 26159, 26160, 26161, 26162, 26163, 26164, 26165, 26166, 26167, 26168, 26169, 26170, 26171, 26172, 26173, 26174, 26175, 26176, 26177, 26178, 26179, 26180, 26181, 26182, 26183, 26184, 26185, 26186, 26187, 26188, 26189, 26190, 26191, 26192, 26193, 26194, 26195, 26196, 26197, 26198, 26199, 26200, 26201, 26202, 26203, 26204, 26205, 26206, 26207, 26208, 26209, 26210, 26211, 26212, 26213, 26214, 26215, 26216, 26217, 26218, 26219, 26220, 26221, 26222, 26223, 26224, 26225, 26226, 26227, 26228, 26229, 26230, 26231, 26232, 26233, 26234, 26235, 26236, 26237, 26238, 26239, 26240, 26241, 26242, 26243, 26244, 26245, 26246, 26247, 26248, 26249, 26250, 26251, 26252, 26253, 26254, 26255, 26256, 26257, 26258, 26259, 26260, 26261, 26262, 26263, 26264, 26265, 26266, 26267, 26268, 26269, 26270, 26271, 26272, 26273, 26274, 26275, 26276, 26277, 26278, 26279, 26280, 26281, 26282, 26283, 26284, 26285, 26286, 26287, 26288, 26289, 26290, 26291, 26292, 26293, 26294, 26295, 26296, 26297, 26298, 26299, 26300, 26301, 26302, 26303, 26304, 26305, 26306, 26307, 26308, 26309, 26310, 26311, 26312, 26313, 26314, 26315, 26316, 26317, 26318, 26319, 26320, 26321, 26322, 26323, 26324, 26325, 26326, 26327, 26328, 26329, 26330, 26331, 26332, 26333, 26334, 26335, 26336, 26337, 26338, 26339, 26340, 26341, 26342, 26343, 26344, 26345, 26346, 26347, 26348, 26349, 26350, 26351, 26352, 26353, 26354, 26355, 26356, 26357, 26358, 26359, 26360, 26361, 26362, 26363, 26364, 26365, 26366, 26367, 26368, 26369, 26370, 26371, 26372, 26373, 26374, 26375, 26376, 26377, 26378, 26379, 26380, 26381, 26382, 26383, 26384, 26385, 26386, 26387, 26388, 26389, 26390, 26391, 26392, 26393, 26394, 26395, 26396, 26397, 26398, 26399, 26400, 26401, 26402, 26403, 26404, 26405, 26406, 26407, 26408, 26409, 26410, 26411, 26412, 26413, 26414, 26415, 26416, 26417, 26418, 26419, 26420, 26421, 26422, 26423, 26424, 26425, 26426, 26427, 26428, 26429, 26430, 26431, 26432, 26433, 26434, 26435, 26436, 26437, 26438, 26439, 26440, 26441, 26442, 26443, 26444, 26445, 26446, 26447, 26448, 26449, 26450, 26451, 26452, 26453, 26454, 26455, 26456, 26457, 26458, 26459, 26460, 26461, 26462, 26463, 26464, 26465, 26466, 26467, 26468, 26469, 26470, 26471, 26472, 26473, 26474, 26475, 26476, 26477, 26478, 26479, 26480, 26481, 26482, 26483, 26484, 26485, 26486, 26487, 26488, 26489, 26490, 26491, 26492, 26493, 26494, 26495, 26496, 26497, 26498, 26499, 26500, 26501, 26502, 26503, 26504, 26505, 26506, 26507, 26508, 26509, 26510, 26511, 26512, 26513, 26514, 26515, 26516, 26517, 26518, 26519, 26520, 26521, 26522, 26523, 26524, 26525, 26526, 26527, 26528, 26529, 26530, 26531, 26532, 26533, 26534, 26535, 26536, 26537, 26538, 26539, 26540, 26541, 26542, 26543, 26544, 26545, 26546, 26547, 26548, 26549, 26550, 26551, 26552, 26553, 26554, 26555, 26556, 26557, 26558, 26559, 26560, 26561, 26562, 26563, 26564, 26565, 26566, 26567, 26568, 26569, 26570, 26571, 26572, 26573, 26574, 26575, 26576, 26577, 26578, 26579, 26580, 26581, 26582, 26583, 26584, 26585, 26586, 26587, 26588, 26589, 26590, 26591, 26592, 26593, 26594, 26595, 26596, 26597, 26598, 26599, 26600, 26601, 26602, 26603, 26604, 26605, 26606, 26607, 26608, 26609, 26610, 26611, 26612, 26613, 26614, 26615, 26616, 26617, 26618, 26619, 26620, 26621, 26622, 26623, 26624, 26625, 26626, 26627, 26628, 26629, 26630, 26631, 26632, 26633, 26634, 26635, 26636, 26637, 26638, 26639, 26640, 26641, 26642, 26643, 26644, 26645, 26646, 26647, 26648, 26649, 26650, 26651, 26652, 26653, 26654, 26655, 26656, 26657, 26658, 26659, 26660, 26661, 26662, 26663, 26664, 26665, 26666, 26667, 26668, 26669, 26670, 26671, 26672, 26673, 26674, 26675, 26676, 26677, 26678, 26679, 26680, 26681, 26682, 26683, 26684, 26685, 26686, 26687, 26688, 26689, 26690, 26691, 26692, 26693, 26694, 26695, 26696, 26697, 26698, 26699, 26700, 26701, 26702, 26703, 26704, 26705, 26706, 26707, 26708, 26709, 26710, 26711, 26712, 26713, 26714, 26715, 26716, 26717, 26718, 26719, 26720, 26721, 26722, 26723, 26724, 26725, 26726, 26727, 26728, 26729, 26730, 26731, 26732, 26733, 26734, 26735, 26736, 26737, 26738, 26739, 26740, 26741, 26742, 26743, 26744, 26745, 26746, 26747, 26748, 26749, 26750, 26751, 26752, 26753, 26754, 26755, 26756, 26757, 26758, 26759, 26760, 26761, 26762, 26763, 26764, 26765, 26766, 26767, 26768, 26769, 26770, 26771, 26772, 26773, 26774, 26775, 26776, 26777, 26778, 26779, 26780, 26781, 26782, 26783, 26784, 26785, 26786, 26787, 26788, 26789, 26790, 26791, 26792, 26793, 26794, 26795, 26796, 26797, 26798, 26799, 26800, 26801, 26802, 26803, 26804, 26805, 26806, 26807, 26808, 26809, 26810, 26811, 26812, 26813, 26814, 26815, 26816, 26817, 26818, 26819, 26820, 26821, 26822, 26823, 26824, 26825, 26826, 26827, 26828, 26829, 26830, 26831, 26832, 26833, 26834, 26835, 26836, 26837, 26838, 26839, 26840, 26841, 26842, 26843, 26844, 26845, 26846, 26847, 26848, 26849, 26850, 26851, 26852, 26853, 26854, 26855, 26856, 26857, 26858, 26859, 26860, 26861, 26862, 26863, 26864, 26865, 26866, 26867, 26868, 26869, 26870, 26871, 26872, 26873, 26874, 26875, 26876, 26877, 26878, 26879, 26880, 26881, 26882, 26883, 26884, 26885, 26886, 26887, 26888, 26889, 26890, 26891, 26892, 26893, 26894, 26895, 26896, 26897, 26898, 26899, 26900, 26901, 26902, 26903, 26904, 26905, 26906, 26907, 26908, 26909, 26910, 26911, 26912, 26913, 26914, 26915, 26916, 26917, 26918, 26919, 26920, 26921, 26922, 26923, 26924, 26925, 26926, 26927, 26928, 26929, 26930, 26931, 26932, 26933, 26934, 26935, 26936, 26937, 26938, 26939, 26940, 26941, 26942, 26943, 26944, 26945, 26946, 26947, 26948, 26949, 26950, 26951, 26952, 26953, 26954, 26955, 26956, 26957, 26958, 26959, 26960, 26961, 26962, 26963, 26964, 26965, 26966, 26967, 26968, 26969, 26970, 26971, 26972, 26973, 26974, 26975, 26976, 26977, 26978, 26979, 26980, 26981, 26982, 26983, 26984, 26985, 26986, 26987, 26988, 26989, 26990, 26991, 26992, 26993, 26994, 26995, 26996, 26997, 26998, 26999, 27000, 27001, 27002, 27003, 27004, 27005, 27006, 27007, 27008, 27009, 27010, 27011, 27012, 27013, 27014, 27015, 27016, 27017, 27018, 27019, 27020, 27021, 27022, 27023, 27024, 27025, 27026, 27027, 27028, 27029, 27030, 27031, 27032, 27033, 27034, 27035, 27036, 27037, 27038, 27039, 27040, 27041, 27042, 27043, 27044, 27045, 27046, 27047, 27048, 27049, 27050, 27051, 27052, 27053, 27054, 27055, 27056, 27057, 27058, 27059, 27060, 27061, 27062, 27063, 27064, 27065, 27066, 27067, 27068, 27069, 27070, 27071, 27072, 27073, 27074, 27075, 27076, 27077, 27078, 27079, 27080, 27081, 27082, 27083, 27084, 27085, 27086, 27087, 27088, 27089, 27090, 27091, 27092, 27093, 27094, 27095, 27096, 27097, 27098, 27099, 27100, 27101, 27102, 27103, 27104, 27105, 27106, 27107, 27108, 27109, 27110, 27111, 27112, 27113, 27114, 27115, 27116, 27117, 27118, 27119, 27120, 27121, 27122, 27123, 27124, 27125, 27126, 27127, 27128, 27129, 27130, 27131, 27132, 27133, 27134, 27135, 27136, 27137, 27138, 27139, 27140, 27141, 27142, 27143, 27144, 27145, 27146, 27147, 27148, 27149, 27150, 27151, 27152, 27153, 27154, 27155, 27156, 27157, 27158, 27159, 27160, 27161, 27162, 27163, 27164, 27165, 27166, 27167, 27168, 27169, 27170, 27171, 27172, 27173, 27174, 27175, 27176, 27177, 27178, 27179, 27180, 27181, 27182, 27183, 27184, 27185, 27186, 27187, 27188, 27189, 27190, 27191, 27192, 27193, 27194, 27195, 27196, 27197, 27198, 27199, 27200, 27201, 27202, 27203, 27204, 27205, 27206, 27207, 27208, 27209, 27210, 27211, 27212, 27213, 27214, 27215, 27216, 27217, 27218, 27219, 27220, 27221, 27222, 27223, 27224, 27225, 27226, 27227, 27228, 27229, 27230, 27231, 27232, 27233, 27234, 27235, 27236, 27237, 27238, 27239, 27240, 27241, 27242, 27243, 27244, 27245, 27246, 27247, 27248, 27249, 27250, 27251, 27252, 27253, 27254, 27255, 27256, 27257, 27258, 27259, 27260, 27261, 27262, 27263, 27264, 27265, 27266, 27267, 27268, 27269, 27270, 27271, 27272, 27273, 27274, 27275, 27276, 27277, 27278, 27279, 27280, 27281, 27282, 27283, 27284, 27285, 27286, 27287, 27288, 27289, 27290, 27291, 27292, 27293, 27294, 27295, 27296, 27297, 27298, 27299, 27300, 27301, 27302, 27303, 27304, 27305, 27306, 27307, 27308, 27309, 27310, 27311, 27312, 27313, 27314, 27315, 27316, 27317, 27318, 27319, 27320, 27321, 27322, 27323, 27324, 27325, 27326, 27327, 27328, 27329, 27330, 27331, 27332, 27333, 27334, 27335, 27336, 27337, 27338, 27339, 27340, 27341, 27342, 27343, 27344, 27345, 27346, 27347, 27348, 27349, 27350, 27351, 27352, 27353, 27354, 27355, 27356, 27357, 27358, 27359, 27360, 27361, 27362, 27363, 27364, 27365, 27366, 27367, 27368, 27369, 27370, 27371, 27372, 27373, 27374, 27375, 27376, 27377, 27378, 27379, 27380, 27381, 27382, 27383, 27384, 27385, 27386, 27387, 27388, 27389, 27390, 27391, 27392, 27393, 27394, 27395, 27396, 27397, 27398, 27399, 27400, 27401, 27402, 27403, 27404, 27405, 27406, 27407, 27408, 27409, 27410, 27411, 27412, 27413, 27414, 27415, 27416, 27417, 27418, 27419, 27420, 27421, 27422, 27423, 27424, 27425, 27426, 27427, 27428, 27429, 27430, 27431, 27432, 27433, 27434, 27435, 27436, 27437, 27438, 27439, 27440, 27441, 27442, 27443, 27444, 27445, 27446, 27447, 27448, 27449, 27450, 27451, 27452, 27453, 27454, 27455, 27456, 27457, 27458, 27459, 27460, 27461, 27462, 27463, 27464, 27465, 27466, 27467, 27468, 27469, 27470, 27471, 27472, 27473, 27474, 27475, 27476, 27477, 27478, 27479, 27480, 27481, 27482, 27483, 27484, 27485, 27486, 27487, 27488, 27489, 27490, 27491, 27492, 27493, 27494, 27495, 27496, 27497, 27498, 27499, 27500, 27501, 27502, 27503, 27504, 27505, 27506, 27507, 27508, 27509, 27510, 27511, 27512, 27513, 27514, 27515, 27516, 27517, 27518, 27519, 27520, 27521, 27522, 27523, 27524, 27525, 27526, 27527, 27528, 27529, 27530, 27531, 27532, 27533, 27534, 27535, 27536, 27537, 27538, 27539, 27540, 27541, 27542, 27543, 27544, 27545, 27546, 27547, 27548, 27549, 27550, 27551, 27552, 27553, 27554, 27555, 27556, 27557, 27558, 27559, 27560, 27561, 27562, 27563, 27564, 27565, 27566, 27567, 27568, 27569, 27570, 27571, 27572, 27573, 27574, 27575, 27576, 27577, 27578, 27579, 27580, 27581, 27582, 27583, 27584, 27585, 27586, 27587, 27588, 27589, 27590, 27591, 27592, 27593, 27594, 27595, 27596, 27597, 27598, 27599, 27600, 27601, 27602, 27603, 27604, 27605, 27606, 27607, 27608, 27609, 27610, 27611, 27612, 27613, 27614, 27615, 27616, 27617, 27618, 27619, 27620, 27621, 27622, 27623, 27624, 27625, 27626, 27627, 27628, 27629, 27630, 27631, 27632, 27633, 27634, 27635, 27636, 27637, 27638, 27639, 27640, 27641, 27642, 27643, 27644, 27645, 27646, 27647, 27648, 27649, 27650, 27651, 27652, 27653, 27654, 27655, 27656, 27657, 27658, 27659, 27660, 27661, 27662, 27663, 27664, 27665, 27666, 27667, 27668, 27669, 27670, 27671, 27672, 27673, 27674, 27675, 27676, 27677, 27678, 27679, 27680, 27681, 27682, 27683, 27684, 27685, 27686, 27687, 27688, 27689, 27690, 27691, 27692, 27693, 27694, 27695, 27696, 27697, 27698, 27699, 27700, 27701, 27702, 27703, 27704, 27705, 27706, 27707, 27708, 27709, 27710, 27711, 27712, 27713, 27714, 27715, 27716, 27717, 27718, 27719, 27720, 27721, 27722, 27723, 27724, 27725, 27726, 27727, 27728, 27729, 27730, 27731, 27732, 27733, 27734, 27735, 27736, 27737, 27738, 27739, 27740, 27741, 27742, 27743, 27744, 27745, 27746, 27747, 27748, 27749, 27750, 27751, 27752, 27753, 27754, 27755, 27756, 27757, 27758, 27759, 27760, 27761, 27762, 27763, 27764, 27765, 27766, 27767, 27768, 27769, 27770, 27771, 27772, 27773, 27774, 27775, 27776, 27777, 27778, 27779, 27780, 27781, 27782, 27783, 27784, 27785, 27786, 27787, 27788, 27789, 27790, 27791, 27792, 27793, 27794, 27795, 27796, 27797, 27798, 27799, 27800, 27801, 27802, 27803, 27804, 27805, 27806, 27807, 27808, 27809, 27810, 27811, 27812, 27813, 27814, 27815, 27816, 27817, 27818, 27819, 27820, 27821, 27822, 27823, 27824, 27825, 27826, 27827, 27828, 27829, 27830, 27831, 27832, 27833, 27834, 27835, 27836, 27837, 27838, 27839, 27840, 27841, 27842, 27843, 27844, 27845, 27846, 27847, 27848, 27849, 27850, 27851, 27852, 27853, 27854, 27855, 27856, 27857, 27858, 27859, 27860, 27861, 27862, 27863, 27864, 27865, 27866, 27867, 27868, 27869, 27870, 27871, 27872, 27873, 27874, 27875, 27876, 27877, 27878, 27879, 27880, 27881, 27882, 27883, 27884, 27885, 27886, 27887, 27888, 27889, 27890, 27891, 27892, 27893, 27894, 27895, 27896, 27897, 27898, 27899, 27900, 27901, 27902, 27903, 27904, 27905, 27906, 27907, 27908, 27909, 27910, 27911, 27912, 27913, 27914, 27915, 27916, 27917, 27918, 27919, 27920, 27921, 27922, 27923, 27924, 27925, 27926, 27927, 27928, 27929, 27930, 27931, 27932, 27933, 27934, 27935, 27936, 27937, 27938, 27939, 27940, 27941, 27942, 27943, 27944, 27945, 27946, 27947, 27948, 27949, 27950, 27951, 27952, 27953, 27954, 27955, 27956, 27957, 27958, 27959, 27960, 27961, 27962, 27963, 27964, 27965, 27966, 27967, 27968, 27969, 27970, 27971, 27972, 27973, 27974, 27975, 27976, 27977, 27978, 27979, 27980, 27981, 27982, 27983, 27984, 27985, 27986, 27987, 27988, 27989, 27990, 27991, 27992, 27993, 27994, 27995, 27996, 27997, 27998, 27999, 28000, 28001, 28002, 28003, 28004, 28005, 28006, 28007, 28008, 28009, 28010, 28011, 28012, 28013, 28014, 28015, 28016, 28017, 28018, 28019, 28020, 28021, 28022, 28023, 28024, 28025, 28026, 28027, 28028, 28029, 28030, 28031, 28032, 28033, 28034, 28035, 28036, 28037, 28038, 28039, 28040, 28041, 28042, 28043, 28044, 28045, 28046, 28047, 28048, 28049, 28050, 28051, 28052, 28053, 28054, 28055, 28056, 28057, 28058, 28059, 28060, 28061, 28062, 28063, 28064, 28065, 28066, 28067, 28068, 28069, 28070, 28071, 28072, 28073, 28074, 28075, 28076, 28077, 28078, 28079, 28080, 28081, 28082, 28083, 28084, 28085, 28086, 28087, 28088, 28089, 28090, 28091, 28092, 28093, 28094, 28095, 28096, 28097, 28098, 28099, 28100, 28101, 28102, 28103, 28104, 28105, 28106, 28107, 28108, 28109, 28110, 28111, 28112, 28113, 28114, 28115, 28116, 28117, 28118, 28119, 28120, 28121, 28122, 28123, 28124, 28125, 28126, 28127, 28128, 28129, 28130, 28131, 28132, 28133, 28134, 28135, 28136, 28137, 28138, 28139, 28140, 28141, 28142, 28143, 28144, 28145, 28146, 28147, 28148, 28149, 28150, 28151, 28152, 28153, 28154, 28155, 28156, 28157, 28158, 28159, 28160, 28161, 28162, 28163, 28164, 28165, 28166, 28167, 28168, 28169, 28170, 28171, 28172, 28173, 28174, 28175, 28176, 28177, 28178, 28179, 28180, 28181, 28182, 28183, 28184, 28185, 28186, 28187, 28188, 28189, 28190, 28191, 28192, 28193, 28194, 28195, 28196, 28197, 28198, 28199, 28200, 28201, 28202, 28203, 28204, 28205, 28206, 28207, 28208, 28209, 28210, 28211, 28212, 28213, 28214, 28215, 28216, 28217, 28218, 28219, 28220, 28221, 28222, 28223, 28224, 28225, 28226, 28227, 28228, 28229, 28230, 28231, 28232, 28233, 28234, 28235, 28236, 28237, 28238, 28239, 28240, 28241, 28242, 28243, 28244, 28245, 28246, 28247, 28248, 28249, 28250, 28251, 28252, 28253, 28254, 28255, 28256, 28257, 28258, 28259, 28260, 28261, 28262, 28263, 28264, 28265, 28266, 28267, 28268, 28269, 28270, 28271, 28272, 28273, 28274, 28275, 28276, 28277, 28278, 28279, 28280, 28281, 28282, 28283, 28284, 28285, 28286, 28287, 28288, 28289, 28290, 28291, 28292, 28293, 28294, 28295, 28296, 28297, 28298, 28299, 28300, 28301, 28302, 28303, 28304, 28305, 28306, 28307, 28308, 28309, 28310, 28311, 28312, 28313, 28314, 28315, 28316, 28317, 28318, 28319, 28320, 28321, 28322, 28323, 28324, 28325, 28326, 28327, 28328, 28329, 28330, 28331, 28332, 28333, 28334, 28335, 28336, 28337, 28338, 28339, 28340, 28341, 28342, 28343, 28344, 28345, 28346, 28347, 28348, 28349, 28350, 28351, 28352, 28353, 28354, 28355, 28356, 28357, 28358, 28359, 28360, 28361, 28362, 28363, 28364, 28365, 28366, 28367, 28368, 28369, 28370, 28371, 28372, 28373, 28374, 28375, 28376, 28377, 28378, 28379, 28380, 28381, 28382, 28383, 28384, 28385, 28386, 28387, 28388, 28389, 28390, 28391, 28392, 28393, 28394, 28395, 28396, 28397, 28398, 28399, 28400, 28401, 28402, 28403, 28404, 28405, 28406, 28407, 28408, 28409, 28410, 28411, 28412, 28413, 28414, 28415, 28416, 28417, 28418, 28419, 28420, 28421, 28422, 28423, 28424, 28425, 28426, 28427, 28428, 28429, 28430, 28431, 28432, 28433, 28434, 28435, 28436, 28437, 28438, 28439, 28440, 28441, 28442, 28443, 28444, 28445, 28446, 28447, 28448, 28449, 28450, 28451, 28452, 28453, 28454, 28455, 28456, 28457, 28458, 28459, 28460, 28461, 28462, 28463, 28464, 28465, 28466, 28467, 28468, 28469, 28470, 28471, 28472, 28473, 28474, 28475, 28476, 28477, 28478, 28479, 28480, 28481, 28482, 28483, 28484, 28485, 28486, 28487, 28488, 28489, 28490, 28491, 28492, 28493, 28494, 28495, 28496, 28497, 28498, 28499, 28500, 28501, 28502, 28503, 28504, 28505, 28506, 28507, 28508, 28509, 28510, 28511, 28512, 28513, 28514, 28515, 28516, 28517, 28518, 28519, 28520, 28521, 28522, 28523, 28524, 28525, 28526, 28527, 28528, 28529, 28530, 28531, 28532, 28533, 28534, 28535, 28536, 28537, 28538, 28539, 28540, 28541, 28542, 28543, 28544, 28545, 28546, 28547, 28548, 28549, 28550, 28551, 28552, 28553, 28554, 28555, 28556, 28557, 28558, 28559, 28560, 28561, 28562, 28563, 28564, 28565, 28566, 28567, 28568, 28569, 28570, 28571, 28572, 28573, 28574, 28575, 28576, 28577, 28578, 28579, 28580, 28581, 28582, 28583, 28584, 28585, 28586, 28587, 28588, 28589, 28590, 28591, 28592, 28593, 28594, 28595, 28596, 28597, 28598, 28599, 28600, 28601, 28602, 28603, 28604, 28605, 28606, 28607, 28608, 28609, 28610, 28611, 28612, 28613, 28614, 28615, 28616, 28617, 28618, 28619, 28620, 28621, 28622, 28623, 28624, 28625, 28626, 28627, 28628, 28629, 28630, 28631, 28632, 28633, 28634, 28635, 28636, 28637, 28638, 28639, 28640, 28641, 28642, 28643, 28644, 28645, 28646, 28647, 28648, 28649, 28650, 28651, 28652, 28653, 28654, 28655, 28656, 28657, 28658, 28659, 28660, 28661, 28662, 28663, 28664, 28665, 28666, 28667, 28668, 28669, 28670, 28671, 28672, 28673, 28674, 28675, 28676, 28677, 28678, 28679, 28680, 28681, 28682, 28683, 28684, 28685, 28686, 28687, 28688, 28689, 28690, 28691, 28692, 28693, 28694, 28695, 28696, 28697, 28698, 28699, 28700, 28701, 28702, 28703, 28704, 28705, 28706, 28707, 28708, 28709, 28710, 28711, 28712, 28713, 28714, 28715, 28716, 28717, 28718, 28719, 28720, 28721, 28722, 28723, 28724, 28725, 28726, 28727, 28728, 28729, 28730, 28731, 28732, 28733, 28734, 28735, 28736, 28737, 28738, 28739, 28740, 28741, 28742, 28743, 28744, 28745, 28746, 28747, 28748, 28749, 28750, 28751, 28752, 28753, 28754, 28755, 28756, 28757, 28758, 28759, 28760, 28761, 28762, 28763, 28764, 28765, 28766, 28767, 28768, 28769, 28770, 28771, 28772, 28773, 28774, 28775, 28776, 28777, 28778, 28779, 28780, 28781, 28782, 28783, 28784, 28785, 28786, 28787, 28788, 28789, 28790, 28791, 28792, 28793, 28794, 28795, 28796, 28797, 28798, 28799, 28800, 28801, 28802, 28803, 28804, 28805, 28806, 28807, 28808, 28809, 28810, 28811, 28812, 28813, 28814, 28815, 28816, 28817, 28818, 28819, 28820, 28821, 28822, 28823, 28824, 28825, 28826, 28827, 28828, 28829, 28830, 28831, 28832, 28833, 28834, 28835, 28836, 28837, 28838, 28839, 28840, 28841, 28842, 28843, 28844, 28845, 28846, 28847, 28848, 28849, 28850, 28851, 28852, 28853, 28854, 28855, 28856, 28857, 28858, 28859, 28860, 28861, 28862, 28863, 28864, 28865, 28866, 28867, 28868, 28869, 28870, 28871, 28872, 28873, 28874, 28875, 28876, 28877, 28878, 28879, 28880, 28881, 28882, 28883, 28884, 28885, 28886, 28887, 28888, 28889, 28890, 28891, 28892, 28893, 28894, 28895, 28896, 28897, 28898, 28899, 28900, 28901, 28902, 28903, 28904, 28905, 28906, 28907, 28908, 28909, 28910, 28911, 28912, 28913, 28914, 28915, 28916, 28917, 28918, 28919, 28920, 28921, 28922, 28923, 28924, 28925, 28926, 28927, 28928, 28929, 28930, 28931, 28932, 28933, 28934, 28935, 28936, 28937, 28938, 28939, 28940, 28941, 28942, 28943, 28944, 28945, 28946, 28947, 28948, 28949, 28950, 28951, 28952, 28953, 28954, 28955, 28956, 28957, 28958, 28959, 28960, 28961, 28962, 28963, 28964, 28965, 28966, 28967, 28968, 28969, 28970, 28971, 28972, 28973, 28974, 28975, 28976, 28977, 28978, 28979, 28980, 28981, 28982, 28983, 28984, 28985, 28986, 28987, 28988, 28989, 28990, 28991, 28992, 28993, 28994, 28995, 28996, 28997, 28998, 28999, 29000, 29001, 29002, 29003, 29004, 29005, 29006, 29007, 29008, 29009, 29010, 29011, 29012, 29013, 29014, 29015, 29016, 29017, 29018, 29019, 29020, 29021, 29022, 29023, 29024, 29025, 29026, 29027, 29028, 29029, 29030, 29031, 29032, 29033, 29034, 29035, 29036, 29037, 29038, 29039, 29040, 29041, 29042, 29043, 29044, 29045, 29046, 29047, 29048, 29049, 29050, 29051, 29052, 29053, 29054, 29055, 29056, 29057, 29058, 29059, 29060, 29061, 29062, 29063, 29064, 29065, 29066, 29067, 29068, 29069, 29070, 29071, 29072, 29073, 29074, 29075, 29076, 29077, 29078, 29079, 29080, 29081, 29082, 29083, 29084, 29085, 29086, 29087, 29088, 29089, 29090, 29091, 29092, 29093, 29094, 29095, 29096, 29097, 29098, 29099, 29100, 29101, 29102, 29103, 29104, 29105, 29106, 29107, 29108, 29109, 29110, 29111, 29112, 29113, 29114, 29115, 29116, 29117, 29118, 29119, 29120, 29121, 29122, 29123, 29124, 29125, 29126, 29127, 29128, 29129, 29130, 29131, 29132, 29133, 29134, 29135, 29136, 29137, 29138, 29139, 29140, 29141, 29142, 29143, 29144, 29145, 29146, 29147, 29148, 29149, 29150, 29151, 29152, 29153, 29154, 29155, 29156, 29157, 29158, 29159, 29160, 29161, 29162, 29163, 29164, 29165, 29166, 29167, 29168, 29169, 29170, 29171, 29172, 29173, 29174, 29175, 29176, 29177, 29178, 29179, 29180, 29181, 29182, 29183, 29184, 29185, 29186, 29187, 29188, 29189, 29190, 29191, 29192, 29193, 29194, 29195, 29196, 29197, 29198, 29199, 29200, 29201, 29202, 29203, 29204, 29205, 29206, 29207, 29208, 29209, 29210, 29211, 29212, 29213, 29214, 29215, 29216, 29217, 29218, 29219, 29220, 29221, 29222, 29223, 29224, 29225, 29226, 29227, 29228, 29229, 29230, 29231, 29232, 29233, 29234, 29235, 29236, 29237, 29238, 29239, 29240, 29241, 29242, 29243, 29244, 29245, 29246, 29247, 29248, 29249, 29250, 29251, 29252, 29253, 29254, 29255, 29256, 29257, 29258, 29259, 29260, 29261, 29262, 29263, 29264, 29265, 29266, 29267, 29268, 29269, 29270, 29271, 29272, 29273, 29274, 29275, 29276, 29277, 29278, 29279, 29280, 29281, 29282, 29283, 29284, 29285, 29286, 29287, 29288, 29289, 29290, 29291, 29292, 29293, 29294, 29295, 29296, 29297, 29298, 29299, 29300, 29301, 29302, 29303, 29304, 29305, 29306, 29307, 29308, 29309, 29310, 29311, 29312, 29313, 29314, 29315, 29316, 29317, 29318, 29319, 29320, 29321, 29322, 29323, 29324, 29325, 29326, 29327, 29328, 29329, 29330, 29331, 29332, 29333, 29334, 29335, 29336, 29337, 29338, 29339, 29340, 29341, 29342, 29343, 29344, 29345, 29346, 29347, 29348, 29349, 29350, 29351, 29352, 29353, 29354, 29355, 29356, 29357, 29358, 29359, 29360, 29361, 29362, 29363, 29364, 29365, 29366, 29367, 29368, 29369, 29370, 29371, 29372, 29373, 29374, 29375, 29376, 29377, 29378, 29379, 29380, 29381, 29382, 29383, 29384, 29385, 29386, 29387, 29388, 29389, 29390, 29391, 29392, 29393, 29394, 29395, 29396, 29397, 29398, 29399, 29400, 29401, 29402, 29403, 29404, 29405, 29406, 29407, 29408, 29409, 29410, 29411, 29412, 29413, 29414, 29415, 29416, 29417, 29418, 29419, 29420, 29421, 29422, 29423, 29424, 29425, 29426, 29427, 29428, 29429, 29430, 29431, 29432, 29433, 29434, 29435, 29436, 29437, 29438, 29439, 29440, 29441, 29442, 29443, 29444, 29445, 29446, 29447, 29448, 29449, 29450, 29451, 29452, 29453, 29454, 29455, 29456, 29457, 29458, 29459, 29460, 29461, 29462, 29463, 29464, 29465, 29466, 29467, 29468, 29469, 29470, 29471, 29472, 29473, 29474, 29475, 29476, 29477, 29478, 29479, 29480, 29481, 29482, 29483, 29484, 29485, 29486, 29487, 29488, 29489, 29490, 29491, 29492, 29493, 29494, 29495, 29496, 29497, 29498, 29499, 29500, 29501, 29502, 29503, 29504, 29505, 29506, 29507, 29508, 29509, 29510, 29511, 29512, 29513, 29514, 29515, 29516, 29517, 29518, 29519, 29520, 29521, 29522, 29523, 29524, 29525, 29526, 29527, 29528, 29529, 29530, 29531, 29532, 29533, 29534, 29535, 29536, 29537, 29538, 29539, 29540, 29541, 29542, 29543, 29544, 29545, 29546, 29547, 29548, 29549, 29550, 29551, 29552, 29553, 29554, 29555, 29556, 29557, 29558, 29559, 29560, 29561, 29562, 29563, 29564, 29565, 29566, 29567, 29568, 29569, 29570, 29571, 29572, 29573, 29574, 29575, 29576, 29577, 29578, 29579, 29580, 29581, 29582, 29583, 29584, 29585, 29586, 29587, 29588, 29589, 29590, 29591, 29592, 29593, 29594, 29595, 29596, 29597, 29598, 29599, 29600, 29601, 29602, 29603, 29604, 29605, 29606, 29607, 29608, 29609, 29610, 29611, 29612, 29613, 29614, 29615, 29616, 29617, 29618, 29619, 29620, 29621, 29622, 29623, 29624, 29625, 29626, 29627, 29628, 29629, 29630, 29631, 29632, 29633, 29634, 29635, 29636, 29637, 29638, 29639, 29640, 29641, 29642, 29643, 29644, 29645, 29646, 29647, 29648, 29649, 29650, 29651, 29652, 29653, 29654, 29655, 29656, 29657, 29658, 29659, 29660, 29661, 29662, 29663, 29664, 29665, 29666, 29667, 29668, 29669, 29670, 29671, 29672, 29673, 29674, 29675, 29676, 29677, 29678, 29679, 29680, 29681, 29682, 29683, 29684, 29685, 29686, 29687, 29688, 29689, 29690, 29691, 29692, 29693, 29694, 29695, 29696, 29697, 29698, 29699, 29700, 29701, 29702, 29703, 29704, 29705, 29706, 29707, 29708, 29709, 29710, 29711, 29712, 29713, 29714, 29715, 29716, 29717, 29718, 29719, 29720, 29721, 29722, 29723, 29724, 29725, 29726, 29727, 29728, 29729, 29730, 29731, 29732, 29733, 29734, 29735, 29736, 29737, 29738, 29739, 29740, 29741, 29742, 29743, 29744, 29745, 29746, 29747, 29748, 29749, 29750, 29751, 29752, 29753, 29754, 29755, 29756, 29757, 29758, 29759, 29760, 29761, 29762, 29763, 29764, 29765, 29766, 29767, 29768, 29769, 29770, 29771, 29772, 29773, 29774, 29775, 29776, 29777, 29778, 29779, 29780, 29781, 29782, 29783, 29784, 29785, 29786, 29787, 29788, 29789, 29790, 29791, 29792, 29793, 29794, 29795, 29796, 29797, 29798, 29799, 29800, 29801, 29802, 29803, 29804, 29805, 29806, 29807, 29808, 29809, 29810, 29811, 29812, 29813, 29814, 29815, 29816, 29817, 29818, 29819, 29820, 29821, 29822, 29823, 29824, 29825, 29826, 29827, 29828, 29829, 29830, 29831, 29832, 29833, 29834, 29835, 29836, 29837, 29838, 29839, 29840, 29841, 29842, 29843, 29844, 29845, 29846, 29847, 29848, 29849, 29850, 29851, 29852, 29853, 29854, 29855, 29856, 29857, 29858, 29859, 29860, 29861, 29862, 29863, 29864, 29865, 29866, 29867, 29868, 29869, 29870, 29871, 29872, 29873, 29874, 29875, 29876, 29877, 29878, 29879, 29880, 29881, 29882, 29883, 29884, 29885, 29886, 29887, 29888, 29889, 29890, 29891, 29892, 29893, 29894, 29895, 29896, 29897, 29898, 29899, 29900, 29901, 29902, 29903, 29904, 29905, 29906, 29907, 29908, 29909, 29910, 29911, 29912, 29913, 29914, 29915, 29916, 29917, 29918, 29919, 29920, 29921, 29922, 29923, 29924, 29925, 29926, 29927, 29928, 29929, 29930, 29931, 29932, 29933, 29934, 29935, 29936, 29937, 29938, 29939, 29940, 29941, 29942, 29943, 29944, 29945, 29946, 29947, 29948, 29949, 29950, 29951, 29952, 29953, 29954, 29955, 29956, 29957, 29958, 29959, 29960, 29961, 29962, 29963, 29964, 29965, 29966, 29967, 29968, 29969, 29970, 29971, 29972, 29973, 29974, 29975, 29976, 29977, 29978, 29979, 29980, 29981, 29982, 29983, 29984, 29985, 29986, 29987, 29988, 29989, 29990, 29991, 29992, 29993, 29994, 29995, 29996, 29997, 29998, 29999, 30000, 30001, 30002, 30003, 30004, 30005, 30006, 30007, 30008, 30009, 30010, 30011, 30012, 30013, 30014, 30015, 30016, 30017, 30018, 30019, 30020, 30021, 30022, 30023, 30024, 30025, 30026, 30027, 30028, 30029, 30030, 30031, 30032, 30033, 30034, 30035, 30036, 30037, 30038, 30039, 30040, 30041, 30042, 30043, 30044, 30045, 30046, 30047, 30048, 30049, 30050, 30051, 30052, 30053, 30054, 30055, 30056, 30057, 30058, 30059, 30060, 30061, 30062, 30063, 30064, 30065, 30066, 30067, 30068, 30069, 30070, 30071, 30072, 30073, 30074, 30075, 30076, 30077, 30078, 30079, 30080, 30081, 30082, 30083, 30084, 30085, 30086, 30087, 30088, 30089, 30090, 30091, 30092, 30093, 30094, 30095, 30096, 30097, 30098, 30099, 30100, 30101, 30102, 30103, 30104, 30105, 30106, 30107, 30108, 30109, 30110, 30111, 30112, 30113, 30114, 30115, 30116, 30117, 30118, 30119, 30120, 30121, 30122, 30123, 30124, 30125, 30126, 30127, 30128, 30129, 30130, 30131, 30132, 30133, 30134, 30135, 30136, 30137, 30138, 30139, 30140, 30141, 30142, 30143, 30144, 30145, 30146, 30147, 30148, 30149, 30150, 30151, 30152, 30153, 30154, 30155, 30156, 30157, 30158, 30159, 30160, 30161, 30162, 30163, 30164, 30165, 30166, 30167, 30168, 30169, 30170, 30171, 30172, 30173, 30174, 30175, 30176, 30177, 30178, 30179, 30180, 30181, 30182, 30183, 30184, 30185, 30186, 30187, 30188, 30189, 30190, 30191, 30192, 30193, 30194, 30195, 30196, 30197, 30198, 30199, 30200, 30201, 30202, 30203, 30204, 30205, 30206, 30207, 30208, 30209, 30210, 30211, 30212, 30213, 30214, 30215, 30216, 30217, 30218, 30219, 30220, 30221, 30222, 30223, 30224, 30225, 30226, 30227, 30228, 30229, 30230, 30231, 30232, 30233, 30234, 30235, 30236, 30237, 30238, 30239, 30240, 30241, 30242, 30243, 30244, 30245, 30246, 30247, 30248, 30249, 30250, 30251, 30252, 30253, 30254, 30255, 30256, 30257, 30258, 30259, 30260, 30261, 30262, 30263, 30264, 30265, 30266, 30267, 30268, 30269, 30270, 30271, 30272, 30273, 30274, 30275, 30276, 30277, 30278, 30279, 30280, 30281, 30282, 30283, 30284, 30285, 30286, 30287, 30288, 30289, 30290, 30291, 30292, 30293, 30294, 30295, 30296, 30297, 30298, 30299, 30300, 30301, 30302, 30303, 30304, 30305, 30306, 30307, 30308, 30309, 30310, 30311, 30312, 30313, 30314, 30315, 30316, 30317, 30318, 30319, 30320, 30321, 30322, 30323, 30324, 30325, 30326, 30327, 30328, 30329, 30330, 30331, 30332, 30333, 30334, 30335, 30336, 30337, 30338, 30339, 30340, 30341, 30342, 30343, 30344, 30345, 30346, 30347, 30348, 30349, 30350, 30351, 30352, 30353, 30354, 30355, 30356, 30357, 30358, 30359, 30360, 30361, 30362, 30363, 30364, 30365, 30366, 30367, 30368, 30369, 30370, 30371, 30372, 30373, 30374, 30375, 30376, 30377, 30378, 30379, 30380, 30381, 30382, 30383, 30384, 30385, 30386, 30387, 30388, 30389, 30390, 30391, 30392, 30393, 30394, 30395, 30396, 30397, 30398, 30399, 30400, 30401, 30402, 30403, 30404, 30405, 30406, 30407, 30408, 30409, 30410, 30411, 30412, 30413, 30414, 30415, 30416, 30417, 30418, 30419, 30420, 30421, 30422, 30423, 30424, 30425, 30426, 30427, 30428, 30429, 30430, 30431, 30432, 30433, 30434, 30435, 30436, 30437, 30438, 30439, 30440, 30441, 30442, 30443, 30444, 30445, 30446, 30447, 30448, 30449, 30450, 30451, 30452, 30453, 30454, 30455, 30456, 30457, 30458, 30459, 30460, 30461, 30462, 30463, 30464, 30465, 30466, 30467, 30468, 30469, 30470, 30471, 30472, 30473, 30474, 30475, 30476, 30477, 30478, 30479, 30480, 30481, 30482, 30483, 30484, 30485, 30486, 30487, 30488, 30489, 30490, 30491, 30492, 30493, 30494, 30495, 30496, 30497, 30498, 30499, 30500, 30501, 30502, 30503, 30504, 30505, 30506, 30507, 30508, 30509, 30510, 30511, 30512, 30513, 30514, 30515, 30516, 30517, 30518, 30519, 30520, 30521, 30522, 30523, 30524, 30525, 30526, 30527, 30528, 30529, 30530, 30531, 30532, 30533, 30534, 30535, 30536, 30537, 30538, 30539, 30540, 30541, 30542, 30543, 30544, 30545, 30546, 30547, 30548, 30549, 30550, 30551, 30552, 30553, 30554, 30555, 30556, 30557, 30558, 30559, 30560, 30561, 30562, 30563, 30564, 30565, 30566, 30567, 30568, 30569, 30570, 30571, 30572, 30573, 30574, 30575, 30576, 30577, 30578, 30579, 30580, 30581, 30582, 30583, 30584, 30585, 30586, 30587, 30588, 30589, 30590, 30591, 30592, 30593, 30594, 30595, 30596, 30597, 30598, 30599, 30600, 30601, 30602, 30603, 30604, 30605, 30606, 30607, 30608, 30609, 30610, 30611, 30612, 30613, 30614, 30615, 30616, 30617, 30618, 30619, 30620, 30621, 30622, 30623, 30624, 30625, 30626, 30627, 30628, 30629, 30630, 30631, 30632, 30633, 30634, 30635, 30636, 30637, 30638, 30639, 30640, 30641, 30642, 30643, 30644, 30645, 30646, 30647, 30648, 30649, 30650, 30651, 30652, 30653, 30654, 30655, 30656, 30657, 30658, 30659, 30660, 30661, 30662, 30663, 30664, 30665, 30666, 30667, 30668, 30669, 30670, 30671, 30672, 30673, 30674, 30675, 30676, 30677, 30678, 30679, 30680, 30681, 30682, 30683, 30684, 30685, 30686, 30687, 30688, 30689, 30690, 30691, 30692, 30693, 30694, 30695, 30696, 30697, 30698, 30699, 30700, 30701, 30702, 30703, 30704, 30705, 30706, 30707, 30708, 30709, 30710, 30711, 30712, 30713, 30714, 30715, 30716, 30717, 30718, 30719, 30720, 30721, 30722, 30723, 30724, 30725, 30726, 30727, 30728, 30729, 30730, 30731, 30732, 30733, 30734, 30735, 30736, 30737, 30738, 30739, 30740, 30741, 30742, 30743, 30744, 30745, 30746, 30747, 30748, 30749, 30750, 30751, 30752, 30753, 30754, 30755, 30756, 30757, 30758, 30759, 30760, 30761, 30762, 30763, 30764, 30765, 30766, 30767, 30768, 30769, 30770, 30771, 30772, 30773, 30774, 30775, 30776, 30777, 30778, 30779, 30780, 30781, 30782, 30783, 30784, 30785, 30786, 30787, 30788, 30789, 30790, 30791, 30792, 30793, 30794, 30795, 30796, 30797, 30798, 30799, 30800, 30801, 30802, 30803, 30804, 30805, 30806, 30807, 30808, 30809, 30810, 30811, 30812, 30813, 30814, 30815, 30816, 30817, 30818, 30819, 30820, 30821, 30822, 30823, 30824, 30825, 30826, 30827, 30828, 30829, 30830, 30831, 30832, 30833, 30834, 30835, 30836, 30837, 30838, 30839, 30840, 30841, 30842, 30843, 30844, 30845, 30846, 30847, 30848, 30849, 30850, 30851, 30852, 30853, 30854, 30855, 30856, 30857, 30858, 30859, 30860, 30861, 30862, 30863, 30864, 30865, 30866, 30867, 30868, 30869, 30870, 30871, 30872, 30873, 30874, 30875, 30876, 30877, 30878, 30879, 30880, 30881, 30882, 30883, 30884, 30885, 30886, 30887, 30888, 30889, 30890, 30891, 30892, 30893, 30894, 30895, 30896, 30897, 30898, 30899, 30900, 30901, 30902, 30903, 30904, 30905, 30906, 30907, 30908, 30909, 30910, 30911, 30912, 30913, 30914, 30915, 30916, 30917, 30918, 30919, 30920, 30921, 30922, 30923, 30924, 30925, 30926, 30927, 30928, 30929, 30930, 30931, 30932, 30933, 30934, 30935, 30936, 30937, 30938, 30939, 30940, 30941, 30942, 30943, 30944, 30945, 30946, 30947, 30948, 30949, 30950, 30951, 30952, 30953, 30954, 30955, 30956, 30957, 30958, 30959, 30960, 30961, 30962, 30963, 30964, 30965, 30966, 30967, 30968, 30969, 30970, 30971, 30972, 30973, 30974, 30975, 30976, 30977, 30978, 30979, 30980, 30981, 30982, 30983, 30984, 30985, 30986, 30987, 30988, 30989, 30990, 30991, 30992, 30993, 30994, 30995, 30996, 30997, 30998, 30999, 31000, 31001, 31002, 31003, 31004, 31005, 31006, 31007, 31008, 31009, 31010, 31011, 31012, 31013, 31014, 31015, 31016, 31017, 31018, 31019, 31020, 31021, 31022, 31023, 31024, 31025, 31026, 31027, 31028, 31029, 31030, 31031, 31032, 31033, 31034, 31035, 31036, 31037, 31038, 31039, 31040, 31041, 31042, 31043, 31044, 31045, 31046, 31047, 31048, 31049, 31050, 31051, 31052, 31053, 31054, 31055, 31056, 31057, 31058, 31059, 31060, 31061, 31062, 31063, 31064, 31065, 31066, 31067, 31068, 31069, 31070, 31071, 31072, 31073, 31074, 31075, 31076, 31077, 31078, 31079, 31080, 31081, 31082, 31083, 31084, 31085, 31086, 31087, 31088, 31089, 31090, 31091, 31092, 31093, 31094, 31095, 31096, 31097, 31098, 31099, 31100, 31101, 31102, 31103, 31104, 31105, 31106, 31107, 31108, 31109, 31110, 31111, 31112, 31113, 31114, 31115, 31116, 31117, 31118, 31119, 31120, 31121, 31122, 31123, 31124, 31125, 31126, 31127, 31128, 31129, 31130, 31131, 31132, 31133, 31134, 31135, 31136, 31137, 31138, 31139, 31140, 31141, 31142, 31143, 31144, 31145, 31146, 31147, 31148, 31149, 31150, 31151, 31152, 31153, 31154, 31155, 31156, 31157, 31158, 31159, 31160, 31161, 31162, 31163, 31164, 31165, 31166, 31167, 31168, 31169, 31170, 31171, 31172, 31173, 31174, 31175, 31176, 31177, 31178, 31179, 31180, 31181, 31182, 31183, 31184, 31185, 31186, 31187, 31188, 31189, 31190, 31191, 31192, 31193, 31194, 31195, 31196, 31197, 31198, 31199, 31200, 31201, 31202, 31203, 31204, 31205, 31206, 31207, 31208, 31209, 31210, 31211, 31212, 31213, 31214, 31215, 31216, 31217, 31218, 31219, 31220, 31221, 31222, 31223, 31224, 31225, 31226, 31227, 31228, 31229, 31230, 31231, 31232, 31233, 31234, 31235, 31236, 31237, 31238, 31239, 31240, 31241, 31242, 31243, 31244, 31245, 31246, 31247, 31248, 31249, 31250, 31251, 31252, 31253, 31254, 31255, 31256, 31257, 31258, 31259, 31260, 31261, 31262, 31263, 31264, 31265, 31266, 31267, 31268, 31269, 31270, 31271, 31272, 31273, 31274, 31275, 31276, 31277, 31278, 31279, 31280, 31281, 31282, 31283, 31284, 31285, 31286, 31287, 31288, 31289, 31290, 31291, 31292, 31293, 31294, 31295, 31296, 31297, 31298, 31299, 31300, 31301, 31302, 31303, 31304, 31305, 31306, 31307, 31308, 31309, 31310, 31311, 31312, 31313, 31314, 31315, 31316, 31317, 31318, 31319, 31320, 31321, 31322, 31323, 31324, 31325, 31326, 31327, 31328, 31329, 31330, 31331, 31332, 31333, 31334, 31335, 31336, 31337, 31338, 31339, 31340, 31341, 31342, 31343, 31344, 31345, 31346, 31347, 31348, 31349, 31350, 31351, 31352, 31353, 31354, 31355, 31356, 31357, 31358, 31359, 31360, 31361, 31362, 31363, 31364, 31365, 31366, 31367, 31368, 31369, 31370, 31371, 31372, 31373, 31374, 31375, 31376, 31377, 31378, 31379, 31380, 31381, 31382, 31383, 31384, 31385, 31386, 31387, 31388, 31389, 31390, 31391, 31392, 31393, 31394, 31395, 31396, 31397, 31398, 31399, 31400, 31401, 31402, 31403, 31404, 31405, 31406, 31407, 31408, 31409, 31410, 31411, 31412, 31413, 31414, 31415, 31416, 31417, 31418, 31419, 31420, 31421, 31422, 31423, 31424, 31425, 31426, 31427, 31428, 31429, 31430, 31431, 31432, 31433, 31434, 31435, 31436, 31437, 31438, 31439, 31440, 31441, 31442, 31443, 31444, 31445, 31446, 31447, 31448, 31449, 31450, 31451, 31452, 31453, 31454, 31455, 31456, 31457, 31458, 31459, 31460, 31461, 31462, 31463, 31464, 31465, 31466, 31467, 31468, 31469, 31470, 31471, 31472, 31473, 31474, 31475, 31476, 31477, 31478, 31479, 31480, 31481, 31482, 31483, 31484, 31485, 31486, 31487, 31488, 31489, 31490, 31491, 31492, 31493, 31494, 31495, 31496, 31497, 31498, 31499, 31500, 31501, 31502, 31503, 31504, 31505, 31506, 31507, 31508, 31509, 31510, 31511, 31512, 31513, 31514, 31515, 31516, 31517, 31518, 31519, 31520, 31521, 31522, 31523, 31524, 31525, 31526, 31527, 31528, 31529, 31530, 31531, 31532, 31533, 31534, 31535, 31536, 31537, 31538, 31539, 31540, 31541, 31542, 31543, 31544, 31545, 31546, 31547, 31548, 31549, 31550, 31551, 31552, 31553, 31554, 31555, 31556, 31557, 31558, 31559, 31560, 31561, 31562, 31563, 31564, 31565, 31566, 31567, 31568, 31569, 31570, 31571, 31572, 31573, 31574, 31575, 31576, 31577, 31578, 31579, 31580, 31581, 31582, 31583, 31584, 31585, 31586, 31587, 31588, 31589, 31590, 31591, 31592, 31593, 31594, 31595, 31596, 31597, 31598, 31599, 31600, 31601, 31602, 31603, 31604, 31605, 31606, 31607, 31608, 31609, 31610, 31611, 31612, 31613, 31614, 31615, 31616, 31617, 31618, 31619, 31620, 31621, 31622, 31623, 31624, 31625, 31626, 31627, 31628, 31629, 31630, 31631, 31632, 31633, 31634, 31635, 31636, 31637, 31638, 31639, 31640, 31641, 31642, 31643, 31644, 31645, 31646, 31647, 31648, 31649, 31650, 31651, 31652, 31653, 31654, 31655, 31656, 31657, 31658, 31659, 31660, 31661, 31662, 31663, 31664, 31665, 31666, 31667, 31668, 31669, 31670, 31671, 31672, 31673, 31674, 31675, 31676, 31677, 31678, 31679, 31680, 31681, 31682, 31683, 31684, 31685, 31686, 31687, 31688, 31689, 31690, 31691, 31692, 31693, 31694, 31695, 31696, 31697, 31698, 31699, 31700, 31701, 31702, 31703, 31704, 31705, 31706, 31707, 31708, 31709, 31710, 31711, 31712, 31713, 31714, 31715, 31716, 31717, 31718, 31719, 31720, 31721, 31722, 31723, 31724, 31725, 31726, 31727, 31728, 31729, 31730, 31731, 31732, 31733, 31734, 31735, 31736, 31737, 31738, 31739, 31740, 31741, 31742, 31743] + EmptyAttributes: + GlobalAttributes:["HTTP_LINK","Generation_date","LINK_TITLE","Acknowledgement","Rules_of_use","Generated_by","Time_resolution","LINK_TEXT"] + VariableAttributes:["LABL_PTR_1"] diff --git a/cdf38_1-dist/cdfjava/cdfjson/wi.txt b/cdf38_1-dist/cdfjava/cdfjson/wi.txt new file mode 100644 index 0000000..d8d64d2 --- /dev/null +++ b/cdf38_1-dist/cdfjava/cdfjson/wi.txt @@ -0,0 +1,1847 @@ +wi_h0_mfi_00000000_v01.cdf: + CDFFileInfo: + FileVersion:3.8.0 + Format:SINGLE + Majority:COLUMN + Encoding:NETWORK + CDFglobalAttributes: + Project: + 0:"ISTP>International Solar-Terrestrial Physics" + Discipline: + 0:"Space Physics>Heliospheric Science" + Source_name: + 0:"WIND>Wind Interplanetary Plasma Laboratory" + Software_version: + 0:" " + Data_type: + 0:"H0>3 sec, 1 min, and hourly Definitive Data" + Descriptor: + 0:"MFI>Magnetic Fields Investigation" + Data_version: + 0:" " + TITLE: + 0:"WIND Magnetic Field Investigation (MFI) Standard Production" + TEXT: + 0:"WIND MFI Composite data file. This file contains multiple time resolution data." + 1:"1 Minute data averages " + 2:"3 Second data averages " + 3:"1 Hour data averages " + 4:"WIND MFI Instrument turn on 11/12/1994 " + 5:"Data versions: " + 6:"03 - Extrapolated Bz correction " + 7:"04 - Final Bz correction " + 8:"05 - Final orbit and Bz correction " + 9:"References: " + 10:"1. Lepping, R. P., et al., The WIND Magnetic Field Investigation, p. 207 in " + 11:"The Global Geospace Mission, ed. by C. T. Russell, Kluwer,1995 " + 12:"2. Panetta, P. (GSFC), GGS WIND MFI Operator's Manual, September 15, 1992. " + 13:"3. Computer Sciences Corporation, Data Format Control Document (DFCD) Between " + 14:"The International Solar-Terrestrial Physics (ISTP) Program Information " + 15:"Processing Division Ground Data Processing System and The ISTP Mission " + 16:"Investigators, CSC/TR-91/6014, 560-1DFD/0190, July 1992. " + 17:"4. Behannon, K. W., International Solar Terrestrial Physics (ISTP) Program " + 18:"Investigator Data Analysis Requirements For WIND and GEOTAIL Spacecraft " + 19:"Magnetometer Experiment, September 1987. " + 20:"5. National Space Science Data Center, CDF User's Guide, Version 2.3.0, " + 21:"October 1, 1992. " + 22:"6. Mish, W. H., International Solar-Terrestrial Physics (ISTP) Key Parameter " + 23:"Generation Software (KPGS) Standards & Conventions, September 1992. " + 24:"7. Mish, W. H., IMP F and G Phase I Magnetic Field Analysis, April 1972 " + MODS: + 0:" " + ADID_ref: + 0:"NSSD0141" + Logical_file_id: + 0:"wi_h0_mfi_00000000_v00" + Logical_source: + 0:"wi_h0_mfi" + Logical_source_description: + 0:"Wind Magnetic Fields Investigation: 3 sec, 1 min, and hourly Definitive Data." + Processing_date: + 0:" " + Level_0_file: + 0:" " + HKlvl_0_file: + 0:" " + Orbit_file: + 0:" " + Attitude_file: + 0:" " + def_FLAGS: + 0:"00 - Interpolated Calibration Values " + 1:"01 - Last available Calibration Values " + 2:"02 - Daily Computed Calibration Values " + 3:"03 - Daily Computed Calibration Values with Bz corrections " + 4:"04 - High-Resolution Calibration Values " + 5:"05 - High-Resolution Calibration Values with Bz corrections" + def_SPC_MODE: + 0:"01 - Science mode (92 sec)" + 1:"03 - Maneuver mode (92 sec)" + 2:"04 - Contingency mode (92 sec)" + 3:"05 - Science mode (46 sec)" + 4:"07 - Maneuver mode (46 sec)" + 5:"08 - Contingency mode (46 sec)" + def_MAG_MODE: + 0:"00 - Primary to Secondary Ratio (1:1) Outboard prime w/ FFT & Snapshot" + 1:"01 - Primary to Secondary Ratio (20:1) Outboard prime w/ FFT & Snapshot" + 2:"02 - Primary to Secondary Ratio (20:1) Outboard prime w/ Snapshot only " + 3:"03 - Primary to Secondary Ratio (1:1) Outboard prime Maneuver " + 4:"07 - Primary to Secondary Ratio (1:1) Outboard prime used Inboard data" + 5:"10 - Primary to Secondary Ratio (1:1) Inboard prime w/ FFT & Snapshot" + 6:"11 - Primary to Secondary Ratio (20:1) Inboard prime w/ FFT & Snapshot" + 7:"12 - Primary to Secondary Ratio (20:1) Inboard prime w/ Snapshot only " + 8:"13 - Primary to Secondary Ratio (1:1) Inboard prime Maneuver " + PI_name: + 0:"A. Koval" + PI_affiliation: + 0:"UMBC, NASA/GSFC" + Instrument_type: + 0:"Magnetic Fields (space)" + TEXT_supplement_1: + 0:" " + LINK_TEXT: + 0:"Wind " + 1:"MFI Versions and Processing: " + LINK_TITLE: + 0:"Home Page " + 1:"Latest (Oct. 2011) Notes and Warnings " + HTTP_LINK: + 0:"http://wind.nasa.gov" + 1:"http://wind.nasa.gov/mfi/notes.html" + alt_logical_source: + 0:"Wind_MFI_Magnetic-Fields-H0_3sec-1min-1hour_cdf" + Mission_group: + 0:"Wind" + 1:"!___Interplanetary Data near 1 AU" + Web_sites: + 0:"http://wind.nasa.gov" + spase_DatasetResourceID: + 0:"spase://NASA/NumericalData/Wind/MFI/PT03S" + CDFVariables: + Epoch: + VarDescription: + DataType:"CDF_EPOCH" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:"0000-01-01T00:00:00.000" + VarAttributes: + FIELDNAM:"Time Line (1 min)" + VALIDMIN:"1994-11-11T19:06:40.000" + VALIDMAX:"2030-12-30T17:06:40.000" + UNITS:"ms" + LABLAXIS:"Epoch" + FORMAT:"E14.8" + MONOTON:"INCREASE" + SCALETYP:"LINEAR" + CATDESC:"Time, Centered, Number of milliseconds since the epoch (1 min)" + FILLVAL:"9999-12-31T23:59:59.999" + VAR_TYPE:"support_data" + TIME_RES:"1 min" + Time_PB5: + VarDescription: + DataType:"CDF_INT4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-2147483647 + VarAttributes: + FIELDNAM:"Time Line (1 min)" + VALIDMIN:[1994,316,0] + VALIDMAX:[2030,365,0] + MONOTON:"INCREASE" + SCALETYP:"LINEAR" + CATDESC:"Time of observation in Year, Day, & milliseconds (1 min)" + FILLVAL:-1 + LABL_PTR_1:"label_time" + UNIT_PTR:"unit_time" + FORM_PTR:"format_time" + DEPEND_0:"Epoch" + DEPEND_1:"unit_time" + VAR_TYPE:"support_data" + TIME_RES:"1 min" + NUM_PTS: + VarDescription: + DataType:"CDF_INT4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-2147483647 + VarAttributes: + FIELDNAM:"Number of points in average (1 min)" + VALIDMIN:0 + VALIDMAX:1500 + UNITS:" " + LABLAXIS:"No. Points" + FORMAT:"I4" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Number of points in average (1 min)" + FILLVAL:-1 + DEPEND_0:"Epoch" + VAR_TYPE:"support_data" + TIME_RES:"1 min" + BF1: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Magnetic field magnitude (1 min)" + VALIDMIN:0.0 + VALIDMAX:65534.0 + UNITS:"nT (1min)" + LABLAXIS:"B" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Magnetic field magnitude (1 min)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch" + VAR_TYPE:"data" + TIME_RES:"1 min" + VAR_NOTES:"Average of the magnitudes (F1)" + BF1LOG: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Magnetic field magnitude (1 min)" + VALIDMIN:0.0 + VALIDMAX:65534.0 + UNITS:"nT (1min)" + LABLAXIS:"B" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"log" + CATDESC:"Magnetic field magnitude (1 min - log scaled)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch" + FUNCTION:"alternate_view" + COMPONENT_0:"BF1" + VIRTUAL:"TRUE" + VAR_TYPE:"data" + TIME_RES:"1 min" + VAR_NOTES:"Average of the magnitudes (F1)" + BRMSF1: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"RMS magnitude (1 min)" + VALIDMIN:0.0 + VALIDMAX:65534.0 + UNITS:"nT (1min)" + LABLAXIS:"B_RMS" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"RMS magnitude (1 min)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch" + VAR_TYPE:"data" + TIME_RES:"1 min" + VAR_NOTES:"RMS of the magnitudes (F1 RMS)" + BGSM: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Magnetic field vector in GSM cartesian coordinates (1 min)" + VALIDMIN:[-65534.0,-65534.0,-65534.0] + VALIDMAX:[65534.0,65534.0,65534.0] + UNITS:"nT (1min)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Magnetic field vector in GSM cartesian coordinates (1 min)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_bgsm" + DEPEND_0:"Epoch" + DEPEND_1:"cartesian" + VAR_TYPE:"data" + TIME_RES:"1 min" + BRMSGSM: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"RMS vector in GSM coordinates (1 min)" + VALIDMIN:[0.0,0.0,0.0] + VALIDMAX:[65534.0,65534.0,65534.0] + UNITS:"nT (1min)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"RMS vector in GSM coordinates (1 min)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_bgsmr" + DEPEND_0:"Epoch" + DEPEND_1:"cartesian" + VAR_TYPE:"data" + TIME_RES:"1 min" + BGSE: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Magnetic field vector in GSE cartesian coordinates (1 min)" + VALIDMIN:[-65534.0,-65534.0,-65534.0] + VALIDMAX:[65534.0,65534.0,65534.0] + UNITS:"nT (1min)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Magnetic field vector in GSE cartesian coordinates (1 min)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_bgse" + DEPEND_0:"Epoch" + DEPEND_1:"cartesian" + VAR_TYPE:"data" + TIME_RES:"1 min" + BGSEa: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Magnetic field vector in angular GSE coordinates (1 min)" + VALIDMIN:[-65534.0,-90.0,0.0] + VALIDMAX:[65534.0,90.0,360.0] + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Magnetic field vector in GSE angular coordinates (1 min)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_bgse_ang" + UNIT_PTR:"units_bgse__ang" + DEPEND_0:"Epoch" + DEPEND_1:"angle" + FUNCTION:"conv_pos1" + COMPONENT_0:"BGSE" + VIRTUAL:"TRUE" + DISPLAY_TYPE:"time_series" + VAR_TYPE:"data" + TIME_RES:"1 min" + BRMSGSE: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"RMS vector in GSE coordinates (1 min)" + VALIDMIN:[0.0,0.0,0.0] + VALIDMAX:[65534.0,65534.0,65534.0] + UNITS:"nT (1min)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"RMS vector in GSE coordinates (1 min)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_bgser" + DEPEND_0:"Epoch" + DEPEND_1:"cartesian" + VAR_TYPE:"data" + TIME_RES:"1 min" + DIST: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Radial Distance (1 min)" + VALIDMIN:0.0 + VALIDMAX:300.0 + UNITS:"Re (1min)" + LABLAXIS:"Rad. Dist." + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Distance from the center of the earth (Define Re = 6378km) (1 min)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch" + VAR_TYPE:"data" + TIME_RES:"1 min" + PGSM: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Position in GSM coordinates (1 min)" + VALIDMIN:[-300.0,-300.0,-300.0] + VALIDMAX:[300.0,300.0,300.0] + UNITS:"Re (1min)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Position vector in GSM coordinates (Define Re = 6378km) (1 min)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_pgsm" + DEPEND_0:"Epoch" + DEPEND_1:"cartesian" + VAR_TYPE:"data" + TIME_RES:"1 min" + PGSE: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Position in GSE coordinates (1 min)" + VALIDMIN:[-300.0,-300.0,-300.0] + VALIDMAX:[300.0,300.0,300.0] + UNITS:"Re (1min)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Position vector in GSE coordinates (Define Re = 6378km) (1 min)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_pgse" + DEPEND_0:"Epoch" + DEPEND_1:"cartesian" + VAR_TYPE:"data" + TIME_RES:"1 min" + SGSM: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Unit spin vector in GSM coordinates (1 min)" + VALIDMIN:[-1.0,-1.0,-1.0] + VALIDMAX:[1.0,1.0,1.0] + UNITS:" " + LABLAXIS:"Unit Vector" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Unit spin vector in GSM coordinates (1 min)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch" + VAR_TYPE:"metadata" + TIME_RES:"1 min" + SGSE: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Unit spin vector in GSE coordinates (1 min)" + VALIDMIN:[-1.0,-1.0,-1.0] + VALIDMAX:[1.0,1.0,1.0] + UNITS:" " + LABLAXIS:"Unit Vector" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Unit spin vector in GSE coordinates (1 min)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch" + DEPEND_1:"cartesian" + VAR_TYPE:"support_data" + TIME_RES:"1 min" + DB_SC: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Delta B (Outer - Inner) (1 min)" + VALIDMIN:-25.0 + VALIDMAX:25.0 + UNITS:"nT" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Delta B (Outer - Inner) (1 min)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_dbsc" + DEPEND_0:"Epoch" + DEPEND_1:"cartesian" + VAR_TYPE:"support_data" + TIME_RES:"1 min" + TILTANG: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Dipole Tilt Angle (Degrees) (1 min)" + VALIDMIN:-35.0 + VALIDMAX:35.0 + UNITS:"Degrees" + LABLAXIS:"Dipole Tilt" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Dipole Tilt Angle (Degrees)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch" + VAR_TYPE:"support_data" + TIME_RES:"1 min" + RANGE_I: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Average Range Inner Magnetometer (1 min)" + VALIDMIN:0.0 + VALIDMAX:7.0 + UNITS:" " + LABLAXIS:"Range Inner" + FORMAT:"F4.2" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Average Range Inner Magnetometer (1 min)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch" + VAR_TYPE:"support_data" + TIME_RES:"1 min" + RANGE_O: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Average Range Outer Magnetometer (1 min)" + VALIDMIN:0.0 + VALIDMAX:7.0 + UNITS:" " + LABLAXIS:"Range Outer" + FORMAT:"F4.2" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Average Range Outer Magnetometer (1 min)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch" + VAR_TYPE:"support_data" + TIME_RES:"1 min" + SPC_MODE: + VarDescription: + DataType:"CDF_INT4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-2147483647 + VarAttributes: + FIELDNAM:"S/C operational mode (1 min)" + VALIDMIN:0 + VALIDMAX:10 + UNITS:" " + LABLAXIS:"S/C MODE" + FORMAT:"I2" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"S/C operational mode (1 min)" + FILLVAL:-1 + DEPEND_0:"Epoch" + VAR_TYPE:"support_data" + TIME_RES:"1 min" + MAG_MODE: + VarDescription: + DataType:"CDF_INT4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-2147483647 + VarAttributes: + FIELDNAM:"WIND/MFI operational mode (1 min)" + VALIDMIN:0 + VALIDMAX:15 + UNITS:" " + LABLAXIS:"MFI MODE" + FORMAT:"I2" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"WIND/MFI operational mode (1 min)" + FILLVAL:-1 + DEPEND_0:"Epoch" + VAR_TYPE:"support_data" + TIME_RES:"1 min" + Epoch3: + VarDescription: + DataType:"CDF_EPOCH" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:"0000-01-01T00:00:00.000" + VarAttributes: + FIELDNAM:"Time Line (3 sec)" + VALIDMIN:"1994-11-11T19:06:40.000" + VALIDMAX:"2030-12-30T17:06:40.000" + UNITS:"ms" + LABLAXIS:"Epoch" + FORMAT:"E14.8" + MONOTON:"INCREASE" + SCALETYP:"LINEAR" + CATDESC:"Time, Centered, Number of milliseconds since the epoch (3 sec)" + FILLVAL:"9999-12-31T23:59:59.999" + VAR_TYPE:"support_data" + TIME_RES:"3 sec" + Time3_PB5: + VarDescription: + DataType:"CDF_INT4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-2147483647 + VarAttributes: + FIELDNAM:"Time Line (3 sec)" + VALIDMIN:[1994,316,0] + VALIDMAX:[2030,365,0] + MONOTON:"INCREASE" + SCALETYP:"LINEAR" + CATDESC:"Time of observation in Year, Day, & milliseconds (3 sec)" + FILLVAL:-1 + LABL_PTR_1:"label_time" + UNIT_PTR:"unit_time" + FORM_PTR:"format_time" + DEPEND_0:"Epoch3" + DEPEND_1:"unit_time" + VAR_TYPE:"support_data" + TIME_RES:"3 sec" + NUM3_PTS: + VarDescription: + DataType:"CDF_INT4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-2147483647 + VarAttributes: + FIELDNAM:"Number of points in average (3 sec)" + VALIDMIN:0 + VALIDMAX:100 + UNITS:" " + LABLAXIS:"No. Points" + FORMAT:"I4" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Number of points in average (3 sec)" + FILLVAL:-1 + DEPEND_0:"Epoch3" + VAR_TYPE:"support_data" + TIME_RES:"3 sec" + B3F1: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Magnetic field magnitude (3 sec)" + VALIDMIN:0.0 + VALIDMAX:65534.0 + UNITS:"nT (3sec)" + LABLAXIS:"B" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Magnetic field magnitude (3 sec)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch3" + VAR_TYPE:"data" + TIME_RES:"3 sec" + VAR_NOTES:"Average of the magnitudes (F1)" + B3F1LOG: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Magnetic field magnitude (3 sec)" + VALIDMIN:0.0 + VALIDMAX:65534.0 + UNITS:"nT (3sec)" + LABLAXIS:"B" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LOG" + CATDESC:"Magnetic field magnitude (3 sec - log scaled)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch3" + FUNCTION:"alternate_view" + COMPONENT_0:"B3F1" + VIRTUAL:"TRUE" + VAR_TYPE:"data" + TIME_RES:"3 sec" + VAR_NOTES:"Average of the magnitudes (F1)" + B3RMSF1: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"RMS magnitude (3 sec)" + VALIDMIN:0.0 + VALIDMAX:65534.0 + UNITS:"nT (3sec)" + LABLAXIS:"B_RMS" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"RMS magnitude (3 sec)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch3" + VAR_TYPE:"data" + TIME_RES:"3 sec" + VAR_NOTES:"RMS of the magnitudes (F1 RMS)" + B3GSM: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Magnetic field vector in GSM cartesian coordinates (3 sec)" + VALIDMIN:[-65534.0,-65534.0,-65534.0] + VALIDMAX:[65534.0,65534.0,65534.0] + UNITS:"nT (3sec)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Magnetic field vector in GSM cartesian coordinates (3 sec)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_bgsm" + DEPEND_0:"Epoch3" + DEPEND_1:"cartesian" + VAR_TYPE:"data" + TIME_RES:"3 sec" + B3RMSGSM: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"RMS vector in GSM coordinates (3 sec)" + VALIDMIN:[0.0,0.0,0.0] + VALIDMAX:[65534.0,65534.0,65534.0] + UNITS:"nT (3sec)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"RMS vector in GSM coordinates (3 sec)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_bgsmr" + DEPEND_0:"Epoch3" + DEPEND_1:"cartesian" + VAR_TYPE:"data" + TIME_RES:"3 sec" + B3GSE: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Magnetic field vector in GSE cartesian coordinates (3 sec)" + VALIDMIN:[-65534.0,-65534.0,-65534.0] + VALIDMAX:[65534.0,65534.0,65534.0] + UNITS:"nT (3sec)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Magnetic field vector in GSE cartesian coordinates (3 sec)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_bgse" + DEPEND_0:"Epoch3" + DEPEND_1:"cartesian" + VAR_TYPE:"data" + TIME_RES:"3 sec" + B3GSEa: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Magnetic field vector in angular GSE coordinates (3 sec)" + VALIDMIN:[-65534.0,-90.0,0.0] + VALIDMAX:[65534.0,90.0,360.0] + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Magnetic field vector in GSE angular coordinates (3 sec)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_bgse_ang" + UNIT_PTR:"units_bgse3_ang" + DEPEND_0:"Epoch3" + DEPEND_1:"angle" + FUNCTION:"conv_pos1" + COMPONENT_0:"B3GSE" + VIRTUAL:"TRUE" + DISPLAY_TYPE:"time_series" + VAR_TYPE:"data" + TIME_RES:"3 sec" + B3RMSGSE: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"RMS vector in GSE coordinates (3 sec)" + VALIDMIN:[0.0,0.0,0.0] + VALIDMAX:[65534.0,65534.0,65534.0] + UNITS:"nT (3sec)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"RMS vector in GSE coordinates (3 sec)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_bgser" + DEPEND_0:"Epoch3" + DEPEND_1:"cartesian" + VAR_TYPE:"data" + TIME_RES:"3 sec" + Epoch1: + VarDescription: + DataType:"CDF_EPOCH" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:"0000-01-01T00:00:00.000" + VarAttributes: + FIELDNAM:"Time Line (1 hour)" + VALIDMIN:"1994-11-11T19:06:40.000" + VALIDMAX:"2030-12-30T17:06:40.000" + UNITS:"ms" + LABLAXIS:"Epoch" + FORMAT:"E14.8" + MONOTON:"INCREASE" + SCALETYP:"LINEAR" + CATDESC:"Time, Centered, Number of milliseconds since the epoch (1 hour)" + FILLVAL:"9999-12-31T23:59:59.999" + VAR_TYPE:"support_data" + TIME_RES:"1 hour" + Time1_PB5: + VarDescription: + DataType:"CDF_INT4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-2147483647 + VarAttributes: + FIELDNAM:"Time Line (1 hour)" + VALIDMIN:[1994,316,0] + VALIDMAX:[2030,365,0] + MONOTON:"INCREASE" + SCALETYP:"LINEAR" + CATDESC:"Time of observation in Year, Day, & milliseconds (1 hour)" + FILLVAL:-1 + LABL_PTR_1:"label_time" + UNIT_PTR:"unit_time" + FORM_PTR:"format_time" + DEPEND_0:"Epoch1" + DEPEND_1:"unit_time" + VAR_TYPE:"support_data" + TIME_RES:"1 hour" + NUM1_PTS: + VarDescription: + DataType:"CDF_INT4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-2147483647 + VarAttributes: + FIELDNAM:"Number of points in average (1 hour)" + VALIDMIN:0 + VALIDMAX:80000 + UNITS:" " + LABLAXIS:"No. Points" + FORMAT:"I4" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Number of points in average (1 hour)" + FILLVAL:-1 + DEPEND_0:"Epoch1" + VAR_TYPE:"support_data" + TIME_RES:"1 hour" + B1F1: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Magnetic field magnitude (1 hour)" + VALIDMIN:0.0 + VALIDMAX:65534.0 + UNITS:"nT (1hr)" + LABLAXIS:"B" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Magnetic field magnitude (1 hour)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch1" + VAR_TYPE:"data" + TIME_RES:"1 hour" + VAR_NOTES:"Average of the magnitudes (F1)" + B1F1LOG: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Magnetic field magnitude (1 hour)" + VALIDMIN:0.0 + VALIDMAX:65534.0 + UNITS:"nT (1hr)" + LABLAXIS:"B" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LOG" + CATDESC:"Magnetic field magnitude (1 hour - log scaled)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch1" + FUNCTION:"alternate_view" + COMPONENT_0:"B1F1" + VIRTUAL:"TRUE" + VAR_TYPE:"data" + TIME_RES:"1 hour" + VAR_NOTES:"Average of the magnitudes (F1)" + B1RMSF1: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"RMS magnitude (1 hour)" + VALIDMIN:0.0 + VALIDMAX:65534 + UNITS:"nT (1hr)" + LABLAXIS:"B_RMS" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"RMS magnitude (1 hour)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch1" + VAR_TYPE:"data" + TIME_RES:"1 hour" + VAR_NOTES:"RMS of the magnitudes (F1 RMS)" + B1GSM: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Magnetic field vector in GSM coordinates (1 hour)" + VALIDMIN:[-65534.0,-65534.0,-65534.0] + VALIDMAX:[65534.0,65534.0,65534.0] + UNITS:"nT (1hr)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Magnetic field vector in GSM cartesian coordinates (1 hour)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_bgsm" + DEPEND_0:"Epoch1" + DEPEND_1:"cartesian" + VAR_TYPE:"data" + TIME_RES:"1 hour" + B1RMSGSM: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"RMS vector in GSM coordinates (1 hour)" + VALIDMIN:[0.0,0.0,0.0] + VALIDMAX:[65534.0,65534.0,65534.0] + UNITS:"nT (1hr)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"RMS vector in GSM coordinates (1 hour)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_bgsmr" + DEPEND_0:"Epoch1" + DEPEND_1:"cartesian" + VAR_TYPE:"data" + TIME_RES:"1 hour" + B1GSE: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Magnetic field vector in GSE coordinates (1 hour)" + VALIDMIN:[-65534.0,-65534.0,-65534.0] + VALIDMAX:[65534.0,65534.0,65534.0] + UNITS:"nT (1hr)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Magnetic field vector in GSE cartesian coordinates (1 hour)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_bgse" + DEPEND_0:"Epoch1" + DEPEND_1:"cartesian" + VAR_TYPE:"data" + TIME_RES:"1 hour" + B1GSEa: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Magnetic field vector in angular GSE coordinates (1 hour)" + VALIDMIN:[-65534.0,-90.0,0.0] + VALIDMAX:[65534.0,90.0,360.0] + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Magnetic field vector in GSE angular coordinates (1 hour)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_bgse_ang" + UNIT_PTR:"units_bgse1_ang" + DEPEND_0:"Epoch1" + DEPEND_1:"angle" + FUNCTION:"conv_pos1" + COMPONENT_0:"B1GSE" + VIRTUAL:"TRUE" + DISPLAY_TYPE:"time_series" + VAR_TYPE:"data" + TIME_RES:"1 hour" + B1RMSGSE: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"RMS vector in GSE coordinates (1 hour)" + VALIDMIN:[0.0,0.0,0.0] + VALIDMAX:[65534.0,65534.0,65534.0] + UNITS:"nT (1hr)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"RMS vector in GSE coordinates (1 hour)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_bgser" + DEPEND_0:"Epoch1" + VAR_TYPE:"data" + TIME_RES:"1 hour" + DIST1: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Radial Distance (1 hour)" + VALIDMIN:0.0 + VALIDMAX:300.0 + UNITS:"Re (1hr)" + LABLAXIS:"Rad. Dist." + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Distance from the center of the earth (Define Re = 6378km) (1 hour)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch1" + VAR_TYPE:"data" + TIME_RES:"1 hour" + P1GSM: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Position in GSM coordinates (1 hour)" + VALIDMIN:[-300.0,-300.0,-300.0] + VALIDMAX:[300.0,300.0,300.0] + UNITS:"Re (1hr)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Position vector in GSM coordinates (Define Re = 6378km) (1 hour)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_pgsm" + DEPEND_0:"Epoch1" + DEPEND_1:"cartesian" + VAR_TYPE:"data" + TIME_RES:"1 hour" + P1GSE: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Position in GSE coordinates (1 hour)" + VALIDMIN:[-300.0,-300.0,-300.0] + VALIDMAX:[300.0,300.0,300.0] + UNITS:"Re (1hr)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Position vector in GSE coordinates (Define Re = 6378km) (1 hour)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_pgse" + DEPEND_0:"Epoch1" + DEPEND_1:"cartesian" + VAR_TYPE:"data" + TIME_RES:"1 hour" + DISTV: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Radial DistanceV (1 min)" + VALIDMIN:0.0 + VALIDMAX:300.0 + UNITS:"Re (1min)" + LABLAXIS:"Rad. Dist." + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Time axis label: Distance from the center of the earth (Define Re = 6378km) (1 min)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch" + FUNCTION:"alternate_view" + COMPONENT_0:"DIST" + VIRTUAL:"TRUE" + DISPLAY_TYPE:"time_text" + VAR_TYPE:"data" + TIME_RES:"1 min" + PGSMV: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Position in GSM coordinatesV (1 min)" + VALIDMIN:[-300.0,-300.0,-300.0] + VALIDMAX:[300.0,300.0,300.0] + UNITS:"Re (1min)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Time axis label: Position vector in GSM coordinates (Define Re = 6378km) (1 min)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_pgsm" + DEPEND_0:"Epoch" + DEPEND_1:"cartesian" + FUNCTION:"alternate_view" + COMPONENT_0:"PGSM" + VIRTUAL:"TRUE" + DISPLAY_TYPE:"time_text" + VAR_TYPE:"data" + TIME_RES:"1 min" + PGSEV: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Position in GSE coordinatesV (1 min)" + VALIDMIN:[-300.0,-300.0,-300.0] + VALIDMAX:[300.0,300.0,300.0] + UNITS:"Re (1min)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Time axis label: Position vector in GSE coordinates (Define Re = 6378km) (1 min)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_pgse" + DEPEND_0:"Epoch" + DEPEND_1:"cartesian" + FUNCTION:"alternate_view" + COMPONENT_0:"PGSE" + VIRTUAL:"TRUE" + DISPLAY_TYPE:"time_text" + VAR_TYPE:"data" + TIME_RES:"1 min" + DIST1V: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:0 + RecVariance:"VARY" + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Radial DistanceV (1 hour)" + VALIDMIN:0.0 + VALIDMAX:300.0 + UNITS:"Re (1hr)" + LABLAXIS:"Rad. Dist." + FORMAT:"E9.2" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Time axis label: Distance from the center of the earth (Define Re = 6378km) (1 hour)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch1" + FUNCTION:"alternate_view" + COMPONENT_0:"DIST1" + VIRTUAL:"TRUE" + DISPLAY_TYPE:"time_text" + VAR_TYPE:"data" + TIME_RES:"1 hour" + P1GSMV: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Position in GSM coordinatesV (1 hour).." + VALIDMIN:[-300.0,-300.0,-300.0] + VALIDMAX:[300.0,300.0,300.0] + UNITS:"Re (1hr)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Time axis label: Position vector in GSM coordinates (Define Re = 6378km) (1 hour)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_pgsm" + DEPEND_0:"Epoch1" + DEPEND_1:"cartesian" + FUNCTION:"alternate_view" + COMPONENT_0:"P1GSM" + VIRTUAL:"TRUE" + DISPLAY_TYPE:"time_text" + VAR_TYPE:"data" + TIME_RES:"1 hour" + P1GSEV: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Position in GSE coordinatesV (1 hour)" + VALIDMIN:[-300.0,-300.0,-300.0] + VALIDMAX:[300.0,300.0,300.0] + UNITS:"Re (1hr)" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Time axis label: Position vector in GSE coordinates (Define Re = 6378km) (1 hour)" + FILLVAL:-1.0E+31 + LABL_PTR_1:"label_pgse" + DEPEND_0:"Epoch1" + DEPEND_1:"cartesian" + FUNCTION:"alternate_view" + COMPONENT_0:"P1GSE" + VIRTUAL:"TRUE" + DISPLAY_TYPE:"time_text" + VAR_TYPE:"data" + TIME_RES:"1 hour" + S1GSM: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Unit spin vector in GSM coordinates (1 hour)" + VALIDMIN:[-1.0,-1.0,-1.0] + VALIDMAX:[1.0,1.0,1.0] + UNITS:" " + LABLAXIS:"Unit Vector" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Unit spin vector in GSM coordinates (1 hour)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch1" + VAR_TYPE:"metadata" + TIME_RES:"1 hour" + S1GSE: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:1 + DimSizes:[3] + RecVariance:"VARY" + DimVariances:["VARY"] + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Unit spin vector in GSE coordinates (1 hour)" + VALIDMIN:[-1.0,-1.0,-1.0] + VALIDMAX:[1.0,1.0,1.0] + UNITS:" " + LABLAXIS:"Unit Vector" + FORMAT:"E13.6" + MONOTON:"FALSE" + SCALETYP:"LINEAR" + CATDESC:"Unit spin vector in GSE coordinates (1 hour)" + FILLVAL:-1.0E+31 + DEPEND_0:"Epoch1" + VAR_TYPE:"metadata" + TIME_RES:"1 hour" + ZERO_I: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:2 + DimSizes:[3,8] + RecVariance:"NOVARY" + DimVariances:["VARY","VARY"] + NumWrittenRecords:1 + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Sensor Zeros (Inner)" + FILLVAL:-1.0E+31 + VAR_TYPE:"metadata" + VarData: + [1883.02, 2007.32, 2045.7, 2047.08, 2044.32, 2045.11, 2049.03, 2048.01, 1478.36, 1902.24, 2022.31, 2041.32, 2047.11, 2046.75, 2051.94, 2047.98, 2018.11, 2052.2, 2045.6, 2044.24, 2045.32, 2047.34, 2049.08, 2048.02] + SENS_I: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:2 + DimSizes:[3,8] + RecVariance:"NOVARY" + DimVariances:["VARY","VARY"] + NumWrittenRecords:1 + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Sensor Sensitivities (Inner)" + FILLVAL:-1.0E+31 + VAR_TYPE:"metadata" + VarData: + [0.00207329, 0.00783044, 0.0323013, 0.126701, 0.501958, 1.96778, 8.04288, 31.5194, 0.00201679, 0.00783654, 0.0318094, 0.125311, 0.493705, 1.94592, 7.91017, 31.1714, 0.00206, 0.007905, 0.03231, 0.12691, 0.50356, 1.97663, 8.06849, 31.6655] + AMPL_I: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:2 + DimSizes:[3,8] + RecVariance:"NOVARY" + DimVariances:["VARY","VARY"] + NumWrittenRecords:1 + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Amplitude Correction (Inner)" + FILLVAL:-1.0E+31 + VAR_TYPE:"metadata" + VarData: + [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] + ORTH_I: + VarDescription: + DataType:"CDF_REAL8" + NumElements:1 + NumDims:2 + DimSizes:[3,3] + RecVariance:"NOVARY" + DimVariances:["VARY","VARY"] + NumWrittenRecords:1 + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Orthogonalization Matrix (Inner)" + FILLVAL:-1.0E+31 + VAR_TYPE:"metadata" + VarData: + [0.999733, 0.00995519, -0.024519, 0.00166613, 0.999941, -0.0161693, 0.019728, 0.0171892, 0.999669] + PAYLD_I: + VarDescription: + DataType:"CDF_REAL8" + NumElements:1 + NumDims:2 + DimSizes:[3,3] + RecVariance:"NOVARY" + DimVariances:["VARY","VARY"] + NumWrittenRecords:1 + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Payload Rotation Matrix (Inner)" + FILLVAL:-1.0E+31 + VAR_TYPE:"metadata" + VarData: + [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0] + FLAG_I: + VarDescription: + DataType:"CDF_INT4" + NumElements:1 + NumDims:0 + RecVariance:"NOVARY" + NumWrittenRecords:1 + PadValue:-2147483647 + VarAttributes: + FIELDNAM:"Sensor Zero Flag (Inner)" + FILLVAL:-1 + VAR_TYPE:"metadata" + VarData: + [5] + ZERO_O: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:2 + DimSizes:[3,8] + RecVariance:"NOVARY" + DimVariances:["VARY","VARY"] + NumWrittenRecords:1 + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Sensor Zeros (Outer)" + FILLVAL:-1.0E+31 + VAR_TYPE:"metadata" + VarData: + [-9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30] + SENS_O: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:2 + DimSizes:[3,8] + RecVariance:"NOVARY" + DimVariances:["VARY","VARY"] + NumWrittenRecords:1 + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Sensor Sensitivities (Outer)" + FILLVAL:-1.0E+31 + VAR_TYPE:"metadata" + VarData: + [-9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30] + AMPL_O: + VarDescription: + DataType:"CDF_REAL4" + NumElements:1 + NumDims:2 + DimSizes:[3,8] + RecVariance:"NOVARY" + DimVariances:["VARY","VARY"] + NumWrittenRecords:1 + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Amplitude Correction (Outer)" + FILLVAL:-1.0E+31 + VAR_TYPE:"metadata" + VarData: + [-9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30, -9.999999848243207E+30] + ORTH_O: + VarDescription: + DataType:"CDF_REAL8" + NumElements:1 + NumDims:2 + DimSizes:[3,3] + RecVariance:"NOVARY" + DimVariances:["VARY","VARY"] + NumWrittenRecords:1 + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Orthogonalization Matrix (Outer)" + FILLVAL:-1.0E+31 + VAR_TYPE:"metadata" + VarData: + [-1.0E+31, -1.0E+31, -1.0E+31, -1.0E+31, -1.0E+31, -1.0E+31, -1.0E+31, -1.0E+31, -1.0E+31] + PAYLD_O: + VarDescription: + DataType:"CDF_REAL8" + NumElements:1 + NumDims:2 + DimSizes:[3,3] + RecVariance:"NOVARY" + DimVariances:["VARY","VARY"] + NumWrittenRecords:1 + PadValue:-1.0E+30 + VarAttributes: + FIELDNAM:"Payload Rotation Matrix (Outer)" + FILLVAL:-1.0E+31 + VAR_TYPE:"metadata" + VarData: + [-1.0E+31, -1.0E+31, -1.0E+31, -1.0E+31, -1.0E+31, -1.0E+31, -1.0E+31, -1.0E+31, -1.0E+31] + FLAG_O: + VarDescription: + DataType:"CDF_INT4" + NumElements:1 + NumDims:0 + RecVariance:"NOVARY" + NumWrittenRecords:1 + PadValue:-2147483647 + VarAttributes: + FIELDNAM:"Sensor Zero Flag (Outer)" + FILLVAL:-1 + VAR_TYPE:"metadata" + VarData: + [-1] + label_time: + VarDescription: + DataType:"CDF_CHAR" + NumElements:27 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Label for Time_PB5" + VAR_TYPE:"metadata" + VarData: + ["Year ", "Day of Year (Jan 1 = Day 1)", "Elapsed milliseconds of day"] + format_time: + VarDescription: + DataType:"CDF_CHAR" + NumElements:2 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Format for Time_PB5" + VAR_TYPE:"metadata" + VarData: + ["I4", "I3", "I8"] + unit_time: + VarDescription: + DataType:"CDF_CHAR" + NumElements:4 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Units for Time_PB5" + VAR_TYPE:"metadata" + VarData: + ["year", "day ", "msec"] + units_bgse__ang: + VarDescription: + DataType:"CDF_CHAR" + NumElements:10 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Units for B in GSE angular coordinates" + VAR_TYPE:"metadata" + VarData: + ["nT (1min) ", "Deg.(1min)", "Deg.(1min)"] + units_bgse3_ang: + VarDescription: + DataType:"CDF_CHAR" + NumElements:10 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Units for B in GSE angular coordinates" + VAR_TYPE:"metadata" + VarData: + ["nT (3sec) ", "Deg.(3sec)", "Deg.(3sec)"] + units_bgse1_ang: + VarDescription: + DataType:"CDF_CHAR" + NumElements:9 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Units for B in GSE angular coordinates" + VAR_TYPE:"metadata" + VarData: + ["nT(1hr) ", "Deg.(1hr)", "Deg.(1hr)"] + label_bgse_ang: + VarDescription: + DataType:"CDF_CHAR" + NumElements:13 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Label for B in GSE angular coordinates" + VAR_TYPE:"metadata" + VarData: + ["B (GSE) ", " Lat-B (GSE)", "Phi-B (GSE) "] + label_bgsm: + VarDescription: + DataType:"CDF_CHAR" + NumElements:8 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Label for B in GMS coordinates" + VAR_TYPE:"metadata" + VarData: + ["Bx (GSM)", "By (GSM)", "Bz (GSM)"] + label_bgse: + VarDescription: + DataType:"CDF_CHAR" + NumElements:8 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Label for B in GSE coordinates" + VAR_TYPE:"metadata" + VarData: + ["Bx (GSE)", "By (GSE)", "Bz (GSE)"] + label_bgsmr: + VarDescription: + DataType:"CDF_CHAR" + NumElements:12 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Label for B RMS in GSM coordinates" + VAR_TYPE:"metadata" + VarData: + ["Bx_RMS (GSM)", "By_RMS (GSM)", "Bz_RMS (GSM)"] + label_bgser: + VarDescription: + DataType:"CDF_CHAR" + NumElements:12 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Label for B RMS in GSE coordinates" + VAR_TYPE:"metadata" + VarData: + ["Bx_RMS (GSE)", "By_RMS (GSE)", "Bz_RMS (GSE)"] + label_dbsc: + VarDescription: + DataType:"CDF_CHAR" + NumElements:12 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Label for delta B spacecraft" + VAR_TYPE:"metadata" + VarData: + ["X (Delta SC)", "Y (Delta SC)", "Z (Delta SC)"] + label_pgsm: + VarDescription: + DataType:"CDF_CHAR" + NumElements:7 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Label for S/C Position in GSM coordinates" + VAR_TYPE:"metadata" + VarData: + ["X (GSM)", "Y (GSM)", "Z (GSM)"] + label_pgse: + VarDescription: + DataType:"CDF_CHAR" + NumElements:7 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Label for S/C Position in GSE coordinates" + VAR_TYPE:"metadata" + VarData: + ["X (GSE)", "Y (GSE)", "Z (GSE)"] + cartesian: + VarDescription: + DataType:"CDF_CHAR" + NumElements:11 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Dimension Label" + VAR_TYPE:"metadata" + DICT_KEY:"ISTP>vector>cartesian" + VarData: + ["x-component", "y-component", "z-component"] + angle: + VarDescription: + DataType:"CDF_CHAR" + NumElements:5 + NumDims:1 + DimSizes:[3] + RecVariance:"NOVARY" + DimVariances:["VARY"] + NumWrittenRecords:1 + PadValue:" " + VarAttributes: + FIELDNAM:"Dimension Label" + VAR_TYPE:"metadata" + DICT_KEY:"ISTP>vector>angle" + VarData: + ["r ", "theta", "phi "] + EmptyAttributes: + VariableAttributes:["LABL_PTR_2","AVE_TYPE"] diff --git a/cdf36_3-dist/cdfjava/cdfml/AAREADME.1ST b/cdf38_1-dist/cdfjava/cdfml/AAREADME.1ST similarity index 100% rename from cdf36_3-dist/cdfjava/cdfml/AAREADME.1ST rename to cdf38_1-dist/cdfjava/cdfml/AAREADME.1ST diff --git a/cdf38_1-dist/cdfjava/cdfml/Readme.txt b/cdf38_1-dist/cdfjava/cdfml/Readme.txt new file mode 100644 index 0000000..06fce7a --- /dev/null +++ b/cdf38_1-dist/cdfjava/cdfml/Readme.txt @@ -0,0 +1,78 @@ +*************************************************************************** +* Please make sure that you have done the following before proceeding * +* with the CDF Markup Language (CDFML) utilities: * +* * +* - Installed JDK 1.7 or later. * +* - installed/built the CDF distribution package. * +* - optionally, install Oracle's Multi-Schema XML Validator. * +*************************************************************************** + +Instructions for using the CDF's CDFML programs +----------------------------------------------- + +1. Set the CLASSPATH and LD_LIBRARY_PATH (DYLD_LIBRARY_PATH for Mac OSX) + environment variables. [On Windows, run setenv.bat located in the top + distribution to the setup, if not already done when the package + was installed.] + + 1) CLASSPATH should point to the following information: + - the location (full path name) of the cdfml.jar file that was + extracted in step 1. + - the location (full path name) of the cdfjava.jar file. + + Examples: + + - using Oracle's Java + + setenv CLASSPATH ${CLASSPATH}:.: \ + /home/cdf/cdf38_1-dist/cdfjava/classes/cdfjava.jar: \ + /home/cdf/cdf38_1-dist/cdfjava/cdfml/cdfml.jar + + Note: + Absolute/full path name (not relative path) MUST be used when adding + the location of a program to the CLASSPATH environment variable. + + + 2) LD_LIBRARY_PATH should point to the following information: + - the location (full path name) of the CDF-Java JNI + libcdfNativeLibrary.[so|sl|jnilib] (it should be under cdfjava/lib + from the distribution) + + - the location (full path name) of the CDF shared library that is + defined by the environment variable CDF_LIB. This variable is + defined when the CDF library is installed. + + Example: + setenv LD_LIBRARY_PATH .:/home/cdf/cdf38_1-dist/cdfjava/lib:${CDF_LIB} + + OR for Mac OSX, + setenv DYLD_LIBRARY_PATH .:/home/cdf/cdf38_1-dist/cdfjava/lib:${CDF_LIB} + + +3. Use CDF2CDFML Java program to create a CDFML document from a CDF file. + To get the instructions and valid arguments/options, enter: + + java CDF2CDFML + +4. Use CDFML2CDF Java program to convert a CDFML document to a CDF file. To + get the instructions and valid arguments/options, enter: + + java CDFML2CDF + +5. Use Oracle's Multi-Schema Validator, a Java tool, to validate a CDFML document + conforming to cdf.dtd or cdf.xsd, if needed. + + Run: java -jar msv.jar cdf.dtd test.xml or + java -jar msv.jar cdf.xsd testxsd.xml + + +Note: + If one creates a CDFML file from an existing CDF file and creates a new + CDF file from that CDFML file, the contents of the new file is the same + as the original CDF file. But the ordering of some of the variable + attributes in the new file could be different from the original file + that should be transparent to the users. + + Please direct any comments or questions to: + gsfc-cdf-support@lists.nasa.gov + diff --git a/cdf36_3-dist/cdfjava/cdfml/about.cdfVarData b/cdf38_1-dist/cdfjava/cdfml/about.cdfVarData similarity index 100% rename from cdf36_3-dist/cdfjava/cdfml/about.cdfVarData rename to cdf38_1-dist/cdfjava/cdfml/about.cdfVarData diff --git a/cdf36_3-dist/cdfjava/cdfml/cdf.dtd b/cdf38_1-dist/cdfjava/cdfml/cdf.dtd similarity index 95% rename from cdf36_3-dist/cdfjava/cdfml/cdf.dtd rename to cdf38_1-dist/cdfjava/cdfml/cdf.dtd index ae76d33..1cbff9e 100644 --- a/cdf36_3-dist/cdfjava/cdfml/cdf.dtd +++ b/cdf38_1-dist/cdfjava/cdfml/cdf.dtd @@ -7,6 +7,7 @@ May 2002 1.0 Original Oct 11, 2007 1.1 Added the CDF_EPOCH16 data type. Oct 20, 2011 1.2 Added the CDF_INT8 and CDF_TIME_TT2000 data type. + Feb 20, 2018 1.3 Added ARM and Itanium ports. --> @@ -15,6 +16,7 @@ + @@ -32,7 +34,7 @@ fileFormat (SINGLE | MULTI) #IMPLIED compression (%CDF_COMPRESSION1; | %CDF_COMPRESSION2;) #IMPLIED majority (ROW | COLUMN) #IMPLIED - encoding (%CDF_ENCODING1; | %CDF_ENCODING2; | %CDF_ENCODING3;) #IMPLIED + encoding (%CDF_ENCODING1; | %CDF_ENCODING2; | %CDF_ENCODING3; | %CDF_ENCODING4;) #IMPLIED negToPosFp0 (ENABLE | DISABLE) #IMPLIED > diff --git a/cdf36_3-dist/cdfjava/cdfml/cdf.xsd b/cdf38_1-dist/cdfjava/cdfml/cdf.xsd similarity index 77% rename from cdf36_3-dist/cdfjava/cdfml/cdf.xsd rename to cdf38_1-dist/cdfjava/cdfml/cdf.xsd index 8c1bdcf..0725f10 100644 --- a/cdf36_3-dist/cdfjava/cdfml/cdf.xsd +++ b/cdf38_1-dist/cdfjava/cdfml/cdf.xsd @@ -15,6 +15,7 @@ targetNamespace. Added the CDF_EPOCH16 data type. Oct 21, 2011 1.2 Added CDF_INT8 and CDF_TIME_TT2000 data types. + May 21, 2018 1.2 Added data types for choice elements. @@ -65,6 +66,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -133,7 +169,25 @@ - + + + + + + + + + + + + + + + + + diff --git a/cdf36_3-dist/cdfjava/cdfml/test.cdf b/cdf38_1-dist/cdfjava/cdfml/test.cdf similarity index 100% rename from cdf36_3-dist/cdfjava/cdfml/test.cdf rename to cdf38_1-dist/cdfjava/cdfml/test.cdf diff --git a/cdf36_3-dist/cdfjava/cdfml/test.xml b/cdf38_1-dist/cdfjava/cdfml/test.xml similarity index 100% rename from cdf36_3-dist/cdfjava/cdfml/test.xml rename to cdf38_1-dist/cdfjava/cdfml/test.xml diff --git a/cdf36_3-dist/cdfjava/cdfml/testdtd.xml b/cdf38_1-dist/cdfjava/cdfml/testdtd.xml similarity index 100% rename from cdf36_3-dist/cdfjava/cdfml/testdtd.xml rename to cdf38_1-dist/cdfjava/cdfml/testdtd.xml diff --git a/cdf36_3-dist/cdfjava/cdfml/testnew.cdf b/cdf38_1-dist/cdfjava/cdfml/testnew.cdf similarity index 100% rename from cdf36_3-dist/cdfjava/cdfml/testnew.cdf rename to cdf38_1-dist/cdfjava/cdfml/testnew.cdf diff --git a/cdf36_3-dist/cdfjava/cdfml/testxsd.xml b/cdf38_1-dist/cdfjava/cdfml/testxsd.xml similarity index 100% rename from cdf36_3-dist/cdfjava/cdfml/testxsd.xml rename to cdf38_1-dist/cdfjava/cdfml/testxsd.xml diff --git a/cdf38_1-dist/cdfjava/cdftools/CDFToolsDriver.jar b/cdf38_1-dist/cdfjava/cdftools/CDFToolsDriver.jar new file mode 100644 index 0000000..5c03fc4 Binary files /dev/null and b/cdf38_1-dist/cdfjava/cdftools/CDFToolsDriver.jar differ diff --git a/cdf38_1-dist/cdfjava/classes/cdfjava.jar b/cdf38_1-dist/cdfjava/classes/cdfjava.jar new file mode 100644 index 0000000..8d771c3 Binary files /dev/null and b/cdf38_1-dist/cdfjava/classes/cdfjava.jar differ diff --git a/cdf38_1-dist/cdfjava/classes/cdfjson.jar b/cdf38_1-dist/cdfjava/classes/cdfjson.jar new file mode 100644 index 0000000..2c3b3f7 Binary files /dev/null and b/cdf38_1-dist/cdfjava/classes/cdfjson.jar differ diff --git a/cdf38_1-dist/cdfjava/classes/cdfml.jar b/cdf38_1-dist/cdfjava/classes/cdfml.jar new file mode 100644 index 0000000..a45ec5b Binary files /dev/null and b/cdf38_1-dist/cdfjava/classes/cdfml.jar differ diff --git a/cdf38_1-dist/cdfjava/classes/gson-2.8.6.jar b/cdf38_1-dist/cdfjava/classes/gson-2.8.6.jar new file mode 100644 index 0000000..4765c4a Binary files /dev/null and b/cdf38_1-dist/cdfjava/classes/gson-2.8.6.jar differ diff --git a/cdf38_1-dist/cdfjava/classes/javax.json-1.0.4.jar b/cdf38_1-dist/cdfjava/classes/javax.json-1.0.4.jar new file mode 100644 index 0000000..09967d8 Binary files /dev/null and b/cdf38_1-dist/cdfjava/classes/javax.json-1.0.4.jar differ diff --git a/cdf36_3-dist/cdfjava/examples/CreateCDF.java b/cdf38_1-dist/cdfjava/examples/CreateCDF.java similarity index 97% rename from cdf36_3-dist/cdfjava/examples/CreateCDF.java rename to cdf38_1-dist/cdfjava/examples/CreateCDF.java index cfb79ab..6247b1b 100644 --- a/cdf36_3-dist/cdfjava/examples/CreateCDF.java +++ b/cdf38_1-dist/cdfjava/examples/CreateCDF.java @@ -77,6 +77,7 @@ public static void main(String[] args) { test = Attribute.create(cdf, "Test", GLOBAL_SCOPE), testDate = Attribute.create(cdf, "TestDate", GLOBAL_SCOPE), ep16TestDate = Attribute.create(cdf, "epTestDate", GLOBAL_SCOPE), + utf8 = Attribute.create(cdf, "utf8", GLOBAL_SCOPE), validMin = Attribute.create(cdf, "VALIDMIN", VARIABLE_SCOPE), validMax = Attribute.create(cdf, "VALIDMAX", VARIABLE_SCOPE), @@ -272,7 +273,7 @@ public static void main(String[] args) { System.out.println("Adding global attribute entries..."); - Entry.create(project, 0, CDF_CHAR, "Using the CDFJava ƒ ∑ API"); + Entry.create(project, 0, CDF_CHAR, "Using the CDFJava API"); Entry.create(pi, 3, CDF_CHAR, "Ernie Els"); System.out.println("\tchars completed."); @@ -315,6 +316,9 @@ public static void main(String[] args) { Entry.create(test,16,CDF_UINT1, new short[] {255,254}); System.out.println("\tUINT1 completed."); + Entry.create(test,17,CDF_INT8, new Long(23456789010L)); + System.out.println("\tINT8 completed."); + double testDateData = Epoch.compute(2002, 4, 25, 0, 0, 0, 0); Entry.create(testDate, 1, CDF_EPOCH, new Double(testDateData)); System.out.println("\tEPOCH completed."); @@ -330,6 +334,16 @@ public static void main(String[] args) { new Long(testTT2000)); System.out.println("\tEPOCH completed."); + String spdf1 = new String("ASCII: ABCDEFG"); + String spdf2 = new String("Latin1: ©æêü÷Ƽ®¢¥"); + String spdf3 = new String("Chinese: 社安"); + String spdf4 = new String("Other: ႡႢႣႤႥႦ"); + Entry.create(utf8, 0, CDF_CHAR, spdf1); + Entry.create(utf8, 1, CDF_CHAR, spdf2); + Entry.create(utf8, 2, CDF_CHAR, spdf3); + Entry.create(utf8, 3, CDF_CHAR, spdf4); + System.out.println("\tUTF8 completed."); + /************************************/ /* Add variable attribute entries */ /************************************/ @@ -337,8 +351,8 @@ public static void main(String[] args) { // Entry.create(validMin, longitude.getID(), CDF_INT2, // new Short((short)10)); - Entry.create(validMin, longitude.getID(), CDF_CHAR, - "Test by David"); + Entry.create(validMin, longitude.getID(), CDF_INT2, + new Short((short)-10)); latitude.putEntry(validMin, CDF_INT2, new Short((short)20)); System.out.println("\tAdded VALIDMIN entries."); @@ -366,6 +380,10 @@ public static void main(String[] args) { tt2000.putEntry(dummy, CDF_TIME_TT2000, new Long(testDateData2)); System.out.println("\tAdded dummy for tt2000."); + newI8.putEntry(validMin, CDF_INT8, new Long(-12345678900L)); + newI8.putEntry(validMax, CDF_INT8, new Long(12345678900L)); + System.out.println("\tAdded VALIDMAX/VALIBMIN entries for newI8."); + char ch = 'a'; String myStr = String.valueOf(ch); longitude.putEntry(myAttr, CDF_CHAR, myStr); @@ -637,7 +655,7 @@ public static void main(String[] args) { double epData = Epoch.compute(1999, 3, 5, 5, 6, 7, 100), epData1 = Epoch.compute(1998, 1, 2, 3, 4, 5, 666); String e0 = Epoch.encode(epData1); - double p0 = Epoch.parse(e0); + double p0 = Epoch.toParse(e0); ep.putSingleData(0L, new long[] {0}, new Double(epData)); ep.putSingleData(1L, new long[] {0}, new Double(p0)); @@ -703,7 +721,7 @@ public static void main(String[] args) { long [] nanosecs = new long[5]; long nansecSinceJ2000; try { - nansecSinceJ2000 = CDFTT2000.fromUTCstring(dateTime); + nansecSinceJ2000 = CDFTT2000.toParse(dateTime); } catch (CDFException ex) { nansecSinceJ2000 = 0; } diff --git a/cdf36_3-dist/cdfjava/examples/ReadCDF.java b/cdf38_1-dist/cdfjava/examples/ReadCDF.java similarity index 85% rename from cdf36_3-dist/cdfjava/examples/ReadCDF.java rename to cdf38_1-dist/cdfjava/examples/ReadCDF.java index ec35a00..b8542e1 100644 --- a/cdf36_3-dist/cdfjava/examples/ReadCDF.java +++ b/cdf38_1-dist/cdfjava/examples/ReadCDF.java @@ -26,14 +26,18 @@ public static void main(String[] args) { jj = args.length; if (jj == 0) jj = 1; -/* + try { + + System.out.println("CDF Library version: "+CDF.getLibraryVersion()+"\n"); +/* CDF.setValidate (VALIDATEFILEoff); +*/ } catch (CDFException vax) { - System.out.println("*** Error at setting the validation..."+vax); + System.out.println("*** Error... "+vax); System.exit(1); } -*/ + for (ii = 0; ii < jj; ++ii) { if (args.length != 0) fileName = args[ii]; if (ii > 0) @@ -124,7 +128,7 @@ public static void main(String[] args) { System.out.println (attrName+" ("+n+" entries):"); } else { - String currAttrName = a.getName();; + String currAttrName = a.getName(); if (currAttrName != attrName) { if (n <= 1) System.out.println (currAttrName+" ("+n+" entry):"); @@ -135,30 +139,24 @@ public static void main(String[] args) { i++; Vector ent = a.getEntries(); for (Enumeration e1 =ent.elements() ; e1.hasMoreElements() ;) { - Entry entry = (Entry) e1.nextElement(); - if (entry != null) { - long eDataType = entry.getDataType(); - System.out.print ("\t"+entry.getID()+" ("+ + Entry entry = (Entry) e1.nextElement(); + if (entry != null) { + long eDataType = entry.getDataType(); + System.out.print ("\t"+entry.getID()+" ("+ CDFUtils.getStringDataType(eDataType)+ "/"+entry.getNumElements()+ "): \t"); - Object data = entry.getData(); - if (eDataType == CDF_EPOCH) { - CDFUtils.printData ( - Epoch.encode(((Double) data).doubleValue())); - } else if (eDataType == CDF_EPOCH16) { - CDFUtils.printData (Epoch16.encode((double[])data)); - } else if (eDataType == CDF_TIME_TT2000) { - CDFUtils.printData ( - CDFTT2000.encode(((Long)data).longValue())); - } else { - if (CDFUtils.isStringDataType(eDataType)) - System.out.print("\""); - CDFUtils.printData (data); - if (CDFUtils.isStringDataType(eDataType)) - System.out.print("\""); - } - System.out.println (" "); + Object data = entry.getData(); + if (eDataType == CDF_EPOCH) { + System.out.println(Epoch.toEncode(((Double) data).doubleValue())); + } else if (eDataType == CDF_EPOCH16) { + System.out.println(Epoch16.toEncode((double[])data)); + } else if (eDataType == CDF_TIME_TT2000) { + System.out.println(CDFTT2000.toEncode(((Long)data).longValue())); + } else { + CDFUtils.printData (data); + } +// System.out.println (" "); } } System.out.println (" "); @@ -194,31 +192,49 @@ public static void main(String[] args) { Variable v = cdf.getVariable(entry.getID()); System.out.print ("\t"+v.getName()+" ("+ CDFUtils.getStringDataType(eDataType)+ - "/"+entry.getNumElements()+ - "): "); - + "/"+entry.getNumElements()+"): "); Object data = entry.getData(); if (eDataType == CDF_EPOCH) { - CDFUtils.printData ( - Epoch.encode(((Double) data).doubleValue())); + System.out.println(Epoch.toEncode(((Double) data).doubleValue())); } else if (eDataType == CDF_EPOCH16) { - CDFUtils.printData (Epoch16.encode((double[])data)); + System.out.println(Epoch16.toEncode((double[])data)); } else if (eDataType == CDF_TIME_TT2000) { - CDFUtils.printData ( - CDFTT2000.encode(((Long) data).longValue())); + System.out.println(CDFTT2000.toEncode(((Long) data).longValue())); } else { - if (CDFUtils.isStringDataType(eDataType)) - System.out.print("\""); - CDFUtils.printData (data); - if (CDFUtils.isStringDataType(eDataType)) - System.out.print("\""); + if (entry.getScope() == VARIABLE_SCOPE) { + if (CDFUtils.isStringDataType(eDataType)) { + if (data instanceof String[]) { + long ix = ((String[])data).length; + System.out.println("\t("+ix+" string"+(ix>1?"s":"")+") "); + int iy; + for (iy=0; iy 0) + System.out.println(""); + System.out.println("Reading " + fileName + "...:\n"); + try { + cdf = null; + cdf = CDF.open(fileName, READONLYon); + if (cdf.getStatus() != CDF_OK) + { + if (cdf.getStatus() == CHECKSUM_ERROR) + System.out.println("*** Checksum failed... the cdf file is corrupted...\n"); + if (cdf != null) cdf.close(); + } else { + + /************************************************************/ + /* If a decoding method is not specified when a CDF file is */ + /* opened, the CDF libaray knows what encoding method was */ + /* used to create the CDF file. */ + /* */ + /* Decoding method should be specified only if one needs */ + /* to translate data from one platform to another. */ + /************************************************************/ + // cdf.selectDecoding(NETWORK_DECODING); + + /**********************************/ + /* Print out the file information */ + /**********************************/ + System.out.println("File Info\n"+ + "========================================="); + + if (cdf.confirmReadOnlyMode() == READONLYon) + System.out.println("CDF File: "+cdf+" (READONLYon)"); + else { + System.out.println("CDF File: "+cdf+" (READONLYoff)"); + } + + System.out.println("Version: "+cdf.getVersion()); + String cp = cdf.getCopyright(); + System.out.println("Copyright: "+cp); + System.out.println("Format: "+CDFUtils.getStringFormat(cdf)); + System.out.println("Encoding: "+ + CDFUtils.getStringEncoding(cdf)); + System.out.println("Decoding: "+ + CDFUtils.getStringDecoding(cdf)); + System.out.println("Majority: "+ + CDFUtils.getStringMajority(cdf)); + if (cdf.getMajority() == COLUMN_MAJOR) + System.out.println("(******** Data dumps from multi-dimensional "+ + "variables are shown row-based.)"); + System.out.println("Checksum: "+ + CDFUtils.getStringChecksum(cdf)); + System.out.println("numRvars: "+cdf.getNumRvars()); + System.out.println("numZvars: "+cdf.getNumZvars()); + System.out.println("numAttrs: "+cdf.getNumAttrs()+ + " ("+cdf.getNumGattrs()+" global, "+ + cdf.getNumVattrs()+" variable)"); + System.out.println("Compression: "+cdf.getCompression()); + if (cdf.getCompressionType() != 0) + System.out.println("cPct: "+cdf.getCompressionPct()); + if (new Integer(cdf.getVersion().substring(0,1)).intValue() > 3) { + long lsLastUpdated = cdf.getLeapSecondLastUpdated(); + if (lsLastUpdated > 0) + System.out.println("LeapSecondLastUpdated: "+lsLastUpdated); + } + System.out.println("Cache Size: "+cdf.confirmCDFCacheSize()); + + /**********************************************/ + /* Print out the Global Attribute information */ + /**********************************************/ + Attribute a; + String attrName = null; + int i; + long n = cdf.getNumGattrs(); + Vector ga = cdf.getGlobalAttributes(); + + System.out.println("\nGlobal Attributes ("+n+" attributes)\n"+ + "========================================="); + i = 0; + for (Enumeration e = ga.elements() ; e.hasMoreElements() ;) { + a = (Attribute) e.nextElement(); + n = a.getNumEntries(); + if (i == 0) { + attrName = a.getName(); + if (n <= 1) + System.out.println (attrName+" ("+n+" entry):"); + else + System.out.println (attrName+" ("+n+" entries):"); + } + else { + String currAttrName = a.getName(); + if (currAttrName != attrName) { + if (n <= 1) + System.out.println (currAttrName+" ("+n+" entry):"); + else + System.out.println (currAttrName+" ("+n+" entries):"); + } + } + i++; + Vector ent = a.getEntries(); + for (Enumeration e1 =ent.elements() ; e1.hasMoreElements() ;) { + Entry entry = (Entry) e1.nextElement(); + if (entry != null) { + long eDataType = entry.getDataType(); + System.out.print ("\t"+entry.getID()+" ("+ + CDFUtils.getStringDataType(eDataType)+ + "/"+entry.getNumElements()+ + "): \t"); + Object data = entry.getData(); + if (eDataType == CDF_EPOCH) { + System.out.println(Epoch.toEncode(((Double) data).doubleValue())); + } else if (eDataType == CDF_EPOCH16) { + System.out.println(Epoch16.toEncode((double[])data)); + } else if (eDataType == CDF_TIME_TT2000) { + System.out.println(CDFTT2000.toEncode(((Long)data).longValue())); + } else { + CDFUtils.printData (data); + } +// System.out.println (" "); + } + } + System.out.println (" "); + } + + /************************************************/ + /* Print out the Variable Attribute information */ + /************************************************/ + attrName = null; + n = cdf.getNumVattrs(); + Vector va = cdf.getVariableAttributes(); + + System.out.println("\nVariable Attributes ("+n+" attributes)\n"+ + "========================================="); + i = 0; + for (Enumeration e = va.elements() ; e.hasMoreElements() ;) { + a = (Attribute) e.nextElement(); + if (i == 0) { + attrName = a.getName(); + System.out.println (attrName+":"); + } + else { + String currAttrName = a.getName();; + if (currAttrName != attrName) + System.out.println (currAttrName+":"); + } + i++; + Vector ent = a.getEntries(); + for (Enumeration e1 =ent.elements() ; e1.hasMoreElements() ;) { + Entry entry = (Entry) e1.nextElement(); + if (entry != null) { + long eDataType = entry.getDataType(); + Variable v = cdf.getVariable(entry.getID()); + System.out.print ("\t"+v.getName()+" ("+ + CDFUtils.getStringDataType(eDataType)+ + "/"+entry.getNumElements()+"): "); + Object data = entry.getData(); + if (eDataType == CDF_EPOCH) { + System.out.println(Epoch.toEncode(((Double) data).doubleValue())); + } else if (eDataType == CDF_EPOCH16) { + System.out.println(Epoch16.toEncode((double[])data)); + } else if (eDataType == CDF_TIME_TT2000) { + System.out.println(CDFTT2000.toEncode(((Long) data).longValue())); + } else { + if (entry.getScope() == VARIABLE_SCOPE) { + if (CDFUtils.isStringDataType(eDataType)) { + if (data instanceof String[]) { + long ix = ((String[])data).length; + System.out.println("\t("+ix+" string"+(ix>1?"s":"")+") "); + int iy; + for (iy=0; iy 0) System.out.print (","); + System.out.print (dimSizes[i]); + } + System.out.print ("] "); + // if (numDims == 1) System.out.print ("\t"); + + System.out.print((v.getRecVariance() ? "T" : "F")+"/"); + long[] dimVariances = v.getDimVariances(); + for (i=0; i < v.getNumDims(); i++) + System.out.print( + ((dimVariances[i] == CDFConstants.VARY) ? "T" : "F")); + + String sparseRecord = CDFUtils.getStringSparseRecord(v); + if (!sparseRecord.equals("None")) + System.out.print (" sparseRecord=\""+sparseRecord+"\""); + + // Print the user-define pad value if one exists. + // if (v.checkPadValueExistence()) { +/* + padValue = v.getPadValue(); + if (dt == CDF_EPOCH) + padValue = Epoch.toEncode(((Double) padValue).doubleValue()); + else if (dt == CDF_EPOCH16) + padValue = Epoch16.toEncode((double[]) padValue); + else if (dt == CDF_TIME_TT2000) + padValue = CDFTT2000.toEncode(((Long) padValue).longValue()); + else if (dt != CDF_REAL4 && dt != CDF_FLOAT && + dt != CDF_REAL8 && dt != CDF_DOUBLE) + System.out.print (" PadValue="+((CDFUtils.isStringDataType(dt)|| + CDFUtils.isEpochDataType(dt))? + "\"":"")+padValue+ + ((CDFUtils.isStringDataType(dt)|| + CDFUtils.isEpochDataType(dt))?"\"":"")); + else { + String format; + try { + Attribute attr = cdf.getAttribute("FORMAT"); + format = (String) attr.getEntry (v.getID()).getData(); + } catch (CDFException ee) { + format = null; + } + System.out.print (" PadValue="); + CDFUtils.printDataWithFormat (padValue,format); + } +*/ + // } + + blockingFactor = v.getBlockingFactor(); + if (blockingFactor > 0) + System.out.print (" blockingFactor=\""+blockingFactor+"\""); + + System.out.println (" "); + } + + /**********************************************************/ + /* Print out the Variable data (all variables in the CDF) */ + /**********************************************************/ + System.out.println("\n\nVariable Data ("+n+" variables)\n"+ + "========================================="); + CDFData data = null; + long numRecs, maxRec; + long[] dimIndices = {0L}; + long[] dimIntervals = {1L}; + long[] dimSizes = {1L}; + + for (Enumeration e = vars.elements() ; e.hasMoreElements() ;) { + Variable v = (Variable) e.nextElement(); + + if (v.getNumDims() > 0) { + dimSizes = v.getDimSizes(); + dimIntervals = new long[dimSizes.length]; + dimIndices = new long[dimSizes.length]; + for (i=0; i < dimSizes.length; i++) { + dimIntervals[i] = 1; + dimIndices[i] = 0; + } + } + maxRec = v.getMaxWrittenRecord(); + numRecs = v.getNumWrittenRecords(); + varName = v.getName(); + System.out.println (varName); + String format; + try { + Attribute attr = cdf.getAttribute("FORMAT"); + format = (String) attr.getEntry (v.getID()).getData(); + } catch (CDFException ee) { + format = null; + } + + for (i=0; i < varName.length(); i++) + System.out.print ("-"); + System.out.println (" "); + + if (v.getCompressionType() == NO_COMPRESSION) + System.out.println ("Compression: None"); + else + System.out.println ("Compression: "+ + v.getCompression()+" ("+ + v.getCompressionPct()+"%)"); + if (v.checkPadValueExistence()) { + long myDT = v.getDataType(); + Object pv = v.getPadValue(); + if (pv != null) { + if (myDT == CDF_EPOCH) + System.out.println ("Pad value: "+ + Epoch.toEncode(((Double)pv).doubleValue())); + else if (myDT == CDF_EPOCH16) + System.out.println ("Pad value: "+ + Epoch16.toEncode((double[])pv)); + else if (myDT == CDF_TIME_TT2000) + System.out.println ("Pad value: "+ + CDFTT2000.toUTCstring(((Long)pv).longValue())); + else if (CDFUtils.isStringDataType(myDT)) + System.out.println ("Pad value: \""+ pv+"\""); + else { + System.out.print ("Pad value: "); + CDFUtils.printDataWithFormat (pv, format); + } + } + } + System.out.println ("Records: "+ + numRecs+"n/"+maxRec+"x"); + System.out.println ("Allocated: "+ + v.getNumAllocatedRecords()+"n/"+ + v.getMaxAllocatedRecord()+"x"); + System.out.println ("Blocking Factor: "+ + v.getBlockingFactor()); + System.out.println ("Sparseness: "+ + CDFUtils.getStringSparseRecord(v)); + System.out.println (" "); + + /********************************************************/ + /* maxRec represents the last record number for this */ + /* variable, not the number of records. */ + /* */ + /* NOTE: maxRec starts at 0, so if the value of maxRec */ + /* is 2, the actual number of records is 3. */ + /* If there are no records exists, the value of */ + /* maxRec is -1. */ + /********************************************************/ +/* + long status; + for (i=0; i <= maxRec; i++) { + data = v.getHyperDataObject(i, 1, 1, + dimIndices, + dimSizes, + dimIntervals); + status = cdf.getStatus(); + if (status == CDF_OK || status != VIRTUAL_RECORD_DATA) { + System.out.println ("Record # "+i+":"); + data.dumpDataWithFormat(format); + } + } +*/ + } + cdf.close(); + } + } catch (Exception e) { + System.out.println (e); + } + } + } +} diff --git a/cdf38_1-dist/cdfjava/examples/test-arm.cdf b/cdf38_1-dist/cdfjava/examples/test-arm.cdf new file mode 100644 index 0000000..c6e31f1 Binary files /dev/null and b/cdf38_1-dist/cdfjava/examples/test-arm.cdf differ diff --git a/cdf36_3-dist/cdfjava/examples/test.cdf b/cdf38_1-dist/cdfjava/examples/test.cdf similarity index 84% rename from cdf36_3-dist/cdfjava/examples/test.cdf rename to cdf38_1-dist/cdfjava/examples/test.cdf index ac26feb..3c6a108 100644 Binary files a/cdf36_3-dist/cdfjava/examples/test.cdf and b/cdf38_1-dist/cdfjava/examples/test.cdf differ diff --git a/cdf38_1-dist/cdfjava/examples/test0.cdf b/cdf38_1-dist/cdfjava/examples/test0.cdf new file mode 100644 index 0000000..3c2251a Binary files /dev/null and b/cdf38_1-dist/cdfjava/examples/test0.cdf differ diff --git a/cdf38_1-dist/cdfjava/examples/test1.cdf b/cdf38_1-dist/cdfjava/examples/test1.cdf new file mode 100644 index 0000000..d807d4b Binary files /dev/null and b/cdf38_1-dist/cdfjava/examples/test1.cdf differ diff --git a/cdf36_3-dist/cdfjava/examples/testCdfColMajor.cdf b/cdf38_1-dist/cdfjava/examples/testCdfColMajor.cdf similarity index 100% rename from cdf36_3-dist/cdfjava/examples/testCdfColMajor.cdf rename to cdf38_1-dist/cdfjava/examples/testCdfColMajor.cdf diff --git a/cdf36_3-dist/cdfjava/examples/testCdfRowMajor.cdf b/cdf38_1-dist/cdfjava/examples/testCdfRowMajor.cdf similarity index 100% rename from cdf36_3-dist/cdfjava/examples/testCdfRowMajor.cdf rename to cdf38_1-dist/cdfjava/examples/testCdfRowMajor.cdf diff --git a/cdf38_1-dist/cdfjava/examples/testjson.cdf b/cdf38_1-dist/cdfjava/examples/testjson.cdf new file mode 100644 index 0000000..aa458ac Binary files /dev/null and b/cdf38_1-dist/cdfjava/examples/testjson.cdf differ diff --git a/cdf38_1-dist/cdfjava/examples/testo.cdf b/cdf38_1-dist/cdfjava/examples/testo.cdf new file mode 100644 index 0000000..f7fc98f Binary files /dev/null and b/cdf38_1-dist/cdfjava/examples/testo.cdf differ diff --git a/cdf38_1-dist/cdfjava/jni/Makefile b/cdf38_1-dist/cdfjava/jni/Makefile new file mode 100644 index 0000000..356f2f6 --- /dev/null +++ b/cdf38_1-dist/cdfjava/jni/Makefile @@ -0,0 +1,93 @@ +#------------------------------------------------------------------------------ +# Copyright 1996-2016 United States Government as represented by the +# Administrator of the National Aeronautics and Space Administration. +# All Rights Reserved. +#------------------------------------------------------------------------------ +# +# SPDF/CDF JNI library makefile. +# +# Version 1.0, 23-Jun-2020 +# +# Modification history: +# +# V1.0 23-Jun-20, M Liu Original version. +# +#------------------------------------------------------------------------------ +# + +.SILENT: + +SHELL=/bin/sh +NULL=true + +SHARED= +PIC= +CCx= +LDx= +COPTIONS= +SYSLIBS= +JNIEXT= +SHAREDEXT= +LDOPTIONS= +VERSION= +JAVA_HOME= +JNIOS= +LDLIB= +MAKE=make + +INCLUDEcdf=../../src/include +INCLUDEjni1=. +INCLUDEjni2=$(JAVA_HOME)/include +INCLUDEjni3=$(INCLUDEjni2)/$(JNIOS) + +CC=$(CCx) +LD=$(LDx) + +CFLAGS=$(COPTIONS) $(PIC) -I$(INCLUDEcdf) -I$(INCLUDEjni1) -I$(INCLUDEjni2) -I$(INCLUDEjni3) +LDFLAGS=$(LDOPTIONS) + +#OBJs=cdfNativeLibrary.o ../../src/lib/libcdf.$(SHAREDEXT) +OBJs=cdfNativeLibrary.o ../../src/lib/libcdf.a + +CDFh=$(INCLUDEcdf)/cdf.h $(INCLUDEcdf)/cdfconfig.h $(INCLUDEcdf)/cdfdist.h $(INCLUDEcdf)/cdflib.h $(INCLUDEcdf)/cdflib64.h +JNIh=cdfNativeLibrary.h cdfjava.h + +#------------------------------------------------------------------------------ +# Compile/link. +#------------------------------------------------------------------------------ + +all: shared.$(SHARED) + +shared.yes: libcdfNativeLibrary.$(JNIEXT) + +libcdfNativeLibrary.so \ +libcdfNativeLibrary.jnilib \ +libcdfNativeLibrary.dll \ +libcdfNativeLibrary.sl: $(OBJs) + @if [ -f $@ ] ; then rm $@ ; else $(NULL) ; fi + @echo $(LD) $(LDFLAGS) -o $@ $(OBJs) $(LDLIB) -lc -lm + $(LD) $(LDFLAGS) -o $@ $(OBJs) $(LDLIB) -lc -lm +.c.o: + @echo $(CC) $(CFLAGS) -c $< ; \ + $(CC) $(CFLAGS) -c $< ; \ + +cdfNativeLibrary.o: cdfNativeLibrary.c $(CDFh) $(JNIh) + +shared.no: + +#------------------------------------------------------------------------------ +# Clean/purge. +#------------------------------------------------------------------------------ + +clean: + @-rm -f *.o + @-rm -f core + @-rm -f libcdfNativeLibrary.so + @-rm -f libcdfNativeLibrary.sl + @-rm -f libcdfNativeLibrary.jnilib + @-rm -f libcdfNativeLibrary.dll + +purge: + @-rm -f *~ + @-rm -f *# + diff --git a/cdf36_3-dist/cdfjava/jni/cdfNativeLibrary.c b/cdf38_1-dist/cdfjava/jni/cdfNativeLibrary.c similarity index 97% rename from cdf36_3-dist/cdfjava/jni/cdfNativeLibrary.c rename to cdf38_1-dist/cdfjava/jni/cdfNativeLibrary.c index 1386f5b..4bc0f58 100644 --- a/cdf36_3-dist/cdfjava/jni/cdfNativeLibrary.c +++ b/cdf38_1-dist/cdfjava/jni/cdfNativeLibrary.c @@ -1,5 +1,5 @@ /* - * $Id: cdfNativeLibrary.c,v 1.1.1.1 2016/10/12 19:21:25 liu Exp $ + * $Id: cdfNativeLibrary.c,v 1.2 2021/12/13 20:42:14 mhliu Exp $ */ /****************************************************************************** * Copyright 1996-2014 United States Government as represented by the @@ -110,6 +110,7 @@ static jfieldID cdfStatusID, infoWarnID; static long envVar; static long lib_ver; static char *leapTable; +static int realChar; /* A list of currently available CDFs. This list allows multiple cdfs to be @@ -296,6 +297,7 @@ void getJavaField(JNIEnv *env, argument *arg) { } sprintf(msg,"dummySig = %s", dummySig); MYDEBUG("getJavaField", msg); + switch (dummySig[0]) { case 'Z': /* boolean */ break; @@ -435,6 +437,7 @@ void getJavaField(JNIEnv *env, argument *arg) { case 'L': /* object */ if (strcmp(dummySig,"Ljava/lang/String;") == 0) { +int iu; if (arg->isArray) { /* N/A */ } else { arg->tempString = @@ -442,6 +445,9 @@ void getJavaField(JNIEnv *env, argument *arg) { if (arg->ptr != NULL) free (arg->ptr); arg->ptr = (void *) (*env)->GetStringUTFChars(env, arg->tempString, 0); +//printf("in JNI... "); +//for (iu=0; iu < arg->length; ++iu) printf("%02X ",*(((char *)arg->ptr)+iu)); +//printf("\n"); /* Have to comment out the following line as it causes problems if the combined string is bigger than 2048, the size of msg buffer. */ /* sprintf(msg, "field = %s value(String) = %s", @@ -728,8 +734,30 @@ void setJavaField(JNIEnv *env, argument arg) { string is bigger than 2048, the size of msg buffer. */ /* sprintf(msg,"name = %s; sig = %s val = %s\n", arg.name, arg.sig, ((char *) arg.ptr)); */ - (*env)->SetObjectField(env, arg.myObject, arg.id, - (*env)->NewStringUTF(env, (char *) arg.ptr)); +//printf("###### from CDF: value=%s (len=%d)\n",(char *)arg.ptr,(int)arg.length); fflush(stdout); + if (realChar == 0) { + jobject bb = (*env)->NewDirectByteBuffer(env, (void *) arg.ptr, + (jlong) arg.length-1); + jclass cls_Charset = (*env)->FindClass(env, "java/nio/charset/Charset"); + jmethodID mid_Charset_forName = (*env)->GetStaticMethodID(env, + cls_Charset, "forName", + "(Ljava/lang/String;)Ljava/nio/charset/Charset;"); + jobject charset = (*env)->CallStaticObjectMethod(env, cls_Charset, + mid_Charset_forName, (*env)->NewStringUTF(env, + "UTF-8")); + jmethodID mid_Charset_decode = (*env)->GetMethodID(env, cls_Charset, + "decode", "(Ljava/nio/ByteBuffer;)Ljava/nio/CharBuffer;"); + jobject cb = (*env)->CallObjectMethod(env, charset, + mid_Charset_decode, bb); + jclass cls_CharBuffer = (*env)->FindClass(env, "java/nio/CharBuffer"); + jmethodID mid_CharBuffer_toString = (*env)->GetMethodID(env, + cls_CharBuffer, "toString", "()Ljava/lang/String;"); + jstring str = (*env)->CallObjectMethod(env, cb, + mid_CharBuffer_toString); + (*env)->SetObjectField(env, arg.myObject, arg.id, str); + } else + (*env)->SetObjectField(env, arg.myObject, arg.id, + (*env)->NewStringUTF(env, (char *) arg.ptr)); } } else if (strcmp(dummySig, "Ljava/lang/Byte;") == 0) { sprintf(msg,"building byte object"); @@ -1140,6 +1168,8 @@ CDFstatus getItem(JNIEnv *env, jobject theCDF, jobject itemObj, jobject parent, (strcmp(arg->name, "_data") == 0)) || ((*env)->IsAssignableFrom(env, entryClass, parentClass) && (strcmp(arg->name, "data") == 0)) || + ((*env)->IsAssignableFrom(env, entryClass, parentClass) && + (strcmp(arg->name, "_data") == 0)) || ((*env)->IsAssignableFrom(env, varClass, parentClass) && (strcmp(arg->name, "padValue") == 0))); if (arg->isEntryorVariableData) { @@ -1848,10 +1878,10 @@ CDFstatus JAVAcdflib (JNIEnv *env, return (ErrHandle(status, env, &arg, &arg2, &arg3, &arg4, NULL)); - /****************************************************/ - /* Add the oid (CDF id) returned by the CDFlib call */ - /* to the link list. */ - /****************************************************/ + /****************************************************/ + /* Add the oid (CDF id) returned by the CDFlib call */ + /* to the link list. */ + /****************************************************/ newID = addCDFid(oid); /********************************/ @@ -2057,7 +2087,7 @@ CDFstatus JAVAcdflib (JNIEnv *env, nextItem = (*env)->CallObjectMethod(env, cmdVector, vElemID, i++); if (isItem(nextItem)) { status2 = getFuncOrItem(env, nextItem, &item); - + realChar = 0; while (item < NULL_) { sprintf(msg,"func = %ld item = %ld status = %ld",func,item, @@ -2090,6 +2120,7 @@ CDFstatus JAVAcdflib (JNIEnv *env, case gENTRY_NUMELEMS_: case zENTRY_DATATYPE_: case zENTRY_NUMELEMS_: + case zENTRY_NUMSTRINGS_: case zVAR_NAME_: case zVAR_NUMELEMS_: case zVAR_DATATYPE_: @@ -2109,22 +2140,28 @@ CDFstatus JAVAcdflib (JNIEnv *env, case LIB_RELEASE_: case LIB_VERSION_: case LIB_subINCREMENT_: - if (item == CDF_COPYRIGHT_ || item == LIB_COPYRIGHT_) + if (item == CDF_COPYRIGHT_ || item == LIB_COPYRIGHT_) { + realChar = 1; arg.length = CDF_COPYRIGHT_LEN + 1; + } if (item == ATTR_NAME_) { + realChar = 1; if (lib_ver == 2 || CDFgetFileBackward()) arg.length = CDF_ATTR_NAME_LEN + 1; else arg.length = CDF_ATTR_NAME_LEN256 + 1; } if (item == zVAR_NAME_) { + realChar = 1; if (lib_ver == 2 || CDFgetFileBackward()) arg.length = CDF_VAR_NAME_LEN + 1; else arg.length = CDF_VAR_NAME_LEN256 + 1; } - if (item == LIB_subINCREMENT_) + if (item == LIB_subINCREMENT_) { + realChar = 1; arg.length = 2; + } nextItem = (*env)->CallObjectMethod(env, cmdVector, vElemID, i++); @@ -2198,6 +2235,7 @@ CDFstatus JAVAcdflib (JNIEnv *env, case zVAR_DATA_: case zVAR_HYPERDATA_: case zVAR_PADVALUE_: + if (item == zVAR_PADVALUE_) realChar = 1; nextItem = (*env)->CallObjectMethod(env, cmdVector, vElemID, i++); status = getItem(env, theCDF, nextItem, obj, &arg); if (!CheckStatus("cdflib (GET_, ENTRY/VARIABLE_DATA_) 1", 0)) @@ -2339,6 +2377,7 @@ CDFstatus JAVAcdflib (JNIEnv *env, return(status); nextItem = (*env)->CallObjectMethod(env, cmdVector, vElemID, i++); + status = getItem(env, theCDF, nextItem, obj, &arg3); if (!CheckStatus("cdflib (PUT_,ENTRY_DATA_) 3", 0)) return(status); @@ -2901,6 +2940,7 @@ Java_gsfc_nssdc_cdf_CDFNativeLibrary_cdfNativeLib(JNIEnv *env, } /* Java_gsfc_nssdc_cdf_CDFNativeLibrary_cdfNativeLib */ + /********************************************* ** ** ** Epoch Utility Wrappers ** diff --git a/cdf36_3-dist/cdfjava/jni/cdfNativeLibrary.h b/cdf38_1-dist/cdfjava/jni/cdfNativeLibrary.h similarity index 100% rename from cdf36_3-dist/cdfjava/jni/cdfNativeLibrary.h rename to cdf38_1-dist/cdfjava/jni/cdfNativeLibrary.h diff --git a/cdf36_3-dist/cdfjava/jni/cdfjava.h b/cdf38_1-dist/cdfjava/jni/cdfjava.h similarity index 98% rename from cdf36_3-dist/cdfjava/jni/cdfjava.h rename to cdf38_1-dist/cdfjava/jni/cdfjava.h index 917f042..5ee59c6 100644 --- a/cdf36_3-dist/cdfjava/jni/cdfjava.h +++ b/cdf38_1-dist/cdfjava/jni/cdfjava.h @@ -1,4 +1,4 @@ -/* $Id: cdfjava.h,v 1.1.1.1 2016/10/12 19:21:25 liu Exp $ +/* $Id: cdfjava.h,v 1.1.1.1 2020/05/08 13:29:57 mhliu Exp $ * */ /****************************************************************************** diff --git a/cdf36_3-dist/checkleapseconds.sh b/cdf38_1-dist/checkleapseconds.sh similarity index 77% rename from cdf36_3-dist/checkleapseconds.sh rename to cdf38_1-dist/checkleapseconds.sh index c6b6cf6..f26dab3 100755 --- a/cdf36_3-dist/checkleapseconds.sh +++ b/cdf38_1-dist/checkleapseconds.sh @@ -1,12 +1,14 @@ #! /bin/sh +echo echo Checking for the leap second table... local_url=`printenv CDF_LEAPSECONDSTABLE` if [ -z "$local_url" ]; then echo CDF_LEAPSECONDSTABLE environment variable is not defined... echo Internal hard-coded leap second table may be used... - if [ -n "$CDF_BIN" ]; then - result=`$CDF_BIN/cdfleapsecondsinfo -nodump` + if [ -n "$CDF_BASE" ]; then + result=`$CDF_BASE/bin/cdfleapsecondsinfo -nodump` local_leap=`echo $result | cut -d " " -f31` + ls_folder= else echo "Enter the latest, installed CDF directory: "; read ls_folder @@ -21,7 +23,7 @@ else local_leap=`tail -1 ${local_url}| awk '{ print $1"-"$2"-"$3 }'`; ls_folder=`dirname $local_url` fi -remote_url="http://cdf.gsfc.nasa.gov/html/CDFLeapSeconds.txt" +remote_url="https://cdf.gsfc.nasa.gov/html/CDFLeapSeconds.txt" isCurlAvail=`which curl` if [ `echo "$isCurlAvail" | grep -c "no "` -eq 1 ]; then `wget -q -O /tmp/CDFLeapSeconds.txt ${remote_url}` @@ -47,14 +49,19 @@ localdate=`expr $lyear*10000+$lmonth*100+$lday | bc` remotedate=`expr $ryear*10000+$rmonth*100+$rday | bc` if [ $localdate -lt $remotedate ]; then echo "" - echo "Newer leap second(s) had been added to CDFLeapSeconds.txt at the CDF" + echo "You are using the leap second table at $local_url" + echo "But, newer leap second(s) had been added to CDFLeapSeconds.txt at the CDF" echo "home page. Please update your CDF installation that includes the" - echo "latest CDFLeapSeconds.txt from http://cdf.gsfc.nasa.gov." + echo "latest CDFLeapSeconds.txt from https://cdf.gsfc.nasa.gov." echo "" else if [ $localdate -eq $remotedate ]; then echo "" - echo "Local CDFLeapSeconds.txt in $ls_folder is up-to-date." + if [ -z "$ls_folder" ]; then + echo "Hard-coded CDFLeapSeconds.txt is up-to-date." + else + echo "Local CDFLeapSeconds.txt in $ls_folder is up-to-date." + fi echo "" else echo "" diff --git a/cdf38_1-dist/modify_definition_files.sh b/cdf38_1-dist/modify_definition_files.sh new file mode 100755 index 0000000..f017216 --- /dev/null +++ b/cdf38_1-dist/modify_definition_files.sh @@ -0,0 +1,80 @@ +#! /bin/bash +search="" +replace=$1 # Current working directory +whichos=`uname` +case "$whichos" in + CYGWIN*) topath=1;; + MINGW*) topath=1;; + Darwin*) topath=2;; + * ) topath=0;; +esac + +for file in `ls $replace/bin/definitions.*` +do + extension="${file:${#file}-1}" + if [ $topath -eq 1 ]; then + if [ $extension == "B" ] || [ $extension == "K" ]; then + echo "export PATH=\"$CDF_BASE/lib:\$PATH\"" >> $file + else + echo "setenv PATH \"$CDF_BASE/lib:\$PATH\"" >> $file + fi + elif [ $topath -eq 2 ]; then + if [ $extension == "B" ] || [ $extension == "K" ]; then + echo "if [ -z \$DYLD_LIBRARY_PATH ]; then" >> $file + echo " export DYLD_LIBRARY_PATH=\$CDF_BASE/lib" >> $file + echo "else" >> $file + echo " LDY=\`printenv DYLD_LIBRARY_PATH\`" >> $file + echo " if ! [[ \$LDY =~ \"\$CDF_BASE/lib\" ]]; then" >> $file + echo " export DYLD_LIBRARY_PATH=\$CDF_BASE/lib:\$DYLD_LIBRARY_PATH" >> $file + echo " fi" >> $file + echo "fi" >> $file + else + echo "if \$?DYLD_LIBRARY_PATH then" >> $file + echo " set LDY=\`printenv DYLD_LIBRARY_PATH\`" >> $file + echo " if ( \$LDY !~ \*\${CDF_BASE}/lib\* ) then" >> $file + echo " setenv DYLD_LIBRARY_PATH \$CDF_BASE/lib:\$DYLD_LIBRARY_PATH" >> $file + echo " endif" >> $file + echo "else" >> $file + echo " setenv DYLD_LIBRARY_PATH \$CDF_BASE/lib" >> $file + echo "endif" >> $file + fi + else + if [ $extension == "B" ] || [ $extension == "K" ]; then + echo "if [ -z \$LD_LIBRARY_PATH ]; then" >> $file + echo " export LD_LIBRARY_PATH=\$CDF_BASE/lib" >> $file + echo "else" >> $file + echo " LDY=\`printenv LD_LIBRARY_PATH\`" >> $file + echo " if ! [[ \$LDY =~ \"\$CDF_BASE/lib\" ]]; then" >> $file + echo " export LD_LIBRARY_PATH=\$CDF_BASE/lib:\$LD_LIBRARY_PATH" >> $file + echo " fi" >> $file + echo "fi" >> $file + else + echo "if \$?LD_LIBRARY_PATH then" >> $file + echo " set LDY=\`printenv LD_LIBRARY_PATH\`" >> $file + echo " if ( \$LDY !~ \*\$CDF_BASE/lib\* ) then" >> $file + echo " setenv LD_LIBRARY_PATH \$CDF_BASE/lib:\$LD_LIBRARY_PATH" >> $file + echo " endif" >> $file + echo "else" >> $file + echo " setenv LD_LIBRARY_PATH \$CDF_BASE/lib" >> $file + echo "endif" >> $file + fi + fi + + echo "Modifying the definition file $file .." + if `type ed > /dev/null 2>&1` + then + ed - $file << editend + 1,\$s:$search:$replace:g + w + q +editend + elif `type sed > /dev/null 2>&1` + then + sed -e "s,$search,$replace,g" < $file > $file.new + mv $file.new $file + else + echo Not modified... as both "ed" and "sed" line editor not installed. + echo Use any available text editor to manually modify "$search" to "$replace". + fi +done + diff --git a/cdf36_3-dist/samples/OperateAttributes.c b/cdf38_1-dist/samples/OperateAttributes.c similarity index 100% rename from cdf36_3-dist/samples/OperateAttributes.c rename to cdf38_1-dist/samples/OperateAttributes.c diff --git a/cdf36_3-dist/samples/OperateCDF.c b/cdf38_1-dist/samples/OperateCDF.c similarity index 100% rename from cdf36_3-dist/samples/OperateCDF.c rename to cdf38_1-dist/samples/OperateCDF.c diff --git a/cdf36_3-dist/samples/OperateVariables.c b/cdf38_1-dist/samples/OperateVariables.c similarity index 100% rename from cdf36_3-dist/samples/OperateVariables.c rename to cdf38_1-dist/samples/OperateVariables.c diff --git a/cdf36_3-dist/samples/cacsst2.cdf b/cdf38_1-dist/samples/cacsst2.cdf similarity index 100% rename from cdf36_3-dist/samples/cacsst2.cdf rename to cdf38_1-dist/samples/cacsst2.cdf diff --git a/cdf36_3-dist/samples/cacsst2.skt b/cdf38_1-dist/samples/cacsst2.skt similarity index 100% rename from cdf36_3-dist/samples/cacsst2.skt rename to cdf38_1-dist/samples/cacsst2.skt diff --git a/cdf36_3-dist/src/include/cdf.inc b/cdf38_1-dist/samples/cdf.inc similarity index 100% rename from cdf36_3-dist/src/include/cdf.inc rename to cdf38_1-dist/samples/cdf.inc diff --git a/cdf36_3-dist/samples/d103a2x.cdf b/cdf38_1-dist/samples/d103a2x.cdf similarity index 100% rename from cdf36_3-dist/samples/d103a2x.cdf rename to cdf38_1-dist/samples/d103a2x.cdf diff --git a/cdf36_3-dist/samples/example.dat b/cdf38_1-dist/samples/example.dat similarity index 100% rename from cdf36_3-dist/samples/example.dat rename to cdf38_1-dist/samples/example.dat diff --git a/cdf36_3-dist/samples/example1.c b/cdf38_1-dist/samples/example1.c similarity index 100% rename from cdf36_3-dist/samples/example1.c rename to cdf38_1-dist/samples/example1.c diff --git a/cdf38_1-dist/samples/example1.cdf b/cdf38_1-dist/samples/example1.cdf new file mode 100644 index 0000000..c8b928f Binary files /dev/null and b/cdf38_1-dist/samples/example1.cdf differ diff --git a/cdf36_3-dist/samples/example2.cdf b/cdf38_1-dist/samples/example2.cdf similarity index 76% rename from cdf36_3-dist/samples/example2.cdf rename to cdf38_1-dist/samples/example2.cdf index 3a900a1..550bbfd 100644 Binary files a/cdf36_3-dist/samples/example2.cdf and b/cdf38_1-dist/samples/example2.cdf differ diff --git a/cdf36_3-dist/samples/example2.f b/cdf38_1-dist/samples/example2.f similarity index 100% rename from cdf36_3-dist/samples/example2.f rename to cdf38_1-dist/samples/example2.f diff --git a/cdf36_3-dist/samples/geocpi0.cdf b/cdf38_1-dist/samples/geocpi0.cdf similarity index 100% rename from cdf36_3-dist/samples/geocpi0.cdf rename to cdf38_1-dist/samples/geocpi0.cdf diff --git a/cdf36_3-dist/samples/geocpi0.skt b/cdf38_1-dist/samples/geocpi0.skt similarity index 100% rename from cdf36_3-dist/samples/geocpi0.skt rename to cdf38_1-dist/samples/geocpi0.skt diff --git a/cdf36_3-dist/samples/geocpi1.cdf b/cdf38_1-dist/samples/geocpi1.cdf similarity index 100% rename from cdf36_3-dist/samples/geocpi1.cdf rename to cdf38_1-dist/samples/geocpi1.cdf diff --git a/cdf36_3-dist/samples/geocpi2.cdf b/cdf38_1-dist/samples/geocpi2.cdf similarity index 100% rename from cdf36_3-dist/samples/geocpi2.cdf rename to cdf38_1-dist/samples/geocpi2.cdf diff --git a/cdf36_3-dist/samples/ij01r39.cdf b/cdf38_1-dist/samples/ij01r39.cdf similarity index 100% rename from cdf36_3-dist/samples/ij01r39.cdf rename to cdf38_1-dist/samples/ij01r39.cdf diff --git a/cdf36_3-dist/samples/read_example1.c b/cdf38_1-dist/samples/read_example1.c similarity index 100% rename from cdf36_3-dist/samples/read_example1.c rename to cdf38_1-dist/samples/read_example1.c diff --git a/cdf36_3-dist/samples/zfia10x.cdf b/cdf38_1-dist/samples/zfia10x.cdf similarity index 100% rename from cdf36_3-dist/samples/zfia10x.cdf rename to cdf38_1-dist/samples/zfia10x.cdf diff --git a/cdf36_3-dist/src/definitions/definitions.B b/cdf38_1-dist/src/definitions/definitions.B similarity index 97% rename from cdf36_3-dist/src/definitions/definitions.B rename to cdf38_1-dist/src/definitions/definitions.B index 737dcca..8ecf48e 100644 --- a/cdf36_3-dist/src/definitions/definitions.B +++ b/cdf38_1-dist/src/definitions/definitions.B @@ -1,7 +1,7 @@ #------------------------------------------------------------------------------ # # NSSDC/CDF Definitions for using CDF. -# Bourne shell. +# Bourne shell/bash/zsh. # # Version 1.2, 19-Mar-96, Hughes STX. # @@ -60,8 +60,7 @@ alias cdfbrowse="$CDF_BIN/cdfedit -prompt -browse" alias cdfvalidate=$CDF_BIN/cdfvalidate alias cdfleapsecondsinfo=$CDF_BIN/cdfleapsecondsinfo # The following statements are relevant only for Mac OS X -if [ "$OSTYPE" = "darwin" ] -then +if [ "$OSTYPE" = "darwin" ]; then alias cdf-to-netCDF=$CDF_BIN/cdf-to-netCDF alias netCDF-to-cdf=$CDF_BIN/netCDF-to-cdf fi diff --git a/cdf36_3-dist/src/definitions/definitions.C b/cdf38_1-dist/src/definitions/definitions.C similarity index 100% rename from cdf36_3-dist/src/definitions/definitions.C rename to cdf38_1-dist/src/definitions/definitions.C diff --git a/cdf36_3-dist/src/definitions/definitions.K b/cdf38_1-dist/src/definitions/definitions.K similarity index 98% rename from cdf36_3-dist/src/definitions/definitions.K rename to cdf38_1-dist/src/definitions/definitions.K index 419a7b8..1445a2e 100644 --- a/cdf36_3-dist/src/definitions/definitions.K +++ b/cdf38_1-dist/src/definitions/definitions.K @@ -50,8 +50,7 @@ alias cdfbrowse="$CDF_BIN/cdfedit -prompt -browse" alias cdfvalidate=$CDF_BIN/cdfvalidate alias cdfleapsecondsinfo=$CDF_BIN/cdfleapsecondsinfo # The following statements are relevant only for Mac OS X -if [ "$OSTYPE" = "darwin" ] -then +if [ "$OSTYPE" = "darwin" ]; then alias cdf-to-netCDF=$CDF_BIN/cdf-to-netCDF alias netCDF-to-cdf=$CDF_BIN/netCDF-to-cdf fi diff --git a/cdf36_3-dist/src/help/cdf2skt.olh b/cdf38_1-dist/src/help/cdf2skt.olh similarity index 77% rename from cdf36_3-dist/src/help/cdf2skt.olh rename to cdf38_1-dist/src/help/cdf2skt.olh index 2475f19..423795d 100644 --- a/cdf36_3-dist/src/help/cdf2skt.olh +++ b/cdf38_1-dist/src/help/cdf2skt.olh @@ -20,7 +20,7 @@ #------------------------------------------------------------------------------ #ifos mac win SkeletonTable is used to create a skeleton table file from a CDF. The -parameters/qualifiers dialog box displayed when SkeletonTable is `executed' +parameters/qualifiers dialog box displayed when SkeletonTable is 'executed' contains the following controls. Edit fields for... @@ -35,10 +35,10 @@ Edit fields for... the end of this field a button labeled "Select" is present. When selected, a standard output file dialog is displayed in which the skeleton table pathname may - be specified. Don't specify an extension - `.skt' is + be specified. Don't specify an extension - '.skt' is appended automatically. If this field is left blank, the skeleton table name defaults to the name of the CDF - (with `.skt' appended) and is placed in the folder + (with '.skt' appended) and is placed in the folder containing the SkeletonTable executable. The "Output to screen" check box also affects the destination of the skeleton table. @@ -54,25 +54,25 @@ Edit fields for... comma-separated list of pairs where is the number of cache buffers and is the type of file. The file 's are as follows: - `d' for the dotCDF file, `s' for the staging file, and - `c' for the compression scratch file. For example, - `200d,100s' specifies 200 cache buffers for the dotCDF + 'd' for the dotCDF file, 's' for the staging file, and + 'c' for the compression scratch file. For example, + '200d,100s' specifies 200 cache buffers for the dotCDF file and 100 cache buffers for the staging file. The dotCDF file cache size can also be specified without - the `d' for compatibility with older CDF - releases (eg. `200,100s'). Note that not all of the + the 'd' for compatibility with older CDF + releases (eg. '200,100s'). Note that not all of the file types must be specified. Those not specified will receive a default cache size. Variables: If the values for selected variables are to be displayed, this field should contain a comma-separated - list of delimited variable names. See the `Selected + list of delimited variable names. See the 'Selected variables' radio button. Check boxes for... Output to screen: Whether or not the skeleton table is displayed on the - screen in the `SkeletonTable: standard output' window. + screen in the 'SkeletonTable: standard output' window. If not checked, the skeleton table is written to a file. @@ -116,7 +116,7 @@ Radio buttons for... RV values: Place only RV variable values in the skeleton table. All values: Place all variable values in the skeleton table. Selected values: Place the values of the variables named in the - `Variables' edit field in the skeleton table. + 'Variables' edit field in the skeleton table. Buttons for... @@ -144,6 +144,7 @@ Usage: $ SKELETONTABLE [/SKELETON=] [/[NO]NEG2POSFP0] [/CACHE=()] [/[NO]FORMAT] [/[NO]SCREEN] [/[NO]LOG] [/[NO]PAGE] [/[NO]STATISTICS] [/REPORT=()] [/ZMODE=] [/ABOUT] + [/ISO8601 | /ZISO8601] [/ADVFORMAT=