/******************************************************************************
*
*  NSSDC/CDF                                    Header file for CDF library.
*
*  Version 3.6d, 7-Sep-95, Hughes STX.
*
*  Modification history:
*
*   V1.0  22-Jan-91, R Kulkarni Original version (for CDF V2.0).
*                    J Love
*
*   V2.0   3-Jun-91, J Love     Renamed (was cdf_internal.h).  Modified for
*                               CDF V2.1, namely the moving of constant macros
*                               to "cdf.h" for the INTERNAL interface and the
*                               single/multi-file option.  Renamed some symbols
*                               for clarity.
*   V2.1  24-Jun-91, J Love     Fixed for SGi port.
*   V2.2   8-Aug-91, J Love     Added 'Eof' (feof).  Added some miscellaneous
*                               macro definitions.  Renamed (was cdflib.h).
*                               Added support for Cray/UNICOS.  Added 'Exit'
*                               and 'ExitBAD'.  Added VIO_FOR_STREAM.
*                               Functions in VIO were renamed to avoid
*                               collisions on SGi/IRIX.
*   V3.0  21-Apr-92, J Love     IBM PC & HP-UX port.  CDF V2.2.
*   V3.1  21-Sep-92, J Love     CDF V2.3 (shareable/NeXT/zVar).
*   V3.2  24-Jan-94, J Love     CDF V2.4.
*   V3.2a  8-Feb-94, J Love     DEC Alpha/OpenVMS port.
*   V3.3  15-Dec-94, J Love     CDF V2.5.
*   V3.4   9-Jan-95, J Love     Encode/decode changes.  More cache-residency.
*   V3.5  19-Jan-95, J Love     IRIX 6.0 (64-bit).
*   V3.5a 15-Mar-95, J Love     Solaris 2.3 IDL i/f.  Fixed `recNum' argument
*                               of `LastAllocatedRecord'.
*   V3.6  28-Mar-95, J Love     POSIX.
*   V3.6a 18-Apr-95, J Love     More POSIX.
*   V3.6b  8-May-95, J Love     Virtual memory under Microsoft C 7.00.
*   V3.6c 13-Jun-95, J Love	Linux.
*   V3.6d  7-Sep-95, J Love	Moved `ASSIGNnotNULL' to `cdfdist.h'.
*				CDFexport-related changes.  More virtual
*				memory (Microsoft C 7.00).
*
******************************************************************************/

#if !defined(CDFLIBh_INCLUDEd__)
#define CDFLIBh_INCLUDEd__

/*****************************************************************************
* Include files.
*****************************************************************************/

#include "cdfdist.h"

/*****************************************************************************
* V1.x magic number.
*    This is what a V1 magic number looks like when the bytes are flipped. 
* The bytes will be flipped on a VAX because the longword was assumed to be
* in network order and then flipped to VAX order.  The bytes will be flipped
* on a Sun, SGi, NeXT, HP, IBM RS, etc. because the longword was assumed to
* already be in network order (the same as those machines) but the byte order
* in memory is reversed from that of a VAX (where all V1 CDFs were created).
*****************************************************************************/

#define V1_MAGIC_NUMBER_flip    0x0F000000   

/*****************************************************************************
* V2.x magic numbers.
*****************************************************************************/

#define V2_MAGIC_NUMBER         0x0000FFFF   /* Written twice at the beginning
						of V2.x CDFs. */

#define CDFid_MAGIC_NUMBER      0x12345678   /* Placed in `cdf' structure
						(CDFid).  Used to check that
						a valid CDF has been selected
						by an application. */

#define KILLid_MAGIC_NUMBER     0xF0F0F0F0   /* Placed in `cdf' structure
						(CDFid) when that CDF is
						no longer open.  The `cdf'
						structure is then freed
						but may accidently be selected
						by an application (if some
						sort of memory violation
						doesn't occur. */

/*****************************************************************************
* Virtual memory (Microsoft C 7.00).
*****************************************************************************/

#if defined(MICROSOFTC_700) && INCLUDEvMEMORY
typedef _vmhnd_t MemHandle;
#if defined(CDFLIB)
Logical useVmem = DEFAULT_USEvMEM;
long vMemSize = DEFAULT_vMEMSIZE;
unsigned int vMemMask = DEFAULT_vMEMMASK;
#else
extern Logical useVmem;
extern long vMemSize;
extern unsigned int vMemMask;
#endif
#endif

/*****************************************************************************
* Optimization.
*****************************************************************************/

#define GUESS_V1_VECTOR_SIZES           0       /* When TRUE (1), the number
						   of records in CDF V1 vector
						   (variable) files will be
						   guessed at. */

/*****************************************************************************
* Reserved values.
*****************************************************************************/

#define RESERVED_CDFID      ((CDFid) NULL)      /* Indicates that a CDF hasn't
						   been selected yet. */
#define RESERVED_CDFSTATUS  ((CDFstatus) (-1))  /* Indicates that a CDFstatus
						   hasn't been selected yet. */
#define RESERVED_ATTROFFSET (-1)                /* Indicates that an attribute
						   hasn't been selected yet. */
#define RESERVED_ENTRYNUM   (-1L)               /* Indicates that a g/r/zEntry
						   number hasn't been selected
						   yet. */
#define RESERVED_ENTRYOFFSET (-1)               /* Indicates that the current
						   g/r/zEntry does not exist.*/
#define RESERVED_VARNUM     (-1L)               /* Indicates that a variable
						   hasn't been selected yet. */

/******************************************************************************
* NETWORKbyteORDERcpu.
*   network (big-endian)..........Sun, SGi, IBM-RS, HP, NeXT, Macintosh
*   non-network (little-endian)...VAX (VMS, POSIX Shell), DECstation,
*				  IBM-PC (MS-DOS and Linux),
*				  DEC Alpha (OSF/1, OpenVMS, POSIX Shell),
******************************************************************************/

#if defined(sun)||defined(MIPSEB)||defined(IBMRS)||defined(HP)||defined(NeXT)||defined(mac)
#define NETWORKbyteORDERcpu
#endif

/******************************************************************************
* XDRishENCODINGcpu.
*   xdr...........Sun, SGi, IBM-RS, HP, NeXT, Macintosh
*   non-xdr.......VAX (VMS, POSIX Shell), DECstation, IBM-PC (MS-DOS and
*		  Linux), DEC Alpha (OSF/1, OpenVMS, POSIX Shell).
******************************************************************************/

#if defined(sun)||defined(MIPSEB)||defined(IBMRS)||defined(HP)||defined(NeXT)||defined(mac)
#define XDRishENCODINGcpu
#endif

/******************************************************************************
* Constants for `seeking'.
******************************************************************************/

#define vSEEK_SET       0
#define vSEEK_CUR       1
#define vSEEK_END       2

/*****************************************************************************
* CDF V1.1 constants.
*****************************************************************************/

#define V1_DATATYPE_STRING_LEN          8
#define V1_CDR_OFFSET                   4       /* aka, Header record */
#define V1_GDR_OFFSET                   1576
#define V1_FIRST_VDR_OFFSET             1728
#define V1_MAX_DIMS                     10
#define V1_VAR_NAME_LEN                 8
#define V1_ATTR_NAME_LEN                8

#define CDFV1_DATA_TYPE_LEN             8
#define CDFV1_ATTR_NAME_LEN             8
#define CDFV1_VAR_NAME_LEN              8
#define CDFV1_CDF_NAME_LEN              100

#define CDFV1_OK                        0
#define CDFV1_ERROR                     1
#define CDFV1_NO_SUCH_VAR               45
#define CDFV1_NO_SUCH_ATTR              30
#define CDFV1_NO_SUCH_ATTR_ENTRY        25

#define TWO_BLANKS              8224    /* "lowest" 2-character attribute or
					   variable name possible (although
					   nobody in their right mind would
					   use it) */

/*****************************************************************************
* CDF V2.0+ constants.
*****************************************************************************/

#define FIRST_IR_OFFSET                 8
#define V2_MAGIC_OFFSET                 0
#define V2_CDR_OFFSET                   8
#define NUM_VXR_ENTRIES                 10
#define VDR_WASTED_SIZE                 128
#define VARs_INCREMENT                  20

#define MIN_nEXTEND_BYTES_single        512
#define MIN_nEXTEND_RECS_single         1

#define VSTREAM_MAGIC_NUMBER    0x12345678      /* Used to verify that a VFILE
						   structure has been passed
						   to a function. */

#define DEFAULT_nCACHE_BUFFERs  1               /* Default number of buffers
						   in the cache. */
#define nCACHE_BUFFER_BYTEs     512             /* Size (bytes) of each cache
						   buffer. */

#if defined(vms)
#define VMS_DEFAULT_nALLOCATION_BLOCKS  3       /* Allocate only 3 blocks at
						   a time (override VMS default
						   of 128 for fixed record
						   length file [or 200 when
						   file FTPed to VMS]). */
#endif

#define vMAX_TRYs       5                       /* Maximum number of trys on a
						   read or write operation. */

#define MAX_EPOCH_BINARY                3.15569519999999e14
#define CTIME_STRING_LEN                25

/*****************************************************************************
* CDF versions/releases.
*****************************************************************************/

#define VERSION_1       1
#define VERSION_2       2

#define RELEASE_0       0
#define RELEASE_1       1
#define RELEASE_5       5

#define INCREMENT_1     1

/*****************************************************************************
* File types.
*****************************************************************************/

#define CDFt            1
#define Vt              3
#define Zt              4

/*****************************************************************************
* Macros for FORTRAN interface(s).
*****************************************************************************/

