IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 27, 2005, 5:06:32 AM (21 years ago)
Author:
eugene
Message:

converting to use libkapa commands instead of raw graph commands

Location:
trunk/Ohana/src/opihi/cmd.data
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.data/center.c

    r4689 r5846  
    2323  y = atof (argv[2]);
    2424  zoom = 0;
    25   if (argc == 4) {
    26     zoom = atof (argv[3]);
    27   }
     25  if (argc == 4) zoom = atof (argv[3]);
    2826
    29   SendGraphCommand (Ximage, 4, "CENT");
    30   SendGraphMessage (Ximage, "%8.3f %8.3f %8d ", x, y, zoom);
     27  KiiCenter (Ximage, x, y, zoom);
    3128  return (TRUE);
    3229}
  • trunk/Ohana/src/opihi/cmd.data/cursor.c

    r5349 r5846  
    33int cursor (int argc, char **argv) {
    44
    5   char buffer[40], string[20], key[20], keyname[20];
     5  char string[20], key[20];
    66  int i, N, Nsource, Source, IsImage;
    77  double X, Y, R, D, Z;
     
    4242  if (IsImage) buf = SelectBuffer (GetImageName(), OLDBUFFER, FALSE);
    4343 
    44   sprintf (string, "CURS");
    45   write (Source, string, 4); /* ask Source to look for the keystrokes */
     44  KiiCursorOn (Source);
    4645 
    4746  oldsignal = signal (SIGINT, handle_interrupt);
     
    4948  Z = -1.0;
    5049  for (i = 0; ((i < N) || (N == 0)) && !interrupt; i++) {
    51     bzero (buffer, 40);
    52     read (Source, buffer, 40);
    53     buffer[39] = 0;
    54     sscanf (buffer, "%s %lf %lf", key, &X, &Y);
    55     if (ispunct(key[0])) {
    56       strcpy (keyname, "_");
    57     } else {
    58       strcpy (keyname, key);
    59     }
    60     sprintf (string, "X%s", keyname);
     50    KiiCursorRead (Source, &X, &Y, key);
     51
     52    sprintf (string, "X%s", key);
    6153    set_variable (string, X);
    62     sprintf (string, "Y%s", keyname);
     54    sprintf (string, "Y%s", key);
    6355    set_variable (string, Y);
    6456    set_str_variable ("KEY", key);
    6557   
    66     if (IsImage && (buf != NULL))
    67       Z = fits_get_matrix_value (&buf[0].matrix, (int)X, (int)Y);
    68 
    69     if (!IsImage) {
    70       XY_to_RD (&R, &D, X, Y, &graphmode.coords);
    71       sprintf (string, "R%s", keyname);
    72       set_variable (string, R);
    73       sprintf (string, "D%s", keyname);
    74       set_variable (string, D);
    75     }
    76 
    77     /* I still don't like this, but I have to decide which to print... */
    7858    if (IsImage) {
     59      if (buf != NULL) {
     60        Z = fits_get_matrix_value (&buf[0].matrix, (int) X, (int) Y);
     61      }
    7962      fprintf (GetOutfile(), "%s %f %f  %f\n", key, X, Y, Z);
    8063    } 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);
    8169      fprintf (GetOutfile(), "%s %f %f\n", key, X, Y);
    8270    }
    83 
    84     if (!strcasecmp (key, "Q")) {
    85       signal (SIGINT, (void *) oldsignal);
    86       write (Source, "NCUR", 4); /* ask Source to stop looking for the keystrokes */
    87       return (TRUE);
    88     }
    89 
     71    if (!strcasecmp (key, "Q")) break;
    9072  }
    9173
    9274  signal (SIGINT, oldsignal);
    93   write (Source, "NCUR", 4); /* ask Source to look for the keystrokes */
     75  KiiCursorOff (Source);
    9476  return (TRUE);
    95      
    9677}
  • trunk/Ohana/src/opihi/cmd.data/erase.c

    r4689 r5846  
    33int erase (int argc, char **argv) {
    44 
    5   int i, n, N;
     5  int i, N;
    66  int Ximage, Nimage;
    77 
     
    2121
    2222  for (i = 1; i < argc; i++) {
    23     if (strcmp (argv[i], "0")   && strcmp (argv[i], "1")     && strcmp (argv[i], "2")   && strcmp (argv[i], "3") &&
    24         strcmp (argv[i], "red") && strcmp (argv[i], "green") && strcmp (argv[i], "blue") && strcmp (argv[i], "yellow") &&
    25         strcmp (argv[i], "all") && strcmp (argv[i], "tick") ) {
     23    if (!(strcasecmp (argv[i], "all"))) {
     24      KiiEraseOverlay (Ximage, "red");
     25      KiiEraseOverlay (Ximage, "green");
     26      KiiEraseOverlay (Ximage, "blue");
     27      KiiEraseOverlay (Ximage, "yellow");
     28      continue;
     29    }
     30    if (!KiiSelectOverlay (argv[i], &N)) {
    2631      fprintf (stderr, "%s is not a valid overlay\n", argv[i]);
    2732      return (FALSE);
    2833    }
    29     n = atof (argv[i]);
    30     if (!(strcmp (argv[i], "all"))) {
    31       for (n = 0; n < 4; n++) {
    32         SendGraphCommand (Ximage, 4, "ERAS");
    33         SendGraphCommand (Ximage, 16, "OVERLAY %7d ", n);
    34       }
    35       return (TRUE);
    36     }
    37    
    38     if (!(strcmp (argv[i], "red"))) n = 0;
    39     if (!(strcmp (argv[i], "green"))) n = 1;
    40     if (!(strcmp (argv[i], "blue"))) n = 2;
    41     if (!(strcmp (argv[i], "yellow"))) n = 3;
    42     if (!(strcmp (argv[i], "tick"))) n = 4;
    43    
    44     SendGraphCommand (Ximage, 4, "ERAS");
    45     SendGraphCommand (Ximage, 16, "OVERLAY %7d ", n);
     34    KiiEraseOverlay (Ximage, argv[i]);
    4635  }
    4736  return (TRUE);
  • trunk/Ohana/src/opihi/cmd.data/jpeg.c

    r3693 r5846  
    4646    if (!filename[0]) strcpy (filename, "Ximage.jpg");
    4747    strcpy (type, "JPEG");
     48    KiiJpeg (Source, filename);
    4849  } else {
    4950    if (!GetGraph (NULL, &Source, &Nsource)) return (FALSE);
    5051    if (!filename[0]) strcpy (filename, "Xgraph.png");
     52    SendGraphCommand (Source, 4, type);
     53    SendGraphCommand (Source, 16, "LEN: %11d", strlen(filename));
     54    write (Source, filename, strlen(filename));
     55    read (Source, buffer, 4);
    5156  }
    52 
    53   SendGraphCommand (Source, 4, type);
    54   SendGraphCommand (Source, 16, "LEN: %11d", strlen(filename));
    55   write (Source, filename, strlen(filename));
    56   read (Source, buffer, 4);
    57 
    5857  return (TRUE);
    5958}
  • trunk/Ohana/src/opihi/cmd.data/load.c

    r4689 r5846  
    33int load (int argc, char **argv) {
    44 
    5   int N, n, Nline, ISCEL;
    6   int Ximage, Nimage;
    7   char *c, type[10], string[128];
     5  int i, N, n, ISCEL;
     6  int Ximage, Nimage, Noverlay, NOVERLAY;
     7  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, *line;
     11  char *buffer;
    1212  Coords coords;
    1313  Buffer *buf;
     14  KiiOverlay *overlay;
    1415 
    1516  Nimage = -1;
     
    3334  }
    3435 
    35   if (!SelectOverlay (argv[1], &n)) return (FALSE);
    36 
    3736  if (!strcmp (argv[2], "-")) {
    3837    f = stdin;
     
    5049  }
    5150
     51  Noverlay = 0;
     52  NOVERLAY = 1000;
     53  ALLOCATE (overlay, KiiOverlay, NOVERLAY);
     54
    5255  ALLOCATE (buffer, char, 65536);  /* space for 512 lines of 128 bytes */
    5356  bzero (buffer, 65536);
    54   ALLOCATE (line, char, 1024);     /* space to read the file */
    55   Nline = 0;
    5657
    57   SendGraphCommand (Ximage, 4, "LOAD");
    58   SendGraphCommand (Ximage, 16, "OVER %9d ", n);
    59  
    6058  dx = dy = 0;
    6159  for (n = 0; scan_line (f, line) != EOF;) {
     
    8179    case 3:
    8280      if (strcmp (type, "TEXT")) {
    83         fprintf (stderr, "syntactical error in line:\n   %s\n", line);
     81        fprintf (stderr, "syntax error in line:\n   %s\n", line);
    8482        continue;
    8583      }
     
    113111      }
    114112    }
    115     if (!strcmp (type, "TEXT")) {
    116       snprintf (&buffer[Nline*128], 128, "%15s %20.10f %20.10f %s ", type, x, y, string);
     113    overlay[Noverlay].type = KiiOverlayTypeByName (type);
     114    if (overlay[Noverlay].type == KII_OVERLAY_TEXT) {
     115      overlay[Noverlay].text = strcreate (string);
    117116    } else {
    118       snprintf (&buffer[Nline*128], 128, "%15s %20.10f %20.10f %20.10f %20.10f ", type, x, y, dx, dy);
     117      overlay[Noverlay].text = NULL;
    119118    }
    120     n++;
    121     Nline ++;
    122     if (Nline == 512) {
    123       SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline);
    124       write (Ximage, buffer, Nline*128);
    125       bzero (buffer, 65536);
    126       Nline = 0;
    127     }
     119    overlay[Noverlay].x = x;
     120    overlay[Noverlay].y = y;
     121    overlay[Noverlay].dx = dx;
     122    overlay[Noverlay].dy = dy;
     123    Noverlay++;
     124    CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 1000);
    128125  }
    129126
    130   SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline);
    131   write (Ximage, buffer, Nline*128);
    132   SendGraphCommand (Ximage, 16, "DONE");
     127  KiiLoadOverlay (Ximage, overlay, Noverlay, argv[1]);
    133128
    134   free (buffer);
    135   free (line);
    136   fprintf (stderr, "loaded %d objects\n", n);
     129  for (i = 0; i < Noverlay; i++) {
     130    if (overlay[i].text == NULL) continue;
     131    free (overlay[i].text);
     132  }
     133  free (overlay);
     134
     135  fprintf (stderr, "loaded %d objects\n", Noverlay);
     136
    137137  if (f != stdin) {
    138138    fclose (f);
  • trunk/Ohana/src/opihi/cmd.data/point.c

    r4689 r5846  
    33int point (int argc, char **argv) {
    44 
    5   int N, n, ISCEL, ISPIX;
     5  int N, celestial, pixscale;
    66  int Ximage, Nimage;
    7   double x, y, dx, dy, x1, y1;
    8   double dra, ddec, ra1, dec1, ra, dec;
     7  double ra, dec, dra, ddec;
     8  double x1, y1, ra1, dec1;
    99  Coords coords;
    1010  Buffer *buf;
     11  KiiOverlay overlay;
    1112
    1213  Nimage = -1;
     
    1819  if (!GetImage (&Ximage, &Nimage)) return (FALSE);
    1920 
    20   ISCEL = FALSE;
     21  celestial = FALSE;
    2122  if ((N = get_argument (argc, argv, "-c"))) {
    2223    remove_argument (N, &argc, argv);
    23     ISCEL = TRUE;
     24    celestial = TRUE;
    2425  }
    2526 
    26   ISPIX = FALSE;
    27   if ((N = get_argument (argc, argv, "-p"))) {
     27  pixscale = FALSE;
     28  if ((N = get_argument (argc, argv, "-pixscale"))) {
    2829    remove_argument (N, &argc, argv);
    29     ISPIX = TRUE;
     30    pixscale = TRUE;
    3031  }
    3132
     
    3536  }
    3637 
    37   if (!SelectOverlay (argv[1], &n))
    38     return (FALSE);
    39 
    40   if (ISCEL) {
     38  if (celestial) {
    4139    if ((buf = SelectBuffer (GetImageName(), OLDBUFFER, TRUE)) == NULL) return (FALSE);
    4240    GetCoords (&coords, &buf[0].header);
    4341  }
    4442
    45   ra = atof(argv[3]);
    46   dec = atof(argv[4]);
    47   dra = atof(argv[5]);
    48   ddec = atof(argv[6]);
    49   if (ISCEL) {
    50     RD_to_XY (&x, &y, ra, dec, &coords);
    51     if (!ISPIX) {
     43  if (celestial) {
     44    ra   = atof(argv[3]);
     45    dec  = atof(argv[4]);
     46    dra  = atof(argv[5]);
     47    ddec = atof(argv[6]);
     48
     49    fRD_to_XY (&overlay.x, &overlay.y, ra, dec, &coords);
     50    if (pixscale) {
     51      overlay.dx = atof(argv[5]);
     52      overlay.dy = atof(argv[6]);
     53    } else {
    5254      ra1 = ra + dra;
    5355      dec1 = dec + ddec;
    5456      RD_to_XY (&x1, &y1, ra1, dec1, &coords);
    55       dx = x1 - x;
    56       dy = y1 - y;
    57     } else {
    58       dx = atof(argv[5]);
    59       dy = atof(argv[6]);
     57      overlay.dx = x1 - overlay.x;
     58      overlay.dy = y1 - overlay.y;
    6059    }
    6160  }
    6261  else {
    63     x = ra;
    64     y = dec;
    65     dx = dra;
    66     dy = ddec;
     62    overlay.x  = atof(argv[3]);
     63    overlay.y  = atof(argv[4]);
     64    overlay.dx = atof(argv[5]);
     65    overlay.dy = atof(argv[6]);
    6766  }
    68 
    69   SendGraphCommand (Ximage, 4, "LOAD");
    70   SendGraphCommand (Ximage, 16, "OVERLAY %6d ", n);
    71   SendGraphCommand (Ximage, 16, "NLINES %7d ", 1);
    72   SendGraphCommand (Ximage, 128, "%15s %20.10f %20.10f %20.10f %20.10f ", argv[2], x, y, dx, dy);
    73   SendGraphCommand (Ximage, 16, "DONE");
     67  overlay.type = KiiOverlayTypeByName (argv[2]);
     68  KiiLoadOverlay (Ximage, &overlay, 1, argv[1]);
    7469  return (TRUE);
    7570}
    76 
  • trunk/Ohana/src/opihi/cmd.data/ps.c

    r3693 r5846  
    33int ps (int argc, char **argv) {
    44
    5   char filename[1024], buffer[64];
     5  char filename[1024];
    66  int N, Source, Nsource, RawImage, NoScale, IsImage;
    77 
     
    5656 
    5757  /* tell Ximage/Xgraph to ps the image */
    58   if (RawImage) SendGraphCommand (Source, 4, "PSRW");
    59   if (NoScale)  SendGraphCommand (Source, 4, "PSNS");
    60   if (!RawImage && !NoScale) SendGraphCommand (Source, 4, "PSIT");
    61 
    62   /* I need to fix kapa and kii to read NBYTES, etc like other messages */
    63   SendGraphCommand (Source, 16, "LEN: %11d", strlen(filename));
    64   write (Source, filename, strlen(filename));
    65   read (Source, buffer, 4);
    66 
     58  KiiPS (Source, NoScale, RawImage, filename);
    6759  return (TRUE);
    6860}
  • trunk/Ohana/src/opihi/cmd.data/resize.c

    r2843 r5846  
    33int resize (int argc, char **argv) {
    44
    5   char buffer[128], buffer2[128], *end;
     5  char *end;
    66  double NX, NY;
    77  int N, Source, Nsource, IsImage;
     
    4949  if (!strcmp (end, "cm")) { NY *= 38; }
    5050
    51   write (Source, "RSIZ", 4); /* tell Source to resize the image */
    52 
    53   sprintf (buffer, "%d %d", (int) NX, (int) NY);
    54   sprintf (buffer2, "NBYTES: %6d ", strlen (buffer));
    55   write (Source, buffer2, 16);
    56   write (Source, buffer, strlen (buffer));
    57 
     51  KiiResize (Source, NX, NY);
    5852  return (TRUE);
    59 
    6053}
    6154
  • trunk/Ohana/src/opihi/cmd.data/save.c

    r4689 r5846  
    33int save (int argc, char **argv) {
    44 
    5   int N, n, ISCEL;
     5  int N, celestial;
    66  int Ximage, Nimage;
    77 
     
    1414  if (!GetImage (&Ximage, &Nimage)) return (FALSE);
    1515
    16   ISCEL = FALSE;
     16  celestial = FALSE;
    1717  if ((N = get_argument (argc, argv, "-c"))) {
    1818    remove_argument (N, &argc, argv);
    19     ISCEL = TRUE;
     19    celestial = TRUE;
    2020  }
    2121
     
    2626  }
    2727
    28   if (!SelectOverlay (argv[1], &n)) return (FALSE);
    29  
    30   if (ISCEL)
    31     SendGraphCommand (Ximage, 4, "CSVE");
    32   else
    33     SendGraphCommand (Ximage, 4, "SAVE");
    34 
    35   SendGraphMessage (Ximage, "FILE: %d %s", n, argv[2]);
     28  KiiSaveOverlay (Ximage, celestial, argv[1], argv[2]);
    3629  return (TRUE);
    3730}
  • trunk/Ohana/src/opihi/cmd.data/tv.c

    r4689 r5846  
    33int tv (int argc, char **argv) {
    44 
    5   int N, j, Npix, Ncolors, size, ISLOG, NNcol;
    6   char buffer[1024];
    7   double a1, a2, max, min, zero, range;
    8   float *in;
    9   char *out, *outbuffer, *root;
    10   int Ximage, Nimage;
     5  int N, Ximage, Nimage;
    116  Coords coords;
    127  Buffer *buf;
     8  KiiImage image;
     9  KiiDisplayMode mode;
    1310
    1411  Nimage = -1;
     
    2219  /* shell exits on pipe close, FIX */
    2320  if ((N = get_argument (argc, argv, "-kill"))) {
    24     close (Ximage);
     21    KiiClose (Ximage);
    2522    Ximage = 0;
    2623    return (TRUE);
    2724  }
    2825
    29   min = max = 0.0;
    30   ISLOG = FALSE;
     26  mode.logflux = FALSE;
    3127  if ((N = get_argument (argc, argv, "-log"))) {
    3228    remove_argument (N, &argc, argv);
    33     ISLOG = TRUE;
     29    mode.logflux = TRUE;
    3430  }
    3531
     
    3935  }
    4036
    41   GetImageScale (&zero, &range);
     37  GetImageScale (&mode.zero, &mode.range);
    4238  if (argc == 4) {
    43     zero = atof (argv[2]);
    44     range = atof (argv[3]);
    45     if (range == 0.0) range = 0.001;
    46     SetImageScale (zero, range);
     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);
    4743  }
    4844
    4945  if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);
    5046  GetCoords (&coords, &buf[0].header);
     47 
     48  image.data1d = (float *) buf[0].matrix.buffer;
     49  image.Nx = buf[0].matrix.Naxis[0];
     50  image.Ny = buf[0].matrix.Naxis[1];
     51  image.file = buf[0].file;
     52  image.name = buf[0].name;
    5153
    52   Npix = buf[0].matrix.Naxis[0]*buf[0].matrix.Naxis[1];
    53   size = Npix * sizeof (char);
    54   in = (float *) (buf[0].matrix.buffer);
    55   ALLOCATE (outbuffer, char, Npix);
    56   out = outbuffer;
    57 
    58   SendGraphCommand (Ximage, 4, "READ"); /* tell Ximage to look for the incoming image */
    59 
    60   /* convert from (float) internal rep to 1 byte chars -- depends on how many colors Kii owns*/
    61   read (Ximage, buffer, 16);
    62   sscanf (buffer, "%*s %d", &Ncolors);
    63 
    64   /* need to invert the logic if range < 0 */
    65   /* define color table, */
    66   NNcol = Ncolors - 1;
    67   if (ISLOG) {
    68     range = MAX (2, range);
    69     a1 = Ncolors / log10 (range);
    70     for (j = 0; j < Npix; j++, in++, out++) {
    71       *out = (char) MIN (a1 * log10 (MAX (*in - zero, 1.0)), NNcol);
    72     }
    73   }
    74   if (!ISLOG) {
    75     a1 = Ncolors / range;
    76     a2 = Ncolors * zero / range;
    77     for (j = 0; j < Npix; j++, in++, out++) {
    78       *out = (char) MIN (MAX (a1 * *in - a2, 0), NNcol);
    79     }
    80   }
    81  
    82   /* done with the conversion, now send Ximage the converted picture */
    83   SendGraphMessage (Ximage, "%8d %8d 8 1 %f %f", buf[0].matrix.Naxis[0], buf[0].matrix.Naxis[1], 0.0, 1.0);
    84   SendGraphMessage (Ximage, "%f %f %f %f %d ", zero, range, min, max, size);
    85   SendGraphMessage (Ximage, "%f %f %g %g %g ", coords.crval1, coords.crpix1, coords.cdelt1, coords.pc1_1, coords.pc1_2);
    86   SendGraphMessage (Ximage, "%f %f %g %g %g ", coords.crval2, coords.crpix2, coords.cdelt2, coords.pc2_1, coords.pc2_2);
    87 
    88   root = filerootname (buf[0].file);
    89   SendGraphMessage (Ximage, "%s %s %s ", coords.ctype, root, buf[0].name);
    90   write (Ximage, outbuffer, size);
    91   free (outbuffer);
     54  KiiNewPicture1D (Ximage, &image, &mode, &coords);
    9255
    9356  SetImageName (argv[1]);
  • trunk/Ohana/src/opihi/cmd.data/tvcontour.c

    r4689 r5846  
    4242
    4343# define DUMP { \
    44 sprintf (&buffer[Nline*128], "%14s %20.10f %20.10f %20.10f %20.10f ", "LINE", Npix*x, Npix*y, Npix*dx, Npix*dy); \
    45 Nline ++; \
    46 if (Nline == 512) { \
    47   SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline); \
    48   write (Ximage, buffer, Nline*128); \
    49   bzero (buffer, 65536); \
    50   Nline = 0; \
    51 } \
    52 continue; }
    53 
    54 # define NUMP { \
    55 sprintf (&buffer[Nline*128], "%14s %20.10f %20.10f %20.10f %20.10f ", "LINE", Npix*x, Npix*y, Npix*dx, Npix*dy); \
    56 Nline ++; \
    57 if (Nline == 512) { \
    58   SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline); \
    59   write (Ximage, buffer, Nline*128); \
    60   bzero (buffer, 65536); \
    61   Nline = 0; \
    62 } }
     44overlay[Noverlay].type = KII_OVERLAY_LINE; \
     45overlay[Noverlay].x = Npix*x; \
     46overlay[Noverlay].y = Npix*y; \
     47overlay[Noverlay].dx = Npix*dx; \
     48overlay[Noverlay].dy = Npix*dy; \
     49Noverlay ++; \
     50CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 1000); \
     51}
    6352
    6453int tvcontour (int argc, char **argv) {
    6554
    66   int i, j, ii, jj, n, Npix, Nx, Ny, Nline;
     55  int i, j, ii, jj, Npix, Nx, Ny;
    6756  float level, d00, d01, d10, d11, tmp;
    6857  float x, y, dx, dy;
    6958  float *v00, *v01, *v10, *v11;
    7059  float *Vout, *Vin, *matrix;
    71   char *buffer;
    72   int Ximage, Nimage, N;
     60  int Ximage, Nimage, N, Noverlay, NOVERLAY;
    7361  Buffer *buf;
     62  KiiOverlay *overlay;
    7463 
    7564  Nimage = -1;
     
    8776
    8877  if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);
    89   if (!SelectOverlay (argv[2], &n)) return (FALSE);
    9078
    9179  level = atof (argv[3]);
     
    115103      }
    116104    }
    117   }
    118   else {
     105  } else {
    119106    fprintf (stderr, "using scale of 1\n");
    120107    matrix = (float *)(buf[0].matrix.buffer);
    121108  }
    122109
    123   SendGraphCommand (Ximage, 4, "LOAD"); /* force Ximage to look for the incoming image */
    124   SendGraphCommand (Ximage, 16, "OVERLAY %7d ", n);
    125   ALLOCATE (buffer, char, 65536);  /* space for 512 lines of 128 bytes */
    126   bzero (buffer, 65536);
    127   Nline = 0;
     110  Noverlay = 0;
     111  NOVERLAY = 1000;
     112  ALLOCATE (overlay, KiiOverlay, NOVERLAY);
    128113
    129114  v00 = matrix;
     
    150135          LL;
    151136          DUMP;
     137          continue;
    152138        }
    153139        if ((d01 > 0) && (d11 <= 0)) { /* -  */
    154140          HZ;
    155141          DUMP;
     142          continue;
    156143        }
    157144        if ((d01 > 0) && (d11 > 0)) { /* /  */
    158145          UL;
    159146          DUMP;
     147          continue;
    160148        }
    161149        if ((d01 <= 0) && (d11 > 0)) { /* \\  */
    162150          LL;
    163           NUMP;
     151          DUMP;
    164152          UR;
    165153          DUMP;
     154          continue;
    166155        }
    167156      }
     
    171160          LL;
    172161          DUMP;
     162          continue;
    173163        }
    174164        if ((d01 <= 0) && (d11 > 0)) { /* -  */
    175165          HZ;
    176166          DUMP;
     167          continue;
    177168        }
    178169        if ((d01 <= 0) && (d11 <= 0)) { /* /  */
    179170          UL;
    180171          DUMP;
     172          continue;
    181173        }
    182174        if ((d01 > 0) && (d11 <= 0)) { /* //  */
    183175          UL;
    184           NUMP;
     176          DUMP;
    185177          LR;
    186178          DUMP;
     179          continue;
    187180        }
    188181      }
     
    193186          LR;
    194187          DUMP;
     188          continue;
    195189        }
    196190        if ((d01 <= 0) && (d11 > 0)) {
    197191          UR;
    198192          DUMP;
     193          continue;
    199194        }
    200195        if ((d01 > 0) && (d11 > 0)) {
    201196          VT;
    202197          DUMP;
     198          continue;
    203199        }
    204200      }
     
    208204          LR;
    209205          DUMP;
     206          continue;
    210207        }
    211208        if ((d01 > 0) && (d11 <= 0)) {
    212209          UR;
    213210          DUMP;
     211          continue;
    214212        }
    215213        if ((d01 <= 0) && (d11 <= 0)) {
    216214          VT;
    217215          DUMP;
     216          continue;
    218217        }
    219218      }
     
    235234    if (((*v00 > level) && (*v01 <= level)) || ((*v00 <= level) && (*v01 > level))) {
    236235      x = i + (level - *v01)/(*v01 - *v00);
    237       NUMP;
     236      DUMP;
    238237    }
    239238  }
     
    248247    if (((*v00 > level) && (*v01 <= level)) || ((*v00 <= level) && (*v01 > level))) {
    249248      x = i + (level - *v01)/(*v01 - *v00);
    250       NUMP;
     249      DUMP;
    251250    }
    252251  }
     
    261260    if (((*v00 > level) && (*v01 <= level)) || ((*v00 <= level) && (*v01 > level))) {
    262261      y = j + (level - *v01)/(*v01 - *v00);
    263       NUMP;
     262      DUMP;
    264263    }
    265264  }
     
    274273    if (((*v00 > level) && (*v01 <= level)) || ((*v00 <= level) && (*v01 > level))) {
    275274      y = j + (level - *v01)/(*v01 - *v00);
    276       NUMP;
     275      DUMP;
    277276    }
    278277  }
    279278 
    280   if (Nline > 0) {
    281     SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline);
    282     write (Ximage, buffer, Nline*128);
    283   }
    284 
    285   free (buffer);
    286   SendGraphCommand (Ximage, 16, "DONE");
     279  KiiLoadOverlay (Ximage, overlay, Noverlay, argv[2]);
     280  free (overlay);
    287281
    288282  if (Npix != 1) free (matrix);
  • trunk/Ohana/src/opihi/cmd.data/tvgrid.c

    r4689 r5846  
    44int tvgrid (int argc, char **argv) {
    55 
    6   int ncolor, ndig1, ndig2, NX, NY, connect;
     6  int ndig1, ndig2, NX, NY, connect;
    77  int tDEC, tRA;
    88  double ra, dec, ra0, dec0, ra1, dec1;
     
    1111  char format[16];
    1212  Coords coords;
    13   int Ximage, Nimage, N;
     13  int Ximage, Nimage, N, Noverlay, NOVERLAY;
    1414  Buffer *buf;
     15  KiiOverlay *overlay;
    1516
    1617  Nimage = -1;
     
    2324 
    2425  if (argc != 3) {
    25     fprintf (stderr, "USAGE: load (overlay) (buffer)\n");
     26    fprintf (stderr, "USAGE: tvgrid (overlay) (buffer)\n");
    2627    fprintf (stderr, " (overlay) may be: red, green, blue, yellow\n");
    2728    return (FALSE);
    2829  }
    29   if (strcmp (argv[1], "0")   && strcmp (argv[1], "1")     && strcmp (argv[1], "2")   && strcmp (argv[1], "3") &&
    30       strcmp (argv[1], "red") && strcmp (argv[1], "green") && strcmp (argv[1], "blue") && strcmp (argv[1], "yellow")) {
    31     fprintf (stderr, "valid overlays may be: 0, red, 1, green, 2, blue, 3, yellow\n");
    32     return (FALSE);
    33   }
    34 
    35   ncolor = atof (argv[1]);
    36   if (!(strcmp (argv[1], "red")))
    37     ncolor = 0;
    38   if (!(strcmp (argv[1], "green")))
    39     ncolor = 1;
    40   if (!(strcmp (argv[1], "blue")))
    41     ncolor = 2;
    42   if (!(strcmp (argv[1], "yellow")))
    43     ncolor = 3;
    4430
    4531  if ((buf = SelectBuffer (argv[2], OLDBUFFER, TRUE)) == NULL) return (FALSE);
     
    5036  fprintf (stderr, "%f %f  %f %f\n", ra0, dec0, ra1, dec1);
    5137 
    52   /* tell KII to expect overlay data */
    53   SendGraphCommand (Ximage, 4, "LOAD");
    54   SendGraphCommand (Ximage, 16, "OVERLAY: %7d", ncolor);
    55  
     38  Noverlay = 0;
     39  NOVERLAY = 1000;
     40  ALLOCATE (overlay, KiiOverlay, NOVERLAY);
     41
    5642  dDEC = fabs(dec1 - dec0);
    5743  tDEC = log10(dDEC) - log10(5.0);
     
    9076      RD_to_XY (&x1, &y1, ra, dec, &coords);
    9177      if ((x1 >= 0) && (x1 < NX) && (y1 >= 0) && (y1 < NY)) {
    92         if (connect) SendGraphCommand (Ximage, 128, "%15s %20.10f %20.10f %20.10f %20.10f ", "LINE", x0, y0, (x1 - x0), (y1 - y0));
     78        if (connect) {
     79          overlay[Noverlay].type = KII_OVERLAY_LINE;
     80          overlay[Noverlay].x = x0;
     81          overlay[Noverlay].y = y0;
     82          overlay[Noverlay].dx = x1 - x0;
     83          overlay[Noverlay].dy = y1 - y0;
     84          Noverlay ++;
     85          CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 1000);
     86        }
    9387        x0 = x1;
    9488        y0 = y1;
     
    132126      RD_to_XY (&x1, &y1, ra, dec, &coords);
    133127      if ((x1 >= 0) && (x1 < NX) && (y1 >= 0) && (y1 < NY)) {
    134         if (connect) SendGraphCommand (Ximage, 128, "%15s %20.10f %20.10f %20.10f %20.10f ", "LINE", x0, y0, (x1 - x0), (y1 - y0));
     128        if (connect) {
     129          overlay[Noverlay].type = KII_OVERLAY_LINE;
     130          overlay[Noverlay].x = x0;
     131          overlay[Noverlay].y = y0;
     132          overlay[Noverlay].dx = x1 - x0;
     133          overlay[Noverlay].dy = y1 - y0;
     134          Noverlay ++;
     135          CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 1000);
     136        }
    135137        x0 = x1;
    136138        y0 = y1;
     
    142144  }
    143145
    144   /*
     146  # if (0)
     147  /* write the labels on the axes */
    145148  dDEC = fabs(dec1 - dec0) / 100;
    146149  for (ra = dRA * ((int)(MIN(ra0, ra1)/dRA) + 1); ra < MAX(ra0, ra1); ra += dRA) {
     
    159162    }
    160163  }
    161   */
     164  # endif
    162165
    163   SendGraphCommand (Ximage, 128, "DONE");
     166  KiiLoadOverlay (Ximage, overlay, Noverlay, argv[1]);
     167  free (overlay);
     168
    164169  return (TRUE);
    165170}
    166 
    167 /*
    168   write (Ximage, "LOAD", 4);
    169   sprintf (buffer, "OVERLAY: %7d", n);
    170   write (Ximage, buffer, 16);
    171  
    172   for (n = 0; scan_line (f, buffer) != EOF; n++) {
    173     c = strchr (buffer, '#');
    174     if (c != (char *) NULL)
    175       *c = 0; 
    176     while ((c = strchr (buffer, '(')) != (char *) NULL)
    177       *c = ' ';
    178     while ((c = strchr (buffer, ')')) != (char *) NULL)
    179       *c = ' ';
    180     while ((c = strchr (buffer, ',')) != (char *) NULL)
    181       *c = ' ';
    182     N = sscanf (buffer, "%s %lf %lf %lf %lf", type, &x, &y, &dx, &dy);
    183     if (N > 3) {
    184       if (N == 4)
    185         dy = dx;
    186       sprintf (buffer, "%15s %20.10f %20.10f %20.10f %20.10f ", type, x, y, dx, dy);
    187       write (Ximage, buffer, 128);
    188     }
    189   }
    190   fprintf (stderr, "loaded %d objects\n", n);
    191   sprintf (buffer, "DONE");
    192   write (Ximage, buffer, 128);
    193   if (f != stdin) {
    194     fclose (f);
    195   }
    196 */
  • trunk/Ohana/src/opihi/cmd.data/vcontour.c

    r3693 r5846  
    4242
    4343# define DUMP { \
    44 sprintf (&buffer[Nline*128], "%14s %20.10f %20.10f %20.10f %20.10f \0", "LINE", Npix*x, Npix*y, Npix*dx, Npix*dy); \
    45 Nline ++; \
    46 if (Nline == 512) { \
    47   SendGraphCommand (Ximage, 16, "NLINES  %7d \0", Nline); \
    48   write (Ximage, buffer, Nline*128); \
    49   bzero (buffer, 65536); \
    50   Nline = 0; \
    51 } \
    52 continue; }
    53 
    54 # define NUMP { \
    55 sprintf (&buffer[Nline*128], "%14s %20.10f %20.10f %20.10f %20.10f \0", "LINE", Npix*x, Npix*y, Npix*dx, Npix*dy); \
    56 Nline ++; \
    57 if (Nline == 512) { \
    58   SendGraphCommand (Ximage, 16, "NLINES  %7d \0", Nline); \
    59   write (Ximage, buffer, Nline*128); \
    60   bzero (buffer, 65536); \
    61   Nline = 0; \
    62 } }
     44overlay[Noverlay].type = KII_OVERLAY_LINE; \
     45overlay[Noverlay].x = Npix*x; \
     46overlay[Noverlay].y = Npix*y; \
     47overlay[Noverlay].dx = Npix*dx; \
     48overlay[Noverlay].dy = Npix*dy; \
     49Noverlay ++; \
     50CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 1000); \
     51}
    6352
    6453int vcontour (int argc, char **argv) {
     
    11099  /* not really finished */
    111100
     101  Noverlay = 0;
     102  NOVERLAY = 1000;
     103  ALLOCATE (overlay, KiiOverlay, NOVERLAY);
     104
    112105  v01 = matrix + 1;
    113106  v10 = matrix + Nx;
     
    132125          LL;
    133126          DUMP;
     127          continue;
    134128        }
    135129        if ((d01 > 0) && (d11 <= 0)) { /* -  */
    136130          HZ;
    137131          DUMP;
     132          continue;
    138133        }
    139134        if ((d01 > 0) && (d11 > 0)) { /* /  */
    140135          UL;
    141136          DUMP;
     137          continue;
    142138        }
    143139        if ((d01 <= 0) && (d11 > 0)) { /* \\  */
    144140          LL;
    145           NUMP;
     141          DUMP;
    146142          UR;
    147143          DUMP;
     144          continue;
    148145        }
    149146      }
     
    153150          LL;
    154151          DUMP;
     152          continue;
    155153        }
    156154        if ((d01 <= 0) && (d11 > 0)) { /* -  */
    157155          HZ;
    158156          DUMP;
     157          continue;
    159158        }
    160159        if ((d01 <= 0) && (d11 <= 0)) { /* /  */
    161160          UL;
    162161          DUMP;
     162          continue;
    163163        }
    164164        if ((d01 > 0) && (d11 <= 0)) { /* //  */
    165165          UL;
    166           NUMP;
     166          DUMP;
    167167          LR;
    168168          DUMP;
     169          continue;
    169170        }
    170171      }
     
    175176          LR;
    176177          DUMP;
     178          continue;
    177179        }
    178180        if ((d01 <= 0) && (d11 > 0)) {
    179181          UR;
    180182          DUMP;
     183          continue;
    181184        }
    182185        if ((d01 > 0) && (d11 > 0)) {
    183186          VT;
    184187          DUMP;
     188          continue;
    185189        }
    186190      }
     
    190194          LR;
    191195          DUMP;
     196          continue;
    192197        }
    193198        if ((d01 > 0) && (d11 <= 0)) {
    194199          UR;
    195200          DUMP;
     201          continue;
    196202        }
    197203        if ((d01 <= 0) && (d11 <= 0)) {
    198204          VT;
    199205          DUMP;
     206          continue;
    200207        }
    201208      }
     
    217224    if (((*v00 > level) && (*v01 <= level)) || ((*v00 <= level) && (*v01 > level))) {
    218225      x = i + (level - *v01)/(*v01 - *v00);
    219       NUMP;
     226      DUMP;
     227      continue;
    220228    }
    221229  }
     
    230238    if (((*v00 > level) && (*v01 <= level)) || ((*v00 <= level) && (*v01 > level))) {
    231239      x = i + (level - *v01)/(*v01 - *v00);
    232       NUMP;
     240      DUMP;
     241      continue;
    233242    }
    234243  }
     
    243252    if (((*v00 > level) && (*v01 <= level)) || ((*v00 <= level) && (*v01 > level))) {
    244253      y = j + (level - *v01)/(*v01 - *v00);
    245       NUMP;
     254      DUMP;
     255      continue;
    246256    }
    247257  }
     
    256266    if (((*v00 > level) && (*v01 <= level)) || ((*v00 <= level) && (*v01 > level))) {
    257267      y = j + (level - *v01)/(*v01 - *v00);
    258       NUMP;
     268      DUMP;
     269      continue;
    259270    }
    260271  }
    261272 
    262   if (Nline > 0) {
    263     SendGraphCommand (Ximage, 16, "NLINES  %7d \0", Nline);
    264     write (Ximage, buffer, Nline*128);
    265   }
    266 
    267   free (buffer);
    268   SendGraphCommand (Ximage, 16, "DONE");
     273  KiiLoadOverlay (Ximage, overlay, Noverlay, argv[2]);
     274  free (overlay);
     275
    269276  if (Npix != 1) free (matrix);
    270277  fprintf (stderr, "\n");
  • trunk/Ohana/src/opihi/cmd.data/vload.c

    r5702 r5846  
    11# include "data.h"
    2 
    3 # define NPTYPE 3
    4 static char ptype[NPTYPE][8] = {"BOX", "LINE", "CIRCLE"};
    52
    63int vload (int argc, char **argv) {
    74 
    8   int i, N, n, Nline;
    9   int Ximage, Nimage;
     5  int i, N, Noverlay;
     6  int Ximage, Nimage, type;
    107  double dx, dy, size;
    11   char *buffer, *type;
     8  KiiOverlay *overlay;
    129  Vector *vecx, *vecy;
    1310 
     
    2017  if (!GetImage (&Ximage, &Nimage)) return (FALSE);
    2118
    22   type = ptype[0];
     19  type = KII_OVERLAY_BOX;
    2320  if ((N = get_argument (argc, argv, "-type"))) {
    2421    remove_argument (N, &argc, argv);
    25     for (i = 0; i < NPTYPE; i++) {
    26       if (!strcasecmp (argv[N], ptype[i])) {
    27         type = ptype[i];
    28         break;
    29       }
    30     }
    31     if (i == NPTYPE) {
     22    type = KiiOverlayTypeByName (argv[N]);
     23    remove_argument (N, &argc, argv);
     24    if (!type) {
    3225      fprintf (stderr, "unknown Kii point type %s\n", argv[N]);
    3326      return (FALSE);
    3427    }
    35     remove_argument (N, &argc, argv);
    3628  }
    3729
     
    4840  }
    4941 
    50   if (!SelectOverlay (argv[1], &n)) return (FALSE);
     42  if (type == KII_OVERLAY_CIRCLE) {
     43    dx = dy = size / 2;
     44  } else {
     45    dx = dy = size;
     46  }   
    5147
    5248  if ((vecx = SelectVector (argv[2], OLDVECTOR, TRUE)) == NULL) return (FALSE);
     
    5753  }
    5854
    59   ALLOCATE (buffer, char, 65536);  /* space for 512 lines of 128 bytes */
    60   bzero (buffer, 65536);
    61   Nline = 0;
     55  Noverlay = vecx[0].Nelements;
     56  ALLOCATE (overlay, KiiOverlay, Noverlay);
    6257
    63   SendGraphCommand (Ximage, 4, "LOAD");
    64   SendGraphCommand (Ximage, 16, "OVER %9d ", n);
    65 
    66   if (type == ptype[2]) {
    67     dx = dy = size / 2;
    68   } else {
    69     dx = dy = size;
    70   }   
    71   for (i = 0; i < vecx[0].Nelements; i++) {
    72     snprintf (&buffer[Nline*128], 128, "%15s %20.10f %20.10f %20.10f %20.10f ", type,
    73               vecx[0].elements[i]+0.5, vecy[0].elements[i]+0.5, dx, dy);
    74     Nline ++;
    75     if (Nline == 512) {
    76       SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline);
    77       write (Ximage, buffer, Nline*128);
    78       bzero (buffer, 65536);
    79       Nline = 0;
    80     }
     58  for (i = 0; i < Noverlay; i++) {
     59    overlay[i].type = type;
     60    overlay[i].text = NULL;
     61    overlay[i].x = vecx[0].elements[i]+0.5;
     62    overlay[i].y = vecy[0].elements[i]+0.5;
     63    overlay[i].dx = dx;
     64    overlay[i].dy = dy;
    8165  }
    8266
    83   SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline);
    84   write (Ximage, buffer, Nline*128);
    85   SendGraphCommand (Ximage, 16, "DONE");
    86 
    87   free (buffer);
     67  KiiLoadOverlay (Ximage, overlay, Noverlay, argv[1]);
     68  free (overlay);
    8869  return (TRUE);
    8970}
Note: See TracChangeset for help on using the changeset viewer.