#include <limits.h>
#include "par.h"
#ifndef SEGY_H
#define SEGY_H
#define TRCBYTES 240
#define SU_NFLTS 32767
typedef struct {
int tracl;
int tracr;
int fldr;
int tracf;
int ep;
int cdp;
int cdpt;
short trid;
short nvs;
short nhs;
short duse;
int offset;
int gelev;
int selev;
int sdepth;
int gdel;
int sdel;
int swdep;
int gwdep;
short scalel;
short scalco;
int sx;
int sy;
int gx;
int gy;
short counit;
short wevel;
short swevel;
short sut;
short gut;
short sstat;
short gstat;
short tstat;
short laga;
short lagb;
short delrt;
short muts;
short mute;
unsigned short ns;
unsigned short dt;
short gain;
short igc;
short igi;
short corr;
short sfs;
short sfe;
short slen;
short styp;
short stas;
short stae;
short tatyp;
short afilf;
short afils;
short nofilf;
short nofils;
short lcf;
short hcf;
short lcs;
short hcs;
short year;
short day;
short hour;
short minute;
short sec;
short timbas;
short trwf;
short grnors;
short grnofr;
short grnlof;
short gaps;
short otrav;
#ifdef SLTSU_SEGY_H
float d1;
float f1;
float d2;
float f2;
float ungpow;
float unscale;
short mark;
short mutb;
float dz;
float fz;
short n2;
short shortpad;
int ntr;
short unass[8];
#else
float d1;
float f1;
float d2;
float f2;
float ungpow;
float unscale;
int ntr;
short mark;
short shortpad;
short unass[14];
#endif
} segy;
typedef struct {
int jobid;
int lino;
int reno;
short ntrpr;
short nart;
unsigned short hdt;
unsigned short dto;
unsigned short hns;
unsigned short nso;
short format;
short fold;
short tsort;
short vscode;
short hsfs;
short hsfe;
short hslen;
short hstyp;
short schn;
short hstas;
short hstae;
short htatyp;
short hcorr;
short bgrcv;
short rcvm;
short mfeet;
short polyt;
short vpol;
short hunass[170];
} bhed;
#define gettr(x) fgettr(stdin, (x))
#define vgettr(x) fvgettr(stdin, (x))
#define puttr(x) fputtr(stdout, (x))
#define vputtr(x) fvputtr(stdout, (x))
#define gettra(x, y) fgettra(stdin, (x), (y))
#define TOTHER -1
#define TUNK 0
#define TREAL 1
#define TDEAD 2
#define TDUMMY 3
#define TBREAK 4
#define UPHOLE 5
#define SWEEP 6
#define TIMING 7
#define WBREAK 8
#define NFGUNSIG 9
#define FFGUNSIG 10
#define SPSENSOR 11
#define TVERT 12
#define TXLIN 13
#define TINLIN 14
#define ROTVERT 15
#define TTRANS 16
#define TRADIAL 17
#define VRMASS 18
#define VBASS 19
#define VEGF 20
#define VREF 21
#define ACOR 109
#define FCMPLX 110
#define FUNPACKNYQ 111
#define FTPACK 112
#define TCMPLX 113
#define FAMPH 114
#define TAMPH 115
#define REALPART 116
#define IMAGPART 117
#define AMPLITUDE 118
#define PHASE 119
#define KT 121
#define KOMEGA 122
#define ENVELOPE 123
#define INSTPHASE 124
#define INSTFREQ 125
#define TRID_DEPTH 130
#define CHARPACK 201
#define SHORTPACK 202
#define ISSEISMIC(id) (( (id)==TUNK || (id)==TREAL || (id)==TDEAD || (id)==TDUMMY || (id)==TBREAK || (id)==UPHOLE || (id)==SWEEP || (id)==TIMING || (id)==WBREAK || (id)==NFGUNSIG || ( id)==FFGUNSIG || (id)==SPSENSOR || (id)==TVERT || (id)==TXLIN || (id)==TINLIN || (id)==ROTVERT || (id)==TTRANS || (id)==TRADIAL || (id)==ACOR ) ? cwp_true : cwp_false )
#ifdef __cplusplus
extern "C" {
#endif
int fgettr(FILE *fp, segy *tp);
int fvgettr(FILE *fp, segy *tp);
void fputtr(FILE *fp, segy *tp);
void fvputtr(FILE *fp, segy *tp);
int fgettra(FILE *fp, segy *tp, int itr);
segy **fget_gather(FILE *fp, cwp_String *key,cwp_String *type,Value *n_val,
int *nt,int *ntr, float *dt,int *first);
segy **get_gather(cwp_String *key, cwp_String *type, Value *n_val,
int *nt, int *ntr, float *dt, int *first);
segy **fput_gather(FILE *fp, segy **rec,int *nt, int *ntr);
segy **put_gather(segy **rec,int *nt, int *ntr);
void gethval(const segy *tp, int index, Value *valp);
void puthval(segy *tp, int index, Value *valp);
void getbhval(const bhed *bhp, int index, Value *valp);
void putbhval(bhed *bhp, int index, Value *valp);
void gethdval(const segy *tp, char *key, Value *valp);
void puthdval(segy *tp, char *key, Value *valp);
char *hdtype(const char *key);
char *getkey(const int index);
int getindex(const char *key);
void swaphval(segy *tp, int index);
void swapbhval(bhed *bhp, int index);
void printheader(const segy *tp);
void tabplot(segy *tp, int itmin, int itmax);
#ifdef __cplusplus
}
#endif
#endif