#if defined(vms) || defined(MPW_C)
#define Fif_DESCR
#endif

#if (defined(unix) && !defined(Mach))||defined(SALFORDC)||defined(posixSHELL)
#define Fif_GHOSTLEN
#endif

#if (defined(dos) && !defined(SALFORDC)) || defined(Mach)
#define Fif_NOLEN
#endif

#if defined(unix) && !defined(AIX) && !defined(Mach) && !defined(hpux)
#if defined(linux)
#define Fif_ENTRYPOINT(ep__,ep_,ep,EP) ep__
#else
#define Fif_ENTRYPOINT(ep__,ep_,ep,EP) ep_
#endif
#else
#if defined(SALFORDC)
#define Fif_ENTRYPOINT(ep__,ep_,ep,EP) EP
#else
#define Fif_ENTRYPOINT(ep__,ep_,ep,EP) ep
#endif
#endif

#if defined(Fif_GHOSTLEN)
#if defined(SALFORDC)
typedef int *Fif_GHOSTTYPE;
#define Fif_GHOSTFETCH(ap) *(va_arg(ap,int *))
#define Fif_GHOSTUSE(l) *l
#else
typedef int Fif_GHOSTTYPE;
#define Fif_GHOSTFETCH(ap) va_arg(ap,int)
#define Fif_GHOSTUSE(l) l
#endif
#define Fif_GHOSTARG(v) ,v
#define Fif_GHOSTDEF(v) Fif_GHOSTTYPE v;
#else
#define Fif_GHOSTARG(v) \

#define Fif_GHOSTDEF(v) \

#endif

#if defined(MPW_C)
#define Fif_PREFIXa pascal
#else
#define Fif_PREFIXa \

#endif

#if defined(MICROSOFTC)
#if defined(MICROSOFTC_600)
#define Fif_PREFIXb _cdecl
#endif
#if defined(MICROSOFTC_700)
#define Fif_PREFIXb __cdecl
#endif
#else
#define Fif_PREFIXb \

#endif

/******************************************************************************
* Integer orders.
******************************************************************************/

#define LITTLEendianORDER	1
#define BIGendianORDER		2

/******************************************************************************
* Assumed attribute scopes.
******************************************************************************/

#define GLOBALscopeASSUMED	3L
#define VARIABLEscopeASSUMED	4L

/******************************************************************************
* Floating-point types.
******************************************************************************/

#define FP_1			1
#define FP_2			2
#define FP_3			3
#define FP_4			4

/******************************************************************************
* Floating-point structures.
******************************************************************************/

#if defined(FP1cpu)
  struct fp1struct4 {
    unsigned int s : 1, e1 : 7, e0 : 1, m2 : 7, m1 : 8, m0 : 8;
  };
  struct fp2struct4 {
    unsigned int m0 : 8, m1 : 8, e0 : 1, m2 : 7, s : 1, e1 : 7;
  };
  struct fp34struct4 {
    unsigned int e0 : 1, m2 : 7, s : 1, e1 : 7, m0 : 8, m1 : 8;
  };
  struct fp1struct8 {
    unsigned int s : 1, e1 : 7, e0 : 4, m6 : 4, m5 : 8,
		 m4 : 8, m3 : 8, m2 : 8, m1 : 8, m0 : 8;
  };
  struct fp2struct8 {
    unsigned int m0 : 8, m1 : 8, m2 : 8, m3 : 8, m4 : 8,
		 m5 : 8, e0 : 4, m6 : 4, s : 1, e1 : 7;
  };
  struct fp3struct8 {
    unsigned int e0 : 1, m6 : 7, s : 1, e1 : 7, m4 : 8,
		 m5 : 8, m2 : 8, m3 : 8, m0 : 8, m1 : 8;
  };
  struct fp4struct8 {
    unsigned int e0 : 4, m6 : 4, s : 1, e1 : 7, m4 : 8,
		 m5 : 8, m2 : 8, m3 : 8, m0 : 8, m1 : 8;
  };
#endif

#if defined(FP2cpu)
  struct fp1struct4 {
    unsigned int e1 : 7, s : 1, m2 : 7, e0 : 1, m1 : 8, m0 : 8;
  };
  struct fp2struct4 {
    unsigned int m0 : 8, m1 : 8, m2 : 7, e0 : 1, e1 : 7, s : 1;
  };
  struct fp34struct4 {
    unsigned int m2 : 7, e0 : 1, e1 : 7, s : 1, m0 : 8, m1 : 8;
  };
  struct fp1struct8 {
    unsigned int e1 : 7, s : 1, m6 : 4, e0 : 4, m5 : 8,
		 m4 : 8, m3 : 8, m2 : 8, m1 : 8, m0 : 8;
  };
  struct fp2struct8 {
    unsigned int m0 : 8, m1 : 8, m2 : 8, m3 : 8, m4 : 8,
		 m5 : 8, m6 : 4, e0 : 4, e1 : 7, s : 1;
  };
  struct fp3struct8 {
    unsigned int m6 : 7, e0 : 1, e1 : 7, s : 1, m4 : 8,
		 m5 : 8, m2 : 8, m3 : 8, m0 : 8, m1 : 8;
  };
  struct fp4struct8 {
    unsigned int m6 : 4, e0 : 4, e1 : 7, s : 1, m4 : 8,
		 m5 : 8, m2 : 8, m3 : 8, m0 : 8, m1 : 8;
  };
#endif

#if defined(FP3cpu)
  struct fp1struct4 {
    unsigned int e1 : 7, s : 1, m2 : 7, e0 : 1, m1 : 8, m0 : 8;
  };
  struct fp2struct4 {
    unsigned int m0 : 8, m1 : 8, m2 : 7, e0 : 1, e1 : 7, s : 1;
  };
  struct fp34struct4 {
    unsigned int m2 : 7, e0 : 1, e1 : 7, s : 1, m0 : 8, m1 : 8;
  };
  struct fp1struct8 {
    unsigned int e1 : 7, s : 1, m6 : 4, e0 : 4, m5 : 8,
		 m4 : 8, m3 : 8, m2 : 8, m1 : 8, m0 : 8;
  };
  struct fp2struct8 {
    unsigned int m0 : 8, m1 : 8, m2 : 8, m3 : 8, m4 : 8,
		 m5 : 8, m6 : 4, e0 : 4, e1 : 7, s : 1;
  };
  struct fp3struct8 {
    unsigned int m6 : 7, e0 : 1, e1 : 7, s : 1, m4 : 8,
		 m5 : 8, m2 : 8, m3 : 8, m0 : 8, m1 : 8;
  };
  struct fp4struct8 {
    unsigned int m6 : 4, e0 : 4, e1 : 7, s : 1, m4 : 8,
		 m5 : 8, m2 : 8, m3 : 8, m0 : 8, m1 : 8;
  };
#endif

#if defined(FP4cpu)
  struct fp1struct4 {
    unsigned int e1 : 7, s : 1, m2 : 7, e0 : 1, m1 : 8, m0 : 8;
  };
  struct fp2struct4 {
    unsigned int m0 : 8, m1 : 8, m2 : 7, e0 : 1, e1 : 7, s : 1;
  };
  struct fp34struct4 {
    unsigned int m2 : 7, e0 : 1, e1 : 7, s : 1, m0 : 8, m1 : 8;
  };
  struct fp1struct8 {
    unsigned int e1 : 7, s : 1, m6 : 4, e0 : 4, m5 : 8,
		 m4 : 8, m3 : 8, m2 : 8, m1 : 8, m0 : 8;
  };
  struct fp2struct8 {
    unsigned int m0 : 8, m1 : 8, m2 : 8, m3 : 8, m4 : 8,
		 m5 : 8, m6 : 4, e0 : 4, e1 : 7, s : 1;
  };
  struct fp3struct8 {
    unsigned int m6 : 7, e0 : 1, e1 : 7, s : 1, m4 : 8,
		 m5 : 8, m2 : 8, m3 : 8, m0 : 8, m1 : 8;
  };
  struct fp4struct8 {
    unsigned int m6 : 4, e0 : 4, e1 : 7, s : 1, m4 : 8,
		 m5 : 8, m2 : 8, m3 : 8, m0 : 8, m1 : 8;
  };
#endif

/******************************************************************************
* REVERSE2b.
******************************************************************************/

#define REVERSE2b(buf) { \
Byte *_buf_ = (Byte *) (buf), _temp_; \
_temp_ = _buf_[0]; \
_buf_[0] = _buf_[1]; \
_buf_[1] = _temp_; \
}

/******************************************************************************
* REVERSE4b.
******************************************************************************/

#define REVERSE4b(buf) { \
Byte *_buf_ = (Byte *) (buf), _temp_; \
_temp_ = _buf_[0]; \
_buf_[0] = _buf_[3]; \
_buf_[3] = _temp_; \
_temp_ = _buf_[1]; \
_buf_[1] = _buf_[2]; \
_buf_[2] = _temp_; \
}

/******************************************************************************
* REVERSE8b.
******************************************************************************/

#define REVERSE8b(buf) { \
Byte *_buf_ = (Byte *) (buf), _temp_; \
_temp_ = _buf_[0]; \
_buf_[0] = _buf_[7]; \
_buf_[7] = _temp_; \
_temp_ = _buf_[1]; \
_buf_[1] = _buf_[6]; \
_buf_[6] = _temp_; \
_temp_ = _buf_[2]; \
_buf_[2] = _buf_[5]; \
_buf_[5] = _temp_; \
_temp_ = _buf_[3]; \
_buf_[3] = _buf_[4]; \
_buf_[4] = _temp_; \
}

