/*** dvomath.h ***/

# ifndef DVOMATH_H
# define DVOMATH_H

# define NCHARS 256

enum {ANYVECTOR, NEWVECTOR, OLDVECTOR};
enum {ANYBUFFER, NEWBUFFER, OLDBUFFER};

typedef struct {			/* representation of a variable (0-D) */
  char     *name;
  char     *value;
} Variable;

typedef struct {			/* representation of a vector (1-D) */
  char name[1024];
  float *elements;
  int Nelements;
} Vector;

typedef struct {			/* representation of buffer (image) */
  char name[1024];
  char file[1024];
  Header header;
  Matrix matrix;
  int  bitpix, unsign;
  double bscale, bzero;
} Buffer;

typedef struct {			/* math stack structure */
  char   *name;
  char    type;
  float  *ptr;
  Buffer *buffer;
  Vector *vector;
  float   Float;
} StackVar;

/* math functions */
char         *dvomath               PROTO((int argc, char **argv, int *size, int maxsize));
char        **isolate_elements      PROTO((int argc, char **argv, int *nstack));
StackVar     *convert_to_RPN        PROTO((int argc, char **argv, int *nstack));
int           check_stack           PROTO((StackVar *stack, int Nstack, int validsize));
int           evaluate_stack        PROTO((StackVar *stack, int *Nstack));
void          init_stack            PROTO((StackVar *stack));
void          copy_stack	    PROTO((StackVar *stack1, StackVar *stack2));
void          move_stack	    PROTO((StackVar *stack1, StackVar *stack2));
void          clean_stack	    PROTO((StackVar *stack, int Nstack));
void          delete_stack	    PROTO((StackVar *stack, int Nstack));
int           VV_binary             PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op));
int           SV_binary             PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op));
int           VS_binary             PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op));
int           MV_binary             PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op));
int           VM_binary             PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op));
int           MM_binary             PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op));
int           MS_binary             PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op));
int           SM_binary             PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op));
int           SS_binary             PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op));
int           WW_binary             PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op));
int           S_unary               PROTO((StackVar *OUT, StackVar *V1, char *op));
int           V_unary               PROTO((StackVar *OUT, StackVar *V1, char *op));
int           M_unary               PROTO((StackVar *OUT, StackVar *V1, char *op));

/* variable handling */
char         *get_variable          PROTO((char *name));
char         *get_variable_ptr      PROTO((char *name));
char         *get_local_variable_ptr PROTO((char *name));
double        get_double_variable   PROTO((char *name, int *found));
int           get_int_variable      PROTO((char *name, int *found));
int           DeleteNamedScalar     PROTO((char *name));
int           IsScalar              PROTO((char *name));
int           set_variable          PROTO((char *name, double dvalue));
int           set_int_variable      PROTO((char *name, int ivalue));
int           set_str_variable      PROTO((char *name, char *value));
int           set_local_variable    PROTO((char *name, char *value));
void          InitVariables         PROTO((void));
void          ListVariables         PROTO((void));
float         get_variable_default  PROTO((char *name, float dvalue));
int           SelectScalar          PROTO((char *string, double *value));

/* vector handling */
Vector       *InitVector            PROTO((void));
void          InitVectors           PROTO((void));
int           CopyVector            PROTO((Vector *out, Vector *in));
int           MoveVector            PROTO((Vector *out, Vector *in));
int           DeleteVector          PROTO((Vector *vec));
int           CopyNamedVector       PROTO((char *out, char *in));
int           MoveNamedVector       PROTO((char *out, char *in));
int           DeleteNamedVector     PROTO((char *name));
int           IsVector              PROTO((char *name));
int           IsVectorPtr           PROTO((Vector *vec));
int           ListVectors           PROTO((void));
Vector       *SelectVector          PROTO((char *name, int mode, int verbose));

/* buffer handling */
Buffer       *InitBuffer            PROTO((void));
void          InitBuffers           PROTO((void));
int           CopyBuffer            PROTO((Buffer *out, Buffer *in));
int           MoveBuffer            PROTO((Buffer *out, Buffer *in));
int           DeleteBuffer          PROTO((Buffer *buf));
int           CopyNamedBuffer       PROTO((char *out, char *in));
int           MoveNamedBuffer       PROTO((char *out, char *in));
int           DeleteNamedBuffer     PROTO((char *name));
int           IsBuffer              PROTO((char *name));
int           IsBufferPtr           PROTO((Buffer *buf));
int           PrintBuffers          PROTO((int Long));
int           CreateBuffer          PROTO((Buffer *buf, int Nx, int Ny, int bitpix, float bzero, float bscale));
Buffer       *SelectBuffer          PROTO((char *name, int mode, int verbose));
void          dump_buffers          PROTO((int n));  /* deprecated? */
int           SelectOverlay         PROTO((char *name, int *number));

/* why are these in here? */
int           gfits_copy_matrix_info (Matrix *matrix1, Matrix *matrix2);
int           GetTimeFormat         PROTO((time_t *TimeReference, int *TimeFormat));

# endif
