#ifndef STREAKS_H
#define STREAKS_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "string.h"
#include "pslib.h"
#include "psmodules.h"
#include "nebclient.h"

#include "streaksextern.h"
#include "streaksastrom.h"

typedef struct {
    psString    resolved_name;
    psString    name;
    bool        inNebulous;
    bool        write;
    psFits      *fits;
    int         nHDU;
    psString    extname;
    psMetadata  *header;
    int         numZPlanes;
    psImage     *image;
    psArray     *imagecube;
    pmFPAfile   *pmfile;
    int         col0;
    int         numCols;    // number of columns in data section of image (doesn't include bias section)
    int         xParity;
    int         row0;
    int         numRows;    // number of rows in data section of image (does not include bias section)
    int         yParity;
    double      exciseValue;
    psString    program;
} sFile;

// used for error messages
extern char * streaksProgram;

typedef struct {
    pmConfig *config;
    ippStage stage;
    int     extnum;
    int     nHDU;   // number of HDUs in the inputs (all must be equal)
    sFile *inImage;
    sFile *inMask;
    sFile *inWeight;
    sFile *outImage;
    sFile *outMask;
    sFile *outWeight;
    sFile *recImage;
    sFile *recMask;
    sFile *recWeight;
    sFile *inChMask;    // for chip stage input mask is camera mask and output goes to both chip and cam masks
    sFile *outChMask;
    sFile *recChMask;
    sFile *inSources;
    sFile *outSources;
    psMetadata *stats;
    FILE *statsFile;
    psString class_id;
    pmFPAfile  *inAstrom;
    strkAstrom *astrom;
    bool  bilevelAstrometry;
    pmFPAview *view;
    pmChip  *chip;  // current chip
    pmCell  *cell;  // current cell
    psImage *diffedPixels;
    psVector    *tiles;
    double  transparentStreaks;
    psString    program_name;
    psU32   maskStreak;
    psU32   maskMask;
} streakFiles;

#include "streaksio.h"

extern void setupAstrometry(streakFiles *);
extern strkAstrom *streakSetAstrometry(strkAstrom *, ippStage stage, pmFPA *, pmChip *, bool fromCell, psMetadata *md,
    int numCols, int numRows);
// can't declare this in streaksastrom due to header file ordering
extern void cellToChip(double *xChip, double *yChip, strkAstrom *astrom, double xCell, double yCell);
extern void cellToChipInt(unsigned int *xChip, unsigned int *yChip, strkAstrom *astrom, int xCell, int yCell);

extern bool computeDiffedPixels(streakFiles *sf);
extern void streaksExit(psString, int);
extern ippStage parseStage(psString);
extern psString pathToDirectory(char *path);
extern void setStreakFiles( streakFiles *);

extern bool streaksVersionHeaderFull(psMetadata *header);
extern psString streaksVersionLong(void);

#define CHIP_LEVEL_INPUT(_stage) ((_stage == IPP_STAGE_RAW) || (_stage == IPP_STAGE_CHIP))
#define USE_SUPPLIED_ASTROM(_stage) CHIP_LEVEL_INPUT(_stage)

#define SFILE_IS_IMAGE(_sfile) (_sfile->image || _sfile->imagecube)
#define IN_NEBULOUS(_filename) (!strncasecmp(_filename, "neb://", strlen("neb://")))


#endif // STREAKS_H