/******************************************************************************
* REVERSE2bIO.
******************************************************************************/

#define REVERSE2bIO(iPtr,oPtr) \
((Byte *) (oPtr))[0] = ((Byte *) (iPtr))[1]; \
((Byte *) (oPtr))[1] = ((Byte *) (iPtr))[0];

/******************************************************************************
* REVERSE4bIO.
******************************************************************************/

#define REVERSE4bIO(iPtr,oPtr) \
((Byte *) (oPtr))[0] = ((Byte *) (iPtr))[3]; \
((Byte *) (oPtr))[1] = ((Byte *) (iPtr))[2]; \
((Byte *) (oPtr))[2] = ((Byte *) (iPtr))[1]; \
((Byte *) (oPtr))[3] = ((Byte *) (iPtr))[0];

/******************************************************************************
* REVERSE8bIO.
******************************************************************************/

#define REVERSE8bIO(iPtr,oPtr) \
((Byte *) (oPtr))[0] = ((Byte *) (iPtr))[7]; \
((Byte *) (oPtr))[1] = ((Byte *) (iPtr))[6]; \
((Byte *) (oPtr))[2] = ((Byte *) (iPtr))[5]; \
((Byte *) (oPtr))[3] = ((Byte *) (iPtr))[4]; \
((Byte *) (oPtr))[4] = ((Byte *) (iPtr))[3]; \
((Byte *) (oPtr))[5] = ((Byte *) (iPtr))[2]; \
((Byte *) (oPtr))[6] = ((Byte *) (iPtr))[1]; \
((Byte *) (oPtr))[7] = ((Byte *) (iPtr))[0];

/******************************************************************************
* GLOBALscope/VARIABLEscope/DEFINITEscope.
******************************************************************************/

#define GLOBALscope(scope) \
(scope == GLOBAL_SCOPE || scope == GLOBALscopeASSUMED)

#define VARIABLEscope(scope) \
(scope == VARIABLE_SCOPE || scope == VARIABLEscopeASSUMED)

#define DEFINITEscope(scope) \
(BOO(scope == GLOBALscopeASSUMED, \
     GLOBAL_SCOPE,BOO(scope == VARIABLEscopeASSUMED,VARIABLE_SCOPE,scope)))

/******************************************************************************
* FLOAT8dataType.
*    Macro to check for a double-precision floating-point data type.
******************************************************************************/

#define FLOAT8dataType(dataType) \
(dataType == CDF_REAL8 || dataType == CDF_DOUBLE || dataType == CDF_EPOCH)

/******************************************************************************
* Operating system dependent definitions.
******************************************************************************/

#if defined(vms) || defined(dos) || defined(mac)
#define READ_ONLY_a_mode        "rb"
#define READ_PLUS_a_mode        "r+b"
#define WRITE_PLUS_a_mode       "w+b"
#endif

#if defined(unix) || defined(posixSHELL)
#define READ_ONLY_a_mode        "r"
#define READ_PLUS_a_mode        "r+"
#define WRITE_PLUS_a_mode       "w+"
#endif

/******************************************************************************
* Miscellaneous macros.
******************************************************************************/

#define SEEKv(fp,offset,origin) (V_seek(fp,offset,origin) == 0)
#define READv(buffer,size,number,fp) (V_read(buffer,size,number,fp) == number)
#define WRITEv(buffer,size,number,fp) (V_write(buffer,size,number,fp)==number)
#define CACHEv(fp,nBuffers) (V_setcache(fp,nBuffers) == 0)
#define CLOSEv(fp,vStats) (V_close(fp,vStats) == 0)

#define MEMMOVE(dst,src,nBytes) if (dst != src) memmove (dst, src, nBytes);

#define DECODE(function,buffer,numElems) \
BOO(function == NULL,CDF_OK,function(buffer,numElems))

/******************************************************************************
* CURRENTattrSELECTED.
******************************************************************************/

#define CURRENTattrSELECTED(CDF) (CDF->CURattrOffset != RESERVED_ATTROFFSET)

/******************************************************************************
* CURRENTvarSELECTED.
******************************************************************************/

#define CURRENTvarSELECTED(CDF,zOp) \
BOO(zModeON(CDF), \
    CDF->CURzVarNum != RESERVED_VARNUM, \
    BOO(zOp,CDF->CURzVarNum,CDF->CURrVarNum) != RESERVED_VARNUM)

/******************************************************************************
* BADzOP.
*    Check if an operation is legal while in zMode.
******************************************************************************/

#define BADzOP(CDF,rVar) (zModeON(CDF) && rVar)

/******************************************************************************
* vFILE/vCACHE structures.
******************************************************************************/

typedef struct vCACHEstruct {
  uInt32 blockN;        /* File block number in this cache buffer. */
  struct vCACHEstruct *next;
			/* Index of next cache buffer (on linked list). */
  struct vCACHEstruct *prev;
			/* Index of previous cache buffer (on linked list). */
  Logical modified;     /* TRUE if this file block has been modified. */
  void *ptr;		/* Pointer to cache buffer or virtual memory handle
			   (if Microsoft C 7.00). */
} vCACHE;

typedef struct vFILEstruct {
  long magic_number;    /* Magic number for VFILE structure. */
  FILE *fp;             /* File pointer. */
  int error;            /* TRUE if an error has occurred - no further access
			   to the file is allowed. */
  vCACHE *cacheHead;    /* Head of linked list of cache structures. */
  vCACHE *cacheTail;    /* Tail of linked list of cache structures. */
  vSTATS vStats;        /* Statistics for this file. */
  long eof;             /* End-of-file byte (includes what is in the cache
			   but not necessarily what is physically in the
			   file yet). */
  long phyEof;          /* Physical EOF (byte offset) of the file. */
  long offset;          /* Read/write position (byte offset) in file. */
} vFILE;

/******************************************************************************
* Internal CDF/variable status codes.
******************************************************************************/

#define CDF_CLOSED              501
#define CDF_READ_ONLY           502
#define CDF_READ_WRITE          503
#define VAR_CLOSED              504
#define VAR_OPENED              505
#define NO_VAR_FILE             506

/******************************************************************************
* CDR flag bit positions (bit 0 is Least Significant Bit).
******************************************************************************/

#define CDR_MAJORITY_BIT        0       /* majority: set = row major,
						     clear = column major */
#define CDR_FORMAT_BIT          1       /* format: set = single file,
						   clear = multi file */

/******************************************************************************
* VDR flag bit positions (bit 0 is Least Significant Bit).  These apply to
* both rVDRs and zVDRs.
******************************************************************************/

#define VDR_RECVARY_BIT        0       /* Record variance:
					     set = VARY,
					     clear = NOVARY. */
#define VDR_PADVALUE_BIT       1       /* Pad value:
					     set = specified,
					     clear = not specified. */

/******************************************************************************
* Internal record types.
******************************************************************************/

#define UIR_      (Int32) (-1)  /* Unused Internal Record. */
#define CDR_      (Int32) 1     /* CDF Descriptor Record. */
#define GDR_      (Int32) 2     /* Global Descriptor Record. */
#define rVDR_     (Int32) 3     /* rVariable Descriptor Record. */
#define ADR_      (Int32) 4     /* Attribute Descriptor Record. */
#define AgrEDR_   (Int32) 5     /* Attribute g/rEntry Descriptor Record. */
#define VXR_      (Int32) 6     /* Variable indeX Record. */
#define VVR_      (Int32) 7     /* Variable Values Record. */
#define zVDR_     (Int32) 8     /* zVariable Descriptor Record. */
#define AzEDR_    (Int32) 9     /* Attribute zEntry Descriptor Record. */

/******************************************************************************
* Base record sizes (bytes).
******************************************************************************/

#define UIR_BASE_SIZE           16
#define CDR_BASE_SIZE           48
#define GDR_BASE_SIZE           60
#define zVDR_BASE_SIZE          (68 + CDF_VAR_NAME_LEN)
#define rVDR_BASE_SIZE          (64 + CDF_VAR_NAME_LEN)
#define VXR_BASE_SIZE           (20 + (12 * NUM_VXR_ENTRIES))
#define VVR_BASE_SIZE           8
#define ADR_BASE_SIZE           (52 + CDF_ATTR_NAME_LEN)
#define AEDR_BASE_SIZE          48

/******************************************************************************
* CDR structure/fields/offsets.
******************************************************************************/

struct CDRstruct {
  Int32 RecordSize;     /* Size of record (bytes) */
  Int32 RecordType;     /* Type of record (ie. CDR) */
  Int32 GDRoffset;      /* File offset to GDR (bytes) */
  Int32 Version;        /* CDF Version Number */
  Int32 Release;        /* CDF Release Number */
  Int32 Encoding;       /* Encoding of CDF File */
  Int32 Flags;          /* Flags (see bit definitions). */
  Int32 rfuA;           /* reserved for future use (value = 0) */
  Int32 rfuB;           /* reserved for future use (value = 0) */
  Int32 Increment;      /* CDF Increment Number (Vversion.release.increment),
			   always 0 for V2.0 CDFs */
  Int32 rfuD;           /* reserved for future use (value = -1) */
  Int32 rfuE;           /* reserved for future use (value = -1) */
};

#define CDR_NULL                (-1)
#define CDR_RECORD              0
#define CDR_RECORDSIZE          1
#define CDR_RECORDTYPE          2
#define CDR_GDROFFSET           3
#define CDR_VERSION             4
#define CDR_RELEASE             5
#define CDR_ENCODING            6
#define CDR_FLAGS               7
#define CDR_INCREMENT           8
#define CDR_COPYRIGHT           9

