# include "data.h"

int accum            PROTO((int, char **));
int applyfit         PROTO((int, char **));
int applyfit2d       PROTO((int, char **));
int box              PROTO((int, char **));
int book_command     PROTO((int, char **));
int center           PROTO((int, char **));
int circstats        PROTO((int, char **));
int clear            PROTO((int, char **));
int clip             PROTO((int, char **));
int close_device     PROTO((int, char **));
int concat           PROTO((int, char **));
int contour          PROTO((int, char **));
int create           PROTO((int, char **));
int cumulative       PROTO((int, char **));
int cursor           PROTO((int, char **));
int cut              PROTO((int, char **));
int datafile         PROTO((int, char **));
int dbconnect        PROTO((int, char **));
int dbselect         PROTO((int, char **));
int delete           PROTO((int, char **));
int device           PROTO((int, char **));
int dimendown        PROTO((int, char **));
int dimenup          PROTO((int, char **));
int erase            PROTO((int, char **));
int extract          PROTO((int, char **));
int fft1d            PROTO((int, char **));
int fft2d            PROTO((int, char **));
int fit2d            PROTO((int, char **));
int fit              PROTO((int, char **));
int gaussjordan      PROTO((int, char **));
int gaussdeviate     PROTO((int, char **));
int gaussintegral    PROTO((int, char **));
int grid             PROTO((int, char **));
int gridify          PROTO((int, char **));
int grow             PROTO((int, char **));
int ungridify        PROTO((int, char **));
int histogram        PROTO((int, char **));
int imcut            PROTO((int, char **));
int imhist           PROTO((int, char **));
int imsmooth         PROTO((int, char **));
int integrate        PROTO((int, char **));
int interpolate      PROTO((int, char **));
int jpeg             PROTO((int, char **));
int kern             PROTO((int, char **));
int keyword          PROTO((int, char **));
int labels           PROTO((int, char **));
int limits           PROTO((int, char **));
int line             PROTO((int, char **));
int list_buffers     PROTO((int, char **));
int header           PROTO((int, char **));
int list_vectors     PROTO((int, char **));
int load             PROTO((int, char **));
int lookup           PROTO((int, char **));
int mkrgb            PROTO((int, char **));
int mcreate          PROTO((int, char **));
int medacc           PROTO((int, char **));
int mget             PROTO((int, char **));
int minterp          PROTO((int, char **));
int mset             PROTO((int, char **));
int peak             PROTO((int, char **));
int periodogram      PROTO((int, char **));
int plot             PROTO((int, char **));
int dot              PROTO((int, char **));
int point            PROTO((int, char **));
int ps               PROTO((int, char **));
int queuelist        PROTO((int, char **));
int queueload        PROTO((int, char **));
int queueinit        PROTO((int, char **));
int queuedelete      PROTO((int, char **));
int queuedrop        PROTO((int, char **));
int queuepop         PROTO((int, char **));
int queueprint       PROTO((int, char **));
int queuepush        PROTO((int, char **));
int queuesubstr      PROTO((int, char **));
int queuesize        PROTO((int, char **));
int rd               PROTO((int, char **));
int rdseg            PROTO((int, char **));
int read_vectors     PROTO((int, char **));
int rebin            PROTO((int, char **));
int resize           PROTO((int, char **));
int roll             PROTO((int, char **));
int rotate           PROTO((int, char **));
int save             PROTO((int, char **));
int section          PROTO((int, char **));
int set              PROTO((int, char **));
int shift            PROTO((int, char **));
int sort_vectors     PROTO((int, char **));
int spline_apply_cmd PROTO((int, char **));
int spline_construct_cmd PROTO((int, char **));
int stats            PROTO((int, char **));
int style            PROTO((int, char **));
int subraster        PROTO((int, char **));
int subset           PROTO((int, char **));
int svd              PROTO((int, char **));
int swapbytes        PROTO((int, char **));
int textline         PROTO((int, char **));
int tv               PROTO((int, char **));
int tvchannel        PROTO((int, char **));
int tvcolors         PROTO((int, char **));
int tvcontour        PROTO((int, char **));
int tvgrid           PROTO((int, char **));
int uniq             PROTO((int, char **));
int unsign           PROTO((int, char **));
int vbin             PROTO((int, char **));
int vclip            PROTO((int, char **));
int vect_select      PROTO((int, char **));
int vgrid            PROTO((int, char **));
int vgauss           PROTO((int, char **));
int vmaxwell         PROTO((int, char **));
int vload            PROTO((int, char **));
int vzload           PROTO((int, char **));
int vstat            PROTO((int, char **));
int vroll            PROTO((int, char **));
int vpop             PROTO((int, char **));
int vsmooth          PROTO((int, char **));
int wd               PROTO((int, char **));
int write_vectors    PROTO((int, char **));
int zap              PROTO((int, char **));
int zplot            PROTO((int, char **));

