/* szModuleName__ []  = "f:/r3/code/c/incl/fil.h" */
/* szLastVersion []   = "Version 0.3" */
/* szLastSave []      = "1994-07-12*13:22" */
/*
-- DEC/CMS REPLACEMENT HISTORY, Element FIL.ADA
-- DEC/CMS REPLACEMENT HISTORY, Element FIL.ADA
------------------------------------------------------------
-- Fil			File: FIL.H
--
-- Rev
--    990125	 ARG, Modified entry names to avoid collision w. filep
--    941002	 ARG, Au system mode parameter in fpopen
--    940704     ARG, Au system INT32 instead of int
--    940302     CFR, Au system C-headerfile from fil.ada
--
------------------------------------------------------------
*/

#ifndef __NRDFILE_H
#define __NRDFILE_H
#include "apitypes.h"
#ifdef VAXC
#include <types.h>
#include <stdio.h>
#else
#include <sys/types.h>
#include <stdio.h>
#endif
/* ------------------------------------------------------------
   -- IDENT - record below follows
   -- This record start at the beginning of the file.
   -- Immediately after follows the attribute area.
   ------------------------------------------------------------
*/

   typedef struct {
	char SysName[10];
	unsigned char Version;
	unsigned char Size;
   } IdentArea_t;

   /*
   -- Define a "universal" enumeration type onto which 
   -- the generic enumeration type for attributes is mapped.
   -- '0' is used as null value.

   ------------------------------------------------------------
   -- FileType  type.
   ------------------------------------------------------------
*/
#define MaxNameSize 130
typedef enum  {
	InputMode,
	UpdateMode
}FileMode_t;

typedef struct {
	  char Name[MaxNameSize+1];
	  FILE *fp;
	  int Blocks;
	  INT32 Allocated;  /* Last Position written to the file */
	  INT32 AttrSize;
	  INT32 DataSize;
	  char *AttrBuf; /* buffer holding Attr, malloced */
	  unsigned  Opened : 1;
   } Fil_t;


   /*

   ------------------------------------------------------------
   -- Attributes data type.
   ------------------------------------------------------------
*/

typedef enum  {
	None_Attr,
	Name_Attr,
	Area_Attr,
	AreaProperties_Attr,
	Time_Attr,
	Quantity_Attr,
	IntStore_Attr,
	RrTyp_Attr,
	Height_Attr,
	Pixel_Attr,
	Levels_Attr,
	AreaWall_Attr,
	Line_Attr,
	Bitmap_Attr,
	SubAreas_Attr, 
	Resolution_Attr,
	Z_To_R_Constants_Attr,
	Clutter_Treatment_Attr,
	Occultation_Correction_Attr,
	Period_Attr 
}AttrTyp_t;

typedef struct {
	  unsigned short TypSize; /* 16 bytes , Typ = 0-6 Size = 7-15 */
   } AttrHead_t;

/*
   ------------------------------------------------------------
   -- Attributes data type.
   ------------------------------------------------------------
*/
typedef struct {
	unsigned char buff[512];  /* Data type containing actual Attribute */
   } Attr_t;

/* ------------------------------------------------------------
   -- IdentStr_t data type.
   ------------------------------------------------------------
*/
      typedef struct {
	      char Str_t[3];
      }IdentStr_t;

/* 
   ------------------------------------------------------------
   -- Basic file operations
   ------------------------------------------------------------

   -- Each file type is identified with an identifier string.
   subtype
      IdentStr_t is Strings.Str_t ( 3 );

   -- Create a file. The size of the file is determined at creation
   -- It is possible to scale down files after creation.
   -- Scaling up after creation is not possible, though.
*/

extern void fiCreate (Fil_t *F,
		  char *Name,
		  INT32 AttrSize,  /* in blocks */
		  INT32 DataSize,	 /* in bytes */
		  INT32 *Retcode);

extern void fiOpen   (Fil_t *F,
		      FileMode_t FileMode,
		      INT32 *Retcode);


extern void fiClose(Fil_t *F,
		    INT32 *Retcode);

extern void fiDelete(Fil_t *F,
		     INT32 *Retcode);

extern void fiAllocate(Fil_t *F,
		       INT32 Size,
		       INT32  *Offset,
		       INT32 *Retcode);

extern void fiCopy_Header(Fil_t *From_F,
			  Fil_t *To_F,
			  INT32 *Retcode);

extern void fiGetName (Fil_t *Fil,char *pstr,
		       INT32 *Retcode);

/*
   ------------------------------------------------------------
   -- Generic attribute handling.
   ------------------------------------------------------------
*/ 
extern void fiReadAttr(Fil_t *Fil,
		       Attr_t *Attr,
		       AttrTyp_t Type,
		       INT32 *Length,
		       INT32 *Retcode);

extern void fiWriteAttr(Fil_t *Fil,
			Attr_t *Attr,
			AttrTyp_t Type,
			INT32 Length,
			INT32 *Retcode);

#endif /* ifndef __NRDFILE_H */