#define CDR_RECORDSIZE_OFFSET   0
#define CDR_RECORDTYPE_OFFSET   4
#define CDR_GDROFFSET_OFFSET    8
#define CDR_VERSION_OFFSET      12
#define CDR_RELEASE_OFFSET      16
#define CDR_ENCODING_OFFSET     20
#define CDR_FLAGS_OFFSET        24
#define CDR_RFUa_OFFSET         28
#define CDR_RFUb_OFFSET         32
#define CDR_INCREMENT_OFFSET    36
#define CDR_RFUd_OFFSET         40
#define CDR_RFUe_OFFSET         44
#define CDR_COPYRIGHT_OFFSET    48

/******************************************************************************
* GDR structure/fields/offsets.
*
* Note(s):
*   The Eof field was not maintained for V2.0 CDFs (it will contain a random
* value).  When a V2.0 CDF is modified, the end-of-file will be determined and
* this field will be updated.
*   Even though CDF_MAX_DIMS elements are allocated for the `rDimSizes'
* array, only those sizes which actually exist are written to the CDF file.
*
******************************************************************************/

struct GDRstruct {
  Int32 RecordSize;     /* Size of current record (bytes) */
  Int32 RecordType;     /* Type of record (ie. GDR) */
  Int32 rVDRhead;       /* File offset to first rVDR (bytes) */
  Int32 zVDRhead;       /* CDF V2.0, value is undefined (random).
			   CDF V2.1, value = 0.
			   CDF V2.2, File offset to first zVDR (bytes). */
  Int32 ADRhead;        /* File offset to first ADR (bytes) */
  Int32 eof;            /* If V2.0 CDF, value is undefined.
			   If V2.1+ CDF, end-of-file (byte offset). */
  Int32 NrVars;         /* Number of rVariables */
  Int32 NumAttr;        /* Number of Attributes */
  Int32 rMaxRec;        /* Maximum rVariable record number written to. */
  Int32 rNumDims;       /* Number of CDF dimensions (for rVariables). */
  Int32 NzVars;         /* Number of zVariables. */
  Int32 UIRhead;        /* File offset to first UIR (bytes). */
  Int32 rfuC;           /* reserved for future use (value = 0) */
  Int32 rfuD;           /* reserved for future use (value = -1) */
  Int32 rfuE;           /* reserved for future use (value = -1) */
  Int32 rDimSizes[CDF_MAX_DIMS];
			/* Size of each dimension (for rVariables). */
};

#define GDR_NULL                (-1)
#define GDR_RECORD              0
#define GDR_RECORDSIZE          1
#define GDR_RECORDTYPE          2
#define GDR_rVDRHEAD            3
#define GDR_zVDRHEAD            4
#define GDR_ADRHEAD             5
#define GDR_EOF                 6
#define GDR_NrVARS              7
#define GDR_NUMATTR             8
#define GDR_rMAXREC             9
#define GDR_rNUMDIMS            10
#define GDR_NzVARS              11
#define GDR_UIRHEAD             12
#define GDR_rDIMSIZES           13

#define GDR_RECORDSIZE_OFFSET   0
#define GDR_RECORDTYPE_OFFSET   4
#define GDR_rVDRHEAD_OFFSET     8
#define GDR_zVDRHEAD_OFFSET     12
#define GDR_ADRHEAD_OFFSET      16
#define GDR_EOF_OFFSET          20
#define GDR_NrVARS_OFFSET       24
#define GDR_NUMATTR_OFFSET      28
#define GDR_rMAXREC_OFFSET      32
#define GDR_rNUMDIMS_OFFSET     36
#define GDR_NzVARS_OFFSET       40
#define GDR_UIRHEAD_OFFSET      44
#define GDR_RFUc_OFFSET         48
#define GDR_RFUd_OFFSET         52
#define GDR_RFUe_OFFSET         56
#define GDR_rDIMSIZES_OFFSET    60

/******************************************************************************
* rVDR/zVDR structure/fields/offsets.
******************************************************************************/

struct VDRstruct {
  Int32 RecordSize;     /* Size of current record (bytes) */
  Int32 RecordType;     /* Type of record (eg. rVDR/zVDR) */
  Int32 VDRnext;        /* File offset to next rVDR/zVDR (bytes).  Note in
			   V2.0 CDFs this field was not set properly for the
			   last variable (rVariable). */
  Int32 DataType;       /* Data type of variable */
  Int32 MaxRec;         /* Maximum record number for variable */
  Int32 VXRhead;        /* File offset to first VXR (bytes).  Value will be
			   0 if MULTI_FILE format */
  Int32 VXRtail;        /* File offset to last VXR (bytes).  Value will be 0
			   if MULTI_FILE format */
  Int32 Flags;          /* Flags (see bit definitions). */
  Int32 rfuA;           /* reserved for future use (value = 0) */
  Int32 rfuB;           /* reserved for future use (value = 0) */
  Int32 rfuC;           /* reserved for future use (value = -1) */
  Int32 rfuF;           /* reserved for future use (value = -1) */
  Int32 NumElems;       /* Number of elements of DataType (should be 1 if not
			   CDF_CHAR or CDF_UCHAR) */
  Int32 Num;            /* Variable number */
  Int32 rfuD;           /* reserved for future use (value = -1) */
  Int32 NextendRecs;    /* Number of records to extend when new allocations
			   are necessary (if 0, use default).  For multi-file
			   CDFs, extensions are always one record at a time.
			   For NRV variables this value is n/a (only one record
			   is ever written). */
  char  Name[CDF_VAR_NAME_LEN+1];
			/* Variable name */
  Int32 zNumDims;       /* Number of dimensions for zVariable.  N/a if an
			   rVariable. */
  Int32 zDimSizes[CDF_MAX_DIMS];
			/* Dimension sizes for zVariable.  N/a if an
			   rVariable. */
  Int32 DimVarys[CDF_MAX_DIMS];
			/* Dimension variances. */
};

#define VDR_NULL                (-1)
#define VDR_RECORD              0
#define VDR_RECORDSIZE          1
#define VDR_RECORDTYPE          2
#define VDR_VDRNEXT             3
#define VDR_DATATYPE            4
#define VDR_MAXREC              5
#define VDR_VXRHEAD             6
#define VDR_VXRTAIL             7
#define VDR_FLAGS               8
#define VDR_NUMELEMS            9
#define VDR_NUM                 10
#define VDR_NEXTENDRECS         11
#define VDR_NAME                12
#define zVDR_zNUMDIMS           13
#define zVDR_zDIMSIZES          14
#define VDR_DIMVARYS            15
#define VDR_PADVALUE            16

#define VDR_RECORDSIZE_OFFSET   0
#define VDR_RECORDTYPE_OFFSET   4
#define VDR_VDRNEXT_OFFSET      8
#define VDR_DATATYPE_OFFSET     12
#define VDR_MAXREC_OFFSET       16
#define VDR_VXRHEAD_OFFSET      20
#define VDR_VXRTAIL_OFFSET      24
#define VDR_FLAGS_OFFSET        28
#define VDR_RFUa_OFFSET         32
#define VDR_RFUb_OFFSET         36
#define VDR_RFUc_OFFSET         40
#define VDR_RFUf_OFFSET         44
#define VDR_NUMELEMS_OFFSET     48
#define VDR_NUM_OFFSET          52
#define VDR_RFUd_OFFSET         56
#define VDR_NEXTENDRECS_OFFSET  60
#define VDR_NAME_OFFSET         64

#define rVDR_DIMVARYS_OFFSET    128
#define rVDR_PADVALUE_OFFSETb   128     /* Offset base (more will be added). */

#define zVDR_zNUMDIMS_OFFSET    128
#define zVDR_zDIMSIZES_OFFSET   132
#define zVDR_DIMVARYS_OFFSETb   132     /* Offset base (more will be added). */
#define zVDR_PADVALUE_OFFSETb   132     /* Offset base (more will be added). */

#define VDR_WASTED_OFFSET       48

/******************************************************************************
* VXR structure/fields/offsets.
******************************************************************************/

struct VXRstruct {
  Int32 RecordSize;     /* Size of current record (bytes) */
  Int32 RecordType;     /* Type of record (ie. VXR) */
  Int32 VXRnext;        /* File offset to next VXR (bytes) */
  Int32 Nentries;       /* Number of index entries (entries not being used
			   contain -1 in each field) */
  Int32 NusedEntries;   /* Number of index entries actually used */
  Int32 FirstRec[NUM_VXR_ENTRIES];
			/* First record number in VVR */
  Int32 LastRec[NUM_VXR_ENTRIES];
			/* Last record number in VVR */
  Int32 VVRoffset[NUM_VXR_ENTRIES];
			/* File offset to VVR (bytes) */
};

#define VXR_NULL                (-1)
#define VXR_RECORD              0
#define VXR_RECORDSIZE          1
#define VXR_RECORDTYPE          2
#define VXR_VXRNEXT             3
#define VXR_NENTRIES            4
#define VXR_NUSEDENTRIES        5
#define VXR_FIRSTREC            6
#define VXR_LASTREC             7
#define VXR_VVROFFSET           8

#define VXR_RECORDSIZE_OFFSET   0
#define VXR_RECORDTYPE_OFFSET   4
#define VXR_VXRNEXT_OFFSET      8
#define VXR_NENTRIES_OFFSET     12
#define VXR_NUSEDENTRIES_OFFSET 16
#define VXR_FIRSTREC_OFFSET     20
#define VXR_LASTREC_OFFSET      60
#define VXR_VVROFFSET_OFFSET    100

