#if !defined(__AVWIO_H)
#define __AVWIO_H

#include <stdio.h>
#include "dbh.h"

#define AVW_READ  0
#define AVW_WRITE 1

#ifdef __cplusplus
extern "C" {
#endif

typedef struct 
{
  FILE *imgfp;
  FILE *hdrfp;

  int mode, sameorder;

  struct dsr header;
} AVW;

  AVW *AvwOpen(const char *filename, const char *opts);
  
  void AvwInitHeader(AVW *avw, short t, 
		     size_t x, size_t y, size_t z, size_t v,
		     float vx, float vy, float vz, float tr,
		     size_t dim,
		     const char* units);
  void AvwCloneHeader(AVW *dest, const AVW *src);
  
  size_t AvwReadVolumes(AVW *avw, void *buffer, size_t nvols);
  size_t AvwWriteVolumes(AVW *avw, const void *buffer, size_t nvols);
  size_t AvwReadSliceSeries(AVW *avw, void *buffer,short slice, size_t nvols);
  size_t AvwReadRowSeries(AVW *avw, void *buffer, short row, short slice, size_t nvols);
  size_t AvwWriteSliceSeries(AVW *avw,const  void *buffer,short slice, size_t nvols);
  size_t AvwWriteRowSeries(AVW *avw,const  void *buffer, short row, short slice, size_t nvols);
  size_t AvwReadCplxVolumes(AVW *avw, void *buffer, size_t nvols, char mode);
  size_t AvwWriteplxVolumes(AVW *avw, void *buffer, size_t nvols, char mode);
  int AvwSeekVolume(AVW *avw, size_t vols);
  
  size_t AvwGetVolSize(AVW *avw);
  
  void AvwSetDim(AVW *avw, short x, short y, short z, short v);
  void AvwGetDim(AVW *avw, short *x, short *y, short *z, short *v);
  void AvwSetDimensionality(AVW *avw, size_t dim);
  void AvwGetDimensionality(AVW *avw, size_t *dim);
  void AvwSetVoxDim(AVW *avw, float x, float y, float z, float tr);
  void AvwGetVoxDim(AVW *avw, float *x, float *y, float *z, float *tr);
  void AvwSetMinMax(AVW *avw, int min, int max);
  void AvwGetMinMax(AVW *avw, int *min, int *max);
  
  void AvwSetVoxUnits(AVW *avw, const char *units);
  void AvwGetVoxUnits(AVW *avw, char *units);
  void AvwSetDataType(AVW *avw, short t);
  size_t AvwGetDataType(AVW *avw, short *t);
  void AvwSetOrientation(AVW *avw, const char orient);
  void AvwGetOrientation(AVW *avw, char *orient);
  void AvwSetOriginator(AVW *avw, const short orig[5]);
  void AvwGetOriginator(AVW *avw, short orig[5]);
  
  int IsBackwardOrder(void);
  void Reverse2(void *ptr, size_t n);
  void Reverse4(void *ptr, size_t n);
  void AvwReverseDsr(AVW *avw);
  void AvwReverseBuffer(AVW *avw, void *buffer, size_t n);
  
  int AvwClose(AVW *avw);
  
#ifdef __cplusplus
}
#endif

#endif
