/*------------------------------------------------------------------------------
 * File: 	df.h
 * Purpose:	header file for HDF routines
 * Invokes:	dfi.h
 * Contents: 
 *	Structure definitions: DFddh, DFdd, DFdesc, DFdle, DF, DFdi, DFdata
 *	Procedure type definitions
 *	Global variables
 *	Tag definitions
 *  Error return codes
 *	Logical constants
 * Remarks: This file is included with user programs
 *			Since it includes stdio.h etc., do not include these after df.h
 *----------------------------------------------------------------------------*/


#ifndef DFTAG_NULL				/* avoid re-inclusion */

/* include DF (internal) header information */
#include "dfi.h"

/*--------------------------------------------------------------------------*/
/*						Type declarations 									*/

typedef struct DFddh {		/* format of data descriptor headers as in file */
	int16
		dds;				/* number of dds in header block */
	int32	
		next;				/* offset of next header block */
	} DFddh;

		
typedef struct DFdd {		/* format of data descriptors as in file */
	uint16
		tag,				/* data tag */
		ref;				/* data reference number */
	int32
		offset,				/* offset of data element in file */
		length;				/* number of bytes */
	} DFdd;


	/* descriptor structure is same as dd structure.  ###Note: may be changed */
#define DFdesc	DFdd


	/* DLE is the internal structure which stores data descriptor information */
	/* It is a linked list of DDs */
typedef struct DFdle {		/* Data List element */
	struct DFdle
		*next;				/* link to next dle */
	DFddh
		ddh;				/* To store headers */
	DFdd
		dd[1];				/* dummy size */
	} DFdle;	


	/* DF is the internal structure associated with each DF file */
	/* It holds information associated with the file as a whole */
	/* ### Note: there are hooks for having multiple DF files open at a time */
typedef struct DF {
	DFdle
		*list,			/* Pointer to the DLE list */
		*last_dle;		/* last_dle and last_dd are used in searches to indicate
							element returned by previous call to DFfind */
	int
		type,			/* 0= not in use, 1= normal, -1 = multiple */
						/* this is a hook for when multiple files are open */
		access,			/* permitted access types: 0=none, 1=r, 2=w, 3=r/w */
		changed, 		/* True if anything in DDs modified since last write */
		last_tag,		/* Last tag searched for by DFfind */
		last_ref,		/* Last reference number searched for */
		last_dd,		/* see last_dle */
		defdds,			/* default numer of DD's in each block */
		up_access;		/* access permissions to element being read/updated */
						/* Used by DFstart */
	DFdd
		*up_dd;			/* DD of element being read/updated, used by DFstart */
  			/* file handle is a file pointer or file descriptor */
			/* depending on whether we use buffered or unbuffered i/o */
#ifdef DF_BUFFIO
	FILE *				/* file pointer */
#else DF_BUFFIO
	int					/* file descriptor */
#endif DF_BUFFIO
		file;			/* File handle for real file */
} DF;


typedef struct DFdi {	/* data identifier: specifies data element uniquely */
	uint16 tag;
	uint16 ref;
} DFdi;



typedef struct DFdata {	/* structure for returning status information */
	int version;		/* version number of program */
} DFdata;

/*--------------------------------------------------------------------------*/
/*							Procedure types 								*/

#ifndef VMS
DF *DFopen();
int32 DFgetelement(), DFread(), DFseek(), DFwrite();
uint16 DFnewref();
char *DFIgetspace(), *DFIfreespace(), *DFIf2cstring();
#else VMS
			/* for VMS need to prepend _ to avoid name conflict with Fortran */
DF *_DFopen();
int32 _DFgetelement(), _DFread(), _DFseek(), _DFwrite();
uint16 _DFnewref();
char *_DFIgetspace(), *_DFIfreespace(), *_DFIf2cstring();
#endif VMS


/*--------------------------------------------------------------------------*/
/*							Global Variables 								*/

#ifndef DFMASTER
extern
#endif DFMASTER
int
	DFerror;			/* Error code for DF routines */

/*--------------------------------------------------------------------------*/
/*							 Tag Definitions							    */

#define DFREF_WILDCARD 0	/* wildcard ref for searches */

#define DFTAG_WILDCARD 0	/* wildcard tag for searches */
#define	DFTAG_NULL	1		/* empty DD */

	/* utility set */
#define DFTAG_FID	100		/* File identifier */
#define	DFTAG_FD	101		/* File description */
#define	DFTAG_TID	102		/* Tag identifier */
#define	DFTAG_TD	103		/* Tag descriptor */
#define DFTAG_DIL	104		/* data identifier label */
#define DFTAG_DIA	105		/* data identifier annotation */
#define DFTAG_NT	106		/* number type */
#define DFTAG_MT	107		/* machine type */

	/* raster-8 set */
#define DFTAG_ID8	200		/* 8-bit Image dimension */
#define DFTAG_IP8	201		/* 8-bit Image palette */
#define DFTAG_RI8	202		/* Raster-8 image */
#define DFTAG_CI8	203		/* RLE compressed 8-bit image */
#define DFTAG_II8	204		/* IMCOMP compressed 8-bit image */

	/* Raster Image set */
#define DFTAG_ID	300		/* Image DimRec */
#define DFTAG_LUT	301		/* Image Palette */
#define	DFTAG_RI	302		/* Raster Image */
#define	DFTAG_CI	303		/* Compressed Image */