/******************************************************************************
* VVR structure/fields/offsets.
******************************************************************************/

struct VVRstruct {
  Int32 RecordSize;     /* Size of current record (bytes). */
  Int32 RecordType;     /* Type of record (ie. VVR). */
  void *buffer;         /* Record(s). */
};

#define VVR_NULL                (-1)
#define VVR_RECORD              0
#define VVR_RECORDSIZE          1
#define VVR_RECORDTYPE          2
#define VVR_BUFFER              3

#define VVR_RECORDSIZE_OFFSET   0
#define VVR_RECORDTYPE_OFFSET   4
#define VVR_BUFFER_OFFSET       8

/******************************************************************************
* ADR structure/fields/offsets.
******************************************************************************/

struct ADRstruct {
  Int32 RecordSize;     /* Size of current record (bytes). */
  Int32 RecordType;     /* Type of record (ie. ADR). */
  Int32 ADRnext;        /* File offset to next ADR (bytes).  Note that in
			   V2.0 CDFs this field was not set properly for the
			   last attribute. */
  Int32 AgrEDRhead;     /* File offset to first AgrEDR (bytes). */
  Int32 Scope;          /* Variable or global. */
  Int32 Num;            /* Attribute id number. */
  Int32 NgrEntries;     /* Number of attribute gEntries/rEntries. */
  Int32 MAXgrEntry;     /* Maximum attribute gEntry/rEntry number. */
  Int32 rfuA;           /* reserved for future use (value = 0). */
  Int32 AzEDRhead;      /* File offset to first AzEDR (bytes). */
  Int32 NzEntries;      /* Number of attribute zEntries. */
  Int32 MAXzEntry;      /* Maximum attribute zEntry number. */
  Int32 rfuE;           /* Reserved for future use (value = -1). */
  char  Name[CDF_ATTR_NAME_LEN+1];
			/* Attribute name. */
};

#define ADR_NULL                (-1)
#define ADR_RECORD              0
#define ADR_RECORDSIZE          1
#define ADR_RECORDTYPE          2
#define ADR_ADRNEXT             3
#define ADR_AgrEDRHEAD          4
#define ADR_SCOPE               5
#define ADR_NUM                 6
#define ADR_NgrENTRIES          7
#define ADR_MAXgrENTRY          8
#define ADR_AzEDRHEAD           9
#define ADR_NzENTRIES           10
#define ADR_MAXzENTRY           11
#define ADR_NAME                12

#define ADR_RECORDSIZE_OFFSET   0
#define ADR_RECORDTYPE_OFFSET   4
#define ADR_ADRNEXT_OFFSET      8
#define ADR_AgrEDRHEAD_OFFSET   12
#define ADR_SCOPE_OFFSET        16
#define ADR_NUM_OFFSET          20
#define ADR_NgrENTRIES_OFFSET   24
#define ADR_MAXgrENTRY_OFFSET   28
#define ADR_RFUa_OFFSET         32
#define ADR_AzEDRHEAD_OFFSET    36
#define ADR_NzENTRIES_OFFSET    40
#define ADR_MAXzENTRY_OFFSET    44
#define ADR_RFUe_OFFSET         48
#define ADR_NAME_OFFSET         52

/******************************************************************************
* ArEDR/AzEDR structure/fields/offsets.
******************************************************************************/

struct AEDRstruct {
  Int32 RecordSize;     /* Size of current record (bytes) */
  Int32 RecordType;     /* Type of record (ie. ArEDR/AzEDR) */
  Int32 AEDRnext;       /* File offset to next ArEDR/AzEDR.  Note that in
			   V2.0 CDFs this field was not set properly for the
			   last entry (rEntry). */
  Int32 AttrNum;        /* Attribute Number */
  Int32 DataType;       /* Entry Data Type */
  Int32 Num;            /* Entry number (rVariable/zVariable number or
			   arbitrary global `entry' [gEntry] number) */
  Int32 NumElems;       /* Number of elements of DataType */
  Int32 rfuA;           /* reserved for future use (value = 0) */
  Int32 rfuB;           /* reserved for future use (value = 0) */
  Int32 rfuC;           /* reserved for future use (value = 0) */
  Int32 rfuD;           /* reserved for future use (value = -1) */
  Int32 rfuE;           /* reserved for future use (value = -1) */
};

#define AEDR_NULL               (-1)
#define AEDR_RECORD             0
#define AEDR_RECORDSIZE         1
#define AEDR_RECORDTYPE         2
#define AEDR_AEDRNEXT           3
#define AEDR_ATTRNUM            4
#define AEDR_DATATYPE           5
#define AEDR_NUM                6
#define AEDR_NUMELEMS           7
#define AEDR_VALUE              8

#define AEDR_RECORDSIZE_OFFSET  0
#define AEDR_RECORDTYPE_OFFSET  4
#define AEDR_AEDRNEXT_OFFSET    8
#define AEDR_ATTRNUM_OFFSET     12
#define AEDR_DATATYPE_OFFSET    16
#define AEDR_NUM_OFFSET         20
#define AEDR_NUMELEMS_OFFSET    24
#define AEDR_RFUa_OFFSET        28
#define AEDR_RFUb_OFFSET        32
#define AEDR_RFUc_OFFSET        36
#define AEDR_RFUd_OFFSET        40
#define AEDR_RFUe_OFFSET        44
#define AEDR_VALUE_OFFSET       48

/******************************************************************************
* UIR structure/fields/offsets.
******************************************************************************/

struct UIRstruct {
  Int32 RecordSize;     /* Size of current record (bytes). */
  Int32 RecordType;     /* Type of record (ie. UIR). */
  Int32 NextUIR;        /* File offset of next UIR (bytes). */
  Int32 PrevUIR;        /* File offset of previous UIR (bytes). */
};

#define UIR_NULL                (-1)
#define UIR_RECORD              0
#define UIR_RECORDSIZE          1
#define UIR_RECORDTYPE          2
#define UIR_NEXTUIR             3
#define UIR_PREVUIR             4

#define UIR_RECORDSIZE_OFFSET   0
#define UIR_RECORDTYPE_OFFSET   4
#define UIR_NEXTUIR_OFFSET      8
#define UIR_PREVUIR_OFFSET      12

/******************************************************************************
* Structure for variable record/dimension states for read/write operations.
******************************************************************************/

struct rdSTRUCT {
  long recNumber;                       /* Current record number. */
  long recCount;                        /* Current record count. */
  long recInterval;                     /* Current record interval. */
  long dimIndices[CDF_MAX_DIMS];        /* Current dimension indices. */
  long dimCounts[CDF_MAX_DIMS];         /* Current dimension counts. */
  long dimIntervals[CDF_MAX_DIMS];      /* Current dimension intervals. */
};

/******************************************************************************
* Structures for rVariable/zVariable related data.
******************************************************************************/

struct sFileSTRUCT {
  Int32 maxAllocated;           /* Maximum record number allocated. */
  Int32 maxWritten;             /* Maximum record number written/padded. */
  Int32 firstRecInVVR;          /* First record in most recently accessed
				   VVR. */
  Int32 lastRecInVVR;           /* Last record in most recently accessed
				   VVR. */
  Int32 offsetOfVVR;            /* Offset of most recently accessed VVR. */
  long nExtendRecs;             /* Number of records by which to extend a
				   variable when necessary. */
};

struct varSTRUCT {
  Int32 VDRoffset;              /* Byte offset of rVDR/zVDR. */
  Logical zVar;                 /* TRUE if a zVariable, FALSE if an
				   rVariable.  Independent of zMode. */
  long varN;                    /* The variable's number. */
  vFILE *fp;                    /* For a MULTI file CDF, this is set when
				   the variable file is first opened.
				   For a SINGLE file CDF, this is set to the
				   'fp' of the CDF (the .CDF file contains
				   the variable data). */
  int status;                   /* VAR_OPENED, VAR_CLOSED, or NO_VAR_FILE. */
  int nCacheBuffers;            /* Number of cache buffers to request when
				   the variable file is opened.  N/a if a
				   single-file CDF. */
  long accessed_at;             /* Pseudo-clock time of last access. */
  CDFstatus (*DecodeFunction) PROTOARGs((void *buffer, long numElems));
				/* Function which converts values read from
				   the CDF to the desired decoding. */
  CDFstatus (*EncodeFunction) PROTOARGs((void *buffer, long numElems));
				/* Function which converts values being written
				   to the CDF to the desired encoding. */
  /****************************************************************************
  * The following value(s) are maintained in memory for efficiency.  They must
  * be written to the CDF when it is closed.  These are the values to use when
  * necessary (rather than the values in the CDF).
  ****************************************************************************/
  Int32 maxRec;                 /* Maximum record number. */
  /****************************************************************************
  * The following values are calculated based on the current zMode.  For
  * rVariables they may differ from the values in the VDR.  For zVariables
  * they will be the same as the values in the VDR but are maintained here
  * for consistency.
  ****************************************************************************/
  long numDims;                 /* Number of dimensions, based on zMode. */
  long dimSizes[CDF_MAX_DIMS];  /* Dimension sizes, based on zMode. */
  long recVary;                 /* Record variance, based on zMode (doesn't
				   differ but done for consistency). */
  long dimVarys[CDF_MAX_DIMS];  /* Dimension variances, based on zMode. */
  /****************************************************************************
  * The following values are maintained in memory for efficiency.
  ****************************************************************************/
  long NvalueElems;             /* Number of elements per value. */
  long NelemBytes;              /* Number of bytes per element. */
  long NvalueBytes;             /* Number of bytes per value. */
  long NphyRecValues;           /* Number of physical values per record. */
  long NvirtRecValues;          /* Number of virtual values per record. */
  long NphyRecElems;            /* Number of physical elements per record. */
  long NvirtRecElems;           /* Number of virtual elements per record. */
  long NphyRecBytes;            /* Number of physical bytes per record. */
  long NvirtRecBytes;           /* Number of virtual bytes per record. */
  long nPhyDimValues[CDF_MAX_DIMS];
				/* Number of physical values `below' each
				   occurance of a dimension. */
  struct sFileSTRUCT sFile;     /* Single-file specific values. */
  /****************************************************************************
  * The following values maintain the current positioning.
  ****************************************************************************/
  long seqValueOffset;          /* Used for sequential access.  The current
				   value offset (not the byte offset). */
  struct rdSTRUCT zRD;          /* Current record/dimension states.  These are
				   always used for zVariables.  For rVariables,
				   these are only used while in zMode.  When
				   not in zMode, the current record/dimension
				   states in the `CDF' structure are used (and
				   are the same for all rVariables). */
};

