IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28003 for branches/pap/Ohana


Ignore:
Timestamp:
May 18, 2010, 12:49:05 PM (16 years ago)
Author:
eugene
Message:

merging changes from trunk into branches/pap

Location:
branches/pap
Files:
2 deleted
57 edited
6 copied

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/Ohana

  • branches/pap/Ohana/src/addstar/src/find_matches_closest_refstars.c

    r27582 r28003  
    159159    /** in replace mode, search for entry and replace values M, dM, R, D */
    160160    // XXX this fails for unsorted catalogs, right?
    161     if (options.replace && replace_match (&catalog[0].average[n], catalog[0].measure, stars[N])) continue;
     161    if (options.replace && replace_match (&catalog[0].average[n], catalog[0].measure, stars[N])) {
     162        i++;
     163        continue;
     164    }
    162165
    163166    /* make sure there is space for next entry */
  • branches/pap/Ohana/src/dvomerge/src/merge_catalogs_old.c

    r27583 r28003  
    1010int merge_catalogs_old (SkyRegion *region, Catalog *output, Catalog *input, double RADIUS) {
    1111
    12   off_t i, j, n, N, Nin, offset, J, Jmin, status, Nstars;
     12  off_t i, j, Nin, offset, J, Jmin, status, Nstars;
    1313  double RADIUS2, Rmin, Rin, Din;
    1414  double *X1, *Y1, *X2, *Y2;
     
    152152    /*** a match is found, add to average, measure ***/
    153153    Nmatch ++;
    154     n = N2[Jmin];
    155     N = N1[i];
     154    off_t n = N2[Jmin];
     155    off_t N = N1[i];
    156156
    157157    /* make sure there is space for next Nmeasure entries */
     
    223223  /* these new entries are all written out in UPDATE mode */
    224224  for (i = 0; i < Nstars; i++) {
     225    off_t N = N1[i];
     226
    225227    /* make sure there is space for next entry */
    226228    if (Nmeas + input[0].average[N].Nmeasure >= NMEAS) {
     
    235237    }
    236238
    237     N = N1[i];
    238239    if (input[0].found[N] >= 0) continue;
    239240    if (!IN_REGION (input[0].average[N].R, input[0].average[N].D)) continue;
  • branches/pap/Ohana/src/getstar/src/MatchCoords.c

    r27435 r28003  
    5454
    5555#ifdef notdef
    56         printf("%d %8.1f %8.1f %s\n", i, x, y, dbImages[i].name);
     56        printf("%ld %8.1f %8.1f %s\n", i, x, y, dbImages[i].name);
    5757#endif
    5858
  • branches/pap/Ohana/src/kapa2/doc/mark.issues.txt

    r25918 r28003  
     1
     2* option to set window margin
     3* option to add section outer box
     4* option to set limits based on associated image (and change dynamically...)
     5o need consistency of graph defaults : axis, tick, labels should come from kapa
     6o clear should erase current plot
     7
    18-> The "plot" command needs to be fixed so that boundaries of contours do
    29not cause it to draw excessive amounts of lines connecting unrelated
    310contours. A specific "contour line type" would be useful.
    4 
    5 -> DVO is not consistently placing the x/y axis labels, especially in
    6 user-defined sections of the plot window.
     11(-pt 100?)
    712
    813-> DVO does not plot the end-points of histograms properly (e.g., the
     
    1318relay output to the file in the same order. Also, until DVO is closed, the
    1419output does not appear in the file.
     20(fixed both issues)
    1521
     22-> DVO is not consistently placing the x/y axis labels, especially in
     23user-defined sections of the plot window.
     24(fixed)
     25* box -labelpad -labelpad[x,y] +labelpad[x,y] -
     26
     27
     28---
     29
     30
     311)You wanted me to remind you to update ~ipp-svn; this was so I could have
     32the latest version of DVO on-hand
     33
     342)The plotting of axis labels remains inconsistent; depending on section
     35dimensions and the presence/absence of tick-marks, labels will change
     36their distance from their corresponding axis. This results in labels
     37falling off the screen or overlapping with other plot sections
     38
     393)Plot section locations in the plot window shift if labels/tick-marks are
     40present or absent
     41
     424)It would be useful to have an option for the box or section command that
     43causes the background to be opaque. This will allow plots to have insets.
     44
     455)It would be useful to have a rectangle plotting command in order to
     46shade out regions on plots
     47
     486)The limits command combined with box will sometimes produce tick-marks
     49with only the zero-point labeled, making the axes difficult to interpret
     50
     517)Text is printed to a file at different times when using either the echo
     52or fprintf commands alongside the output command. Sometimes output is
     53printed to the file immediately, while other times it is printed only when
     54the file is closed for output.
     55
     568)The use of ^C as an interrupt does not always work when a macro is doing
     57for loops.
     58
     599)It would be useful for DVO to echo which line of a macro contains an
     60error, or at which line it was forced to stop. This would help debugging a
     61lot.
     62
     6310)The cgrid could use an option to print RA/DEC tick-mark labels so that
     64image plots would be more informative
  • branches/pap/Ohana/src/kapa2/include/prototypes.h

    r27530 r28003  
    2626
    2727/* X drawing utilities */
    28 void          DrawFrame           PROTO((KapaGraphWidget *graph));
     28int           DrawFrame           PROTO((KapaGraphWidget *graph));
    2929int           DrawObjects         PROTO((KapaGraphWidget *graph));
    3030void          DrawLabels          PROTO((KapaGraphWidget *graph));
     
    3939void          DrawXErrors         PROTO((KapaGraphWidget *graph, Gobjects *objects));
    4040void          DrawYErrors         PROTO((KapaGraphWidget *graph, Gobjects *objects));
    41 void          DrawTick            PROTO((int fx, int fy, int dfx, int dfy, int P, double min, double max, double value, int IsLabel, int IsMajor, int naxis));
     41void          DrawTick            PROTO((Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis));
    4242void          AxisTickScale       PROTO((Axis *axis, double *major, double *minor));
     43TickMarkData *CreateAxisTicks     PROTO((Axis *axis, int *nticks));
    4344
    4445/* EventLoop */
     
    4748int           Reconfig            PROTO((XEvent *event));
    4849void          Refresh             PROTO((void));
     50void          DrawSectionBG       PROTO((Graphic *graphic, Section *section));
    4951
    5052/* CheckPipe */
     
    6163int           SetSection          PROTO((int sock));
    6264int           ListSection         PROTO((int sock));
     65int           SetSectionBG        PROTO((int sock));
    6366int           MoveSection         PROTO((int sock));
    6467int           DefineSection       PROTO((int sock));
     
    8487void          FreeSection         PROTO((Section *section));
    8588void          FreeSections        PROTO((void));
    86 Section      *AddSection          PROTO((char *name, float x, float y, float dx, float dy));
     89Section      *AddSection          PROTO((char *name, float x, float y, float dx, float dy, int bg));
    8790int           DelSection          PROTO((char *name));
    8891int           GetSectionByName    PROTO((char *name));
     
    112115void          PSXErrors           PROTO((KapaGraphWidget *graph, Gobjects *objects, FILE *f));
    113116void          PSYErrors           PROTO((KapaGraphWidget *graph, Gobjects *objects, FILE *f));
    114 void          PSTick              PROTO((FILE *f, double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int IsLabel, int IsMajor, int naxis));
     117void          PSTick              PROTO((Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis, FILE *f));
    115118void          ClipLinePS          PROTO((double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0, FILE *f));
    116119int           PSimage             PROTO((KapaImageWidget *image, FILE *f));
     
    131134void          bDrawXErrors        PROTO((KapaGraphWidget *graph, Gobjects *object));
    132135void          bDrawYErrors        PROTO((KapaGraphWidget *graph, Gobjects *object));
    133 void          bDrawTick           PROTO((double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int IsLabel, int IsMajor, int naxis));
     136void          bDrawTick           PROTO((Axis *axis, int P, TickMarkData *tick, int naxis));
    134137void          bDrawClipLine       PROTO((double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0));
    135138bDrawBuffer  *bDrawIt             PROTO((void));
  • branches/pap/Ohana/src/kapa2/include/structures.h

    r25757 r28003  
    137137  double min, max;
    138138  char isaxis, areticks, islabel, islog;
     139  double pad, labelPad, ticktextPad;
    139140  double fx, dfx, fy, dfy;  /* axis location on graphic */
    140141  double lweight;
    141142  int color;
    142143} Axis;
     144
     145// structure to describe the ticks for an axis
     146typedef struct {
     147  double value;
     148  int IsMajor;
     149  int IsLabel;
     150} TickMarkData;
    143151
    144152// a single graph in the display window
     
    210218  float  x,  y;
    211219  float dx, dy;
     220  int bg;
    212221  char *name;
    213222} Section;
  • branches/pap/Ohana/src/kapa2/src/CheckPipe.c

    r25757 r28003  
    221221  }
    222222 
     223  if (!strcmp (word, "BSEC")) {
     224    status = SetSectionBG (sock);
     225    KiiSendCommand (sock, 4, "DONE");
     226    FINISHED (TRUE);
     227  }
     228 
    223229  if (!strcmp (word, "FONT")) {
    224230    status = SetFont (sock);
  • branches/pap/Ohana/src/kapa2/src/DefineSection.c

    r21153 r28003  
    44int DefineSection (int sock) {
    55 
    6   int N, MoveSection;
     6  int N, MoveSection, bg;
    77  char name[128];
    88  double x, y, dx, dy;
    99  Section *section;
    1010
    11   KiiScanMessage (sock, "%s %lf %lf %lf %lf", name, &x, &y, &dx, &dy);
     11  KiiScanMessage (sock, "%s %lf %lf %lf %lf %d", name, &x, &y, &dx, &dy, &bg);
    1212
    1313  MoveSection = FALSE;
     
    1515  N = GetSectionByName (name);
    1616  if (N < 0) {
    17     section = AddSection (name, x, y, dx, dy);
     17    section = AddSection (name, x, y, dx, dy, bg);
    1818    MoveSection = TRUE;
    1919  } else {
     
    3030    section[0].dx = dx;
    3131    section[0].dy = dy;
     32    section[0].bg = bg;
    3233  }
    3334
  • branches/pap/Ohana/src/kapa2/src/DrawFrame.c

    r27603 r28003  
    11# include "Ximage.h"
    2 # define MIN_RANGE 1e-10
     2
    33# define DrawLine(X,Y,DX,DY) (XDrawLine (graphic->display, graphic->window, graphic->gc, (int)(X), (int)(Y), (int)(X+DX), (int)(Y+DY)))
    44 
    5 static Graphic *graphic;
    6 
    7 void DrawFrame (KapaGraphWidget *graph) {
    8  
    9   int i, fx, fy, dfx, dfy, P, IsLabel, IsMajor;
    10   double range, major, minor, first, next, lweight;
     5int DrawFrame (KapaGraphWidget *graph) {
     6 
     7  int i, j, Nticks, P;
     8  double fx, fy, dfx, dfy, lweight;
     9  Graphic *graphic;
     10  TickMarkData *ticks;
     11  int color;
    1112
    1213  graphic = GetGraphic();
    1314
    14   /* each axis is drawn independently, but ticks and labels are placed according to
    15      perpendicular distance. */
     15  /* each axis is drawn independently, but ticks and labels are placed according to perpendicular distance. */
    1616  for (i = 0; i < 4; i++) {
    17     fx = graph[0].axis[i].fx;
    18     fy = graph[0].axis[i].fy;
     17    fx  = graph[0].axis[i].fx;
     18    fy  = graph[0].axis[i].fy;
    1919    dfx = graph[0].axis[i].dfx;
    2020    dfy = graph[0].axis[i].dfy;
    21     P = hypot ((double)graph[0].axis[(i+1)%2].dfx, (double)graph[0].axis[(i+1)%2].dfy);
     21    P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
    2222
    2323    lweight = MAX (0, MIN (10, graph[0].axis[i].lweight));
     24    color = MAX (0, MIN (15, graph[0].axis[i].color));
     25
    2426    XSetLineAttributes (graphic->display, graphic->gc, lweight, LineSolid, CapNotLast, JoinMiter);
    25    
    26     graph[0].axis[i].color = MAX (0, MIN (15, graph[0].axis[i].color));
    27 
    28     XSetForeground (graphic->display, graphic->gc, graphic->color[graph[0].axis[i].color]);
    29     DrawRotTextInit (graphic->display, graphic->window, graphic->gc, graphic->color[graph[0].axis[i].color], graphic->back);
    30 
    31     // fprintf (stderr, "axis: %d, color: %d, %ld, weight: %f\n", i, graph[0].axis[i].color, graphic->color[graph[0].axis[i].color], lweight);
     27    XSetForeground (graphic->display, graphic->gc, graphic->color[color]);
     28    DrawRotTextInit (graphic->display, graphic->window, graphic->gc, graphic->color[color], graphic->back);
    3229
    3330    if (graph[0].axis[i].isaxis) {
    3431      DrawLine (fx, fy, dfx, dfy);
    35       // fprintf (stderr, "%d : %d %d - %d %d\n", i, fx, fy, dfx, dfy);
    36       // if (i == 0) {
    37       //        int j;
    38       //        for (j = fx; j < fx + dfx; j+= 10) {
    39       //          DrawLine (j, fy-10, 0, 20);
    40       //        }
    41       // }
    4232    }
    4333   
    4434    if (graph[0].axis[i].areticks) {
    45       if (isnan(graph[0].axis[i].min) || isinf(graph[0].axis[i].min)) continue;
    46       if (isnan(graph[0].axis[i].max) || isinf(graph[0].axis[i].max)) continue;
    47 
    48       range = graph[0].axis[i].max - graph[0].axis[i].min;
    49       if (fabs(range) < MIN_RANGE) continue;
    50 
    51       if (fabs(range) < MIN_RANGE) {
    52         range = (range < 0) ? -MIN_RANGE : +MIN_RANGE;
     35      ticks = CreateAxisTicks (&graph[0].axis[i], &Nticks);
     36      for (j = 0; j < Nticks; j++) {
     37        DrawTick (graphic, &graph[0].axis[i], P, &ticks[j], i);
    5338      }
    54 
    55       AxisTickScale (&graph[0].axis[i], &major, &minor);
    56 
    57       first = minor*((int)(graph[0].axis[i].min/minor));
    58       if ((range > 0) && (first < graph[0].axis[i].min)) {
    59         first += minor;
    60       }
    61       if ((range < 0) && (first > graph[0].axis[i].min)) {
    62         first -= minor;
    63       }
    64       for (next = first; ((range > 0) && (next <= graph[0].axis[i].max)) || ((range < 0) && (next >= graph[0].axis[i].max));) {
    65         IsMajor = FALSE;
    66         IsMajor |= (fabs((int)(next/major) - (next/major)) < 0.5*(minor/major));
    67         IsMajor |= (fabs((int)((next + 0.5*minor)/major) - (next/major)) < 0.5*(minor/major));
    68         IsMajor |= (fabs ((int)((next - 0.5*minor)/major) - (next/major)) < 0.5*(minor/major));
    69         IsLabel = (IsMajor && graph[0].axis[i].islabel);
    70         DrawTick (fx, fy, dfx, dfy, P, graph[0].axis[i].min, graph[0].axis[i].max, next, IsLabel, IsMajor, i);
    71         if (range > 0)
    72           next += minor;
    73         else
    74           next -= minor;
    75       }
     39      FREE (ticks);
    7640    }
    7741  }
    78 }
    79 
    80 void DrawTick (int fx, int fy, int dfx, int dfy,
    81                int P, double min, double max,
    82                double value, int IsLabel, int IsMajor, int naxis) {
    83  
    84   int x, y, dx, dy, pos, dir, fontsize;
    85   double size, n;
     42  return (TRUE);
     43}
     44
     45void DrawTick (Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis) {
     46 
     47  double x, y, dx, dy;
     48  int pos, dir, fontsize;
     49  double size, n, pad;
    8650  char string[64], *fontname;
    8751
    88   if (IsMajor) {
     52  double fx  = axis->fx;
     53  double fy  = axis->fy;
     54  double dfx = axis->dfx;
     55  double dfy = axis->dfy;
     56
     57  double min = axis->min;
     58  double max = axis->max;
     59
     60  double value = tick->value;
     61
     62  pos = size = 0;
     63
     64  if (tick->IsMajor) {
    8965    size = MAX (0.02, 7.0 / P);
    9066  } else {
     
    9268  }
    9369 
    94   n = P / sqrt ((double)(dfx*dfx + dfy*dfy));
     70  n = P / hypot(dfx, dfy);
    9571  x = fx + (value-min)*dfx/(max - min);
    9672  y = fy + (value-min)*dfy/(max - min);
    9773
    98   dir = +1;
    99   if ((naxis == 0) || (naxis == 1)) dir *= -1;
     74  if ((naxis == 0) || (naxis == 2)) {
     75    x = MAX(x, fx);
     76  }
     77  //   y = MAX(y, fy);
     78  // }
     79
     80  dir = ((naxis == 0) || (naxis == 1)) ? -1 : +1;
    10081  dx = dir*size*dfy*n; 
    10182  dy = dir*size*dfx*n;
     
    10384  DrawLine (x, y, dx, dy);
    10485
    105 # ifdef IN_AND_OUT_TICKS
    106 # define GAP 0.03
    107 # else
    108 # define GAP 0.01
    109 # endif
    110 
    111   if (IsLabel) {
     86  if (tick->IsLabel) {
     87    int xt, yt;
     88
    11289    fontname = GetRotFont (&fontsize);
    113     pos = 0;
     90   
     91    pad = !isnan(axis->ticktextPad) ? axis->ticktextPad*fontsize : fontsize + 4.0;
     92    // pad = !isnan(axis->ticktextPad) ? axis->ticktextPad*fontsize : 0.8*fontsize + 1.0;
    11493   
    11594    /* temporarily assume rectilinear axes */
    116     if (naxis == 0) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 1; }
    117     if (naxis == 2) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 7; }
    118 
    119     if (naxis == 1) { dy = 0; dx = -(0.8*fontsize + 1); pos = 3; }
    120     if (naxis == 3) { dy = 0; dx = +(0.8*fontsize + 1); pos = 5; }
    121 
    122     x = fx + (value-min)*dfx/(max - min) + dx;
    123     y = fy + (value-min)*dfy/(max - min) + dy;
     95    if (naxis == 0) { dx = 0; dy = +1.0*pad; pos = 7; }
     96    if (naxis == 2) { dx = 0; dy = -1.0*pad; pos = 1; }
     97
     98    if (naxis == 1) { dy = 0; dx = -0.5*pad; pos = 3; }
     99    if (naxis == 3) { dy = 0; dx = +0.5*pad; pos = 5; }
     100
     101    xt = fx + (value-min)*dfx/(max - min) + dx;
     102    yt = fy + (value-min)*dfy/(max - min) + dy;
    124103    if (fabs(value/(max-min)) < 0.001) { value = 0.0; }
    125104    sprintf (string, "%4g", value);
    126     DrawRotText (x, y, string, pos, 0.0);
    127   }
    128  
    129 }
    130 
     105    DrawRotText (xt, yt, string, pos, 0.0);
     106  }
     107}
     108
     109# define MIN_RANGE 1e-10
    131110
    132111void AxisTickScale (Axis *axis, double *major, double *minor) {
     
    192171  }
    193172}
     173
     174TickMarkData *CreateAxisTicks (Axis *axis, int *nticks) {
     175
     176  TickMarkData *ticks;
     177  double range, major, minor, first, value, dPixels, overshoot;
     178  int i, NTICKS, nPixels, done, ifirst;
     179
     180  *nticks = 0;
     181
     182  if (isnan(axis->min) || isinf(axis->min)) return NULL;
     183  if (isnan(axis->max) || isinf(axis->max)) return NULL;
     184 
     185  range = axis->max - axis->min;
     186
     187  // not sure why I skip out here instead of using the MIN_RANGE value
     188  if (fabs(range) < MIN_RANGE) return NULL;
     189 
     190  if (fabs(range) < MIN_RANGE) {
     191    range = (range < 0) ? -MIN_RANGE : +MIN_RANGE;
     192  }
     193
     194  // length of the axis in pixels
     195  nPixels = hypot(axis->dfx, axis->dfy);
     196  dPixels = nPixels / range; // axis pixel-scale
     197
     198  AxisTickScale (axis, &major, &minor);
     199
     200  // be a little generous
     201  NTICKS = (int)(fabs(range / minor)) + 2;
     202  ALLOCATE (ticks, TickMarkData, NTICKS);
     203
     204  // value of the tick mark
     205  ifirst = (axis->min < 0.0) ? (axis->min/minor - 0.05) : (axis->min/minor + 0.05);
     206  first = minor*ifirst;
     207 
     208  // allow undershoot by 1 pixel
     209  overshoot = (axis->min - first) * dPixels;
     210  // if (overshoot > 0.5) {
     211  //   if (range > 0) {
     212  //     first += minor;
     213  //   } else {
     214  //     first -= minor;
     215  //   }
     216  // }
     217
     218  // loop to find the ticks
     219  done = FALSE;
     220  value = first;
     221  for (i = 0; !done && (i < NTICKS); i++) {
     222    ticks[i].IsMajor = FALSE;
     223    ticks[i].IsMajor |= (fabs((int)(value/major) - (value/major)) < 0.5*(minor/major));
     224    ticks[i].IsMajor |= (fabs((int)((value + 0.5*minor)/major) - (value/major)) < 0.5*(minor/major));
     225    ticks[i].IsMajor |= (fabs((int)((value - 0.5*minor)/major) - (value/major)) < 0.5*(minor/major));
     226    ticks[i].IsLabel = (ticks[i].IsMajor && axis->islabel);
     227    ticks[i].value = value;
     228    if (range > 0)
     229      value += minor;
     230    else
     231      value -= minor;
     232   
     233    done |= (range > 0) && (value > axis->max);
     234    done |= (range < 0) && (value < axis->max);
     235  }
     236
     237  *nticks = i;
     238  return (ticks);
     239}
  • branches/pap/Ohana/src/kapa2/src/DrawLabels.c

    r17466 r28003  
    3434      switch (i) {
    3535      case 0: pos = 7; break;
     36      case 2: pos = 1; break;
    3637      case 1: pos = 1; angle = -90; break;
    37       case 2: pos = 1; break;
    3838      case 3: pos = 1; angle =  90; break;
    3939      case 4: pos = 2; break;
  • branches/pap/Ohana/src/kapa2/src/EraseSections.c

    r21153 r28003  
    88 
    99  FreeSections ();
    10   AddSection ("default", 0.0, 0.0, 1.0, 1.0);
     10  AddSection ("default", 0.0, 0.0, 1.0, 1.0, -1);
    1111
    1212  if (USE_XWINDOW) XClearWindow (graphic->display, graphic->window);
  • branches/pap/Ohana/src/kapa2/src/Graphs.c

    r27530 r28003  
    1818    graph[0].axis[i].lweight = 0.0;
    1919    graph[0].axis[i].color = 0;
     20    graph[0].axis[i].ticktextPad = NAN;
     21    graph[0].axis[i].labelPad = NAN;
     22    graph[0].axis[i].pad = NAN;
    2023  }   
     24  graph[0].data.ticktextPad = NAN;
     25
     26  graph[0].data.labelPadXm = NAN;
     27  graph[0].data.labelPadXp = NAN;
     28  graph[0].data.labelPadYm = NAN;
     29  graph[0].data.labelPadYp = NAN;
     30
     31  graph[0].data.padXm = NAN;
     32  graph[0].data.padXp = NAN;
     33  graph[0].data.padYm = NAN;
     34  graph[0].data.padYp = NAN;
     35
    2136  for (i = 0; i < 8; i++) {
    2237    strcpy (graph[0].label[i].text, "");
     
    3752  graph[0].data.size    = 1.0;          // point size of 1.0
    3853
    39   graph[0].data.flipeast  = 1;          // +East  = -X by default
    40   graph[0].data.flipnorth = 0;          // +North = +Y by default
     54  graph[0].data.flipeast = TRUE;        // +East  = -X by default
     55  graph[0].data.flipnorth = FALSE;      // +North = +Y by default
     56
     57  graph[0].data.coords.pc1_1 = graph[0].data.coords.pc2_2 = 1.0;
     58  graph[0].data.coords.pc1_2 = graph[0].data.coords.pc2_1 = 0.0;
     59  graph[0].data.coords.crval1 = 0.0;
     60  graph[0].data.coords.crval2 = 0.0;
     61  graph[0].data.coords.crpix1 = 0.0;
     62  graph[0].data.coords.crpix2 = 0.0;
     63  graph[0].data.coords.cdelt1 = graph[0].data.coords.cdelt2 = 1.0;
     64  strcpy (graph[0].data.coords.ctype, "RA---LIN");
     65  strcpy (graph[0].data.axis, "2222");
     66  strcpy (graph[0].data.ticks, "2222");
     67  strcpy (graph[0].data.labels, "2222");
    4168
    4269  graph[0].Nobjects = 0;
  • branches/pap/Ohana/src/kapa2/src/Layout.c

    r14737 r28003  
    4343
    4444  /* create basic section, empty of image or graph */
    45   section = AddSection ("default", 0.0, 0.0, 1.0, 1.0);
     45  section = AddSection ("default", 0.0, 0.0, 1.0, 1.0, -1);
    4646}
  • branches/pap/Ohana/src/kapa2/src/LoadFrame.c

    r21153 r28003  
    33int LoadFrame (int sock) {
    44 
    5   int i, color;
    6   char Axis[16], Labels[16], Ticks[16];
    7   double lweight;
     5  int i;
    86  Section *section;
    97  KapaGraphWidget *graph;
     
    1614  graph = section->graph;
    1715
    18   KiiScanMessage (sock, "%lf %lf %lf %lf",
    19                   &graph[0].axis[0].min, &graph[0].axis[0].max,
    20                   &graph[0].axis[1].min, &graph[0].axis[1].max);
     16  KapaScanGraphData (sock, &graph[0].data);
    2117
    2218  graph[0].axis[3].min = graph[0].axis[1].min;
     
    2521  graph[0].axis[2].max = graph[0].axis[0].max;
    2622 
    27   KiiScanMessage (sock, "%lf %d", &lweight, &color);
    28   color = MAX (0, MIN (15, color));
     23  // XXX this is fragile
     24  graph[0].data.color = MAX (0, MIN (15, graph[0].data.color));
    2925
    30   KiiScanMessage (sock, "%s %s %s", Axis, Labels, Ticks);
     26  graph[0].axis[0].pad = graph[0].data.padXm;
     27  graph[0].axis[1].pad = graph[0].data.padYm;
     28  graph[0].axis[2].pad = graph[0].data.padXp;
     29  graph[0].axis[3].pad = graph[0].data.padYp;
     30
     31  graph[0].axis[0].labelPad = graph[0].data.labelPadXm;
     32  graph[0].axis[1].labelPad = graph[0].data.labelPadYm;
     33  graph[0].axis[2].labelPad = graph[0].data.labelPadXp;
     34  graph[0].axis[3].labelPad = graph[0].data.labelPadYp;
    3135
    3236  for (i = 0; i < 4; i++) {
    33     graph[0].axis[i].lweight = lweight;
    34     graph[0].axis[i].color = color;
     37    graph[0].axis[i].lweight = graph[0].data.lweight;
     38    graph[0].axis[i].color = graph[0].data.color;
    3539
    36     switch (Axis[i]) {
     40    graph[0].axis[i].ticktextPad = graph[0].data.ticktextPad;
     41
     42    switch (graph[0].data.axis[i]) {
    3743    case '0':
    3844      graph[0].axis[i].isaxis = FALSE;
     
    4551      break;
    4652    }
    47     switch (Ticks[i]) {
     53    switch (graph[0].data.ticks[i]) {
    4854    case '0':
    4955      graph[0].axis[i].areticks = FALSE;
     
    5662      break;
    5763    }
    58     switch (Labels[i]) {
     64    switch (graph[0].data.labels[i]) {
    5965    case '0':
    6066      graph[0].axis[i].islabel = FALSE;
     
    7076
    7177  SetSectionSizes (section);
    72   if (USE_XWINDOW) DrawFrame (graph);
    73   FlushDisplay ();
     78  Refresh();
     79  // if (USE_XWINDOW) DrawFrame (graph);
     80  // FlushDisplay ();
    7481
    7582  /* XXX why did I do this??? */
  • branches/pap/Ohana/src/kapa2/src/PSFrame.c

    r19834 r28003  
    44int PSFrame (KapaGraphWidget *graph, FILE *f) {
    55 
    6   int i, P, IsLabel, IsMajor, fontsize;
    7   double fx, fy, dfx, dfy, range, major, minor, first, next;
    8   char *fontname;
     6  int i, Nticks, P;
     7  double fx, fy, dfx, dfy, lweight;
    98  Graphic *graphic;
    10   float weight;
     9  TickMarkData *ticks;
    1110  bDrawColor color;
    1211
     
    1413
    1514  /* each axis is drawn independently */
    16   fontname = GetRotFont (&fontsize);
    1715  fprintf (f, "1 setlinewidth\n");
    1816  for (i = 0; i < 4; i++) {
    19     fx = graph[0].axis[i].fx;
    20     fy = graphic->dy - graph[0].axis[i].fy;
     17    fx  = graph[0].axis[i].fx;
     18    fy  = graphic->dy - graph[0].axis[i].fy;
    2119    dfx = graph[0].axis[i].dfx;
    2220    dfy = -graph[0].axis[i].dfy;
    23     P = hypot ((double)graph[0].axis[(i+1)%2].dfx, (double)graph[0].axis[(i+1)%2].dfy);
     21    P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
    2422
    25     weight = MAX (0, MIN (10, graph[0].axis[i].lweight));
     23    lweight = MAX (0, MIN (10, graph[0].axis[i].lweight));
    2624    color = MAX (0, MIN (15, graph[0].axis[i].color));
    27     fprintf (f, "%.1f setlinewidth\n", weight);
     25
     26    fprintf (f, "%.1f setlinewidth\n", lweight);
    2827    fprintf (f, "%s setrgbcolor\n", KapaColorRGBString(color));
     28    // no need to init rot font
    2929
    30     if (graph[0].axis[i].isaxis) { DrawLine (fx, fy, dfx, dfy); }
     30    if (graph[0].axis[i].isaxis) {
     31      DrawLine (fx, fy, dfx, dfy);
     32    }
    3133   
    3234    if (graph[0].axis[i].areticks) {
    33       if (isnan(graph[0].axis[i].min) || isinf(graph[0].axis[i].min)) continue;
    34       if (isnan(graph[0].axis[i].max) || isinf(graph[0].axis[i].max)) continue;
    35 
    36       range = graph[0].axis[i].max - graph[0].axis[i].min;
    37       AxisTickScale (&graph[0].axis[i], &major, &minor);
    38 
    39       first = minor*((int)(graph[0].axis[i].min/minor));
    40       if ((range > 0) && (first < graph[0].axis[i].min)) {
    41         first += minor;
     35      ticks = CreateAxisTicks (&graph[0].axis[i], &Nticks);
     36      for (i = 0; i < Nticks; i++) {
     37        PSTick (graphic, &graph[0].axis[i], P, &ticks[i], i, f);
    4238      }
    43       if ((range < 0) && (first > graph[0].axis[i].min)) {
    44         first -= minor;
    45       }
    46       for (next = first; ((range > 0) && (next <= graph[0].axis[i].max)) || ((range < 0) && (next >= graph[0].axis[i].max));) {
    47         IsMajor = FALSE;
    48         IsMajor |= (fabs((int)(next/major) - (next/major)) < 0.5*(minor/major));
    49         IsMajor |= (fabs ((int)((next + 0.5*minor)/major) - (next/major)) < 0.5*(minor/major));
    50         IsMajor |= (fabs ((int)((next - 0.5*minor)/major) - (next/major)) < 0.5*(minor/major));
    51         IsLabel = (IsMajor && graph[0].axis[i].islabel);
    52         PSTick (f, fx, fy, dfx, dfy, P, graph[0].axis[i].min, graph[0].axis[i].max, next, IsLabel, IsMajor, i);
    53         if (range > 0)
    54           next += minor;
    55         else
    56           next -= minor;
    57       }
    58     }
     39      FREE (ticks);
     40    }     
    5941  }
    6042  return (TRUE);
    6143}
    6244
    63 void PSTick (FILE *f, double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int IsLabel, int IsMajor, int naxis) {
     45void PSTick (Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis, FILE *f) {
    6446 
     47  double x, y, dx, dy;
    6548  int pos, dir, fontsize;
    66   double size, n, x, y, dx, dy;
     49  double size, n, pad;
    6750  char string[64], *fontname;
     51
     52  double fx  = axis->fx;
     53  double fy  = graphic->dy - axis->fy;
     54  double dfx = axis->dfx;
     55  double dfy = -axis->dfy;
     56
     57  double min = axis->min;
     58  double max = axis->max;
     59
     60  double value = tick->value;
    6861
    6962  pos = size = 0;
    7063
    71   if (IsMajor) {
     64  if (tick->IsMajor) {
    7265    size = MAX (0.02, 7.0 / P);
    7366  } else {
     
    7568  }
    7669 
    77   n = P / sqrt ((double)(dfx*dfx + dfy*dfy));
     70  n = P / hypot(dfx, dfy);
    7871  x = fx + (value-min)*dfx/(max - min);
    7972  y = fy + (value-min)*dfy/(max - min);
    8073
    81   dir = -1;
    82   if ((naxis == 0) || (naxis == 1)) dir *= -1;
     74  dir = ((naxis == 0) || (naxis == 1)) ? -1 : +1;
    8375  dx = dir*size*dfy*n; 
    8476  dy = dir*size*dfx*n;
     
    8678  DrawLine (x, y, dx, dy);
    8779
    88   if (IsLabel) {
     80  if (tick->IsLabel) {
     81    int xt, yt;
     82
    8983    fontname = GetRotFont (&fontsize);
    9084
     85    pad = !isnan(axis->ticktextPad) ? axis->ticktextPad*fontsize : 0.8*fontsize + 1.0;
     86   
    9187    /* temporarily assume rectilinear axes */
    92     if (naxis == 0) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 1; }
    93     if (naxis == 2) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 7; }
     88    if (naxis == 0) { dx = 0; dy = +pad; pos = 1; }
     89    if (naxis == 2) { dx = 0; dy = -pad; pos = 7; }
    9490
    95     if (naxis == 1) { dy = 0; dx = -(0.8*fontsize + 1); pos = 3; }
    96     if (naxis == 3) { dy = 0; dx = +(0.8*fontsize + 1); pos = 5; }
     91    if (naxis == 1) { dy = 0; dx = -pad; pos = 3; }
     92    if (naxis == 3) { dy = 0; dx = +pad; pos = 5; }
    9793
    98     x = fx + (value-min)*dfx/(max - min) + dx;
    99     y = fy + (value-min)*dfy/(max - min) + dy;
    100     if (fabs(value) < 1e-14) { value = 0.0; }
    101     sprintf (string, "%g", value);
    102     PSRotText (f, (int)x, (int)y, string, pos, 0.0);
     94    xt = fx + (value-min)*dfx/(max - min) + dx;
     95    yt = fy + (value-min)*dfy/(max - min) + dy;
     96    if (fabs(value) < 0.001) { value = 0.0; }
     97    sprintf (string, "%4g", value);
     98    PSRotText (f, xt, yt, string, pos, 0.0);
    10399  }
    104100}
  • branches/pap/Ohana/src/kapa2/src/Refresh.c

    r21153 r28003  
    2121  for (i = 0; i < Nsection; i++) {
    2222      section = GetSectionByNumber (i);
     23      DrawSectionBG (graphic, section);
    2324      DrawImage (section->image);
    2425      DrawGraph (section->graph);
     
    2829}
    2930
     31void DrawSectionBG (Graphic *graphic, Section *section) {
     32
     33  int Ncolors;
     34  int X0, Y0, dX, dY;
     35
     36  if (section->bg == -1) return;
     37
     38  Ncolors = KapaColormapSize();
     39
     40  if (section->bg < 0) return;
     41  if (section->bg >= Ncolors) return;
     42
     43  XSetForeground (graphic->display, graphic->gc, graphic->color[section->bg]);
     44
     45  dY = graphic[0].dy * section[0].dy;
     46  dX = graphic[0].dx * section[0].dx;
     47  Y0 = graphic[0].dy - graphic[0].dy * section[0].y - dY;
     48  X0 = graphic[0].dx * section[0].x;
     49  // fprintf (stderr, "section: (%s) %d %d - %d %d\n", section[0].name, X0, Y0, dX, dY);
     50
     51  XFillRectangle (graphic[0].display,  graphic[0].window, graphic[0].gc, X0, Y0, dX, dY);
     52  return;
     53}
  • branches/pap/Ohana/src/kapa2/src/Sections.c

    r21153 r28003  
    1616  section[0].dx = 0;
    1717  section[0].dy = 0;
     18  section[0].bg = -1;
    1819
    1920  section[0].name = NULL;
     
    4243}
    4344
    44 Section *AddSection (char *name, float x, float y, float dx, float dy) {
     45Section *AddSection (char *name, float x, float y, float dx, float dy, int bg) {
    4546
    4647  int N;
     
    6162  sections[N][0].dx = dx;
    6263  sections[N][0].dy = dy;
     64  sections[N][0].bg = bg;
    6365  ActiveSection = N;
    6466  return (sections[N]);
     
    155157}
    156158
     159int SetSectionBG (int sock) {
     160
     161  int N, background;
     162  char name[128];
     163
     164  KiiScanMessage (sock, "%s %d", name, &background);
     165 
     166  N = GetSectionByName (name);
     167  if (N < 0) {
     168    fprintf (stderr, "section %s not found\n", name);
     169    return (TRUE);
     170  }
     171
     172  sections[N][0].bg = background;
     173
     174  return (TRUE);
     175}
     176
    157177// return TRUE even for nonsense cases to avoid quitting kapa
    158178int MoveSection (int sock) {
  • branches/pap/Ohana/src/kapa2/src/SetGraphData.c

    r21153 r28003  
    1818  graph = section->graph;
    1919 
    20   // get graph data from client
    21   KiiScanMessage (sock, "%d %d %d %d %d %d %lf %lf",
    22                   &graph[0].data.style,
    23                   &graph[0].data.ptype,
    24                   &graph[0].data.ltype,
    25                   &graph[0].data.etype,
    26                   &graph[0].data.ebar,
    27                   &graph[0].data.color,
    28                   &graph[0].data.lweight,
    29                   &graph[0].data.size);
     20  KapaScanGraphData (sock, &graph[0].data);
    3021
    31   KiiScanMessage (sock, "%lf %lf %lf %lf",
    32                   &graph[0].data.xmin,
    33                   &graph[0].data.xmax,
    34                   &graph[0].data.ymin,
    35                   &graph[0].data.ymax);
     22  for (i = 0; i < 4; i++) {
     23    graph[0].axis[i].ticktextPad = graph[0].data.ticktextPad;
     24  }   
     25  graph[0].axis[0].labelPad = graph[0].data.labelPadXm;
     26  graph[0].axis[1].labelPad = graph[0].data.labelPadYm;
     27  graph[0].axis[2].labelPad = graph[0].data.labelPadXp;
     28  graph[0].axis[3].labelPad = graph[0].data.labelPadYp;
    3629
    37   KiiScanMessage (sock, "%f %f %f %f",
    38                   &graph[0].data.coords.pc1_1, &graph[0].data.coords.pc2_2,
    39                   &graph[0].data.coords.pc1_2, &graph[0].data.coords.pc2_1);
    40 
    41   KiiScanMessage (sock, "%d %d %s",
    42                   &graph[0].data.flipeast, &graph[0].data.flipnorth,
    43                   graph[0].data.coords.ctype);
    44 
    45   KiiScanMessage (sock, "%lf %lf %f %f %f %f",
    46                   &graph[0].data.coords.crval1,
    47                   &graph[0].data.coords.crval2,
    48                   &graph[0].data.coords.crpix1,
    49                   &graph[0].data.coords.crpix2,
    50                   &graph[0].data.coords.cdelt1,
    51                   &graph[0].data.coords.cdelt2);
    52 
    53 
     30  graph[0].axis[0].pad = graph[0].data.padXm;
     31  graph[0].axis[1].pad = graph[0].data.padYm;
     32  graph[0].axis[2].pad = graph[0].data.padXp;
     33  graph[0].axis[3].pad = graph[0].data.padYp;
    5434
    5535  xmin = graph[0].data.xmin;
     
    9070  graph = section->graph;
    9171
    92   KiiSendMessage (sock, "%8d %d %d %d %d %d %f %f",
    93                   graph[0].data.style,
    94                   graph[0].data.ptype, graph[0].data.ltype,
    95                   graph[0].data.etype, graph[0].data.ebar, graph[0].data.color,
    96                   graph[0].data.lweight, graph[0].data.size);
    97 
    98   KiiSendMessage (sock, "%g %g %g %g",
    99                   graph[0].data.xmin, graph[0].data.xmax,
    100                   graph[0].data.ymin, graph[0].data.ymax);
    101 
    102   KiiSendMessage (sock, "%g %g %g %g",
    103                   graph[0].data.coords.pc1_1, graph[0].data.coords.pc2_2,
    104                   graph[0].data.coords.pc1_2, graph[0].data.coords.pc2_1);
    105 
    106   KiiSendMessage (sock, "%d %d %s",
    107                   graph[0].data.flipeast, graph[0].data.flipnorth,
    108                   graph[0].data.coords.ctype);
    109 
    110   KiiSendMessage (sock, "%g %g %g %g %g %g",
    111                   graph[0].data.coords.crval1,
    112                   graph[0].data.coords.crval2,
    113                   graph[0].data.coords.crpix1,
    114                   graph[0].data.coords.crpix2,
    115                   graph[0].data.coords.cdelt1,
    116                   graph[0].data.coords.cdelt2);
     72  KapaSendGraphData (sock, &graph[0].data);
    11773
    11874  return (TRUE);
  • branches/pap/Ohana/src/kapa2/src/SetGraphSize.c

    r16011 r28003  
    66void SetGraphSize (Section *section) {
    77
    8   int fontsize, bump, Nc;
    9   int textpad, textdY, WdY;
    10   double PADx, PADy, Dx, Dy;
    11   double PXm, PXp, PYm, PYp;
     8  int i, Nticks;
     9  int fontsize, Nc = 0;
     10  int textpad, textdY, WdY;
     11  int dXm, dXp, dYm, dYp;
     12  double padXm, padXp, padYm, padYp;
     13  double minPADx, maxPADx, minPADy;
     14  double minPAD, maxPAD;
    1215  double X0, Y0, dX, dY;
    1316  char string[64], *fontname;
    1417  KapaGraphWidget *graph;
    1518  Graphic *graphic;
     19  TickMarkData *ticks;
    1620
    1721  if (section == NULL) return;
     
    2226  fontname = GetRotFont (&fontsize);
    2327
    24   PADx = MAX (graphic->dx / 20.0, fontsize);
    25   PADy = MAX (graphic->dy / 20.0, fontsize);
    26   Dx = graphic->dx - 2*PADx;
    27   Dy = graphic->dy - 2*PADy;
     28  minPAD = 1.0*fontsize + 0;
     29  maxPAD = 2.0*fontsize + 4;
    2830
    29   /* each graph has a padding PXm, PXp, PYm, PYp */
    30   PXm = (graph[0].axis[1].islabel) ? 4*fontsize : 0;
    31   PXp = (graph[0].axis[3].islabel) ? 4*fontsize : 0;
    32   PYm = (graph[0].axis[0].islabel) ? 4*fontsize : 0;
    33   PYp = (graph[0].axis[2].islabel) ? 4*fontsize : 0;
    34  
     31  minPADx = 1.5*fontsize;
     32  maxPADx = 2.5*fontsize + 4.0;
     33
     34  minPADy = 1.5*fontsize;
     35
     36  // dXm : offset to label from lower x-axis, dYp : offset to label from right y-axis, etc
     37  // padXm : padding below x-axis, padYp : padding to right of y-axis, etc
     38
     39  // offset from lower x-axis to labels and tick values
     40  // these depend on (a) existence of tick labels and (b) auto-offset or not
     41  if (isnan(graph[0].axis[0].labelPad)) {
     42    dXm = (graph[0].axis[0].islabel) ? maxPAD  : minPAD;
     43  } else {
     44    dXm = graph[0].axis[0].labelPad * fontsize;
     45  }
     46  if (isnan(graph[0].axis[0].pad)) {
     47    padXm = graph[0].axis[0].islabel ? maxPADx : minPADx;
     48  } else {
     49    padXm = graph[0].axis[0].pad * fontsize;
     50  }
     51
     52  // offset from upper x-axis to labels and tick values
     53  // these depend on (a) existence of tick labels and (b) auto-offset or not
     54  if (isnan(graph[0].axis[2].labelPad)) {
     55    dXp = (graph[0].axis[2].islabel) ? maxPAD : minPAD;
     56  } else {
     57    dXp = graph[0].axis[2].labelPad * fontsize;
     58  }
     59  if (isnan(graph[0].axis[2].pad)) {
     60    padXp = graph[0].axis[2].islabel ? maxPADx : minPADx;
     61  } else {
     62    padXp = graph[0].axis[2].pad * fontsize;
     63  }
     64
     65  // offset from left y-axis to labels and tick values
     66  // these depend on (a) existence of tick labels and (b) auto-offset or not.
     67  // in the auto-offset case, offset depends on the width of the tick label strings
     68  if (graph[0].axis[1].islabel && (isnan(graph[0].axis[1].labelPad) || isnan(graph[0].axis[1].pad))) {
     69    /* check for the max size of the axis label */
     70    Nc = 0;
     71    ticks = CreateAxisTicks (&graph[0].axis[1], &Nticks);
     72    for (i = 0; i < Nticks; i++) {
     73      if (!ticks[i].IsMajor) continue;
     74      sprintf (string, "%g", ticks[i].value);
     75      Nc = MAX (Nc, strlen (string));
     76    }
     77    FREE(ticks);
     78  }
     79  if (isnan(graph[0].axis[1].labelPad)) {
     80    dYm = (graph[0].axis[1].islabel) ? (0.7*(Nc + 1.5)*fontsize) : minPAD;
     81  } else {
     82    dYm = graph[0].axis[1].labelPad * fontsize;
     83  }
     84  if (isnan(graph[0].axis[1].pad)) {
     85    padYm = graph[0].axis[1].islabel ? (0.7*(Nc + 2.5)*fontsize) : minPADy;
     86  } else {
     87    padYm = graph[0].axis[1].pad * fontsize;
     88  }
     89
     90  // offset from right y-axis to labels and tick values
     91  // these depend on (a) existence of tick labels and (b) auto-offset or not.
     92  // in the auto-offset case, offset depends on the width of the tick label strings
     93  if (graph[0].axis[3].islabel && (isnan(graph[0].axis[3].labelPad) || isnan(graph[0].axis[3].pad))) {
     94    Nc = 0;
     95    ticks = CreateAxisTicks (&graph[0].axis[3], &Nticks);
     96    for (i = 0; i < Nticks; i++) {
     97      if (!ticks[i].IsMajor) continue;
     98      sprintf (string, "%g", ticks[i].value);
     99      Nc = MAX (Nc, strlen (string));
     100    }
     101    FREE(ticks);
     102  }
     103  if (isnan(graph[0].axis[3].labelPad)) {
     104    dYp = (graph[0].axis[3].islabel) ? (0.7*(Nc + 1.5)*fontsize) : minPAD;
     105  } else {
     106    dYp = graph[0].axis[3].labelPad * fontsize;
     107  }
     108  if (isnan(graph[0].axis[3].pad)) {
     109    padYp = graph[0].axis[3].islabel ? (0.7*(Nc + 2.5)*fontsize) : minPADy;
     110  } else {
     111    padYp = graph[0].axis[3].pad * fontsize;
     112  }
     113
    35114  /* basic size of the graph in Xwindow coordinates */
    36   X0 = PADx + PXm + (Dx * section[0].x);
    37   Y0 = PADy + PYm + (Dy * section[0].y);
    38   dX = (Dx * section[0].dx) - PXp - PXm;
    39   dY = (Dy * section[0].dy) - PYp - PYm;
     115  X0 = graphic[0].dx * section[0].x + padYm;
     116  Y0 = graphic[0].dy * section[0].y + padXm;
     117  dX = graphic[0].dx * section[0].dx - padYm - padYp;
     118  dY = graphic[0].dy * section[0].dy - padXm - padXp;
    40119
    41120  // if we are tied to an image, make mods as needed
     
    47126    switch (section->image->location) {
    48127      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;
     128        Y0 = graphic[0].dy * section[0].y + 2*PAD1 + WdY + 2; // tied to image in Y
     129        dY = graphic[0].dy * section[0].dy - 5*PAD1 - WdY - COLORPAD + 1;
     130        break;
    52131      case 3:
    53         dY = graphic[0].dy * section[0].dy - 5*PAD1 - WdY - COLORPAD - PADy - PYm;
    54         break;
     132        dY = graphic[0].dy * section[0].dy - 5*PAD1 - WdY - COLORPAD - padYm - padYp;
     133        break;
    55134      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;
     135        X0 = graphic[0].dx * section[0].x  + 2*PAD1 + ZOOM_X;
     136        dX = graphic[0].dx * section[0].dx - 3*PAD1 - ZOOM_X;
     137        break;
    59138      case 4:
    60         dX = graphic[0].dx * section[0].dx - 3*PAD1 - ZOOM_X - PADx - PXm;
    61         break;
     139        dX = graphic[0].dx * section[0].dx - 3*PAD1 - ZOOM_X - padXm - padXp;
     140        break;
    62141    }
    63142  }
     
    68147  graph[0].axis[0].dfx = dX;
    69148  graph[0].axis[0].dfy = 0;
    70  
     149
    71150  graph[0].axis[1].fx  = X0;
    72151  graph[0].axis[1].fy  = graphic->dy - Y0;
     
    84163  graph[0].axis[3].dfy = -dY;
    85164
    86   PADx = 0.8*fontsize + 2;
    87   PADy = 3.0*fontsize + 4;
     165  /* define locations of axis labels */
     166  graph[0].label[LABELLL].x = graph[0].axis[0].fx;
     167  graph[0].label[LABELLL].y = graph[0].axis[0].fy + dXm;
     168  graph[0].label[LABELX0].x = graph[0].axis[0].fx + 0.5*graph[0].axis[0].dfx;
     169  graph[0].label[LABELX0].y = graph[0].axis[0].fy + dXm;
     170  graph[0].label[LABELLR].x = graph[0].axis[0].fx + graph[0].axis[0].dfx;
     171  graph[0].label[LABELLR].y = graph[0].axis[0].fy + dXm;
    88172
    89   /* define locations of axis labels */
    90   graph[0].label[LABELX0].x = graph[0].axis[0].fx + 0.5*graph[0].axis[0].dfx;
    91   bump = (graph[0].axis[0].islabel) ? PADy : PADx;
    92   graph[0].label[LABELX0].y = graph[0].axis[0].fy + bump;
    93 
     173  graph[0].label[LABELUL].x = graph[0].axis[2].fx;
     174  graph[0].label[LABELUL].y = graph[0].axis[2].fy - dXp;
    94175  graph[0].label[LABELX1].x = graph[0].axis[2].fx + 0.5*graph[0].axis[2].dfx;
    95   bump = (graph[0].axis[2].islabel) ? PADy : PADx;
    96   graph[0].label[LABELX1].y = graph[0].axis[2].fy - bump;
    97 
    98   /* check for the max size of the axis label */
    99   sprintf (string, "%4g", graph[0].axis[1].min);
    100   Nc = strlen (string);
    101   sprintf (string, "%4g", graph[0].axis[1].max);
    102   Nc = MAX (Nc, strlen (string));
     176  graph[0].label[LABELX1].y = graph[0].axis[2].fy - dXp;
     177  graph[0].label[LABELUR].x = graph[0].axis[2].fx + graph[0].axis[2].dfx;
     178  graph[0].label[LABELUR].y = graph[0].axis[2].fy - dXp;
    103179
    104180  graph[0].label[LABELY0].y = graph[0].axis[1].fy + 0.5*graph[0].axis[1].dfy;
    105   bump = (graph[0].axis[1].islabel) ? (0.8*Nc*fontsize + 1) : PADx;
    106   graph[0].label[LABELY0].x = graph[0].axis[1].fx - bump;
    107 
    108   sprintf (string, "%4g", graph[0].axis[3].min);
    109   Nc = strlen (string);
    110   sprintf (string, "%4g", graph[0].axis[3].max);
    111   Nc = MAX (Nc, strlen (string));
     181  graph[0].label[LABELY0].x = graph[0].axis[1].fx - dYm;
    112182
    113183  graph[0].label[LABELY1].y = graph[0].axis[3].fy + 0.5*graph[0].axis[3].dfy;
    114   bump = (graph[0].axis[3].islabel) ? (0.8*Nc*fontsize + 1) : PADx;
    115   graph[0].label[LABELY1].x = graph[0].axis[3].fx + bump;
    116  
     184  graph[0].label[LABELY1].x = graph[0].axis[3].fx + dYp;
     185
     186  // fprintf (stderr, "section %s, %f,%f : %f,%f\n", section->name, X0, Y0, dX, dY);
     187
    117188  /* these are wrong and have to be adjusted to sit in the corners */
    118189
    119   graph[0].label[LABELUL].x = graph[0].axis[2].fx - PADx;
    120   graph[0].label[LABELUL].y = graph[0].axis[2].fy - PADx;
    121   graph[0].label[LABELUR].x = graph[0].axis[2].fx + graph[0].axis[2].dfx + PADx;
    122   graph[0].label[LABELUR].y = graph[0].axis[2].fy - PADx;
    123   graph[0].label[LABELLL].x = graph[0].axis[0].fx - PADx;
    124   graph[0].label[LABELLL].y = graph[0].axis[0].fy + PADx;
    125   graph[0].label[LABELLR].x = graph[0].axis[0].fx + graph[0].axis[0].dfx + PADx;
    126   graph[0].label[LABELLR].y = graph[0].axis[0].fy + PADx;
    127 
    128190}
  • branches/pap/Ohana/src/kapa2/src/bDrawFrame.c

    r19837 r28003  
    11# include "Ximage.h"
     2// bDrawLine is a function, not a macro like DrawLine
    23
    34int bDrawFrame (KapaGraphWidget *graph) {
    45 
    5   int i, P, IsLabel, IsMajor, fontsize;
    6   double fx, fy, dfx, dfy, range, major, minor, first, next;
    7   char *fontname;
    8   int weight;
     6  int i, Nticks, P;
     7  double fx, fy, dfx, dfy, lweight;
     8  // Graphic graphic; is not needed
     9  TickMarkData *ticks;
    910  bDrawColor color;
    1011
     12  // don't need graphic, unlink DrawFrame
     13
    1114  /* each axis is drawn independently */
    12   fontname = GetRotFont (&fontsize);
    1315  for (i = 0; i < 4; i++) {
    1416    fx  = graph[0].axis[i].fx;
     
    1618    dfx = graph[0].axis[i].dfx;
    1719    dfy = graph[0].axis[i].dfy;
    18     P = hypot ((double)graph[0].axis[(i+1)%2].dfx, (double)graph[0].axis[(i+1)%2].dfy);
     20    P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
    1921
    20     weight = MAX (0, MIN (10, graph[0].axis[i].lweight));
     22    lweight = MAX (0, MIN (10, graph[0].axis[i].lweight));
    2123    color = MAX (0, MIN (15, graph[0].axis[i].color));
    22     bDrawSetStyle (color, weight, 0);
     24
     25    bDrawSetStyle (color, lweight, 0);
     26    // function about sets solor and weight
     27    // bDrawRotTextInit does not exist
    2328
    2429    if (graph[0].axis[i].isaxis) {
     
    2732   
    2833    if (graph[0].axis[i].areticks) {
    29       if (isnan(graph[0].axis[i].min) || isinf(graph[0].axis[i].min)) continue;
    30       if (isnan(graph[0].axis[i].max) || isinf(graph[0].axis[i].max)) continue;
    31 
    32       range = graph[0].axis[i].max - graph[0].axis[i].min;
    33 
    34       AxisTickScale (&graph[0].axis[i], &major, &minor);
    35 
    36       first = minor*((int)(graph[0].axis[i].min/minor));
    37       if ((range > 0) && (first < graph[0].axis[i].min)) {
    38         first += minor;
     34      ticks = CreateAxisTicks (&graph[0].axis[i], &Nticks);
     35      for (i = 0; i < Nticks; i++) {
     36        bDrawTick (&graph[0].axis[i], P, &ticks[i], i);
    3937      }
    40       if ((range < 0) && (first > graph[0].axis[i].min)) {
    41         first -= minor;
    42       }
    43       for (next = first; ((range > 0) && (next <= graph[0].axis[i].max)) || ((range < 0) && (next >= graph[0].axis[i].max));) {
    44         IsMajor = FALSE;
    45         IsMajor |= (fabs((int)(next/major) - (next/major)) < 0.5*(minor/major));
    46         IsMajor |= (fabs ((int)((next + 0.5*minor)/major) - (next/major)) < 0.5*(minor/major));
    47         IsMajor |= (fabs ((int)((next - 0.5*minor)/major) - (next/major)) < 0.5*(minor/major));
    48         IsLabel = (IsMajor && graph[0].axis[i].islabel);
    49         bDrawTick (fx, fy, dfx, dfy, P, graph[0].axis[i].min, graph[0].axis[i].max, next, IsLabel, IsMajor, i);
    50         if (range > 0)
    51           next += minor;
    52         else
    53           next -= minor;
    54       }
     38      FREE (ticks);
    5539    }
    5640  }
     
    5842}
    5943
    60 void bDrawTick (double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int IsLabel, int IsMajor, int naxis) {
     44void bDrawTick (Axis *axis, int P, TickMarkData *tick, int naxis) {
    6145 
     46  double x, y, dx, dy;
    6247  int pos, dir, fontsize;
    63   double size, n, x, y, dx, dy;
     48  double size, n, pad;
    6449  char string[64], *fontname;
     50
     51  double fx  = axis->fx;
     52  double fy  = axis->fy;
     53  double dfx = axis->dfx;
     54  double dfy = axis->dfy;
     55
     56  double min = axis->min;
     57  double max = axis->max;
     58
     59  double value = tick->value;
    6560
    6661  pos = size = 0;
    6762
    68   if (IsMajor) {
     63  if (tick->IsMajor) {
    6964    size = MAX (0.02, 7.0 / P);
    7065  } else {
     
    7267  }
    7368 
    74   n = P / sqrt ((double)(dfx*dfx + dfy*dfy));
     69  n = P / hypot(dfx, dfy);
    7570  x = fx + (value-min)*dfx/(max - min);
    7671  y = fy + (value-min)*dfy/(max - min);
    7772
    78   dir = +1;
    79   if ((naxis == 0) || (naxis == 1)) dir *= -1;
     73  dir = ((naxis == 0) || (naxis == 1)) ? -1 : +1;
    8074  dx = dir*size*dfy*n; 
    8175  dy = dir*size*dfx*n;
     
    8377  bDrawLine (x, y, x+dx, y+dy);
    8478
    85   if (IsLabel) {
     79  if (tick->IsLabel) {
     80    int xt, yt;
     81
    8682    fontname = GetRotFont (&fontsize);
    8783
     84    pad = !isnan(axis->ticktextPad) ? axis->ticktextPad*fontsize : 0.8*fontsize + 1.0;
     85   
    8886    /* temporarily assume rectilinear axes */
    89     if (naxis == 0) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 1; }
    90     if (naxis == 2) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 7; }
     87    if (naxis == 0) { dx = 0; dy = +pad; pos = 1; }
     88    if (naxis == 2) { dx = 0; dy = -pad; pos = 7; }
    9189
    92     if (naxis == 1) { dy = 0; dx = -(0.8*fontsize + 1); pos = 3; }
    93     if (naxis == 3) { dy = 0; dx = +(0.8*fontsize + 1); pos = 5; }
     90    if (naxis == 1) { dy = 0; dx = -pad; pos = 3; }
     91    if (naxis == 3) { dy = 0; dx = +pad; pos = 5; }
    9492
    95     x = fx + (value-min)*dfx/(max - min) + dx;
    96     y = fy + (value-min)*dfy/(max - min) + dy;
    97     if (fabs(value) < 1e-14) { value = 0.0; }
    98     sprintf (string, "%g", value);
    99     bDrawRotText ((int)x, (int)y, string, pos, 0.0);
     93    xt = fx + (value-min)*dfx/(max - min) + dx;
     94    yt = fy + (value-min)*dfy/(max - min) + dy;
     95    if (fabs(value) < 0.001) { value = 0.0; }
     96    sprintf (string, "%4g", value);
     97    bDrawRotText (xt, yt, string, pos, 0.0);
    10098  }
    10199}
  • branches/pap/Ohana/src/libdvo/include/dvo.h

    r27580 r28003  
    443443void sort_image_subset (Image *image, off_t *subset, off_t N);
    444444void sort_coords_index (double *X, double *Y, off_t *S, off_t N);
     445void sort_coords_indexonly (double *X, double *Y, off_t *S, off_t N);
    445446void sort_regions (SkyRegion *region, off_t N);
    446447
  • branches/pap/Ohana/src/libdvo/src/coordops.c

    r27435 r28003  
    353353      dY = (dM*dLdX - dL*dMdX) * Do;
    354354
    355       // fprintf (stderr, "X,Y + dX,dY : %f, %f : %f, %f\n", X, Y, dX, dY);
     355      // fprintf (stderr, "Xo,Yo + dX,dY : %f, %f : %f, %f\n", Xo, Yo, dX, dY);
    356356
    357357      Xo += dX;
  • branches/pap/Ohana/src/libdvo/src/dvosorts.c

    r27435 r28003  
    4646}
    4747
     48/* sort a coordinate pair (X,Y) and the associated index (S) */
     49void sort_coords_indexonly (double *X, double *Y, off_t *S, off_t N) {
     50 
     51# define SWAPFUNC(A,B){ off_t itmp; \
     52  itmp = S[A]; S[A] = S[B]; S[B] = itmp; \
     53}
     54# define COMPARE(A,B)(X[S[A]] < X[S[B]])
     55
     56  OHANA_SORT (N, COMPARE, SWAPFUNC);
     57
     58# undef SWAPFUNC
     59# undef COMPARE
     60
     61}
     62
    4863void sort_regions (SkyRegion *region, off_t N) {
    4964
  • branches/pap/Ohana/src/libkapa/include/kapa.h

    r27435 r28003  
    7272  float dx;
    7373  float dy;
     74  int bg;
    7475} KapaSection;
    7576
     
    7879  int style, ptype, ltype, etype, ebar, color;
    7980  double lweight, size;
     81  double ticktextPad;
     82  double labelPadXm, labelPadYm, labelPadXp, labelPadYp;
     83  double padXm, padXp, padYm, padYp;
    8084  Coords coords;
    8185  int flipeast, flipnorth;
     
    173177int KapaSelectSection (int fd, char *name);
    174178int KapaGetSection (int fd, char *name);
     179int KapaSectionBG (int fd, char *name, int bg);
    175180int KapaMoveSection (int fd, char *name, char *direction);
    176181int KapaSetGraphData (int fd, Graphdata *graphmode);
    177182int KapaGetGraphData (int fd, Graphdata *graphmode);
     183int KapaScanGraphData (int fd, Graphdata *graphmode);
     184int KapaSendGraphData (int fd, Graphdata *graphmode);
    178185int KapaSetImageData (int fd, KapaImageData *graphmode);
    179186int KapaGetImageData (int fd, KapaImageData *graphmode);
  • branches/pap/Ohana/src/libkapa/src/KapaColors.c

    r7080 r28003  
    3737    }   
    3838  }
     39  if (!strcasecmp (name, "none")) return (-1);
     40
    3941  fprintf (stderr, "color may be one of:\n");
    4042  for (i = 0; i < N_KAPA_COLORS; i++) {
  • branches/pap/Ohana/src/libkapa/src/KapaOpen.c

    r27588 r28003  
    3131  if (status == -1) {
    3232    if (errno == EADDRINUSE) {
    33         close (InitSocket);
    34         Address[0].sin_port ++;
    35         if (Address[0].sin_port > MY_PORT_MAX) exit (2);
    36         goto retry_server;
     33        close (InitSocket);
     34        Address[0].sin_port ++;
     35        if (Address[0].sin_port > MY_PORT_MAX) exit (2);
     36        goto retry_server;
    3737    }
    3838    perror ("bind: ");
     
    6969
    7070  /* do I need to clear rfds on each pass? */
     71  FD_ZERO(&rfds);
    7172  FD_SET (InitSocket, &rfds);
    7273  status = select (InitSocket + 1, &rfds, NULL, NULL, &wait);
     
    9899
    99100  for (i = 0; i < Nvalid; i++) {
    100     /* valid IP addresses may be machines (120.90.121.142) or 
     101    /* valid IP addresses may be machines (120.90.121.142) or
    101102       class C networks (120.90.121.0) */
    102        
     103
    103104    /* for machine, address must match */
    104105    if ((0xff & (VALID[i] >> 24)) != 0) {
     
    138139  test = TRUE;
    139140  test &= (status == 4);
    140   test &= ((ip1 > 0) && (ip1 < 256)); 
    141   test &= ((ip2 > 0) && (ip2 < 256)); 
    142   test &= ((ip3 > 0) && (ip3 < 256)); 
    143   test &= ((ip4 >=0) && (ip4 < 256)); 
     141  test &= ((ip1 > 0) && (ip1 < 256));
     142  test &= ((ip2 > 0) && (ip2 < 256));
     143  test &= ((ip3 > 0) && (ip3 < 256));
     144  test &= ((ip4 >=0) && (ip4 < 256));
    144145  if (!test) {
    145146    fprintf (stderr, "invalid IP address %s\n", string);
     
    205206
    206207  // the client uses a BLOCKing socket by default
    207   fcntl (InitSocket, F_SETFL, !O_NONBLOCK); 
     208  fcntl (InitSocket, F_SETFL, !O_NONBLOCK);
    208209  return (InitSocket);
    209210}
     
    211212int KapaOpen (char *kapa_exec, char *kapa_name) {
    212213
    213   // kapa_exec may be kapa://host, in which case we attempt to connect to an 
     214  // kapa_exec may be kapa://host, in which case we attempt to connect to an
    214215  // already running kapa, or the program path, in which case we are supposed
    215216  // to launch it locally, then connect to it.
     
    265266  unlink (socket_name);
    266267
    267   strcpy (Address.sun_path, socket_name); 
    268   Address.sun_family = AF_UNIX; 
    269   InitSocket = socket (AF_UNIX, SOCK_STREAM, 0); 
     268  strcpy (Address.sun_path, socket_name);
     269  Address.sun_family = AF_UNIX;
     270  InitSocket = socket (AF_UNIX, SOCK_STREAM, 0);
    270271  status = bind (InitSocket, (struct sockaddr *) &Address, sizeof (Address));
    271272  status = listen (InitSocket, 1);
    272  
     273
    273274  if (name == NULL) {
    274275    sprintf (temp, "%s -socket %s &", kapa_exec, socket_name);
     
    282283
    283284  AddressLength =  sizeof (Address);
    284   fcntl (InitSocket, F_SETFL, O_NONBLOCK); 
     285  fcntl (InitSocket, F_SETFL, O_NONBLOCK);
    285286
    286287# define NTRY 500
     
    297298
    298299  // the client uses a BLOCKing socket by default
    299   fcntl (fd, F_SETFL, !O_NONBLOCK); 
     300  fcntl (fd, F_SETFL, !O_NONBLOCK);
    300301  return (fd);
    301302}
     
    317318
    318319  // the server uses an unblocked socket
    319   fcntl (sock, F_SETFL, O_NONBLOCK); 
     320  fcntl (sock, F_SETFL, O_NONBLOCK);
    320321  unlink (sockpath);
    321322  return (sock);
  • branches/pap/Ohana/src/libkapa/src/KapaWindow.c

    r27588 r28003  
    3838
    3939  KiiSendCommand (fd, 4, "DBOX");
    40   KiiSendMessage (fd, "%12.6g %12.6g %12.6g %12.6g",
    41                     graphdata[0].xmin, graphdata[0].xmax, graphdata[0].ymin, graphdata[0].ymax);
    42 
    43   KiiSendMessage (fd, "%lf %d", graphdata[0].lweight, graphdata[0].color);
    44 
    45   KiiSendMessage (fd, "%s %s %s", graphdata[0].axis, graphdata[0].labels, graphdata[0].ticks);
     40
     41  KapaSendGraphData (fd, graphdata);
     42
    4643  KiiWaitAnswer (fd, "DONE");
    4744  return (TRUE);
     
    8481}
    8582
     83// XXX drop this function? : kapa is responsible for the graph initialization
    8684int KapaInitGraph (Graphdata *graphdata) {
    8785
     
    103101  graphdata[0].flipeast = TRUE;
    104102  graphdata[0].flipnorth = FALSE;
     103
    105104  strcpy (graphdata[0].axis, "2222");
    106105  strcpy (graphdata[0].ticks, "2222");
    107106  strcpy (graphdata[0].labels, "2222");
     107
     108  graphdata[0].ticktextPad = NAN;
     109
     110  graphdata[0].labelPadXm = NAN;
     111  graphdata[0].labelPadXp = NAN;
     112  graphdata[0].labelPadYm = NAN;
     113  graphdata[0].labelPadYp = NAN;
     114
     115  graphdata[0].padXm = NAN;
     116  graphdata[0].padXp = NAN;
     117  graphdata[0].padYm = NAN;
     118  graphdata[0].padYp = NAN;
    108119
    109120  return (TRUE);
     
    128139}
    129140
    130 int KapaSetGraphData (int fd, Graphdata *data) {
    131 
    132   /* tell kapa to look for the incoming image */
    133   KiiSendCommand (fd, 4, "SSTY");
    134  
     141int KapaSendGraphData (int fd, Graphdata *data) {
     142
    135143  /* send kapa the plot details */
     144  KiiSendMessage (fd, "%g %g %g %g",
     145                  data[0].xmin, data[0].xmax,
     146                  data[0].ymin, data[0].ymax);
     147
    136148  KiiSendMessage (fd, "%8d %d %d %d %d %d %f %f",
    137149                  data[0].style,
     
    140152                  data[0].lweight, data[0].size);
    141153
     154  KiiSendMessage (fd, "%g %g %g %g %g",
     155                  data[0].ticktextPad,
     156                  data[0].padXm, data[0].padXp,
     157                  data[0].padYm, data[0].padYp);
     158
    142159  KiiSendMessage (fd, "%g %g %g %g",
    143                   data[0].xmin, data[0].xmax,
    144                   data[0].ymin, data[0].ymax);
     160                  data[0].labelPadXm, data[0].labelPadXp,
     161                  data[0].labelPadYm, data[0].labelPadYp);
    145162
    146163  KiiSendMessage (fd, "%g %g %g %g",
     
    160177                  data[0].coords.cdelt2);
    161178
    162   KiiWaitAnswer (fd, "DONE");
    163   return (TRUE);
    164 }
    165 
    166 int KapaGetGraphData (int fd, Graphdata *data) {
    167 
    168   /* tell kapa to look for the incoming image */
    169   KiiSendCommand (fd, 4, "GSTY");
    170  
     179  KiiSendMessage (fd, "%s %s %s", data[0].axis, data[0].ticks, data[0].labels);
     180
     181  return (TRUE);
     182}
     183
     184int KapaScanGraphData (int fd, Graphdata *data) {
     185
    171186  /* send kapa the plot details */
     187  KiiScanMessage (fd, "%lf %lf %lf %lf",
     188                  &data[0].xmin, &data[0].xmax,
     189                  &data[0].ymin, &data[0].ymax);
     190
    172191  KiiScanMessage (fd, "%d %d %d %d %d %d %lf %lf",
    173192                  &data[0].style,
     
    176195                  &data[0].lweight, &data[0].size);
    177196
     197  KiiScanMessage (fd, "%lf %lf %lf %lf %lf",
     198                  &data[0].ticktextPad,
     199                  &data[0].padXm, &data[0].padXp,
     200                  &data[0].padYm, &data[0].padYp);
     201
    178202  KiiScanMessage (fd, "%lf %lf %lf %lf",
    179                   &data[0].xmin, &data[0].xmax,
    180                   &data[0].ymin, &data[0].ymax);
     203                  &data[0].labelPadXm, &data[0].labelPadXp,
     204                  &data[0].labelPadYm, &data[0].labelPadYp);
    181205
    182206  KiiScanMessage (fd, "%f %f %f %f",
     
    196220                  &data[0].coords.cdelt2);
    197221
     222  KiiScanMessage (fd, "%s %s %s", data[0].axis, data[0].ticks, data[0].labels);
     223
    198224  // XXX at some point, we need to add polynomials and 2-level mosaic
    199225  // astrometry here.
    200226
    201227  data[0].coords.Npolyterms = 0;
     228
     229  return (TRUE);
     230}
     231
     232int KapaSetGraphData (int fd, Graphdata *data) {
     233
     234  /* tell kapa to look for the incoming image */
     235  KiiSendCommand (fd, 4, "SSTY");
     236 
     237  KapaSendGraphData (fd, data);
     238
     239  KiiWaitAnswer (fd, "DONE");
     240  return (TRUE);
     241}
     242
     243int KapaGetGraphData (int fd, Graphdata *data) {
     244
     245  /* tell kapa to look for the incoming image */
     246  KiiSendCommand (fd, 4, "GSTY");
     247 
     248  KapaScanGraphData (fd, data);
    202249
    203250  KiiWaitAnswer (fd, "DONE");
     
    312359
    313360  KiiSendCommand (fd, 4, "DSEC");
    314   KiiSendMessage (fd, "%s %6.3f %6.3f %6.3f %6.3f",
     361  KiiSendMessage (fd, "%s %6.3f %6.3f %6.3f %6.3f %3d",
    315362                  section[0].name,
    316363                  section[0].x,
    317364                  section[0].y,
    318365                  section[0].dx,
    319                   section[0].dy);
     366                  section[0].dy,
     367                  section[0].bg);
     368  KiiWaitAnswer (fd, "DONE");
     369  return (TRUE);
     370}
     371
     372int KapaSectionBG (int fd, char *name, int bg) {
     373
     374  KiiSendCommand (fd, 4, "BSEC");
     375  KiiSendMessage (fd, "%s %3d", name, bg);
    320376  KiiWaitAnswer (fd, "DONE");
    321377  return (TRUE);
  • branches/pap/Ohana/src/libkapa/src/KiiPicture.c

    r27588 r28003  
    4646  Nwrite = write (fd, image[0].data1d, size);
    4747  if (Nwrite != size) {
    48     fprintf (stderr, "error reading picture\n");
     48    fprintf (stderr, "error sending picture to kapa\n");
    4949    return (FALSE);
    5050  }
     
    105105  Nwrite = write (fd, outbuffer, size);
    106106  if (Nwrite != size) {
    107     fprintf (stderr, "error reading picture\n");
     107    fprintf (stderr, "error sending picture to kapa\n");
    108108    return (FALSE);
    109109  }
     
    142142    Nbytes = image[0].Nx*sizeof(float);
    143143    Nwrite = write (fd, image[0].data2d[j], Nbytes);
    144     if (Nwrite != size) {
    145       fprintf (stderr, "error reading picture\n");
     144    if (Nwrite != Nbytes) {
     145      fprintf (stderr, "error sending picture to kapa\n");
    146146      return (FALSE);
    147147    }
  • branches/pap/Ohana/src/opihi/cmd.basic/break.c

    r23582 r28003  
    11# include "basic.h"
    22
     3// auto_break is currently a global
    34int exec_break (int argc, char **argv) {
    45
    56  int N, value;
    67
     8  if ((N = get_argument (argc, argv, "-h"))) goto usage;
     9  if ((N = get_argument (argc, argv, "-help"))) goto usage;
     10  if ((N = get_argument (argc, argv, "--help"))) goto usage;
     11
    712  if ((N = get_argument (argc, argv, "-auto"))) {
    813    remove_argument (N, &argc, argv);
    9     value = -1;
    10     if (!strcasecmp (argv[N], "on")) value = 1;
    11     if (!strcasecmp (argv[N], "off")) value = 0;
    12     if (value == -1) {
    13       gprint (GP_ERR, "USAGE: break -auto [on / off]\n");
     14    if (N == argc) {
    1415      if (auto_break)
    1516        gprint (GP_ERR, "auto break on\n");
     
    1819      return (FALSE);
    1920    }
     21    value = -1;
     22    if (!strcasecmp (argv[N], "on")) value = 1;
     23    if (!strcasecmp (argv[N], "off")) value = 0;
     24    if (value == -1) goto usage;
    2025    auto_break = value;
    2126    return (TRUE);
    2227  }
    23 
     28 
    2429  loop_break = TRUE;
    2530  return (FALSE);
    26 
     31 
     32usage:
     33  gprint (GP_ERR, "USAGE: break -auto [on / off]\n");
     34  return (FALSE);
    2735}
  • branches/pap/Ohana/src/opihi/cmd.basic/opihi.c

    r27255 r28003  
    33int opihi_setmode (int argc, char **argv) {
    44
    5   int value;
     5  OpihiVerboseMode value;
    66
    77  if (argc < 2) {
    8     gprint (GP_ERR, "USAGE: opihi (verbose) [on/off]\n");
     8    gprint (GP_ERR, "USAGE: opihi (verbose) [on/off/error]\n");
    99    return (FALSE);
    1010  }
     
    1313      if (argc == 2) {
    1414          value = get_verbose_shell();
    15           if (value) {
    16             gprint (GP_ERR, "opihi verbose mode: on\n");
    17           } else {
    18             gprint (GP_ERR, "opihi verbose mode: off\n");
    19           }
     15          switch (value) {
     16            case OPIHI_VERBOSE_OFF:
     17              gprint (GP_ERR, "opihi verbose mode: off\n");
     18              break;
     19            case OPIHI_VERBOSE_ON:
     20              gprint (GP_ERR, "opihi verbose mode: on\n");
     21              break;
     22            case OPIHI_VERBOSE_ERROR:
     23              gprint (GP_ERR, "opihi verbose mode: error\n");
     24              break;
     25            default:
     26              fprintf (stderr, "impossible condition\n");
     27              abort();
     28          }
    2029          return (TRUE);
    2130      }
    2231      if (!strcasecmp(argv[2], "on")) {
    23         set_verbose_shell (TRUE);
     32        set_verbose_shell (OPIHI_VERBOSE_ON);
    2433        return (TRUE);
    2534      }
    2635      if (!strcasecmp(argv[2], "off")) {
    27         set_verbose_shell (FALSE);
     36        set_verbose_shell (OPIHI_VERBOSE_OFF);
     37        return (TRUE);
     38      }
     39      if (!strcasecmp(argv[2], "error")) {
     40        set_verbose_shell (OPIHI_VERBOSE_ERROR);
    2841        return (TRUE);
    2942      }
  • branches/pap/Ohana/src/opihi/cmd.basic/run_for.c

    r16464 r28003  
    77  int ThisList, depth, i, done, status, found, NLINES, j;
    88  double start, end, delta;
    9   char *input;
     9  char *input, *endptr;
    1010  double value, sign;
    1111  Macro loop;
     
    1616  }
    1717
    18   start = atof (argv[2]);
    19   end   = atof (argv[3]);
     18  start = strtod (argv[2], &endptr);
     19  if (*endptr) {
     20    gprint (GP_ERR, "for loop starting value must be numerical (%s)\n", argv[2]);
     21    return (FALSE);
     22  }
     23
     24  end = strtod (argv[3], &endptr);
     25  if (*endptr) {
     26    gprint (GP_ERR, "for loop ending value must be numerical (%s)\n", argv[3]);
     27    return (FALSE);
     28  }
     29
    2030  delta = 1.0;
    21   if (argc == 5) delta = atof (argv[4]);
     31  if (argc == 5) {
     32    delta = strtod (argv[4], &endptr);
     33    if (*endptr) {
     34      gprint (GP_ERR, "for loop delta value must be numerical (%s)\n", argv[4]);
     35      return (FALSE);
     36    }
     37  }
    2238  sign = SIGN(delta);
    2339
  • branches/pap/Ohana/src/opihi/cmd.data/Makefile

    r26891 r28003  
    7272$(SRC)/lookup.$(ARCH).o \
    7373$(SRC)/matrix.$(ARCH).o \
     74$(SRC)/match2d.$(ARCH).o        \
    7475$(SRC)/mkrgb.$(ARCH).o  \
    7576$(SRC)/mcreate.$(ARCH).o        \
  • branches/pap/Ohana/src/opihi/cmd.data/box.c

    r19839 r28003  
    2525  }
    2626
    27   graphmode.lweight = 1;
     27  // graphmode.lweight = 1;
    2828  if ((N = get_argument (argc, argv, "-lw"))) {
    2929    remove_argument (N, &argc, argv);
     
    3232  }
    3333
    34   graphmode.color = KapaColorByName ("black");
     34  // graphmode.color = KapaColorByName ("black");
    3535  if ((N = get_argument (argc, argv, "-c"))) {
    3636    remove_argument (N, &argc, argv);
     
    4040  }
    4141
    42   strcpy (graphmode.ticks, "2222");
     42  // XXX need to get the current values from kapa
     43  // strcpy (graphmode.ticks, "2222");
    4344  if ((N = get_argument (argc, argv, "-ticks"))) {
    4445    remove_argument (N, &argc, argv);
     
    5152  }
    5253 
    53   strcpy (graphmode.labels, "2222");
     54  // strcpy (graphmode.labels, "2222");
    5455  if ((N = get_argument (argc, argv, "-labels"))) {
    5556    remove_argument (N, &argc, argv);
     
    6263  }
    6364
    64   strcpy (graphmode.axis, "2222");
     65  // strcpy (graphmode.axis, "2222");
    6566  if ((N = get_argument (argc, argv, "-axis"))) {
    6667    remove_argument (N, &argc, argv);
     
    7172      if ((graphmode.axis[i] != '0') && (graphmode.axis[i] != '1') && (graphmode.axis[i] != '2')) { goto usage; }
    7273    }
     74  }
     75
     76  if ((N = get_argument (argc, argv, "-tickpad"))) {
     77    remove_argument (N, &argc, argv);
     78    graphmode.ticktextPad = atof(argv[N]);
     79    remove_argument (N, &argc, argv);
     80  }
     81
     82  if ((N = get_argument (argc, argv, "-labelpadx"))) {
     83    remove_argument (N, &argc, argv);
     84    graphmode.labelPadXm = atof(argv[N]);
     85    remove_argument (N, &argc, argv);
     86  }
     87
     88  if ((N = get_argument (argc, argv, "-labelpady"))) {
     89    remove_argument (N, &argc, argv);
     90    graphmode.labelPadYm = atof(argv[N]);
     91    remove_argument (N, &argc, argv);
     92  }
     93
     94  if ((N = get_argument (argc, argv, "+labelpadx"))) {
     95    remove_argument (N, &argc, argv);
     96    graphmode.labelPadXp = atof(argv[N]);
     97    remove_argument (N, &argc, argv);
     98  }
     99
     100  if ((N = get_argument (argc, argv, "+labelpady"))) {
     101    remove_argument (N, &argc, argv);
     102    graphmode.labelPadYp = atof(argv[N]);
     103    remove_argument (N, &argc, argv);
     104  }
     105
     106  if ((N = get_argument (argc, argv, "-labelpad"))) {
     107    remove_argument (N, &argc, argv);
     108    graphmode.labelPadXm = atof(argv[N]);
     109    graphmode.labelPadXp = atof(argv[N]);
     110    graphmode.labelPadYm = atof(argv[N]);
     111    graphmode.labelPadYp = atof(argv[N]);
     112    remove_argument (N, &argc, argv);
     113  }
     114
     115  if ((N = get_argument (argc, argv, "-pad"))) {
     116    remove_argument (N, &argc, argv);
     117    graphmode.padXm = atof(argv[N]);
     118    graphmode.padXp = atof(argv[N]);
     119    graphmode.padYm = atof(argv[N]);
     120    graphmode.padYp = atof(argv[N]);
     121    remove_argument (N, &argc, argv);
     122  }
     123  if ((N = get_argument (argc, argv, "-xpad"))) {
     124    remove_argument (N, &argc, argv);
     125    graphmode.padXm = atof(argv[N]);
     126    remove_argument (N, &argc, argv);
     127  }
     128  if ((N = get_argument (argc, argv, "+xpad"))) {
     129    remove_argument (N, &argc, argv);
     130    graphmode.padXp = atof(argv[N]);
     131    remove_argument (N, &argc, argv);
     132  }
     133  if ((N = get_argument (argc, argv, "-ypad"))) {
     134    remove_argument (N, &argc, argv);
     135    graphmode.padYm = atof(argv[N]);
     136    remove_argument (N, &argc, argv);
     137  }
     138  if ((N = get_argument (argc, argv, "+ypad"))) {
     139    remove_argument (N, &argc, argv);
     140    graphmode.padYp = atof(argv[N]);
     141    remove_argument (N, &argc, argv);
    73142  }
    74143
  • branches/pap/Ohana/src/opihi/cmd.data/create.c

    r20936 r28003  
    1414
    1515  if ((argc != 5) && (argc != 4)) {
    16     gprint (GP_ERR, "USAGE: create vector start end [delta]\n");
     16    gprint (GP_ERR, "USAGE: create vector start end [delta] [-int]\n");
     17    gprint (GP_ERR, " -int : resulting vector is integer type (delta must be integer)\n");
    1718    return (FALSE);
    1819  }
     
    2021  if ((vec = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) return (FALSE);
    2122
     23  delta = 1;
    2224  start = atof (argv[2]);
    2325  end   = atof (argv[3]);
    24   delta = 1;
    2526  if (argc == 5) delta = atof (argv[4]);
     27
    2628  if ((start == end) || (delta == 0)) {
    2729    gprint (GP_ERR, "error in value: %f to %f, %f\n", start, end, delta);
  • branches/pap/Ohana/src/opihi/cmd.data/fit1d.c

    r24081 r28003  
    5353    return (FALSE);
    5454  }
    55   REQUIRE_VECTOR_FLT (xvec, FALSE);
    56   REQUIRE_VECTOR_FLT (yvec, FALSE);
     55  CastVector (xvec, OPIHI_FLT);
     56  CastVector (yvec, OPIHI_FLT);
    5757
    5858  if (Weight) {
    59     REQUIRE_VECTOR_FLT (dyvec, FALSE);
     59    CastVector (dyvec, OPIHI_FLT);
    6060    if (xvec[0].Nelements != dyvec[0].Nelements) {
    6161      gprint (GP_ERR, "vectors must have same length\n");
  • branches/pap/Ohana/src/opihi/cmd.data/fit2d.c

    r20936 r28003  
    6464    return (FALSE);
    6565  }
    66   REQUIRE_VECTOR_FLT (xvec, FALSE);
    67   REQUIRE_VECTOR_FLT (yvec, FALSE);
    68   REQUIRE_VECTOR_FLT (zvec, FALSE);
     66  CastVector (xvec, OPIHI_FLT);
     67  CastVector (yvec, OPIHI_FLT);
     68  CastVector (zvec, OPIHI_FLT);
    6969
    7070  if (Weight) {
    71     REQUIRE_VECTOR_FLT (dzvec, FALSE);
     71    CastVector (dzvec, OPIHI_FLT);
    7272    if (xvec[0].Nelements != dzvec[0].Nelements) {
    7373      gprint (GP_ERR, "vectors must have same length\n");
  • branches/pap/Ohana/src/opihi/cmd.data/histogram.c

    r20936 r28003  
    33int histogram (int argc, char **argv) {
    44 
    5   int i, bin, Nbins;
     5  int i, N, bin, Nbins;
    66  opihi_int *OUT;
    77  opihi_flt start, end, delta;
    8   Vector *xvec, *yvec;
     8  Vector *xvec, *yvec, *range;
     9
     10  range = NULL;
     11  if ((N = get_argument (argc, argv, "-range"))) {
     12    remove_argument (N, &argc, argv);
     13    if ((range = SelectVector (argv[N], ANYVECTOR, TRUE)) == NULL) return (FALSE);   
     14    remove_argument (N, &argc, argv);
     15  }
    916
    1017  if ((argc != 6) && (argc != 5)) {
    11     gprint (GP_ERR, "USAGE: hist invec outvec start end [delta]\n");
     18    gprint (GP_ERR, "USAGE: hist invec outvec start end [delta] [-range range]\n");
    1219    return (FALSE);
    1320  }
     
    3138  if ((xvec = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
    3239  if ((yvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) return (FALSE);
     40
     41  if (range) {
     42    ResetVector (range, OPIHI_FLT, Nbins);
     43    for (i = 0; i < range[0].Nelements; i++) {
     44      range[0].elements.Flt[i] = start + i*delta;
     45    }
     46  }
    3347
    3448  ResetVector (yvec, OPIHI_INT, Nbins);
  • branches/pap/Ohana/src/opihi/cmd.data/init.c

    r26891 r28003  
    6161int lookup           PROTO((int, char **));
    6262int matrix           PROTO((int, char **));
     63int match2d          PROTO((int, char **));
    6364int mkrgb            PROTO((int, char **));
    6465int mcreate          PROTO((int, char **));
     
    201202  {1, "iminterp",     minterp,          "interpolate image pixels"},
    202203  {1, "matrix",       matrix,           "matrix math operations"},
     204  {1, "match2d",      match2d,          "match 2 pairs of X,Y vectors and return matched indexes"},
    203205  {1, "mkrgb",        mkrgb,            "convert 3 images to rgb jpeg (use Kapa for better control)"},
    204206  {1, "mset",         mset,             "insert a vector in an image"},
  • branches/pap/Ohana/src/opihi/cmd.data/section.c

    r27491 r28003  
    11# include "data.h"
    22
    3 enum {NONE, LIST, UP, DOWN, TOP, BOTTOM, TOOL};
     3enum {NONE, LIST, UP, DOWN, TOP, BOTTOM, TOOL, BG};
    44
    55int section (int argc, char **argv) {
    66 
    7   int N, action, kapa;
     7  int N, action, kapa, background;
    88  Graphdata graphmode;
    99  KapaSection section;
     
    3737    location = argv[N];
    3838    remove_argument (N, &argc, argv);
     39  }
     40
     41  background = -1; // invisible
     42  if ((N = get_argument (argc, argv, "-bg"))) {
     43    remove_argument (N, &argc, argv);
     44    if (!strcasecmp (argv[N], "NONE")) {
     45      background = -1;
     46    } else {
     47      background = KapaColorByName(argv[N]);
     48    }
     49    remove_argument (N, &argc, argv);
     50    action = BG;
    3951  }
    4052
     
    8294        break;
    8395
     96      case BG:
     97        KapaSectionBG (kapa, argv[1], background);
     98        break;
     99
    84100      case TOOL:
    85101        if (!strcmp(location, "-x")) {
     
    121137    section.dx = atof (argv[4]);
    122138    section.dy = atof (argv[5]);
     139    section.bg = background;
    123140    KapaSetSection (kapa, &section);
    124141    return (TRUE);
  • branches/pap/Ohana/src/opihi/include/shell.h

    r27435 r28003  
    1515typedef enum {GP_FILE, GP_BUFF} gpMode;
    1616typedef enum {GP_LOG, GP_ERR} gpDest;
     17typedef enum {OPIHI_VERBOSE_OFF, OPIHI_VERBOSE_ON, OPIHI_VERBOSE_ERROR} OpihiVerboseMode;
    1718
    1819typedef int CommandF (int argc, char **argv);
  • branches/pap/Ohana/src/opihi/lib.shell/command.c

    r27255 r28003  
    22# define DEBUG 0
    33
    4 static int VERBOSE_SHELL = FALSE;
     4static int VERBOSE_SHELL = OPIHI_VERBOSE_OFF;
    55
    66int command (char *line, char **outline, int VERBOSE) {
     
    1010  Command *cmd;
    1111
    12   rawline = NULL;
    13   // rawline = strcreate (line);
     12  // rawline = NULL;
     13  rawline = strcreate (line);
    1414
    1515  /* force a space between ! and first word: !ls becomes ! ls */
     
    2424  /* expand anything of the form fred[N] */
    2525  line = expand_vectors (line);  /* line is freed here, new one allocated */
     26
     27  // print the line with the variables and vectors expanded, but before evaluating
     28  // any in-line math expression
     29  if (VERBOSE_SHELL == OPIHI_VERBOSE_ON) gprint (GP_ERR, "opihi: %s\n", line);
     30
    2631  /* solve math expresions, assign variable, if needed */
    2732  line = parse (line);        /* line is freed here, new one allocated */
     
    3136  *outline = line;
    3237 
    33   if (VERBOSE_SHELL) gprint (GP_ERR, "opihi: %s\n", line);
    34 
    3538  argv = parse_commands (line, &argc);
    3639  if (argc == 0) {
     
    6063    msg = get_variable_ptr ("ERRORMSG");
    6164    if (msg != (char *) NULL) gprint (GP_ERR, "%s\n", msg);
    62     if (VERBOSE_SHELL) gprint (GP_ERR, "error on line: %s\n", rawline);
     65    if (VERBOSE_SHELL != OPIHI_VERBOSE_OFF) gprint (GP_ERR, "error on line: %s\n", rawline);
    6366  }
    6467
  • branches/pap/Ohana/src/opihi/lib.shell/startup.c

    r16472 r28003  
    124124    if (LOAD_RC && !is_script) {
    125125      rcfile = get_variable ("RCFILE");
    126       sprintf (line, "input %s/%s", home, rcfile);
    127       status = command (line, &outline, TRUE);
    128       if (outline != (char *) NULL) free (outline);
     126      if (rcfile && check_file_access (rcfile, FALSE, FALSE, FALSE)) {
     127        sprintf (line, "input %s/%s", home, rcfile);
     128        status = command (line, &outline, TRUE);
     129        if (outline != (char *) NULL) free (outline);
     130        if (status) {
     131          gprint (GP_LOG, "loaded file %s\n", rcfile);
     132        }         
     133      }
    129134      if (rcfile) free (rcfile);
    130135    }
  • branches/pap/Ohana/src/opihi/pantasks/Makefile

    r26411 r28003  
    125125
    126126.PHONY: pantasks pantasks_client pantasks_server
     127
     128.PRECIOUS: $(SRC)/pantasks.c
     129.PRECIOUS: $(SRC)/pantasks_client.c
     130.PRECIOUS: $(SRC)/pantasks_server.c
  • branches/pap/Ohana/src/opihi/pantasks/pantasks.c.in

    r23530 r28003  
    1818  InitBasic ();
    1919  InitData ();
     20  InitAstro ();
    2021  InitPantasks ();
    2122
  • branches/pap/Ohana/src/opihi/pantasks/pantasks_server.c.in

    r23530 r28003  
    1313*/
    1414
     15void special_init (int *argc, char **argv);
     16
    1517/* program-dependent initialization */
    1618int main (int argc, char **argv) {
    1719 
    18   char log_stdout[128], log_stderr[128];
     20  char log_stdout[1024], log_stderr[1024];
    1921  pthread_t JobsAndTasksThread;
    2022  pthread_t clientsThread;
     
    2325  SockAddress Address;
    2426
    25   general_init (&argc, argv);
     27  strcpy (log_stdout, "stdout");
     28  strcpy (log_stderr, "stderr");
    2629
    27   // define server output log files
     30  special_init (&argc, argv);
     31
     32  //
     33  stdin = freopen ("/dev/zero", "r", stdin);
     34
     35  // this block redirects the actual stderr, stdout steams to the output files
    2836  if (VarConfig ("PANTASKS_SERVER_STDOUT", "%s", log_stdout) != NULL) {
     37    if (strcmp (log_stdout, "stdout")) {
     38      stdout = freopen (log_stdout, "a", stdout);
     39      if (!stdout) {
     40        fprintf (stderr, "failed to open %s for output\n", log_stdout);
     41        exit (1);
     42      }
     43    }
     44  }
     45  if (VarConfig ("PANTASKS_SERVER_STDERR", "%s", log_stderr) != NULL) {
     46    if (strcmp (log_stderr, "stderr")) {
     47      stderr = freopen (log_stderr, "a", stderr);
     48      if (!stderr) {
     49        fprintf (stdout, "failed to open %s for error output\n", log_stderr);
     50        exit (1);
     51      }
     52    }
     53  }
     54
     55  /* init for main (or only) thread */
     56  gprintInit ();
     57
     58  // this block changes the target of the gprint output streams
     59  if (strcmp (log_stdout, "stdout")) {
    2960      gprintSetFileThisThread (GP_LOG, log_stdout);
    3061  }
    31   if (VarConfig ("PANTASKS_SERVER_STDERR", "%s", log_stderr) != NULL) {
     62  if (strcmp (log_stderr, "stderr")) {
    3263      gprintSetFileThisThread (GP_ERR, log_stderr);
    3364  }
     
    4172  InitBasic ();
    4273  InitData ();
     74  InitAstro ();
    4375  InitPantasksServer ();
    4476
     
    105137void welcome () { }
    106138void program_init (int *argc, char **argv) {}
     139
     140// I need to do things in a different order here to have config / freopen / gprint sequenced correctly
     141void special_init (int *argc, char **argv) {
     142
     143  /* init srand for rnd numbers elsewhere */
     144  long A, B;
     145  A = time(NULL);
     146  for (B = 0; A == time(NULL); B++);
     147  srand48(B);
     148 
     149  /* set signals */
     150  signal (SIGINT, SIG_IGN);
     151
     152  init_error ();
     153
     154  /* load config data (.ptolemyrc) */
     155  if (!ConfigInit (argc, argv)) {
     156    fprintf (stderr, "can't find (.ptolemyrc,ptolemy.rc) config file. some functions will be unavailable\n");
     157  }
     158
     159  return;
     160}
  • branches/pap/Ohana/src/relastro

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/pap/Ohana/src/relphot/src/StarOps.c

    r27586 r28003  
    225225          }
    226226
     227          // XXX make it optional to apply Mcal (do I need an extra field for advisory Mcal?)
    227228          list[N] = Msys - catalog[i].measure[m].Mcal;
    228229          dlist[N] = MAX (catalog[i].measure[m].dM, MIN_ERROR);
  • branches/pap/Ohana/src/uniphot/Makefile

    r12842 r28003  
    1 default: uniphot
     1default: uniphot setphot
    22help:
    3         @echo "make options: uniphot (default)"
     3@echo "make options: uniphot setphot default help install default (uniphot setphot)"
    44
    55include ../../Makefile.System
     
    1818
    1919uniphot: $(BIN)/uniphot.$(ARCH)
    20 install: $(DESTBIN)/uniphot
     20setphot: $(BIN)/setphot.$(ARCH)
     21install: $(DESTBIN)/uniphot $(DESTBIN)/setphot
    2122
    2223UNIPHOT = \
     
    2425$(SRC)/initialize.$(ARCH).o         \
    2526$(SRC)/ConfigInit.$(ARCH).o         \
    26 $(SRC)/args.$(ARCH).o               \
     27$(SRC)/args.$(ARCH).o               \
    2728$(SRC)/liststats.$(ARCH).o          \
    2829$(SRC)/load_images.$(ARCH).o        \
     
    3940$(UNIPHOT): $(INC)/uniphot.h
    4041$(BIN)/uniphot.$(ARCH): $(UNIPHOT)
     42
     43SETPHOT = \
     44$(SRC)/setphot.$(ARCH).o            \
     45$(SRC)/initialize.$(ARCH).o         \
     46$(SRC)/ConfigInit.$(ARCH).o         \
     47$(SRC)/args.$(ARCH).o               \
     48$(SRC)/liststats.$(ARCH).o          \
     49$(SRC)/load_zpt_table.$(ARCH).o     \
     50$(SRC)/load_images.$(ARCH).o        \
     51$(SRC)/match_zpts_to_images.$(ARCH).o       \
     52$(SRC)/update_catalog_setphot.$(ARCH).o \
     53$(SRC)/SetSignals.$(ARCH).o         \
     54$(SRC)/Shutdown.$(ARCH).o           
     55
     56$(SETPHOT): $(INC)/uniphot.h
     57$(BIN)/setphot.$(ARCH): $(SETPHOT)
  • branches/pap/Ohana/src/uniphot/include/uniphot.h

    r27435 r28003  
    3939} Group;
    4040
     41typedef struct {
     42    float zpt;
     43    e_time time;
     44    int found;
     45} ZptTable;
     46
    4147/* global variables set in parameter file */
    4248char         ImageCat[256];
     
    4450char         CATMODE[16];    /* raw, mef, split, mysql */
    4551char         CATFORMAT[16];  /* internal, elixir, loneos, panstarrs */
     52char         SKY_TABLE[256];
     53int          SKY_DEPTH;  /** XXX EAM : depth of catalog tables, fix usage */
     54char         GSCFILE[256];
    4655char         STATMODE[64];
    4756int          VERBOSE;
     
    6675
    6776/***** prototypes ****/
    68 void          ConfigInit         PROTO((int *argc, char **argv));
    69 void          DonePlotting       PROTO((Graphdata *graphmode, int N));
    70 void          JpegPlot           PROTO((Graphdata *graphmode, int N, char *filename));
    71 void          PSPlot             PROTO((Graphdata *graphmode, int N, char *filename));
    72 void          PlotLabel          PROTO((char *string, int N));
    73 void          PlotVector         PROTO((int Npts, double *vect, int mode, int N));
    74 void          PrepPlotting       PROTO((int Npts, Graphdata *graphmode, int N));
    75 void          XDead              PROTO((void));
    76 int           args               PROTO((int argc, char **argv));
    77 void          dumpresult         PROTO((void));
    78 Group        *find_image_sgroups PROTO((FITS_DB *db, ImageLink **imlink, int *Nsgroup));
    79 Group        *find_image_tgroups PROTO((FITS_DB *db, ImageLink **imlink, int *Ntgroup));
    80 void          fit_sgroup         PROTO((Group *sgroup, int Nsgroup));
    81 void          fit_tgroup         PROTO((Group *tgroup, int Ntgroup));
    82 int           gcatalog           PROTO((Catalog *catalog));
    83 void          initialize         PROTO((int argc, char **argv));
    84 void          initstats          PROTO((char *mode));
    85 int           liststats          PROTO((double *value, double *dvalue, int N, StatType *stats));
    86 int           load_images        PROTO((FITS_DB *db));
    87 int           main               PROTO((int argc, char **argv));
    88 int           open_graph         PROTO((int N));
    89 void          sort               PROTO((unsigned int *X, int N));
    90 void          sortB              PROTO((double *X, double *Y, int N));
    91 void          sortD              PROTO((double *X, double *Y, double *Z, int N));
    92 void          update_dvo_catalog PROTO((Catalog *catalog, Group *sgroup, int warn));
    93 void          wcatalog           PROTO((Catalog *catalog));
    94 void          wimages            PROTO((Image *image, int Nimage));
    95 void          check_permissions  PROTO((char *basefile));
    96 void          lock_image_db      PROTO((FITS_DB *db, char *filename));
    97 void          unlock_image_db    PROTO((FITS_DB *db));
    98 void          create_image_db    PROTO((FITS_DB *db));
    99 void          set_db             PROTO((FITS_DB *in));
    100 int           Shutdown           PROTO((char *format, ...) OHANA_FORMAT(printf, 1, 2) );
    101 void          TrapSignal         PROTO((int sig));
    102 void          SetProtect         PROTO((int mode));
    103 int           SetSignals         PROTO((void));
    104 int           subset_images      PROTO((FITS_DB *db));
    105 void          update             PROTO((FITS_DB *db, Group *sgroup, int Nsgroup));
    106 void          sort_time          PROTO((unsigned int *value, int N));
     77void          ConfigInit          PROTO((int *argc, char **argv));
     78void          DonePlotting        PROTO((Graphdata *graphmode, int N));
     79void          JpegPlot            PROTO((Graphdata *graphmode, int N, char *filename));
     80void          PSPlot              PROTO((Graphdata *graphmode, int N, char *filename));
     81void          PlotLabel           PROTO((char *string, int N));
     82void          PlotVector          PROTO((int Npts, double *vect, int mode, int N));
     83void          PrepPlotting        PROTO((int Npts, Graphdata *graphmode, int N));
     84void          XDead               PROTO((void));
     85int           args_uniphot        PROTO((int argc, char **argv));
     86int           args_setphot        PROTO((int argc, char **argv));
     87void          dumpresult          PROTO((void));
     88Group        *find_image_sgroups  PROTO((FITS_DB *db, ImageLink **imlink, int *Nsgroup));
     89Group        *find_image_tgroups  PROTO((FITS_DB *db, ImageLink **imlink, int *Ntgroup));
     90void          fit_sgroup          PROTO((Group *sgroup, int Nsgroup));
     91void          fit_tgroup          PROTO((Group *tgroup, int Ntgroup));
     92int           gcatalog            PROTO((Catalog *catalog));
     93void          initialize_uniphot  PROTO((int argc, char **argv));
     94void          initialize_setphot  PROTO((int argc, char **argv));
     95void          initstats           PROTO((char *mode));
     96int           liststats           PROTO((double *value, double *dvalue, int N, StatType *stats));
     97int           load_images_uniphot PROTO((FITS_DB *db));
     98int           main                PROTO((int argc, char **argv));
     99int           open_graph          PROTO((int N));
     100void          sort                PROTO((unsigned int *X, int N));
     101void          sortB               PROTO((double *X, double *Y, int N));
     102void          sortD               PROTO((double *X, double *Y, double *Z, int N));
     103void          update_dvo_catalog  PROTO((Catalog *catalog, Group *sgroup, int warn));
     104void          wcatalog            PROTO((Catalog *catalog));
     105void          wimages             PROTO((Image *image, int Nimage));
     106void          check_permissions   PROTO((char *basefile));
     107void          lock_image_db       PROTO((FITS_DB *db, char *filename));
     108void          unlock_image_db     PROTO((FITS_DB *db));
     109void          create_image_db     PROTO((FITS_DB *db));
     110void          set_db              PROTO((FITS_DB *in));
     111int           Shutdown            PROTO((char *format, ...) OHANA_FORMAT(printf, 1, 2) );
     112void          TrapSignal          PROTO((int sig));
     113void          SetProtect          PROTO((int mode));
     114int           SetSignals          PROTO((void));
     115int           subset_images       PROTO((FITS_DB *db));
     116void          update              PROTO((FITS_DB *db, Group *sgroup, int Nsgroup));
     117void          sort_time           PROTO((unsigned int *value, int N));
     118
     119// setphot-specific prototypes
     120ZptTable     *load_zpt_table         PROTO((char *filename, int *nzpts));
     121Image        *load_images_setphot    PROTO((FITS_DB *db, off_t *Nimage));
     122int           match_zpts_to_images   PROTO((Image *image, off_t Nimage, ZptTable *zpts, int Nzpts));
     123int           update_setphot         PROTO((Image *image, off_t Nimage));
     124void          update_catalog_setphot PROTO((Catalog *catalog, Image *image, off_t *index, off_t Nimage));
  • branches/pap/Ohana/src/uniphot/src/ConfigInit.c

    r25757 r28003  
    11# include "uniphot.h"
     2
     3void GetConfig (char *config, char *field, char *format, int N, void *ptr);
    24
    35void ConfigInit (int *argc, char **argv) {
     
    1820  if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file);
    1921
    20   ScanConfig (config, "CATDIR",                 "%s",  0, CATDIR);
     22  GetConfig (config, "CATDIR",                 "%s",  0, CATDIR);
    2123  ScanConfig (config, "CATMODE",                "%s",  0, CATMODE);
    2224  ScanConfig (config, "CATFORMAT",              "%s",  0, CATFORMAT);
     
    2426
    2527  sprintf (ImageCat, "%s/Images.dat", CATDIR);
     28
     29  GetConfig (config, "GSCFILE",                 "%s",  0, GSCFILE);
     30  if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) {
     31    SKY_DEPTH = 2;
     32  }
     33  if (!ScanConfig (config, "SKY_TABLE",         "%s",  0, SKY_TABLE)) {
     34    SKY_TABLE[0] = 0;
     35  }
    2636
    2737  ScanConfig (config, "ZERO_PT",                "%lf", 0, &ZERO_POINT);
     
    4252
    4353}
     54
     55void GetConfig (char *config, char *field, char *format, int N, void *ptr) {
     56
     57  char *status;
     58
     59  status = ScanConfig (config, field, format, N, ptr);
     60  if (status == NULL) {
     61    fprintf (stderr, "error in config, cannot find %s\n", field);
     62    exit (1);
     63  }
     64  return;
     65}
  • branches/pap/Ohana/src/uniphot/src/Shutdown.c

    r7080 r28003  
    2323  SetProtect (TRUE);
    2424  gfits_db_close (db);
    25   fprintf (stderr, "ERROR: addstar halted\n");
     25  fprintf (stderr, "ERROR: halted\n");
    2626  exit (1);
    2727}
  • branches/pap/Ohana/src/uniphot/src/args.c

    r14590 r28003  
    11# include "uniphot.h"
    22
    3 int args (int argc, char **argv) {
     3int args_uniphot (int argc, char **argv) {
    44
    55  int N;
     
    7272}
    7373
     74int args_setphot (int argc, char **argv) {
     75
     76  int N;
     77
     78  VERBOSE = FALSE;
     79  if ((N = get_argument (argc, argv, "-v"))) {
     80    VERBOSE = TRUE;
     81    remove_argument (N, &argc, argv);
     82  }
     83
     84  UPDATE = FALSE;
     85  if ((N = get_argument (argc, argv, "-update"))) {
     86    remove_argument (N, &argc, argv);
     87    UPDATE = TRUE;
     88  }
     89
     90  if (argc != 2) {
     91    fprintf (stderr, "ERROR: USAGE: setphot (zptfile) [options]\n");
     92    exit (2);
     93  }
     94
     95  return (TRUE);
     96}
     97
  • branches/pap/Ohana/src/uniphot/src/initialize.c

    r2492 r28003  
    11# include "uniphot.h"
    22
    3 void initialize (int argc, char **argv) {
     3void initialize_uniphot (int argc, char **argv) {
    44
    55  /* are these set correctly? */
    66  ConfigInit (&argc, argv);
    7   args (argc, argv);
     7  args_uniphot (argc, argv);
    88
    99  if ((photcode = GetPhotcodebyName (argv[1])) == NULL) {
     
    2121}
    2222
     23void initialize_setphot (int argc, char **argv) {
     24
     25  /* are these set correctly? */
     26  ConfigInit (&argc, argv);
     27  args_setphot (argc, argv);
     28}
     29
  • branches/pap/Ohana/src/uniphot/src/load_images.c

    r6238 r28003  
    11# include "uniphot.h"
    22
    3 int load_images (FITS_DB *db) {
     3int load_images_uniphot (FITS_DB *db) {
    44
    55  if (VERBOSE) fprintf (stderr, "finding images\n");
     
    1010  return (TRUE);
    1111}
     12
     13Image *load_images_setphot (FITS_DB *db, off_t *Nimage) {
     14
     15  Image *image;
     16
     17  if (VERBOSE) fprintf (stderr, "finding images\n");
     18
     19  /* read entire db table */
     20  if (!dvo_image_load (db, VERBOSE, FALSE)) Shutdown ("can't read image catalog %s", db[0].filename);
     21
     22  /* use a vtable to keep the images to be calibrated */
     23  image = gfits_table_get_Image (&db[0].ftable, Nimage, &db[0].swapped);
     24
     25  fprintf (stderr, "loaded %lld images\n", (long long) *Nimage);
     26
     27  return (image);
     28}
  • branches/pap/Ohana/src/uniphot/src/uniphot.c

    r6238 r28003  
    99
    1010  /* get configuration info, args, lockfile */
    11   initialize (argc, argv);
     11  initialize_uniphot (argc, argv);
    1212
    1313  set_db (&db);
     
    1818
    1919  /* load images */
    20   load_images (&db);
     20  load_images_uniphot (&db);
    2121 
    2222  /* filter image list by selection */
Note: See TracChangeset for help on using the changeset viewer.