/* L.Lee   02/17/00N Add EPOCH field to ff_data & ff_param             */ 
/* define the different structs some time soon */

#ifndef FF_IGPP
#include <stdio.h>
#include <errno.h>

#define FF_LINE     72
#define FF_FORMAT   "%-72s"
#define FF_LOCK		020
#define FF_EXIST	010
#define FF_CREATE	004
#define FF_READ		002
#define FF_WRITE	001

#define FF_MAINID	000
#define FF_HEADER	001
#define FF_DATA		002

#define TIME66		000
#define DOUBLE		001
#define FLOAT		002
#define LONG		003
#define ULONG		004
#define SHORT		005
#define USHORT		006
#define BYTE		007
#define CHAR		010

extern int errno;
/* leel 03/02/00   | This should correlate to enum defs in time_igpp.h */
#ifndef D_EPOCH
enum EPOCH   {Y1966 = 19660,Y2000 = 20000,J2000=20005,Y1958=19580};
/* cline time, EPOCH=2000, ET */
#define D_EPOCH
#endif
enum OPSYS   {UNIXOPS=0,SUNOPS=1,PCOPS=2,MACOPS=3};

#ifndef TIME_IGPP
#include <time_igpp.h>
#endif
#ifdef FF_LIB
#ifdef PC
#define FFSTDOUT
FILE *ff_stdout=NULL;   /* file pointer for "opened" messages and ff_hlist */
FILE *ff_stderr=NULL;   /* file pointer for errors */
#endif
#ifdef LINUX
#define FFSTDOUT
FILE *ff_stdout;        /* file pointer for "opened" messages and ff_hlist */
FILE *ff_stderr;        /* file pointer for errors */
#endif
#ifndef FFSTDOUT
FILE *ff_stdout=stdout; /* file pointer for "opened" messages and ff_hlist */
FILE *ff_stderr=stderr; /* file pointer for errors */
#endif
#endif


typedef struct ff_id FF_ID;
typedef struct ff_header FF_HID;
typedef struct ff_data FF_DID;
typedef struct ff_col_desc FF_COL_DESC;
typedef struct ff_h_info FF_H_INFO;
typedef struct ff_param FF_O_PARAM;

/*
 * The first four elements of ff_id, ff_header and ff_data should be
 * indentical so that ff_reporterror can be called with a pointer
 * to any of these structures.
 */
struct ff_id {
  int type;
  struct ff_header *ffh;
  struct ff_data *ffd;
  struct ff_id *id;
  int status,opsys;
};

/*
 * The first 7 elements of ff_header and ff_data should be
 * indentical so that ff_reporterror can be called with a pointer
 * to either of these structures.
 */
struct ff_header {
  int type;
  struct ff_header *ffh;
  struct ff_data *ffd;
  struct ff_id *id;
  FILE *fp;
  char *name;
  int error;
  int loc;
/* leel 12/12/00 Account EPOCH= line, to calculate where col desc */
/*               begins in header file                            */
  int eoffset;
/* leel 12/05/00 unit descriptors are nolonger limited to 10 char */
  int fmunit;
};

struct ff_data {
  int type;
  struct ff_header *ffh;
  struct ff_data *ffd;
  struct ff_id *id;
  FILE *fp;
  char *name;
  int error;
  struct ff_datafields *df;
  long nrows,size;
  int recl,ncols;
  enum EPOCH epoch;
};

struct ff_param {
  int status,recl,ncols,nbufs;
  unsigned long nrows;
  enum EPOCH epoch;
};


struct ff_h_info {
  double first_time,last_time,resolution,flag;
  char owner[80]; /* char owner[L_cuserid]; */
  int first_orbit,last_orbit;
};

#define FF_COL_NAMELEN 20
#define FF_COL_UNITSLEN 32
#define FF_COL_SOURCELEN 30
#define FF_COL_TYPELEN 8

struct ff_col_desc {
  int ncol;
  char name[FF_COL_NAMELEN];
  char units[FF_COL_UNITSLEN];
  char source[FF_COL_SOURCELEN];
  char type[FF_COL_TYPELEN];
  int loc;
};

struct ff_datafields { int type,loc,len; };

FF_ID *ff_open (char *fname,FF_O_PARAM *o_parms);
int ff_put (FF_DID *id,char *record,int len);
int ff_get (FF_DID *id,char *record,int len);
int ff_cput(FF_HID *id,char *record);
int ff_cget(FF_HID *id,char *record);
int ff_hget(FF_HID *id,FF_COL_DESC *hr);
int ff_hput(FF_HID *id,FF_COL_DESC *hr);
int ff_hputinfo(FF_HID *id,FF_H_INFO *info);
int ff_hgetinfo(FF_HID *id,FF_H_INFO *info);
int ff_close (FF_ID *id);

/* Added, jw, Dec 2003 */
int ff_hcopyabstract(FF_HID * idin, FF_HID *idout);
void FFSwapRecords (char *buffer, int nchar); 

long ff_setrow(FF_DID *id,long row);
long ff_getrow(FF_DID *id);
long ff_bsearch(FF_ID *id,double time,long row1,long row2);
void ff_reporterror(FF_HID *id);
void PrintFF_DATA(struct ff_data *ff_data);
void PrintFF_HEADER(struct ff_header *ff_header);
void SetUnitFormat(int len);
void PrintFFColDesc(FF_COL_DESC desc);
void PrintFFParam(FF_O_PARAM parm);
void PrintFFINFO(FF_H_INFO info);
void FFSilentMode();
void FFOldStyle();
#define FF_IGPP
#endif