#define DFTAG_RIG	306		/* Raster Image Group */
#define DFTAG_LD	307		/* Palette DimRec */
#define	DFTAG_MD	308		/* Matte DimRec */
#define DFTAG_MA	309		/* Matte Data */
#define DFTAG_CCN	310		/* color correction */
#define DFTAG_CFM	311		/* color format */
#define DFTAG_AR	312		/* aspect ratio */
	
#define	DFTAG_DRAW	400		/* Draw these images in sequence */
#define	DFTAG_RUN	401		/* run this as a program/script */

#define DFTAG_XYP	500		/* x-y position */
#define DFTAG_MTO	501		/* machine-type override */

	/* Tektronix */
#define DFTAG_T14	602		/* TEK 4014 data */
#define DFTAG_T105	603		/* TEK 4105 data */

	/* Scientific Data set */
#define DFTAG_SDG	700		/* Scientific Data Group */
#define DFTAG_SDD	701		/* Scientific Data DimRec */
#define DFTAG_SD	702		/* Scientific Data */
#define DFTAG_SDS	703		/* Scales */
#define DFTAG_SDL	704		/* Labels */
#define DFTAG_SDU	705		/* Units */
#define DFTAG_SDF	706		/* Formats */
#define DFTAG_SDM	707		/* Max/Min */
#define DFTAG_SDC	708		/* Coord sys */
#define DFTAG_SDT	709		/* Transpose */

	/* compression schemes */
#define DFTAG_RLE	11		/* run length encoding */
#define DFTAG_IMC	12		/* IMCOMP compression */

/*--------------------------------------------------------------------------*/
/*							Error Return Codes 								*/

#define	DFE_NOERROR		0	/* No error */
#define	DFE_FNF			-1	/* File not found error */
#define	DFE_DENIED		-2	/* Access to file denied */
#define	DFE_ALROPEN		-3	/* File already open */
#define	DFE_TOOMANY		-4	/* Too Many DF's or files open */
#define DFE_BADNAME		-5	/* Bad file name on open */
#define	DFE_BADACC		-6	/* Bad file access mode */
#define DFE_BADOPEN		-7	/* Other open error */
#define DFE_NOTOPEN		-8	/* File can't be closed 'cause it isn't open */
#define DFE_CANTCLOSE	-9	/* fclose wouldn't work! */
#define DFE_DFNULL		-10	/* DF is a null pointer */
#define DFE_ILLTYPE		-11	/* DF has an illegal type: internal error */
#define DFE_UNSUPPORTED	-12	/* Feature not currently supported */
#define DFE_BADDDLIST	-13	/* The DD list is non-existent: internal error */
#define DFE_NOTDFFILE	-14	/* This is not a DF file and it is not 0 length */
#define DFE_SEEDTWICE	-15	/* The DD list already seeded: internal error */
#define	DFE_NOSPACE		-16	/* Malloc failed */
#define	DFE_NOSUCHTAG	-17	/* There is no such tag in the file: search failed*/
#define DFE_READERROR	-18	/* There was a read error */
#define DFE_WRITEERROR	-19	/* There was a write error */
#define DFE_SEEKERROR	-20	/* There was a seek error */
#define DFE_NOFREEDD	-21	/* There are no free DD's left: internal error */
#define DFE_BADTAG		-22	/* illegal WILDCARD tag */
#define DFE_BADREF		-23	/* illegal WILDCARD reference # */
#define DFE_RDONLY		-24	/* The DF is read only */
#define DFE_BADCALL		-25	/* Calls in wrong order */
#define DFE_BADPTR		-26 /* NULL ptr argument */
#define DFE_BADLEN		-27	/* negative len specified */
#define DFE_BADSEEK		-28	/* Attempt to seek past end of element */
#define DFE_NOMATCH		-29	/* No (more) DDs which match specified tag/ref */
#define DFE_NOTINSET	-30	/* Warning: Set contained unknown tag: ignored */
#define DFE_BADDIM		-31	/* negative or zero dimensions specified */
#define DFE_BADOFFSET	-32	/* Illegal offset specified */
#define DFE_BADSCHEME	-33	/* Unknown compression scheme specified */
#define DFE_NODIM		-34	/* No dimension record associated with image */
#define DFE_NOTENOUGH	-35	/* space provided insufficient for size of data */
#define DFE_NOVALS		-36	/* Values not available */
#define DFE_CORRUPT		-37	/* File is corrupted */
#define DFE_BADCONV		-37	/* Don't know how to convert data type */
#define DFE_BADFP		-38	/* The file contained an illegal floating point no*/
#define DFE_NOREF		-39	/* no more reference numbers are available */
#define DFE_BADDATATYPE	-40	/* unknown or unavailable data type specified */
#define DFE_BADMCTYPE	-41	/* unknown or unavailable machine type specified */
#define DFE_BADNUMTYPE	-42	/* unknown or unavailable number type specified */
#define DFE_BADORDER	-43	/* unknown or illegal array order specified */
#define DFE_NOTIMPL		-44	/* This feature not yet implemented */

/*--------------------------------------------------------------------------*/
/*							Logical Constants 								*/

#define DFACC_READ		1	/* Read Access */
#define DFACC_WRITE		2	/* Write Access */
#define DFACC_CREATE	4	/* force file to be created */
#define DFACC_ALL		7	/* the logical and of all the above values */

#endif DFTAG_NULL