/******************************************************************************
* Structures for CDF related data.
******************************************************************************/

struct cdfSTRUCT {
  long struct_magic_number;             /* Magic number stored in CDF structure
					   in memory. */
  Int32 file_magic_number;              /* Magic number written to `.cdf'
					   file. */
  Int32 CDRoffset;                      /* Byte offset of CDR.  N/a if a
					   Version 1 CDF. */
  Int32 GDRoffset;                      /* Byte offset of GDR.  N/a if a
					   Version 1 CDF. */
  char pathname[CDF_PATHNAME_LEN+1];    /* Full/expanded pathname of CDF. */
  Logical no_append;                    /* TRUE if pathnames should not have
					   extensions or version numbers
					   appended. */
  Logical upper_case_ext;               /* TRUE if uppercase file extensions.*/
  Logical version_numbers;              /* TRUE if a ";1" is appended to all
					   pathnames. */
  Logical fakeEPOCH;                    /* TRUE if a CDF prior to CDF V2.1.1
					   for which the data type CDF_EPOCH
					   should be substituted for the actual
					   data type in some cases involving
					   the rVariable "EPOCH". */
  Logical wastedSpace;                  /* TRUE if a CDF prior to CDF V2.5 in
					   which there is 128 bytes of wasted
					   space in each VDR and 1689 bytes of
					   wasted space in the CDR. */
  Logical badEOF;                       /* TRUE if a CDF prior to CDF V2.1 in
					   which case the EOF of the GDR was
					   not used (ie. contains garbage). */
  Logical badTerminatingOffsets;        /* TRUE if a CDF prior to CDF V2.1 in
					   which the terminating offsets of the
					   ADR and rVDR linked lists are bad.*/
  Logical assumedScopes;                /* TRUE if a CDF prior to CDF V2.5 in
					   which there are assumed attribute
					   scopes. */
  char cdfname[CDF_PATHNAME_LEN+1];     /* CDF name as specified by caller. */
  vFILE *fp;
  long decoding;                        /* Decoding (encoding) for attribute
					   entry and variable values read from
					   a CDF. */
  long readonlyMode;                    /* READONLYon: read-only access,
					   READONLYoff: read-write access. */
  long zMode;                           /* zMODEoff: no zMode,
					   zMODEon1: keep NOVARY variances
						     (rVariables --> zGroup),
					   zMODEon2: remove dimensions with
						     NOVARY variance. */
  long negToPosFp0mode;                 /* Convert -0.0 to 0.0? 
						NEGtoPOSfp0on means yes,
						NEGtoPOSfp0off means no. */
  int status;                           /* CDF_CLOSED, CDF_READ_ONLY, or
					   CDF_READ_WRITE */
  int nCacheBuffers;                    /* Number of cache buffers. */
  Logical explicitCache;                /* TRUE if an explicit cache size has
					   been requested for the `.cdf' file
					   of the CDF. */
  unsigned long pseudo_clock;           /* Tick count used to determine which
					   variable was least recently used. */
  Logical singleFile;                   /* TRUE if a single-file CDF. */
  Logical rowMajor;                     /* TRUE if a row major CDF. */
  Int32 encoding;                       /* Encoding of CDF. */
  Int32 rMaxRec;                        /* Maximum record number of all the
					   rVariables. */
  Int32 rNumDims;                       /* Number of dimensions for
					   rVariables. */
  Int32 rDimSizes[CDF_MAX_DIMS];        /* Dimension sizes for rVariables. */
  Int32 NrVars;                         /* Number of rVariables. */
  Int32 NzVars;                         /* Number of zVariables. */
  int MAXrVars;                         /* Current size of `rVars' array. */
  int MAXzVars;                         /* Current size of `zVars' array. */
  struct varSTRUCT **rVars;             /* Pointer to array of pointers to
					   rVariable data structures. */
  struct varSTRUCT **zVars;             /* Pointer to array of pointers to
					   zVariable data structures. */
  long CURrVarNum;                      /* Current rVariable number (when not
					   in zMode). */
  long CURzVarNum;                      /* Current zVariable number (used when
					   zMode is on or off). */
  Int32 CURattrOffset;                  /* Offset of current attribute's ADR.
					   Set to RESERVED_ATTROFFSET if an
					   attribute is not selected. */
  long CURgrEntryNum;                   /* Currently selected gEntry/rEntry
					   number (a corresponding gEntry/
					   rEntry in the current attribute
					   does not have to exist yet).  When
					   in zMode, this is used only for
					   the gEntry number.  Set to
					   RESERVED_ENTRYNUM when a
					   gEntry/rEntry is not selected. */
  long CURzEntryNum;                    /* Currently selected zEntry number (a
					   corresponding zEntry in the current
					   attribute does not have to exist
					   yet).  This is used when zMode is
					   on or off.  When zMode is on, could
					   actually point to an AgrEDR.  Set to
					   RESERVED_ENTRYNUM when a zEntry is
					   not selected. */
  Int32 CURgrEntryOffset;               /* Offset of current AgrEDR.  Not set
					   to RESERVED_ENTRYOFFSET when an
					   attribute and gEntry/rEntry have
					   been selected and the entry actually
					   exists. */
  Int32 CURzEntryOffset;                /* Offset of current AzEDR.  Not set
					   to RESERVED_ENTRYOFFSET when an
					   attribute and zEntry have been
					   selected and the entry actually
					   exists.  If zMode is on, could point
					   to an AgrEDR. */
  struct rdSTRUCT rRD;                  /* Current record/dimension states for
					   the rVariables (they are the same
					   for all rVariables). */
};

/******************************************************************************
* Structure for `string' related data (used by FORTRAN interfaces).
******************************************************************************/

struct STRINGstruct {
  char *string;
  struct STRINGstruct *next;
};

/******************************************************************************
* Structure for `varargs' related data.
******************************************************************************/

struct VAstruct {
  va_list ap;
  long fnc;
  long item;
};

/******************************************************************************
* Structure for `current' data.
******************************************************************************/

struct CURstruct {
  struct cdfSTRUCT *cdf;
  CDFstatus status;
};

/******************************************************************************
* SelectCDF.
******************************************************************************/

#define SelectCDF(cdf_,ptr_,error_) \
if (cdf_ == NULL) \
  return error_; \
else \
  ptr_ = cdf_;

/******************************************************************************
* SINGLEfileBITset.
******************************************************************************/

#define SINGLEfileBITset(flags) (BITSET(flags,CDR_FORMAT_BIT))

/******************************************************************************
* ROWmajorBITset.
******************************************************************************/

#define ROWmajorBITset(flags) (BITSET(flags,CDR_MAJORITY_BIT))

/******************************************************************************
* zModeON/zModeOFF.
******************************************************************************/

#define zModeON(CDF) (CDF->zMode == zMODEon1 || CDF->zMode == zMODEon2)
#define zModeOFF(CDF) (CDF->zMode == zMODEoff)

/******************************************************************************
* PADvalueBITset.
******************************************************************************/

#define PADvalueBITset(flags) (BITSET(flags,VDR_PADVALUE_BIT))

/******************************************************************************
* RECvaryBITset.
******************************************************************************/

#define RECvaryBITset(flags) (BITSET(flags,VDR_RECVARY_BIT))

/******************************************************************************
* Function prototypes.
******************************************************************************/