static Command cmds[] = {  
  {1, "accum",        accum,            "accumulate vector values in another vector"},
  {1, "applyfit",     applyfit,         "apply fit to new vector"},
  {1, "applyfit2d",   applyfit2d,       "apply 2-d fit to new vector"},
  {1, "box",          box,              "draw a box on the plot"},
  {1, "book",         book_command,     "commands to manipulate book/page/word data"},
  {1, "center",       center,           "center image on coords"},
  {1, "circstats",    circstats,        "circular statistics"},
  {1, "clear",        clear,            "erase plot"},
  {1, "clip",         clip,             "clip values in a buffer to be within a range"},
  {1, "close",        close_device,     "close the current display device"},
  {1, "concat",       concat,           "reduce vector dimension"},
  {1, "contour",      contour,          "create contour from image"},
  {1, "create",       create,           "create a new vector"},
  {1, "cumulative",   cumulative,       "build a cumulative histogram from a specific histogram"},
  {1, "cursor",       cursor,           "get coords from cursor"},
  {1, "cut",          cut,              "extract a cut across an image"},
  {1, "datafile",     datafile,         "define file to read vectors"},
  {1, "dbconnect",    dbconnect,        "setup mysql db connection"},
  {1, "dbselect",     dbselect,         "extract vectors from mysql database table"},
  {1, "delete",       delete,           "delete vectors or matrices"},
  {1, "device",       device,           "set / get current graphics device"},
  {1, "dimendown",    dimendown,        "convert matrix to vector"},
  {1, "dimenup",      dimenup,          "convert vector to matrix"},
  {1, "erase",        erase,            "erase objects on an overlay"},
  {1, "extract",      extract,          "extract a portion of a buffer into another buffer"},
  {1, "fft1d",        fft1d,            "fft on the pixel-stream in an image"},
  {1, "fft2d",        fft2d,            "fft on an image"},
  {1, "fit",          fit,              "fit polynomial to vector pair"},
  {1, "fit2d",        fit2d,            "fit 2-d polynomial to vector triplet"},
  {1, "gaussj",       gaussjordan,      "solve Ax = B (N-D)"},
  {1, "gaussdev",     gaussdeviate,     "generate a gaussian deviate vector"},
  {1, "gaussint",     gaussintegral,    "return the integrated gaussian vector"},
  {1, "grid",         grid,             "plot cartesian grid"},
  {1, "gridify",      gridify,          "convert vector triplet to buffer"},
  {1, "grow",         grow,             "grow a mask"},
  {1, "ungridify",    ungridify,        "convert buffer region to vector triplet"},
  {1, "header",       header,           "print buffer header"},
  {1, "histogram",    histogram,        "generate histogram from vector"},
  {1, "imcut",        imcut,            "linear image cut between arbitrary coords"},
  {1, "imhist",       imhist,           "histogram of an image region"},
  {1, "imsmooth",     imsmooth,         "circular gaussian smoothing"},
  {1, "integrate",    integrate,        "integrate a vector"},
  {1, "interpolate",  interpolate,      "interpolate between vector pairs"},
  {1, "jpeg",         jpeg,             "write text line on graph"},
  {1, "png",          jpeg,             "write text line on graph"},
  {1, "ppm",          jpeg,             "write text line on graph"},
  {1, "kern",         kern,             "convolve with 3x3 kernel"},
  {1, "keyword",      keyword,          "extract a FITS keyword from buffer header"},
  {1, "labels",       labels,           "define labels for plot"},
  {1, "limits",       limits,           "define plot limits"},
  {1, "line",         line,             "plot line"},
  {1, "buffers",      list_buffers,     "list the currently allocated buffers"},
  {1, "vectors",      list_vectors,     "list vectors"},
  {1, "load",         load,             "load an SAOimage style overlay"},
  {1, "lookup",       lookup,           "convert vector via lookup table (vector pair)"},
  {1, "mkrgb",        mkrgb,            "convert 3 images to rgb jpeg"},
  {1, "mcreate",      mcreate,          "create a matrix"},
  {1, "medacc",       medacc,           "accumulate vector values in another vector"},
  {1, "mget",         mget,             "extract a vector from a matrix"},
  {1, "minterp",      minterp,          "interpolate image pixels"},
  {1, "mset",         mset,             "insert a vector in a matrix"},
  {1, "peak",         peak,             "find vector peak in range"},
  {1, "periodogram",  periodogram,      "measure periods in unevenly sampled data"},
  {1, "plot",         plot,             "plot a pair of vectors"},
  {1, "dot",          dot,              "plot a single point"},
  {1, "point",        point,            "load overlay with single point"},
  {1, "ps",           ps,               "define labels for plot"},
  {1, "queuepop",     queuepop,         "pop value from queue to variable"},
  {1, "queuedrop",    queuedrop,        "drop values from queue matching a key"},
  {1, "queueprint",   queueprint,       "print the contents of a queue"},
  {1, "queuepush",    queuepush,        "push value onto queue"},
  {1, "queueinit",    queueinit,        "create an empty queue"},
  {1, "queuedelete",  queuedelete,      "delete a queue"},
  {1, "queuelist",    queuelist,        "list defined queues"},
  {1, "queueload",    queueload,        "load queue from command"},
  {1, "queuesubstr",  queuesubstr,      "bulk replace strings in queue"},
  {1, "queuesize",    queuesize,        "show queue size"},
  {1, "rd",           rd,               "load fits image"},
  {1, "rdseg",        rdseg,            "read a segment of an image from a file"},
  {1, "read",         read_vectors,     "read vectors from datafile"},
  {1, "rebin",        rebin,            "rebin data by factor of N"},
  {1, "resize",       resize,           "set graphics/image window size"},
  {1, "roll",         roll,             "roll image to new start point"},
  {1, "rotate",       rotate,           "rotate image"},
  {1, "save",         save,             "save an SAOimage style overlay"},
  {1, "section",      section,          "define section of graph"},
  {1, "set",          set,              "vector math"},
  {1, "shift",        shift,            "shift data in an image"},
  {1, "sort",         sort_vectors,     "sort list of vectors"},
  {1, "spline.apply", spline_apply_cmd, "apply spline fit to generate an image"},
  {1, "spline.const", spline_construct_cmd, "create spline 2nd deriv. terms"},
  {1, "stats",        stats,            "give statistics on a portion of a buffer"},
  {1, "style",        style,            "set the style for graph plots"},
  {1, "subraster",    subraster,        "subraster of fits image"},
  {1, "subset",       subset,           "expand vector dimension"},
  {1, "svd",          svd,              "singular value decomposition of a matrix"},
  {1, "swapbytes",    swapbytes,        "byte swap thing"},
  {1, "textline",     textline,         "write text line on graph"},
  {1, "tv",           tv,               "display an image on the Kii window"},
  {1, "tvchannel",    tvchannel,        "set the current tv channel"},
  {1, "tvcolors",     tvcolors,         "set the tv colormap"},
  {1, "tvcontour",    tvcontour,        "send contour to overlay"},
  {1, "tvgrid",       tvgrid,           "wait until return is typed"},
  {1, "uniq",         uniq,             "create a uniq vector subset from a vector"},
  {1, "unsign",       unsign,           "toggle the UNSIGN status"},
  {1, "vbin",         vbin,             "bin values in a vector to be within a range"},
  {1, "vclip",        vclip,            "clip values in a vector to be within a range"},
  {1, "select",       vect_select,      "selective vector assignment"},
  {1, "vgauss",       vgauss,           ""},
  {1, "vmaxwell",     vmaxwell,         ""},
  {1, "vgrid",        vgrid,            ""},
  {1, "vload",        vload,            "load vectors on Kii"},
  {1, "vzload",       vzload,           "load vectors on Kii"},
  {1, "vstat",        vstat,            "get info from imreg database"},
  {1, "vsmooth",      vsmooth,          "gaussian smooth of a vector"},
  {1, "vroll",        vroll,            "roll vector elements"},
  {1, "vpop",         vpop,             "remove first element"},
  {1, "wd",           wd,               "write an image to a file"},
  {1, "write",        write_vectors,    "write vectors to datafile"},
  {1, "zap",          zap,              "delete pixels"},
  {1, "zplot",        zplot,            "plot x y with size scaled by z"},
}; 

void InitData () {
  
  int i;

  InitKapa ();
  InitQueues ();
  InitBooks ();

  for (i = 0; i < sizeof (cmds) / sizeof (Command); i++) {
    AddCommand (&cmds[i]);
  }
}

void FreeData () {

  FreeKapa ();
  FreeQueues ();
  FreeBooks ();
}
