IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13479


Ignore:
Timestamp:
May 22, 2007, 12:23:09 PM (19 years ago)
Author:
eugene
Message:

upgrading to kapa 2.0 API, upgrades to dvo user interface

Location:
trunk/Ohana
Files:
21 added
159 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/Makefile.in

    r12859 r13479  
    3737imclean     \
    3838imregister  \
    39 kapa        \
    40 kii         \
     39kapa2       \
    4140misc        \
    4241mosastro    \
     
    9695mana:
    9796        make libs
    98         make kii.install
    99         make kapa.install
     97        make kapa2.install
    10098        cd src/opihi; make mana.install && exit
    10199
    102100dvoshell:
    103101        make libs
    104         make kii.install
    105         make kapa.install
     102        make kapa2.install
    106103        cd src/opihi; make dvo.install && exit
    107104
  • trunk/Ohana/src/addstar/src/SEDops.c

    r8361 r13479  
    111111  graphdata.style = 2;
    112112  graphdata.ptype = 2;
    113   KapaClear (Xgraph, TRUE);
     113  KapaClearSections (Xgraph);
    114114  magSection.name = strcreate ("mag");
    115115  magSection.x  = 0;
     
    141141
    142142  int j, minRow, Nfilter;
    143   double X, Y;
     143  double X, Y, Z, RA, DEC;
    144144  char line[1024], key[20];
    145145
     
    156156  SWAP (graphdata.ymin, graphdata.ymax);
    157157
    158   KapaClear (Xgraph, TRUE);
     158  KapaClearSections (Xgraph);
    159159  KapaSetSection (Xgraph, &magSection);
    160160  KapaSetLimits (Xgraph, &graphdata);
     
    164164  graphdata.ptype = 7;
    165165  KapaPrepPlot (Xgraph, Nfilter, &graphdata);
    166   KapaPlotVector (Xgraph, Nfilter, table[0].wavecode);
    167   KapaPlotVector (Xgraph, Nfilter, fitmags);
     166  KapaPlotVector (Xgraph, Nfilter, table[0].wavecode, "x");
     167  KapaPlotVector (Xgraph, Nfilter, fitmags, "y");
    168168
    169169  graphdata.color = KapaColorByName ("red");
     
    178178  }
    179179  KapaPrepPlot (Xgraph, Nfilter, &graphdata);
    180   KapaPlotVector (Xgraph, Nfilter, table[0].wavecode);
    181   KapaPlotVector (Xgraph, Nfilter, fitmags);
    182   KapaPlotVector (Xgraph, Nfilter, fiterrs);
    183   KapaPlotVector (Xgraph, Nfilter, fiterrs);
     180  KapaPlotVector (Xgraph, Nfilter, table[0].wavecode, "x");
     181  KapaPlotVector (Xgraph, Nfilter, fitmags, "x");
     182  KapaPlotVector (Xgraph, Nfilter, fiterrs, "dym");
     183  KapaPlotVector (Xgraph, Nfilter, fiterrs, "dyp");
    184184  KapaSendLabel (Xgraph, "model,fit (mags)", 1);
    185185
     
    208208  }
    209209  KapaPrepPlot (Xgraph, Nfilter, &graphdata);
    210   KapaPlotVector (Xgraph, Nfilter, table[0].wavecode);
    211   KapaPlotVector (Xgraph, Nfilter, fitmags);
    212   KapaPlotVector (Xgraph, Nfilter, fiterrs);
    213   KapaPlotVector (Xgraph, Nfilter, fiterrs);
     210  KapaPlotVector (Xgraph, Nfilter, table[0].wavecode, "x");
     211  KapaPlotVector (Xgraph, Nfilter, fitmags, "y");
     212  KapaPlotVector (Xgraph, Nfilter, fiterrs, "dym");
     213  KapaPlotVector (Xgraph, Nfilter, fiterrs, "dyp");
    214214  KapaSendLabel (Xgraph, "wavelength (nm)", 0);
    215215  KapaSendLabel (Xgraph, "resid (mags)", 1);
    216216
    217217  KiiCursorOn (Xgraph);
    218   while (KiiCursorRead (Xgraph, &X, &Y, key)) {
     218  while (KiiCursorRead (Xgraph, &X, &Y, &Z, &RA, &DEC, key)) {
    219219    // fprintf (stderr, "window: %f %f (%s)\n", X, Y, key);
    220220    if (!strcasecmp (key, "Q")) {
  • trunk/Ohana/src/gastro/Makefile

    r12842 r13479  
    1515FULL_CFLAGS   = $(BASE_CFLAGS)
    1616FULL_CPPFLAGS = $(BASE_CPPFLAGS)
    17 FULL_LDFLAGS  = -ldvo -lFITS -lohana $(BASE_LDFLAGS)
     17FULL_LDFLAGS  = -lkapa -ldvo -lFITS -lohana $(BASE_LDFLAGS)
    1818
    1919gastro: $(BIN)/gastro.$(ARCH)
  • trunk/Ohana/src/gastro/src/plotstuff.c

    r12332 r13479  
    1313int open_graph (int N) {
    1414
    15 # ifdef ANSI
    16 #   define F_SETFL      4   
    17 #   define O_NONBLOCK 0200000 
    18 #   define       AF_UNIX         1         
    19 #   define       SOCK_STREAM     1         
    20 #define ENOENT          2       /* No such file or directory    */
    21 # endif /* ANSI */
    22 
    23   int InitSocket, status;
    24   socklen_t addreslen;
    25   struct sockaddr_un Address;
    26   char temp[100];
    27   char socket_name[100];
     15  char name[100];
    2816 
    2917  active = N;
    30   sprintf (socket_name, "/tmp/kapa%d", N);
    31   sprintf (temp, "rm -f %s", socket_name);
    32   system (temp);
    33    
    34   strcpy (Address.sun_path, socket_name);
    35   Address.sun_family = AF_UNIX;
    36   InitSocket = socket (AF_UNIX, SOCK_STREAM, 0);
    37   status = bind (InitSocket, (struct sockaddr *) &Address, sizeof (Address));
    38   status = listen (InitSocket, 1);
    39  
    40   sprintf (temp, "kapa %s &", socket_name);
    41 # ifndef DEBUG
    42   system (temp);
    43 # else 
    44   fprintf (stderr, "start kapa, press return: %s\n", temp);
    45   fscanf (stdin, "%d", &i);
    46 # endif
    47  
    48   addreslen =  sizeof (Address);
    49   Xgraph[N] = accept (InitSocket, (struct sockaddr *) &Address, &addreslen);
     18
     19  sprintf (name, "gastro [%d]", N);
     20  Xgraph[N] = KapaOpen ("kapa", name);
     21
    5022  if (Xgraph[N] < 0) {
    5123    fprintf (stderr, "error starting kapa\n");
    5224    return (FALSE);
    5325  }
    54   else {
    55     return (TRUE);
    56   }
    57  
     26  return (TRUE);
    5827}
    5928
    6029void DonePlotting (Graphdata *graphmode, int N) {
    61   char buffer[65], buffer2[65];
    6230
    63   write (Xgraph[N], "DBOX", 4);
    64   sprintf (buffer, "%f %f %f %f ", graphmode[0].xmin, graphmode[0].xmax, graphmode[0].ymin, graphmode[0].ymax);
    65   sprintf (buffer2, "NBYTES: %6d ", (unsigned int) strlen (buffer));
    66   write (Xgraph[N], buffer2, 16);
    67   write (Xgraph[N], buffer, strlen (buffer));
    68 
    69   sprintf (buffer, "%s %s %s", "2222", "2222", "2222");
    70   sprintf (buffer2, "NBYTES: %6d ", (unsigned int) strlen (buffer));
    71   write (Xgraph[N], buffer2, 16);
    72   write (Xgraph[N], buffer, strlen (buffer));
     31  if (Xgraph[N] == 0) return;
     32  KapaBox (Xgraph[N], graphmode);
     33  return;
    7334}
    7435
    7536void PrepPlotting (int Npts, Graphdata *graphmode, int N) {
    7637
    77   int i, status;
    78   char buffer[128], buffer2[128];
     38  if (Xgraph[N] == 0) return;
    7939
    8040  active = N;
    8141  if (Npts < 1) return;
    8242
    83   /* test Xgraph[N], flush junk from pipe */
    84   signal (SIGPIPE, XDead);
    85   fcntl (Xgraph[N], F_SETFL,  O_NONBLOCK);
    86   for (i = 0; (read (Xgraph[N], buffer, 64) > 0) && (i < 20); i++);
    87   fcntl (Xgraph[N], F_SETFL, !O_NONBLOCK);
    88  
    89   if (Xgraph[N] < 1) if (!open_graph(N)) return;
    90  
    91   /* tell kapa to look for the incoming image */
    92   status = write (Xgraph[N], "PLOT", 4);
    93 
    94   /* send Xgraph[N] the plot details */
    95   sprintf (buffer, "%8d %8d %d %d %d %d %f %f ",
    96            Npts, graphmode[0].style,
    97            graphmode[0].ptype, graphmode[0].ltype,
    98            graphmode[0].etype, graphmode[0].color,
    99            graphmode[0].lweight, graphmode[0].size);
    100   sprintf (buffer2, "NBYTES: %6d ", (unsigned int) strlen (buffer));
    101   write (Xgraph[N], buffer2, 16);
    102   write (Xgraph[N], buffer, strlen (buffer));
    103  
    104   sprintf (buffer, "%f %f %f %f ",
    105            graphmode[0].xmin, graphmode[0].xmax,
    106            graphmode[0].ymin, graphmode[0].ymax);
    107   sprintf (buffer2, "NBYTES: %6d ", (unsigned int) strlen (buffer));
    108   write (Xgraph[N], buffer2, 16);
    109   write (Xgraph[N], buffer, strlen (buffer));
    110 
     43  KapaPrepPlot (Xgraph[N], Npts, graphmode);
    11144}
    11245
     
    11649
    11750  if (Npts < 1) return;
    118 
    11951  active = N;
    120   Nbytes = Npts * sizeof (float);
    121   write (Xgraph[N], vect, Nbytes);
    122 
     52  KapaPlotVector (Xgraph[N], Npts, vect);
    12353}
    12454
     
    13565 
    13666  if (Xgraph[N] < 1) if (!open_graph(N)) return;
    137  
    138   write (Xgraph[N], "ERAS", 4);
     67  KapaClearSections (Xgraph[N]);
     68}
    13969
    140 }
    14170/* include these lines to plot a pair of vectors:
    14271
  • trunk/Ohana/src/gastro2/Makefile

    r12842 r13479  
    1515FULL_CFLAGS   = $(BASE_CFLAGS)
    1616FULL_CPPFLAGS = $(BASE_CPPFLAGS)
    17 FULL_LDFLAGS  = -ldvo -lFITS -lohana $(BASE_LDFLAGS)
     17FULL_LDFLAGS  = -lkapa -ldvo -lFITS -lohana $(BASE_LDFLAGS)
    1818
    1919gastro2: $(BIN)/gastro2.$(ARCH)
  • trunk/Ohana/src/gastro2/src/plotstuff.c

    r12332 r13479  
    1313int open_graph (int N) {
    1414
    15 # ifdef ANSI
    16 #   define F_SETFL      4   
    17 #   define O_NONBLOCK 0200000 
    18 #   define       AF_UNIX         1         
    19 #   define       SOCK_STREAM     1         
    20 #define ENOENT          2       /* No such file or directory    */
    21 # endif /* ANSI */
    22 
    23   int InitSocket, status;
    24   socklen_t addreslen;
    25   struct sockaddr_un Address;
    26   char temp[100];
    27   char socket_name[100];
     15  char name[100];
    2816 
    2917  active = N;
    30   sprintf (socket_name, "/tmp/kapa%d", N);
    31   sprintf (temp, "rm -f %s", socket_name);
    32   system (temp);
    33    
    34   strcpy (Address.sun_path, socket_name);
    35   Address.sun_family = AF_UNIX;
    36   InitSocket = socket (AF_UNIX, SOCK_STREAM, 0);
    37   status = bind (InitSocket, (struct sockaddr *) &Address, sizeof (Address));
    38   status = listen (InitSocket, 1);
    39  
    40   sprintf (temp, "kapa %s -name %d &", socket_name, N);
    41 # ifndef DEBUG
    42   system (temp);
    43 # else 
    44   fprintf (stderr, "start kapa, press return: %s\n", temp);
    45   fscanf (stdin, "%d", &i);
    46 # endif
    47  
    48   addreslen =  sizeof (Address);
    49   Xgraph[N] = accept (InitSocket, (struct sockaddr *) &Address, &addreslen);
     18
     19  sprintf (name, "gastro [%d]", N);
     20  Xgraph[N] = KapaOpen ("kapa", name);
     21
    5022  if (Xgraph[N] < 0) {
    5123    fprintf (stderr, "error starting kapa\n");
    5224    return (FALSE);
    5325  }
    54   else {
    55     return (TRUE);
    56   }
    57  
     26  return (TRUE);
    5827}
    5928
    6029void DonePlotting (Graphdata *graphmode, int N) {
    61   char buffer[65], buffer2[65];
    6230
    63   write (Xgraph[N], "DBOX", 4);
    64   sprintf (buffer, "%f %f %f %f", graphmode[0].xmin, graphmode[0].xmax, graphmode[0].ymin, graphmode[0].ymax);
    65   sprintf (buffer2, "NBYTES: %6d", (unsigned int) strlen (buffer));
    66   write (Xgraph[N], buffer2, 16);
    67   write (Xgraph[N], buffer, strlen (buffer));
    68 
    69   sprintf (buffer, "%s %s %s", "2222", "2222", "2222");
    70   sprintf (buffer2, "NBYTES: %6d", (unsigned int) strlen (buffer));
    71   write (Xgraph[N], buffer2, 16);
    72   write (Xgraph[N], buffer, strlen (buffer));
     31  if (Xgraph[N] == 0) return;
     32  KapaBox (Xgraph[N], graphmode);
     33  return;
    7334}
    7435
    7536void PrepPlotting (int Npts, Graphdata *graphmode, int N) {
    7637
    77   int i, status;
    78   char buffer[128], buffer2[128];
     38  if (Xgraph[N] == 0) return;
    7939
    8040  active = N;
    8141  if (Npts < 1) return;
    8242
    83   /* test Xgraph[N], flush junk from pipe */
    84   signal (SIGPIPE, XDead);
    85   fcntl (Xgraph[N], F_SETFL,  O_NONBLOCK);
    86   for (i = 0; (read (Xgraph[N], buffer, 64) > 0) && (i < 20); i++);
    87   fcntl (Xgraph[N], F_SETFL, !O_NONBLOCK);
    88  
    89   if (Xgraph[N] < 1) if (!open_graph(N)) return;
    90  
    91   /* tell kapa to look for the incoming image */
    92   status = write (Xgraph[N], "PLOT", 4);
    93 
    94   /* send Xgraph[N] the plot details */
    95   sprintf (buffer, "%8d %8d %d %d %d %d %d %f %f",
    96            Npts, graphmode[0].style,
    97            graphmode[0].ptype, graphmode[0].ltype,
    98            graphmode[0].etype, graphmode[0].ebar, graphmode[0].color,
    99            graphmode[0].lweight, graphmode[0].size);
    100   sprintf (buffer2, "NBYTES: %6d", (unsigned int) strlen (buffer));
    101   write (Xgraph[N], buffer2, 16);
    102   write (Xgraph[N], buffer, strlen (buffer));
    103  
    104   sprintf (buffer, "%f %f %f %f",
    105            graphmode[0].xmin, graphmode[0].xmax,
    106            graphmode[0].ymin, graphmode[0].ymax);
    107   sprintf (buffer2, "NBYTES: %6d", (unsigned int) strlen (buffer));
    108   write (Xgraph[N], buffer2, 16);
    109   write (Xgraph[N], buffer, strlen (buffer));
    110 
     43  KapaPrepPlot (Xgraph[N], Npts, graphmode);
    11144}
    11245
     
    11649
    11750  if (Npts < 1) return;
    118 
    11951  active = N;
    120   Nbytes = Npts * sizeof (float);
    121   write (Xgraph[N], vect, Nbytes);
    122 
     52  KapaPlotVector (Xgraph[N], Npts, vect);
    12353}
    12454
     
    13565 
    13666  if (Xgraph[N] < 1) if (!open_graph(N)) return;
    137  
    138   write (Xgraph[N], "ERAS", 4);
     67  KapaClearSections (Xgraph[N]);
     68}
    13969
    140 }
    14170/* include these lines to plot a pair of vectors:
    14271
  • trunk/Ohana/src/kapa2/Makefile

    r13333 r13479  
    1 default: kapa2
     1default: kapa
    22help:
    33        @echo "make options: kapa (default)"
     
    2020INDEPS  = $(DESTINC)/kapa.h $(DESTINC)/dvo.h $(DESTINC)/gfitsio.h $(DESTINC)/ohana.h
    2121
    22 kapa2: $(BIN)/kapa2.$(ARCH)
    23 install: $(DESTBIN)/kapa2
     22kapa2: $(BIN)/kapa.$(ARCH)
     23install: $(DESTBIN)/kapa
    2424
    2525KAPA = \
     
    4949$(SRC)/Graphs.$(ARCH).o                   $(SRC)/SetGraphSize.$(ARCH).o       \
    5050$(SRC)/Resize.$(ARCH).o                   $(SRC)/ErasePlots.$(ARCH).o         \
     51$(SRC)/EraseImage.$(ARCH).o               $(SRC)/SetToolbox.$(ARCH).o         \
    5152$(SRC)/EraseCurrentPlot.$(ARCH).o         $(SRC)/EraseSections.$(ARCH).o      \
    5253$(SRC)/SetSection.$(ARCH).o               $(SRC)/DefineSection.$(ARCH).o      \
     
    6465$(SRC)/CreatePicture.$(ARCH).o            $(SRC)/CreateColorbar.$(ARCH).o     \
    6566$(SRC)/MakeColormap.$(ARCH).o             $(SRC)/SetColormap.$(ARCH).o        \
    66 $(SRC)/PaintOverlay.$(ARCH).o             $(SRC)/PaintTickmarks.$(ARCH).o     \
     67$(SRC)/PaintOverlay.$(ARCH).o             $(SRC)/SetGraphData.$(ARCH).o       \
    6768$(SRC)/LoadOverlay.$(ARCH).o              $(SRC)/EraseOverlay.$(ARCH).o       \
    68 $(SRC)/LoadTickmarks.$(ARCH).o            $(SRC)/SaveOverlay.$(ARCH).o        \
     69$(SRC)/SaveOverlay.$(ARCH).o              $(SRC)/SetImageData.$(ARCH).o       \
    6970$(SRC)/CSaveOverlay.$(ARCH).o             $(SRC)/EraseOverlay.$(ARCH).o       \
    7071$(SRC)/CheckVisual.$(ARCH).o              $(SRC)/CursorOps.$(ARCH).o          \
     
    8889$(OBJ): $(INDEPS) $(LDDEPS)
    8990
    90 $(BIN)/kapa2.$(ARCH): $(OBJ)
     91$(BIN)/kapa.$(ARCH): $(OBJ)
  • trunk/Ohana/src/kapa2/include/constants.h

    r13320 r13479  
    1010 | PointerMotionMask)
    1111
    12 # define PAD1  5
    13 # define PAD2  3
     12# define PAD1  3
     13# define PAD2  5
    1414# define TEXTPAD 25
    1515# define COLORPAD 10
    1616# define TEXT_Y 15
    17 # define ZOOM_X 170
    18 # define ZOOM_Y 170
     17# define ZOOM_X 152
     18# define ZOOM_Y 152
    1919# define NOVERLAYS 4
    2020# define BUTTON_WIDTH 28
  • trunk/Ohana/src/kapa2/include/globals.h

    r13333 r13479  
    1515
    1616/* file descriptor for socket connection to mana */
    17 int sock;
     17// int sock;
    1818
    1919/* each layout / section defines one of the active portions of the graphics window
  • trunk/Ohana/src/kapa2/include/prototypes.h

    r13333 r13479  
    3939
    4040/* EventLoop */
    41 int           PScommand           PROTO(());
     41int           PScommand           PROTO((int sock));
    4242int           CheckPipe           PROTO(());
    4343int           Reconfig            PROTO((XEvent *event));
     
    4545
    4646/* CheckPipe */
    47 int           PNGit               PROTO(());
    48 int           PPMit               PROTO(());
    49 int           LoadFrame           PROTO(());
    50 int           LoadObject          PROTO(());
    51 int           LoadLabels          PROTO(());
    52 int           LoadTextlines       PROTO(());
    53 int           LoadVectorData      PROTO(());
    54 int           Resize              PROTO(());
    55 int           GetLimits           PROTO(());
    56 int           SetLimits           PROTO(());
    57 int           SetSection          PROTO(());
    58 int           ListSection         PROTO(());
    59 int           DefineSection       PROTO(());
    60 int           SetFont             PROTO(());
    61 int           EraseCurrentPlot    PROTO(());
    62 int           ErasePlots          PROTO(());
    63 int           EraseSections       PROTO(());
     47int           PNGit               PROTO((int sock));
     48int           PPMit               PROTO((int sock));
     49int           LoadFrame           PROTO((int sock));
     50int           LoadObject          PROTO((int sock));
     51int           LoadLabels          PROTO((int sock));
     52int           LoadTextlines       PROTO((int sock));
     53int           Resize              PROTO((int sock));
     54int           GetLimits           PROTO((int sock));
     55int           SetLimits           PROTO((int sock));
     56int           SetSection          PROTO((int sock));
     57int           ListSection         PROTO((int sock));
     58int           MoveSection         PROTO((int sock));
     59int           DefineSection       PROTO((int sock));
     60int           SetFont             PROTO((int sock));
     61int           EraseCurrentPlot    PROTO((void));
     62int           ErasePlots          PROTO((void));
     63int           EraseSections       PROTO((void));
     64int           EraseImage          PROTO((void));
     65int           SetGraphData        PROTO((int sock));
     66int           GetGraphData        PROTO((int sock));
     67int           SetImageData        PROTO((int sock));
     68int           GetImageData        PROTO((int sock));
     69
     70int           LoadVectorData      PROTO((int sock, KapaGraphWidget *graph, int N, char *type));
    6471
    6572/* Section Utilities */
     
    7481Section      *GetActiveSection    PROTO(());
    7582int           SetActiveSectionByNumber PROTO((int N));
    76 int           ListSection         PROTO(());
     83int           ListSection         PROTO((int sock));
    7784
    7885KapaGraphWidget *InitGraph        PROTO(());
    7986void          DrawGraph           PROTO((KapaGraphWidget *graph));
    8087void          SetGraphSize        PROTO((Section *section));
     88void          FreeGraph           PROTO((KapaGraphWidget *graph));
    8189
    8290void          InitLayout          PROTO((int argc, char **argv));
     
    124132void          QuitX               PROTO((Display *display, char *message));
    125133Graphic      *GetGraphic          PROTO(());
     134int           GetPixelCount       PROTO((int sock));
    126135
    127136int           Center              PROTO(());
     
    131140void          Remap24             PROTO((Graphic *graphic, KapaImageWidget *image, Matrix *matrix));
    132141void          Remap32             PROTO((Graphic *graphic, KapaImageWidget *image, Matrix *matrix));
    133 int           LoadPicture         PROTO(());
     142int           LoadPicture         PROTO((int sock));
     143
    134144KapaImageWidget *InitImage        PROTO(());
     145void          FreeImage           PROTO((KapaImageWidget *image));
    135146void          SetImageSize        PROTO((Section *section));
    136 int           GetPixelCount       PROTO(());
     147
    137148void          InitButtonSize      PROTO((Button *button, int width, int height, char *bitmap));
    138149void          InitButtonFunc      PROTO((Button *button, int (*function)()));
  • trunk/Ohana/src/kapa2/include/structures.h

    r13320 r13479  
    9595  int Nobjects;
    9696  unsigned long color;
    97   Object *objects;
     97  KiiOverlay *objects;
    9898} Overlay;
    9999 
     
    116116  Axis      axis[4];    /* coordinate axes */
    117117  Label     label[8];   /* fixed axis labels */
     118  Graphdata data;       /* current graph data */
    118119
    119120  Gobjects *objects;    /* graphic objects */   
     
    138139  Button   grey_button;
    139140  Button   rainbow_button;
    140   Button   puns_button;
     141  Button    puns_button;
    141142  Button   overlay_button[NOVERLAYS];
    142143
    143144  // location of the status box
    144145  int      text_x, text_y;
     146  int      text_dx, text_dy;
    145147  int      location;          // position of the zoom/status widgets (0 = none, 1-4 = bottom,left,top,right)
    146148  int      MovePointer;
     
    159161  Coords   coords;
    160162  char     file[1024];     /* name of file */
    161   char     buffer_name[1024];  /* name of buffer */
     163  char     name[1024];  /* name of buffer */
    162164} KapaImageWidget;
    163165
  • trunk/Ohana/src/kapa2/src/CSaveOverlay.c

    r13320 r13479  
    11# include "Ximage.h"
    22
    3 int CSaveOverlay () {
     3int CSaveOverlay (int sock) {
    44
    5   char filename[256];
     5  char filename[256], *type;
    66  int i, N;
    77  double ra, dec, ra1, dec1, x1, y1, dra, ddec;
     
    1010  KapaImageWidget *image;
    1111
     12  KiiScanMessage (sock, "%*s %d %s", &N, filename);
     13 
    1214  section = GetActiveSection();
    1315  image   = section->image;
     16  if (image == NULL) return (TRUE);
    1417
    15   KiiScanMessage (sock, "%*s %d %s", &N, filename);
    16  
    1718  f = fopen (filename, "w");
    1819  if (f == NULL) {
     
    2223
    2324  for (i = 0; i < image[0].overlay[N].Nobjects; i++) {
    24     if (!strcmp (image[0].overlay[N].objects[i].type, "LINE")) {
     25    if (image[0].overlay[N].objects[i].type == KII_OVERLAY_LINE) {
    2526      XY_to_RD (&ra, &dec, image[0].overlay[N].objects[i].x, image[0].overlay[N].objects[i].y, &image[0].coords);
    2627      x1 = image[0].overlay[N].objects[i].x + image[0].overlay[N].objects[i].dx;
     
    4041      dra = cos (dec*RAD_DEG) * fabs (ra1 - ra);
    4142    }
    42     fprintf (f, "%s %lf %lf %lf %lf\n", image[0].overlay[N].objects[i].type, ra, dec, dra, ddec);
     43    type = KiiOverlayTypeByNumber (image[0].overlay[N].objects[i].type);
     44    if (type == NULL) continue;
     45    fprintf (f, "%s %lf %lf %lf %lf\n", type, ra, dec, dra, ddec);
    4346   }
    4447  fclose (f);
  • trunk/Ohana/src/kapa2/src/Center.c

    r13320 r13479  
    11# include "Ximage.h"
    22
    3 int Center () {
     3int Center (int sock) {
    44
    55  int zoom;
     
    99  KapaImageWidget *image;
    1010
     11  KiiScanMessage (sock, "%lf %lf %d", &X,  &Y, &zoom);
     12
    1113  graphic = GetGraphic();
    1214  section = GetActiveSection();
    1315  image = section->image;
    14 
    15   KiiScanMessage (sock, "%lf %lf %d", &X,  &Y, &zoom);
     16  if (image == NULL) return (TRUE);
    1617
    1718  image[0].X = 0.5*image[0].matrix.Naxis[0] - X;
  • trunk/Ohana/src/kapa2/src/CheckPipe.c

    r13333 r13479  
    22# define STRCONST(A) ((int)(0x1000000*A[0] + 0x10000*A[1] + 0x100*A[2] + 0x1*A[3]))
    33
     4static KapaSockAddress Address;
     5static int InitSocket = -1;
     6static int sock = -1;
     7
     8// we can supply a port here, with only small changes
     9void InitPipe () {
     10  InitSocket = KapaServerInit (&Address);
     11  return;
     12}
     13
     14int GetActiveSocket () {
     15  return (sock);
     16}
     17
     18// after we have processed the command, we unblock the socket
     19# define FINISHED(A) { fcntl (sock, F_SETFL, O_NONBLOCK); return (A); }
     20
    421int CheckPipe () {
    522
    623  int status;
    7   char buffer[32];
     24  char word[5];
     25
     26  // check if we have a valid connection. if not, see if we can get one
     27  if (sock == -1) {
     28    sock = KapaServerWait (InitSocket, &Address);
     29    if (sock == -1) return (TRUE);
     30    close (InitSocket); /* stop listening for new connections */
     31    fcntl (sock, F_SETFL, O_NONBLOCK); 
     32  }
    833
    934  /***** read (4 byte) message word from socket ****/
    10   status = read (sock, buffer, 4);
    11   buffer[4] = 0;
     35  status = read (sock, word, 4);
     36  word[4] = 0;
    1237  switch (status) {
    1338  case -1:                          /* no input from pipe: continue */
     
    2954  }
    3055 
     56  /* once we get a command, we block to ensure we get complete messages */
     57  fcntl (sock, F_SETFL, !O_NONBLOCK); 
     58
    3159  /***** handle different messages ****/
    3260  if (ACTIVE_CURSOR) {
    33     if (strcmp (buffer, "NCUR")) {
    34       fprintf (stderr, "wrong end message %s\n", buffer);
    35       return (TRUE);
     61    if (strcmp (word, "NCUR")) {
     62      fprintf (stderr, "wrong end message %s\n", word);
     63      KiiSendCommand (sock, 4, "DONE");
     64      FINISHED (TRUE);
    3665    }
    3766    ACTIVE_CURSOR = FALSE;
    38     return (TRUE);
     67    KiiSendCommand (sock, 4, "DONE");
     68    FINISHED (TRUE);
    3969  }
    4070
    41   if (!strcmp (buffer, "QUIT")) return (FALSE);
    42  
    43   if (!strcmp (buffer, "CURS")) {
     71  if (!strcmp (word, "QUIT")) FINISHED (FALSE);
     72 
     73  if (!strcmp (word, "CURS")) {
    4474    ACTIVE_CURSOR = TRUE;
    45     return (TRUE);
    46   }
    47  
    48   if (!strcmp (buffer, "PSIT")) {
    49     status = PScommand ();
    50     write (sock, "DONE", 4);
    51     return (status);
    52   }
    53  
    54   if (!strcmp (buffer, "PNGF")) {
    55     status = PNGit ();
    56     write (sock, "DONE", 4);
    57     return (status);
    58   }
    59  
    60   if (!strcmp (buffer, "PPMF")) {
    61     status = PPMit ();
    62     write (sock, "DONE", 4);
    63     return (status);
    64   }
    65  
    66   if (!strcmp (buffer, "DBOX")) {
    67     status = LoadFrame ();
    68     return (status);
    69   }
    70  
    71   if (!strcmp (buffer, "PLOT")) {
    72     status = LoadObject ();
    73     return (status);
    74   }
    75  
    76   if (!strcmp (buffer, "LABL")) {
    77     status = LoadLabels ();
    78     return (TRUE);
    79   }
    80  
    81   if (!strcmp (buffer, "PTXT")) {
    82     status = LoadTextlines ();
    83     return (TRUE);
    84   }
    85  
    86   if (!strcmp (buffer, "RSIZ")) {
    87     status = Resize ();
    88     return (status);
    89   }
    90 
    91   if (!strcmp (buffer, "LIMS")) {
    92     GetLimits ();
    93     return (TRUE);
    94   }
    95  
    96   if (!strcmp (buffer, "SLIM")) {
    97     status = SetLimits ();
    98     return (TRUE);
    99   }
    100  
    101   if (!strcmp (buffer, "SSEC")) {
    102     status = SetSection ();
    103     return (TRUE);
    104   }
    105  
    106   if (!strcmp (buffer, "LSEC")) {
    107     status = ListSection ();
    108     return (TRUE);
    109   }
    110  
    111   if (!strcmp (buffer, "DSEC")) {
    112     status = DefineSection ();
    113     return (TRUE);
    114   }
    115  
    116   if (!strcmp (buffer, "FONT")) {
    117     status = SetFont ();
    118     return (TRUE);
     75    KiiSendCommand (sock, 4, "DONE");
     76    FINISHED (TRUE);
     77  }
     78 
     79  if (!strcmp (word, "PSIT")) {
     80    status = PScommand (sock);
     81    KiiSendCommand (sock, 4, "DONE");
     82    FINISHED (status);
     83  }
     84 
     85  if (!strcmp (word, "PNGF")) {
     86    status = PNGit (sock);
     87    KiiSendCommand (sock, 4, "DONE");
     88    FINISHED (status);
     89  }
     90 
     91  if (!strcmp (word, "PPMF")) {
     92    status = PPMit (sock);
     93    KiiSendCommand (sock, 4, "DONE");
     94    FINISHED (status);
     95  }
     96 
     97  if (!strcmp (word, "DBOX")) {
     98    status = LoadFrame (sock);
     99    KiiSendCommand (sock, 4, "DONE");
     100    FINISHED (status);
     101  }
     102 
     103  if (!strcmp (word, "PLOT")) {
     104    status = LoadObject (sock);
     105    // LoadObject sends its own handshake
     106    // KiiSendCommand (sock, 4, "DONE");
     107    FINISHED (status);
     108  }
     109 
     110  if (!strcmp (word, "LABL")) {
     111    status = LoadLabels (sock);
     112    KiiSendCommand (sock, 4, "DONE");
     113    FINISHED (TRUE);
     114  }
     115 
     116  if (!strcmp (word, "PTXT")) {
     117    status = LoadTextlines (sock);
     118    KiiSendCommand (sock, 4, "DONE");
     119    FINISHED (TRUE);
     120  }
     121 
     122  if (!strcmp (word, "RSIZ")) {
     123    status = Resize (sock);
     124    KiiSendCommand (sock, 4, "DONE");
     125    FINISHED (status);
     126  }
     127
     128  if (!strcmp (word, "GLIM")) {
     129    GetLimits (sock);
     130    KiiSendCommand (sock, 4, "DONE");
     131    FINISHED (TRUE);
     132  }
     133 
     134  if (!strcmp (word, "SLIM")) {
     135    status = SetLimits (sock);
     136    KiiSendCommand (sock, 4, "DONE");
     137    FINISHED (TRUE);
     138  }
     139 
     140  if (!strcmp (word, "GSTY")) {
     141    GetGraphData (sock);
     142    KiiSendCommand (sock, 4, "DONE");
     143    FINISHED (TRUE);
     144  }
     145 
     146  if (!strcmp (word, "SSTY")) {
     147    status = SetGraphData (sock);
     148    KiiSendCommand (sock, 4, "DONE");
     149    FINISHED (TRUE);
     150  }
     151 
     152  if (!strcmp (word, "GIMD")) {
     153    GetImageData (sock);
     154    KiiSendCommand (sock, 4, "DONE");
     155    FINISHED (TRUE);
     156  }
     157 
     158  if (!strcmp (word, "SIMD")) {
     159    status = SetImageData (sock);
     160    KiiSendCommand (sock, 4, "DONE");
     161    FINISHED (TRUE);
     162  }
     163 
     164  if (!strcmp (word, "TOOL")) {
     165    status = SetToolbox (sock);
     166    KiiSendCommand (sock, 4, "DONE");
     167    FINISHED (TRUE);
     168  }
     169 
     170  if (!strcmp (word, "SSEC")) {
     171    status = SetSection (sock);
     172    KiiSendCommand (sock, 4, "DONE");
     173    FINISHED (TRUE);
     174  }
     175 
     176  if (!strcmp (word, "LSEC")) {
     177    status = ListSection (sock);
     178    KiiSendCommand (sock, 4, "DONE");
     179    FINISHED (TRUE);
     180  }
     181 
     182  if (!strcmp (word, "DSEC")) {
     183    status = DefineSection (sock);
     184    KiiSendCommand (sock, 4, "DONE");
     185    FINISHED (TRUE);
     186  }
     187 
     188  if (!strcmp (word, "MSEC")) {
     189    status = MoveSection (sock);
     190    KiiSendCommand (sock, 4, "DONE");
     191    FINISHED (TRUE);
     192  }
     193 
     194  if (!strcmp (word, "FONT")) {
     195    status = SetFont (sock);
     196    KiiSendCommand (sock, 4, "DONE");
     197    FINISHED (TRUE);
    119198  }
    120199 
    121200  /* Erase Section */
    122   if (!strcmp (buffer, "ERSC")) {
    123     status = EraseCurrentPlot (TRUE);
    124     return (status);
    125   }
    126  
    127   /* Erase Section */
    128   if (!strcmp (buffer, "ERAS")) {
    129     status = ErasePlots (TRUE);
    130     return (status);
    131   }
    132  
    133   /* Don't Erase Section */
    134   if (!strcmp (buffer, "ERSS")) {
    135     status = EraseSections (FALSE);
    136     return (status);
    137   }
    138  
    139 
    140   if (!strcmp (buffer, "READ")) {
    141     status = LoadPicture ();
    142     return (status);
    143   }
    144 
    145   // XXX duplicate Command word
    146   if (!strcmp (buffer, "ERAS")) {
    147     status = EraseOverlay ();
    148     return (status);
    149   }
    150 
    151   if (!strcmp (buffer, "LOAD")) {
    152     status = LoadOverlay ();
    153     return (status);
    154   }
    155 
    156   if (!strcmp (buffer, "TICK")) {
    157     status = LoadTickmarks ();
    158     return (status);
    159   }
    160 
    161   if (!strcmp (buffer, "SAVE")) {
    162     status = SaveOverlay ();
    163     return (status);
    164   }
    165 
    166   if (!strcmp (buffer, "CSVE")) {
    167     status = CSaveOverlay ();
    168     return (status);
    169   }
    170 
    171   if (!strcmp (buffer, "JPEG")) {
    172     status = JPEGit24 ();
    173     write (sock, "DONE", 4);
    174     return (status);
    175   }
    176 
    177   if (!strcmp (buffer, "CENT")) {
    178     status = Center ();
    179     return (status);
    180   }
    181 
    182   if (!strcmp (buffer, "NPIX")) {
    183     GetPixelCount ();
    184     return (TRUE);
    185   }
    186 
    187   fprintf (stderr, "unknown signal %s\n", buffer);
    188 
    189   return (TRUE);
    190 
     201  if (!strcmp (word, "ERSC")) {
     202    status = EraseCurrentPlot ();
     203    KiiSendCommand (sock, 4, "DONE");
     204    FINISHED (status);
     205  }
     206 
     207  /* Erase Plots */
     208  if (!strcmp (word, "ERSP")) {
     209    status = ErasePlots ();
     210    KiiSendCommand (sock, 4, "DONE");
     211    FINISHED (status);
     212  }
     213 
     214  /* Erase Sections */
     215  if (!strcmp (word, "ERSS")) {
     216    status = EraseSections ();
     217    KiiSendCommand (sock, 4, "DONE");
     218    FINISHED (status);
     219  }
     220
     221  /* Erase Image */
     222  if (!strcmp (word, "ERSI")) {
     223    status = EraseImage ();
     224    KiiSendCommand (sock, 4, "DONE");
     225    FINISHED (status);
     226  }
     227
     228  /* Erase Overlay for this section */
     229  if (!strcmp (word, "ERSO")) {
     230    status = EraseOverlay (sock);
     231    KiiSendCommand (sock, 4, "DONE");
     232    FINISHED (status);
     233  }
     234
     235  if (!strcmp (word, "READ")) {
     236    status = LoadPicture (sock);
     237    KiiSendCommand (sock, 4, "DONE");
     238    FINISHED (status);
     239  }
     240
     241  if (!strcmp (word, "LOAD")) {
     242    status = LoadOverlay (sock);
     243    KiiSendCommand (sock, 4, "DONE");
     244    FINISHED (status);
     245  }
     246
     247  if (!strcmp (word, "SAVE")) {
     248    status = SaveOverlay (sock);
     249    KiiSendCommand (sock, 4, "DONE");
     250    FINISHED (status);
     251  }
     252
     253  if (!strcmp (word, "CSVE")) {
     254    status = CSaveOverlay (sock);
     255    KiiSendCommand (sock, 4, "DONE");
     256    FINISHED (status);
     257  }
     258
     259  if (!strcmp (word, "JPEG")) {
     260    status = JPEGit24 (sock);
     261    KiiSendCommand (sock, 4, "DONE");
     262    FINISHED (status);
     263  }
     264
     265  if (!strcmp (word, "CENT")) {
     266    status = Center (sock);
     267    KiiSendCommand (sock, 4, "DONE");
     268    FINISHED (status);
     269  }
     270
     271  if (!strcmp (word, "NPIX")) {
     272    GetPixelCount (sock);
     273    KiiSendCommand (sock, 4, "DONE");
     274    FINISHED (TRUE);
     275  }
     276
     277  fprintf (stderr, "unknown signal %s\n", word);
     278  KiiSendCommand (sock, 4, "DONE");
     279  FINISHED (TRUE);
    191280}
  • trunk/Ohana/src/kapa2/src/CheckVisual.c

    r13320 r13479  
    158158    /* make private colormap  */
    159159    if (graphic[0].Npixels < 16) {
    160       fprintf (stderr, "can't allocate enough cells, using private colormap\n");
     160      // fprintf (stderr, "can't allocate enough cells, using private colormap\n");
    161161      graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, AllocNone);
    162162      for (graphic[0].Npixels = NPIXELS;
     
    178178  if (!dyn) {
    179179    graphic[0].Npixels = 256;
    180     fprintf (stderr, "can't use dynamic colors, color scrollbar inactive\n");
    181     fprintf (stderr, " this can be avoided by using a dynamic visual class\n");
    182     fprintf (stderr, " (see Kii help page for details)\n");
     180    // fprintf (stderr, "can't use dynamic colors, color scrollbar inactive\n");
     181    // fprintf (stderr, " this can be avoided by using a dynamic visual class\n");
     182    // fprintf (stderr, " (see Kii help page for details)\n");
    183183  }
    184184
  • trunk/Ohana/src/kapa2/src/CreatePicture.c

    r13320 r13479  
    5656  case 32:
    5757    REALLOCATE (image[0].picture.data, char, (4*image[0].picture.dx*image[0].picture.dy + 32));
    58     fprintf (stderr, "allocating %d for picture data\n", (4*image[0].picture.dx*image[0].picture.dy + 32));
    5958    memset (image[0].picture.data, 0xbd, 4*image[0].picture.dx*image[0].picture.dy + 30);
    6059    l = (unsigned int *) image[0].picture.data;
  • trunk/Ohana/src/kapa2/src/CreateZoom16.c

    r13320 r13479  
    11# include "Ximage.h"
    2 # define XPIX(x,Rx,S) (x*S + Rx)
    3 # define ZPIX(value,Rz1,Rz2) (value*Rz1 - Rz2)
    42# define FRAC(a) ((a) - (int)(a))
     3
     4static float slope = 1.0;
     5static float start = 0.0;
     6static int MaxValue = 255;
     7
     8// XXX inline this if needed
     9static int PixelLookup(float value) {
     10  int out;
     11  out = MIN (MAX (slope * value - start, 0), MaxValue);
     12  return (out);
     13}
    514
    615void CreateZoom16 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
     
    918  int i_start, i_end, j_start, j_end;
    1019  int dropback;  /* this is a bit of a kludge... */
    11   int dx, dy, DX, DY;
     20  int dx, dy, DX, DY, pixelN;
    1221  double expand, zoomscale, Rx, Ry;
    1322  int expand_in, expand_out;
    1423  unsigned char *out_pix, *out_pix2, *data;
    15   unsigned char *in_pix,  *in_pix2;
     24  float *imdata, *in_pix,  *in_pix2;
    1625  unsigned char pixel1[256], pixel2[256];
    1726  unsigned char pixvalue1, pixvalue2;
     
    3746  back1 = 0x0000ff & back;
    3847  back2 = 0x0000ff & (back >> 8);
     48  // define the color transform parameters
     49  MaxValue = graphic[0].Npixels - 1;
     50  if (image[0].range != 0.0) {
     51    slope = graphic[0].Npixels / image[0].range;
     52    start = graphic[0].Npixels * image[0].zero / image[0].range;
     53  } else {
     54    slope = 1.0;
     55    start = image[0].zero;
     56  }
    3957
    4058  zoomscale = MAX (5, image[0].expand + 5);
     
    5674
    5775  data = out_pix = (unsigned char *) image[0].zoom.data;
    58   in_pix  = (unsigned char *) (image[0].matrix.buffer) + DX*(int)MAX(Ry,0) + (int)MAX(Rx,0);
     76  imdata  = (float *) image[0].matrix.buffer;
     77  in_pix  = &imdata[DX*(int)MAX(Ry,0) + (int)MAX(Rx,0)];
    5978
    6079  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    91110    if (expand_out == 1) {
    92111      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=2) {
    93         out_pix[0] = pixel1[*in_pix2];
    94         out_pix[1] = pixel2[*in_pix2];
     112        pixelN = PixelLookup(*in_pix2);
     113        out_pix[0] = pixel1[pixelN];
     114        out_pix[1] = pixel2[pixelN];
    95115      }
    96     }
    97     else {
     116    } else {
    98117      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 2*expand_out) {
    99         pixvalue1 = pixel1[*in_pix2];
    100         pixvalue2 = pixel2[*in_pix2];
     118        pixelN = PixelLookup(*in_pix2);
     119        pixvalue1 = pixel1[pixelN];
     120        pixvalue2 = pixel2[pixelN];
    101121        out_pix2 = out_pix;
    102122        for (jj = 0; jj < expand_out; jj++, out_pix2+=2*(dx-expand_out)) {
     
    129149  }
    130150
    131   image[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, 16, ZPixmap, 0,
    132                                         image[0].zoom.data, image[0].zoom.dx, image[0].zoom.dy, 32, 0);
     151  image[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0,
     152                                        image[0].zoom.data, image[0].zoom.dx, image[0].zoom.dy, 16, 0);
    133153 
    134154}
  • trunk/Ohana/src/kapa2/src/CreateZoom24.c

    r13320 r13479  
    11# include "Ximage.h"
    2 # define XPIX(x,Rx,S) (x*S + Rx)
    3 # define ZPIX(value,Rz1,Rz2) (value*Rz1 - Rz2)
    42# define FRAC(a) ((a) - (int)(a))
     3
     4static float slope = 1.0;
     5static float start = 0.0;
     6static int MaxValue = 255;
     7
     8// XXX inline this if needed
     9static int PixelLookup(float value) {
     10  int out;
     11  out = MIN (MAX (slope * value - start, 0), MaxValue);
     12  return (out);
     13}
    514
    615void CreateZoom24 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
     
    918  int i_start, i_end, j_start, j_end;
    1019  int dropback;  /* this is a bit of a kludge... */
    11   int dx, dy, DX, DY;
     20  int dx, dy, DX, DY, pixelN;
    1221  double expand, zoomscale, Rx, Ry;
    1322  int expand_in, expand_out;
    1423  unsigned char *out_pix, *out_pix2, *data;
    15   unsigned char *in_pix, *in_pix2;
     24  float *imdata, *in_pix, *in_pix2;
    1625  unsigned char pixel1[256], pixel2[256], pixel3[256];
    1726  unsigned char pixvalue1, pixvalue2, pixvalue3;
     
    4150  back3 = 0x0000ff & (back >> 16);
    4251
     52  // define the color transform parameters
     53  MaxValue = graphic[0].Npixels - 1;
     54  if (image[0].range != 0.0) {
     55    slope = graphic[0].Npixels / image[0].range;
     56    start = graphic[0].Npixels * image[0].zero / image[0].range;
     57  } else {
     58    slope = 1.0;
     59    start = image[0].zero;
     60  }
     61
    4362  zoomscale = MAX (5, image[0].expand + 5);
    4463  expand = 1 / zoomscale;
     
    5978
    6079  data = out_pix = (unsigned char *) image[0].zoom.data;
    61   in_pix  = (unsigned char *) (image[0].matrix.buffer) + DX*(int)MAX(Ry,0) + (int)MAX(Rx,0);
     80  imdata  = (float *) image[0].matrix.buffer;
     81  in_pix  = &imdata[DX*(int)MAX(Ry,0) + (int)MAX(Rx,0)];
    6282
    6383  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    97117    if (expand_out == 1) {
    98118      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=3) {
    99         out_pix[0] = pixel1[*in_pix2];
    100         out_pix[1] = pixel2[*in_pix2];
    101         out_pix[2] = pixel3[*in_pix2];
     119        pixelN = PixelLookup(*in_pix2);
     120        out_pix[0] = pixel1[pixelN];
     121        out_pix[1] = pixel2[pixelN];
     122        out_pix[2] = pixel3[pixelN];
    102123      }
    103     }
    104     else {
     124    } else {
    105125      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 3*expand_out) {
    106         pixvalue1 = pixel1[*in_pix2];
    107         pixvalue2 = pixel2[*in_pix2];
    108         pixvalue3 = pixel3[*in_pix2];
     126        pixelN   = PixelLookup(*in_pix2);
     127        pixvalue1 = pixel1[pixelN];
     128        pixvalue2 = pixel2[pixelN];
     129        pixvalue3 = pixel3[pixelN];
    109130        out_pix2 = out_pix;
    110131        for (jj = 0; jj < expand_out; jj++, out_pix2+=3*(dx-expand_out)+extra) {
  • trunk/Ohana/src/kapa2/src/CreateZoom32.c

    r13320 r13479  
    11# include "Ximage.h"
    2 # define XPIX(x,Rx,S) (x*S + Rx)
    3 # define ZPIX(value,Rz1,Rz2) (value*Rz1 - Rz2)
    42# define FRAC(a) ((a) - (int)(a))
     3
     4static float slope = 1.0;
     5static float start = 0.0;
     6static int MaxValue = 255;
     7
     8// XXX inline this if needed
     9static int PixelLookup(float value) {
     10  int out;
     11  out = MIN (MAX (slope * value - start, 0), MaxValue);
     12  return (out);
     13}
    514
    615void CreateZoom32 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
     
    918  int i_start, i_end, j_start, j_end;
    1019  int dropback;  /* this is a bit of a kludge... */
    11   int dx, dy, DX, DY;
     20  int dx, dy, DX, DY, pixelN;
    1221  double expand, zoomscale, Rx, Ry;
    1322  int expand_in, expand_out;
    14   unsigned int *out_pix, *out_pix2, *data;
    15   unsigned char  *in_pix, *in_pix2;
     23  unsigned int *out_pix, *out_pix2;
     24  float *imdata, *in_pix, *in_pix2;
    1625  unsigned long pixel[256], pixvalue;
    1726  unsigned long back;
     
    2837  }
    2938  back = graphic[0].back;
     39
     40  // define the color transform parameters
     41  MaxValue = graphic[0].Npixels - 1;
     42  if (image[0].range != 0.0) {
     43    slope = graphic[0].Npixels / image[0].range;
     44    start = graphic[0].Npixels * image[0].zero / image[0].range;
     45  } else {
     46    slope = 1.0;
     47    start = image[0].zero;
     48  }
    3049
    3150  zoomscale = MAX (5, image[0].expand + 5);
     
    4968
    5069  out_pix = (unsigned int *) image[0].zoom.data;
    51   data = (unsigned int *) image[0].zoom.data;
    52   in_pix  = (unsigned char *) (image[0].matrix.buffer) + DX*(int)MAX(Ry,0) + (int)MAX(Rx,0);
     70  imdata  = (float *) image[0].matrix.buffer;
     71  in_pix  = &imdata[DX*(int)MAX(Ry,0) + (int)MAX(Rx,0)];
    5372
    5473  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    81100    if (expand_out == 1) {
    82101      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
    83         out_pix[0] = pixel[*in_pix2];
     102        pixelN = PixelLookup(*in_pix2);
     103        out_pix[0] = pixel[pixelN];
    84104      }
    85105    }
    86106    else {
    87107      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) {
    88         pixvalue = *(pixel + *in_pix2);
     108        pixelN   = PixelLookup(*in_pix2);
     109        pixvalue = pixel[pixelN];
    89110        out_pix2 = out_pix;
    90111        for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
  • trunk/Ohana/src/kapa2/src/CreateZoom8.c

    r13320 r13479  
    11# include "Ximage.h"
    2 # define XPIX(x,Rx,S) (x*S + Rx)
    3 # define ZPIX(value,Rz1,Rz2) (value*Rz1 - Rz2)
    42# define FRAC(a) ((a) - (int)(a))
     3
     4static float slope = 1.0;
     5static float start = 0.0;
     6static int MaxValue = 255;
     7
     8// XXX inline this if needed
     9static int PixelLookup(float value) {
     10  int out;
     11  out = MIN (MAX (slope * value - start, 0), MaxValue);
     12  return (out);
     13}
    514
    615void CreateZoom8 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
     
    918  int i_start, i_end, j_start, j_end;
    1019  int dropback;  /* this is a bit of a kludge... */
    11   int dx, dy, DX, DY;
     20  int dx, dy, DX, DY, pixelN;
    1221  double expand, zoomscale, Rx, Ry;
    1322  int expand_in, expand_out;
    14   char *out_pix, *out_pix2;
    15   char  *in_pix, *in_pix2;
     23  unsigned char *out_pix, *out_pix2;
     24  float *imdata, *in_pix, *in_pix2;
    1625  unsigned long pixel[256], pixvalue;
    1726  unsigned long back;
     
    3039  back = graphic[0].back;
    3140
     41  // define the color transform parameters
     42  MaxValue = graphic[0].Npixels - 1;
     43  if (image[0].range != 0.0) {
     44    slope = graphic[0].Npixels / image[0].range;
     45    start = graphic[0].Npixels * image[0].zero / image[0].range;
     46  } else {
     47    slope = 1.0;
     48    start = image[0].zero;
     49  }
     50
    3251  zoomscale = MAX (5, image[0].expand + 5);
    3352  expand = 1 / zoomscale;
    3453  expand_out = (int) zoomscale;
    3554  expand_in  = 1;
    36 
    37   /*
    38   dx = image[0].zoom.dx;
    39   dy = image[0].zoom.dy;
    40   DX = image[0].matrix.Naxis[0];
    41   DY = image[0].matrix.Naxis[1];
    42   Rx = 0.5*(DX - (dx - 1)*expand) - x;
    43   Ry = 0.5*(DY - (dy - 1)*expand) - y;
    44   data coords of 0,0 point in pic array
    45   X = 0.5*image[0].matrix.Naxis[0] - expand*((int)(0.5*image[0].zoom.dx + 0.5) - 0.0) - image[0].X;
    46   Y = 0.5*image[0].matrix.Naxis[1] - expand*((int)(0.5*image[0].zoom.dy + 0.5) - 0.0) - image[0].Y; 
    47   i_start = MIN (MAX (-Rx / expand, 0), dx - expand_out + 1);
    48   j_start = MIN (MAX (-Ry / expand, 0), dy - expand_out + 1);
    49   i_end   = MAX (MIN ((DX-Rx) / expand, dx - expand_out + 1), 0);
    50   j_end   = MAX (MIN ((DY-Ry) / expand, dy - expand_out + 1), 0);
    51   dropback = expand_out - (i_end - i_start) % expand_out;
    52   if ((i_end - i_start) % expand_out == 0) dropback = 0;
    53 
    54   out_pix = image[0].zoom.data;
    55   in_pix  = (char *) (image[0].matrix.buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
    56 
    57   */
    5855
    5956  dx = image[0].zoom.dx;
     
    7269
    7370  out_pix = (char *) image[0].zoom.data;
    74   in_pix  = (char *) (image[0].matrix.buffer) + DX*(int)MAX(Ry,0) + (int)MAX(Rx,0);
     71  imdata  = (float *) image[0].matrix.buffer;
     72  in_pix  = &imdata[DX*(int)MAX(Ry,0) + (int)MAX(Rx,0)];
    7573
    7674  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    10098    in_pix2 = in_pix;
    10199    if (expand_out == 1) {
    102       for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++)
    103         *out_pix = *(pixel + *in_pix2);
    104     }
    105     else {
     100      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
     101        pixelN = PixelLookup(*in_pix2);
     102        *out_pix = pixel[pixelN];
     103      }
     104    } else {
    106105      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) {
    107         pixvalue = *(pixel + *in_pix2);
     106        pixelN   = PixelLookup(*in_pix2);
     107        pixvalue = pixel[pixelN];
    108108        out_pix2 = out_pix;
    109109        for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
     
    131131 
    132132  /**** fill in top area ****/
    133   for (j = 0; (j < dx*(dy - j_end)) && (out_pix - image[0].zoom.data < dx*dy); j++, out_pix++) {
     133  for (j = 0; (j < dx*(dy - j_end)) && (out_pix - (unsigned char *) image[0].zoom.data < dx*dy); j++, out_pix++) {
    134134    *out_pix = back;
    135135  }
  • trunk/Ohana/src/kapa2/src/DefineSection.c

    r13320 r13479  
    11# include "Ximage.h"
    22
    3 int DefineSection () {
     3// define the section, but do not create a graph or image
     4int DefineSection (int sock) {
    45 
    56  int i, N, MoveSection;
     
    1516  if (N < 0) {
    1617    section = AddSection (name, x, y, dx, dy);
    17     section->graph = InitGraph ();
    1818    MoveSection = TRUE;
    1919  } else {
     
    3333
    3434  if (MoveSection) {
    35     SetGraphSize (section);
     35    SetSectionSizes (section);
    3636    Refresh (1);
    3737  }
  • trunk/Ohana/src/kapa2/src/EraseCurrentPlot.c

    r13320 r13479  
    1111  section = GetActiveSection();
    1212  if (section->graph == NULL) return (TRUE);
     13
    1314  EraseGraph (section->graph);
    1415 
  • trunk/Ohana/src/kapa2/src/EraseOverlay.c

    r13331 r13479  
    11# include "Ximage.h"
    22
    3 int EraseOverlay () {
     3int EraseOverlay (int sock) {
    44
    55  char buffer[256];
     
    1212  section = GetActiveSection();
    1313  image = section->image;
     14  if (image == NULL) return (TRUE);
    1415
    1516  KiiScanCommand (sock, 16, "%*s %d", &N);
    1617
    1718  if (N > NOVERLAYS) {
    18     REALLOCATE (image[0].tickmarks.objects, Object, 1);
     19    REALLOCATE (image[0].tickmarks.objects, KiiOverlay, 1);
    1920    image[0].tickmarks.Nobjects = 0;
    2021  } else {
    2122    for (i = 0; i < image[0].overlay[N].Nobjects; i++) {
    22       if (!strcmp (image[0].overlay[N].objects[i].type, "TEXT")) {
     23      if (image[0].overlay[N].objects[i].type == KII_OVERLAY_TEXT) {
    2324        free (image[0].overlay[N].objects[i].text);
    2425      }
    2526    }
    26     REALLOCATE (image[0].overlay[N].objects, Object, 1);
     27    REALLOCATE (image[0].overlay[N].objects, KiiOverlay, 1);
    2728    image[0].overlay[N].Nobjects = 0;
    2829    image[0].overlay[N].active = FALSE;
  • trunk/Ohana/src/kapa2/src/GetPixelCount.c

    r13320 r13479  
    11# include "Ximage.h"
    22
    3 int GetPixelCount () {
     3int GetPixelCount (int sock) {
    44 
    55  int i;
  • trunk/Ohana/src/kapa2/src/Graphs.c

    r13320 r13479  
    2020    strcpy (graph[0].label[i].text, "");
    2121  }
     22
     23  graph[0].data.xmin = 0.0;
     24  graph[0].data.xmax = 1.0;
     25  graph[0].data.ymin = 0.0;
     26  graph[0].data.ymax = 1.0;
    2227
    2328  graph[0].Nobjects = 0;
     
    100105  FREE (graph[0].objects);
    101106  FREE (graph[0].textline);
     107  free (graph);
    102108  return;
    103109}
  • trunk/Ohana/src/kapa2/src/Image.c

    r13331 r13479  
    2121  image[0].start = 0;
    2222  image[0].slope = 1;
     23  image[0].location = 4;
    2324
    2425  image[0].coords.Npolyterms = 0;
    2526  for (i = 0; i < NOVERLAYS; i++) {
    2627    image[0].overlay[i].Nobjects = 0;
    27     ALLOCATE (image[0].overlay[i].objects, Object, 1);  /* allocate so later free will not crash! */
     28    ALLOCATE (image[0].overlay[i].objects, KiiOverlay, 1);  /* allocate so later free will not crash! */
    2829    image[0].overlay[i].active = FALSE;
    2930    image[0].overlay[i].color = graphic[0].overlay_color[i];
     
    9697  graphic = GetGraphic ();
    9798
    98   XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore);
    99   XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc,
    100                   image[0].picture.x, image[0].picture.y,
    101                   image[0].picture.dx + 1, image[0].picture.dy + 1);
     99  XSetForeground (graphic[0].display,  graphic[0].gc, graphic[0].fore);
     100  XDrawRectangle (graphic[0].display,  graphic[0].window, graphic[0].gc,
     101                  image[0].picture.x,  image[0].picture.y,
     102                  image[0].picture.dx+1, image[0].picture.dy+1);
    102103 
    103104  XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
     
    106107             image[0].picture.dx, image[0].picture.dy);
    107108
    108   XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
    109              image[0].cmapbar.pix, 0, 0,
    110              image[0].cmapbar.x, image[0].cmapbar.y,
    111              image[0].cmapbar.dx, image[0].cmapbar.dy);
    112 
    113   CrossHairs (graphic, image);
    114 
    115109  for (i = 0; i < NOVERLAYS; i++) {
    116110    if (image[0].overlay[i].active) {
     
    118112    }
    119113  }
    120 # if (0)
    121   PaintTickmarks (graphic, image);
    122 # endif
    123114
    124   // XXX make this optional?a
    125   if (1) {
     115  if (image[0].location) {
     116    XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
     117               image[0].cmapbar.pix, 0, 0,
     118               image[0].cmapbar.x, image[0].cmapbar.y,
     119               image[0].cmapbar.dx, image[0].cmapbar.dy);
     120
     121    CrossHairs (graphic, image);
     122 
    126123    /* erase everything below zoom box, then draw */
     124    /*
    127125    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].back);
    128126    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc,
    129                     image[0].text_x, image[0].text_x, image[0].zoom.dx, graphic[0].dy);
    130    
     127                    image[0].text_x, image[0].text_x, image[0].text_dx, image[0].text_dy);
     128    */   
    131129    DrawButton (graphic, &image[0].PS_button);
    132130    DrawButton (graphic, &image[0].recenter_button);
     
    139137      DrawButton (graphic, &image[0].overlay_button[i]);
    140138    }
     139    StatusBox (graphic, image);
    141140  }
    142 
    143   StatusBox (graphic, image);
    144141
    145142  FlushDisplay (graphic[0].display);
    146143}
     144
     145void FreeImage (KapaImageWidget *image) {
     146
     147  int i;
     148
     149  if (image == NULL) return;
     150
     151  for (i = 0; i < NOVERLAYS; i++) {
     152    free (image[0].overlay[i].objects);
     153  }
     154  free (image[0].matrix.buffer);
     155  free (image[0].picture.data);
     156  free (image[0].cmapbar.data);
     157  free (image[0].zoom.data);
     158
     159  free (image);
     160}
  • trunk/Ohana/src/kapa2/src/InterpretKeys.c

    r13333 r13479  
    33int InterpretKeys (Graphic *graphic, XKeyEvent *event) {
    44
    5   double           X, Y, offset;
    6   int              modstate;
     5  float           *imdata;
     6  double           X, Y, Z, R, D, offset;
     7  int              sock, DX, DY, modstate;
    78  char            *name, string[16], line[40];
    89  KeySym           keysym;
     
    2324  // XXX allow user to choose graph or image coords
    2425  if (ACTIVE_CURSOR) {
     26
     27    sock = GetActiveSocket ();
     28    if (sock == -1) goto skip_cursor;
     29
    2530    name = XKeysymToString (keysym);
    2631
     
    4348    if (!strcmp (name, "(null)")) goto skip_cursor;
    4449
     50    Z = -1;
     51
    4552    if (graph) {
    4653      X = (event[0].x - graph[0].axis[0].fx)*(graph[0].axis[0].max - graph[0].axis[0].min)/graph[0].axis[0].dfx + graph[0].axis[0].min;
    4754      Y = (event[0].y - graph[0].axis[1].fy)*(graph[0].axis[1].max - graph[0].axis[1].min)/graph[0].axis[1].dfy + graph[0].axis[1].min;
     55      XY_to_RD (&R, &D, X, Y, &graph[0].data.coords);
    4856    }
    4957    if (image && !graph) {
     
    5361      if (event[0].y > image[0].picture.y + image[0].picture.dy) goto skip_cursor;
    5462      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, image);
     63      XY_to_RD (&R, &D, X, Y, &image[0].coords);
     64
     65      DX = image[0].matrix.Naxis[0];
     66      DY = image[0].matrix.Naxis[1];
     67
     68      if (X < 0) goto off_image;
     69      if (Y < 0) goto off_image;
     70      if (X >= DX) goto off_image;
     71      if (Y >= DY) goto off_image;
     72      imdata = (float *) image[0].matrix.buffer;
     73      Z      = imdata[DX*(int)(Y) + (int)(X)];
    5574    }
    56     snprintf (line, 40, "%12s %12.6f %12.6f ", name, X, Y);
    57     write (sock, line, 40);
     75  off_image:
     76    KiiSendMessage (sock, "%12s %12.6f %12.6f %12.6f %12.6f %12.6f", name, X, Y, Z, R, D);
    5877  }
    5978
    6079skip_cursor:
     80  if (image == NULL) return (TRUE);
     81
    6182  // offset is in image pixels:
    6283  // 0.5 image pixels is 1 screen pixel for expand == +2
  • trunk/Ohana/src/kapa2/src/InterpretPresses.c

    r13333 r13479  
    33int InterpretPresses (Graphic *graphic, XButtonEvent *event) {
    44
    5   int              status, done, this_button, old_cursor;
     5  int              sock, DX, DY, status, done, this_button, old_cursor;
    66  char             name[16], line[40];
    7   double           X, Y;
     7  double           X, Y, Z, R, D;
     8  float           *imdata;
    89  KeySym           keysym;
    910  Button          *button;
     
    2021  // XXX allow user to choose graph or image coords
    2122  if (ACTIVE_CURSOR) {
     23    sock = GetActiveSocket ();
     24    if (sock == -1) goto skip_cursor;
     25
    2226    sprintf (name, "Button%d", event[0].button);
    2327    if (graph) {
    2428      X = (event[0].x - graph[0].axis[0].fx)*(graph[0].axis[0].max - graph[0].axis[0].min)/graph[0].axis[0].dfx + graph[0].axis[0].min;
    2529      Y = (event[0].y - graph[0].axis[1].fy)*(graph[0].axis[1].max - graph[0].axis[1].min)/graph[0].axis[1].dfy + graph[0].axis[1].min;
     30      XY_to_RD (&R, &D, X, Y, &graph[0].data.coords);
    2631    }
    2732    if (image && !graph) {
     
    3035      if (event[0].x > image[0].picture.x + image[0].picture.dx) goto skip_cursor;
    3136      if (event[0].y > image[0].picture.y + image[0].picture.dy) goto skip_cursor;
    32        
    3337      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, image);
     38
     39      XY_to_RD (&R, &D, X, Y, &image[0].coords);
     40
     41      DX = image[0].matrix.Naxis[0];
     42      DY = image[0].matrix.Naxis[1];
     43
     44      if (X < 0) goto off_image;
     45      if (Y < 0) goto off_image;
     46      if (X >= DX) goto off_image;
     47      if (Y >= DY) goto off_image;
     48      imdata = (float *) image[0].matrix.buffer;
     49      Z      = imdata[DX*(int)(Y) + (int)(X)];
    3450    }
    35     snprintf (line, 40, "%12s %12.6f %12.6f ", name, X, Y);
    36     write (sock, line, 40);
     51  off_image:
     52    KiiSendMessage (sock, "%12s %12.6f %12.6f %12.6f %12.6f %12.6f", name, X, Y, Z, R, D);
    3753  }
    3854
     
    4056  status = TRUE;
    4157  this_button = event[0].button;
     58
     59  // XXX add graph buttons here
     60  if (image == NULL) return (TRUE);
    4261 
    4362  if ((event[0].type == ButtonPress) && InPicture (event, &image[0].picture)) {
  • trunk/Ohana/src/kapa2/src/JPEGit24.c

    r13320 r13479  
    66# define WHITE_B 255
    77
    8 // XXX this currently writes out the jpeg for the active image
    9 int JPEGit24 () {
     8static float slope = 1.0;
     9static float start = 0.0;
     10static int MaxValue = 255;
     11
     12// XXX inline this if needed
     13static int PixelLookup(float value) {
     14  int out;
     15  out = MIN (MAX (slope * value - start, 0), MaxValue);
     16  return (out);
     17}
     18
     19// XXX this currently writes out the jpeg for just the active image
     20int JPEGit24 (int sock) {
    1021
    1122  struct jpeg_compress_struct cinfo;
     
    2132  int i_start, i_end, j_start, j_end;
    2233  int dropback;  /* this is a bit of a kludge... */
    23   int dx, dy, DX, DY;
     34  int dx, dy, DX, DY, pixelN;
    2435  int status, Nbytes, quality;
    2536  int expand_in, expand_out;
    2637  double expand, Rx, Ry, X, Y;
    27   unsigned char *out_pix, *in_pix, *in_pix_ref;
     38  unsigned char *out_pix;
     39  float *imdata, *in_pix, *in_pix_ref;
    2840  unsigned char pixel1[256], pixel2[256], pixel3[256];
    2941  char filename[1024];
    3042  FILE *f;
    3143
     44  /* expect a line telling the number of bytes and a filename */
     45  KiiScanMessage (sock, "%s", filename);
     46
    3247  graphic = GetGraphic();
    3348  section = GetActiveSection();
    3449  image   = section->image;
    35 
    36   /* expect a line telling the number of bytes and a filename */
    37   KiiScanMessage (sock, "%s", filename);
     50  if (image == NULL) return (TRUE);
    3851
    3952  /***** JPEG init calls */
     
    6982  }
    7083
     84  // define the color transform parameters
     85  MaxValue = graphic[0].Npixels - 1;
     86  if (image[0].range != 0.0) {
     87    slope = graphic[0].Npixels / image[0].range;
     88    start = graphic[0].Npixels * image[0].zero / image[0].range;
     89  } else {
     90    slope = 1.0;
     91    start = image[0].zero;
     92  }
     93
    7194  expand = expand_in = expand_out = 1.0;
    7295  if (image[0].expand == 0) /* set up expansions */
     
    122145  ALLOCATE (line_buffer, JSAMPLE, 3*dx);
    123146
    124   in_pix_ref  = (unsigned char *) (image[0].matrix.buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
     147  imdata = (float *) image[0].matrix.buffer;
     148  in_pix_ref = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
    125149
    126150  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    153177    /*** fill in the picture region ***/
    154178    for (i = i_start; i < i_end; i+=expand_out, in_pix+=expand_in) {
     179      pixelN = PixelLookup(*in_pix);
    155180      for (ii = 0; ii < expand_out; ii++, out_pix+=3) {
    156         out_pix[0] = pixel1[*in_pix];
    157         out_pix[1] = pixel2[*in_pix];
    158         out_pix[2] = pixel3[*in_pix];
     181        out_pix[0] = pixel1[pixelN];
     182        out_pix[1] = pixel2[pixelN];
     183        out_pix[2] = pixel3[pixelN];
    159184      }
    160185    }
  • trunk/Ohana/src/kapa2/src/Layout.c

    r13333 r13479  
    44void InitLayout (int argc, char **argv) {
    55
    6   int N, UseGraph;
     6  int N;
    77  Section *section;
    88
    9   UseGraph = FALSE;
    10   if ((N = get_argument (argc, argv, "-image"))) {
    11     remove_argument(N, &argc, argv);
    12     UseGraph = FALSE;
    13   }
    14 
    15   /** initiate connection with server **/
    16   if (!FOREGROUND) {   
    17     if (argc < 2) {
    18       fprintf (stderr, "socket path not specified\n");
    19       exit (0);
    20     }
    21     sock = KiiWait (argv[1]);
    22   }
     9  InitPipe();
    2310
    2411  ACTIVE_CURSOR = FALSE;
     
    3724  }
    3825
     26  /* move this out of here... */
     27  if (argc != 1) {
     28    fprintf (stderr, "USAGE: kapa\n");
     29    exit (0);
     30  }
     31
    3932  InitRotFonts ();
    4033
    41   /* create basic section */
     34  /* create basic section, empty of image or graph */
    4235  section = AddSection ("default", 0.0, 0.0, 1.0, 1.0);
    43   if (UseGraph) {
    44     section->graph = InitGraph ();
    45     SetGraphSize (section);
    46   } else {
    47     section->image = InitImage ();
    48     SetImageSize (section);
    49   }
    5036}
  • trunk/Ohana/src/kapa2/src/LoadFrame.c

    r13320 r13479  
    11# include "Ximage.h"
    22
    3 int LoadFrame () {
     3int LoadFrame (int sock) {
    44 
    55  int i, status;
     
    99
    1010  section = GetActiveSection();
     11  if (section->graph == NULL) {
     12    section->graph = InitGraph ();
     13    SetSectionSizes (section);
     14  }
    1115  graph = section->graph;
    1216
    13   // XXX what to do if graph is NULL?
    14  
    1517  KiiScanMessage (sock, "%lf %lf %lf %lf",
    1618                  &graph[0].axis[0].min, &graph[0].axis[0].max,
     
    6062  }
    6163
     64  SetSectionSizes (section);
    6265  if (USE_XWINDOW) DrawFrame (graph);
    6366  FlushDisplay ();
  • trunk/Ohana/src/kapa2/src/LoadLabels.c

    r13320 r13479  
    11# include "Ximage.h"
    22
    3 int LoadLabels () {
     3int LoadLabels (int sock) {
    44 
    55  char *c, *label;
     
    99
    1010  section = GetActiveSection();
     11  if (section->graph == NULL) {
     12    section->graph = InitGraph ();
     13    SetSectionSizes (section);
     14  }
    1115  graph = section->graph;
    12  
    13   fcntl (sock, F_SETFL, !O_NONBLOCK); 
    1416 
    1517  KiiScanMessage (sock, "%d", &mode);
     
    2123  strncpy (graph[0].label[mode].text, label, Nbytes);
    2224  label[Nbytes] = 0;
    23 
    24   fcntl (sock, F_SETFL, O_NONBLOCK); 
    2525 
    2626  c = GetRotFont (&size);
  • trunk/Ohana/src/kapa2/src/LoadObject.c

    r13320 r13479  
    11# include "Ximage.h"
    22# include <errno.h>
    3 
    4 int LoadObject () {
     3# define DEBUG 0
     4
     5int LoadObject (int sock) {
    56 
    67  int N;
     
    910
    1011  section = GetActiveSection();
     12  if (section->graph == NULL) {
     13    section->graph = InitGraph ();
     14    SetSectionSizes (section);
     15  }
    1116  graph = section->graph;
    12  
    13   fcntl (sock, F_SETFL, !O_NONBLOCK); 
    1417 
    1518  N = graph[0].Nobjects;
     
    4144                  &graph[0].objects[N].x0, &graph[0].objects[N].x1,
    4245                  &graph[0].objects[N].y0, &graph[0].objects[N].y1);
    43  
    44   fcntl (sock, F_SETFL, O_NONBLOCK); 
    45  
    46   if (!LoadVectorData (graph, N, "x")) {
     46
     47  // acknowledge receipt of the metadata
     48  KiiSendCommand (sock, 4, "DONE");
     49 
     50  // XXX Currently, I require these in a special order.  The data includes a message defining the
     51  // object type.  This could be made more flexible by using the information (though we still need
     52  // to know how many items will be sent)
     53
     54  if (!LoadVectorData (sock, graph, N, "x")) {
    4755    FreeObjectData (&graph[0].objects[N]);
    4856    graph[0].Nobjects --;
     
    5058  }
    5159   
    52   if (!LoadVectorData (graph, N, "y")) {
     60  if (!LoadVectorData (sock, graph, N, "y")) {
    5361    FreeObjectData (&graph[0].objects[N]);
    5462    graph[0].Nobjects --;
     
    5664  }
    5765  if (graph[0].objects[N].size < 0.0) {
    58     if (!LoadVectorData (graph, N, "z")) {
     66    if (!LoadVectorData (sock, graph, N, "z")) {
    5967      FreeObjectData (&graph[0].objects[N]);
    6068      graph[0].Nobjects --;
     
    6371  }
    6472  if (graph[0].objects[N].etype & 0x01) {
    65     if (!LoadVectorData (graph, N, "dym")) {
    66       FreeObjectData (&graph[0].objects[N]);
    67       graph[0].Nobjects --;
    68       REALLOCATE (graph[0].objects, Gobjects, MAX (1, graph[0].Nobjects));
    69     }
    70     if (!LoadVectorData (graph, N, "dyp")) {
     73    if (!LoadVectorData (sock, graph, N, "dym")) {
     74      FreeObjectData (&graph[0].objects[N]);
     75      graph[0].Nobjects --;
     76      REALLOCATE (graph[0].objects, Gobjects, MAX (1, graph[0].Nobjects));
     77    }
     78    if (!LoadVectorData (sock, graph, N, "dyp")) {
    7179      FreeObjectData (&graph[0].objects[N]);
    7280      graph[0].Nobjects --;
     
    7583  }
    7684  if (graph[0].objects[N].etype & 0x02) {
    77     if (!LoadVectorData (graph, N, "dxm")) {
    78       FreeObjectData (&graph[0].objects[N]);
    79       graph[0].Nobjects --;
    80       REALLOCATE (graph[0].objects, Gobjects, MAX (1, graph[0].Nobjects));
    81     }
    82     if (!LoadVectorData (graph, N, "dxp")) {
     85    if (!LoadVectorData (sock, graph, N, "dxm")) {
     86      FreeObjectData (&graph[0].objects[N]);
     87      graph[0].Nobjects --;
     88      REALLOCATE (graph[0].objects, Gobjects, MAX (1, graph[0].Nobjects));
     89    }
     90    if (!LoadVectorData (sock, graph, N, "dxp")) {
    8391      FreeObjectData (&graph[0].objects[N]);
    8492      graph[0].Nobjects --;
     
    96104}
    97105
    98 /* load data for the named component */
    99 int LoadVectorData (KapaGraphWidget *graph, int N, char *type) {
    100  
    101   int Npts, Ninpts, status, Ntry;
     106int LoadVectorData (int sock, KapaGraphWidget *graph, int N, char *type) {
     107 
     108  int i, Npts, Ninpts, status, Ntry;
    102109  int bytes_left;
    103   char *buff;
    104 
    105   buff = NULL;
     110  char *byte, *buffer, type_send[16], tmp;
     111  int Npts_send, Nbytes_send, swap_client, swap_host;
     112
     113  buffer = NULL;
    106114  Npts = graph[0].objects[N].Npts;
     115
     116  KiiWaitAnswer (sock, "PLOB");
     117  KiiScanMessage (sock, "%s %d %d %d", type_send, &Npts_send, &Nbytes_send, &swap_client);
     118  if (strcmp (type, type_send)) {
     119    fprintf (stderr, "Kapa Communication error: unexpected data type %s vs %s\n", type_send, type);
     120  }
     121  if (Npts_send != Npts) {
     122    fprintf (stderr, "Kapa Communication error: unexpected number of points %d vs %d\n", Npts_send, Npts);
     123  }
     124  if (Nbytes_send != Npts_send*sizeof(float)) {
     125    fprintf (stderr, "Kapa Communication error: unexpected data size %d vs %d\n", Nbytes_send, Npts_send*sizeof(float));
     126  }
     127
    107128  status = 1;
    108129  if (!strcmp (type, "x")) {
    109130    ALLOCATE (graph[0].objects[N].x, float, MAX (1, Npts));
    110     buff = (char *) graph[0].objects[N].x;
     131    buffer = (char *) graph[0].objects[N].x;
    111132  }
    112133  if (!strcmp (type, "y")) {
    113134    ALLOCATE (graph[0].objects[N].y, float, MAX (1, Npts));
    114     buff = (char *) graph[0].objects[N].y;
     135    buffer = (char *) graph[0].objects[N].y;
    115136  }
    116137  if (!strcmp (type, "z")) {
    117138    ALLOCATE (graph[0].objects[N].z, float, MAX (1, Npts));
    118     buff = (char *) graph[0].objects[N].z;
     139    buffer = (char *) graph[0].objects[N].z;
    119140  }
    120141  if (!strcmp (type, "dxm")) {
    121142    ALLOCATE (graph[0].objects[N].dxm, float, MAX (1, Npts));
    122     buff = (char *) graph[0].objects[N].dxm;
     143    buffer = (char *) graph[0].objects[N].dxm;
    123144  }
    124145  if (!strcmp (type, "dxp")) {
    125146    ALLOCATE (graph[0].objects[N].dxp, float, MAX (1, Npts));
    126     buff = (char *) graph[0].objects[N].dxp;
     147    buffer = (char *) graph[0].objects[N].dxp;
    127148  }
    128149  if (!strcmp (type, "dym")) {
    129150    ALLOCATE (graph[0].objects[N].dym, float, MAX (1, Npts));
    130     buff = (char *) graph[0].objects[N].dym;
     151    buffer = (char *) graph[0].objects[N].dym;
    131152  }
    132153  if (!strcmp (type, "dyp")) {
    133154    ALLOCATE (graph[0].objects[N].dyp, float, MAX (1, Npts));
    134     buff = (char *) graph[0].objects[N].dyp;
     155    buffer = (char *) graph[0].objects[N].dyp;
    135156  }
    136157
    137158  bytes_left = Npts*sizeof (float);
    138159
     160  fcntl (sock, F_SETFL, O_NONBLOCK); 
     161
     162  // read the vector data as raw binary in client machine byte order (floats)
    139163  Ntry = 0;
    140164  if (DEBUG) fprintf (stderr, "starting vector load\n");
    141165  Ninpts = 0;
     166  byte = buffer;
    142167  while (bytes_left > 0) {
    143     status = read (sock, buff, bytes_left);
     168    status = read (sock, byte, bytes_left);
    144169    if (DEBUG) fprintf (stderr, "status: %d, %d\n", status, bytes_left);
    145170    if (status == 0) {  /* No more pipe */
     
    150175      Ninpts += status;
    151176      bytes_left -= status;
    152       buff = (char *)(buff + status);
     177      byte = (char *)(byte + status);
    153178      Ntry = 0;
    154179      continue;
     
    165190    perror ("kapa load");
    166191  }
     192
     193  fcntl (sock, F_SETFL, !O_NONBLOCK); 
     194  KiiSendCommand (sock, 4, "DONE");
     195
     196# ifdef BYTE_SWAP
     197  swap_host = 1;
     198# else
     199  swap_host = 0;
     200# endif 
     201
     202  // if host and client have opposite swap parities, word swap the incoming data
     203  // SWAP_WORD is strangely defined... it takes the number of the start byte in a
     204  // buffer called 'byte'
     205  if ((swap_host && !swap_client) || (!swap_host && swap_client)) {
     206    byte = buffer;
     207    for (i = 0; i < Nbytes_send; i+=4) {
     208      SWAP_WORD (i);
     209    }
     210  }
     211
    167212  if (Ninpts != Npts*sizeof(float)) { 
    168213    fprintf (stderr, "error: expected %d bytes, but got only %d\n", Ninpts, (unsigned int)(Npts*sizeof(float)));
     
    185230  if (object[0].dyp != (float *) NULL) free (object[0].dyp);
    186231}
    187 
  • trunk/Ohana/src/kapa2/src/LoadOverlay.c

    r13331 r13479  
    11# include "Ximage.h"
    22
    3 // XXX this is a very inefficient method to send the data: binary would be better
    4 int LoadOverlay () {
     3int LoadOverlay (int sock) {
    54 
    6   char word[17], type[16], string[128];
    7   char *buffer, *buff;
    8   double x, y, dx, dy;
    9   int Nin, bytes, status;
    10   int i, N, NOBJECTS, Nobjects, Nstart;
     5  int i, j, Ntotal, Nbytes, Nread, Nfound, Ntext, Nobjects, overnum;
     6  int Noverlay, NOVERLAY, Ntextdata;
     7  char *textdata, *buffer, *p, *q;
    118  Section *section;
    129  KapaImageWidget *image;
    1310  Graphic *graphic;
     11  KiiOverlayBase *overlay;
    1412
    1513  graphic = GetGraphic ();
    1614  section = GetActiveSection();
    17   image   = section->image;
     15  if (section->image == NULL) {
     16    section->image = InitImage ();
     17    SetSectionSizes (section);
     18  }
     19  image = section->image;
    1820
    19   ALLOCATE (buffer, char, 65536);  /* space for 512 lines of 128 bytes */
    20   bzero (buffer, 65536);
     21  KiiScanMessage (sock, "%d %d %d %d", &overnum, &Noverlay, &Ntext, &Ntextdata);
    2122
    22   KiiScanCommand (sock, 16, "%*s %d", &N);
    23   Nstart = image[0].overlay[N].Nobjects;
     23  // XXX need to validate overnum
     24  if ((overnum < 0) || (overnum >= NOVERLAYS)) overnum = 0;
    2425
    25   while (1) {
    26     KiiScanCommand (sock, 16, "%s %d", word, &Nin);
    27     if (!strcmp (word, "DONE")) break;
    28     if (strcmp (word, "NLINES")) abort();
     26  // read the overlay data as binary
     27  Ntotal = 0;
     28  Nbytes = Noverlay*sizeof(KiiOverlayBase);
     29  fcntl (sock, F_SETFL, O_NONBLOCK); 
     30  ALLOCATE (overlay, KiiOverlayBase, Noverlay);
     31  buffer = (char *) overlay;
     32  while (Nbytes > 0) {
     33    Nread = read (sock, &buffer[Ntotal], Nbytes);
     34    // fprintf (stderr, "read: %d of %d remaining, %d so far, %d expected\n", Nread, Nbytes, Ntotal, Noverlay*sizeof(KiiOverlayBase));
     35    if (Nread == 0) {  /* No more pipe */
     36      fprintf (stderr, "error: pipe closed\n");
     37      free (overlay);
     38      fcntl (sock, F_SETFL, !O_NONBLOCK); 
     39      return (FALSE);
     40    }
     41    if (Nread != -1) { /* pipe has data */
     42      Nbytes -= Nread;
     43      Ntotal += Nread;
     44    }
     45  }
     46  fcntl (sock, F_SETFL, !O_NONBLOCK); 
     47  KiiSendCommand (sock,  4, "DONE");
    2948
    30     buff = buffer;
    31     bytes = 128*Nin;
     49  // read the textdata as binary
     50  Ntotal = 0;
     51  Nbytes = Ntextdata;
     52  fcntl (sock, F_SETFL, O_NONBLOCK); 
     53  ALLOCATE (textdata, char, Ntextdata);
     54  while (Nbytes > 0) {
     55    Nread = read (sock, &textdata[Ntotal], Nbytes);
     56    if (Nread == 0) {  /* No more pipe */
     57      fprintf (stderr, "error: pipe closed\n");
     58      free (textdata);
     59      free (overlay);
     60      fcntl (sock, F_SETFL, !O_NONBLOCK); 
     61      return (FALSE);
     62    }
     63    if (Nread != -1) { /* pipe has data */
     64      Nbytes -= Nread;
     65      Ntotal += Nread;
     66    }
     67  }
     68  fcntl (sock, F_SETFL, !O_NONBLOCK); 
     69  KiiSendCommand (sock,  4, "DONE");
    3270
    33     /* accept data from the socket until we have all of the bytes */
    34     fcntl (sock, F_SETFL, O_NONBLOCK); 
    35     while (bytes > 0) {
    36       status = read (sock, buff, bytes);
    37       if (status == 0) {  /* No more pipe */
    38         fprintf (stderr, "error: pipe closed\n");
    39         free (buffer);
    40         fcntl (sock, F_SETFL, O_NONBLOCK); 
    41         return (FALSE);
    42       }
    43       if (status != -1) { /* pipe has data */
    44         bytes -= status;
    45         buff = (char *)(buff + status);
    46       }
    47     }
    48     fcntl (sock, F_SETFL, !O_NONBLOCK); 
     71  // add new overlay objects to existing data
     72  Nobjects = image[0].overlay[overnum].Nobjects + Noverlay;
     73  REALLOCATE (image[0].overlay[overnum].objects, KiiOverlay, Nobjects);
    4974
    50     /* parse buffer data */
    51     NOBJECTS = image[0].overlay[N].Nobjects + Nin;
    52     Nobjects = image[0].overlay[N].Nobjects;
    53     REALLOCATE (image[0].overlay[N].objects, Object, NOBJECTS);
    54     for (i = 0; i < Nin; i++) {
    55       sscanf (&buffer[i*128], "%s %lf %lf %lf %lf\n", type, &x, &y, &dx, &dy);
    56 
    57       if (strcasecmp (type, "TEXT") && strcasecmp (type, "LINE") && strcasecmp (type, "BOX") && strcasecmp (type, "CIRCLE")) {  /* skip */
    58         fprintf (stderr, "don't know %s, skipping\n", type);
    59         continue;
    60       }
    61 
    62       if (!strcasecmp (type, "TEXT")) { /* end of objects */
    63         sscanf (&buffer[i*128], "%s %lf %lf %s\n", type, &x, &y, string);
    64       }
    65        
    66       strcpy (image[0].overlay[N].objects[Nobjects].type, type);
    67       image[0].overlay[N].objects[Nobjects].x = x;
    68       image[0].overlay[N].objects[Nobjects].y = y;
    69       if (!strcmp (type, "TEXT")) {
    70         image[0].overlay[N].objects[Nobjects].dx = 0;
    71         image[0].overlay[N].objects[Nobjects].dy = 0;
    72         image[0].overlay[N].objects[Nobjects].text = strcreate (string);
    73       } else {
    74         image[0].overlay[N].objects[Nobjects].dx = dx;
    75         image[0].overlay[N].objects[Nobjects].dy = dy;
    76       }
    77       Nobjects++;
    78     }
    79     REALLOCATE (image[0].overlay[N].objects, Object, MAX(Nobjects, 1));
    80     image[0].overlay[N].Nobjects = Nobjects;
     75  j = image[0].overlay[overnum].Nobjects;
     76  for (i = 0; i < Noverlay; i++, j++) {
     77    image[0].overlay[overnum].objects[j].x = overlay[i].x;
     78    image[0].overlay[overnum].objects[j].y = overlay[i].y;
     79    image[0].overlay[overnum].objects[j].dx = overlay[i].dx;
     80    image[0].overlay[overnum].objects[j].dy = overlay[i].dy;
     81    image[0].overlay[overnum].objects[j].type = overlay[i].type;
     82    image[0].overlay[overnum].objects[j].text = NULL;
    8183  }
    8284
    83   /* cleanup */
    84   free (buffer);
    85   REALLOCATE (image[0].overlay[N].objects, Object, MAX (1, image[0].overlay[N].Nobjects));
    86   image[0].overlay[N].active = TRUE;
    87   fcntl (sock, F_SETFL, O_NONBLOCK); 
     85  // parse the text data : text lines are separated by '\n', one per text entry
     86  p = textdata;
     87  Nfound = 0;
     88  for (i = 0; i < Noverlay; i++) {
     89    if (overlay[i].type != KII_OVERLAY_TEXT) continue;
     90    if (Nfound >= Ntext) {
     91      fprintf (stderr, "inconsistent number of text lines\n");
     92      break;
     93    }
     94    if (! *p) {
     95      fprintf (stderr, "inconsistent number of text lines\n");
     96      break;
     97    }
     98    q = strchr (p, '\n');
     99    if (q == NULL) {
     100      fprintf (stderr, "inconsistent text line\n");
     101      break;
     102    }
     103    j = image[0].overlay[overnum].Nobjects + i;
     104    image[0].overlay[overnum].objects[j].text = strncreate (p, q-p);
     105    p = q + 1;
     106    Nfound ++;
     107  }
     108  if (Nfound != Ntext) {
     109    fprintf (stderr, "read %d text lines, expected %d\n", Nfound, Ntext);
     110  }
     111
     112  free (textdata);
     113  free (overlay);
     114
     115  image[0].overlay[overnum].Nobjects = Nobjects;
     116  image[0].overlay[overnum].active = TRUE;
    88117
    89118  if (USE_XWINDOW) {
     
    93122      }
    94123    }
    95     PaintTickmarks (graphic, image);
    96124    XFlush (graphic[0].display);
    97125  }
  • trunk/Ohana/src/kapa2/src/LoadPicture.c

    r13320 r13479  
    11# include "Ximage.h"
    22
    3 int LoadPicture () {
     3int LoadPicture (int sock) {
    44
    55  Header header;
     
    1212  graphic = GetGraphic ();
    1313  section = GetActiveSection();
    14   image   = section->image;
     14  if (section->image == NULL) {
     15    section->image = InitImage ();
     16    SetSectionSizes (section);
     17  }
     18  image = section->image;
    1519 
    1620  KiiSendMessage (sock, "%d", graphic->Npixels);
    1721
    18   fcntl (sock, F_SETFL, !O_NONBLOCK); 
    19 
    2022  header.Naxes = 2;
    21 
    2223  KiiScanMessage (sock, "%d %d %d %d %lf %lf", &header.Naxis[0], &header.Naxis[1]);
    2324  KiiScanMessage (sock, "%d %d %d %d %lf %lf", &header.bitpix, &header.unsign, &header.bzero, &header.bscale);
    24   KiiScanMessage (sock, "%lf %lf",  &image[0].zero, &image[0].range);
     25  KiiScanMessage (sock, "%lf %lf %s",  &image[0].zero, &image[0].range, image[0].name, image[0].file);
    2526  KiiScanMessage (sock, "%lf %lf %d", &image[0].min,  &image[0].max, &header.size);
    2627  KiiScanMessage (sock, "%lf %f %f %f %f", &image[0].coords.crval1, &image[0].coords.crpix1, &image[0].coords.cdelt1, &image[0].coords.pc1_1, &image[0].coords.pc1_2);
    2728  KiiScanMessage (sock, "%lf %f %f %f %f", &image[0].coords.crval2, &image[0].coords.crpix2, &image[0].coords.cdelt2, &image[0].coords.pc2_1, &image[0].coords.pc2_2);
    28          
    29   KiiScanMessage (sock, "%s %s %s", image[0].coords.ctype, image[0].file, image[0].buffer_name);
     29  KiiScanMessage (sock, "%s", image[0].coords.ctype);
    3030
    3131  gfits_free_matrix (&image[0].matrix);
     
    5151  }
    5252
     53  fcntl (sock, F_SETFL, !O_NONBLOCK); 
     54
    5355  if (DEBUG) fprintf (stderr, "read %d bytes\n", image[0].matrix.size);
    5456  /* it it not obvious this condition should kill kii, but ... */
  • trunk/Ohana/src/kapa2/src/LoadTextlines.c

    r13320 r13479  
    11# include "Ximage.h"
    22
    3 int LoadTextlines () {
     3int LoadTextlines (int sock) {
    44 
    55  char *string;
     
    1111  section = GetActiveSection();
    1212  graph = section->graph;
    13  
    14   fcntl (sock, F_SETFL, !O_NONBLOCK); 
    15  
     13    if (section->graph == NULL) {
     14    section->graph = InitGraph ();
     15    SetSectionSizes (section);
     16  }
     17
    1618  graph[0].Ntextline = MAX (graph[0].Ntextline, 0);
    1719  N = graph[0].Ntextline;
     
    3436  strcpy (graph[0].textline[N].text, string);
    3537  free (string);
    36 
    37   fcntl (sock, F_SETFL, O_NONBLOCK); 
    3838 
    3939  string = GetRotFont (&size);
  • trunk/Ohana/src/kapa2/src/LoadTickmarks.c

    r13320 r13479  
    11# include "Ximage.h"
    22
    3 int LoadTickmarks () {
     3int LoadTickmarks (int sock) {
    44 
    55  char line[129], type[16];
     
    1010
    1111  section = GetActiveSection();
     12  if (section->image == NULL) {
     13    section->image = InitImage ();
     14    SetSectionSizes (section);
     15  }
    1216  image   = section->image;
    13   fcntl (sock, F_SETFL, !O_NONBLOCK); 
    1417
    1518  Nobjects = image[0].tickmarks.Nobjects;
    1619  NOBJECTS = Nobjects + 100;
    17   REALLOCATE (image[0].tickmarks.objects, Object, NOBJECTS);
     20  REALLOCATE (image[0].tickmarks.objects, KiiOverlay, NOBJECTS);
    1821 
    1922  done = FALSE;
     
    5154    if (Nobjects >= NOBJECTS) {
    5255      NOBJECTS = Nobjects + 100;
    53       REALLOCATE (image[0].tickmarks.objects, Object, NOBJECTS);
     56      REALLOCATE (image[0].tickmarks.objects, KiiOverlay, NOBJECTS);
    5457    }
    5558
    5659  }
    5760
    58   REALLOCATE (image[0].tickmarks.objects, Object, MAX(Nobjects, 1));
     61  REALLOCATE (image[0].tickmarks.objects, KiiOverlay, MAX(Nobjects, 1));
    5962  image[0].tickmarks.Nobjects = Nobjects;
    6063
    6164  if (USE_XWINDOW) Refresh ();
    62 
    63   fcntl (sock, F_SETFL, O_NONBLOCK); 
    6465  return (TRUE);
    65  
    6666}
  • trunk/Ohana/src/kapa2/src/PNGit.c

    r13320 r13479  
    11# include "Ximage.h"
    22
    3 int PNGit () {
     3int PNGit (int sock) {
    44
    55  FILE *f;
  • trunk/Ohana/src/kapa2/src/PPMit.c

    r13320 r13479  
    11# include "Ximage.h"
    22
    3 int PPMit () {
     3int PPMit (int sock) {
    44
    55  FILE *f;
  • trunk/Ohana/src/kapa2/src/PSOverlay.c

    r13331 r13479  
    3131    dY = (image[0].overlay[N].objects[i].dy)/expand;
    3232   
    33     if (!strcmp (image[0].overlay[N].objects[i].type, "LINE")) {
    34       if (((X < Xmin) && (X + dX < Xmin)) || ((X > Xmax) && (X + dX > Xmax)) ||
    35           ((Y < Ymin) && (Y + dY < Ymin)) || ((Y > Ymax) && (Y + dY > Ymax))) {
    36         continue;
    37       }
    38       fprintf (f, " %6.1f %6.1f %6.1f %6.1f L\n", X + extra, Y + extra, (X+dX + extra), (Y-dY + extra));
    39       continue;
     33    switch (image[0].overlay[N].objects[i].type) {
     34      case KII_OVERLAY_LINE:
     35        if (((X < Xmin) && (X + dX < Xmin)) || ((X > Xmax) && (X + dX > Xmax)) ||
     36            ((Y < Ymin) && (Y + dY < Ymin)) || ((Y > Ymax) && (Y + dY > Ymax))) {
     37          break;
     38        }
     39        fprintf (f, " %6.1f %6.1f %6.1f %6.1f L\n", X + extra, Y + extra, (X+dX + extra), (Y-dY + extra));
     40        break;
     41      case KII_OVERLAY_TEXT:
     42        if (((X < Xmin) && (X + dX < Xmin)) || ((X > Xmax) && (X + dX > Xmax)) ||
     43            ((Y < Ymin) && (Y + dY < Ymin)) || ((Y > Ymax) && (Y + dY > Ymax))) {
     44          break;
     45        }
     46        fprintf (f, "(%s) %6.1f %6.1f T\n", image[0].overlay[N].objects[i].text, X + extra, Y + extra);
     47        break;
     48      case KII_OVERLAY_BOX:
     49        if (((X - 0.5*dX < Xmin) && (X + 0.5*dX < Xmin)) || ((X - 0.5*dX > Xmax) && (X + 0.5*dX > Xmax)) ||
     50            ((Y - 0.5*dY < Ymin) && (Y + 0.5*dY < Ymin)) || ((Y - 0.5*dY > Ymax) && (Y + 0.5*dY > Ymax))) {
     51          break;
     52        }
     53        fprintf (f, " %6.1f %6.1f %6.1f %6.1f B\n", (dX + 2*extra), (dY + 2*extra), (X - 0.5*dX - extra), (Y - 0.5*dY - extra));
     54        break;
     55      case KII_OVERLAY_CIRCLE:
     56        if (((X - dX < Xmin) && (X + dX < Xmin)) || ((X - dX > Xmax) && (X + dX > Xmax)) ||
     57            ((Y - dY < Ymin) && (Y + dY < Ymin)) || ((Y - dY > Ymax) && (Y + dY > Ymax))) {
     58          break;
     59        }
     60        fprintf (f, " %6.1f %6.1f %6.1f C\n", X, Y, fabs(dX + extra));
     61        break;
     62      default:
     63        fprintf (stderr, "skipping unknown object\n");
     64        break;
    4065    }
    41     if (!strcmp (image[0].overlay[N].objects[i].type, "TEXT")) {
    42       if (((X < Xmin) && (X + dX < Xmin)) || ((X > Xmax) && (X + dX > Xmax)) ||
    43           ((Y < Ymin) && (Y + dY < Ymin)) || ((Y > Ymax) && (Y + dY > Ymax))) {
    44         continue;
    45       }
    46       fprintf (f, "(%s) %6.1f %6.1f T\n", image[0].overlay[N].objects[i].text, X + extra, Y + extra);
    47       continue;
    48     }
    49     if (!strcmp (image[0].overlay[N].objects[i].type, "BOX")) {
    50       if (((X - 0.5*dX < Xmin) && (X + 0.5*dX < Xmin)) || ((X - 0.5*dX > Xmax) && (X + 0.5*dX > Xmax)) ||
    51           ((Y - 0.5*dY < Ymin) && (Y + 0.5*dY < Ymin)) || ((Y - 0.5*dY > Ymax) && (Y + 0.5*dY > Ymax))) {
    52         continue;
    53       }
    54       fprintf (f, " %6.1f %6.1f %6.1f %6.1f B\n", (dX + 2*extra), (dY + 2*extra), (X - 0.5*dX - extra), (Y - 0.5*dY - extra));
    55       continue;
    56     }
    57     if (!strcmp (image[0].overlay[N].objects[i].type, "CIRCLE")) {
    58       if (((X - dX < Xmin) && (X + dX < Xmin)) || ((X - dX > Xmax) && (X + dX > Xmax)) ||
    59           ((Y - dY < Ymin) && (Y + dY < Ymin)) || ((Y - dY > Ymax) && (Y + dY > Ymax))) {
    60         continue;
    61       }
    62       fprintf (f, " %6.1f %6.1f %6.1f C\n", X, Y, fabs(dX + extra));
    63       continue;
    64     }
    65     fprintf (stderr, "don't know %s, skipping\n", image[0].overlay[N].objects[i].type);
    6666  }
    67  
    6867}
  • trunk/Ohana/src/kapa2/src/PSit.c

    r13331 r13479  
    66static Graphic *graphic;
    77
    8 int PScommand () {
     8int PScommand (int sock) {
    99
    1010  int status, scaleMode, pageMode;
  • trunk/Ohana/src/kapa2/src/PaintOverlay.c

    r13320 r13479  
    4141       for a BOX (x, y) is the center, (dx, dy) is the width */
    4242
    43     if (!strcasecmp (image[0].overlay[N].objects[i].type, "LINE")) {
    44       XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, (X+dX), (Y+dY));
    45       continue;
     43    switch (image[0].overlay[N].objects[i].type) {
     44      case KII_OVERLAY_LINE:
     45        XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, (X+dX), (Y+dY));
     46        break;
     47      case KII_OVERLAY_TEXT:
     48        XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, image[0].overlay[N].objects[i].text, strlen(image[0].overlay[N].objects[i].text));
     49        break;
     50      case KII_OVERLAY_BOX:
     51        dx = MAX (abs(dX),2) / 2;
     52        dy = MAX (abs(dY),2) / 2;
     53        XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, (X - dx), (Y - dy), 2*dx, 2*dy);
     54        break;
     55      case KII_OVERLAY_CIRCLE:
     56        dx = MAX (abs(dX),2);
     57        dy = MAX (abs(dY),2);
     58        XDrawArc (graphic[0].display, graphic[0].window, graphic[0].gc, (X - dx), (Y - dy), 2*dx, 2*dy, 0, 23040);
     59        break;
     60      default:
     61        fprintf (stderr, "skipping unknown object\n");
     62        break;
    4663    }
    47     if (!strcasecmp (image[0].overlay[N].objects[i].type, "TEXT")) {
    48       XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, image[0].overlay[N].objects[i].text, strlen(image[0].overlay[N].objects[i].text));
    49       continue;
    50     }
    51     if (!strcasecmp (image[0].overlay[N].objects[i].type, "BOX")) {
    52       dx = MAX (abs(dX),2) / 2;
    53       dy = MAX (abs(dY),2) / 2;
    54       XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, (X - dx), (Y - dy), 2*dx, 2*dy);
    55        continue;
    56     }
    57     if (!strcasecmp (image[0].overlay[N].objects[i].type, "CIRCLE")) {
    58       dx = MAX (abs(dX),2);
    59       dy = MAX (abs(dY),2);
    60       XDrawArc (graphic[0].display, graphic[0].window, graphic[0].gc, (X - dx), (Y - dy), 2*dx, 2*dy, 0, 23040);
    61       continue;
    62     }
    63     fprintf (stderr, "don't know %s, skipping (PO)\n", image[0].overlay[N].objects[i].type);
    6464  }
    6565 
  • trunk/Ohana/src/kapa2/src/PaintTickmarks.c

    r13320 r13479  
    2222    dY = image[0].tickmarks.objects[i].dy * Yrange;
    2323
    24     if (!strcmp (image[0].tickmarks.objects[i].type, "LINE")) {
    25       XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, (X+dX), (Y+dY));
    26       continue;
     24    switch (image[0].overlay[0].objects[i].type) {
     25      case KII_OVERLAY_LINE:
     26        XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, (X+dX), (Y+dY));
     27        break;
     28      case KII_OVERLAY_TEXT:
     29        if (image[0].tickmarks.objects[i].dy == 0) {
     30            XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].back);
     31            XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y-11, 6*strlen(image[0].tickmarks.objects[i].text), 11);
     32            XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore);
     33            XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, image[0].tickmarks.objects[i].text, strlen(image[0].tickmarks.objects[i].text));
     34        }
     35        if (image[0].tickmarks.objects[i].dy == 90) {
     36            XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].back);
     37            XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y-6*strlen(image[0].tickmarks.objects[i].text), 11, 6*strlen(image[0].tickmarks.objects[i].text));
     38            XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore);
     39            /* XDrawRotString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, image[0].tickmarks.objects[i].text, strlen(image[0].tickmarks.objects[i].text)); */
     40        }
     41        break;
     42      case KII_OVERLAY_BOX:
     43        XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, (int)(X - 0.5*dX), (int)(Y - 0.5*dY), abs(dX), abs(dY));
     44        break;
     45      case KII_OVERLAY_CIRCLE:
     46        XDrawArc (graphic[0].display, graphic[0].window, graphic[0].gc, X - dX, Y - dY, abs(2*dX), abs(2*dY), 0, 23040);
     47        break;
     48      default:
     49        fprintf (stderr, "skipping unknown object\n");
     50        break;
    2751    }
    28     if (!strcmp (image[0].tickmarks.objects[i].type, "TEXT")) {
    29       if (image[0].tickmarks.objects[i].dy == 0) {
    30         XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].back);
    31         XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y-11, 6*strlen(image[0].tickmarks.objects[i].text), 11);
    32         XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore);
    33         XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, image[0].tickmarks.objects[i].text, strlen(image[0].tickmarks.objects[i].text));
    34       }
    35       if (image[0].tickmarks.objects[i].dy == 90) {
    36         XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].back);
    37         XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y-6*strlen(image[0].tickmarks.objects[i].text), 11, 6*strlen(image[0].tickmarks.objects[i].text));
    38         XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore);
    39         /* XDrawRotString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, image[0].tickmarks.objects[i].text, strlen(image[0].tickmarks.objects[i].text)); */
    40       }
    41       continue;
    42     }
    43     if (!strcmp (image[0].tickmarks.objects[i].type, "BOX")) {
    44       XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, (int)(X - 0.5*dX), (int)(Y - 0.5*dY), abs(dX), abs(dY));
    45        continue;
    46     }
    47     if (!strcmp (image[0].tickmarks.objects[i].type, "CIRCLE")) {
    48       XDrawArc (graphic[0].display, graphic[0].window, graphic[0].gc, X - dX, Y - dY, abs(2*dX), abs(2*dY), 0, 23040);
    49       continue;
    50     }
    51     fprintf (stderr, "don't know %s, skipping (PO)\n", image[0].tickmarks.objects[i].type);
    5252  }
    53  
    5453  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore);
    55 
    5654}
  • trunk/Ohana/src/kapa2/src/Reconfig.c

    r13320 r13479  
    2525  for (i = 0; i < Nsection; i++) {
    2626      section = GetSectionByNumber (i);
    27       SetGraphSize (section);
    28       SetImageSize (section);
     27      SetSectionSizes (section);
    2928  }
    3029
  • trunk/Ohana/src/kapa2/src/Refresh.c

    r13320 r13479  
    2121  for (i = 0; i < Nsection; i++) {
    2222      section = GetSectionByNumber (i);
     23      DrawImage (section->image);
    2324      DrawGraph (section->graph);
    24       DrawImage (section->image);
    2525  }
    2626
  • trunk/Ohana/src/kapa2/src/Remap16.c

    r13320 r13479  
    11# include "Ximage.h"
    2 # define FRAC(a) ((a) - (int)(a))
     2
     3static float slope = 1.0;
     4static float start = 0.0;
     5static int MaxValue = 255;
     6
     7// XXX inline this if needed
     8static int PixelLookup(float value) {
     9  int out;
     10  out = MIN (MAX (slope * value - start, 0), MaxValue);
     11  return (out);
     12}
    313
    414void Remap16 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
     
    717  int i_start, i_end, j_start, j_end;
    818  int dropback;  /* this is a bit of a kludge... */
    9   int dx, dy, DX, DY;
     19  int dx, dy, DX, DY, pixelN;
    1020  double expand, Rx, Ry, X, Y;
    1121  int expand_in, expand_out;
    1222  unsigned char *out_pix, *out_pix2, *data;
    13   unsigned char *in_pix, *in_pix2;
    14   unsigned char pixel1[256], pixel2[256], pixel3[256];
     23  float *imdata, *in_pix, *in_pix2;
     24  unsigned char pixel1[256], pixel2[256];
    1525  unsigned char pixvalue1, pixvalue2;
    1626  unsigned long back;
    1727  unsigned char back1, back2;
    1828
     29  // local array for pixel values (is this working??)
    1930  for (i = 0; i < 256; i++) { /* set up pixel array */
    20     pixel1[i] = 0x0000ff &  graphic[0].cmap[i].pixel;
    21     pixel2[i] = 0x0000ff & (graphic[0].cmap[i].pixel >> 8);
    22     pixel3[i] = 0x0000ff & (graphic[0].cmap[i].pixel >> 16);
     31    pixel1[i] = 0x00ff &  graphic[0].cmap[i].pixel;
     32    pixel2[i] = 0x00ff & (graphic[0].cmap[i].pixel >> 8);
    2333  }
    2434  back = graphic[0].back;
     
    2636  back2 = 0x00ff & (back >> 8);
    2737
     38  // define the color transform parameters
     39  MaxValue = graphic[0].Npixels - 1;
     40  if (image[0].range != 0.0) {
     41    slope = graphic[0].Npixels / image[0].range;
     42    start = graphic[0].Npixels * image[0].zero / image[0].range;
     43  } else {
     44    slope = 1.0;
     45    start = image[0].zero;
     46  }
     47
     48  // set up expansions
    2849  expand = expand_in = expand_out = 1.0;
    2950  if (image[0].expand == 0) /* set up expansions */
     
    4061  }
    4162
     63  // define the image boundaries
    4264  dx = image[0].picture.dx;
    4365  dy = image[0].picture.dy;
     
    7698
    7799  data = out_pix = (unsigned char *) image[0].picture.data;
    78   in_pix  = (unsigned char *) (matrix[0].buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
     100  imdata  = (float *) matrix[0].buffer;
     101  in_pix  = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
    79102
    80103  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    105128    if (expand_out == 1) {
    106129      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=2) {
    107         out_pix[0] = pixel1[*in_pix2];
    108         out_pix[1] = pixel2[*in_pix2];
     130        pixelN = PixelLookup(*in_pix2);
     131        out_pix[0] = pixel1[pixelN];
     132        out_pix[1] = pixel2[pixelN];
    109133      }
    110134    }
    111135    else {
    112136      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 2*expand_out) {
    113         pixvalue1 = pixel1[*in_pix2];
    114         pixvalue2 = pixel2[*in_pix2];
     137        pixelN    = PixelLookup(*in_pix2);
     138        pixvalue1 = pixel1[pixelN];
     139        pixvalue2 = pixel2[pixelN];
    115140        out_pix2 = out_pix;
    116141        for (jj = 0; jj < expand_out; jj++, out_pix2+=2*(dx-expand_out)) {
  • trunk/Ohana/src/kapa2/src/Remap24.c

    r13320 r13479  
    11# include "Ximage.h"
    2 # define FRAC(a) ((a) - (int)(a))
     2
     3static float slope = 1.0;
     4static float start = 0.0;
     5static int MaxValue = 255;
     6
     7// XXX inline this if needed
     8static int PixelLookup(float value) {
     9  int out;
     10  out = MIN (MAX (slope * value - start, 0), MaxValue);
     11  return (out);
     12}
    313
    414void Remap24 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
     
    717  int i_start, i_end, j_start, j_end;
    818  int dropback, extra;  /* this is a bit of a kludge... */
    9   int dx, dy, DX, DY;
     19  int dx, dy, DX, DY, pixelN;
    1020  double expand, Rx, Ry, X, Y;
    1121  int expand_in, expand_out;
    1222  unsigned char *out_pix, *out_pix2, *data;
    13   unsigned char *in_pix, *in_pix2;
     23  float *imdata, *in_pix, *in_pix2;
    1424  unsigned char pixel1[256], pixel2[256], pixel3[256];
    1525  unsigned char pixvalue1, pixvalue2, pixvalue3;
     
    1727  unsigned char back1, back2, back3;
    1828
     29  // local arrays for pixel values
    1930  for (i = 0; i < 256; i++) { /* set up pixel array */
    2031    pixel1[i] = 0x0000ff &  graphic[0].cmap[i].pixel;
     
    2738  back3 = 0x0000ff & (back >> 16);
    2839
     40  // define the color transform parameters
     41  MaxValue = graphic[0].Npixels - 1;
     42  if (image[0].range != 0.0) {
     43    slope = graphic[0].Npixels / image[0].range;
     44    start = graphic[0].Npixels * image[0].zero / image[0].range;
     45  } else {
     46    slope = 1.0;
     47    start = image[0].zero;
     48  }
     49
     50  // set up expansions
    2951  expand = expand_in = expand_out = 1.0;
    3052  if (image[0].expand == 0) /* set up expansions */
     
    78100
    79101  data = out_pix = (unsigned char *) image[0].picture.data;
    80   in_pix  = (unsigned char *) (matrix[0].buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
     102  imdata  = (float *) matrix[0].buffer;
     103  in_pix  = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
    81104
    82105  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    110133    if (expand_out == 1) {
    111134      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=3) {
    112         out_pix[0] = pixel1[*in_pix2];
    113         out_pix[1] = pixel2[*in_pix2];
    114         out_pix[2] = pixel3[*in_pix2];
     135        pixelN = PixelLookup(*in_pix2);
     136        out_pix[0] = pixel1[pixelN];
     137        out_pix[1] = pixel2[pixelN];
     138        out_pix[2] = pixel3[pixelN];
    115139      }
    116     }
    117     else {
     140    } else {
    118141      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 3*expand_out) {
    119         pixvalue1 = pixel1[*in_pix2];
    120         pixvalue2 = pixel2[*in_pix2];
    121         pixvalue3 = pixel3[*in_pix2];
     142        pixelN = PixelLookup(*in_pix2);
     143        pixvalue1 = pixel1[pixelN];
     144        pixvalue2 = pixel2[pixelN];
     145        pixvalue3 = pixel3[pixelN];
    122146        out_pix2 = out_pix;
    123147        for (jj = 0; jj < expand_out; jj++, out_pix2+=3*(dx-expand_out)+extra) {
  • trunk/Ohana/src/kapa2/src/Remap32.c

    r13320 r13479  
    11# include "Ximage.h"
    2 # define FRAC(a) ((a) - (int)(a))
     2
     3static float slope = 1.0;
     4static float start = 0.0;
     5static int MaxValue = 255;
     6
     7// XXX inline this if needed
     8static int PixelLookup(float value) {
     9  int out;
     10  out = MIN (MAX (slope * value - start, 0), MaxValue);
     11  return (out);
     12}
    313
    414void Remap32 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
     
    717  int i_start, i_end, j_start, j_end;
    818  int dropback;  /* this is a bit of a kludge... */
    9   int dx, dy, DX, DY;
     19  int dx, dy, DX, DY, pixelN;
    1020  double expand, Rx, Ry, X, Y;
    1121  int expand_in, expand_out;
    1222  unsigned int *out_pix, *out_pix2;
    13   unsigned char *in_pix, *in_pix2;
     23  float *imdata, *in_pix, *in_pix2;
    1424  unsigned long pixel[256], pixvalue;
    1525  unsigned long back;
    1626
    17   for (i = 0; i < 256; i++) { /* set up pixel array */
     27  // local array for pixel values
     28  for (i = 0; i < 256; i++) {
    1829    pixel[i] = graphic[0].cmap[i].pixel;
    1930  }
    2031  back = graphic[0].back;
    2132
     33  // define the color transform parameters
     34  MaxValue = graphic[0].Npixels - 1;
     35  if (image[0].range != 0.0) {
     36    slope = graphic[0].Npixels / image[0].range;
     37    start = graphic[0].Npixels * image[0].zero / image[0].range;
     38  } else {
     39    slope = 1.0;
     40    start = image[0].zero;
     41  }
     42
     43  // set up expansions
    2244  expand = expand_in = expand_out = 1.0;
    23   if (image[0].expand == 0) /* set up expansions */
     45  if (image[0].expand == 0)
    2446    image[0].expand = 1;
    2547  if (image[0].expand > 0) {
     
    3456  }
    3557
     58  // define the image boundaries
    3659  dx = image[0].picture.dx;
    3760  dy = image[0].picture.dy;
     
    6992
    7093  out_pix = (unsigned int *) image[0].picture.data;
    71   in_pix  = (unsigned char *) (matrix[0].buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
     94  imdata  = (float *) matrix[0].buffer;
     95  in_pix  = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
    7296
    7397  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    92116    if (expand_out == 1) {
    93117      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
    94         *out_pix = pixel[*in_pix2];
     118        pixelN = PixelLookup(*in_pix2);
     119        *out_pix = pixel[pixelN];
    95120      }
    96       /* *out_pix = *(pixel + *in_pix2);  */
    97121    }
    98122    else {
    99123      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) {
    100         pixvalue = pixel[*in_pix2];
     124        pixelN   = PixelLookup(*in_pix2);
     125        pixvalue = pixel[pixelN];
    101126        out_pix2 = out_pix;
    102127        for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
  • trunk/Ohana/src/kapa2/src/Remap8.c

    r13320 r13479  
    11# include "Ximage.h"
    2 # define FRAC(a) ((a) - (int)(a))
     2
     3static float slope = 1.0;
     4static float start = 0.0;
     5static int MaxValue = 255;
     6
     7// XXX inline this if needed
     8static int PixelLookup(float value) {
     9  int out;
     10  out = MIN (MAX (slope * value - start, 0), MaxValue);
     11  return (out);
     12}
    313
    414void Remap8 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
     
    717  int i_start, i_end, j_start, j_end;
    818  int dropback;  /* this is a bit of a kludge... */
    9   int dx, dy, DX, DY;
     19  int dx, dy, DX, DY, pixelN;
    1020  double expand, Rx, Ry, X, Y;
    1121  int expand_in, expand_out;
    1222  unsigned char *out_pix, *out_pix2;
    13   unsigned char *in_pix,  *in_pix2;
     23  float *imdata, *in_pix,  *in_pix2;
    1424  unsigned long pixel[256], pixvalue;
    1525  unsigned long back;
    1626
    17   for (i = 0; i < 256; i++) { /* set up pixel array */
     27  // local array for pixel values
     28  for (i = 0; i < 256; i++) {
    1829    pixel[i] = graphic[0].cmap[i].pixel;
    1930  }
    2031  back = graphic[0].back;
    2132
     33  // define the color transform parameters
     34  MaxValue = graphic[0].Npixels - 1;
     35  if (image[0].range != 0.0) {
     36    slope = graphic[0].Npixels / image[0].range;
     37    start = graphic[0].Npixels * image[0].zero / image[0].range;
     38  } else {
     39    slope = 1.0;
     40    start = image[0].zero;
     41  }
     42
     43  // set up expansions
    2244  expand = expand_in = expand_out = 1.0;
    2345  if (image[0].expand == 0) /* set up expansions */
     
    3456  }
    3557
     58  // define the image boundaries
    3659  dx = image[0].picture.dx;
    3760  dy = image[0].picture.dy;
    3861  DX = matrix[0].Naxis[0];
    3962  DY = matrix[0].Naxis[1];
     63
    4064  /* X,Y are the image coordinates of the first image pixel */
    4165  X = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
     
    6993
    7094  out_pix = (unsigned char *) image[0].picture.data;
    71   in_pix  = (unsigned char *) matrix[0].buffer + DX*(int)MAX(Y,0) + (int)MAX(X,0);
     95  imdata  = (float *) matrix[0].buffer;
     96  in_pix  = &imdata[(int)(DX*(int)MAX(Y,0) + (int)MAX(X,0))];
    7297
    7398  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
     
    92117    if (expand_out == 1) {
    93118      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
    94         *out_pix = pixel[*in_pix2];
     119        pixelN = PixelLookup(*in_pix2);
     120        *out_pix = pixel[pixelN];
    95121      }
    96       /* *out_pix = *(pixel + *in_pix2);  */
    97     }
    98     else {
     122    } else {
    99123      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) {
    100         pixvalue = pixel[*in_pix2];
     124        pixelN   = PixelLookup(*in_pix2);
     125        pixvalue = pixel[pixelN];
    101126        out_pix2 = out_pix;
    102127        for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
  • trunk/Ohana/src/kapa2/src/Resize.c

    r13320 r13479  
    22
    33// XXX Should there be a base command + KiiMessage command?
    4 int Resize () {
     4int Resize (int sock) {
    55 
    66  int i, Nsection;
     
    3030  for (i = 0; i < Nsection; i++) {
    3131      section = GetSectionByNumber (i);
    32       SetGraphSize (section);
    33       SetImageSize (section);
     32      SetSectionSizes (section);
    3433  }
    3534
  • trunk/Ohana/src/kapa2/src/SaveOverlay.c

    r13320 r13479  
    11# include "Ximage.h"
    22
    3 int SaveOverlay () {
     3int SaveOverlay (int sock) {
    44
    55  int i, N;
    6   char filename[256];
     6  char filename[256], *type;
    77  FILE *f;
    88  Section *section;
     
    1111  section = GetActiveSection();
    1212  image   = section->image;
     13  if (image == NULL) return (TRUE);
    1314
    1415  KiiScanMessage (sock, "%*s %d %s", &N, filename);
     
    2122
    2223  for (i = 0; i < image[0].overlay[N].Nobjects; i++) {
     24    type = KiiOverlayTypeByNumber (image[0].overlay[N].objects[i].type);
     25    if (type == NULL) continue;
    2326    fprintf (f, "%s %lf %lf %lf %lf\n",
    24              image[0].overlay[N].objects[i].type,
     27             type,
    2528             image[0].overlay[N].objects[i].x,
    2629             image[0].overlay[N].objects[i].y,
     
    3134  return (TRUE);
    3235}
     36
     37/* this is asymmetric with LoadOverlay.c.  In that case, the client reads the file and sends
     38 * the overlay objects to kapa.  In this case, kapa writes the file directly...
     39 */
  • trunk/Ohana/src/kapa2/src/Sections.c

    r13320 r13479  
    2424
    2525  if (section == NULL) return;
    26   if (section[0].graph != NULL) FreeGraph (section[0].graph);
    27   // if (section[0].image != NULL) FreeImage (section[0].image);
    28   if (section[0].name  != NULL) free (section[0].name);
     26  FreeGraph (section[0].graph);
     27  FreeImage (section[0].image);
     28  FREE (section[0].name);
    2929  free (section);
    3030}
     
    4242}
    4343
    44 // XXX how to set the section type?
    45 // XXX set active section on Add?
    4644Section *AddSection (char *name, float x, float y, float dx, float dy) {
    4745
     
    116114}
    117115
    118 int ListSection () {
     116int ListSection (int sock) {
    119117 
    120118  int i, ThisSection;
     
    149147  return (TRUE);
    150148}
     149
     150void SetSectionSizes (Section *section) {
     151
     152    SetGraphSize (section);
     153    SetImageSize (section);
     154    return;
     155}
     156
     157// return TRUE even for nonsense cases to avoid quitting kapa
     158int MoveSection (int sock) {
     159
     160  int i, N;
     161  char name[128];
     162  char direction[16];
     163  Section *tmpSection = NULL;
     164
     165  KiiScanMessage (sock, "%s %s", name, direction);
     166 
     167  N = GetSectionByName (name);
     168  if (N < 0) {
     169    fprintf (stderr, "section %s not found\n", name);
     170    return (TRUE);
     171  }
     172
     173  if (!strcasecmp (direction, "up")) {
     174      if (N < 0) return (TRUE);
     175      if (N > Nsections - 2) return (TRUE);
     176      tmpSection = sections[N];
     177      sections[N] = sections[N+1];
     178      sections[N+1] = tmpSection;
     179      Refresh (1);
     180      return (TRUE);
     181  }
     182
     183  if (!strcasecmp (direction, "down")) {
     184      if (N < 1) return (TRUE);
     185      if (N > Nsections - 1) return (TRUE);
     186      tmpSection = sections[N];
     187      sections[N] = sections[N-1];
     188      sections[N-1] = tmpSection;
     189      Refresh (1);
     190      return (TRUE);
     191  }
     192
     193  if (!strcasecmp (direction, "top")) {
     194      if (N < 0) return (TRUE);
     195      if (N > Nsections - 2) return (TRUE);
     196      tmpSection = sections[N];
     197      for (i = N; i < Nsections - 1; i++) {
     198        sections[i] = sections[i+1];
     199      }
     200      sections[i] = tmpSection;
     201      Refresh (1);
     202      return (TRUE);
     203  }
     204
     205  if (!strcasecmp (direction, "bottom")) {
     206      if (N < 1) return (TRUE);
     207      if (N > Nsections - 1) return (TRUE);
     208      tmpSection = sections[N];
     209      for (i = N; i >= 1; i--) {
     210        sections[i] = sections[i-1];
     211      }
     212      sections[i] = tmpSection;
     213      Refresh (1);
     214      return (TRUE);
     215  }
     216  fprintf (stderr, "unknown direction %s for MoveSection\n", direction);
     217  return (TRUE);
     218}
  • trunk/Ohana/src/kapa2/src/SetFont.c

    r13320 r13479  
    11# include "Ximage.h"
    22
    3 int SetFont () {
     3int SetFont (int sock) {
    44 
    55  char name[64];
  • trunk/Ohana/src/kapa2/src/SetGraphSize.c

    r13320 r13479  
    77
    88  int fontsize, bump, Nc;
     9  int textpad, textdY, WdY;
    910  double PADx, PADy, Dx, Dy;
    1011  double PXm, PXp, PYm, PYp;
     
    3233  PYp = (graph[0].axis[2].islabel) ? 4*fontsize : 0;
    3334 
    34   /* size of the graph in Xwindow coordinates */
     35  /* basic size of the graph in Xwindow coordinates */
    3536  X0 = PADx + PXm + (Dx * section[0].x);
    3637  Y0 = PADy + PYm + (Dy * section[0].y);
    3738  dX = (Dx * section[0].dx) - PXp - PXm;
    3839  dY = (Dy * section[0].dy) - PYp - PYm;
     40
     41  // if we are tied to an image, make mods as needed
     42  if (section->image) {
     43    textpad = graphic[0].font[0].ascent;
     44    textdY = 6*textpad + 7*PAD1;
     45    WdY = MAX (ZOOM_Y, textdY + 2*BUTTON_HEIGHT + PAD1);
     46
     47    switch (section->image->location) {
     48      case 1:
     49        Y0 = graphic[0].dy * section[0].y + 2*PAD1 + WdY + 2; // tied to image in Y
     50        dY = graphic[0].dy * section[0].dy - 5*PAD1 - WdY - COLORPAD + 1;
     51        break;
     52      case 3:
     53        dY = graphic[0].dy * section[0].dy - 5*PAD1 - WdY - COLORPAD - PADy - PYm;
     54        break;
     55      case 2:
     56        X0 = graphic[0].dx * section[0].x  + 2*PAD1 + ZOOM_X;
     57        dX = graphic[0].dx * section[0].dx - 3*PAD1 - ZOOM_X;
     58        break;
     59      case 4:
     60        dX = graphic[0].dx * section[0].dx - 3*PAD1 - ZOOM_X - PADx - PXm;
     61        break;
     62    }
     63  }
    3964
    4065  /* define locations of coordinate axes */
  • trunk/Ohana/src/kapa2/src/SetImageSize.c

    r13320 r13479  
    77void SetImageSize (Section *section) {
    88
     9  int Xs, Ys, Xe, Ye, dX, dY;
     10  int textpad, textdY, WdY;
    911  KapaImageWidget *image;
     12  KapaGraphWidget *graph;
    1013  Graphic *graphic;
    1114
     
    1316  image = section->image;
    1417  if (image == NULL) return;
     18  graph = section->graph;
    1519
    1620  graphic = GetGraphic ();
    1721
    18   image[0].cmapbar.dx = graphic[0].dx - 2*PAD1;
    19   image[0].cmapbar.dy = COLORPAD;
    20   image[0].cmapbar.x = PAD1;
    21   image[0].cmapbar.y = PAD1;
    22 
    23   image[0].zoom.dx = ZOOM_X;
    24   image[0].zoom.dy = ZOOM_Y;
    25   image[0].zoom.x = graphic[0].dx - PAD1 - ZOOM_X;
    26   image[0].zoom.y = image[0].cmapbar.y + image[0].cmapbar.dy + PAD2;
    27 
    28   image[0].picture.dx = image[0].zoom.x - 2*PAD1 - 25;
    29   image[0].picture.dy = graphic[0].dy - 2*PAD1 - PAD2 - COLORPAD - 25;
    30   image[0].picture.x = PAD1 + 25;
    31   image[0].picture.y = PAD1 + PAD2 + COLORPAD;
    32 
    33   /** everything below is tied in x-dir to the zoom box **/
    34   image[0].text_x = image[0].zoom.x;
    35   image[0].text_y = image[0].zoom.y + image[0].zoom.dy + PAD2;
    36 
    37   /*  image[0].PS_button.y = graphic[0].dy - BUTTON_HEIGHT - PAD1; */
    38   image[0].PS_button.x = image[0].zoom.x + 5;
    39   image[0].PS_button.y = 2*ZOOM_Y;
    40 
    41   /** everything below is tied to the PS_button in y-dir **/
    42   image[0].grey_button.x = image[0].PS_button.x + image[0].PS_button.dx + PAD1;
    43   image[0].grey_button.y = image[0].PS_button.y;
    44 
    45   image[0].rainbow_button.x = image[0].grey_button.x + image[0].grey_button.dx + PAD1;
    46   image[0].rainbow_button.y = image[0].PS_button.y;
    47 
    48   image[0].puns_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
    49   image[0].puns_button.y = image[0].PS_button.y;
    50 
    51   image[0].recenter_button.x = image[0].puns_button.x + image[0].puns_button.dx + PAD1;
    52   image[0].recenter_button.y = image[0].PS_button.y;
    53 
    54   image[0].overlay_button[0].x = image[0].zoom.x + 5;
    55   image[0].overlay_button[0].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
     22  /* the image is placed within the graphic window in region specified by section */
     23  Xs = graphic[0].dx * section[0].x;
     24  Ys = graphic[0].dy * (1 - section[0].y - section[0].dy);
     25  dX = graphic[0].dx * section[0].dx;
     26  dY = graphic[0].dy * section[0].dy;
     27
     28  switch (image[0].location) {
     29    case 0:
     30      if (section->graph) {
     31          image[0].picture.x  = graph[0].axis[0].fx;
     32          image[0].picture.y  = graph[0].axis[1].fy + graph[0].axis[1].dfy;
     33          image[0].picture.dx = MAX(graph[0].axis[0].dfx + 1, 1);
     34          image[0].picture.dy = MAX(fabs(graph[0].axis[1].dfy) - 1, 1);
     35      } else {
     36          image[0].picture.x  = Xs + PAD1;
     37          image[0].picture.y  = Ys + PAD1;
     38          image[0].picture.dx = dX - 2*PAD1;
     39          image[0].picture.dy = dY - 2*PAD1;
     40      }
     41      if (USE_XWINDOW) CreatePicture (image, graphic);
     42      Remap (graphic, image, &image[0].matrix);
     43      return;
     44
     45    case 1:
     46      textpad = graphic[0].font[0].ascent;
     47      textdY = 6*textpad + 7*PAD1;
     48      WdY = MAX (ZOOM_Y, textdY + 2*BUTTON_HEIGHT + PAD1);
     49
     50      if (section->graph) {
     51          image[0].picture.x = graph[0].axis[0].fx;
     52          image[0].picture.y = Ys + 2*PAD1 + COLORPAD;
     53          image[0].picture.dx = graph[0].axis[0].dfx;
     54          image[0].picture.dy = dY - 5*PAD1 - WdY - COLORPAD;
     55      } else {
     56          image[0].picture.x  = Xs + PAD1;
     57          image[0].picture.y  = Ys + 2*PAD1 + COLORPAD;
     58          image[0].picture.dx = dX - 2*PAD1;
     59          image[0].picture.dy = dY - 5*PAD1 - WdY - COLORPAD;
     60      }
     61
     62      image[0].cmapbar.dx = dX - 2*PAD1;
     63      image[0].cmapbar.dy = COLORPAD;
     64      image[0].cmapbar.x = Xs + PAD1;
     65      image[0].cmapbar.y = Ys + PAD1;
     66
     67      // XXX zoom should scale somewhat with the image? (with a min and a max)
     68      // XXX actually, it is limited by the buttons and status region
     69      image[0].zoom.dx = ZOOM_X;
     70      image[0].zoom.dy = ZOOM_Y;
     71      image[0].zoom.x = Xs + PAD1;
     72      image[0].zoom.y = image[0].picture.y + image[0].picture.dy + PAD1;
     73
     74      /** everything below is tied in x-dir to the zoom box **/
     75      image[0].text_x = image[0].zoom.x + image[0].zoom.dx + PAD1;
     76      image[0].text_y = image[0].zoom.y;
     77      image[0].text_dx = ZOOM_X;
     78      image[0].text_dy = 6*textpad + 7*PAD1;
     79
     80      image[0].overlay_button[0].x = image[0].text_x;
     81      image[0].overlay_button[0].y = image[0].text_y + image[0].text_dy + PAD1;
    5682   
    57   image[0].overlay_button[1].x = image[0].overlay_button[0].x + image[0].overlay_button[0].dx + PAD1;
    58   image[0].overlay_button[1].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
    59 
    60   image[0].overlay_button[2].x = image[0].overlay_button[1].x + image[0].overlay_button[1].dx + PAD1;
    61   image[0].overlay_button[2].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
    62 
    63   image[0].overlay_button[3].x = image[0].overlay_button[2].x + image[0].overlay_button[2].dx + PAD1;
    64   image[0].overlay_button[3].y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
    65 
    66   image[0].hms_button.x = image[0].overlay_button[3].x + image[0].overlay_button[3].dx + PAD1;
    67   image[0].hms_button.y = image[0].PS_button.y - BUTTON_HEIGHT - PAD1;
     83      image[0].overlay_button[1].x = image[0].overlay_button[0].x + image[0].overlay_button[0].dx + PAD1;
     84      image[0].overlay_button[1].y = image[0].overlay_button[0].y;
     85
     86      image[0].overlay_button[2].x = image[0].overlay_button[1].x + image[0].overlay_button[1].dx + PAD1;
     87      image[0].overlay_button[2].y = image[0].overlay_button[0].y;
     88
     89      image[0].overlay_button[3].x = image[0].overlay_button[2].x + image[0].overlay_button[2].dx + PAD1;
     90      image[0].overlay_button[3].y = image[0].overlay_button[0].y;
     91
     92      image[0].hms_button.x = image[0].overlay_button[3].x + image[0].overlay_button[3].dx + PAD1;
     93      image[0].hms_button.y = image[0].overlay_button[0].y;
     94
     95      image[0].PS_button.x = image[0].text_x;
     96      image[0].PS_button.y = image[0].overlay_button[0].y + BUTTON_HEIGHT + PAD1;
     97
     98      /** everything below is tied to the PS_button in y-dir + the neighbor in x-dir **/
     99      image[0].grey_button.x = image[0].PS_button.x + image[0].PS_button.dx + PAD1;
     100      image[0].grey_button.y = image[0].PS_button.y;
     101
     102      image[0].rainbow_button.x = image[0].grey_button.x + image[0].grey_button.dx + PAD1;
     103      image[0].rainbow_button.y = image[0].PS_button.y;
     104
     105      image[0].puns_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
     106      image[0].puns_button.y = image[0].PS_button.y;
     107
     108      image[0].recenter_button.x = image[0].puns_button.x + image[0].puns_button.dx + PAD1;
     109      image[0].recenter_button.y = image[0].PS_button.y;
     110      break;
     111
     112    case 3:
     113      textpad = graphic[0].font[0].ascent;
     114      textdY = 6*textpad + 7*PAD1;
     115      WdY = MAX (ZOOM_Y, textdY + 2*BUTTON_HEIGHT + PAD1);
     116
     117      if (section->graph) {
     118        image[0].picture.x = graph[0].axis[0].fx;
     119        image[0].picture.y = graph[0].axis[1].fy + graph[0].axis[1].dfy;
     120        image[0].picture.dx = MAX(graph[0].axis[0].dfx, 1);
     121        image[0].picture.dy = MAX(fabs(graph[0].axis[1].dfy) - 1, 1);
     122      } else {
     123        image[0].picture.dx = dX - 2*PAD1;
     124        image[0].picture.dy = dY - 5*PAD1 - WdY - COLORPAD;
     125        image[0].picture.x = Xs + PAD1;
     126        image[0].picture.y = Ys + 4*PAD1 + COLORPAD + WdY;
     127      }
     128
     129      image[0].cmapbar.dx = dX - 2*PAD1;
     130      image[0].cmapbar.dy = COLORPAD;
     131      image[0].cmapbar.x = Xs + PAD1;
     132      image[0].cmapbar.y = Ys + PAD1;
     133
     134      // XXX zoom should scale somewhat with the image? (with a min and a max)
     135      // XXX actually, it is limited by the buttons and status region
     136      image[0].zoom.dx = ZOOM_X;
     137      image[0].zoom.dy = ZOOM_Y;
     138      image[0].zoom.x = Xs + PAD1;
     139      image[0].zoom.y = Ys + 2*PAD1 + COLORPAD;
     140
     141      /** everything below is tied in x-dir to the zoom box **/
     142      image[0].text_x = image[0].zoom.x + image[0].zoom.dx + PAD1;
     143      image[0].text_y = image[0].zoom.y;
     144      image[0].text_dx = ZOOM_X;
     145      image[0].text_dy = 6*textpad + 7*PAD1;
     146
     147      image[0].overlay_button[0].x = image[0].text_x;
     148      image[0].overlay_button[0].y = image[0].text_y + image[0].text_dy + PAD1;
     149   
     150      image[0].overlay_button[1].x = image[0].overlay_button[0].x + image[0].overlay_button[0].dx + PAD1;
     151      image[0].overlay_button[1].y = image[0].overlay_button[0].y;
     152
     153      image[0].overlay_button[2].x = image[0].overlay_button[1].x + image[0].overlay_button[1].dx + PAD1;
     154      image[0].overlay_button[2].y = image[0].overlay_button[0].y;
     155
     156      image[0].overlay_button[3].x = image[0].overlay_button[2].x + image[0].overlay_button[2].dx + PAD1;
     157      image[0].overlay_button[3].y = image[0].overlay_button[0].y;
     158
     159      image[0].hms_button.x = image[0].overlay_button[3].x + image[0].overlay_button[3].dx + PAD1;
     160      image[0].hms_button.y = image[0].overlay_button[0].y;
     161
     162      image[0].PS_button.x = image[0].text_x;
     163      image[0].PS_button.y = image[0].overlay_button[0].y + BUTTON_HEIGHT + PAD1;
     164
     165      /** everything below is tied to the PS_button in y-dir + the neighbor in x-dir **/
     166      image[0].grey_button.x = image[0].PS_button.x + image[0].PS_button.dx + PAD1;
     167      image[0].grey_button.y = image[0].PS_button.y;
     168
     169      image[0].rainbow_button.x = image[0].grey_button.x + image[0].grey_button.dx + PAD1;
     170      image[0].rainbow_button.y = image[0].PS_button.y;
     171
     172      image[0].puns_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
     173      image[0].puns_button.y = image[0].PS_button.y;
     174
     175      image[0].recenter_button.x = image[0].puns_button.x + image[0].puns_button.dx + PAD1;
     176      image[0].recenter_button.y = image[0].PS_button.y;
     177      break;
     178
     179    case 2:
     180
     181      if (section->graph) {
     182        image[0].picture.x = Xs + 2*PAD1 + ZOOM_X;
     183        image[0].picture.y = graph[0].axis[1].fy + graph[0].axis[1].dfy;
     184        image[0].picture.dx = dX - 3*PAD1 - ZOOM_X;
     185        image[0].picture.dy = MAX(fabs(graph[0].axis[1].dfy) - 1, 1);
     186      } else {
     187        image[0].picture.dx = dX - 3*PAD1 - ZOOM_X;
     188        image[0].picture.dy = dY - 3*PAD1 - COLORPAD;
     189        image[0].picture.x = Xs + 2*PAD1 + ZOOM_X;
     190        image[0].picture.y = Ys + 2*PAD1 + COLORPAD;
     191      }
     192
     193      image[0].cmapbar.dx = dX - 2*PAD1;
     194      image[0].cmapbar.dy = COLORPAD;
     195      image[0].cmapbar.x = Xs + PAD1;
     196      image[0].cmapbar.y = Ys + PAD1;
     197
     198      // XXX zoom should scale somewhat with the image? (with a min and a max)
     199      // XXX actually, it is limited by the buttons and status region
     200      image[0].zoom.dx = ZOOM_X;
     201      image[0].zoom.dy = ZOOM_Y;
     202      image[0].zoom.x = Xs + PAD1;
     203      image[0].zoom.y = image[0].picture.y;
     204
     205      /** everything below is tied in x-dir to the zoom box **/
     206      textpad = graphic[0].font[0].ascent;
     207      image[0].text_x = image[0].zoom.x;
     208      image[0].text_y = image[0].zoom.y + image[0].zoom.dy + PAD1;
     209      image[0].text_dx = ZOOM_X;
     210      image[0].text_dy = 6*textpad + 7*PAD1;
     211
     212      image[0].overlay_button[0].x = image[0].text_x;
     213      image[0].overlay_button[0].y = image[0].text_y + image[0].text_dy + PAD1;
     214   
     215      image[0].overlay_button[1].x = image[0].overlay_button[0].x + image[0].overlay_button[0].dx + PAD1;
     216      image[0].overlay_button[1].y = image[0].overlay_button[0].y;
     217
     218      image[0].overlay_button[2].x = image[0].overlay_button[1].x + image[0].overlay_button[1].dx + PAD1;
     219      image[0].overlay_button[2].y = image[0].overlay_button[0].y;
     220
     221      image[0].overlay_button[3].x = image[0].overlay_button[2].x + image[0].overlay_button[2].dx + PAD1;
     222      image[0].overlay_button[3].y = image[0].overlay_button[0].y;
     223
     224      image[0].hms_button.x = image[0].overlay_button[3].x + image[0].overlay_button[3].dx + PAD1;
     225      image[0].hms_button.y = image[0].overlay_button[0].y;
     226
     227      image[0].PS_button.x = image[0].zoom.x;
     228      image[0].PS_button.y = image[0].overlay_button[0].y + BUTTON_HEIGHT + PAD1;
     229
     230      /** everything below is tied to the PS_button in y-dir + the neighbor in x-dir **/
     231      image[0].grey_button.x = image[0].PS_button.x + image[0].PS_button.dx + PAD1;
     232      image[0].grey_button.y = image[0].PS_button.y;
     233
     234      image[0].rainbow_button.x = image[0].grey_button.x + image[0].grey_button.dx + PAD1;
     235      image[0].rainbow_button.y = image[0].PS_button.y;
     236
     237      image[0].puns_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
     238      image[0].puns_button.y = image[0].PS_button.y;
     239
     240      image[0].recenter_button.x = image[0].puns_button.x + image[0].puns_button.dx + PAD1;
     241      image[0].recenter_button.y = image[0].PS_button.y;
     242      break;
     243
     244    case 4:
     245
     246      if (section->graph) {
     247        image[0].picture.x = graph[0].axis[0].fx;
     248        image[0].picture.y = graph[0].axis[1].fy + graph[0].axis[1].dfy;
     249        image[0].picture.dx = dX - 3*PAD1 - ZOOM_X - graph[0].axis[0].fx;
     250        image[0].picture.dy = MAX(fabs(graph[0].axis[1].dfy) - 1, 1);
     251      } else {
     252        image[0].picture.dx = dX - 3*PAD1 - ZOOM_X;
     253        image[0].picture.dy = dY - 3*PAD1 - COLORPAD;
     254        image[0].picture.x = Xs + PAD1;
     255        image[0].picture.y = Ys + 2*PAD1 + COLORPAD;
     256      }
     257
     258      image[0].cmapbar.dx = dX - 2*PAD1;
     259      image[0].cmapbar.dy = COLORPAD;
     260      image[0].cmapbar.x = Xs + PAD1;
     261      image[0].cmapbar.y = Ys + PAD1;
     262
     263      // XXX zoom should scale somewhat with the image? (with a min and a max)
     264      // XXX actually, it is limited by the buttons and status region
     265      image[0].zoom.dx = ZOOM_X;
     266      image[0].zoom.dy = ZOOM_Y;
     267      image[0].zoom.x = image[0].picture.x + image[0].picture.dx + PAD1;
     268      image[0].zoom.y = image[0].picture.y;
     269
     270      /** everything below is tied in x-dir to the zoom box **/
     271      textpad = graphic[0].font[0].ascent;
     272      image[0].text_x = image[0].zoom.x;
     273      image[0].text_y = image[0].zoom.y + image[0].zoom.dy + PAD1;
     274      image[0].text_dx = ZOOM_X;
     275      image[0].text_dy = 6*textpad + 7*PAD1;
     276
     277      image[0].overlay_button[0].x = image[0].text_x;
     278      image[0].overlay_button[0].y = image[0].text_y + image[0].text_dy + PAD1;
     279   
     280      image[0].overlay_button[1].x = image[0].overlay_button[0].x + image[0].overlay_button[0].dx + PAD1;
     281      image[0].overlay_button[1].y = image[0].overlay_button[0].y;
     282
     283      image[0].overlay_button[2].x = image[0].overlay_button[1].x + image[0].overlay_button[1].dx + PAD1;
     284      image[0].overlay_button[2].y = image[0].overlay_button[0].y;
     285
     286      image[0].overlay_button[3].x = image[0].overlay_button[2].x + image[0].overlay_button[2].dx + PAD1;
     287      image[0].overlay_button[3].y = image[0].overlay_button[0].y;
     288
     289      image[0].hms_button.x = image[0].overlay_button[3].x + image[0].overlay_button[3].dx + PAD1;
     290      image[0].hms_button.y = image[0].overlay_button[0].y;
     291
     292      image[0].PS_button.x = image[0].zoom.x;
     293      image[0].PS_button.y = image[0].overlay_button[0].y + BUTTON_HEIGHT + PAD1;
     294
     295      /** everything below is tied to the PS_button in y-dir + the neighbor in x-dir **/
     296      image[0].grey_button.x = image[0].PS_button.x + image[0].PS_button.dx + PAD1;
     297      image[0].grey_button.y = image[0].PS_button.y;
     298
     299      image[0].rainbow_button.x = image[0].grey_button.x + image[0].grey_button.dx + PAD1;
     300      image[0].rainbow_button.y = image[0].PS_button.y;
     301
     302      image[0].puns_button.x = image[0].rainbow_button.x + image[0].rainbow_button.dx + PAD1;
     303      image[0].puns_button.y = image[0].PS_button.y;
     304
     305      image[0].recenter_button.x = image[0].puns_button.x + image[0].puns_button.dx + PAD1;
     306      image[0].recenter_button.y = image[0].PS_button.y;
     307      break;
     308
     309    default:
     310      abort ();
     311      break;
     312  }
    68313
    69314  if (USE_XWINDOW) {
  • trunk/Ohana/src/kapa2/src/SetLimits.c

    r13320 r13479  
    11# include "Ximage.h"
    22
    3 int SetLimits () {
     3int SetLimits (int sock) {
    44 
    55  int i;
     
    1414
    1515  section = GetActiveSection();
    16   if (section->graph == NULL) return (TRUE);
     16  if (section->graph == NULL) {
     17    section->graph = InitGraph ();
     18    SetSectionSizes (section);
     19  }
    1720  graph = section->graph;
    18 
     21 
    1922  graph[0].axis[2].min = graph[0].axis[0].min = xmin;
    2023  graph[0].axis[2].max = graph[0].axis[0].max = xmax;
     
    3235  Refresh (1);
    3336
    34   return (TRUE);
    35  
     37  return (TRUE); 
    3638}
    3739
    38 int GetLimits () {
     40int GetLimits (int sock) {
    3941 
    4042  double dX, dY;
  • trunk/Ohana/src/kapa2/src/SetNormalHints.c

    r13320 r13479  
    1717
    1818  // XXX : can we drop the position flag
    19   sizehints[0].flags = USPosition | USSize | PMinSize;
     19  // sizehints[0].flags = USPosition | USSize | PMinSize;
     20  sizehints[0].flags = USSize | PMinSize;
    2021
    2122  sizehints[0].base_width = graphic->dx;
  • trunk/Ohana/src/kapa2/src/SetSection.c

    r13320 r13479  
    22
    33// set active section
    4 int SetSection () {
     4int SetSection (int sock) {
    55 
    66  int N;
  • trunk/Ohana/src/kapa2/src/UpdatePointer.c

    r13320 r13479  
    66  int textpad;
    77  double  x, y, z;
     8  float *data;
    89  char line[100];
    910  Section *section;
     
    1314  section = GetActiveSection();
    1415  image   = section->image;
     16  if (image == NULL) return (TRUE);
     17  if (!image[0].location) return (TRUE);
    1518
    1619  if (image[0].MovePointer && InPicture ((XButtonEvent *)event, &image[0].picture)) {
    1720
     21    data = (float *) image[0].matrix.buffer;
    1822    Screen_to_Image (&x, &y, (double)event[0].x, (double)event[0].y, image);
    1923
    20     if ((x >= 0) && (x < image[0].matrix.Naxis[0]) && (y >= 0) && (y < image[0].matrix.Naxis[1])) {
    21       /*
    22       X = event[0].x - image[0].picture.x;
    23       Y = event[0].y - image[0].picture.y;
    24       pix = MIN (MAX (X + Y*image[0].picture.dx, 0), image[0].picture.dx*image[0].picture.dy - 1);
    25       z = image[0].range * image[0].picture.data[pix] / image[0].Npixels + image[0].zero;
    26       */
    27       z = -1;
    28     }
    29     else
    30       z = -1;
     24    z = -1;
     25    if (x < 0) goto skip;
     26    if (x >= image[0].matrix.Naxis[0]) goto skip;
     27    if (y < 0) goto skip;
     28    if (y >= image[0].matrix.Naxis[1]) goto skip;
     29    z = data[(int)(y)*image[0].matrix.Naxis[0] + (int)(x)];
     30
     31  skip:
    3132    image[0].x = x;
    3233    image[0].y = y;
     
    4344    CrossHairs (graphic, image);
    4445    XFlush (graphic[0].display);
    45    
    4646  }
    4747 
     
    5454    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore);
    5555    bzero (line, 100);
    56     sprintf (line, "%25.2f", z);
     56    sprintf (line, "%22.3f", z);
    5757    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    5858                 image[0].text_x + PAD1, image[0].text_y + textpad + PAD1,
  • trunk/Ohana/src/kapa2/src/UpdateStatusBox.c

    r13320 r13479  
    1414    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].back);
    1515    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc,
    16                     image[0].text_x, image[0].text_y, ZOOM_X, 6*textpad+7*PAD1); 
     16                    image[0].text_x, image[0].text_y, image[0].text_dx, image[0].text_dy); 
    1717    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore);
    1818    XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc,
    19                     image[0].text_x, image[0].text_y, ZOOM_X, 6*textpad+7*PAD1);
     19                    image[0].text_x, image[0].text_y, image[0].text_dx, image[0].text_dy);
    2020 
    2121    bzero (line, 100);
     
    3131   
    3232    bzero (line, 100);
    33     sprintf (line, "(%s)                                          ", image[0].buffer_name);
     33    sprintf (line, "(%s)                                          ", image[0].name);
    3434    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    3535                 image[0].text_x + PAD1, image[0].text_y + 6*textpad + 6*PAD1, line, 25);
     
    3838    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].back);
    3939    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc,
    40                     image[0].text_x + 1, image[0].text_y + 1, ZOOM_X - 2, 3*textpad+3*PAD1 +1); 
     40                    image[0].text_x+1, image[0].text_y+1, image[0].text_dx-2, image[0].text_dy-2); 
    4141    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore);
    4242  }
    4343  bzero (line, 100);
    44   sprintf (line, "%25.3f", z);
     44  sprintf (line, "%22.3f", z);
    4545  XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    4646               image[0].text_x + PAD1, image[0].text_y + textpad + PAD1, line, strlen(line));
    4747 
    4848  bzero (line, 100);
    49   sprintf (line, "%12.1f %12.1f", x, y);
     49  sprintf (line, "%10.1f %10.1f", x, y);
    5050  XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    5151               image[0].text_x + PAD1, image[0].text_y + 2*textpad + 2*PAD1, line, strlen(line));
     
    5353  bzero (line, 100);
    5454  if (image[0].DecimalDegrees) {
    55     sprintf (line, "%12.6f %12.6f", ra, dec);
     55    sprintf (line, "%10.6f %10.6f", ra, dec);
    5656  } else {
    5757    hh_hms (line, ra, dec, ':');
  • trunk/Ohana/src/kapa2/src/bDrawIt.c

    r13320 r13479  
    2222      section = GetSectionByNumber (i);
    2323      bDrawGraph (section->graph);
    24       // bDrawImage (section->graph);
     24      // bDrawImage (section->image);
    2525  }
    2626
  • trunk/Ohana/src/kapa2/src/bDrawOverlay.c

    r13320 r13479  
    2323    expand = fabs((double)image[0].expand);
    2424  }
    25   /*
    26   X = 0.5*image[0].matrix.Naxis[0] - expand*((int)(0.5*image[0].picture.dx + 0.5) - 0.0) - image[0].X;
    27   Y = 0.5*image[0].matrix.Naxis[1] - expand*((int)(0.5*image[0].picture.dy + 0.5) - 0.0) - image[0].Y; 
    28   X0 =  (image[0].X + 1 - (int)(0.5*image[0].matrix.Naxis[0] + 0.5) - X + (int)X)/expand + image[0].picture.x + 0.5*image[0].picture.dx;
    29   Y0 =  (image[0].Y + 1 - (int)(0.5*image[0].matrix.Naxis[1] + 0.5) - Y + (int)Y)/expand + image[0].picture.y + 0.5*image[0].picture.dy;
    30   */
    3125
    3226  Image_to_Screen (&X0, &Y0, 0.0, 0.0, image);
     
    6256       for a BOX (x, y) is the center, (dx, dy) is the width */
    6357
    64     if (!strcasecmp (image[0].overlay[N].objects[i].type, "LINE")) {
    65       bDrawLine (X, Y, (X+dX), (Y+dY));
    66       continue;
     58    switch (image[0].overlay[N].objects[i].type) {
     59      case KII_OVERLAY_LINE:
     60        bDrawLine (X, Y, (X+dX), (Y+dY));
     61        break;
     62      case KII_OVERLAY_TEXT:
     63        bDrawRotText (X, Y, image[0].overlay[N].objects[i].text, 8, 0.0);
     64        break;
     65      case KII_OVERLAY_BOX:
     66        dx = MAX (abs(dX),2) / 2;
     67        dy = MAX (abs(dY),2) / 2;
     68        bDrawRectOpen ((X-dx), (Y-dy), (X+dx), (Y+dy));
     69        // bDrawRectOpen ((X-dx), (Y-dy), (X), (Y));
     70        break;
     71      case KII_OVERLAY_CIRCLE:
     72        dx = MAX (abs(dX),2);
     73        dy = MAX (abs(dY),2);
     74        bDrawArc (X, Y, dx, dy, 0, 360);
     75        break;
     76      default:
     77        fprintf (stderr, "skipping unknown object\n");
     78        break;
    6779    }
    68     if (!strcasecmp (image[0].overlay[N].objects[i].type, "TEXT")) {
    69       bDrawRotText (X, Y, image[0].overlay[N].objects[i].text, 8, 0.0);
    70       continue;
    71     }
    72     if (!strcasecmp (image[0].overlay[N].objects[i].type, "BOX")) {
    73       dx = MAX (abs(dX),2) / 2;
    74       dy = MAX (abs(dY),2) / 2;
    75       bDrawRectOpen ((X-dx), (Y-dy), (X+dx), (Y+dy));
    76       // bDrawRectOpen ((X-dx), (Y-dy), (X), (Y));
    77        continue;
    78     }
    79     if (!strcasecmp (image[0].overlay[N].objects[i].type, "CIRCLE")) {
    80       dx = MAX (abs(dX),2);
    81       dy = MAX (abs(dY),2);
    82       bDrawArc (X, Y, dx, dy, 0, 360);
    83       continue;
    84     }
    85     fprintf (stderr, "don't know %s, skipping (PO)\n", image[0].overlay[N].objects[i].type);
    8680  }
    8781 
  • trunk/Ohana/src/kapa2/src/kapa.c

    r13320 r13479  
    77  SetUpGraphic (&argc, argv);
    88
    9   // XXX get socket connection here?
    10 
    119  InitLayout (argc, argv);
    1210  EventLoop ();
  • trunk/Ohana/src/kii/event/CheckPipe.c

    r5700 r13479  
    123123  }
    124124
     125  /* is this no longer used ?
    125126  if (!strcmp (buffer, "NPIX")) {
    126127    sprintf (buffer, "NPIX:   %8d", layout[0].Npixels);
     
    128129    return (TRUE);
    129130  }
     131  */
    130132
    131133  fprintf (stderr, "unknown signal %s\n", buffer);
  • trunk/Ohana/src/libkapa/Makefile

    r12879 r13479  
    2929$(SRC)/KiiConvert.$(ARCH).o \
    3030$(SRC)/KapaWindow.$(ARCH).o \
    31 $(SRC)/KapaColors.$(ARCH).o
     31$(SRC)/KapaColors.$(ARCH).o \
     32$(SRC)/KapaOpen.$(ARCH).o
    3233
    3334DRAW = \
  • trunk/Ohana/src/libkapa/include/kapa.h

    r13326 r13479  
    22# define KAPA_H
    33
     4/* linux is happy with this, not solaris */
     5# include <netinet/ip.h>
     6# include <netdb.h>
     7# include <arpa/inet.h>
     8
     9# include <sys/types.h>
     10# include <sys/socket.h>
    411# include <X11/Xlib.h>
    512# include <png.h>
    613# include <dvo.h>
     14
     15typedef struct sockaddr_in KapaSockAddress;
    716
    817typedef struct {
     
    1120  int Nx;
    1221  int Ny;
    13   char *file;
    14   char *name;
    1522} KiiImage;
    1623
    1724typedef struct {
    18   double zero;
    19   double range;
    20   int logflux;
    21 } KiiDisplayMode;
     25  float x;
     26  float y;
     27  float dx;
     28  float dy;
     29  int type;
     30} KiiOverlayBase;
    2231
    2332typedef struct {
     
    7382
    7483typedef struct {
     84  int logflux;
     85  double zero, range;
     86  char name[1024];
     87  char file[1024];
     88} KapaImageData;
     89
     90typedef struct {
    7591  int dx, dy, ascent;
    7692  unsigned char *bits;
     
    98114int KiiSendData (int device, char *data, int Nbytes);
    99115char *KiiRecvData (int device);
     116int KiiWaitAnswer (int device, char *expect);
    100117
    101118/* KiiOpen.c */
     
    105122
    106123/* KiiPicture.c */
    107 int KiiNewPicture1D (int fd, KiiImage *image, KiiDisplayMode *mode, Coords *coords);
    108 int KiiNewPicture2D (int fd, KiiImage *image, KiiDisplayMode *mode, Coords *coords);
     124int KiiNewPicture1D (int fd, KiiImage *image, KapaImageData *data, Coords *coords);
     125int KiiNewPicture2D (int fd, KiiImage *image, KapaImageData *data, Coords *coords);
    109126
    110127/* KiiOverlay.c */
     
    125142int KiiCursorOn (int fd);
    126143int KiiCursorOff (int fd);
    127 int KiiCursorRead (int fd, double *x, double *y, char *key);
     144int KiiCursorRead (int fd, double *x, double *y, double *z, double *r, double *d, char *key);
    128145
    129146/* KapaWindow.c */
     
    131148int KiiCenter (int fd, double x, double y, int zoom);
    132149int KapaBox (int fd, Graphdata *graphdata);
    133 int KapaClear (int fd, int ClearSection);
     150int KapaClearCurrentPlot (int fd);
     151int KapaClearPlots (int fd);
     152int KapaClearSections (int fd);
     153int KapaClearImage (int fd);
    134154int KapaInitGraph (Graphdata *graphdata);
    135155int KapaPrepPlot (int fd, int Npts, Graphdata *graphmode);
    136 int KapaPlotVector (int fd, int Npts, float *values);
     156int KapaPlotVector (int fd, int Npts, float *values, char *type);
    137157int KapaSetFont (int fd, char *name, int size);
    138158int KapaSendLabel (int fd, char *string, int mode);
     
    142162int KapaSelectSection (int fd, char *name);
    143163int KapaGetSection (int fd, char *name);
     164int KapaMoveSection (int fd, char *name, char *direction);
     165int KapaSetGraphData (int fd, Graphdata *graphmode);
     166int KapaGetGraphData (int fd, Graphdata *graphmode);
     167int KapaSetImageData (int fd, KapaImageData *graphmode);
     168int KapaGetImageData (int fd, KapaImageData *graphmode);
    144169
    145170/* KapaColors */
     
    196221int bDrawRotBitmap (int x, int y, int dx, int dy, unsigned char *bitmap, int mode, double angle, double scale);
    197222
     223/* Kapa Socket functions */
     224int KapaOpen (char *kapa_exec, char *kapa_name);
     225int KapaServerInit (KapaSockAddress *Address);
     226int KapaServerWait (int InitSocket, KapaSockAddress *Address);
     227int KapaDefineValidIP (char *ipstring);
     228int KapaClientSocket (char *hostname);
     229
    198230/* define Kapa names for shared functions */
    199 # define KapaOpen(p,n) KiiOpen(p,n)
     231// # define KapaOpen(p,n) KiiOpen(p,n)
    200232# define KapaResize(fd,Nx,Ny) KiiResize(fd,Nx,Ny)
    201233# define KapaCenter(fd,x,y,z) KiiResize(fd,x,y,z)
  • trunk/Ohana/src/libkapa/src/IOfuncs.c

    r13326 r13479  
    11# include <kapa_internal.h>
     2
     3/** these function expect to operate with a BLOCKing socket **/
    24
    35/* why is this not defined in stdarg.h for linux/x64? */
     
    6163  status = read (device, buffer, 16);
    6264  buffer[16] = 0;
     65  if (status != 16) fprintf (stderr, "dropped message length\n");
    6366
    6467  /* find the message length, allocate space */
     
    7174  message[status] = 0;
    7275  /* make the string easy to parse */
     76
     77  // fprintf (stderr, "recv: %s\n", message);
    7378
    7479  /* scan the incoming message */
     
    104109
    105110  write (device, string, length);
     111
     112  // fprintf (stderr, "send: %s\n", string);
     113
    106114  free (string);
    107115  return (TRUE);
     
    111119int KiiScanCommand (int device, int length, char *format, ...) {
    112120
    113   int Nbytes, status;
    114   char *buffer, *message;
     121  int status;
     122  char *message;
    115123  va_list argp; 
    116124
     
    118126
    119127  /* read Nbytes from the device */
    120   status = read (device, message, Nbytes);
    121   if (status != Nbytes) fprintf (stderr, "Kii/Kapa comm error\n");
    122   message[status] = 0;
    123   /* make the string easy to parse */
     128  status = read (device, message, length);
     129
     130  if (status != length) {
     131      fprintf (stderr, "Kii/Kapa comm error\n");
     132      return (0);
     133  }
     134  message[status] = 0; // make the string easy to parse
    124135
    125136  /* scan the incoming message */
    126137  va_start (argp, format);
    127   Nbytes = vsscanf (message, format, argp);
     138  vsscanf (message, format, argp);
    128139  va_end (argp);
    129140
    130   return (status);
     141  return (1);
    131142}
     143
     144int KiiWaitAnswer (int device, char *expect) {
     145
     146  int Nbytes;
     147  char *answer;
     148
     149  Nbytes = strlen (expect);
     150  ALLOCATE (answer, char, Nbytes + 1);
     151
     152  KiiScanCommand (device, Nbytes, "%s", answer);
     153  if (strcmp (answer, expect)) {
     154      fprintf (stderr, "unexpected response %s, expected %s\n", answer, expect);
     155      REALLOCATE (answer, char, 128);
     156      Nbytes = read (device, answer, 127);
     157      answer[Nbytes] = 0;
     158      fprintf (stderr, "extra data in buffer: %d bytes\n", Nbytes);
     159      fprintf (stderr, "garbage: %s\n", answer);
     160      return (FALSE);
     161  }
     162  return (TRUE);
     163}
  • trunk/Ohana/src/libkapa/src/KapaOpen.c

    r13344 r13479  
    3030  if (status == -1) {
    3131    if (errno == EADDRINUSE) {
     32        close (InitSocket);
    3233        Address[0].sin_port ++;
    3334        if (Address[0].sin_port > MY_PORT + 10) exit (2);
     
    7475  }
    7576  if (!status) return (-1);
    76 
    77   /* this is a blocking wait; use in a separate thread */
    78   // fcntl (InitSocket, F_SETFL, !O_NONBLOCK);
    7977
    8078  if (DEBUG) fprintf (stderr, "init sock: %d, len: %d\n", InitSocket, length);
     
    119117accepted:
    120118  if (DEBUG) fprintf (stderr, "connection accepted\n");
    121   // fcntl (BindSocket, F_SETFL, O_NONBLOCK);
    122119  return (BindSocket);
    123120}
     
    194191    if (DEBUG) fprintf (stderr, "error connecting: %d\n", errno);
    195192    if (errno == ECONNREFUSED) {
     193      close (InitSocket);
    196194      Address.sin_port ++;
    197195      if (Address.sin_port > MY_PORT + 10) return (-1);
     
    204202  if (DEBUG) fprintf (stderr, "connected on port: %d\n", Address.sin_port);
    205203  if (DEBUG) fprintf (stderr, "connected\n");
    206   fcntl (InitSocket, F_SETFL, O_NONBLOCK);
     204
     205  // the client uses a BLOCKing socket by default
     206  fcntl (InitSocket, F_SETFL, !O_NONBLOCK);
    207207  return (InitSocket);
    208208}
     
    225225    sprintf (line, "%s &", kapa_exec);
    226226  } else {
    227     sprintf (line, "%s -name %s &", kapa_exec, kapa_name);
     227    sprintf (line, "%s -name '%s' &", kapa_exec, kapa_name);
    228228  }
    229229  system (line);
  • trunk/Ohana/src/libkapa/src/KapaWindow.c

    r10923 r13479  
    11# include <kapa_internal.h>
     2
     3int KiiCenter (int fd, double x, double y, int zoom) {
     4
     5  KiiSendCommand (fd, 4, "CENT");
     6  KiiSendMessage (fd, "%8.3f %8.3f %8d ", x, y, zoom);
     7  KiiWaitAnswer (fd, "DONE");
     8 
     9  return (TRUE);
     10}
    211
    312int KiiResize (int fd, int Nx, int Ny) {
     
    514  KiiSendCommand (fd, 4, "RSIZ");
    615  KiiSendMessage (fd, "%d %d", Nx, Ny);
    7   return (TRUE);
    8 }
    9 
    10 int KiiCenter (int fd, double x, double y, int zoom) {
    11 
    12   KiiSendCommand (fd, 4, "CENT");
    13   KiiSendMessage (fd, "%8.3f %8.3f %8d ", x, y, zoom);
     16  KiiWaitAnswer (fd, "DONE");
    1417  return (TRUE);
    1518}
     
    1821
    1922  KiiSendCommand (fd, 4, "DBOX");
    20 
    2123  KiiSendMessage (fd, "%12.6g %12.6g %12.6g %12.6g",
    2224                    graphdata[0].xmin, graphdata[0].xmax, graphdata[0].ymin, graphdata[0].ymax);
    2325
    2426  KiiSendMessage (fd, "%s %s %s", graphdata[0].axis, graphdata[0].labels, graphdata[0].ticks);
    25   return (TRUE);
    26 }
    27 
    28 int KapaClear (int fd, int ClearSection) {
    29 
    30   if (ClearSection) {
    31     KiiSendCommand (fd, 4, "ERAS");
    32   } else {
    33     KiiSendCommand (fd, 4, "ERSS");
    34   }
     27  KiiWaitAnswer (fd, "DONE");
     28  return (TRUE);
     29}
     30
     31int KapaClearCurrentPlot (int fd) {
     32 
     33  KiiSendCommand (fd, 4, "ERSC");
     34  KiiWaitAnswer (fd, "DONE");
     35  return (TRUE);
     36}
     37
     38int KapaClearPlots (int fd) {
     39 
     40  KiiSendCommand (fd, 4, "ERSP");
     41  KiiWaitAnswer (fd, "DONE");
     42  return (TRUE);
     43}
     44
     45int KapaClearSections (int fd) {
     46 
     47  KiiSendCommand (fd, 4, "ERSS");
     48  KiiWaitAnswer (fd, "DONE");
     49  return (TRUE);
     50}
     51
     52int KapaClearImage (int fd) {
     53 
     54  KiiSendCommand (fd, 4, "ERSI");
     55  KiiWaitAnswer (fd, "DONE");
     56  return (TRUE);
     57}
     58
     59int KapaSetToolbox (int fd, int location) {
     60 
     61  KiiSendCommand (fd, 4, "TOOL");
     62  KiiSendMessage (fd, "%d", location);
     63  KiiWaitAnswer (fd, "DONE");
    3564  return (TRUE);
    3665}
     
    6291}
    6392
    64 int KapaPrepPlot (int fd, int Npts, Graphdata *graphmode) {
     93int KapaPrepPlot (int fd, int Npts, Graphdata *data) {
    6594
    6695  /* tell kapa to look for the incoming image */
    6796  KiiSendCommand (fd, 4, "PLOT");
    6897 
    69   /* send Xgraph the plot details */
     98  /* send kapa the plot details */
    7099  KiiSendMessage (fd, "%8d %8d %d %d %d %d %d %f %f",
    71                   Npts, graphmode[0].style,
    72                   graphmode[0].ptype, graphmode[0].ltype,
    73                   graphmode[0].etype, graphmode[0].ebar, graphmode[0].color,
    74                   graphmode[0].lweight, graphmode[0].size);
     100                  Npts, data[0].style,
     101                  data[0].ptype, data[0].ltype,
     102                  data[0].etype, data[0].ebar, data[0].color,
     103                  data[0].lweight, data[0].size);
    75104  KiiSendMessage (fd, "%g %g %g %g",
    76                   graphmode[0].xmin, graphmode[0].xmax,
    77                   graphmode[0].ymin, graphmode[0].ymax);
    78   return (TRUE);
    79 }
    80 
    81 int KapaPlotVector (int fd, int Npts, float *values) {
     105                  data[0].xmin, data[0].xmax,
     106                  data[0].ymin, data[0].ymax);
     107  KiiWaitAnswer (fd, "DONE");
     108  return (TRUE);
     109}
     110
     111int KapaSetGraphData (int fd, Graphdata *data) {
     112
     113  /* tell kapa to look for the incoming image */
     114  KiiSendCommand (fd, 4, "SSTY");
     115 
     116  /* send kapa the plot details */
     117  KiiSendMessage (fd, "%8d %d %d %d %d %d %f %f",
     118                  data[0].style,
     119                  data[0].ptype, data[0].ltype,
     120                  data[0].etype, data[0].ebar, data[0].color,
     121                  data[0].lweight, data[0].size);
     122
     123  KiiSendMessage (fd, "%g %g %g %g",
     124                  data[0].xmin, data[0].xmax,
     125                  data[0].ymin, data[0].ymax);
     126
     127  KiiSendMessage (fd, "%g %g %g %g",
     128                  data[0].coords.pc1_1, data[0].coords.pc2_2,
     129                  data[0].coords.pc1_2, data[0].coords.pc2_1);
     130
     131  KiiSendMessage (fd, "%d %d %s",
     132                  data[0].flipeast, data[0].flipnorth,
     133                  data[0].coords.ctype);
     134
     135  KiiSendMessage (fd, "%g %g %g %g %g %g",
     136                  data[0].coords.crval1,
     137                  data[0].coords.crval2,
     138                  data[0].coords.crpix1,
     139                  data[0].coords.crpix2,
     140                  data[0].coords.cdelt1,
     141                  data[0].coords.cdelt2);
     142
     143  KiiWaitAnswer (fd, "DONE");
     144  return (TRUE);
     145}
     146
     147int KapaGetGraphData (int fd, Graphdata *data) {
     148
     149  /* tell kapa to look for the incoming image */
     150  KiiSendCommand (fd, 4, "GSTY");
     151 
     152  /* send kapa the plot details */
     153  KiiScanMessage (fd, "%d %d %d %d %d %d %lf %lf",
     154                  &data[0].style,
     155                  &data[0].ptype, &data[0].ltype,
     156                  &data[0].etype, &data[0].ebar, &data[0].color,
     157                  &data[0].lweight, &data[0].size);
     158
     159  KiiScanMessage (fd, "%lf %lf %lf %lf",
     160                  &data[0].xmin, &data[0].xmax,
     161                  &data[0].ymin, &data[0].ymax);
     162
     163  KiiScanMessage (fd, "%f %f %f %f",
     164                  &data[0].coords.pc1_1, &data[0].coords.pc2_2,
     165                  &data[0].coords.pc1_2, &data[0].coords.pc2_1);
     166
     167  KiiScanMessage (fd, "%d %d %s",
     168                  &data[0].flipeast, &data[0].flipnorth,
     169                  data[0].coords.ctype);
     170
     171  KiiScanMessage (fd, "%lf %lf %f %f %f %f",
     172                  &data[0].coords.crval1,
     173                  &data[0].coords.crval2,
     174                  &data[0].coords.crpix1,
     175                  &data[0].coords.crpix2,
     176                  &data[0].coords.cdelt1,
     177                  &data[0].coords.cdelt2);
     178
     179  KiiWaitAnswer (fd, "DONE");
     180  return (TRUE);
     181}
     182
     183int KapaSetImageData (int fd, KapaImageData *data) {
     184
     185  /* tell kapa to look for the incoming image */
     186  KiiSendCommand (fd, 4, "SIMD");
     187 
     188  /* send kapa the plot details */
     189  KiiSendMessage (fd, "%g %g %s %s",
     190                  data[0].zero, data[0].range, data[0].name, data[0].file);
     191
     192  KiiWaitAnswer (fd, "DONE");
     193  return (TRUE);
     194}
     195
     196int KapaGetImageData (int fd, KapaImageData *data) {
     197
     198  /* tell kapa to look for the incoming image */
     199  KiiSendCommand (fd, 4, "GIMD");
     200 
     201  KiiScanMessage (fd, "%lf %lf %s %s",
     202                  &data[0].zero, &data[0].range, data[0].name, data[0].file);
     203
     204  KiiWaitAnswer (fd, "DONE");
     205  return (TRUE);
     206}
     207
     208int KapaPlotVector (int fd, int Npts, float *values, char *type) {
    82209
    83210  int Nbytes;
     211  int swap;
     212
     213# ifdef BYTE_SWAP
     214  swap = 1;
     215# else
     216  swap = 0;
     217# endif
    84218
    85219  Nbytes = Npts * sizeof (float);
     220
     221  if (!strcmp(type, "x")) goto valid;
     222  if (!strcmp(type, "y")) goto valid;
     223  if (!strcmp(type, "z")) goto valid;
     224  if (!strcmp(type, "dym")) goto valid;
     225  if (!strcmp(type, "dyp")) goto valid;
     226  if (!strcmp(type, "dxm")) goto valid;
     227  if (!strcmp(type, "dxp")) goto valid;
     228  return (FALSE);
     229
     230valid:
     231  KiiSendCommand (fd, 4, "PLOB");
     232  KiiSendMessage (fd, "%s %d %d %d", type, Npts, Nbytes, swap);
     233
    86234  write (fd, values, Nbytes);
     235  KiiWaitAnswer (fd, "DONE");
    87236  return (TRUE);
    88237}
     
    93242  KiiSendCommand (fd, 16, "%s", name);
    94243  KiiSendCommand (fd, 16, "%d", size);
     244  KiiWaitAnswer (fd, "DONE");
    95245  return (TRUE);
    96246}
    97247
    98248int KapaSendLabel (int fd, char *string, int mode) {
    99  
     249
    100250  KiiSendCommand (fd, 4, "LABL");
    101251  KiiSendMessage (fd, "%6d", mode);
    102252  KiiSendData (fd, string, strlen(string));
     253  KiiWaitAnswer (fd, "DONE");
    103254  return (TRUE);
    104255}
     
    109260  KiiSendMessage (fd, "%f %f %f", x, y, angle);
    110261  KiiSendData (fd, string, strlen(string));
    111   return (TRUE);
    112 }
    113 
    114 int KapaSetLimits (int fd, Graphdata *graphmode) {
     262  KiiWaitAnswer (fd, "DONE");
     263  return (TRUE);
     264}
     265
     266int KapaSetLimits (int fd, Graphdata *data) {
    115267
    116268  KiiSendCommand (fd, 4, "SLIM");
    117   KiiSendMessage (fd, "%g %g %g %g ", graphmode[0].xmin, graphmode[0].xmax, graphmode[0].ymin, graphmode[0].ymax);
     269  KiiSendMessage (fd, "%g %g %g %g ", data[0].xmin, data[0].xmax, data[0].ymin, data[0].ymax);
     270  KiiWaitAnswer (fd, "DONE");
     271  return (TRUE);
     272}
     273
     274// for now, this just gets the dimensions
     275int KapaGetLimits (int fd, float *dx, float *dy) {
     276
     277  KiiSendCommand (fd, 4, "GLIM");
     278  KiiScanMessage (fd, "%f %f", dx, dy);
     279  KiiWaitAnswer (fd, "DONE");
    118280  return (TRUE);
    119281}
     
    128290                  section[0].dx,
    129291                  section[0].dy);
     292  KiiWaitAnswer (fd, "DONE");
     293  return (TRUE);
     294}
     295
     296int KapaMoveSection (int fd, char *name, char *direction) {
     297
     298  if (!strcasecmp(direction, "up")) goto valid;
     299  if (!strcasecmp(direction, "down")) goto valid;
     300  if (!strcasecmp(direction, "top")) goto valid;
     301  if (!strcasecmp(direction, "bottom")) goto valid;
     302 
     303  fprintf (stderr, "unexpected direction %s\n", direction);
     304  return (FALSE);
     305
     306valid:
     307  KiiSendCommand (fd, 4, "MSEC");
     308  KiiSendMessage (fd, "%s %s", name, direction);
     309  KiiWaitAnswer (fd, "DONE");
    130310  return (TRUE);
    131311}
     
    135315  KiiSendCommand (fd, 4, "SSEC");
    136316  KiiSendMessage (fd, "%s", name);
     317  KiiWaitAnswer (fd, "DONE");
    137318  return (TRUE);
    138319}
     
    142323  KiiSendCommand (fd, 4, "LSEC");
    143324  KiiSendMessage (fd, "%s", name);
    144   return (TRUE);
    145 }
     325  KiiWaitAnswer (fd, "DONE");
     326  return (TRUE);
     327}
  • trunk/Ohana/src/libkapa/src/KiiConvert.c

    r12892 r13479  
    33int KiiJPEG (int fd, const char *filename) {
    44
    5   char buffer[20];
    6 
    75  KiiSendCommand (fd, 4, "JPEG");
    86  KiiSendMessage (fd, "%s", filename);
    9 
    10   /* block for the response, which says the operation completed */
    11   read (fd, buffer, 4);
     7  KiiWaitAnswer (fd, "DONE");
    128  return (TRUE);
    139}
     
    1511int KapaPNG (int fd, const char *filename) {
    1612
    17   char buffer[20];
    18 
    1913  KiiSendCommand (fd, 4, "PNGF");
    2014  KiiSendMessage (fd, "%s", filename);
    21 
    22   /* block for the response, which says the operation completed */
    23   read (fd, buffer, 4);
     15  KiiWaitAnswer (fd, "DONE");
    2416  return (TRUE);
    2517}
     
    2719int KapaPPM (int fd, const char *filename) {
    2820
    29   char buffer[20];
    30 
    3121  KiiSendCommand (fd, 4, "PPMF");
    3222  KiiSendMessage (fd, "%s", filename);
    33 
    34   /* block for the response, which says the operation completed */
    35   read (fd, buffer, 4);
     23  KiiWaitAnswer (fd, "DONE");
    3624  return (TRUE);
    3725}
     
    3927int KiiPS (int fd, const char *filename, int scaleMode, int pageMode, char *pagename) {
    4028
    41   char buffer[20];
    42 
    43   /* the default operation */
    4429  KiiSendCommand (fd, 4, "PSIT");
    45 
    4630  KiiSendMessage (fd, "%s %s %d %d", filename, pagename, scaleMode, pageMode);
    47 
    48   /* block for the response, which says the operation completed */
    49   read (fd, buffer, 4);
     31  KiiWaitAnswer (fd, "DONE");
    5032  return (TRUE);
    5133}
  • trunk/Ohana/src/libkapa/src/KiiCursor.c

    r5848 r13479  
    22
    33int KiiCursorOn (int fd) {
    4   write (fd, "CURS", 4); /* ask Source to look for the keystrokes */
     4
     5  KiiSendCommand (fd, 4, "CURS");
     6  KiiWaitAnswer (fd, "DONE");
    57  return (TRUE);
    68}
    79
    810int KiiCursorOff (int fd) {
    9   write (fd, "NCUR", 4); /* ask Source to look for the keystrokes */
     11
     12  KiiSendCommand (fd, 4, "NCUR");
     13  KiiWaitAnswer (fd, "DONE");
    1014  return (TRUE);
    1115}
    1216
    13 int KiiCursorRead (int fd, double *x, double *y, char *key) {
     17int KiiCursorRead (int fd, double *x, double *y, double *z, double *r, double *d, char *key) {
    1418
    15   char buffer[40];
    16 
    17   bzero (buffer, 40);
    18   read (fd, buffer, 40);
    19   buffer[39] = 0;
    20 
    21   sscanf (buffer, "%s %lf %lf", key, x, y);
     19  KiiScanMessage (fd, "%s %lf %lf %lf %lf %lf", key, x, y, z, r, d);
    2220  if (ispunct(key[0])) strcpy (key, "_");
    23 
    2421  return (TRUE);
    2522}
  • trunk/Ohana/src/libkapa/src/KiiOverlay.c

    r13327 r13479  
    5050}
    5151
    52 int KiiLoadOverlay (int fd, KiiOverlay *overlay, int Noverlay, char *overname) {
     52int KiiLoadOverlayOld (int fd, KiiOverlay *overlay, int Noverlay, char *overname) {
    5353
    5454  int i, n, Nline;
     
    8484
    8585  free (buffer);
     86  KiiWaitAnswer (fd, "DONE");
    8687
    8788  /* this is very inefficient: 128 bytes per object vs 17 as binary, plus the
    8889     conversions back and forth
    8990  */
     91
     92  return (TRUE);
     93}
     94
     95int KiiLoadOverlay (int fd, KiiOverlay *overlay, int Noverlay, char *overname) {
     96
     97  int i, overnum, Ntextdata, NTEXTDATA, Ntext, Nchar;
     98  char *textdata;
     99  KiiOverlayBase *buffer;
     100
     101  Ntext = 0;
     102  KiiSelectOverlay (overname, &overnum);
     103
     104  Ntextdata = 0;
     105  NTEXTDATA = 1024;
     106  ALLOCATE (textdata, char, 1024);
     107
     108  // we send the position information as a binary block
     109  ALLOCATE (buffer, KiiOverlayBase, Noverlay);
     110  for (i = 0; i < Noverlay; i++) {
     111    buffer[i].x    = overlay[i].x;
     112    buffer[i].y    = overlay[i].y;
     113    buffer[i].dx   = overlay[i].dx;
     114    buffer[i].dy   = overlay[i].dy;
     115    buffer[i].type = overlay[i].type;
     116    if (buffer[i].type == KII_OVERLAY_TEXT) {
     117      Ntext ++;
     118      Nchar = strlen(overlay[i].text) + 1;
     119      if (Ntextdata + Nchar >= NTEXTDATA) {
     120        NTEXTDATA += 1024;
     121        REALLOCATE (textdata, char, NTEXTDATA);
     122      }
     123      sprintf (&textdata[Ntextdata], "%s\n", overlay[i].text);
     124      Ntextdata += Nchar;
     125    }
     126  }
     127
     128  KiiSendCommand (fd,  4, "LOAD");
     129  KiiSendMessage (fd, "%d %d %d %d", overnum, Noverlay, Ntext, Ntextdata);
     130
     131  // we could break this into segments if we want to trap an interrupt, but why bother?
     132  Nchar = write (fd, buffer, Noverlay*sizeof(KiiOverlayBase));
     133  fprintf (stderr, "sent %d of %d bytes\n", Nchar, Noverlay*sizeof(KiiOverlayBase));
     134  KiiWaitAnswer (fd, "DONE");
     135
     136  write (fd, textdata, Ntextdata);
     137  KiiWaitAnswer (fd, "DONE");
     138
     139  free (buffer);
     140  free (textdata);
     141
     142  KiiWaitAnswer (fd, "DONE");
    90143  return (TRUE);
    91144}
     
    97150  KiiSelectOverlay (overname, &n);
    98151   
    99   KiiSendCommand (fd, 4, "ERAS");
     152  KiiSendCommand (fd, 4, "ERSO");
    100153  KiiSendCommand (fd, 16, "OVERLAY %7d ", n);
    101 
     154  KiiWaitAnswer (fd, "DONE");
    102155  return (TRUE);
    103156}
     
    116169
    117170  KiiSendMessage (fd, "FILE: %d %s", n, file);
     171  KiiWaitAnswer (fd, "DONE");
    118172  return (TRUE);
    119173}
  • trunk/Ohana/src/libkapa/src/KiiPicture.c

    r5852 r13479  
    11# include <kapa_internal.h>
    22
    3 int KiiNewPicture1D (int fd, KiiImage *image, KiiDisplayMode *mode, Coords *coords) {
     3int KiiNewPicture1D (int fd, KiiImage *image, KapaImageData *data, Coords *coords) {
    44
    55  int i;
    66  int Npix, Ncolors, NNcolors, size;
    77  float *in, min, max;
    8   char *out, *outbuffer, *root;
     8  char *out, *outbuffer;
    99  double a1, a2;
    1010
    1111  Npix = image[0].Nx*image[0].Ny;
    1212
    13   KiiSendCommand (fd, 4, "READ"); /* tell Ximage to look for the incoming image */
     13  KiiSendCommand (fd, 4, "READ"); /* tell kapa to look for the incoming image */
     14  KiiScanMessage (fd, "%d", &Ncolors);
     15
     16  in = image[0].data1d;
     17
     18  /* these are for a future upgrade */
     19  min = max = 0.0;
     20  size = Npix*sizeof(float);
     21
     22  /* done with the conversion, now send kapa the converted picture */
     23  KiiSendMessage (fd, "%8d %8d", image[0].Nx, image[0].Ny);
     24  KiiSendMessage (fd, "-32 1 0.0 1.0");
     25  KiiSendMessage (fd, "%f %f %s %s", data[0].zero, data[0].range, data[0].name, data[0].file);
     26  KiiSendMessage (fd, "%f %f %d ", min, max, size);
     27  KiiSendMessage (fd, "%f %f %g %g %g ", coords[0].crval1, coords[0].crpix1, coords[0].cdelt1, coords[0].pc1_1, coords[0].pc1_2);
     28  KiiSendMessage (fd, "%f %f %g %g %g ", coords[0].crval2, coords[0].crpix2, coords[0].cdelt2, coords[0].pc2_1, coords[0].pc2_2);
     29  KiiSendMessage (fd, "%s", coords[0].ctype);
     30
     31  /* send the image data */
     32  write (fd, image[0].data1d, size);
     33
     34  KiiWaitAnswer (fd, "DONE");
     35  return (TRUE);
     36}
     37
     38int KiiNewPicture1D_8bit (int fd, KiiImage *image, KapaImageData *data, Coords *coords) {
     39
     40  int i;
     41  int Npix, Ncolors, NNcolors, size;
     42  float *in, min, max;
     43  char *out, *outbuffer;
     44  double a1, a2;
     45
     46  Npix = image[0].Nx*image[0].Ny;
     47
     48  KiiSendCommand (fd, 4, "READ"); /* tell kapa to look for the incoming image */
    1449  KiiScanMessage (fd, "%d", &Ncolors);
    1550
     
    2257  /* define color table, */
    2358  NNcolors = Ncolors - 1;
    24   if (mode[0].logflux) {
    25     mode[0].range = MAX (2, mode[0].range);
    26     a1 = Ncolors / log10 (mode[0].range);
    27     a2 = mode[0].zero;
     59  if (data[0].logflux) {
     60    data[0].range = MAX (2, data[0].range);
     61    a1 = Ncolors / log10 (data[0].range);
     62    a2 = data[0].zero;
    2863    for (i = 0; i < Npix; i++, in++, out++) {
    2964      *out = (char) MIN (a1 * log10 (MAX (*in - a2, 1.0)), NNcolors);
    3065    }
    3166  } else {
    32     a1 = Ncolors / mode[0].range;
    33     a2 = Ncolors * mode[0].zero / mode[0].range;
     67    a1 = Ncolors / data[0].range;
     68    a2 = Ncolors * data[0].zero / data[0].range;
    3469    for (i = 0; i < Npix; i++, in++, out++) {
    3570      *out = (char) MIN (MAX (a1 * *in - a2, 0), NNcolors);
     
    4176  size = Npix*sizeof(char);
    4277
    43   /* done with the conversion, now send Ximage the converted picture */
     78  /* done with the conversion, now send kapa the converted picture */
    4479  KiiSendMessage (fd, "%8d %8d", image[0].Nx, image[0].Ny);
    4580  KiiSendMessage (fd, "8 1 0.0 1.0");
    46   KiiSendMessage (fd, "%f %f ", mode[0].zero, mode[0].range);
     81  KiiSendMessage (fd, "%f %f %s %s", data[0].zero, data[0].range, data[0].name, data[0].file);
    4782  KiiSendMessage (fd, "%f %f %d ", min, max, size);
    4883  KiiSendMessage (fd, "%f %f %g %g %g ", coords[0].crval1, coords[0].crpix1, coords[0].cdelt1, coords[0].pc1_1, coords[0].pc1_2);
    4984  KiiSendMessage (fd, "%f %f %g %g %g ", coords[0].crval2, coords[0].crpix2, coords[0].cdelt2, coords[0].pc2_1, coords[0].pc2_2);
    50 
    51   /* send the filename */
    52   root = filerootname (image[0].file);
    53   KiiSendMessage (fd, "%s %s %s ", coords[0].ctype, root, image[0].name);
    54   free (root);
     85  KiiSendMessage (fd, "%s", coords[0].ctype);
    5586
    5687  /* send the image data */
     
    5889  free (outbuffer);
    5990
     91  KiiWaitAnswer (fd, "DONE");
    6092  return (TRUE);
    6193}
    6294
    63 int KiiNewPicture2D (int fd, KiiImage *image, KiiDisplayMode *mode, Coords *coords) {
     95int KiiNewPicture2D (int fd, KiiImage *image, KapaImageData *data, Coords *coords) {
    6496
    6597  int i, j;
    6698  int Npix, Ncolors, NNcolors, size;
    6799  float *in, min, max;
    68   char *out, *outbuffer, *root;
    69   char buffer[1024];
     100  char *out, *outbuffer;
    70101  double a1, a2;
    71102
    72103  Npix = image[0].Nx*image[0].Ny;
    73104
    74   KiiSendCommand (fd, 4, "READ"); /* tell Ximage to look for the incoming image */
    75 
    76   /* convert from (float *) to 1 byte chars -- depends on how many colors Kii owns */
    77   /* use this response as a handshake test */
    78   read (fd, buffer, 16);
    79   sscanf (buffer, "%*s %d", &Ncolors);
     105  KiiSendCommand (fd, 4, "READ"); /* tell kapa to look for the incoming image */
     106  KiiScanMessage (fd, "%d", &Ncolors);
    80107
    81108  ALLOCATE (outbuffer, char, Npix);
     
    86113  /* define color table, */
    87114  NNcolors = Ncolors - 1;
    88   if (mode[0].logflux) {
    89     mode[0].range = MAX (2, mode[0].range);
    90     a1 = Ncolors / log10 (mode[0].range);
    91     a2 = mode[0].zero;
     115  if (data[0].logflux) {
     116    data[0].range = MAX (2, data[0].range);
     117    a1 = Ncolors / log10 (data[0].range);
     118    a2 = data[0].zero;
    92119    for (j = 0; j < image[0].Ny; j++) {
    93120      in = image[0].data2d[j];
     
    97124    }
    98125  } else {
    99     a1 = Ncolors / mode[0].range;
    100     a2 = Ncolors * mode[0].zero / mode[0].range;
     126    a1 = Ncolors / data[0].range;
     127    a2 = Ncolors * data[0].zero / data[0].range;
    101128    for (j = 0; j < image[0].Ny; j++) {
    102129      in = image[0].data2d[j];
     
    111138  size = Npix*sizeof(char);
    112139
    113   /* done with the conversion, now send Ximage the converted picture */
    114   KiiSendMessage (fd, "%8d %8d 8 1 %f %f", image[0].Nx, image[0].Ny, 0.0, 1.0);
    115   KiiSendMessage (fd, "%f %f %f %f %d ", mode[0].zero, mode[0].range, min, max, size);
     140  /* done with the conversion, now send kapa the converted picture */
     141  KiiSendMessage (fd, "%8d %8d", image[0].Nx, image[0].Ny);
     142  KiiSendMessage (fd, "8 1 0.0 1.0");
     143  KiiSendMessage (fd, "%f %f %s %s", data[0].zero, data[0].range, data[0].name, data[0].file);
     144  KiiSendMessage (fd, "%f %f %d ", min, max, size);
    116145  KiiSendMessage (fd, "%f %f %g %g %g ", coords[0].crval1, coords[0].crpix1, coords[0].cdelt1, coords[0].pc1_1, coords[0].pc1_2);
    117146  KiiSendMessage (fd, "%f %f %g %g %g ", coords[0].crval2, coords[0].crpix2, coords[0].cdelt2, coords[0].pc2_1, coords[0].pc2_2);
    118 
    119   /* send the filename */
    120   root = filerootname (image[0].file);
    121   KiiSendMessage (fd, "%s %s %s ", coords[0].ctype, root, image[0].name);
     147  KiiSendMessage (fd, "%s", coords[0].ctype);
    122148
    123149  /* send the image data */
     
    125151  free (outbuffer);
    126152
     153  KiiWaitAnswer (fd, "DONE");
    127154  return (TRUE);
    128155}
  • trunk/Ohana/src/opihi/cmd.astro/cgrid.c

    r7917 r13479  
    1414  double x, y;
    1515  Vector Xvec, Yvec;
    16   int NorthPole, SouthPole, N, OnPic, LOnPic, status, NELEMENTS, First;
     16  int kapa, NorthPole, SouthPole, N, OnPic, LOnPic, status, NELEMENTS, First;
    1717  Graphdata graphmode;
    1818
    19   if (!style_args (&graphmode, &argc, argv, 0)) return FALSE;
     19  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
    2020
    2121  if (argc != 1) {
     
    2323    return (FALSE);
    2424  }
    25   SetGraph (graphmode);
    2625
    2726  /* are we plotting one of the poles? */
     
    392391  graphmode.ptype = 100; /* connect a pair */
    393392  graphmode.etype = 0;
    394   PrepPlotting (N, &graphmode);
    395   PlotVector (N, Xvec.elements);
    396   PlotVector (N, Yvec.elements);
     393  PlotVectorPair (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
    397394
    398395  free (Xvec.elements);
  • trunk/Ohana/src/opihi/cmd.astro/cplot.c

    r7917 r13479  
    33int cplot (int argc, char **argv) {
    44 
    5   int i, Npts, status;
     5  int i, kapa, Npts, status;
    66  float *x, *y, *r, *d, Rmin, Rmax;
    77  Vector Xvec, Yvec, *xvec, *yvec;
    88  Graphdata graphmode;
    99
    10   if (!style_args (&graphmode, &argc, argv, 0)) return FALSE;
     10  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
    1111
    1212  if (argc != 3) {
     
    1414    return (FALSE);
    1515  }
    16   SetGraph (graphmode);
    1716
    1817  Rmin = graphmode.coords.crval1 - 182.0;
     
    6766
    6867  graphmode.etype = 0;
    69   PrepPlotting (Npts, &graphmode);
    70   PlotVector (Npts, Xvec.elements);
    71   PlotVector (Npts, Yvec.elements);
     68  PlotVectorPair (kapa, Npts, Xvec.elements, Yvec.elements, &graphmode);
    7269 
    7370  free (Xvec.elements);
  • trunk/Ohana/src/opihi/cmd.astro/czplot.c

    r7917 r13479  
    33int czplot (int argc, char **argv) {
    44 
    5   int i, Npts;
     5  int i, kapa, Npts;
    66  double min, range, Rmin, Rmax;
    77  float *in, *out, *r, *d, *x, *y;
     
    99  Graphdata graphmode;
    1010
    11   if (!style_args (&graphmode, &argc, argv, 0)) return FALSE;
     11  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
    1212
    1313  if (argc != 6) {
     
    1515    return (FALSE);
    1616  }
    17   SetGraph (graphmode);
    1817
    1918  min = atof(argv[4]);
     
    5958  graphmode.etype = 0;
    6059  Npts = Xvec.Nelements;
    61   PrepPlotting (Npts, &graphmode);
    62 
    63   PlotVector (Npts, Xvec.elements);
    64   PlotVector (Npts, Yvec.elements);
    65   PlotVector (Npts, Zvec.elements);
     60  PlotVectorTriplet (kapa, Npts, Xvec.elements, Yvec.elements, Zvec.elements, &graphmode);
    6661
    6762  free (Xvec.elements);
  • trunk/Ohana/src/opihi/cmd.astro/gauss.c

    r7917 r13479  
    55  char key[20];
    66  int i, N, Npix, Nborder, Nspot;
    7   double X, Y, Z, max;
    8   int Ximage, Nimage;
     7  double X, Y, Z, ZP, RA, DEC, max;
     8  int kapa;
     9  char *name;
    910  Buffer *buf;
     11  KapaImageData data;
    1012
    11   Nimage = -1;
     13  name = NULL;
    1214  if ((N = get_argument (argc, argv, "-n"))) {
    1315    remove_argument (N, &argc, argv);
    14     Nimage = atof (argv[N]);
     16    name = strcreate (argv[N]);
    1517    remove_argument (N, &argc, argv);
    1618  }
    17   if (!GetImage (&Ximage, &Nimage)) return (FALSE);
     19  if (!GetImageData (&data, &kapa, name)) return (FALSE);
     20  FREE (name);
    1821
    1922  Nborder = 3;
     
    3740  }
    3841 
    39   if (Ximage < 1) {
     42  if (kapa < 1) {
    4043    gprint (GP_ERR, "no active TV\n");
    4144    return (FALSE);
     
    4851  }
    4952
    50   if ((buf = SelectBuffer (GetImageName(), OLDBUFFER, TRUE)) == NULL) return (FALSE);
     53  if ((buf = SelectBuffer (data.name, OLDBUFFER, TRUE)) == NULL) return (FALSE);
    5154
    52   KiiCursorOn (Ximage);
     55  KiiCursorOn (kapa);
    5356
    5457  for (i = 0; (i < Nspot) || (Nspot == 0); i++) {
    55     KiiCursorRead (Ximage, &X, &Y, key);
     58    KiiCursorRead (kapa, &X, &Y, &ZP, &RA, &DEC, key);
    5659    if (!strcasecmp (key, "Q")) break;
    5760    Z = get_aperture_stats (&buf[0].matrix, (int)(X+0.5), (int)(Y+0.5), Npix, Nborder, max);
    5861  }
    59   KiiCursorOff (Ximage);
     62  KiiCursorOff (kapa);
    6063  return (TRUE);
    6164}
  • trunk/Ohana/src/opihi/cmd.astro/objload.c

    r7917 r13479  
    77  int i, N, Objtype, type, Nline, status;
    88  FILE *f;
    9   char *buffer, *line;
    10   int Ximage, Nimage, Noverlay, NOVERLAY;
     9  char *buffer, *line, *name;
     10  int kapa, Noverlay, NOVERLAY;
    1111  KiiOverlay *overlay;
    1212 
    13   Nimage = -1;
     13  name = NULL;
    1414  if ((N = get_argument (argc, argv, "-n"))) {
    1515    remove_argument (N, &argc, argv);
    16     Nimage = atof (argv[N]);
     16    name = strcreate (argv[N]);
    1717    remove_argument (N, &argc, argv);
    1818  }
    19   if (!GetImage (&Ximage, &Nimage)) return (FALSE);
     19  if (!GetImage (NULL, &kapa, name)) return (FALSE);
     20  FREE (name);
    2021
    2122  Objtype = 0;
     
    6364  free (buffer);
    6465
    65   KiiLoadOverlay (Ximage, overlay, Noverlay, argv[1]);
     66  KiiLoadOverlay (kapa, overlay, Noverlay, argv[1]);
    6667
    6768  free (overlay);
  • trunk/Ohana/src/opihi/cmd.astro/outline.c

    r7917 r13479  
    145145    /* code to draw dots on Ximage */
    146146    {
    147       int Nimage, Ximage;
     147      int kapa;
    148148      float xp, yp, x, y;
    149149      float dx, dy, theta, t, dt;
     
    151151      KiiOverlay *overlay;
    152152     
    153       Nimage = -1;
    154       if (!GetImage (&Ximage, &Nimage)) return (FALSE);
     153      if (!GetImage (NULL, &kapa, NULL)) return (FALSE);
    155154     
    156155      Noverlay = 0;
     
    179178        CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 1000);
    180179      }
    181       KiiLoadOverlay (Ximage, overlay, Noverlay, "red");
     180      KiiLoadOverlay (kapa, overlay, Noverlay, "red");
    182181      free (overlay);
    183182    }
  • trunk/Ohana/src/opihi/cmd.astro/outline2.c

    r7917 r13479  
    303303int plot_outline () {
    304304 
    305   int Nimage, Ximage;
     305  int kapa;
    306306  float xp, yp, x, y;
    307307  float dx, dy, theta, t, dt;
     
    309309  KiiOverlay *overlay;
    310310 
    311   Nimage = -1;
    312   if (!GetImage (&Ximage, &Nimage)) return (FALSE);
     311  if (!GetImage (NULL, &kapa, NULL)) return (FALSE);
    313312 
    314313  Noverlay = 0;
     
    337336    CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 1000);
    338337  }
    339   KiiLoadOverlay (Ximage, overlay, Noverlay, "red");
     338  KiiLoadOverlay (kapa, overlay, Noverlay, "red");
    340339  free (overlay);
    341340  return (TRUE);
  • trunk/Ohana/src/opihi/cmd.astro/region.c

    r10928 r13479  
    55  char string[256];
    66  double Ra, Dec, Radius;
    7   double dx, dy;
    8   int N, Ngraph, Xgraph;
     7  float dx, dy;
     8  int N, kapa;
     9  char *name;
    910  Graphdata graphmode;
    1011
    11   Ngraph = 0;
    12   if (!GetGraph (&graphmode, &Xgraph, &Ngraph)) return (FALSE);
     12  name = NULL;
     13  if ((N = get_argument (argc, argv, "-n"))) {
     14    remove_argument (N, &argc, argv);
     15    name = strcreate (argv[N]);
     16    remove_argument (N, &argc, argv);
     17  }
     18  if (!GetGraph (&graphmode, &kapa, name)) return (FALSE);
     19  FREE (name);
    1320
    1421  if ((N = get_argument (argc, argv, "-ew"))) {
     
    6067 
    6168  /* ask kapa for coordinate limits, so get the right aspect ratio */
    62   KiiSendCommand (Xgraph, 4, "LIMS");
    63   KiiScanMessage (Xgraph, "%lf %lf", &dx, &dy);
     69  KapaGetLimits (kapa, &dx, &dy);
    6470  dx = fabs (dx);
    6571  dy = fabs (dy);
     
    101107  graphmode.coords.cdelt1 = graphmode.coords.cdelt2 = 1.0;
    102108
    103   KapaClear (Xgraph, TRUE);
    104   KapaSetLimits (Xgraph, &graphmode);
     109  KapaClearSections (kapa);
     110  KapaSetLimits (kapa, &graphmode);
    105111
    106112  /* drop this? */
    107113  sprintf (string, "%8.4f %8.4f (%f)", Ra, Dec, Radius);
    108   KapaSendLabel (Xgraph, string, 2);
     114  KapaSendLabel (kapa, string, 2);
    109115
    110   SetGraph (graphmode);
     116  // XXX is this the right thing to be doing?
     117  SetGraph (&graphmode);
    111118  return (TRUE);
    112119}
  • trunk/Ohana/src/opihi/cmd.data/box.c

    r7917 r13479  
    33int box (int argc, char **argv) {
    44 
    5   int i, N, Ngraph, Xgraph;
     5  int i, N, kapa;
     6  char *name;
    67  Graphdata graphmode;
    78 
    8   Ngraph = -1;
     9  name = NULL;
    910  if ((N = get_argument (argc, argv, "-n"))) {
    1011    remove_argument (N, &argc, argv);
    11     Ngraph = atof (argv[N]);
     12    name = strcreate (argv[N]);
    1213    remove_argument (N, &argc, argv);
    1314  }
    14   if (!GetGraph (&graphmode, &Xgraph, &Ngraph)) return (FALSE);
     15  if (!GetGraph (&graphmode, &kapa, name)) return (FALSE);
     16  FREE (name);
    1517
    1618  strcpy (graphmode.ticks, "2222");
     
    4951  if (argc != 1) goto usage;
    5052
    51   KapaBox (Xgraph, &graphmode);
     53  KapaBox (kapa, &graphmode);
    5254  return (TRUE);
    5355     
  • trunk/Ohana/src/opihi/cmd.data/center.c

    r7917 r13479  
    55  double x, y;
    66  int zoom;
    7   int Ximage, Nimage, N;
     7  int kapa, N;
     8  char *name;
    89 
    9   Nimage = -1;
     10  name = NULL;
    1011  if ((N = get_argument (argc, argv, "-n"))) {
    1112    remove_argument (N, &argc, argv);
    12     Nimage = atof (argv[N]);
     13    name = strcreate (argv[N]);
    1314    remove_argument (N, &argc, argv);
    1415  }
    15   if (!GetImage (&Ximage, &Nimage)) return (FALSE);
     16  if (!GetImage (NULL, &kapa, name)) return (FALSE);
     17  FREE (name);
    1618
    1719  if ((argc != 3) && (argc != 4)) {
     
    2527  if (argc == 4) zoom = atof (argv[3]);
    2628
    27   KiiCenter (Ximage, x, y, zoom);
     29  KiiCenter (kapa, x, y, zoom);
    2830  return (TRUE);
    2931}
  • trunk/Ohana/src/opihi/cmd.data/clear.c

    r7917 r13479  
    11# include "data.h"
    22
     3// default is to clear all plots, but not the sections or the images
    34int clear (int argc, char **argv) {
    45 
    5   int N, ClearSection;
    6   int Ngraph, Xgraph;
     6  int N;
     7  int kapa;
     8  char *name;
    79
    8   Ngraph = -1;
     10  name = NULL;
    911  if ((N = get_argument (argc, argv, "-n"))) {
    1012    remove_argument (N, &argc, argv);
    11     Ngraph = atof (argv[N]);
     13    name = strcreate (argv[N]);
    1214    remove_argument (N, &argc, argv);
    1315  }
    14   if (!GetGraph (NULL, &Xgraph, &Ngraph)) return (FALSE);
     16  if (!GetGraph (NULL, &kapa, name)) return (FALSE);
     17  FREE (name);
    1518
    16   ClearSection = FALSE;
    17   if ((N = get_argument (argc, argv, "-s"))) {
    18     remove_argument (N, &argc, argv);
    19     ClearSection = TRUE;
     19  // clear all sections
     20  if ((N = get_argument (argc, argv, "-s")) ||
     21      (N = get_argument (argc, argv, "-section"))) {
     22      KapaClearSections (kapa);
     23      return (TRUE);
     24  }
     25
     26  // clear all sections
     27  if ((N = get_argument (argc, argv, "-graph"))) {
     28      KapaClearCurrentPlot (kapa);
     29      return (TRUE);
     30  }
     31
     32  // clear image
     33  if ((N = get_argument (argc, argv, "-image"))) {
     34      KapaClearImage (kapa);
     35      return (TRUE);
    2036  }
    2137
    2238  if (argc != 1) {
    23     gprint (GP_ERR, "USAGE: clear [-n Xgraph]\n");
     39    gprint (GP_ERR, "USAGE: clear [-n Xgraph] [-s|-section] [-image] [-graph]\n");
     40    gprint (GP_ERR, "       [-s|-section] : clear all sections\n");
     41    gprint (GP_ERR, "       [-graph]      : clear current graph\n");
     42    gprint (GP_ERR, "       [-image]      : clear current image\n");
    2443    return (FALSE);
    2544  }
    2645
    27   KapaClear (Xgraph, ClearSection);
     46  KapaClearPlots (kapa);
    2847  return (TRUE);
    2948}
  • trunk/Ohana/src/opihi/cmd.data/close.c

    r6686 r13479  
    33int close_device (int argc, char **argv) {
    44
    5   int N, Source, Nsource, IsImage;
     5  int N, kapa, IsImage;
     6  char *name;
    67  /* close current graphics device */
    78
    8   Nsource = -1;
     9  name = NULL;
    910  if ((N = get_argument (argc, argv, "-n"))) {
    1011    remove_argument (N, &argc, argv);
    11     Nsource = atof (argv[N]);
     12    name = strcreate (argv[N]);
    1213    remove_argument (N, &argc, argv);
    1314  }
    14   if ((N = get_argument (argc, argv, "-g"))) {
    15     remove_argument (N, &argc, argv);
    16     SetImageDevice (FALSE);
    17   } 
    18   if ((N = get_argument (argc, argv, "-i"))) {
    19     remove_argument (N, &argc, argv);
    20     SetImageDevice (TRUE);
    21   } 
    2215
    23   IsImage = GetCurrentDevice ();
    24   if (IsImage) {
    25     if (!GetImage (&Source, &Nsource)) return (FALSE);
    26     close_image (Nsource);
    27   } else {
    28     if (!GetGraph (NULL, &Source, &Nsource)) return (FALSE);
    29     close_graph (Nsource);
    30   }
     16  if (!GetGraph (NULL, &kapa, name)) return (FALSE);
     17
     18  close_kapa (name);
     19  FREE (name);
    3120
    3221  return (TRUE);
  • trunk/Ohana/src/opihi/cmd.data/cursor.c

    r7917 r13479  
    33int cursor (int argc, char **argv) {
    44
    5   char string[20], key[20];
    6   int i, N, Nsource, Source, IsImage;
     5  char string[20], key[20], *name;
     6  int i, N, kapa;
    77  double X, Y, R, D, Z;
    88  void *oldsignal;
    9   Graphdata graphmode;
    10   Buffer *buf;
    119
    12   Nsource = -1;
     10  // XXX need to be able to specify graph vs image coords
     11  // currently, if only one exists, that frame will be used
     12  // if both exist, defaults to ??
     13  // if ((N = get_argument (argc, argv, "-g"))) {
     14  // if ((N = get_argument (argc, argv, "-i"))) {
     15
     16  name = NULL;
    1317  if ((N = get_argument (argc, argv, "-n"))) {
    1418    remove_argument (N, &argc, argv);
    15     Nsource = atof (argv[N]);
     19    name = strcreate (argv[N]);
    1620    remove_argument (N, &argc, argv);
    1721  }
    18   if ((N = get_argument (argc, argv, "-g"))) {
    19     remove_argument (N, &argc, argv);
    20     SetImageDevice (FALSE);
    21   } 
    22   if ((N = get_argument (argc, argv, "-i"))) {
    23     remove_argument (N, &argc, argv);
    24     SetImageDevice (TRUE);
    25   } 
    26   IsImage = GetCurrentDevice ();
    27   if (IsImage) {
    28     if (!GetImage (&Source, &Nsource)) return (FALSE);
    29   } else {
    30     if (!GetGraph (&graphmode, &Source, &Nsource)) return (FALSE);
    31   }
     22  if (!GetGraphData (NULL, &kapa, name)) return (FALSE);
     23  FREE (name);
    3224
    3325  N = 0;
     
    3931  }
    4032 
    41   buf = NULL;
    42   if (IsImage) buf = SelectBuffer (GetImageName(), OLDBUFFER, FALSE);
    43  
    44   KiiCursorOn (Source);
     33  KiiCursorOn (kapa);
    4534 
    4635  oldsignal = signal (SIGINT, handle_interrupt);
    4736  interrupt = FALSE;
    48   Z = -1.0;
     37
    4938  for (i = 0; ((i < N) || (N == 0)) && !interrupt; i++) {
    50     KiiCursorRead (Source, &X, &Y, key);
     39
     40    KiiCursorRead (kapa, &X, &Y, &Z, &R, &D, key);
    5141
    5242    sprintf (string, "X%s", key);
     
    5444    sprintf (string, "Y%s", key);
    5545    set_variable (string, Y);
     46    sprintf (string, "Z%s", key);
     47    set_variable (string, Z);
     48    sprintf (string, "R%s", key);
     49    set_variable (string, R);
     50    sprintf (string, "D%s", key);
     51    set_variable (string, D);
     52
    5653    set_str_variable ("KEY", key);
    5754   
    58     if (IsImage) {
    59       if (buf != NULL) {
    60         Z = gfits_get_matrix_value (&buf[0].matrix, (int) X, (int) Y);
    61       }
    62       gprint (GP_LOG, "%s %f %f  %f\n", key, X, Y, Z);
    63     } else {
    64       XY_to_RD (&R, &D, X, Y, &graphmode.coords);
    65       sprintf (string, "R%s", key);
    66       set_variable (string, R);
    67       sprintf (string, "D%s", key);
    68       set_variable (string, D);
    69       gprint (GP_LOG, "%s %f %f\n", key, X, Y);
    70     }
     55    gprint (GP_LOG, "%s %f %f %f %f %f\n", key, X, Y, Z, R, D);
     56
    7157    if (!strcasecmp (key, "Q")) break;
    7258  }
    7359
    7460  signal (SIGINT, oldsignal);
    75   KiiCursorOff (Source);
     61  KiiCursorOff (kapa);
    7662  return (TRUE);
    7763}
  • trunk/Ohana/src/opihi/cmd.data/device.c

    r7917 r13479  
    33int device (int argc, char **argv) {
    44
    5   int N, Source, Nsource, IsImage;
     5  int N, kapa, IsImage;
     6  char *name;;
    67  /* set / get current graphics device */
    78
    8   Nsource = -1;
     9  name = NULL;
    910  if ((N = get_argument (argc, argv, "-n"))) {
    1011    remove_argument (N, &argc, argv);
    11     Nsource = atof (argv[N]);
     12    name = strcreate (argv[N]);
    1213    remove_argument (N, &argc, argv);
    1314  }
    14   if ((N = get_argument (argc, argv, "-g"))) {
    15     remove_argument (N, &argc, argv);
    16     SetImageDevice (FALSE);
    17   } 
    18   if ((N = get_argument (argc, argv, "-i"))) {
    19     remove_argument (N, &argc, argv);
    20     SetImageDevice (TRUE);
    21   } 
    2215
    23   IsImage = GetCurrentDevice ();
    24   if (IsImage) {
    25     if (!GetImage (&Source, &Nsource)) return (FALSE);
    26     gprint (GP_ERR, "kii %d\n", Nsource);
     16  if (name == NULL) {
     17    name = GetKapaName ();
     18    if (name == NULL) {
     19      gprint (GP_ERR, "no device defined\n");
     20      return (NULL);
     21    }
    2722  } else {
    28     if (!GetGraph (NULL, &Source, &Nsource)) return (FALSE);
    29     gprint (GP_ERR, "kapa %d\n", Nsource);
     23    if (!GetGraph (NULL, &kapa, name)) return (FALSE);
    3024  }
     25  gprint (GP_ERR, "kapa %s\n", name);
    3126
    3227  return (TRUE);
  • trunk/Ohana/src/opihi/cmd.data/dot.c

    r7917 r13479  
    33int dot (int argc, char **argv) {
    44 
     5  int kapa;
    56  Graphdata graphmode;
    67  float x, y;
    78
    8   if (!style_args (&graphmode, &argc, argv, -1)) return FALSE;
     9  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
    910
    1011  if (argc != 3) {
     
    1516  y = atof(argv[2]);
    1617
    17   /* set plotting options (these are sticky) */
    18   SetGraph (graphmode);
    19 
    2018  /* set point style and errorbar mode (these are NOT sticky) */
    2119  graphmode.style = 2;
    2220  graphmode.etype = 0;
    2321
    24   if (!PrepPlotting (1, &graphmode)) return (FALSE);
    25  
    26   PlotVector (1, &x);
    27   PlotVector (1, &y);
     22  if (!KapaPrepPlot (kapa, 1, &graphmode)) return (FALSE);
     23  KapaPlotVector (kapa, 1, &x, "x");
     24  KapaPlotVector (kapa, 1, &y, "y");
    2825 
    2926  return (TRUE);
  • trunk/Ohana/src/opihi/cmd.data/erase.c

    r7917 r13479  
    44 
    55  int i, N;
    6   int Ximage, Nimage;
     6  int kapa;
     7  char *name;
    78 
    8   Nimage = -1;
     9  name = NULL;
    910  if ((N = get_argument (argc, argv, "-n"))) {
    1011    remove_argument (N, &argc, argv);
    11     Nimage = atof (argv[N]);
     12    name = strcreate (argv[N]);
    1213    remove_argument (N, &argc, argv);
    1314  }
    14   if (!GetImage (&Ximage, &Nimage)) return (FALSE);
     15  if (!GetImage (NULL, &kapa, name)) return (FALSE);
     16  FREE (name);
    1517
    1618  if (argc < 2) {
     
    2224  for (i = 1; i < argc; i++) {
    2325    if (!(strcasecmp (argv[i], "all"))) {
    24       KiiEraseOverlay (Ximage, "red");
    25       KiiEraseOverlay (Ximage, "green");
    26       KiiEraseOverlay (Ximage, "blue");
    27       KiiEraseOverlay (Ximage, "yellow");
     26      KiiEraseOverlay (kapa, "red");
     27      KiiEraseOverlay (kapa, "green");
     28      KiiEraseOverlay (kapa, "blue");
     29      KiiEraseOverlay (kapa, "yellow");
    2830      continue;
    2931    }
     
    3234      return (FALSE);
    3335    }
    34     KiiEraseOverlay (Ximage, argv[i]);
     36    KiiEraseOverlay (kapa, argv[i]);
    3537  }
    3638  return (TRUE);
  • trunk/Ohana/src/opihi/cmd.data/grid.c

    r7917 r13479  
    33int grid (int argc, char **argv) {
    44 
    5   int j, N, MinorTick, MajorTick;
     5  int j, kapa, N, MinorTick, MajorTick;
    66  Vector Xvec, Yvec;
    77  double range, lrange, factor, mantis, fmantis, power, major, minor, first, next;
    88  Graphdata graphmode;
    9   int Ngraph;
    10 
    11   Ngraph = -1;
    12   if ((N = get_argument (argc, argv, "-n"))) {
    13     remove_argument (N, &argc, argv);
    14     Ngraph = atof (argv[N]);
    15     remove_argument (N, &argc, argv);
    16   }
    17   if (!GetGraph (&graphmode, NULL, &Ngraph)) return (FALSE);
     9
     10  if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
    1811
    1912  MajorTick = TRUE;
     
    200193  graphmode.ptype = 100; /* connect a pair */
    201194  graphmode.etype = 0;
    202   PrepPlotting (N, &graphmode);
    203   PlotVector (N, Xvec.elements);
    204   PlotVector (N, Yvec.elements);
     195  PlotVectorPair (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
    205196
    206197  free (Xvec.elements);
  • trunk/Ohana/src/opihi/cmd.data/init.c

    r10997 r13479  
    235235  int i;
    236236
    237   InitGraph ();
    238   InitImage ();
     237  InitKapa ();
    239238  InitQueues ();
    240239
  • trunk/Ohana/src/opihi/cmd.data/jpeg.c

    r7917 r13479  
    44
    55  char filename[1024];
    6   int N, Source, Nsource, IsImage, IsPNG;
     6  int N, kapa, IsImage, IsPNG, IsPPM;
     7  char *name;
    78 
    89  if ((N = get_argument (argc, argv, "--help"))) {
     
    1213
    1314  /* image type */
    14   IsPNG = TRUE;
     15  IsPPM = IsPNG = FALSE;
    1516  if ((N = get_argument (argc, argv, "-ppm"))) {
    1617    remove_argument (N, &argc, argv);
    17     IsPNG = FALSE;
     18    IsPPM = TRUE;
    1819  }
     20  if ((N = get_argument (argc, argv, "-png"))) {
     21    remove_argument (N, &argc, argv);
     22    IsPNG = TRUE;
     23  }
     24  if (!strcmp (argv[0], "png")) IsPNG = TRUE;
     25  if (!strcmp (argv[0], "ppm")) IsPPM = TRUE;
    1926
    2027  /* file name */
     
    2734
    2835  /* display source */
    29   Nsource = -1;
     36  name = NULL;
    3037  if ((N = get_argument (argc, argv, "-n"))) {
    3138    remove_argument (N, &argc, argv);
    32     Nsource = atof (argv[N]);
     39    name = strcreate (argv[N]);
    3340    remove_argument (N, &argc, argv);
    3441  }
     42
     43  /* XXX output png / jpeg needs to include both graph and image
     44     if available.  this is a poor mix of data representations
     45     (png for image / jpeg for plots)
    3546  if ((N = get_argument (argc, argv, "-g"))) {
    36     remove_argument (N, &argc, argv);
    37     SetImageDevice (FALSE);
    38   } 
    3947  if ((N = get_argument (argc, argv, "-i"))) {
    40     remove_argument (N, &argc, argv);
    41     SetImageDevice (TRUE);
    42   } 
    43   IsImage = GetCurrentDevice ();
    44   if (IsImage) {
    45     if (!GetImage (&Source, &Nsource)) return (FALSE);
    46     if (!filename[0]) strcpy (filename, "Ximage.jpg");
    47     KiiJPEG (Source, filename);
    48   } else {
    49     if (!GetGraph (NULL, &Source, &Nsource)) return (FALSE);
    50     if (!filename[0]) strcpy (filename, "Xgraph.png");
    51     if (IsPNG) {
    52       KapaPNG (Source, filename);
    53     } else {
    54       KapaPPM (Source, filename);
    55     }
     48  */
     49
     50  if (!GetGraph (NULL, &kapa, name)) return (FALSE);
     51  if (!IsPNG && !IsPPM) {
     52    if (!filename[0]) strcpy (filename, "kapa.jpg");
     53    KiiJPEG (kapa, filename);
     54  }
     55  if (IsPNG) {
     56    if (!filename[0]) strcpy (filename, "kapa.png");
     57    KapaPNG (kapa, filename);
     58  }
     59  if (IsPPM) {
     60    if (!filename[0]) strcpy (filename, "kapa.ppm");
     61    KapaPPM (kapa, filename);
    5662  }
    5763  return (TRUE);
  • trunk/Ohana/src/opihi/cmd.data/labels.c

    r7917 r13479  
    44 
    55  char name[64];
    6   int N, size, Xgraph;
     6  int N, size, kapa;
    77
    8   if (!GetGraph (NULL, &Xgraph, NULL)) return (FALSE);
     8  if (!GetGraph (NULL, &kapa, NULL)) return (FALSE);
    99
    1010  if (get_argument (argc, argv, "-h")) {
     
    3636    size = atof (argv[N]);
    3737    remove_argument (N, &argc, argv);
    38     KapaSetFont (Xgraph, name, size);
     38    KapaSetFont (kapa, name, size);
    3939  }
    4040
    4141  if ((N = get_argument (argc, argv, "-x"))) {
    4242    remove_argument (N, &argc, argv);
    43     KapaSendLabel (Xgraph, argv[N], 0);
     43    KapaSendLabel (kapa, argv[N], 0);
    4444    remove_argument (N, &argc, argv);
    4545  }
     
    4747  if ((N = get_argument (argc, argv, "-y"))) {
    4848    remove_argument (N, &argc, argv);
    49     KapaSendLabel (Xgraph, argv[N], 1);
     49    KapaSendLabel (kapa, argv[N], 1);
    5050    remove_argument (N, &argc, argv);
    5151  }
     
    5353  if ((N = get_argument (argc, argv, "+x"))) {
    5454    remove_argument (N, &argc, argv);
    55     KapaSendLabel (Xgraph, argv[N], 2);
     55    KapaSendLabel (kapa, argv[N], 2);
    5656    remove_argument (N, &argc, argv);
    5757  }
     
    5959  if ((N = get_argument (argc, argv, "+y"))) {
    6060    remove_argument (N, &argc, argv);
    61     KapaSendLabel (Xgraph, argv[N], 3);
     61    KapaSendLabel (kapa, argv[N], 3);
    6262    remove_argument (N, &argc, argv);
    6363  }
     
    6565  if ((N = get_argument (argc, argv, "-ul"))) {
    6666    remove_argument (N, &argc, argv);
    67     KapaSendLabel (Xgraph, argv[N], 4);
     67    KapaSendLabel (kapa, argv[N], 4);
    6868    remove_argument (N, &argc, argv);
    6969  }
     
    7171  if ((N = get_argument (argc, argv, "-ur"))) {
    7272    remove_argument (N, &argc, argv);
    73     KapaSendLabel (Xgraph, argv[N], 5);
     73    KapaSendLabel (kapa, argv[N], 5);
    7474    remove_argument (N, &argc, argv);
    7575  }
     
    7777  if ((N = get_argument (argc, argv, "-ll"))) {
    7878    remove_argument (N, &argc, argv);
    79     KapaSendLabel (Xgraph, argv[N], 6);
     79    KapaSendLabel (kapa, argv[N], 6);
    8080    remove_argument (N, &argc, argv);
    8181  }
     
    8383  if ((N = get_argument (argc, argv, "-lr"))) {
    8484    remove_argument (N, &argc, argv);
    85     KapaSendLabel (Xgraph, argv[N], 7);
     85    KapaSendLabel (kapa, argv[N], 7);
    8686    remove_argument (N, &argc, argv);
    8787  }
  • trunk/Ohana/src/opihi/cmd.data/limits.c

    r7917 r13479  
    44
    55  int N, APPLY;
    6   int Ngraph, Xgraph;
     6  int kapa;
     7  char *name;
    78  Graphdata graphmode;
    89  Vector *xvec, *yvec;
     
    1516    APPLY = TRUE;
    1617  }
    17 
    18   Ngraph = -1;
     18  name = NULL;
    1919  if ((N = get_argument (argc, argv, "-n"))) {
    2020    remove_argument (N, &argc, argv);
    21     Ngraph = atof (argv[N]);
     21    name = strcreate (argv[N]);
    2222    remove_argument (N, &argc, argv);
    2323  }
    24   if (!GetGraph (&graphmode, &Xgraph, &Ngraph)) return (FALSE);
     24  if (!GetGraph (&graphmode, &kapa, name)) return (FALSE);
     25  FREE (name);
    2526
    2627  if (argc == 1) {
    27     gprint (GP_ERR, "limits: %f %f %f %f [-a] [-n Xgraph]\n",
     28    gprint (GP_ERR, "limits: %f %f %f %f [-a] [-n device]\n",
    2829             graphmode.xmin, graphmode.xmax,
    2930             graphmode.ymin, graphmode.ymax);
     
    7172 success:
    7273  SetLimits (xvec, yvec, &graphmode);
    73   if (APPLY) KapaSetLimits (Xgraph, &graphmode);
     74  if (APPLY) KapaSetLimits (kapa, &graphmode);
    7475  return (TRUE);
    7576}
  • trunk/Ohana/src/opihi/cmd.data/line.c

    r12332 r13479  
    33int line (int argc, char **argv) {
    44 
     5  int kapa;
    56  Graphdata graphmode;
    67  float x[2], y[2];
    78
    8   if (!style_args (&graphmode, &argc, argv, -1)) return FALSE;
     9  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
    910
    1011  if (argc != 6) {
     
    1718  y[1] = atof(argv[5]);
    1819
    19   SetGraph (graphmode);
    20 
    2120  /* set point style and errorbar mode (these are NOT sticky) */
    2221  graphmode.style = 0;
    2322  graphmode.etype = 0;
    2423
    25   if (!PrepPlotting (2, &graphmode)) return (FALSE);
    26  
    27   PlotVector (2, x);
    28   PlotVector (2, y);
     24  if (!KapaPrepPlot (kapa, 2, &graphmode)) return (FALSE);
     25  KapaPlotVector (kapa, 2, x, "x");
     26  KapaPlotVector (kapa, 2, y, "y");
    2927 
    3028  return (TRUE);
    31 
    3229}
  • trunk/Ohana/src/opihi/cmd.data/load.c

    r7917 r13479  
    44 
    55  int i, N, n, ISCEL;
    6   int Ximage, Nimage, Noverlay, NOVERLAY;
     6  int kapa, Noverlay, NOVERLAY;
    77  char *c, type[10], string[128], line[1024];
    88  double x, y, dx, dy, x1, y1;
    99  double dra, ddec, ra1, dec1, ra, dec;
    1010  FILE *f;
    11   char *buffer;
     11  char *buffer, *name;
    1212  Coords coords;
    1313  Buffer *buf;
    1414  KiiOverlay *overlay;
     15  KapaImageData data;
    1516 
    16   Nimage = -1;
     17  name = NULL;
    1718  if ((N = get_argument (argc, argv, "-n"))) {
    1819    remove_argument (N, &argc, argv);
    19     Nimage = atof (argv[N]);
     20    name = strcreate (argv[N]);
    2021    remove_argument (N, &argc, argv);
    2122  }
    22   if (!GetImage (&Ximage, &Nimage)) return (FALSE);
     23  if (!GetImageData (&data, &kapa, name)) return (FALSE);
     24  FREE (name);
    2325
    2426  ISCEL = FALSE;
     
    4547
    4648  if (ISCEL) {
    47     if ((buf = SelectBuffer (GetImageName(), OLDBUFFER, TRUE)) == NULL) return (FALSE);
     49    if ((buf = SelectBuffer (data.name, OLDBUFFER, TRUE)) == NULL) return (FALSE);
    4850    GetCoords (&coords, &buf[0].header);
    4951  }
     
    125127  }
    126128
    127   KiiLoadOverlay (Ximage, overlay, Noverlay, argv[1]);
     129  KiiLoadOverlay (kapa, overlay, Noverlay, argv[1]);
    128130
    129131  for (i = 0; i < Noverlay; i++) {
  • trunk/Ohana/src/opihi/cmd.data/plot.c

    r7917 r13479  
    33int plot (int argc, char **argv) {
    44 
    5   int N, Npts;
     5  int kapa, N, Npts;
    66  Graphdata graphmode;
    77  Vector *xvec, *yvec, *dxmvec, *dxpvec, *dymvec, *dypvec;
    88
    9   if (!style_args (&graphmode, &argc, argv, -1)) return FALSE;
     9  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
    1010
    1111  /* decide on error bars */
     
    3636    return (FALSE);
    3737  }
    38   SetGraph (graphmode);
    3938
    4039  /* set errorbar mode (these are NOT sticky) */
     
    5756  if (Npts == 0) return (TRUE);
    5857
    59   if (!PrepPlotting (Npts, &graphmode)) return (FALSE);
     58  if (!KapaPrepPlot (kapa, Npts, &graphmode)) return (FALSE);
    6059 
    61   PlotVector (Npts, xvec[0].elements);
    62   PlotVector (Npts, yvec[0].elements);
     60  KapaPlotVector (kapa, Npts, xvec[0].elements, "x");
     61  KapaPlotVector (kapa, Npts, yvec[0].elements, "y");
    6362  if (graphmode.etype & 0x01) {
    64     PlotVector (Npts, dymvec[0].elements);
    65     PlotVector (Npts, dypvec[0].elements);
     63    KapaPlotVector (kapa, Npts, dymvec[0].elements, "dym");
     64    KapaPlotVector (kapa, Npts, dypvec[0].elements, "dyp");
    6665  }
    6766  if (graphmode.etype & 0x02) {
    68     PlotVector (Npts, dxmvec[0].elements);
    69     PlotVector (Npts, dxpvec[0].elements);
     67    KapaPlotVector (kapa, Npts, dxmvec[0].elements, "dxm");
     68    KapaPlotVector (kapa, Npts, dxpvec[0].elements, "dxp");
    7069  }
    71  
    7270  return (TRUE);
    73 
    7471}
  • trunk/Ohana/src/opihi/cmd.data/point.c

    r7917 r13479  
    44 
    55  int N, celestial, pixscale;
    6   int Ximage, Nimage;
     6  int kapa;
    77  double ra, dec, dra, ddec;
    88  double x1, y1, ra1, dec1;
     9  char *name;
    910  Coords coords;
    1011  Buffer *buf;
    1112  KiiOverlay overlay;
     13  KapaImageData data;
    1214
    13   Nimage = -1;
     15  name = NULL;
    1416  if ((N = get_argument (argc, argv, "-n"))) {
    1517    remove_argument (N, &argc, argv);
    16     Nimage = atof (argv[N]);
     18    name = strcreate (argv[N]);
    1719    remove_argument (N, &argc, argv);
    1820  }
    19   if (!GetImage (&Ximage, &Nimage)) return (FALSE);
    20  
     21  if (!GetImageData (&data, &kapa, name)) return (FALSE);
     22  FREE (name);
     23
    2124  celestial = FALSE;
    2225  if ((N = get_argument (argc, argv, "-c"))) {
     
    3740 
    3841  if (celestial) {
    39     if ((buf = SelectBuffer (GetImageName(), OLDBUFFER, TRUE)) == NULL) return (FALSE);
     42    if ((buf = SelectBuffer (data.name, OLDBUFFER, TRUE)) == NULL) return (FALSE);
    4043    GetCoords (&coords, &buf[0].header);
    4144  }
     
    6669  }
    6770  overlay.type = KiiOverlayTypeByName (argv[2]);
    68   KiiLoadOverlay (Ximage, &overlay, 1, argv[1]);
     71  KiiLoadOverlay (kapa, &overlay, 1, argv[1]);
    6972  return (TRUE);
    7073}
  • trunk/Ohana/src/opihi/cmd.data/ps.c

    r12892 r13479  
    33int ps (int argc, char **argv) {
    44
    5   char filename[1024], pagename[1024];
    6   int N, Source, Nsource, scaleMode, pageMode, IsImage;
     5  char filename[1024], pagename[1024], *name;
     6  int N, kapa, scaleMode, pageMode, IsImage;
    77 
    88  if ((N = get_argument (argc, argv, "--help"))) goto help;
     
    4444
    4545  /* which tool */
    46   Nsource = -1;
     46  name = NULL;
    4747  if ((N = get_argument (argc, argv, "-n"))) {
    4848    remove_argument (N, &argc, argv);
    49     Nsource = atof (argv[N]);
     49    name = strcreate (argv[N]);
    5050    remove_argument (N, &argc, argv);
    5151  }
    52   /* which device */
    53   if ((N = get_argument (argc, argv, "-g"))) {
    54     remove_argument (N, &argc, argv);
    55     SetImageDevice (FALSE);
    56   } 
    57   if ((N = get_argument (argc, argv, "-i"))) {
    58     remove_argument (N, &argc, argv);
    59     SetImageDevice (TRUE);
    60   } 
    61  
     52
    6253  if ((argc > 1) && filename[0]) goto help;
    6354
    6455  if (argc > 1) strcpy (filename, argv[1]);
    6556
    66   IsImage = GetCurrentDevice ();
    67   if (IsImage) {
    68     if (!GetImage (&Source, &Nsource)) return (FALSE);
    69     if (!filename[0]) strcpy (filename, "Ximage.ps");
    70   } else {
    71     if (!GetGraph (NULL, &Source, &Nsource)) return (FALSE);
    72     if (!filename[0]) strcpy (filename, "Xgraph.ps");
    73   }
     57  // get the connection to kapa, false if none available
     58  if (!GetGraphData (NULL, &kapa, name)) return (FALSE);
     59  FREE (name);
     60
     61  if (!filename[0]) strcpy (filename, "kapa.ps");
    7462 
    7563  /* tell Ximage/Xgraph to ps the image */
    76   KiiPS (Source, filename, scaleMode, pageMode, pagename);
     64  KiiPS (kapa, filename, scaleMode, pageMode, pagename);
    7765  return (TRUE);
    7866
  • trunk/Ohana/src/opihi/cmd.data/rd.c

    r13107 r13479  
    5959
    6060  /* find matrix, free old data */
    61   if ((buf = SelectBuffer (argv[1], ANYBUFFER, TRUE)) == NULL) return (FALSE);
     61  if ((buf = SelectBuffer (argv[1], ANYBUFFER, TRUE)) == NULL) {
     62      fclose (f);
     63      return (FALSE);
     64  }
    6265  gfits_free_matrix (&buf[0].matrix);
    6366  gfits_free_header (&buf[0].header);
     
    7982      gprint (GP_ERR, "entry in %s not found\n", argv[2]);
    8083      DeleteBuffer (buf);
     84      fclose (f);
    8185      return (FALSE);
    8286    }
     
    99103        DeleteBuffer (buf);
    100104        free (CCDKeyword);
     105        fclose (f);
    101106        return (FALSE);
    102107      }
     
    105110        DeleteBuffer (buf);
    106111        free (CCDKeyword);
     112        fclose (f);
    107113        return (FALSE);
    108114      }
     
    143149    buf[0].header.bzero = 0;
    144150    buf[0].header.bscale = 1;
     151    fclose (f);
    145152    return (TRUE);
    146153  }
     
    152159    gprint (GP_ERR, "-plane is too large: %d total planes\n", Nplane);
    153160    DeleteBuffer (buf);
     161    fclose (f);
    154162    return (FALSE);
    155163  }
  • trunk/Ohana/src/opihi/cmd.data/resize.c

    r7917 r13479  
    55  char *end;
    66  double NX, NY;
    7   int N, Source, Nsource, IsImage;
     7  int N, kapa;
     8  char *name;
    89 
    910  /* display source */
    10   Nsource = -1;
     11  name = NULL;
    1112  if ((N = get_argument (argc, argv, "-n"))) {
    1213    remove_argument (N, &argc, argv);
    13     Nsource = atof (argv[N]);
     14    name = strcreate (argv[N]);
    1415    remove_argument (N, &argc, argv);
    1516  }
    16   if ((N = get_argument (argc, argv, "-g"))) {
    17     remove_argument (N, &argc, argv);
    18     SetImageDevice (FALSE);
    19   } 
    20   if ((N = get_argument (argc, argv, "-i"))) {
    21     remove_argument (N, &argc, argv);
    22     SetImageDevice (TRUE);
    23   } 
    24   IsImage = GetCurrentDevice ();
    25   if (IsImage) {
    26     if (!GetImage (&Source, &Nsource)) return (FALSE);
    27   } else {
    28     if (!GetGraph (NULL, &Source, &Nsource)) return (FALSE);
    29   }
     17  if (!GetImage (NULL, &kapa, name)) return (FALSE);
     18  FREE (name);
    3019
    3120  if (argc != 3) {
     
    4938  if (!strcmp (end, "cm")) { NY *= 38; }
    5039
    51   KiiResize (Source, NX, NY);
     40  KiiResize (kapa, NX, NY);
    5241  return (TRUE);
    5342}
  • trunk/Ohana/src/opihi/cmd.data/save.c

    r7917 r13479  
    44 
    55  int N, celestial;
    6   int Ximage, Nimage;
     6  int kapa;
     7  char *name;
    78 
    8   Nimage = -1;
     9  name = NULL;
    910  if ((N = get_argument (argc, argv, "-n"))) {
    1011    remove_argument (N, &argc, argv);
    11     Nimage = atof (argv[N]);
     12    name = strcreate (argv[N]);
    1213    remove_argument (N, &argc, argv);
    1314  }
    14   if (!GetImage (&Ximage, &Nimage)) return (FALSE);
     15  if (!GetImage (NULL, &kapa, name)) return (FALSE);
     16  FREE (name);
    1517
    1618  celestial = FALSE;
     
    2628  }
    2729
    28   KiiSaveOverlay (Ximage, celestial, argv[1], argv[2]);
     30  KiiSaveOverlay (kapa, celestial, argv[1], argv[2]);
    2931  return (TRUE);
    3032}
  • trunk/Ohana/src/opihi/cmd.data/section.c

    r7917 r13479  
    11# include "data.h"
     2
     3enum {NONE, LIST, UP, DOWN, TOP, BOTTOM, TOOL};
    24
    35int section (int argc, char **argv) {
    46 
    5   int N, List;
    6   int Ngraph, Xgraph;
     7  int N, action, kapa;
     8  char *name, *location;
    79  Graphdata graphmode;
    810  KapaSection section;
    911
    10   List = FALSE;
     12  action = NONE;
    1113  if ((N = get_argument (argc, argv, "-list"))) {
     14    action = LIST;
    1215    remove_argument (N, &argc, argv);
    13     List = TRUE;
     16  }
     17  if ((N = get_argument (argc, argv, "-up"))) {
     18    action = UP;
     19    remove_argument (N, &argc, argv);
     20  }
     21  if ((N = get_argument (argc, argv, "-down"))) {
     22    action = DOWN;
     23    remove_argument (N, &argc, argv);
     24  }
     25  if ((N = get_argument (argc, argv, "-top"))) {
     26    action = TOP;
     27    remove_argument (N, &argc, argv);
     28  }
     29  if ((N = get_argument (argc, argv, "-bottom"))) {
     30    action = BOTTOM;
     31    remove_argument (N, &argc, argv);
     32  }
     33  if ((N = get_argument (argc, argv, "-imtool"))) {
     34    action = TOOL;
     35    remove_argument (N, &argc, argv);
     36    location = argv[N];
     37    remove_argument (N, &argc, argv);
    1438  }
    1539
    16   Ngraph = -1;
     40  name = NULL;
    1741  if ((N = get_argument (argc, argv, "-n"))) {
    1842    remove_argument (N, &argc, argv);
    19     Ngraph = atof (argv[N]);
     43    name = strcreate (argv[N]);
    2044    remove_argument (N, &argc, argv);
    2145  }
    22   if (!GetGraph (&graphmode, &Xgraph, &Ngraph)) return (FALSE);
     46  if (!GetGraph (&graphmode, &kapa, name)) return (FALSE);
     47  FREE (name);
    2348
    2449  /* list sections */
    25   if (argc == 1) {
    26     KapaGetSection (Xgraph, "*");
    27     gprint (GP_ERR, "USAGE: section name [x y dx dy]\n");
     50  if ((argc == 1) && (action == NONE)) {
     51    KapaGetSection (kapa, "*");
     52    gprint (GP_ERR, "USAGE: section name [x y dx dy] [options]\n");
     53    gprint (GP_ERR, "OPTIONS: -list   : show properties of all sections\n");
     54    gprint (GP_ERR, "         -up     : move section up in display stack\n");
     55    gprint (GP_ERR, "         -down   : move section down in display stack\n");
     56    gprint (GP_ERR, "         -top    : move section to top of display stack\n");
     57    gprint (GP_ERR, "         -bottom : move section to bottom of display stack\n");
     58    gprint (GP_ERR, "         -imtool (position) : set location of image zoom / status box\n");
     59    gprint (GP_ERR, "                 (position may be: -x, +x, -y, +y, none)\n");
    2860    return (TRUE);
    2961  }
     
    3163  if (argc == 2) {
    3264    /* select / show section */
    33     if (List) {
    34       KapaGetSection (Xgraph, argv[1]);
    35     } else {
    36       KapaSelectSection (Xgraph, argv[1]);
     65    switch (action) {
     66      case NONE:
     67        KapaSelectSection (kapa, argv[1]);
     68        break;
     69
     70      case UP:
     71        KapaMoveSection (kapa, argv[1], "up");
     72        break;
     73      case DOWN:
     74        KapaMoveSection (kapa, argv[1], "down");
     75        break;
     76      case TOP:
     77        KapaMoveSection (kapa, argv[1], "top");
     78        break;
     79      case BOTTOM:
     80        KapaMoveSection (kapa, argv[1], "bottom");
     81        break;
     82
     83      case TOOL:
     84        if (!strcmp(location, "-x")) {
     85          KapaSetToolbox (kapa, 1);
     86          break;
     87        }
     88        if (!strcmp(location, "+x")) {
     89          KapaSetToolbox (kapa, 3);
     90          break;
     91        }
     92        if (!strcmp(location, "-y")) {
     93          KapaSetToolbox (kapa, 2);
     94          break;
     95        }
     96        if (!strcmp(location, "+y")) {
     97          KapaSetToolbox (kapa, 4);
     98          break;
     99        }
     100        if (!strcmp(location, "none")) {
     101          KapaSetToolbox (kapa, 0);
     102          break;
     103        }
     104        gprint (GP_ERR, "unknown toolbox location %s\n", location);
     105        gprint (GP_ERR, "valid values: -x, +x, -y, +y, none\n");
     106        return (FALSE);
     107
     108      case LIST:
     109        KapaGetSection (kapa, argv[1]);
     110        break;
    37111    }
    38112    return (TRUE);
     
    46120    section.dx = atof (argv[4]);
    47121    section.dy = atof (argv[5]);
    48     KapaSetSection (Xgraph, &section);
     122    KapaSetSection (kapa, &section);
    49123    return (TRUE);
    50124  }
    51125  gprint (GP_ERR, "USAGE: section name [x y dx dy]\n");
     126  gprint (GP_ERR, "USAGE: section name [-list] [-up] [-down] [-top] [-bottom]\n");
    52127  return (FALSE);
    53128}
  • trunk/Ohana/src/opihi/cmd.data/style.c

    r7917 r13479  
    33int style (int argc, char **argv) {
    44 
    5   Graphdata graphmode;
     5  int kapa;
     6  Graphdata data;
    67
    7   if (!style_args (&graphmode, &argc, argv, -1)) return FALSE;
     8  if (!style_args (&data, &argc, argv, &kapa)) return FALSE;
    89
    910  if (argc > 1) {
     
    1112    return (FALSE);
    1213  }
    13   SetGraph (graphmode);
     14  KapaSetGraphData (kapa, &data);
    1415
    1516  return (TRUE);
  • trunk/Ohana/src/opihi/cmd.data/textline.c

    r7917 r13479  
    66  char name[64];
    77  double x, y, angle;
    8   int Ngraph, Xgraph;
     8  int kapa;
    99  Graphdata graphmode;
    1010
    11   Ngraph = -1;
    12   if ((N = get_argument (argc, argv, "-n"))) {
    13     remove_argument (N, &argc, argv);
    14     Ngraph = atof (argv[N]);
    15     remove_argument (N, &argc, argv);
    16   }
    17   if (!GetGraph (&graphmode, &Xgraph, &Ngraph)) return (FALSE);
     11  if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
    1812
    1913  if ((N = get_argument (argc, argv, "-fn"))) {
     
    2317    size = atof (argv[N]);
    2418    remove_argument (N, &argc, argv);
    25     KapaSetFont (Xgraph, name, size);
     19    KapaSetFont (kapa, name, size);
    2620  }
    2721
     
    5852  }   
    5953
    60   KapaSendTextline (Xgraph, argv[3], x, y, angle);
     54  KapaSendTextline (kapa, argv[3], x, y, angle);
    6155  return (TRUE);
    6256}
  • trunk/Ohana/src/opihi/cmd.data/tv.c

    r7917 r13479  
    33int tv (int argc, char **argv) {
    44 
    5   int N, Ximage, Nimage;
     5  int N, kapa;
     6  char *name, *file;
    67  Coords coords;
    78  Buffer *buf;
    89  KiiImage image;
    9   KiiDisplayMode mode;
     10  KapaImageData data;
    1011
    11   Nimage = -1;
     12  name = NULL;
    1213  if ((N = get_argument (argc, argv, "-n"))) {
    1314    remove_argument (N, &argc, argv);
    14     Nimage = atof (argv[N]);
     15    name = strcreate (argv[N]);
    1516    remove_argument (N, &argc, argv);
    1617  }
    17   if (!GetImage (&Ximage, &Nimage)) return (FALSE);
     18  if (!GetImage (&data, &kapa, name)) return (FALSE);
     19  FREE (name);
    1820
    1921  /* shell exits on pipe close, FIX */
    2022  if ((N = get_argument (argc, argv, "-kill"))) {
    21     KiiClose (Ximage);
    22     Ximage = 0;
     23    KiiClose (kapa);
    2324    return (TRUE);
    2425  }
    2526
    26   mode.logflux = FALSE;
     27  data.logflux = FALSE;
    2728  if ((N = get_argument (argc, argv, "-log"))) {
    2829    remove_argument (N, &argc, argv);
    29     mode.logflux = TRUE;
     30    data.logflux = TRUE;
    3031  }
    3132
     33  // use the currently-set zero,range values if not supplied
    3234  if ((argc != 2) && (argc != 4)) {
    3335    gprint (GP_ERR, "USAGE: tv <buffer> [zero range] [-n Nimage] [-log] [-kill]\n");
     
    3537  }
    3638
    37   GetImageScale (&mode.zero, &mode.range);
    3839  if (argc == 4) {
    39     mode.zero = atof (argv[2]);
    40     mode.range = atof (argv[3]);
    41     if (mode.range == 0.0) mode.range = 0.001;
    42     SetImageScale (mode.zero, mode.range);
     40    data.zero = atof (argv[2]);
     41    data.range = atof (argv[3]);
     42    if (data.range == 0.0) data.range = 0.001;
    4343  }
    4444
     
    4949  image.Nx = buf[0].matrix.Naxis[0];
    5050  image.Ny = buf[0].matrix.Naxis[1];
    51   image.file = buf[0].file;
    52   image.name = buf[0].name;
    5351
    54   KiiNewPicture1D (Ximage, &image, &mode, &coords);
     52  // send only the root of the file, not the full path
     53  file = filerootname (buf[0].file);
     54  strcpy (data.file, file);
     55  free (file);
    5556
    56   SetImageName (argv[1]);
     57  strcpy (data.name, argv[1]);
     58 
     59  KiiNewPicture1D (kapa, &image, &data, &coords);
     60
    5761  set_str_variable ("TV", argv[1]);
    5862  return (TRUE);
    5963}
    60 
    61 
    62 /*
    63 projections and coordinates:
    64 
    65 IRAS:
    66 CTYPE1  = 'LL      '                    /TANGENT PLANE (L)                     
    67 CRVAL1  =         0.100000D+02          /R.A. OF MAP CENTER  *** SEE COMMENT   
    68 CDELT1  =        -0.133333D-01          /SEPARATION IN L (DEG)                 
    69 CRPIX1  =                  128          /MAPCENTER IN L                       
    70 CROTA1  =         0.000000E+00          /NO ROTATION           
    71                                                                                
    72 CTYPE2  = 'MM      '                    /TANGENT PLANE (M)                     
    73 CRVAL2  =         0.410000D+02          /DEC. OF MAP CENTER  *** SEE COMMENT   
    74 CDELT2  =         0.133333D-01          /SEPARATION IN M (DEG)                 
    75 CRPIX2  =                  128          /MAP CENTER IN M                       
    76 CROTA2  =         0.000000E+00          /NO ROTATION                           
    77 
    78 HIRAS:
    79 CTYPE1  = 'RA---TAN          ' / PRIMARY AXIS NAME                             
    80 CRVAL1  =   1.000000000000E+01 / PRIMARY REFERENCE VALUE                       
    81 CDELT1  =  -5.555555555556E-03 / PRIMARY PIXEL SEPARATION                     
    82 CRPIX1  =   2.560000000000E+02 / PRIMARY REFERENCE PIXEL                       
    83 CUNIT1  = 'DEGREE            ' / PRIMARY AXIS UNITS                           
    84 
    85 CDELT2  =   5.555555555556E-03 / PRIMARY PIXEL SEPARATION                     
    86 CRPIX2  =   2.560000000000E+02 / PRIMARY REFERENCE PIXEL                       
    87 CRVAL2  =   4.100000000000E+01 / PRIMARY REFERENCE VALUE                       
    88 CTYPE2  = 'DEC--TAN          ' / PRIMARY AXIS NAME                             
    89 CUNIT2  = 'DEGREE            ' / PRIMARY AXIS UNITS                           
    90 
    91 PROJTYPE= 'GNOMON    '                                                         
    92 COORDSYS= 'EQUATORIAL     '                                                   
    93 
    94 gene (small FOV linear):
    95 RA_O
    96 RA_X
    97 RA_Y
    98 DEC_O
    99 DEC_X
    100 DEC_Y
    101 
    102 
    103 */
    104 
    105 # ifdef NEWTVMODE 
    106   {
    107     double *pixvalues, slope;
    108 
    109     ALLOCATE (pixvalues, double, Ncolors + 1);
    110     range = fabs (range);
    111     for (i = 0; i < Ncolors + 1; i++) {
    112       if (ISLOG) {
    113         pixvalues[i] = i*range / NNcol + zero;
    114       }
    115       if (!ISLOG) {
    116         pixvalues[i] = pow (10.0, i*log10(range - 1.0) / NNcol) + zero - 1.0;
    117       }     
    118     }
    119     for (j = 0; j < Npix; j++, in++, out++) {
    120       if (*in < pixvalues[0]) {
    121         i = 0;
    122       } else {
    123         if (*in > pixvalues[NNcol]) {
    124           i = NNcol;
    125         } else {
    126           for (i = 0; (*in < pixvalues[i]) || (*in > pixvalues[i+1]); ) {
    127             slope = 1.0 / (pixvalues[i+1] - pixvalues[i]);
    128             i = MIN (MAX (0, i + (*in - pixvalues[i]) * slope), NNcol);
    129           }
    130         }       
    131       }
    132       /* for (i = 0; (i < Ncolors - 1) && (pixvalues[i] < *in); i++); */
    133       *out = i;
    134     }
    135     free (pixvalues);
    136   }
    137 # endif
  • trunk/Ohana/src/opihi/cmd.data/tvcontour.c

    r7917 r13479  
    5858  float *v00, *v01, *v10, *v11;
    5959  float *Vout, *Vin, *matrix;
    60   int Ximage, Nimage, N, Noverlay, NOVERLAY;
     60  char *name;
     61  int kapa, N, Noverlay, NOVERLAY;
    6162  Buffer *buf;
    6263  KiiOverlay *overlay;
    6364 
    64   Nimage = -1;
     65  name = NULL;
    6566  if ((N = get_argument (argc, argv, "-n"))) {
    6667    remove_argument (N, &argc, argv);
    67     Nimage = atof (argv[N]);
     68    name = strcreate (argv[N]);
    6869    remove_argument (N, &argc, argv);
    6970  }
    70   if (!GetImage (&Ximage, &Nimage)) return (FALSE);
     71  if (!GetImage (NULL, &kapa, name)) return (FALSE);
     72  FREE (name);
    7173
    7274  if ((argc != 4) && (argc != 5)) {
     
    277279  }
    278280 
    279   KiiLoadOverlay (Ximage, overlay, Noverlay, argv[2]);
     281  KiiLoadOverlay (kapa, overlay, Noverlay, argv[2]);
    280282  free (overlay);
    281283
  • trunk/Ohana/src/opihi/cmd.data/tvgrid.c

    r7917 r13479  
    1111  char format[16];
    1212  Coords coords;
    13   int Ximage, Nimage, N, Noverlay, NOVERLAY;
     13  int kapa, N, Noverlay, NOVERLAY;
     14  char *name;
    1415  Buffer *buf;
    1516  KiiOverlay *overlay;
    1617
    17   Nimage = -1;
     18  name = NULL;
    1819  if ((N = get_argument (argc, argv, "-n"))) {
    1920    remove_argument (N, &argc, argv);
    20     Nimage = atof (argv[N]);
     21    name = strcreate (argv[N]);
    2122    remove_argument (N, &argc, argv);
    2223  }
    23   if (!GetImage (&Ximage, &Nimage)) return (FALSE);
    24  
     24  if (!GetImage (NULL, &kapa, name)) return (FALSE);
     25  FREE (name);
     26
    2527  if (argc != 3) {
    2628    gprint (GP_ERR, "USAGE: tvgrid (overlay) (buffer)\n");
     
    144146  }
    145147
    146   # if (0)
    147   /* write the labels on the axes */
    148   dDEC = fabs(dec1 - dec0) / 100;
    149   for (ra = dRA * ((int)(MIN(ra0, ra1)/dRA) + 1); ra < MAX(ra0, ra1); ra += dRA) {
    150     RD_to_XY (&x0, &y0, ra + 0.1*dRA, MIN(dec0, dec1), &coords);
    151     sprintf (label, format, ra);
    152     sprintf (buffer, "%15s %20.10f %20.10f %20.10f %20.10f ", "TEXT", x0, y0, (double)(strlen(label) + 1), 0.0);
    153     write (Ximage, buffer, 128);
    154     write (Ximage, label, strlen(label) + 1);
    155     RD_to_XY (&x0, &y0, ra, MIN(dec0, dec1), &coords);
    156     for (dec = MIN(dec0, dec1) + dDEC; dec < MAX(dec0,dec1); dec += dDEC) {
    157       RD_to_XY (&x1, &y1, ra, dec, &coords);
    158       sprintf (buffer, "%15s %20.10f %20.10f %20.10f %20.10f ", "LINE", x0, y0, (x1 - x0), (y1 - y0));
    159       write (Ximage, buffer, 128);
    160       x0 = x1;
    161       y0 = y1;
    162     }
    163   }
    164   # endif
    165 
    166   KiiLoadOverlay (Ximage, overlay, Noverlay, argv[1]);
     148  KiiLoadOverlay (kapa, overlay, Noverlay, argv[1]);
    167149  free (overlay);
    168150
  • trunk/Ohana/src/opihi/cmd.data/vload.c

    r7917 r13479  
    44 
    55  int i, N, Noverlay;
    6   int Ximage, Nimage, type;
     6  int kapa, type;
     7  char *name;
    78  double dx, dy, size;
    89  KiiOverlay *overlay;
    910  Vector *vecx, *vecy;
    1011 
    11   Nimage = -1;
     12  name = NULL;
    1213  if ((N = get_argument (argc, argv, "-n"))) {
    1314    remove_argument (N, &argc, argv);
    14     Nimage = atof (argv[N]);
     15    name = strcreate (argv[N]);
    1516    remove_argument (N, &argc, argv);
    1617  }
    17   if (!GetImage (&Ximage, &Nimage)) return (FALSE);
     18  if (!GetImage (NULL, &kapa, name)) return (FALSE);
     19  FREE (name);
    1820
    1921  type = KII_OVERLAY_BOX;
     
    6567  }
    6668
    67   KiiLoadOverlay (Ximage, overlay, Noverlay, argv[1]);
     69  KiiLoadOverlay (kapa, overlay, Noverlay, argv[1]);
    6870  free (overlay);
    6971  return (TRUE);
  • trunk/Ohana/src/opihi/cmd.data/zplot.c

    r7917 r13479  
    33int zplot (int argc, char **argv) {
    44 
    5   int i, N, Npts, Ngraph;
     5  int i, kapa, N, Npts;
    66  float *in, *out;
    77  double min, range;
     
    99  Vector *xvec, *yvec, *zvec, Zvec;
    1010
    11   Ngraph = -1;
    12   if ((N = get_argument (argc, argv, "-n"))) {
    13     remove_argument (N, &argc, argv);
    14     Ngraph = atof (argv[N]);
    15     remove_argument (N, &argc, argv);
    16   }
    17   if (!GetGraph (&graphmode, NULL, &Ngraph)) return (FALSE);
     11  if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
    1812
    1913  if (argc != 6) {
     
    5145  graphmode.etype = 0; /* no errorbars */
    5246  Npts = xvec[0].Nelements;
    53   PrepPlotting (Npts, &graphmode);
    54 
    55   PlotVector (Npts, xvec[0].elements);
    56   PlotVector (Npts, yvec[0].elements);
    57   PlotVector (Npts, Zvec.elements);
     47  PlotVectorTriplet (kapa, Npts, xvec[0].elements, yvec[0].elements, Zvec.elements, &graphmode);
    5848
    5949  free (Zvec.elements);
  • trunk/Ohana/src/opihi/dimm/dimm.c.in

    r12280 r13479  
    5050/* add program-dependent exit functions here */
    5151void cleanup () {
    52   QuitImage ();
    53   QuitGraph ();
     52  QuitKapa ();
    5453  return;
    5554}
  • trunk/Ohana/src/opihi/dvo/ImageSelection.c

    r7917 r13479  
    2020 
    2121  if (RegionSelect) {
    22     Ngraph = 0;
    23     if (!GetGraphData (&graphsky, NULL, &Ngraph)) {
     22    // how does this know which sky plot to use?
     23    if (!GetGraphData (&graphsky, NULL, NULL)) {
    2424      gprint (GP_ERR, "region display not available\n");
    2525      return (FALSE);
  • trunk/Ohana/src/opihi/dvo/Makefile

    r12842 r13479  
    2121$(SRC)/init.$(ARCH).o                   \
    2222$(SRC)/ImageOps.$(ARCH).o               \
    23 $(SRC)/ImageSelection.$(ARCH).o \
     23$(SRC)/ImageSelection.$(ARCH).o         \
    2424$(SRC)/LoadImages.$(ARCH).o             \
    2525$(SRC)/cmpReadFile.$(ARCH).o            \
    26 $(SRC)/compare.$(ARCH).o               \
     26$(SRC)/compare.$(ARCH).o                \
    2727$(SRC)/match_image.$(ARCH).o            \
    28 $(SRC)/photometry.$(ARCH).o            \
     28$(SRC)/photometry.$(ARCH).o             \
    2929$(SRC)/dvomisc.$(ARCH).o                \
    3030$(SRC)/region_list.$(ARCH).o            \
     31$(SRC)/dvomisc.$(ARCH).o                \
     32$(SRC)/dbBooleanCond.$(ARCH).o          \
     33$(SRC)/dbCheckStack.$(ARCH).o           \
     34$(SRC)/dbCmdlineFields.$(ARCH).o        \
     35$(SRC)/dbExtractAverages.$(ARCH).o      \
     36$(SRC)/dbExtractMeasures.$(ARCH).o      \
     37$(SRC)/dbFields.$(ARCH).o               \
     38$(SRC)/dbRPN.$(ARCH).o                  \
     39$(SRC)/dbStackMath.$(ARCH).o            \
     40$(SRC)/dbStackOps.$(ARCH).o             \
    3141$(SRC)/dvo.$(ARCH).o
    3242
  • trunk/Ohana/src/opihi/dvo/avextract.c

    r12332 r13479  
    33int avextract (int argc, char **argv) {
    44 
    5   int i, j, m, N, NPTS, param;
     5  int i, j, n, m, Npts, NPTS, last, Nfields, Nreturn, Ncstack, Nstack;
    66  int Nsecfilt, mode;
    77  char *RegionName, *RegionList, *p;
     8  char **cstack;
     9  float *values;
    810
    911  Catalog catalog;
    1012  SkyList *skylist;
    1113  PhotCode *code;
    12   Vector *vec;
     14  Vector **vec;
     15
     16  dbField *fields;
     17  dbStack *stack;
    1318
    1419  /* defaults */
     
    2429  Nsecfilt = GetPhotcodeNsecfilt ();
    2530
    26   /* interpret command-line options */
    27   SetSelectionParam (0);
     31  // remove skyregion options
     32  // XXX this needs to explicitly handle -qregion and -skyregion
    2833  if (!SetRegionSelection (&argc, argv, &RegionName, &RegionList)) goto escape;
    29   if (!SetPhotSelections (&argc, argv, 1)) goto usage;
    3034
    31   /* interpret required command-line arguments: mextract (value) */
    32   if (argc != 2) { goto usage; }
    33   param = GetAverageParam (argv[1]);
    34   if (param == AVE_ZERO) {
    35     if (!GetPhotcodeInfo (argv[1], &code, &mode)) {
    36       GetAverageParamHelp ();
    37       goto escape;
    38     }
    39     param = AVE_MAG;
    40     for (p = argv[1]; *p != 0; p++) {
    41       if (*p == '.') *p = ':';
    42     }
    43   }
    44   if (!TestPhotSelections (&code, &mode, param)) goto escape;
     35  // command-line is of the form: avextract field,field, field [where (field op value)...]
     36
     37  // parse the fields to be extracted and returned
     38  fields = dbCmdlineFields (argc, argv, DVO_TABLE_AVERAGE, &last, &Nfields);
     39  if (fields == NULL) return (FALSE);
     40
     41  // parse the remainder of the line as a boolean math expression
     42  cstack = isolate_elements (argc-last, &argv[last], &Ncstack);
     43 
     44  // construct the db Boolean math stack (frees cstack)
     45  stack = dbRPN (Ncstack, cstack, &Nstack);
     46
     47  Nreturn = Nfields;
     48  dbCheckStack (stack, Nstack, DVO_TABLE_AVERAGE, &fields, &Nfields);
     49  // XXX handle errors
    4550
    4651  /* load region corresponding to selection above */
    4752  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
    4853
    49   /* create storage vector */
    50   N = 0;
     54  /* create output storage vectors */
     55  ALLOCATE (values, float, Nfields);
     56  ALLOCATE (vec, Vector *, Nreturn);
     57  for (i = 0; i < Nreturn; i++) {
     58    if ((vec[i] = SelectVector (fields[i].name, ANYVECTOR, TRUE)) == NULL) goto escape;
     59  }
     60
     61  Npts = 0;
    5162  NPTS = 1;
    52   if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto escape;
    5363
    5464  // XXX need to add interrupt test to this loop
     
    6878    for (j = 0; j < catalog.Naverage; j++) {
    6979      m = catalog.average[j].offset;
    70       vec[0].elements[N] = ExtractAverages (code, mode, &catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], param);
    71       N++;
    72       CHECK_REALLOCATE (vec[0].elements, float, NPTS, N, 2000);
     80      // extract the relevant values
     81      // XXX for measure values, this could be optimized for one loop over measures...
     82      for (n = 0; n < Nfields; n++) {
     83        values[n] = dbExtractAverages (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &fields[n]);
     84      }
     85      // test the conditional statement
     86      if (!dbBooleanCond (stack, Nstack, values)) continue;
     87      for (n = 0; n < Nreturn; n++) {
     88        vec[n][0].elements[Npts] = values[n];
     89      }
     90      Npts++;
     91      if (Npts >= NPTS) {
     92        NPTS += 2000;
     93        for (n = 0; n < Nreturn; n++) {
     94          REALLOCATE (vec[n][0].elements, float, NPTS);
     95        }
     96      }
    7397    }
    7498    dvo_catalog_free (&catalog);
    7599  }
    76   vec[0].Nelements = N;
    77   REALLOCATE (vec[0].elements, float, MAX(1,N));
     100  for (n = 0; n < Nreturn; n++) {
     101    vec[n][0].Nelements = Npts;
     102    REALLOCATE (vec[n][0].elements, float, MAX(1,Npts));
     103  }
     104
     105  // XXX free fields and stack
    78106
    79107  SkyListFree (skylist, ((RegionName != NULL) || (RegionList != NULL)));
  • trunk/Ohana/src/opihi/dvo/catalog.c

    r12332 r13479  
    2828  int Ngraph;
    2929
    30   Ngraph = 0;
    31   if (!GetGraph (&graphmode, NULL, &Ngraph)) return (FALSE);
     30  if (!GetGraph (&graphmode, NULL, NULL)) return (FALSE);
    3231
    3332  VarConfig ("GSCDIR", "%s", gscdir);
     
    392391    PrepPlotting (N, &graphmode);
    393392   
    394     PlotVector (N, Xvec.elements);
    395     PlotVector (N, Yvec.elements);
    396     PlotVector (N, Zvec.elements);
     393    PlotVector (N, Xvec.elements, "x");
     394    PlotVector (N, Yvec.elements, "y");
     395    PlotVector (N, Zvec.elements, "z");
    397396   
    398397    free (Xvec.elements);
  • trunk/Ohana/src/opihi/dvo/cmpload.c

    r7917 r13479  
    88  int i, Noverlay, NOVERLAY, Nstar, N, Nin, Nextra, Objtype, type;
    99  int doneread, done, Nskip, Nbytes, nbytes, Ninstar;
    10   char *c, *c2;
     10  char *c, *c2, *name;
    1111  double dtmp;
    1212  FILE *f;
    1313  char *buffer;
    14   int Ximage, Nimage;
     14  int kapa;
    1515  Header header;
    1616  KiiOverlay *overlay;
    1717 
    18   Nimage = -1;
     18  name = NULL;
    1919  if ((N = get_argument (argc, argv, "-n"))) {
    2020    remove_argument (N, &argc, argv);
    21     Nimage = atof (argv[N]);
     21    name = strcreate (argv[N]);
    2222    remove_argument (N, &argc, argv);
    2323  }
    24   if (!GetImage (&Ximage, &Nimage)) return (FALSE);
     24  if (!GetImage (NULL, &kapa, name)) return (FALSE);
     25  FREE (name);
    2526
    2627  Objtype = 0;
     
    131132  fclose (f);
    132133
    133   KiiLoadOverlay (Ximage, overlay, Noverlay, argv[1]);
     134  KiiLoadOverlay (kapa, overlay, Noverlay, argv[1]);
    134135  free (overlay);
    135136
  • trunk/Ohana/src/opihi/dvo/dmt.c

    r12332 r13479  
    44int dmt (int argc, char **argv) {
    55 
    6   int i, m, k, N, Ngraph, SaveVectors;
     6  int i, m, k, N, kapa, SaveVectors;
    77  int Nsec, Nsecfilt, NPTS;
    88  double Radius;
     
    3838  }
    3939
    40   Ngraph = 0;
    41   if (!GetGraphData (&graphsky, NULL, &Ngraph)) return (FALSE);
     40  // XXX this needs to be fixed: how to access different graphs at once?
     41  gprint (GP_ERR, "ERROR: this function is currently disabled\n");
     42  return (FALSE);
     43  if (!GetGraphData (&graphsky, &kapa, NULL)) return (FALSE);
    4244  if (!GetGraph (&graphmode, NULL, NULL)) return (FALSE);
    4345
     
    142144  } else {
    143145    graphmode.style = 2; /* set style to points */
    144     PrepPlotting (N, &graphmode);
    145    
    146     PlotVector (N, Xvec.elements);
    147     PlotVector (N, Yvec.elements);
     146    PlotVector (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
    148147
    149148    free (Xvec.elements);
  • trunk/Ohana/src/opihi/dvo/dvo.c.in

    r12280 r13479  
    5555/* add program-dependent exit functions here */
    5656void cleanup () {
    57   QuitImage ();
    58   QuitGraph ();
     57  QuitKapa ();
    5958  return;
    6059}
  • trunk/Ohana/src/opihi/dvo/extract.c

    r12332 r13479  
    3131  RegionFile *regions;
    3232
    33   Ngraph = 0;
    34   if (!GetGraphData (&graphmode, NULL, &Ngraph)) return (FALSE);
     33  if (!GetGraphData (&graphmode, NULL, NULL)) return (FALSE);
    3534  if (!InitPhotcodes ()) return (FALSE);
    3635
  • trunk/Ohana/src/opihi/dvo/fitcolors.c

    r12332 r13479  
    2020  float *out, *colorFit, *deltaFit, dColor, C0, C1;
    2121  float minDelta, maxDelta, minColor, maxColor;
    22   int fd, Npx, Npy, NPX, NPY, Nplot, PLOT;
     22  int kapa, Npx, Npy, NPX, NPY, Nplot, PLOT;
    2323  Graphdata graphdata;
    2424  KapaSection section;
     
    8686
    8787  if (PLOT) {
    88     if (!GetGraph (&graphdata, &fd, NULL)) return (FALSE);
     88    if (!GetGraph (&graphdata, &kapa, NULL)) return (FALSE);
    8989    Nplot = 0;
    9090    Npx = Npy = 0;
     
    9595    graphdata.style = 2;
    9696    graphdata.ptype = 2;
    97     KapaClear (fd, TRUE);
    98     KapaSetFont (fd, "helvetica", 14);
     97    KapaClearSections (kapa);
     98    KapaSetFont (kapa, "helvetica", 14);
    9999
    100100    ALLOCATE (colorFit, float, 11);
     
    301301          strcpy (graphdata.labels, "1100");
    302302        }
    303         KapaSetSection (fd, &section);
    304         KapaSetLimits (fd, &graphdata);
    305         KapaBox (fd, &graphdata);
    306         KapaPrepPlot (fd, Npts, &graphdata);
    307         KapaPlotVector (fd, Npts, xvec[0].elements);
    308         KapaPlotVector (fd, Npts, yvec[0].elements);
     303        KapaSetSection (kapa, &section);
     304        KapaSetLimits (kapa, &graphdata);
     305        KapaBox (kapa, &graphdata);
     306        KapaPrepPlot (kapa, Npts, &graphdata);
     307        KapaPlotVector (kapa, Npts, xvec[0].elements, "x");
     308        KapaPlotVector (kapa, Npts, yvec[0].elements, "y");
    309309
    310310        for (i = 0; i < 11; i++) {
     
    313313        graphdata.style = 0;
    314314        graphdata.color = KapaColorByName ("red");
    315         KapaPrepPlot (fd, 11, &graphdata);
    316         KapaPlotVector (fd, 11, colorFit);
    317         KapaPlotVector (fd, 11, deltaFit);
    318 
    319         KapaSetFont (fd, "helvetica", 8);
     315        KapaPrepPlot (kapa, 11, &graphdata);
     316        KapaPlotVector (kapa, 11, colorFit, "x");
     317        KapaPlotVector (kapa, 11, deltaFit, "y");
     318
     319        KapaSetFont (kapa, "helvetica", 8);
    320320        sprintf (label, "%s", code[0][0].name);
    321         KapaSendTextline (fd, label, 0.2*maxColor + 0.8*minColor, 0.8*maxDelta + 0.2*minDelta, 0.0);
     321        KapaSendTextline (kapa, label, 0.2*maxColor + 0.8*minColor, 0.8*maxDelta + 0.2*minDelta, 0.0);
    322322        sprintf (label, "%s", code[1][0].name);
    323         KapaSendTextline (fd, label, 0.2*maxColor + 0.8*minColor, 0.2*maxDelta + 0.8*minDelta, 0.0);
    324         KapaSetFont (fd, "helvetica", 14);
     323        KapaSendTextline (kapa, label, 0.2*maxColor + 0.8*minColor, 0.2*maxDelta + 0.8*minDelta, 0.0);
     324        KapaSetFont (kapa, "helvetica", 14);
    325325
    326326        graphdata.style = 2;
     
    336336            Npy = 0;
    337337            sprintf (filename, "%s.%02d.png", plotname, Nplot);
    338             KapaPNG (fd, filename);
    339             KapaClear (fd, TRUE);
     338            KapaPNG (kapa, filename);
     339            KapaClearSections (kapa);
    340340            Nplot++;
    341341          }
  • trunk/Ohana/src/opihi/dvo/fitsed.c

    r12332 r13479  
    3131  float *fitmags, *fiterrs, *wavecode, *vegaToAB;
    3232  float color;
    33   double X, Y;
    34   int fd, PLOT;
     33  double X, Y, ZP, RA, DEC;
     34  int kapa, PLOT;
    3535  int Nrow, NROW, idx, Nfilter, start, row;
    3636  unsigned short colorP, colorM, code, USNOred, USNOblu;
     
    157157
    158158  if (PLOT) {
    159     if (!GetGraph (&graphdata, &fd, NULL)) return (FALSE);
     159    if (!GetGraph (&graphdata, &kapa, NULL)) return (FALSE);
    160160    SetLimitsRaw (wavecode, NULL, Nfilter, &graphdata);
    161161    graphdata.style = 2;
    162162    graphdata.ptype = 2;
    163     KapaClear (fd, TRUE);
     163    KapaClearSections (kapa);
    164164    magSection.name = strcreate ("mag");
    165165    magSection.x  = 0;
     
    173173    resSection.dy = 0.5;
    174174   
    175     KapaSetFont (fd, "helvetica", 14);
     175    KapaSetFont (kapa, "helvetica", 14);
    176176    ALLOCATE (fitmags, float, Nfilter);
    177177    ALLOCATE (fiterrs, float, Nfilter);
     
    261261        SWAP (graphdata.ymin, graphdata.ymax);
    262262
    263         KapaClear (fd, TRUE);
    264         KapaSetSection (fd, &magSection);
    265         KapaSetLimits (fd, &graphdata);
    266         KapaBox (fd, &graphdata);
     263        KapaClearSections (kapa);
     264        KapaSetSection (kapa, &magSection);
     265        KapaSetLimits (kapa, &graphdata);
     266        KapaBox (kapa, &graphdata);
    267267        graphdata.color = KapaColorByName ("blue");
    268268        graphdata.etype = 0;
    269         KapaPrepPlot (fd, Nfilter, &graphdata);
    270         KapaPlotVector (fd, Nfilter, wavecode);
    271         KapaPlotVector (fd, Nfilter, SEDtable[minFit.row][0].mags);
     269        KapaPrepPlot (kapa, Nfilter, &graphdata);
     270        KapaPlotVector (kapa, Nfilter, wavecode, "x");
     271        KapaPlotVector (kapa, Nfilter, SEDtable[minFit.row][0].mags, "y");
    272272        graphdata.color = KapaColorByName ("red");
    273273        graphdata.etype = 1;
     
    279279          fiterrs[j] = sourceError.mags[j];
    280280        }
    281         KapaPrepPlot (fd, Nfilter, &graphdata);
    282         KapaPlotVector (fd, Nfilter, wavecode);
    283         KapaPlotVector (fd, Nfilter, fitmags);
    284         KapaPlotVector (fd, Nfilter, fiterrs);
    285         KapaPlotVector (fd, Nfilter, fiterrs);
    286         KapaSendLabel (fd, "model,fit (mags)", 1);
     281        KapaPrepPlot (kapa, Nfilter, &graphdata);
     282        KapaPlotVector (kapa, Nfilter, wavecode, "x");
     283        KapaPlotVector (kapa, Nfilter, fitmags, "y");
     284        KapaPlotVector (kapa, Nfilter, fiterrs, "dym");
     285        KapaPlotVector (kapa, Nfilter, fiterrs, "dyp");
     286        KapaSendLabel (kapa, "model,fit (mags)", 1);
    287287
    288288        sprintf (line, "star: %10.6f %10.6f  T: %5.0fK  A_V|: %4.2f  M_D|: %5.2f  &sc&h^2|: %5.2f",
    289289                 catalog.average[i].R, catalog.average[i].D,
    290290                 SEDtable[minFit.row][0].Temp, SEDtable[minFit.row][0].Av, minFit.Md, minFit.chisq);
    291         KapaSendLabel (fd, line, 2);
    292         KapaSendLabel (fd, "model,fit (mags)", 1);
    293 
    294         KapaSetSection (fd, &resSection);
     291        KapaSendLabel (kapa, line, 2);
     292        KapaSendLabel (kapa, "model,fit (mags)", 1);
     293
     294        KapaSetSection (kapa, &resSection);
    295295        graphdata.ymin = -1.0;
    296296        graphdata.ymax = +1.0;
    297         KapaSetLimits (fd, &graphdata);
    298         KapaBox (fd, &graphdata);
     297        KapaSetLimits (kapa, &graphdata);
     298        KapaBox (kapa, &graphdata);
    299299        graphdata.color = KapaColorByName ("red");
    300300        graphdata.etype = 1;
     
    307307          fiterrs[j] = sourceError.mags[j];
    308308        }
    309         KapaPrepPlot (fd, Nfilter, &graphdata);
    310         KapaPlotVector (fd, Nfilter, wavecode);
    311         KapaPlotVector (fd, Nfilter, fitmags);
    312         KapaPlotVector (fd, Nfilter, fiterrs);
    313         KapaPlotVector (fd, Nfilter, fiterrs);
    314         KapaSendLabel (fd, "wavelength (nm)", 0);
    315         KapaSendLabel (fd, "resid (mags)", 1);
    316 
    317         KiiCursorOn (fd);
    318         while (KiiCursorRead (fd, &X, &Y, key)) {
     309        KapaPrepPlot (kapa, Nfilter, &graphdata);
     310        KapaPlotVector (kapa, Nfilter, wavecode, "x");
     311        KapaPlotVector (kapa, Nfilter, fitmags, "y");
     312        KapaPlotVector (kapa, Nfilter, fiterrs, "dym");
     313        KapaPlotVector (kapa, Nfilter, fiterrs, "dyp");
     314        KapaSendLabel (kapa, "wavelength (nm)", 0);
     315        KapaSendLabel (kapa, "resid (mags)", 1);
     316
     317        KiiCursorOn (kapa);
     318        while (KiiCursorRead (kapa, &X, &Y, &ZP, &RA, &DEC, key)) {
    319319          gprint (GP_ERR, "window: %f %f (%s)\n", X, Y, key);
    320320          if (!strcasecmp (key, "Q")) {
    321             KiiCursorOff (fd);
     321            KiiCursorOff (kapa);
    322322            break;
    323323          }
    324324          if (!strcasecmp (key, "ESCAPE")) {
    325             KiiCursorOff (fd);
     325            KiiCursorOff (kapa);
    326326            goto escape;
    327327          }
  • trunk/Ohana/src/opihi/dvo/images.c

    r12753 r13479  
    1414  int WITH_MOSAIC, SOLO_MOSAIC, HIDDEN;
    1515  time_t tzero, tend;
    16   int N, NPTS, n, npts, Npts;
     16  int N, NPTS, n, npts, Npts, kapa;
    1717  Vector Xvec, Yvec;
    1818  double r[8], d[8], x[8], y[8], Rmin, Rmax, Rmid, trange, Radius;
     
    2222  int typehash;
    2323
    24   if (!style_args (&graphmode, &argc, argv, 0)) return FALSE;
     24  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
    2525
    2626  WITH_MOSAIC = FALSE;
     
    101101    return (FALSE);
    102102  }
    103   SetGraph (graphmode);
    104103 
    105104  /* it is not an error for the database not to have any images */
     
    282281    graphmode.ptype = 100; /* connect pairs of points */
    283282    graphmode.etype = 0;
    284     PrepPlotting (N, &graphmode);
    285     PlotVector (N, Xvec.elements);
    286     PlotVector (N, Yvec.elements);
     283    PlotVectorPair (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
    287284  }
    288285
  • trunk/Ohana/src/opihi/dvo/imbox.c

    r12332 r13479  
    33int imbox (int argc, char **argv) {
    44 
    5   int j, Nskip, status, InPic, flipped;
     5  int j, kapa, Nskip, status, InPic, flipped;
    66  Vector Xvec, Yvec;
    77  double r, d, x[4], y[4], Rmin, Rmax, Rmid;
     
    1212  FILE *f;
    1313
    14   if (!style_args (&graphmode, &argc, argv, 0)) return FALSE;
     14  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
    1515
    1616  if (argc != 2) {
     
    1818    return (FALSE);
    1919  }
    20   SetGraph (graphmode);
    2120
    2221  f = fopen (argv[1], "r");
     
    7776      graphmode.ptype = 100; /* connect pairs of points */
    7877      graphmode.etype = 0;
    79       PrepPlotting (8, &graphmode);
    80       PlotVector (8, Xvec.elements);
    81       PlotVector (8, Yvec.elements);
     78      PlotVectorPair (kapa, 8, Xvec.elements, Yvec.elements, &graphmode);
    8279    }
    8380  skip:
  • trunk/Ohana/src/opihi/dvo/imdense.c

    r7917 r13479  
    55 
    66  long A, B;
    7   int i, N, Nimage, status, NPTS, Ngraph;
     7  int i, kapa, N, Nimage, status, NPTS;
    88  double r, d, x, y, Rmin, Rmax;
    99  Vector Xvec, Yvec;
    1010  Image *image;
    1111  Graphdata graphmode;
     12
     13  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
    1214
    1315  /* need options to list only images in region and only images in a time range */
     
    1719    return (FALSE);
    1820  }
    19   Ngraph = 0;
    20   if (!GetGraph (&graphmode, NULL, &Ngraph)) return (FALSE);
    2121
    2222  if ((image = LoadImages (&Nimage)) == NULL) return (FALSE);
     
    6262    graphmode.style = 2; /* points */
    6363    graphmode.etype = 0;
    64     PrepPlotting (N, &graphmode);
    65     PlotVector (N, Xvec.elements);
    66     PlotVector (N, Yvec.elements);
     64    PlotVectorPair (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
    6765  }
    6866
  • trunk/Ohana/src/opihi/dvo/imextract.c

    r12729 r13479  
    55int imextract (int argc, char **argv) {
    66 
    7   int i, j, Nimage, mode, N, Ngraph, PhotcodeSelect;
     7  int i, j, Nimage, mode, N, PhotcodeSelect;
    88  int TimeSelect, RegionSelect, *subset, Nsubset, TimeFormat, FlagSelect, FlagValue;
    99  double x, y, ra, dec, t, trange;
     
    1515  Vector *vec;
    1616
    17   Ngraph = 0;
    18   if (!GetGraphData (&graphsky, NULL, &Ngraph)) return (FALSE);
     17  if (!GetGraphData (&graphsky, NULL, NULL)) return (FALSE);
    1918  if (!InitPhotcodes ()) return (FALSE);
    2019
  • trunk/Ohana/src/opihi/dvo/imlist.c

    r12332 r13479  
    88  double r, d, trange, t;
    99  char *name;
    10   int Ngraph;
    1110  Image *image;
    1211  Graphdata graphmode;
    1312  PhotCode *PhotcodeValue;
    1413
    15   Ngraph = 0;
    16   if (!GetGraphData (&graphmode, NULL, &Ngraph)) return (FALSE);
     14  if (!GetGraphData (&graphmode, NULL, NULL)) return (FALSE);
    1715
    1816  TimeSelect = FALSE;
  • trunk/Ohana/src/opihi/dvo/imstats.c

    r12332 r13479  
    33int imstats (int argc, char **argv) {
    44 
    5   int i, Nimage, N;
    6   int Mcal, AutoLimits, Ngraph;
     5  int i, kapa, Nimage, N;
     6  int Mcal, AutoLimits;
    77  double r, d;
    88  Image *image;
     
    1010  Graphdata graphmode;
    1111
    12   Ngraph = -1;
    13   if ((N = get_argument (argc, argv, "-n"))) {
    14     remove_argument (N, &argc, argv);
    15     Ngraph = atof (argv[N]);
    16     remove_argument (N, &argc, argv);
    17   }
    18   if (!GetGraph (&graphmode, NULL, &Ngraph)) return (FALSE);
     12  if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
    1913
    2014  Mcal = TRUE;
     
    6054  graphmode.style = 2;
    6155  graphmode.etype = 0;
    62   PrepPlotting (Nimage, &graphmode);
    63   PlotVector (Nimage, Xvec.elements);
    64   PlotVector (Nimage, Yvec.elements);
     56  PlotVectorPair (kapa, Nimage, Xvec.elements, Yvec.elements, &graphmode);
    6557 
    6658  free (Xvec.elements);
  • trunk/Ohana/src/opihi/dvo/lcat.c

    r7917 r13479  
    88  struct stat filestat;
    99  Graphdata graphmode;
    10   int Ngraph;
    1110  SkyTable *sky;
    1211  SkyList *skylist;
    1312
    14   Ngraph = 0;
    15   if (!GetGraphData (&graphmode, NULL, &Ngraph)) return (FALSE);
     13  if (!GetGraphData (&graphmode, NULL, NULL)) return (FALSE);
    1614
    1715  ShowAll = FALSE;
  • trunk/Ohana/src/opihi/dvo/lcurve.c

    r12332 r13479  
    66  double Ra, Dec, Radius, Radius2, r;
    77  float *RA, *DEC;
    8   int Ngraph, Xgraph, TimeFormat;
     8  int kapa, TimeFormat;
    99  int Nstars, found, AutoLimits, ErrorBars, GalMag, AbsPhot, SaveVectors;
    1010  int i, j, m, N, NPTS, *N1;
     
    1919
    2020  if (!InitPhotcodes ()) return (FALSE);
    21 
    22   Ngraph = -1;
    23   if ((N = get_argument (argc, argv, "-n"))) {
    24     remove_argument (N, &argc, argv);
    25     Ngraph = atof (argv[N]);
    26     remove_argument (N, &argc, argv);
    27   }
    28   if (!GetGraph (&graphmode, &Xgraph, &Ngraph)) return (FALSE);
     21  if (!style_args (&graphmode, &argc, argv, &kapa)) return (FALSE);
    2922
    3023  AutoLimits = FALSE;
     
    161154    graphmode.etype = 0; 
    162155
    163   PrepPlotting (N, &graphmode);
    164   PlotVector (N, Xvec.elements);
    165   PlotVector (N, Yvec.elements);
     156  KapaPrepPlot (kapa, N, &graphmode);
     157  KapaPlotVector (kapa, N, Xvec.elements, "x");
     158  KapaPlotVector (kapa, N, Yvec.elements, "y");
    166159  if (ErrorBars) {
    167     PlotVector (N, dYvec.elements);
    168     PlotVector (N, dYvec.elements);
     160    KapaPlotVector (kapa, N, dYvec.elements, "dym");
     161    KapaPlotVector (kapa, N, dYvec.elements, "dyp");
    169162  }
    170163
     
    175168           timeptr[0].tm_year, timeptr[0].tm_mon+1, timeptr[0].tm_mday);
    176169  free (p);
    177   KapaSendLabel (Xgraph, string, 0);
     170  KapaSendLabel (kapa, string, 0);
    178171
    179172  free (RA);
  • trunk/Ohana/src/opihi/dvo/mextract.c

    r12332 r13479  
    33int mextract (int argc, char **argv) {
    44 
    5   int i, j, k, m, N, N1, NPTS;
     5  int i, j, k, m, n, N, N1, Npts, NPTS, last, Nfields, Nreturn, Ncstack, Nstack;
    66  int param, mode, Nsecfilt;
    77  char *RegionName, *RegionList, *p;
    88  double *M1;
     9  char **cstack;
     10  float *values;
    911
    10   PhotCode *code;
    1112  Catalog catalog;
    1213  SkyList *skylist;
    13   Vector *vec;
     14  PhotCode *code;
     15  Vector **vec;
     16
     17  dbField *fields;
     18  dbStack *stack;
    1419
    1520  /* defaults */
     
    2429  if (!InitPhotcodes ()) goto escape;
    2530  Nsecfilt = GetPhotcodeNsecfilt ();
     31 
     32  // init locally static variables (time refs)
     33  dbExtractMeasuresInit();
    2634
    27   /* interpret command-line options */
    28   SetSelectionParam (0);
     35  // remove skyregion options
     36  // XXX this needs to explicitly handle -qregion and -skyregion
    2937  if (!SetRegionSelection (&argc, argv, &RegionName, &RegionList)) goto escape;
    30   if (!SetPhotSelections (&argc, argv, 1)) goto usage;
    3138
    32   /* interpret required command-line arguments: mextract (value) */
    33   if (argc != 2) goto usage;
    34   param = GetMeasureParam (argv[1]);
    35   if (param == MEAS_ZERO) {
    36     if (!GetPhotcodeInfo (argv[1], &code, &mode)) {
    37       GetMeasureParam ("help");
    38       goto escape;
    39     }
    40     param = MEAS_MAG;
    41     for (p = argv[1]; *p != 0; p++) {
    42       if (*p == '.') *p = ':';
    43     }
    44   }
    45   if (!TestPhotSelections (&code, &mode, MEAS_ZERO)) goto escape;
     39  // command-line is of the form: avextract field,field, field [where (field op value)...]
     40
     41  // parse the fields to be extracted and returned
     42  fields = dbCmdlineFields (argc, argv, DVO_TABLE_MEASURE, &last, &Nfields);
     43  if (fields == NULL) return (FALSE);
     44
     45  // parse the remainder of the line as a boolean math expression
     46  cstack = isolate_elements (argc-last, &argv[last], &Ncstack);
     47 
     48  // construct the db Boolean math stack (frees cstack)
     49  stack = dbRPN (Ncstack, cstack, &Nstack);
     50
     51  Nreturn = Nfields;
     52  dbCheckStack (stack, Nstack, DVO_TABLE_MEASURE, &fields, &Nfields);
     53  // XXX handle errors
    4654
    4755  /* load region corresponding to selection above */
    4856  if ((skylist = SelectRegions (RegionName, RegionList)) == NULL) goto escape;
    49   if (!SetImageSelection (param, ((RegionName == NULL) && (RegionList == NULL)))) goto escape;
     57
     58  // XXX is this still needed?
     59  // if (!SetImageSelection (param, ((RegionName == NULL) && (RegionList == NULL)))) goto escape;
    5060
    5161  /* create storage vector */
    52   N = 0;
     62  ALLOCATE (values, float, Nfields);
     63  ALLOCATE (vec, Vector *, Nreturn);
     64  for (i = 0; i < Nreturn; i++) {
     65    if ((vec[i] = SelectVector (fields[i].name, ANYVECTOR, TRUE)) == NULL) goto escape;
     66  }
     67
     68  Npts = 0;
    5369  NPTS = 1;
    54   if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto escape;
    5570
     71  // XXX need to add interrupt test to this loop
    5672  for (i = 0; i < skylist[0].Nregions; i++) {
     73    /* lock, load, unlock catalog */
    5774    catalog.filename = skylist[0].filename[i];
    5875    catalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_SECF;
     
    6986
    7087    for (j = 0; j < catalog.Naverage; j++) {
    71       M1 = NULL;
    7288      m = catalog.average[j].offset;
    73       M1 = ExtractMeasures (code, mode, &catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &N1, param);
    74       for (k = 0; k < N1; k++) {
    75         vec[0].elements[N] = M1[k];
    76         N++;
    77         CHECK_REALLOCATE (vec[0].elements, float, NPTS, N, 2000);
     89      for (k = 0; k < catalog.average[j].Nm; k++, m++) {
     90
     91        // extract the relevant values for this measurement
     92        for (n = 0; n < Nfields; n++) {
     93          values[n] = dbExtractMeasures (&catalog.average[j], &catalog.secfilt[j*Nsecfilt], &catalog.measure[m], &fields[n]);
     94        }
     95       
     96        // test the conditional statement
     97        if (!dbBooleanCond (stack, Nstack, values)) continue;
     98        for (n = 0; n < Nreturn; n++) {
     99          vec[n][0].elements[Npts] = values[n];
     100        }
     101        Npts++;
     102        if (Npts >= NPTS) {
     103          NPTS += 2000;
     104          for (n = 0; n < Nreturn; n++) {
     105            REALLOCATE (vec[n][0].elements, float, NPTS);
     106          }
     107        }
    78108      }
    79       if (M1 != NULL) free (M1);
    80109    }
    81110    dvo_catalog_free (&catalog);
    82111  }
    83   vec[0].Nelements = N;
    84   REALLOCATE (vec[0].elements, float, MAX(1,N));
     112  for (n = 0; n < Nreturn; n++) {
     113    vec[n][0].Nelements = Npts;
     114    REALLOCATE (vec[n][0].elements, float, MAX(1,Npts));
     115  }
     116
     117  // XXX free fields and stack
    85118
    86119  FreeImageSelection ();
  • trunk/Ohana/src/opihi/dvo/paverage.c

    r12332 r13479  
    55 
    66  FILE *f;
    7   int i, j, Narg, Npts, NPTS, status, VERBOSE;
     7  int i, j, kapa, Narg, Npts, NPTS, status, VERBOSE;
    88  int Nsecfilt, Nsec;
    99  double Mz, Mr, mag;
     
    2323  Nsecfilt = GetPhotcodeNsecfilt ();
    2424
    25   if (!style_args (&graphmode, &argc, argv, 0)) return FALSE;
     25  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
    2626
    2727  f = (FILE *) NULL;
     
    8282    return (FALSE);
    8383  }
    84   SetGraph (graphmode);
    8584  graphmode.style = 2; /* set style to points */
    8685  graphmode.size = -1; /* point size determined by Zvec */
     
    141140      }
    142141      if (Npts > NCHUNK) {
    143           PlotVectorTriplet (Npts, Xvec, Yvec, Zvec, &graphmode);
     142          PlotVectorTriplet (kapa, Npts, Xvec, Yvec, Zvec, &graphmode);
    144143          Npts = 0;
    145144      }
     
    147146    dvo_catalog_free (&catalog);
    148147  }
    149   if (Npts > 0) PlotVectorTriplet (Npts, Xvec, Yvec, Zvec, &graphmode);
     148  if (Npts > 0) PlotVectorTriplet (kapa, Npts, Xvec, Yvec, Zvec, &graphmode);
    150149
    151150  free (Xvec);
  • trunk/Ohana/src/opihi/dvo/pcat.c

    r7917 r13479  
    66 
    77  double Radius;
    8   int i, j, N, Nregions, ShowAll, NPTS, Npts, leftside;
     8  int i, j, kapa, N, Nregions, ShowAll, NPTS, Npts, leftside;
    99  RegionFile *regions;
    1010  char filename[128];
     
    1414  double X[4], Y[4], Rmin, Rmax, Rmid;
    1515  char catdir[256];
    16   int Ngraph, VERBOSE;
     16  int VERBOSE;
    1717
    1818  VarConfig ("CATDIR", "%s", catdir);
     
    3333    return (FALSE);
    3434  }
    35   Ngraph = 0;
    36   if (!GetGraph (&graphmode, NULL, &Ngraph)) return (FALSE);
     35  if (!GetGraph (&graphmode, &kapa, NULL)) return (FALSE);
    3736 
    3837  Radius = MAX (fabs(graphmode.xmax), fabs(graphmode.ymax));
     
    8483    graphmode.ptype = 100; /* connect pairs of points */
    8584    graphmode.etype = 0;
    86     PrepPlotting (Npts, &graphmode);
    87     PlotVector (Npts, Xvec.elements);
    88     PlotVector (Npts, Yvec.elements);
     85    PlotVectorPair (kapa, Npts, Xvec.elements, Yvec.elements, &graphmode);
    8986  }
    9087
  • trunk/Ohana/src/opihi/dvo/photometry.c

    r12730 r13479  
    174174}
    175175
     176// XXX moved to dbFields
     177# if (0)
    176178int GetMagMode (char *string) {
    177179
     
    188190  return (mode);
    189191}
     192# endif
    190193
    191194int GetMeasureParam (char *parname) {
  • trunk/Ohana/src/opihi/dvo/pmeasure.c

    r12332 r13479  
    55 
    66  FILE *f;
    7   int i, j, k, m, Narg, Npts, NPTS, status, VERBOSE;
     7  int i, j, k, m, kapa, Narg, Npts, NPTS, status, VERBOSE;
    88  double Mz, Mr, mag;
    99  double Radius, Rmin, Rmax, R, D;
     
    1919
    2020  if (!InitPhotcodes ()) return (FALSE);
    21   if (!style_args (&graphmode, &argc, argv, 0)) return FALSE;
     21  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
    2222
    2323  f = (FILE *) NULL;
     
    7575    return (FALSE);
    7676  }
    77   SetGraph (graphmode);
    7877  graphmode.style = 2; /* set style to points */
    7978  graphmode.size = -1; /* point size determined by Zvec */
     
    144143        }
    145144        if (Npts > NCHUNK) {
    146             PlotVectorTriplet (Npts, Xvec, Yvec, Zvec, &graphmode);
     145            PlotVectorTriplet (kapa, Npts, Xvec, Yvec, Zvec, &graphmode);
    147146            Npts = 0;
    148147        }
     
    151150    dvo_catalog_free (&catalog);
    152151  }
    153   if (Npts > 0) PlotVectorTriplet (Npts, Xvec, Yvec, Zvec, &graphmode);
     152  if (Npts > 0) PlotVectorTriplet (kapa, Npts, Xvec, Yvec, Zvec, &graphmode);
    154153
    155154  free (Xvec);
  • trunk/Ohana/src/opihi/dvo/procks.c

    r7917 r13479  
    1616  FILE *f;
    1717  Vector Xvec, Yvec;
    18   int i, j, N, NROCKS;
     18  int kapa, i, j, N, NROCKS;
    1919  int N0, N1, SpeedClip, Reload;
    2020  unsigned int t0, t1;
     
    2323  Graphdata graphmode;
    2424  char rockcat[256];
    25   int Ngraph;
    2625
    27   Ngraph = 0;
    2826  VarConfig ("ROCK_CATALOG", "%s", rockcat);
    29   if (!GetGraph (&graphmode, NULL, &Ngraph)) return (FALSE);
     27  if (!GetGraph (&graphmode, &kapa, NULL)) return (FALSE);
    3028
    3129  f = (FILE *) NULL;
     
    115113  graphmode.style = 2; /* set style to points */
    116114  graphmode.etype = 0; /* no errorbars */
    117   PrepPlotting (N, &graphmode);
    118  
    119   PlotVector (N, Xvec.elements);
    120   PlotVector (N, Yvec.elements);
     115  PlotVectorPair (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
    121116
    122117  /* now plot vectors between two extrema */
     
    148143  graphmode.ptype = 100; /* connect pairs */
    149144  graphmode.etype = 0; /* no errorbars */
    150   PrepPlotting (N, &graphmode);
    151  
    152   PlotVector (N, Xvec.elements);
    153   PlotVector (N, Yvec.elements);
     145
     146  PlotVectorPair (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
    154147
    155148  free (Xvec.elements);
  • trunk/Ohana/src/opihi/dvo/region_list.c

    r7917 r13479  
    9595
    9696  double Radius;
    97   int Ngraph;
    9897  Graphdata graphsky;
    9998  SkyList *skylist;
     
    121120  }
    122121
    123   Ngraph = 0;
    124   if (!GetGraphData (&graphsky, NULL, &Ngraph)) {
     122  if (!GetGraphData (&graphsky, NULL, NULL)) {
    125123    gprint (GP_ERR, "region display not available\n");
    126124    return (NULL);
  • trunk/Ohana/src/opihi/dvo/scripts/navigate

    r10847 r13479  
    1111  $KEY = "none"
    1212  while ("$KEY" != "q")
    13     cursor -g 1
     13    cursor 1
    1414
    1515    # help list
     
    147147      $ok = $KEY
    148148      echo "type 'd' again at endpoint"
    149       cursor -g 1
     149      cursor 1
    150150      $r1 = $R$KEY
    151151      $d1 = $D$KEY
     
    168168      $ok = $KEY
    169169      echo "type 'z' again at radius"
    170       cursor -g 1
     170      cursor 1
    171171      $r1 = $R$KEY
    172172      $d1 = $D$KEY
     
    400400    if ("$KEY" == "p")
    401401      echo "P - new coords; p - old coords"
    402       cursor -g 1
     402      cursor 1
    403403      exec echo $Rp $Dp $RP $DP >> fix.coords
    404404    end
  • trunk/Ohana/src/opihi/dvo/showtile.c

    r7917 r13479  
    55int showtile (int argc, char **argv) {
    66
    7   int Nd, N, NPTS, Ngraph, status, i, InPic;
     7  int kapa, Nd, N, NPTS, status, i, InPic;
    88  Graphdata graphmode;
    99  Coords coords;
     
    1313
    1414  /* show tile pattern in viewed region */
    15 
    16   Ngraph = 0;
    17   if (!GetGraph (&graphmode, NULL, &Ngraph)) return (FALSE);
     15  if (!GetGraph (&graphmode, &kapa, NULL)) return (FALSE);
    1816
    1917  if (argc != 1) {
     
    8886    graphmode.ptype = 100; /* connect pairs of points */
    8987    graphmode.etype = 0;
    90     PrepPlotting (N, &graphmode);
    91     PlotVector (N, Xvec.elements);
    92     PlotVector (N, Yvec.elements);
     88    PlotVectorPair (kapa, N, Xvec.elements, Yvec.elements, &graphmode);
    9389  }
    9490
  • trunk/Ohana/src/opihi/dvo/simage.c

    r7917 r13479  
    1212  Header header;
    1313  Coords coords;
    14   int i, j, Nstars, nstars, Nbytes, nbytes, Npts, N;
     14  int i, j, kapa, Nstars, nstars, Nbytes, nbytes, Npts, N;
    1515  Graphdata graphmode;
    16   int Ngraph;
    1716
    18   Ngraph = 0;
    19   if (!GetGraph (&graphmode, NULL, &Ngraph)) return (FALSE);
     17  if (!GetGraph (&graphmode, &kapa, NULL)) return (FALSE);
    2018
    2119  zero = 17.0;
     
    156154  graphmode.etype = 0;
    157155  Npts = Xvec.Nelements;
    158   PrepPlotting (Npts, &graphmode);
    159156
    160   PlotVector (Npts, Xvec.elements);
    161   PlotVector (Npts, Yvec.elements);
    162   PlotVector (Npts, Zvec.elements);
     157  PlotVectorTriplet (kapa, Npts, Xvec.elements, Yvec.elements, Zvec.elements, &graphmode);
    163158
    164159  free (Xvec.elements);
  • trunk/Ohana/src/opihi/dvo/skycat.c

    r8328 r13479  
    66 
    77  double Radius;
    8   int i, j, N, Nregions, ShowAll, NPTS, Npts, leftside, Depth, VERBOSE;
     8  int i, j, N, Nregions, kapa, ShowAll, NPTS, Npts, leftside, Depth, VERBOSE;
    99  struct stat filestat;
    1010  Vector Xvec, Yvec;
     
    3232  }
    3333
    34   if (!style_args (&graphmode, &argc, argv, 0)) return FALSE;
     34  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
    3535
    3636  if (argc != 1) {
     
    3838    return (FALSE);
    3939  }
    40   SetGraph (graphmode);
    4140
    4241  Radius = MAX (fabs(graphmode.xmax), fabs(graphmode.ymax));
     
    9796    graphmode.ptype = 100; /* connect pairs of points */
    9897    graphmode.etype = 0;
    99     PrepPlotting (Npts, &graphmode);
    100     PlotVector (Npts, Xvec.elements);
    101     PlotVector (Npts, Yvec.elements);
     98    PlotVectorPair (kapa, Npts, Xvec.elements, Yvec.elements, &graphmode);
    10299  }
    103100
  • trunk/Ohana/src/opihi/include/data.h

    r11007 r13479  
    162162void          SetLimitsRaw          PROTO((float *xvec, float *yvec, int Npts, Graphdata *graphmode));
    163163void          ApplyLimits           PROTO((int Xgraph, Graphdata *graphmode, int apply));
    164 int           style_args            PROTO((Graphdata *graphmode, int *argc, char **argv, int Nforce));
     164int           style_args            PROTO((Graphdata *graphmode, int *argc, char **argv, int *kapa));
    165165
    166166int read_table_vectors (int argc, char **argv, char *extname);
  • trunk/Ohana/src/opihi/include/display.h

    r12332 r13479  
    55# define DISPLAY_H
    66
    7 # if (0)
    8 typedef struct {
    9   double xmin, xmax, ymin, ymax;
    10   int style, ptype, ltype, etype, ebar, color;
    11   double lweight, size;
    12   Coords coords;
    13   int flipeast, flipnorth;
    14   char axis[8], labels[8], ticks[8];
    15 } Graphdata;
    16 # endif
     7/*** kapa graph functions ***/
     8int           PlotVectorPair        PROTO((int kapa, int Npts, float *xValues, float *yValues, Graphdata *graphmode));
     9int           PlotVectorTriplet     PROTO((int kapa, int Npts, float *xValues, float *yValues, float *zValues, Graphdata *graphmode));
     10int           GetGraphData          PROTO((Graphdata *data, int *kapa, char *name));
     11int           GetGraph              PROTO((Graphdata *data, int *kapa, char *name));
     12int           SetGraph              PROTO((Graphdata *data));
    1713
    18 /*** plotting functions ***/
    19 int           GetCurrentDevice      PROTO((void));
    20 int           PrepPlotting          PROTO((int Npts, Graphdata *graphmode));
    21 int           PlotVector            PROTO((int, float *));
    22 int           PlotVectorTriplet     PROTO((int N, float *xValues, float *yValues, float *zValues, Graphdata *graphmode));
    23 int           GetGraphData          PROTO((Graphdata *data, int *sock, int *N));
    24 int           GetGraph              PROTO((Graphdata *data, int *socket, int *N));
    25 void          InitGraph             PROTO((void));
    26 int           open_graph            PROTO((int N));
    27 int           close_graph           PROTO((int N));
    28 void          QuitGraph             PROTO((void));
    29 void          SetGraph              PROTO((Graphdata data));
    30 void          XGraphDead            PROTO((int input));
    31 int           GetColor              PROTO((char *name));
     14/*** kapa image functions */
     15int           GetImageData          PROTO((KapaImageData *data, int *kapa, char *name));
     16int           GetImage              PROTO((KapaImageData *data, int *kapa, char *name));
     17int           SetImage              PROTO((KapaImageData *data));
    3218
    33 /* image (tv) functions */
    34 int           GetImage              PROTO((int *socket, int *N));
    35 char         *GetImageName          PROTO((void));
    36 void          GetImageScale         PROTO((double *zero, double *range));
    37 void          InitImage             PROTO((void));
    38 int           open_image            PROTO((int N));
    39 int           close_image           PROTO((int N));
    40 void          QuitImage             PROTO((void));
    41 void          SetImageDevice        PROTO((int state));
    42 void          SetImageName          PROTO((char *name));
    43 void          SetImageScale         PROTO((double zero, double range));
    44 void          XImageDead            PROTO((int input));
    45 int           SelectOverlay         PROTO((char *name, int *number));
     19void          QuitKapa              PROTO(());
     20void          InitKapa              PROTO(());
     21int           open_kapa             PROTO((int entry));
     22int           close_kapa            PROTO((char *name));
     23int           AddKapaDevice         PROTO((char *name));
     24int           DelKapaDevice         PROTO((char *name));
     25int           FindKapaDevice        PROTO((char *name));
     26char         *GetKapaName           PROTO(());
    4627
    4728/* calling program need to define a function 'get_variable' which
  • trunk/Ohana/src/opihi/include/dvoshell.h

    r7960 r13479  
    77
    88/* magnitude types */
    9 enum {MAG_NONE, MAG_INST, MAG_CAT, MAG_SYS, MAG_REL, MAG_CAL, MAG_AVE, MAG_REF};
     9enum {MAG_NONE, MAG_INST, MAG_CAT, MAG_SYS, MAG_REL, MAG_CAL, MAG_AVE, MAG_REF, MAG_ERR, MAG_CHISQ};
    1010
    11 /* measure params */
     11/* measure fields */
    1212enum {MEAS_ZERO, MEAS_RA, MEAS_DEC, MEAS_MAG, MEAS_dMAG, MEAS_MINST, MEAS_MCAT,
    1313      MEAS_MSYS, MEAS_MREL, MEAS_MCAL, MEAS_PHOTCODE, MEAS_TIME, MEAS_dR, MEAS_dD,
    1414      MEAS_FWHM, MEAS_DOPHOT, MEAS_XCCD, MEAS_YCCD, MEAS_XMOSAIC, MEAS_YMOSAIC, MEAS_FLAGS, MEAS_EXPTIME, MEAS_AIRMASS};
    1515
    16 /* average params */
     16/* average fields */
    1717enum {AVE_ZERO, AVE_RA, AVE_DEC, AVE_RA_ERR, AVE_DEC_ERR, AVE_U_RA, AVE_U_DEC,
    1818      AVE_U_RA_ERR, AVE_U_DEC_ERR, AVE_PAR, AVE_PAR_ERR, AVE_MAG, AVE_REF, AVE_dMAG,
    1919      AVE_Xm, AVE_Xp, AVE_NMEAS, AVE_NMISS, AVE_TYPE, AVE_NPHOT, AVE_NCODE, AVE_NCRIT,
    2020      AVE_FLAG, AVE_TYPEFRAC};
     21
     22enum {DVO_TABLE_AVERAGE, DVO_TABLE_MEASURE};
     23
     24// a single db field
     25typedef struct {
     26  char *name;
     27  int extract;
     28  int table;
     29  int ID;
     30  int magMode;
     31  PhotCode *photcode;
     32} dbField;
     33
     34// db boolean operations
     35typedef struct {
     36  char   *name;
     37  char    type;
     38  int     field;
     39  float   Float;
     40} dbStack;
    2141
    2242typedef struct {
     
    96116int           RD_to_XYpic           PROTO((double *x, double *y, double r, double d, Coords *coords, double Rmin, double Rmax, double Rmid, int *leftside));
    97117
     118// dvo DB field functions
     119dbField     *dbCmdlineFields        PROTO((int argc, char **argv, int table, int *last, int *nfields));
     120dbStack     *dbRPN                  PROTO((int argc, char **argv, int *nstack));
     121int          dbCheckStack           PROTO((dbStack *stack, int Nstack, int table, dbField **inFields, int *Nfields));
     122int          dbBooleanCond          PROTO((dbStack *inStack, int NinStack, float *fields));
     123void         dbInitStack            PROTO((dbStack *stack));
     124void         dbFreeStack            PROTO((dbStack *stack, int Nstack));
     125void         dbFreeEntry            PROTO((dbStack *stack));
     126
     127dbStack     *dbBinary               PROTO((dbStack *V1, dbStack *V2, char *op, float *fields));
     128dbStack     *dbUnary                PROTO((dbStack *V1, char *op, float *fields));
     129
     130int          GetMagMode             PROTO((char *string));
     131PhotCode    *ParsePhotcodeField     PROTO((char *field, int *mode, int def));
     132int          ParseMeasureField      PROTO((dbField *field, char *fieldName));
     133int          ParseAverageField      PROTO((dbField *field, char *fieldName));
     134
     135double       dbExtractAverages      PROTO((Average *average, SecFilt *secfilt, Measure *measure, dbField *field));
     136double       dbExtractMeasures      PROTO((Average *average, SecFilt *secfilt, Measure *measure, dbField *field));
     137void         dbExtractMeasuresInit  PROTO(());
     138
    98139# endif
  • trunk/Ohana/src/opihi/lib.data/Makefile

    r12879 r13479  
    2929$(SDIR)/gaussian.$(ARCH).o              \
    3030$(SDIR)/graphtools.$(ARCH).o            \
    31 $(SDIR)/open_graph.$(ARCH).o            \
    32 $(SDIR)/open_image.$(ARCH).o            \
    3331$(SDIR)/queues.$(ARCH).o                \
    3432$(SDIR)/PlotVectors.$(ARCH).o           \
     33$(SDIR)/open_kapa.$(ARCH).o             \
    3534$(SDIR)/style_args.$(ARCH).o
     35
     36#$(SDIR)/open_graph.$(ARCH).o            \
     37#$(SDIR)/open_image.$(ARCH).o            \
    3638
    3739# dependancy rules for include files ########################
  • trunk/Ohana/src/opihi/lib.data/PlotVectors.c

    r10795 r13479  
    11# include "display.h"
    22
    3 static int Xgraph;
     3int PlotVectorPair (int kapa, int Npts, float *xValues, float *yValues, Graphdata *graphmode) {
    44
    5 int PrepPlotting (int Npts, Graphdata *graphmode) {
     5  KapaPrepPlot (kapa, Npts, graphmode);
     6  KapaPlotVector (kapa, Npts, xValues, "x");
     7  KapaPlotVector (kapa, Npts, yValues, "y");
    68
    7   if (!GetGraph (NULL, &Xgraph, NULL)) return (FALSE);
    8  
    9   /* tell kapa to look for the incoming image */
    10   KiiSendCommand (Xgraph, 4, "PLOT");
    11  
    12   /* send Xgraph the plot details */
    13   KiiSendMessage (Xgraph, "%8d %8d %d %d %d %d %d %f %f",
    14                   Npts, graphmode[0].style,
    15                   graphmode[0].ptype, graphmode[0].ltype,
    16                   graphmode[0].etype, graphmode[0].ebar, graphmode[0].color,
    17                   graphmode[0].lweight, graphmode[0].size);
    18   KiiSendMessage (Xgraph, "%g %g %g %g",
    19                   graphmode[0].xmin, graphmode[0].xmax,
    20                   graphmode[0].ymin, graphmode[0].ymax);
    219  return (TRUE);
    2210}
    2311
    24 int PlotVector (int Npts, float *values) {
     12int PlotVectorTriplet (int kapa, int Npts, float *xValues, float *yValues, float *zValues, Graphdata *graphmode) {
    2513
    26   int Nbytes;
     14  KapaPrepPlot   (kapa, Npts, graphmode);
     15  KapaPlotVector (kapa, Npts, xValues, "x");
     16  KapaPlotVector (kapa, Npts, yValues, "y");
     17  KapaPlotVector (kapa, Npts, zValues, "z");
    2718
    28   Nbytes = Npts * sizeof (float);
    29   write (Xgraph, values, Nbytes);
    3019  return (TRUE);
    3120}
    32 
    33 int PlotVectorPair (int N, float *xValues, float *yValues, Graphdata *graphmode) {
    34 
    35     PrepPlotting (N, graphmode);
    36     PlotVector (N, xValues);
    37     PlotVector (N, yValues);
    38 
    39     return (TRUE);
    40 }
    41 
    42 int PlotVectorTriplet (int N, float *xValues, float *yValues, float *zValues, Graphdata *graphmode) {
    43 
    44     PrepPlotting (N, graphmode);
    45     PlotVector (N, xValues);
    46     PlotVector (N, yValues);
    47     PlotVector (N, zValues);
    48 
    49     return (TRUE);
    50 }
    51 
    52 /* we don't use GetGraph in PlotVector because it flushes the connection */
  • trunk/Ohana/src/opihi/lib.data/graphtools.c

    r7680 r13479  
    3333    graphmode[0].ymax = maxY + 0.05*range;
    3434  }
    35   SetGraph (graphmode[0]);
     35  SetGraph (graphmode);
    3636
    3737  set_variable ("XMIN", graphmode[0].xmin);
     
    7373    graphmode[0].ymax = maxY + 0.05*range;
    7474  }
    75   SetGraph (graphmode[0]);
     75  SetGraph (graphmode);
    7676
    7777  set_variable ("XMIN", graphmode[0].xmin);
  • trunk/Ohana/src/opihi/lib.data/open_image.c

    r7938 r13479  
    122122  return (Ximbuffer[Active]);
    123123}
    124  
     124 
     125// leave this information on kapa, request when needed?
    125126void SetImageScale (double zero, double range) {
    126127  Xzero[Active] = zero;
  • trunk/Ohana/src/opihi/lib.data/open_kapa.c

    r13344 r13479  
    11# include "display.h"
    22# include "shell.h"
     3# include <assert.h>
     4
    35
    46/* kapa support for the new version of kapa (v2.0), which has both graph and image
     
    911
    1012/* list of available socket connections */
    11 static int        Active;        // currently active socket (not device)
     13static int        Active;        // currently active socket entry (index value, not socket value)
    1214static int       *Socket = NULL; // list of available sockets
    13 static int       *Device = NULL; // list of device numbers for each socked
    14 static int       Nsocket = 0;    // number of available sockets / devices
     15static char     **Device = NULL; // list of device names for each socket
     16static int       Ndevice = 0;    // number of available sockets / devices
    1517
    1618void InitKapa () {
    1719
    18   Active  = -1;               // -1 is the INVALID entry
    19   Nsocket = 0;                // number of defined sockets
    20   ALLOCATE (Device, int, 1);
    21   ALLOCATE (Socket, int, 1);
    22   Device[Active] = 0; 
    23   Socket[Active] = 0; 
    24 }
    25 
    26 // returns the number of the requested device, or -1 if not found
    27 int FindKapaDevice (int thisDevice) {
     20  Active  = -1;                                   // -1 is the INVALID entry
     21  Ndevice = 0;                                    // number of defined sockets
     22  ALLOCATE (Device, char *, 1);                   // for future REALLOCATE calls
     23  ALLOCATE (Socket, int, 1);                      // for future REALLOCATE calls
     24}
     25
     26// add new device name if not found
     27int AddKapaDevice (char *name) {
     28
     29  int N;
     30
     31  N = FindKapaDevice (name);
     32  if (N != -1) return (N);
     33  N = Ndevice;
     34  Ndevice ++;
     35  REALLOCATE (Device, char *, Ndevice);
     36  REALLOCATE (Socket, int, Ndevice);
     37  Device[N] = strcreate (name);
     38  Socket[N] = -1;
     39  return (N);
     40}
     41
     42// delete device by name, close if not closed
     43int DelKapaDevice (char *name) {
     44
     45  int i, N;
     46
     47  N = FindKapaDevice (name);
     48  if (N == -1) return (FALSE);
     49
     50  if (Socket[N] != -1) close (Socket[N]);
     51  free (Device[N]);
     52  for (i = N; i < Ndevice - 1; i++) {
     53    Device[i] = Device[i+1];
     54    Socket[i] = Socket[i+1];
     55  }
     56
     57  if (N == Active) {
     58    Active = -1;
     59  }
     60
     61  Ndevice --;
     62  REALLOCATE (Device, char *, Ndevice);
     63  REALLOCATE (Socket, int, Ndevice);
     64
     65  return (TRUE);
     66}
     67
     68// returns the entry of the requested device, or -1 if not found
     69int FindKapaDevice (char *name) {
    2870
    2971  int i;
    3072
    31   for (i = 0; i < Nsocket; i++) {
    32     if (Device[i] == thisDevice) {
    33       return (i);
    34     }
     73  if (name == NULL) return (-1);
     74
     75  for (i = 0; i < Ndevice; i++) {
     76    if (!strcmp(Device[i], name)) return (i);
    3577  }
    3678  return (-1);
    3779}
    3880
    39 // set the active device to the given device number, open if needed
    40 int open_kapa (int thisDevice) {
    41 
    42   int fd, entry;
    43   char *kapa_exec, name[16];
     81// set the active device to the given device, open if needed
     82int open_kapa (int entry) {
     83
     84  int fd;
     85  char *kapa_exec, *kapa_name;
    4486
    4587  // find the given device number, or create. set this to active
    46   entry = FindKapaDevice (thisDevice);
    47   if (entry < 0) {
    48     Active = Nsocket;
    49     Nsocket ++;
    50     REALLOCATE (Device, int, Nsocket);
    51     REALLOCATE (Socket, int, Nsocket);
    52     Device[Active] = -1;
    53     Socket[Active] = -1;
    54   } else {
    55     Active = entry;
    56   }
     88  assert (entry >= 0);
     89  assert (entry <  Ndevice);
    5790
    5891  // if the (now) active socket is not open, open it
    59   if (Socket[Active] < 0) {
     92  if (Socket[entry] < 0) {
    6093    kapa_exec = get_variable ("KAPA");
    6194    if (kapa_exec == (char *) NULL) {
     
    6598
    6699    // KAPA may be either kapa://host or /path/to/program
    67 
    68     snprintf (name, 16, "[%d]", thisDevice);
    69     fd = KapaOpen (kapa_exec, name);
     100    ALLOCATE (kapa_name, char, strlen(Device[entry]) + 5);
     101    snprintf (kapa_name, strlen(Device[entry]) + 5, "[%s]", Device[entry]);
     102    fd = KapaOpen (kapa_exec, kapa_name);
    70103    free (kapa_exec);
     104    free (kapa_name);
    71105
    72106    if (fd < 0) {
    73       gprint (GP_ERR, "error starting kapa\n");
    74       // delete the active entry
     107      gprint (GP_ERR, "error starting kapa device %s\n", Device[entry]);
    75108      return (FALSE);
    76109    }
    77     Device[Active] = thisDevice;
    78     Socket[Active] = fd;
     110    Socket[entry] = fd;
    79111  }
    80   return (TRUE);
    81 }
    82 
    83 /**************** graph ops */
    84 
    85 // XXX for now, use a local variable.  later: get from kapa
    86 static Graphdata graphdata;
    87 
    88 void InitGraph () {
    89   graphdata.xmin = graphdata.ymin = 0.0;
    90   graphdata.xmax = graphdata.ymax = 1.0;
    91   graphdata.style = graphdata.ptype = 0;
    92   graphdata.ltype = graphdata.color = 0;
    93   graphdata.etype = graphdata.ebar = 0;
    94   graphdata.lweight = graphdata.size = 1.0;
    95    
    96   graphdata.coords.pc1_1 = graphdata.coords.pc2_2 = 1.0;
    97   graphdata.coords.pc1_2 = graphdata.coords.pc2_1 = 0.0;
    98   strcpy (graphdata.coords.ctype, "RA---LIN");
    99   graphdata.coords.crval1 = 0.0;
    100   graphdata.coords.crval2 = 0.0;
    101   graphdata.coords.crpix1 = 0.0;
    102   graphdata.coords.crpix2 = 0.0;
    103   graphdata.coords.cdelt1 = graphdata.coords.cdelt2 = 1.0;
    104   graphdata.flipeast = TRUE;
    105   graphdata.flipnorth = FALSE;
    106   strcpy (graphdata.axis, "2222");
    107   strcpy (graphdata.ticks, "2222");
    108   strcpy (graphdata.labels, "2222");
    109 }
    110 
    111 # if (0)
    112   /* test Xgraph[0], flush junk from pipe */
    113   signal (SIGPIPE, XGraphDead);
    114   fcntl (Socket[n], F_SETFL,  O_NONBLOCK);
    115   for (i = 0; (read (Socket[n], buffer, 64) > 0) && (i < 20); i++);
    116   fcntl (Socket[n], F_SETFL, !O_NONBLOCK);
    117 # endif
    118 
    119 /* return pointers for current Xgraph, set if desired, test, open if needed */
    120 int GetGraph (Graphdata *data, int *fd, int *dev) {
    121 
    122   int thisDevice;
    123 
    124   SetImageDevice (FALSE);
    125   if (dev == NULL) {
    126     if (Active < 0) {
    127       thisDevice = 0;
     112  Active = entry;
     113  return (TRUE);
     114}
     115
     116/**************** graph specific ops *******************/
     117
     118// return the current device name, if set
     119char *GetKapaName () {
     120  if (Active < 0) return NULL;
     121  return Device[Active];
     122}
     123
     124/* return pointers for named device or current; open if needed */
     125// if fd == NULL, don't return the value
     126// if name == NULL, use the currently active device
     127int GetGraph (Graphdata *data, int *fd, char *name) {
     128
     129  int entry;
     130
     131  if (name == NULL) {
     132    if (Active < 0) {
     133      entry = AddKapaDevice ("0");
    128134    } else {
    129       thisDevice = Device[Active];
    130     }
    131   } else {
    132     thisDevice = *dev;
    133   }
    134  
    135   if (!open_kapa (thisDevice)) {
    136     return (FALSE);
    137   }
    138  
    139   if (data != NULL) *data = graphdata;
     135      entry = Active;
     136    }
     137  } else {
     138    entry = AddKapaDevice (name);
     139  }
     140 
     141  if (!open_kapa (entry)) {
     142    return (FALSE);
     143  }
     144 
     145  if (data != NULL) KapaGetGraphData (Socket[Active], data);
    140146  if (fd != NULL) *fd = Socket[Active];
    141147
     
    143149}
    144150
    145 /* return pointers for given Xgraph, don't set or open */
    146 int GetGraphData (Graphdata *data, int *fd, int *dev) {
    147 
    148   int n;
    149 
    150   if (dev == NULL) {
    151     if (Active < 0) {
    152       gprint (GP_ERR, "invalid Xgraph window %d\n", *dev);
    153       return (FALSE);
    154     }
    155     *fd = Socket[Active];
    156     return (TRUE);
    157   }
    158 
    159   n = FindKapaDevice (*dev);
    160   if (n < 0) {
    161     gprint (GP_ERR, "invalid Xgraph window %d\n", *dev);
    162     return (FALSE);
    163   }
    164 
    165   Active = n;
    166 
     151/* return pointers for given kapa, don't set or open */
     152int GetGraphData (Graphdata *data, int *fd, char *name) {
     153
     154  int entry;
     155
     156  if (name == NULL) {
     157    if (Active < 0) {
     158      gprint (GP_ERR, "no active kapa window\n");
     159      return (FALSE);
     160    }
     161    entry = Active;
     162  } else {
     163    entry = FindKapaDevice (name);
     164    if (entry < 0) {
     165      gprint (GP_ERR, "invalid kapa window %s\n", name);
     166      return (FALSE);
     167    }
     168  }
     169
     170  if (fd != NULL) *fd = Socket[entry];
     171  if (data != NULL) KapaGetGraphData (Socket[entry], data);
     172  return (TRUE);
     173}
     174
     175/* assign given values to current kapa */
     176int SetGraph (Graphdata *data) {
     177  if (Active < 0) {
     178    gprint (GP_ERR, "no active kapa window\n");
     179    return (FALSE);
     180  }
     181  if (Socket[Active] == -1) {
     182    gprint (GP_ERR, "no active kapa window\n");
     183    return (FALSE);
     184  }
     185  KapaSetGraphData (Socket[Active], data);
     186}
     187
     188/************* image ops ***********/
     189
     190/* return pointers for current Ximage, set if desired, test, open if needed */
     191int GetImage (KapaImageData *data, int *fd, char *name) {
     192
     193  int entry;
     194
     195  if (name == NULL) {
     196    if (Active < 0) {
     197      entry = AddKapaDevice ("0");
     198    } else {
     199      entry = Active;
     200    }
     201  } else {
     202    entry = AddKapaDevice (name);
     203  }
     204 
     205  if (!open_kapa (entry)) {
     206    return (FALSE);
     207  }
     208 
     209  if (data != NULL) KapaGetImageData (Socket[Active], data);
    167210  if (fd != NULL) *fd = Socket[Active];
    168   if (data != NULL) *data = graphdata;
    169 
    170   return (TRUE);
    171 }
    172 
    173 /* assign given values to current Xgraph */
    174 void SetGraph (Graphdata data) {
    175   graphdata = data;
    176 }
    177 
    178 /** internal tracking of current active device type **/
    179 /* drop this stuff */
    180 static int       IsImage = FALSE;
    181 
    182 int GetCurrentDevice () {
    183   return (IsImage);
    184 }
    185 
    186 void SetImageDevice (int state) {
    187   IsImage = state;
    188 }
    189 
    190 /************* image ops ***********/
    191 // XXX for now, use local static:
    192 
    193 static char      Ximbuffer[512];
    194 static double    Xzero;
    195 static double    Xrange;
    196 
    197 void InitImage () {
    198   Xzero = 0;
    199   Xrange = 1024;
    200   strcpy (Ximbuffer, "none");
    201 }
    202 
    203 /* return pointers for current Ximage, set if desired, test, open if needed */
    204 int GetImage (int *fd, int *N) {
    205   int status;
    206   status = GetGraph (NULL, fd, N);
    207   return (status);
    208 }
    209 
    210 void SetImageName (char *name) {
    211   strcpy (Ximbuffer, name);
    212 }
    213 
    214 char *GetImageName () {
    215   return (Ximbuffer);
    216 }
    217  
    218 // leave this information on kapa, request when needed?
    219 void SetImageScale (double zero, double range) {
    220   Xzero = zero;
    221   Xrange = range;
    222 }
    223 void GetImageScale (double *zero, double *range) {
    224   *zero = Xzero;
    225   *range = Xrange;
    226 }
     211
     212  return (TRUE);
     213}
     214
     215/* return pointers for given kapa, don't set or open */
     216int GetImageData (KapaImageData *data, int *fd, char *name) {
     217
     218  int entry;
     219
     220  if (name == NULL) {
     221    if (Active < 0) {
     222      gprint (GP_ERR, "no active kapa window\n");
     223      return (FALSE);
     224    }
     225    entry = Active;
     226  } else {
     227    entry = FindKapaDevice (name);
     228    if (entry < 0) {
     229      gprint (GP_ERR, "invalid kapa window %s\n", name);
     230      return (FALSE);
     231    }
     232  }
     233
     234  if (fd != NULL) *fd = Socket[entry];
     235  if (data != NULL) KapaGetImageData (Socket[entry], data);
     236  return (TRUE);
     237}
     238
     239/* assign given values to current kapa */
     240int SetImage (KapaImageData *data) {
     241  if (Active < 0) {
     242    gprint (GP_ERR, "no active kapa window\n");
     243    return (FALSE);
     244  }
     245  if (Socket[Active] == -1) {
     246    gprint (GP_ERR, "no active kapa window\n");
     247    return (FALSE);
     248  }
     249  KapaSetImageData (Socket[Active], data);
     250}
     251
     252int close_kapa (char *name) {
     253
     254  int N;
     255
     256  N = FindKapaDevice (name);
     257  if (N == -1) {
     258    if (Active < 0) return (FALSE);
     259    name = Device[Active];
     260  }
     261  DelKapaDevice (name);
     262  return (TRUE);
     263}
     264
     265void QuitKapa () {
     266
     267  int i;
     268 
     269  for (i = 0; i < Ndevice; i++) {
     270    if (Socket[i] != -1) close (Socket[i]);
     271    if (Device[i] != NULL) free (Device[i]);
     272  }
     273  REALLOCATE (Socket, int, 1);
     274  REALLOCATE (Device, char *, 1);
     275
     276  Ndevice = 0;
     277  Active = -1;
     278}
  • trunk/Ohana/src/opihi/lib.data/style_args.c

    r7917 r13479  
    22# include "display.h"
    33
    4 int style_args (Graphdata *graphmode, int *argc, char **argv, int Nforce) {
     4int style_args (Graphdata *graphmode, int *argc, char **argv, int *kapa) {
    55 
    6   int N, Ngraph;
    7   char *name;
     6  int N;
     7  char *colorName;
     8  char *kapaName;
    89
    9   Ngraph = -1;
     10  kapaName = NULL;
    1011  if ((N = get_argument (*argc, argv, "-n"))) {
    1112    remove_argument (N, argc, argv);
    12     Ngraph = atof (argv[N]);
     13    kapaName = strcreate (argv[N]);
    1314    remove_argument (N, argc, argv);
    1415  }
    15   if (Nforce != -1) Ngraph = Nforce;
    16   if (!GetGraph (graphmode, NULL, &Ngraph)) return (FALSE);
     16  if (!GetGraph (graphmode, kapa, kapaName)) return (FALSE);
     17  FREE (kapaName);
    1718
    1819  if (*argc == 1) {
    19     name = KapaColorName (graphmode[0].color);
    20     gprint (GP_ERR, "current style (%d): -x %d -c %s -pt %d -lt %d -lw %f -sz %f\n", Ngraph,
    21              graphmode[0].style, name, graphmode[0].ptype,
     20    kapaName = GetKapaName();
     21    colorName = KapaColorName (graphmode[0].color);
     22    gprint (GP_ERR, "current style (%s): -x %d -c %s -pt %d -lt %d -lw %f -sz %f\n", kapaName,
     23             graphmode[0].style, colorName, graphmode[0].ptype,
    2224             graphmode[0].ltype, graphmode[0].lweight,
    2325             graphmode[0].size);
  • trunk/Ohana/src/opihi/lib.shell/BufferOps.c

    r9275 r13479  
    195195}
    196196
    197 int SelectOverlay (char *name, int *number) {
    198 
    199   *number = -1;
    200   if (!strcmp (name, "red") || !strcmp (name, "0"))
    201     *number = 0;
    202   if (!strcmp (name, "green") || !strcmp (name, "1"))
    203     *number = 1;
    204   if (!strcmp (name, "blue") || !strcmp (name, "2"))
    205     *number = 2;
    206   if (!strcmp (name, "yellow") || !strcmp (name, "3"))
    207     *number = 3;
    208 
    209   if (*number < 0) {
    210     gprint (GP_ERR, "valid overlays may be: red (0), green (1), blue (2), yellow (3)\n");
    211     return (FALSE);
    212   }
    213   else {
    214     return (TRUE);
    215   }
    216 }
    217 
    218197void dump_buffers (int n) {
    219198
  • trunk/Ohana/src/opihi/lib.shell/startup.c

    r12902 r13479  
    4343    else
    4444      set_str_variable ("HOME", home);
    45     set_str_variable ("KII", "kii");
    4645    set_str_variable ("KAPA", "kapa");
    4746    set_variable ("PID", getpid());
  • trunk/Ohana/src/opihi/mana/mana.c.in

    r12280 r13479  
    5151/* add program-dependent exit functions here */
    5252void cleanup () {
    53   QuitImage ();
    54   QuitGraph ();
     53  QuitKapa ();
    5554  return;
    5655}
  • trunk/Ohana/src/opihi/mana/opihi.c

    r10647 r13479  
    6464/* add program-dependent exit functions here */
    6565void cleanup () {
    66   /* -libdisplay
    67   QuitImage ();
    68   QuitGraph (); */
     66  QuitKapa ();
    6967  return;
    7068}
  • trunk/Ohana/src/opihi/pantasks/pantasks.c.in

    r12280 r13479  
    6464/* add program-dependent exit functions here */
    6565void cleanup () {
    66   QuitImage ();
    67   QuitGraph ();
     66  QuitKapa ();
    6867  QuitController ();
    6968  return;
  • trunk/Ohana/src/opihi/pantasks/pantasks_client.c.in

    r12280 r13479  
    5454/* add program-dependent exit functions here */
    5555void cleanup () {
    56   QuitImage ();
    57   QuitGraph ();
     56  QuitKapa ();
    5857  return;
    5958}
  • trunk/Ohana/src/opihi/pantasks/pantasks_server.c

    r11890 r13479  
    7474/* add program-dependent exit functions here */
    7575void cleanup () {
    76   // QuitImage ();
    77   // QuitGraph ();
    78   // QuitController ();
     76  QuitKapa ();
     77  QuitController ();
    7978  return;
    8079}
  • trunk/Ohana/src/relastro/src/plotstuff.c

    r12892 r13479  
    2121int open_graph (int N) {
    2222
    23   Xgraph[N] = KiiOpen ("kapa", NULL);
     23  char name[100];
     24
     25  sprintf (name, "gastro [%d]", N);
     26  Xgraph[N] = KapaOpen ("kapa", name);
     27
    2428  if (Xgraph[N] < 0) {
    2529    fprintf (stderr, "error starting kapa\n");
     
    5963  if (Xgraph[N] < 1) if (!open_graph(N)) return;
    6064
    61   KapaClear (Xgraph[N], TRUE);
     65  KapaClearSections (Xgraph[N]);
    6266
    63   KiiSendCommand (Xgraph[N], 4, "PLOT");
    64  
    65   /* send Xgraph the plot details */
    66   KiiSendMessage (Xgraph[N], "%8d %8d %d %d %d %d %d %f %f",
    67                   Npts, graphmode[0].style,
    68                   graphmode[0].ptype, graphmode[0].ltype,
    69                   graphmode[0].etype, graphmode[0].ebar, graphmode[0].color,
    70                   graphmode[0].lweight, graphmode[0].size);
    71   KiiSendMessage (Xgraph[N], "%g %g %g %g",
    72                   graphmode[0].xmin, graphmode[0].xmax,
    73                   graphmode[0].ymin, graphmode[0].ymax);
    74 
     67  KapaPrepPlot (Xgraph[N], Npts, graphmode);
    7568  return;
    7669}
     
    8376}
    8477
    85 void PlotVector (int Npts, double *vect, int mode, int N) {
     78void PlotVector (int Npts, double *vect, int mode, int N, char *type) {
    8679
    8780  float *values;
     
    9588  }
    9689
    97   Nbytes = Npts * sizeof (float);
    98   write (Xgraph[N], values, Nbytes);
     90  KapaPlotVector (Xgraph[N], Npts, values, type);
    9991  free (values);
    10092  return;
     
    123115
    124116  PrepPlotting (N, graphdata, 0);
    125   PlotVector (N, xlist, 0, 0);
    126   PlotVector (N, ylist, 1, 0);
     117  PlotVector (N, xlist, 0, 0, "x");
     118  PlotVector (N, ylist, 1, 0, "y");
    127119  if (label != NULL) PlotLabel (label, 0);
    128120  DonePlotting (graphdata, 0);
  • trunk/Ohana/src/relphot/src/plotstuff.c

    r12892 r13479  
    2121int open_graph (int N) {
    2222
    23   Xgraph[N] = KiiOpen ("kapa", NULL);
     23  char name[100];
     24
     25  sprintf (name, "gastro [%d]", N);
     26  Xgraph[N] = KapaOpen ("kapa", name);
     27
    2428  if (Xgraph[N] < 0) {
    2529    fprintf (stderr, "error starting kapa\n");
     
    5963  if (Xgraph[N] < 1) if (!open_graph(N)) return;
    6064
    61   KapaClear (Xgraph[N], TRUE);
     65  KapaClearSections (Xgraph[N]);
    6266
    63   KiiSendCommand (Xgraph[N], 4, "PLOT");
    64  
    65   /* send Xgraph the plot details */
    66   KiiSendMessage (Xgraph[N], "%8d %8d %d %d %d %d %d %f %f",
    67                   Npts, graphmode[0].style,
    68                   graphmode[0].ptype, graphmode[0].ltype,
    69                   graphmode[0].etype, graphmode[0].ebar, graphmode[0].color,
    70                   graphmode[0].lweight, graphmode[0].size);
    71   KiiSendMessage (Xgraph[N], "%g %g %g %g",
    72                   graphmode[0].xmin, graphmode[0].xmax,
    73                   graphmode[0].ymin, graphmode[0].ymax);
    74 
     67  KapaPrepPlot (Xgraph[N], Npts, graphmode);
    7568  return;
    7669}
     
    8376}
    8477
    85 void PlotVector (int Npts, double *vect, int mode, int N) {
     78void PlotVector (int Npts, double *vect, int mode, int N, char *type) {
    8679
    8780  float *values;
     
    9588  }
    9689
    97   Nbytes = Npts * sizeof (float);
    98   write (Xgraph[N], values, Nbytes);
     90  KapaPlotVector (Xgraph[N], Npts, values, type);
    9991  free (values);
    10092  return;
     
    123115
    124116  PrepPlotting (N, graphdata, 0);
    125   PlotVector (N, xlist, 0, 0);
    126   PlotVector (N, ylist, 1, 0);
     117  PlotVector (N, xlist, 0, 0, "x");
     118  PlotVector (N, ylist, 1, 0, "y");
    127119  if (label != NULL) PlotLabel (label, 0);
    128120  DonePlotting (graphdata, 0);
  • trunk/Ohana/src/uniphot/src/plotstuff.c

    r4797 r13479  
    1313int open_graph (int N) {
    1414
    15   int i, InitSocket, status, addreslen;
    16   struct sockaddr_un Address;
    17   char temp[100], *display_name;
    18   char socket_name[100];
    19   FILE *f;
     15  char name[100];
    2016 
    2117  active = N;
    22   sprintf (socket_name, "/tmp/kapa%d", N);
    23   sprintf (temp, "rm -f %s", socket_name);
    24   system (temp);
    25    
    26   strcpy (Address.sun_path, socket_name);
    27   Address.sun_family = AF_UNIX;
    28   InitSocket = socket (AF_UNIX, SOCK_STREAM, 0);
    29   status = bind (InitSocket, &Address, sizeof (Address));
    30   status = listen (InitSocket, 1);
    31  
    32   sprintf (temp, "kapa %s &", socket_name);
    33 # ifndef DEBUG
    34   system (temp);
    35 # else 
    36   fprintf (stderr, "start kapa, press return: %s\n", temp);
    37   fscanf (stdin, "%d", &i);
    38 # endif
    39  
    40   addreslen =  sizeof (Address);
    41   Xgraph[N] = accept (InitSocket, &Address, &addreslen);
     18
     19  sprintf (name, "gastro [%d]", N);
     20  Xgraph[N] = KapaOpen ("kapa", name);
     21
    4222  if (Xgraph[N] < 0) {
    4323    fprintf (stderr, "error starting kapa\n");
    4424    return (FALSE);
    4525  }
    46   else {
    47     return (TRUE);
    48   }
    49  
     26  return (TRUE);
    5027}
    5128
    5229void DonePlotting (Graphdata *graphmode, int N) {
    53   char buffer[65], buffer2[65];
    5430
    5531  if (Xgraph[N] == 0) return;
    56 
    57   write (Xgraph[N], "DBOX", 4);
    58   sprintf (buffer, "%f %f %f %f", graphmode[0].xmin, graphmode[0].xmax, graphmode[0].ymin, graphmode[0].ymax);
    59   sprintf (buffer2, "NBYTES: %6d", strlen (buffer));
    60   write (Xgraph[N], buffer2, 16);
    61   write (Xgraph[N], buffer, strlen (buffer));
    62 
    63   sprintf (buffer, "%s %s %s", "2222", "2222", "2222");
    64   sprintf (buffer2, "NBYTES: %6d", strlen (buffer));
    65   write (Xgraph[N], buffer2, 16);
    66   write (Xgraph[N], buffer, strlen (buffer));
    67 }
    68 
    69 void JpegPlot (Graphdata *graphmode, int N, char *filename) {
    70   char buffer[65], buffer2[65];
    71 
    72   if (Xgraph[N] == 0) return;
    73 
    74   write (Xgraph[N], "PNGF", 4);
    75   sprintf (buffer, "LEN: %11d", strlen (filename));
    76   write (Xgraph[N], buffer, 16);
    77   write (Xgraph[N], filename, strlen (filename));
    78   read (Xgraph[N], buffer, 4);
    79 }
    80 
    81 void PSPlot (Graphdata *graphmode, int N, char *filename) {
    82   char buffer[65], buffer2[65];
    83 
    84   if (Xgraph[N] == 0) return;
    85 
    86   write (Xgraph[N], "PSIT", 4);
    87   sprintf (buffer, "LEN: %11d", strlen (filename));
    88   write (Xgraph[N], buffer, 16);
    89   write (Xgraph[N], filename, strlen (filename));
    90   read (Xgraph[N], buffer, 4);
     32  KapaBox (Xgraph[N], graphmode);
     33  return;
    9134}
    9235
    9336void PrepPlotting (int Npts, Graphdata *graphmode, int N) {
    9437
    95   int i, status;
    96   char buffer[128], buffer2[128];
    97 
    9838  active = N;
    9939  if (Npts < 1) return;
    10040
    101   if (Xgraph[N] < 1) if (!open_graph(N)) return;
     41  KapaPrepPlot (Xgraph[N], Npts, graphmode);
     42}
    10243
    103   /* test Xgraph[N], flush junk from pipe */
    104   signal (SIGPIPE, XDead);
    105   fcntl (Xgraph[N], F_SETFL,  O_NONBLOCK);
    106   for (i = 0; (read (Xgraph[N], buffer, 64) > 0) && (i < 20); i++);
    107   fcntl (Xgraph[N], F_SETFL, !O_NONBLOCK);
    108  
    109   write (Xgraph[N], "ERAS", 4);
    110  
    111   /* tell kapa to look for the incoming image */
    112   status = write (Xgraph[N], "PLOT", 4);
     44void PlotVector (int Npts, float *vect, int mode, int N) {
    11345
    114   /* send Xgraph[N] the plot details */
    115   sprintf (buffer, "%8d %8d %d %d %d %d %f %f",
    116            Npts, graphmode[0].style,
    117            graphmode[0].ptype, graphmode[0].ltype,
    118            graphmode[0].etype, graphmode[0].color,
    119            graphmode[0].lweight, graphmode[0].size);
    120   sprintf (buffer2, "NBYTES: %6d", strlen (buffer));
    121   write (Xgraph[N], buffer2, 16);
    122   write (Xgraph[N], buffer, strlen (buffer));
    123  
    124   sprintf (buffer, "%f %f %f %f",
    125            graphmode[0].xmin, graphmode[0].xmax,
    126            graphmode[0].ymin, graphmode[0].ymax);
    127   sprintf (buffer2, "NBYTES: %6d", strlen (buffer));
    128   write (Xgraph[N], buffer2, 16);
    129   write (Xgraph[N], buffer, strlen (buffer));
     46  int Nbytes;
    13047
     48  if (Npts < 1) return;
     49  active = N;
     50  KapaPlotVector (Xgraph[N], Npts, vect);
    13151}
    13252
     
    13757  if (Xgraph[N] == 0) return;
    13858
    139   write (Xgraph[N], "LABL", 4);
    140   sprintf (buffer, " %6d %6d", strlen (string), 2);
    141   write (Xgraph[N], buffer, 16);
    142   write (Xgraph[N], string, strlen (string));
     59  KapaSendLabel (Xgraph[N[, string, 4);
    14360}
    14461
    145 void PlotVector (int Npts, double *vect, int mode, int N) {
     62void PlotReset (int N) {
    14663
    147   float *values;
    148   int i, Nbytes;
     64  char buffer[128];
     65  int i;
    14966
    150   active = N;
    151   if (Npts < 1) return;
     67  /* test Xgraph[N], flush junk from pipe */
     68  signal (SIGPIPE, XDead);
     69  fcntl (Xgraph[N], F_SETFL,  O_NONBLOCK);
     70  for (i = 0; (read (Xgraph[N], buffer, 64) > 0) && (i < 20); i++);
     71  fcntl (Xgraph[N], F_SETFL, !O_NONBLOCK);
     72 
     73  if (Xgraph[N] < 1) if (!open_graph(N)) return;
     74  KapaClearSections (Xgraph[N]);
     75}
    15276
    153   ALLOCATE (values, float, Npts);
    154   for (i = 0; i < Npts; i++) {
    155     values[i] = vect[i];
    156   }
     77void JpegPlot (Graphdata *graphmode, int N, char *filename) {
    15778
    158   Nbytes = Npts * sizeof (float);
    159   write (Xgraph[N], values, Nbytes);
    160   free (values);
     79  if (Xgraph[N] == 0) return;
    16180
     81  KapaPNG (Xgraph[N], filename);
     82  return;
     83}
     84
     85void PSPlot (Graphdata *graphmode, int N, char *filename) {
     86
     87  if (Xgraph[N] == 0) return;
     88
     89  KiiPS (Xgraph[N], filename, TRUE, KAPA_PS_NEWPLOT, "default");
     90  return;
    16291}
    16392
Note: See TracChangeset for help on using the changeset viewer.