STATICforIDL struct varSTRUCT *VarStructPtr PROTOARGs((
  struct cdfSTRUCT *CDF, Logical zOp, long varN
));
STATICforIDL void DefaultPadValue PROTOARGs((long, long, void *));
STATICforIDL CDFstatus DefaultPadBuffer PROTOARGs((
  struct cdfSTRUCT *CDF, struct varSTRUCT *Var, long nValues, void *buffer
));
STATICforIDL CDFstatus PadBuffer PROTOARGs((
  struct cdfSTRUCT *CDF, struct varSTRUCT *Var, long nValues, void *buffer
));
STATICforIDL CDFstatus WasteInternalRecord PROTOARGs((
  struct cdfSTRUCT *CDF, Int32 offset, Int32 size
));
STATICforIDL long IndicesValueOffset PROTOARGs((
  long numDims, long *indices, long *dimVarys, long *nPhyDimValues
));
STATICforIDL void ValueOffsetIndices PROTOARGs((
  long offset, Logical rowMajor, long numDims, long *dimVarys,
  long *nPhyDimValues, long *indices
));
STATICforIDL Int32 RecordByteOffset PROTOARGs((
  struct cdfSTRUCT *CDF, struct varSTRUCT *Var, long phyRecN
));
STATICforIDL Int32 ValueByteOffset PROTOARGs((
  struct cdfSTRUCT *CDF, struct varSTRUCT *Var, long phyRecN, long *dimIndices
));
STATICforIDL CDFstatus ConfigureNEWzMode PROTOARGs((struct cdfSTRUCT *));
STATICforIDL void InitCURobjectsStates PROTOARGs((struct cdfSTRUCT *));
STATICforIDL long HostEncoding PROTOARGs((void));
STATICforIDL long HostDecoding PROTOARGs((void));
STATICforIDL int IntegerOrder PROTOARGs((long));
STATICforIDL int FpType PROTOARGs((long));
STATICforIDL Logical EquivDataTypes PROTOARGs((long, long));
STATICforIDL void FreeCDFid PROTOARGs((struct cdfSTRUCT *));
STATICforIDL CDFstatus CloseLRUvar PROTOARGs((struct cdfSTRUCT *));
STATICforIDL CDFstatus CalcVarParms PROTOARGs((
  struct cdfSTRUCT *, struct varSTRUCT *
));
STATICforIDL CDFstatus VarAccess PROTOARGs((
  struct cdfSTRUCT *, struct varSTRUCT *
));
STATICforIDL CDFstatus SingleAllocateRecords PROTOARGs((
  struct cdfSTRUCT *, struct varSTRUCT *, long, Logical
));
STATICforIDL CDFstatus PadRecords PROTOARGs((
  struct cdfSTRUCT *CDF, struct varSTRUCT *Var, long firstRec, long lastRec
));
STATICforIDL CDFstatus PadContiguousRecords PROTOARGs((
  struct cdfSTRUCT *CDF, struct varSTRUCT *Var, Int32 offset, long nRecords
));
STATICforIDL CDFstatus CloseCDFfiles PROTOARGs((
  struct cdfSTRUCT *CDF, vSTATS *vStats
));
STATICforIDL Logical WriteAccess PROTOARGs((
  struct cdfSTRUCT *CDF, struct CURstruct *Cur, CDFstatus *pStatus
));
STATICforIDL Logical DeleteAccess PROTOARGs((
  struct cdfSTRUCT *CDF, struct CURstruct *Cur, CDFstatus *pStatus
));
STATICforIDL CDFstatus WriteVarElems PROTOARGs((
  struct varSTRUCT *Var, long numElems, void *buffer
));
STATICforIDL CDFstatus WriteBuffer PROTOARGs((
  struct cdfSTRUCT *CDF, long dataType, long numElems, void *buffer
));
STATICforIDL CDFstatus HyperRead PROTOARGs((
  struct cdfSTRUCT *CDF, struct varSTRUCT *Var, struct rdSTRUCT *rd,
  void *buffer
));
STATICforIDL CDFstatus HyperReadDim PROTOARGs((
  long numDims, long *dimSizes, long *dimVarys, long *indices, long *counts,
  long *intervals, long *nHypDimValues, long *nPhyDimValues,
  Logical *fullPhyDim, int firstDim, int dimIncr, Int32 offset, void *buffer,
  struct cdfSTRUCT *CDF, struct varSTRUCT *Var
));
STATICforIDL CDFstatus HyperWrite PROTOARGs((
  struct cdfSTRUCT *CDF, struct varSTRUCT *Var, struct rdSTRUCT *rd,
  void *buffer
));
STATICforIDL CDFstatus HyperWriteDim PROTOARGs((
  long numDims, long *dimSizes, long *dimVarys, long *indices, long *counts,
  long *intervals, long *nHypDimValues, long *nPhyDimValues,
  Logical *fullPhyDim, int firstDim, int dimIncr, Int32 offset, void *buffer,
  struct cdfSTRUCT *CDF, struct varSTRUCT *Var
));
STATICforIDL CDFstatus ContiguousRecords PROTOARGs((
  struct cdfSTRUCT *CDF, struct varSTRUCT *Var, long firstRec, long lastRec,
  Logical *contig
));
STATICforIDL CDFstatus CDFcre PROTOARGs((
  struct VAstruct *, struct CURstruct *
));
STATICforIDL CDFstatus CDFope PROTOARGs((
  struct VAstruct *, struct CURstruct *
));
STATICforIDL CDFstatus CDFdel PROTOARGs((
  struct VAstruct *, struct CURstruct *
));
STATICforIDL CDFstatus CDFclo PROTOARGs((
  struct VAstruct *, struct CURstruct *
));
STATICforIDL CDFstatus CDFget PROTOARGs((
  struct VAstruct *, struct CURstruct *
));
STATICforIDL CDFstatus CDFput1 PROTOARGs((
  struct VAstruct *, struct CURstruct *
));
STATICforIDL CDFstatus CDFput2 PROTOARGs((
  struct VAstruct *, struct CURstruct *
));
STATICforIDL CDFstatus CDFsel PROTOARGs((
  struct VAstruct *, struct CURstruct *
));
STATICforIDL CDFstatus CDFcon PROTOARGs((
  struct VAstruct *, struct CURstruct *
));
STATICforIDL void CDFcopyRight PROTOARGs((char *));
STATICforIDL CDFstatus CDFstatusText PROTOARGs((CDFstatus, char *));
STATICforIDL CDFstatus Read_V1_header PROTOARGs((struct cdfSTRUCT *));
STATICforIDL CDFstatus Read_V2_header PROTOARGs((struct cdfSTRUCT *));
STATICforIDL CDFstatus Write_V2_header PROTOARGs((struct cdfSTRUCT *));
STATICforIDL char *NULterminate PROTOARGs((
  char *, size_t, struct STRINGstruct **
));
STATICforIDL void FreeStrings PROTOARGs((struct STRINGstruct *));
STATICforIDL Logical ValidCDFname PROTOARGs((char *));
STATICforIDL Logical ValidVarName PROTOARGs((char *));
STATICforIDL Logical ValidAttrName PROTOARGs((char *));
STATICforIDL Logical ValidDataType PROTOARGs((long));
STATICforIDL Logical ValidAttrScope PROTOARGs((long));
STATICforIDL Logical ValidEncoding PROTOARGs((long, long *));
STATICforIDL Logical ValidDecoding PROTOARGs((long));
STATICforIDL CDFstatus ConversionFunction PROTOARGs((
  long dataType, long encoding, long decoding, long negToPosFp0mode,
  CDFstatus (**function) PROTOARGs((void *buffer, long numElems))
));
STATICforIDL CDFstatus FP1toFP34single PROTOARGs((void *buffer,long numElems));
STATICforIDL CDFstatus FP2toFP34single PROTOARGs((void *buffer,long numElems));
STATICforIDL CDFstatus FP34toFP1single PROTOARGs((void *buffer,long numElems));
STATICforIDL CDFstatus FP34toFP2single PROTOARGs((void *buffer,long numElems));
STATICforIDL CDFstatus FP1toFP2singleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP1toFP34singleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP2toFP1singleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP2toFP34singleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP34toFP1singleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP34toFP2singleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP1toFP3double PROTOARGs((void *buffer, long numElems));
STATICforIDL CDFstatus FP1toFP4double PROTOARGs((void *buffer, long numElems));
STATICforIDL CDFstatus FP2toFP3double PROTOARGs((void *buffer, long numElems));
STATICforIDL CDFstatus FP2toFP4double PROTOARGs((void *buffer, long numElems));
STATICforIDL CDFstatus FP3toFP1double PROTOARGs((void *buffer, long numElems));
STATICforIDL CDFstatus FP3toFP2double PROTOARGs((void *buffer, long numElems));
STATICforIDL CDFstatus FP3toFP4double PROTOARGs((void *buffer, long numElems));
STATICforIDL CDFstatus FP4toFP1double PROTOARGs((void *buffer, long numElems));
STATICforIDL CDFstatus FP4toFP2double PROTOARGs((void *buffer, long numElems));
STATICforIDL CDFstatus FP4toFP3double PROTOARGs((void *buffer, long numElems));
STATICforIDL CDFstatus FP1toFP2doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP1toFP3doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP1toFP4doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP2toFP1doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP2toFP3doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP2toFP4doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP3toFP1doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP3toFP2doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP3toFP4doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP4toFP1doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP4toFP2doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP4toFP3doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP1singleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP2singleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP34singleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP1doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP2doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP3doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP4doubleNEGtoPOS PROTOARGs((
  void *buffer, long numElems
));
STATICforIDL CDFstatus FP3doubleLIMIT PROTOARGs((void *buffer, long numElems));
STATICforIDL CDFstatus Reverse2 PROTOARGs((void *buffer, long numElems));
STATICforIDL CDFstatus Reverse4 PROTOARGs((void *buffer, long numElems));
STATICforIDL CDFstatus Reverse8 PROTOARGs((void *buffer, long numElems));
#if defined(Fif_DESCR)
STATICforIDL Logical isDESCR PROTOARGs((void *, char **, size_t *));
STATICforIDL char *DESCRtoREF PROTOARGs((void *));
STATICforIDL char *DESCRtoREFnul PROTOARGs((
  void *, size_t, struct STRINGstruct **
));
#endif
#if defined(Fif_NOLEN)
STATICforIDL char *FindEndNUL PROTOARGs((
  char *, size_t, struct STRINGstruct **
));
#endif
STATICforIDL void SetBit32 PROTOARGs((Int32 *value, int bit));
STATICforIDL void ClearBit32 PROTOARGs((Int32 *value, int bit));
STATICforIDL void CtoFORTstring PROTOARGs((
  char *Cstring, void *FORTstring, int length
));
STATICforIDL void NulPad PROTOARGs((char *string, int length));
STATICforIDL void UpdateMaxRec PROTOARGs((
  struct cdfSTRUCT *CDF, struct varSTRUCT *Var, long phyRecNum
));
STATICforIDL CDFstatus FindCDF PROTOARGs((
  char *path, Logical *append, Logical *upper, Logical *version
));
STATICforIDL void BuildFilePath PROTOARGs((
  int fileType, char *path, Logical no_append, Logical upper, Logical version,
  long varN, int cdfVersion, char pathX[DU_MAX_PATH_LEN+1]
));
STATICforIDL CDFstatus LocateCurrentVar PROTOARGs((
  struct cdfSTRUCT *CDF, Logical zOp, Int32 *offset, Logical *zVar,
  struct varSTRUCT **Var
));
STATICforIDL CDFstatus InitCurrentVar PROTOARGs((
  struct cdfSTRUCT *CDF, Logical zVar, struct varSTRUCT **Var
));
STATICforIDL CDFstatus InitVar PROTOARGs((
  struct cdfSTRUCT *CDF, long varN, Logical zVar, struct varSTRUCT **Var
));
STATICforIDL CDFstatus VarIdentity PROTOARGs((
  struct cdfSTRUCT *CDF, long varN, Logical zOp, long *varNt, Logical *zVar,
  struct varSTRUCT **Var
));
STATICforIDL CDFstatus ReadWriteVar PROTOARGs((
  struct cdfSTRUCT *CDF, struct varSTRUCT *Var
));
STATICforIDL CDFstatus FindAttrByName PROTOARGs((
  struct cdfSTRUCT *CDF, char *searchName, Int32 *offset
));
STATICforIDL CDFstatus FindAttrByNumber PROTOARGs((
  struct cdfSTRUCT *CDF, long searchNum, Int32 *offset
));
STATICforIDL CDFstatus FindEntryByNumber PROTOARGs((
  struct cdfSTRUCT *CDF, Int32 ADRoffset, Logical zEntry, long entryN,
  Int32 *offset
));
STATICforIDL CDFstatus FindVarByName PROTOARGs((
  struct cdfSTRUCT *CDF, char *searchName, Int32 *offset, Logical *zVar,
  struct varSTRUCT **Var
));
STATICforIDL CDFstatus FindVarByNumber PROTOARGs((
  struct cdfSTRUCT *CDF, long searchNum, Int32 *offset, Logical zVar
));
STATICforIDL CDFstatus FindLastAttr PROTOARGs((
  struct cdfSTRUCT *CDF, Int32 *lastOffset
));
STATICforIDL CDFstatus FindLastEntry PROTOARGs((
  struct cdfSTRUCT *CDF, Int32 ADRoffset, Logical zEntry, Int32 *lastOffset
));
STATICforIDL CDFstatus FindPrevEntry PROTOARGs((
  struct cdfSTRUCT *CDF, Int32 ADRoffset, Int32 searchOffset, Logical zEntry,
  Int32 *prevOffset
));
STATICforIDL CDFstatus CheckEntryOp PROTOARGs((
  struct cdfSTRUCT *CDF, int entryType, struct CURstruct *Cur
));
STATICforIDL CDFstatus SetCURgrEntry PROTOARGs((
  struct cdfSTRUCT *CDF, Logical useCurrent, long entryNum
));
STATICforIDL CDFstatus SetCURzEntry PROTOARGs((
  struct cdfSTRUCT *CDF, Logical useCurrent, long entryNum
));
STATICforIDL CDFstatus CalcNumDims PROTOARGs((
  struct cdfSTRUCT *CDF, Int32 offset, Logical zVar, long *numDims
));
STATICforIDL CDFstatus CalcDimVarys PROTOARGs((
  struct cdfSTRUCT *CDF, Int32 offset, Logical zVar, long dimVarys[]
));
STATICforIDL CDFstatus CalcDimSizes PROTOARGs((
  struct cdfSTRUCT *CDF, Int32 offset, Logical zVar, long dimVarys[]
));
STATICforIDL CDFstatus UpdateInitializedVars PROTOARGs((
  struct cdfSTRUCT *CDF
));
STATICforIDL Int32 SeqValueByteOffset PROTOARGs((
  struct cdfSTRUCT *CDF, struct varSTRUCT *Var
));
STATICforIDL void NULterminateMAX PROTOARGs((char *string, size_t maxLen));
STATICforIDL CDFstatus AllocateInternalRecord PROTOARGs((
  struct cdfSTRUCT *CDF, Int32 size, Int32 *offset
));
STATICforIDL CDFstatus ResizeInternalRecord PROTOARGs((
  struct cdfSTRUCT *CDF, Int32 curSize, Int32 curOffset, Int32 newSize,
  Int32 *newOffset, Logical move, Logical *success
));
STATICforIDL CDFstatus RemoveUIRs PROTOARGs((
  struct cdfSTRUCT *CDF, Int32 sOffset, Int32 eOffset
));
STATICforIDL CDFstatus LastAllocatedRecord PROTOARGs((
  struct cdfSTRUCT *CDF, Int32 offset, Logical zVar, Int32 *recNum
));
STATICforIDL CDFstatus VerifyNoRecordsWritten PROTOARGs((
  struct cdfSTRUCT *CDF, Logical *no
));
STATICforIDL CDFstatus VerifyNoPadsSpecified PROTOARGs((
  struct cdfSTRUCT *CDF, Logical *no
));
STATICforIDL CDFstatus VerifyNoEntriesWritten PROTOARGs((
  struct cdfSTRUCT *CDF, Logical *no
));
STATICforIDL Logical Read32 PROTOARGs((vFILE *fp, Int32 *value));
STATICforIDL Logical Read32s PROTOARGs((vFILE *fp, Int32 *buffer, int count));
STATICforIDL CDFstatus ReadCDR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL CDFstatus ReadGDR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL CDFstatus ReadADR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL CDFstatus ReadAEDR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL CDFstatus ReadVDR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL CDFstatus ReadVXR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL CDFstatus ReadVVR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL CDFstatus ReadUIR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL Logical Write32 PROTOARGs((vFILE *fp, Int32 *value));
STATICforIDL Logical Write32s PROTOARGs((vFILE *fp, Int32 *buffer, int count));
STATICforIDL CDFstatus WriteCDR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL CDFstatus WriteGDR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL CDFstatus WriteADR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL CDFstatus WriteAEDR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL CDFstatus WriteVDR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL CDFstatus WriteVXR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL CDFstatus WriteVVR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL CDFstatus WriteUIR PROTOARGs((struct cdfSTRUCT *CDF, ...));
STATICforIDL CDFstatus ConvertBuffer PROTOARGs((
  long srcEncoding, long dstEncoding, long negToPosFp0mode, long dataType,
  long numElems, void *srcbuffer, void *dstBuffer
));
STATICforIDL Logical PriorTo PROTOARGs((
  char *spec, Int32 version, Int32 release, Int32 increment
));
STATICforIDL CDFstatus ShortenCDR PROTOARGs((struct cdfSTRUCT *CDF));
STATICforIDL CDFstatus ShortenVDRs PROTOARGs((struct cdfSTRUCT *CDF));
STATICforIDL CDFstatus CorrectEPOCH PROTOARGs((struct cdfSTRUCT *CDF));
STATICforIDL CDFstatus CorrectScopes PROTOARGs((struct cdfSTRUCT *CDF));
STATICforIDL CDFstatus CorrectV20offsets PROTOARGs((struct cdfSTRUCT *CDF));
STATICforIDL CDFstatus CorrectV20eof PROTOARGs((struct cdfSTRUCT *CDF));
STATICforIDL void DeleteFile PROTOARGs((char *path));
STATICforIDL void AbortAccess PROTOARGs((
  struct cdfSTRUCT *CDF, Logical deleteCDF, struct CURstruct *Cur
));
STATICforIDL void DeleteCDFfiles PROTOARGs((struct cdfSTRUCT *CDF));
STATICforIDL CDFstatus DeleteEntry PROTOARGs((
  struct cdfSTRUCT *CDF, Int32 aOffset, Int32 eOffset
));
STATICforIDL vFILE *V_open PROTOARGs((char *file_spec, char *a_mode));
STATICforIDL int V_setcache PROTOARGs((vFILE *vfp, int nCacheBuffers));
STATICforIDL int V_seek PROTOARGs((vFILE *vfp, long offset, int direction));
STATICforIDL long V_tell PROTOARGs((vFILE *vfp));
STATICforIDL int V_eof PROTOARGs((vFILE *vfp));
STATICforIDL size_t V_read PROTOARGs((
  void *buffer, size_t item_size, size_t n_items, vFILE *vfp
));
STATICforIDL size_t V_write PROTOARGs((
  void *biffer, size_t item_size, size_t n_items, vFILE *vfp
));
STATICforIDL int V_close PROTOARGs((vFILE *vfp, vSTATS *vStats));
STATICforIDL void StripTrailingBlanks PROTOARGs((char *string));
STATICforIDL int NumberOfCacheBuffers PROTOARGs((struct cdfSTRUCT *CDF));

#if defined(MICROSOFTC_700) && INCLUDEvMEMORY
STATICforIDL MemHandle AllocateVMemory PROTOARGs((size_t nBytes));
STATICforIDL void *LoadVMemory PROTOARGs((
  MemHandle handle, Logical writeFlag
));
STATICforIDL int FreeVMemory PROTOARGs((MemHandle handle));
#endif

/*****************************************************************************/

#endif
