IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 21, 2014, 5:42:34 AM (12 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ps2-tc3-20130727
Files:
164 edited
40 copied

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ps2-tc3-20130727

  • branches/eam_branches/ps2-tc3-20130727/Ohana

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/GetFileMode.c

    r35416 r36680  
    1212  gfits_scan_alt (header, "SIMPLE", "%t", 1, &simple);
    1313  int haveNaxis = gfits_scan (header, "NAXIS",  "%d", 1, &Naxis);
    14   int haveCTYPE = gfits_scan (header, "CTYPE1", "%s", 1, ctype);
     14  int haveCTYPE = gfits_scan (header, "CTYPE2", "%s", 1, ctype);
    1515
    1616  gfits_scan_alt (header, "EXTEND", "%t", 1, &extend);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/LoadDataPMM.c

    r34088 r36680  
    193193
    194194    // XXX for now, we define a totally fake coordinate system centered on the plate center
    195     strcpy (image[0].coords.ctype, "RA---TAN");
     195    strcpy (image[0].coords.ctype, "DEC--TAN");
    196196   
    197197    image[0].coords.crval1  = pmm_get_ra (RA);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/ReadStarsSDSS.c

    r34088 r36680  
    201201   
    202202    // XXX for now, we define a totally fake coordinate system centered on the first listed star
    203     strcpy (images[N].coords.ctype, "RA---TAN");
     203    strcpy (images[N].coords.ctype, "DEC--TAN");
    204204   
    205205    images[N].coords.crval1 = stars[0].average.R;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/fakeimage.c

    r30613 r36680  
    3434
    3535  /* create a mosaic distortion structure */
    36   strcpy (MOSAIC.ctype, "RA---DIS");
     36  strcpy (MOSAIC.ctype, "DEC--DIS");
    3737  MOSAIC.crval1 = FAKE_RA;
    3838  MOSAIC.crval2 = FAKE_DEC;
     
    8686    strcpy (image[i+1].name, name);
    8787
    88     strcpy (image[i+1].coords.ctype, "RA---WRP");
     88    strcpy (image[i+1].coords.ctype, "DEC--WRP");
    8989   
    9090    image[i+1].coords.crval1 = dX*pixscale;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/find_matches.c

    r34361 r36680  
    6565  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    6666  tcoords.Npolyterms = 1;
    67   strcpy (tcoords.ctype, "RA---ARC");
     67  strcpy (tcoords.ctype, "DEC--ARC");
    6868
    6969  /* build spatial index (RA sort) referencing input array sequence */
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/find_matches_closest.c

    r34361 r36680  
    6464  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    6565  tcoords.Npolyterms = 1;
    66   strcpy (tcoords.ctype, "RA---ARC");
     66  strcpy (tcoords.ctype, "DEC--ARC");
    6767
    6868  /* build spatial index (RA sort) referencing input array sequence */
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/find_matches_closest_refstars.c

    r34361 r36680  
    5959  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    6060  tcoords.Npolyterms = 0;
    61   strcpy (tcoords.ctype, "RA---ARC");
     61  strcpy (tcoords.ctype, "DEC--ARC");
    6262 
    6363  /* build spatial index (RA sort) referencing input array sequence */
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/find_matches_refstars.c

    r34260 r36680  
    5757  tcoords.pc1_1 = tcoords.pc2_2 = 1.0;
    5858  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    59   strcpy (tcoords.ctype, "RA---ZEA");
     59  strcpy (tcoords.ctype, "DEC--ZEA");
    6060  tcoords.Npolyterms = 0;
    6161 
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/findskycell.c

    r34844 r36680  
    1212// in an even more specific case, RA[i,zone] = RA_origin[zone] + RA_offset[zone]
    1313
    14 enum {TREE_NONE, TREE_MAKE, TREE_USE};
     14enum {TREE_NONE, TREE_MAKE, TREE_LOCAL, TREE_USE};
     15enum {REGION_NONE, REGION_USER, REGION_MIN, REGION_MAX};
    1516
    1617void usage (void) {
    1718  fprintf (stderr, "USAGE: findcell -mktree (tree) (catdir) [-nx Nx] [-ny Ny]\n");
     19  fprintf (stderr, "USAGE: findcell -mklocal (file) (catdir) [-nx Nx] [-ny Ny]\n");
    1820  fprintf (stderr, "USAGE: findcell -tree (tree) (datafile)\n");
    1921  fprintf (stderr, "   (datafile) should contain a list of RA,DEC pairs\n");
     
    2224
    2325int mktree (char *treefile, char *catdir);
     26int mklocal (char *treefile, char *catdir);
    2427int apply_tree (char *treefile, char *datafile);
    2528
     
    2831int NY_SUB = 1;
    2932
     33double R_MIN = 0.0;
     34double R_MAX = 0.0;
     35double D_MIN = 0.0;
     36double D_MAX = 0.0;
     37int REGION_OPTION = REGION_NONE;
     38
     39char *BASENAME = NULL;
     40int projectIDoff = -1;
     41int skycellIDoff = -1;
     42
     43int APPEND = FALSE;
     44
    3045int main (int argc, char **argv) {
    3146
     
    4257  if (get_argument (argc, argv, "-h")) usage ();
    4358
    44   NX_SUB = NY_SUB = 1;
    4559  if ((N = get_argument (argc, argv, "-nx"))) {
    4660    remove_argument (N, &argc, argv);
     
    5569
    5670  /* pixel scale (arcsec/pixel) */
    57   SCALE = 1.0;
    5871  if ((N = get_argument (argc, argv, "-scale"))) {
    5972    remove_argument (N, &argc, argv);
    6073    SCALE = atof (argv[N]);
     74    remove_argument (N, &argc, argv);
     75  }
     76
     77  /* pixel scale (arcsec/pixel) */
     78  if ((N = get_argument (argc, argv, "-append"))) {
     79    remove_argument (N, &argc, argv);
     80    APPEND = TRUE;
     81  }
     82
     83  // user-specified region
     84  R_MIN = NAN;
     85  R_MAX = NAN;
     86  D_MIN = NAN;
     87  D_MAX = NAN;
     88  if ((N = get_argument (argc, argv, "-region"))) {
     89    remove_argument (N, &argc, argv);
     90    if (N > argc - 4) {
     91      fprintf (stderr, "USAGE: -region requires 4 arguments (Rmin Rmax Dmin Dmax)\n");
     92      exit (1);
     93    }
     94    R_MIN = atof (argv[N]); remove_argument (N, &argc, argv);
     95    R_MAX = atof (argv[N]); remove_argument (N, &argc, argv);
     96    D_MIN = atof (argv[N]); remove_argument (N, &argc, argv);
     97    D_MAX = atof (argv[N]); remove_argument (N, &argc, argv);
     98    REGION_OPTION = REGION_USER;
     99  }
     100
     101  if ((N = get_argument (argc, argv, "-region-min"))) {
     102    remove_argument (N, &argc, argv);
     103    REGION_OPTION = REGION_MIN;
     104  }
     105
     106  if ((N = get_argument (argc, argv, "-region-max"))) {
     107    remove_argument (N, &argc, argv);
     108    REGION_OPTION = REGION_MAX;
     109  }
     110
     111  if ((N = get_argument (argc, argv, "-basename"))) {
     112    remove_argument (N, &argc, argv);
     113    if (N > argc - 3) {
     114      fprintf (stderr, "USAGE: -basename (name) (proj_offset) (skycell_offset)\n");
     115      exit (1);
     116    }
     117    BASENAME = strcreate  (argv[N]);
     118    remove_argument (N, &argc, argv);
     119    projectIDoff = atoi(argv[N]);
     120    remove_argument (N, &argc, argv);
     121    skycellIDoff = atoi(argv[N]);
    61122    remove_argument (N, &argc, argv);
    62123  }
     
    70131    remove_argument (N, &argc, argv);
    71132  }
     133  if ((N = get_argument (argc, argv, "-mklocal"))) {
     134    MODE = TREE_LOCAL;
     135    remove_argument (N, &argc, argv);
     136    treefile = strcreate (argv[N]);
     137    remove_argument (N, &argc, argv);
     138  }
    72139  if ((N = get_argument (argc, argv, "-tree"))) {
    73140    MODE = TREE_USE;
     
    83150  if (MODE == TREE_MAKE) {
    84151    mktree (treefile, argv[1]);
     152    exit (0);
     153  }
     154
     155  if (MODE == TREE_LOCAL) {
     156    mklocal (treefile, argv[1]);
    85157    exit (0);
    86158  }
     
    348420  MARKTIME("-- test %d pts: %f sec\n", Npts, dtime);
    349421
    350   BoundaryTreeSave (treefile, &tree);
     422  if (APPEND) {
     423    int Ntess = 0;
     424    TessellationTable *tess = TessellationTableLoad (treefile, &Ntess);
     425    REALLOCATE (tess, TessellationTable, Ntess + 1);
     426    TessellationTableInit (&tess[Ntess], 1);
     427    tess[Ntess].tree = &tree;
     428    tess[Ntess].type = TESS_RINGS;
     429    tess[Ntess].Rmin =   0;
     430    tess[Ntess].Rmax = 360;
     431    tess[Ntess].Dmin = -90;
     432    tess[Ntess].Dmax = +90;
     433
     434    if (BASENAME) {
     435      tess[Ntess].Nbasename = strlen(BASENAME);
     436      tess[Ntess].basename = strcreate(BASENAME);
     437      tess[Ntess].projectIDoff = projectIDoff;
     438      tess[Ntess].skycellIDoff = skycellIDoff;
     439    }
     440     
     441    // add basename an related here...
     442    Ntess ++;
     443    TessellationTableSave (treefile, tess, Ntess);
     444  } else {
     445    BoundaryTreeSave (treefile, &tree);
     446  }
    351447
    352448  return TRUE;
     
    354450
    355451int apply_tree (char *treefile, char *datafile) {
     452
     453  int Ntess = 0;
     454  TessellationTable *tess = TessellationTableLoad (treefile, &Ntess);
     455  if (!tess) {
     456    fprintf (stderr, "error loading tessellation table file %s\n", treefile);
     457    exit (2);
     458  }
     459
     460  FILE *f = fopen (datafile, "r");
     461  if (!f) {
     462    fprintf (stderr, "error opening data file %s\n", datafile);
     463    exit (3);
     464  }
     465
     466  double ra, dec;
     467  int Nvalue = 0;
     468  while ((Nvalue = fscanf (f, "%lf %lf", &ra, &dec)) != EOF) {
     469
     470    int tessID, projID, skycellID;
     471
     472    if (!TessellationPrimaryCellIDs (tess, Ntess, &tessID, &projID, &skycellID, ra, dec)) {
     473      fprintf (stderr, "error finding cell for %f,%f\n", ra, dec);
     474      continue;
     475    }
     476
     477    fprintf (stdout, "%10.6f %10.6f : %2d  %04d %03d : %s\n", ra, dec, tessID, projID, skycellID, tess[tessID].basename);
     478  }
     479
     480  exit (0);
     481}
     482
     483int apply_tree_old (char *treefile, char *datafile) {
    356484
    357485  BoundaryTree *tree = BoundaryTreeLoad (treefile);
     
    405533}
    406534
     535// a given tess is defined by a catdir (more than one per catdir?)
     536// this function takes a catdir and generates an extension for a tess file for a local tess.
     537
     538/*
     539
     540  LOCAL projections are defined by single projection cells.  should I be supplying the info on
     541  the cmd line or figure out the bounds from the catdir? 
     542
     543 */
     544
     545int mklocal (char *treefile, char *catdir) {
     546
     547  int i, j, status;
     548  FITS_DB db;
     549  Image *image;
     550  off_t Nimage;
     551  double x, y, ra, dec;
     552
     553  if (REGION_OPTION == REGION_NONE) {
     554    fprintf (stderr, "ERROR: need to define bounding region (-region Rmin Rmax Dmin Dmax | -region-min | -region-max)\n");
     555    exit (2);
     556  }
     557
     558  if (!BASENAME) {
     559    fprintf (stderr, "ERROR: need to define BASENAME -basename (name) (proj_offset) (skycell_offset)\n");
     560    exit (2);
     561  }
     562
     563  char imagefile[DVO_MAX_PATH];
     564  snprintf (imagefile, DVO_MAX_PATH, "%s/Images.dat", catdir);
     565
     566  status = dvo_image_lock (&db, imagefile, 2.0, LCK_XCLD);
     567  if (!status) Shutdown ("ERROR: failure to lock image catalog %s", db.filename);
     568
     569  /* load or create the image table */
     570  if (db.dbstate == LCK_EMPTY) Shutdown ("can't read image catalog %s", db.filename);
     571
     572  if (!dvo_image_load (&db, TRUE, FALSE)) Shutdown ("can't read image catalog %s", db.filename);
     573
     574  // convert database table to internal structure (binary to Image)
     575  // 'image' points to the same memory as db->ftable->buffer
     576  image = gfits_table_get_Image (&db.ftable, &Nimage, &db.swapped);
     577  if (!image) {
     578    fprintf (stderr, "ERROR: failed to read images\n");
     579    exit (2);
     580  }
     581 
     582  // generate an empty BoundaryTree
     583  TessellationTable *tess = NULL;
     584
     585  int NtessDisk = 0;
     586  if (APPEND) {
     587    tess = TessellationTableLoad (treefile, &NtessDisk);
     588    REALLOCATE (tess, TessellationTable, Nimage + NtessDisk);
     589  } else {
     590    ALLOCATE (tess, TessellationTable, Nimage + NtessDisk);
     591  }
     592
     593  TessellationTableInit (&tess[NtessDisk], Nimage);
     594
     595  // find the RA,DEC of the image centers & assign to cells
     596  int Ntess = NtessDisk;
     597  for (i = 0; i < Nimage; i++) {
     598    // user supplied values, do not try to derive from Image.dat
     599    tess[Ntess].NX_SUB = NX_SUB;
     600    tess[Ntess].NY_SUB = NY_SUB;
     601    tess[Ntess].dPix = SCALE/3600.0;
     602
     603    x = 0.5*image[i].NX;
     604    y = 0.5*image[i].NY;
     605    XY_to_RD (&ra, &dec, x, y, &image[i].coords);
     606
     607    tess[Ntess].Ro  = ra;
     608    tess[Ntess].Do  = dec;
     609    tess[Ntess].Xo  = x;
     610    tess[Ntess].Yo  = y;
     611    tess[Ntess].dX  = image[i].NX / NX_SUB;
     612    tess[Ntess].dY  = image[i].NY / NY_SUB;
     613
     614    // find the minimum or maximum containing region
     615    if ((REGION_OPTION == REGION_MIN) || (REGION_OPTION == REGION_MAX)) {
     616      // XXX short cut for now : if the projection cell bounds the equator or 0,360 boundary, this will fail:
     617      double R[4], D[4];
     618      XY_to_RD (&R[0], &D[0],           0,           0, &image[i].coords);
     619      XY_to_RD (&R[1], &D[1], image[i].NX,           0, &image[i].coords);
     620      XY_to_RD (&R[2], &D[2],           0, image[i].NY, &image[i].coords);
     621      XY_to_RD (&R[3], &D[3], image[i].NX, image[i].NY, &image[i].coords);
     622
     623      if (REGION_OPTION == REGION_MIN) {
     624        for (j = 0; j < 4; j++) {
     625          R_MIN = (R[j] < ra)  ? (isfinite(R_MIN) ? MAX(R_MIN, R[j]) : R[j]) : R_MIN;
     626          R_MAX = (R[j] > ra)  ? (isfinite(R_MAX) ? MIN(R_MAX, R[j]) : R[j]) : R_MAX;
     627          D_MIN = (D[j] < dec) ? (isfinite(D_MIN) ? MAX(D_MIN, D[j]) : D[j]) : D_MIN;
     628          D_MAX = (D[j] > dec) ? (isfinite(D_MAX) ? MIN(D_MAX, D[j]) : D[j]) : D_MAX;
     629        }
     630      } else {
     631        for (j = 0; j < 4; j++) {
     632          R_MIN = (R[j] < ra)  ? (isfinite(R_MIN) ? MIN(R_MIN, R[j]) : R[j]) : R_MIN;
     633          R_MAX = (R[j] > ra)  ? (isfinite(R_MAX) ? MAX(R_MAX, R[j]) : R[j]) : R_MAX;
     634          D_MIN = (D[j] < dec) ? (isfinite(D_MIN) ? MIN(D_MIN, D[j]) : D[j]) : D_MIN;
     635          D_MAX = (D[j] > dec) ? (isfinite(D_MAX) ? MAX(D_MAX, D[j]) : D[j]) : D_MAX;
     636        }
     637      }
     638    }
     639    tess[Ntess].Rmin = R_MIN;
     640    tess[Ntess].Rmax = R_MAX;
     641    tess[Ntess].Dmin = D_MIN;
     642    tess[Ntess].Dmax = D_MAX;
     643
     644    tess[Ntess].type = TESS_LOCAL;
     645
     646    // XXX I don't really want to do the work of discovering the rule...
     647    tess[Ntess].Nbasename = strlen(BASENAME);
     648    tess[Ntess].basename = strcreate(BASENAME);
     649
     650    tess[Ntess].projectIDoff = projectIDoff;
     651    tess[Ntess].skycellIDoff = skycellIDoff;
     652
     653    Ntess ++;
     654  }
     655
     656  TessellationTableSave (treefile, tess, Ntess);
     657
     658  return TRUE;
     659}
     660
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/loadsupercos_plates.c

    r33653 r36680  
    118118
    119119    // for now, we define a fake coordinate system based on the boresite center
    120     strcpy (image[Nimage].coords.ctype, "RA---TAN");
     120    strcpy (image[Nimage].coords.ctype, "DEC--TAN");
    121121   
    122122    image[Nimage].coords.crval1 = RAo;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/addstar/src/sky_tessalation.c

    r34844 r36680  
    11061106  refcoords[0].Npolyterms = 0;
    11071107  memset (refcoords[0].polyterms, 0, 14*sizeof(float));
    1108   strcpy (refcoords[0].ctype, "RA---TAN");
     1108  strcpy (refcoords[0].ctype, "DEC--TAN");
    11091109  return (TRUE);
    11101110}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvo_image_merge_dbs.c

    r34277 r36680  
    167167  off_t i, oldID, newID;
    168168
     169  if (!IDmap->old) {
     170    fprintf (stderr, "input database has image IDs, but no Image table\n");
     171    return FALSE;
     172  }
     173
     174  off_t lastID = IDmap->old[IDmap->Nmap-1];
     175
    169176  for (i = 0; i < catalog[0].Nmeasure; i++) {
    170177    oldID = catalog[0].measure[i].imageID;
    171178    if (oldID == 0) continue;
    172179
    173     if (!IDmap->old) {
    174       fprintf (stderr, "input database has image IDs, but no Image table\n");
    175     }
    176 
    177180    newID = dvo_map_image_ID (IDmap, oldID);
    178181    if (newID == 0) {
     182      if (oldID > lastID) {
     183        fprintf (stderr, "problem with image IDs : input out of range\n");
     184        fprintf (stderr, "old ID: "OFF_T_FMT", last ID: "OFF_T_FMT"\n", oldID, lastID);
     185        exit (2);
     186      }
    179187      if (!IDmap->notFound[oldID]) {
    180188        fprintf (stderr, "cannot find image ID "OFF_T_FMT"\n",  oldID);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvomergeUpdate.c

    r35765 r36680  
    111111  SetPhotcodeTable(NULL);
    112112
    113   dvomergeUpdate_catalogs (input, output, outsky, inlist, NsecfiltInput, NsecfiltOutput, &IDmap, secfiltMap);
     113  int status = dvomergeUpdate_catalogs (input, output, outsky, inlist, NsecfiltInput, NsecfiltOutput, &IDmap, secfiltMap);
    114114
    115115  // save the output sky table copy
     
    123123  gettimeofday (&stop, NULL);
    124124  dtime = DTIME (stop, start);
     125
     126  if (!status) {
     127    fprintf (stderr, "ERROR: elapsed time %9.4f sec\n", dtime);
     128    exit (3);
     129  }
     130
    125131  fprintf (stderr, "SUCCESS: elapsed time %9.4f sec\n", dtime);
    126 
    127132  exit (0);
    128133}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c

    r35765 r36680  
    140140    }
    141141
     142    dvo_update_image_IDs (IDmap, &incatalog);
     143
    142144    // merge input into the appropriate output tables
    143145    for (j = 0; j < outlist[0].Nregions; j++) {
     
    156158      LoadCatalog (&outcatalog, outlist[0].regions[j], outcatalog.filename, "w", NsecfiltOutput);
    157159
    158       dvo_update_image_IDs (IDmap, &incatalog);
    159160      merge_catalogs_old (outlist[0].regions[j], &outcatalog, &incatalog, RADIUS, secfiltMap);
    160161
    161162      outcatalog.catflags = LOAD_AVES | LOAD_MEAS | LOAD_MISS | LOAD_SECF;
    162163
    163       if (outstat[i].missed) {
     164      if (outstat[j].missed) {
    164165        dmhObjectAdd (outstat[j].history, &outcatalog.header, inStats);
    165166      }
     
    248249    if (FORCE_MERGE)         { snprintf (tmpline, DVO_MAX_PATH, "%s -force-merge",     command); strcpy (command, tmpline); }
    249250
     251    // add some config variables:
     252    snprintf (tmpline, DVO_MAX_PATH, "%s -D CATMODE %s",    command, CATMODE);   strcpy (command, tmpline);
     253    snprintf (tmpline, DVO_MAX_PATH, "%s -D CATFORMAT %s",  command, CATFORMAT); strcpy (command, tmpline);
     254    snprintf (tmpline, DVO_MAX_PATH, "%s -D SKY_DEPTH %d",  command, SKY_DEPTH); strcpy (command, tmpline);
     255
    250256    fprintf (stderr, "command: %s\n", command);
    251257
     
    275281  }
    276282  if (!PARALLEL_MANUAL && !PARALLEL_SERIAL) {
    277     HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE);
     283    int status = HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE);
     284    if (!status) {
     285      fprintf (stderr, "error running one of the remote clients\n");
     286      return status;
     287    }
    278288  }
    279289
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvoverify_args.c

    r34405 r36680  
    5656  }
    5757
     58  /*** dvoverify -parallel (dvoverify_client, actually) ignores this argument
     59       dvoverify should save a subset table of just the IDs, and dvoverify_client should load it
     60       dvoverify -cpt should have CHECK_IMAGE_ID = F as default ***/
     61       
    5862  CHECK_IMAGE_ID = TRUE;
    5963  if ((N = get_argument (*argc, argv, "-skip-image-ids"))) {
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvoverify_catalogs.c

    r34405 r36680  
    143143      continue;
    144144    }
    145     fscanf (results, "%*s %d %*s %d", &NbadHost, &NNotSortedHost);
     145    int Nresults = fscanf (results, "%*s %d %*s %d", &NbadHost, &NNotSortedHost);
     146    if (Nresults != 2) {
     147      fprintf (stderr, "warning: failure scanning results\n");
     148      fclose (results);
     149      continue;
     150    }
    146151    *Nbad += NbadHost;
    147152    NNotSorted += NNotSortedHost;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/dvoverify_utils.c

    r35457 r36680  
    302302    for (j = 0; j < catalog[0].average[i].Nmeasure; j++) {
    303303      id = catalog[0].measure[m+j].imageID;
     304      if (id == 0) continue; // detections from ref photcodes can (should) have unset image IDs
    304305      if (id > maxID) {
    305306        Nfail ++;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvomerge/src/merge_catalogs_old.c

    r35416 r36680  
    7676  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    7777  tcoords.Npolyterms = 1;
    78   strcpy (tcoords.ctype, "RA---ARC");
     78  strcpy (tcoords.ctype, "DEC--ARC");
    7979
    8080  if (VERBOSE) fprintf (stderr, "merging %s into %s\n", input[0].filename, output[0].filename);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvopsps/include/dvopsps.h

    r35578 r36680  
    33# include <signal.h>
    44# include "mysql.h"
     5# include "limits.h"
    56
    67# define DVO_MAX_PATH 1024
     
    3839int          PARALLEL_MANUAL;
    3940int          PARALLEL_SERIAL;
     41
     42char        *TIME_START;
     43char        *TIME_END;
     44
     45int          PHOTCODE_START;
     46int          PHOTCODE_END;
    4047
    4148char        *SINGLE_CPT;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvopsps/src/initialize_dvopsps.c

    r35206 r36680  
    22
    33void usage_dvopsps () {
    4   fprintf (stderr, "USAGE: dvopsps (mode) [dbinfo] (mode) [options]\n");
     4  fprintf (stderr, "USAGE: dvopsps (mode) [dbinfo] [options]\n");
    55  fprintf (stderr, "    mysql database info is supplied with these:\n");
    66  fprintf (stderr, "    -dbhost : database host machine\n");
     
    1111  fprintf (stderr, "    -v : verbose mode\n");
    1212  fprintf (stderr, "    -region Rmin Rmax Dmin Dmax\n");
     13  fprintf (stderr, "    -cpt n0000/0000.00 : limit to the named cpt file\n");
    1314  fprintf (stderr, "    -parallel : run in parallel mode\n");
     15  fprintf (stderr, "    -insert-remote : in parallel mode, the client sends the data to the dbhost\n");
     16  fprintf (stderr, "    -time-start YYYY/MM/DD,hh:mm:ss : limit detections to >= this time\n");
     17  fprintf (stderr, "    -time-end   YYYY/MM/DD,hh:mm:ss : limit detections to <  this time\n");
     18
     19  fprintf (stderr, "    -photcode-start NN : limit detections to >= this photcode number\n");
     20  fprintf (stderr, "    -photcode-end   NN : limit detections to <  this photcode number\n");
     21  fprintf (stderr, "\n");
     22
     23  fprintf (stderr, " (mode) is one of detections, objects, skytable\n");
     24
     25  fprintf (stderr, "\n");
    1426  fprintf (stderr, "    -h     : this help list\n");
    1527  fprintf (stderr, "    -help  : this help list\n");
    1628  fprintf (stderr, "    --h    : this help list\n");
    1729  fprintf (stderr, "    --help : this help list\n");
     30
    1831  fprintf (stderr, "    Note that the dvo db can be specified by -D CATDIR (directory)\n");
    1932  exit (2);
     
    110123  if ((N = get_argument (argc, argv, "-insert-remote"))) {
    111124    SAVE_REMOTE = FALSE;
     125    remove_argument (N, &argc, argv);
     126  }
     127
     128  TIME_START = NULL;
     129  if ((N = get_argument (argc, argv, "-time-start"))) {
     130    remove_argument (N, &argc, argv);
     131    TIME_START = strcreate(argv[N]);
     132    remove_argument (N, &argc, argv);
     133    time_t TIME_START_SEC;
     134    if (!ohana_str_to_time (TIME_START, &TIME_START_SEC)) {
     135      fprintf (stderr, "error with starting time given by -time-start: %s\n", TIME_START);
     136      exit (2);
     137    }
     138  }
     139
     140  TIME_END = NULL;
     141  if ((N = get_argument (argc, argv, "-time-end"))) {
     142    remove_argument (N, &argc, argv);
     143    TIME_END = strcreate(argv[N]);
     144    remove_argument (N, &argc, argv);
     145    time_t TIME_END_SEC;
     146    if (!ohana_str_to_time (TIME_END, &TIME_END_SEC)) {
     147      fprintf (stderr, "error with starting time given by -time-end: %s\n", TIME_END);
     148      exit (2);
     149    }
     150  }
     151
     152  PHOTCODE_START = 0;
     153  if ((N = get_argument (argc, argv, "-photcode-start"))) {
     154    remove_argument (N, &argc, argv);
     155    PHOTCODE_START = atoi(argv[N]);
     156    remove_argument (N, &argc, argv);
     157  }
     158
     159  PHOTCODE_END = INT_MAX;
     160  if ((N = get_argument (argc, argv, "-photcode-end"))) {
     161    remove_argument (N, &argc, argv);
     162    PHOTCODE_END = atoi(argv[N]);
    112163    remove_argument (N, &argc, argv);
    113164  }
     
    260311  }
    261312
     313  TIME_START = NULL;
     314  if ((N = get_argument (argc, argv, "-time-start"))) {
     315    remove_argument (N, &argc, argv);
     316    TIME_START = strcreate(argv[N]);
     317    remove_argument (N, &argc, argv);
     318    time_t TIME_START_SEC;
     319    if (!ohana_str_to_time (TIME_START, &TIME_START_SEC)) {
     320      fprintf (stderr, "error with starting time given by -time-start: %s\n", TIME_START);
     321      exit (2);
     322    }
     323  }
     324
     325  TIME_END = NULL;
     326  if ((N = get_argument (argc, argv, "-time-end"))) {
     327    remove_argument (N, &argc, argv);
     328    TIME_END = strcreate(argv[N]);
     329    remove_argument (N, &argc, argv);
     330    time_t TIME_END_SEC;
     331    if (!ohana_str_to_time (TIME_END, &TIME_END_SEC)) {
     332      fprintf (stderr, "error with starting time given by -time-end: %s\n", TIME_END);
     333      exit (2);
     334    }
     335  }
     336
     337  PHOTCODE_START = 0;
     338  if ((N = get_argument (argc, argv, "-photcode-start"))) {
     339    remove_argument (N, &argc, argv);
     340    PHOTCODE_START = atoi(argv[N]);
     341    remove_argument (N, &argc, argv);
     342  }
     343
     344  PHOTCODE_END = INT_MAX;
     345  if ((N = get_argument (argc, argv, "-photcode-end"))) {
     346    remove_argument (N, &argc, argv);
     347    PHOTCODE_END = atoi(argv[N]);
     348    remove_argument (N, &argc, argv);
     349  }
     350
    262351  VERBOSE = FALSE;
    263352  if ((N = get_argument (argc, argv, "-v"))) {
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvopsps/src/insert_detections_dvopsps.c

    r35804 r36680  
    152152    if (VERBOSE)     { snprintf (tmpline, 1024, "%s -v",       command);                          strcpy (command, tmpline); }
    153153    if (SAVE_REMOTE) { snprintf (tmpline, 1024, "%s -save %s", command, table->hosts[i].results); strcpy (command, tmpline); }
     154
     155    // some filters -- these are the detections we skip
     156    if (TIME_START) { snprintf (tmpline, 1024, "%s -time-start %s", command, TIME_START); strcpy (command, tmpline); }
     157    if (TIME_END)   { snprintf (tmpline, 1024, "%s -time-end %s",   command, TIME_END);   strcpy (command, tmpline); }
     158   
     159    if (PHOTCODE_START > 0)      { snprintf (tmpline, 1024, "%s -photcode-start %d", command, PHOTCODE_START); strcpy (command, tmpline); }
     160    if (PHOTCODE_END <= INT_MAX) { snprintf (tmpline, 1024, "%s -photcode-end %d",   command, PHOTCODE_END);   strcpy (command, tmpline); }
    154161
    155162    fprintf (stderr, "command: %s\n", command);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/dvopsps/src/insert_detections_dvopsps_catalog.c

    r35777 r36680  
    2929  }
    3030
     31  time_t TIME_START_SEC = 0;
     32  time_t TIME_END_SEC   = 0;
     33  if (TIME_START) ohana_str_to_time (TIME_START, &TIME_START_SEC); // we validate this in the args.c
     34  if (TIME_END)   ohana_str_to_time (TIME_END,   &TIME_END_SEC);   // we validate this in the args.c
     35
    3136  for (i = 0; i < catalog[0].Naverage; i++) {
    3237
     
    4045      Average *average = &catalog->average[i];
    4146      Measure *measure = &catalog->measure[m + j];
     47
     48      // some filters -- these are the detections we skip
     49      if (TIME_START && (measure->t < TIME_START_SEC)) continue;
     50      if (TIME_END   && (measure->t >=  TIME_END_SEC)) continue;
     51
     52      if (measure->photcode < PHOTCODE_START) continue;
     53      if (measure->photcode >=  PHOTCODE_END) continue;
     54
    4255      PhotCode *code = GetPhotcodebyCode(measure->photcode);
    4356
     
    87100}
    88101
     102time_t TIME_START_SEC = 0;
     103time_t TIME_END_SEC   = INT_MAX;
     104
    89105int insert_detections_dvopsps_catalog (Catalog *catalog, MYSQL *mysql) {
    90106
     
    108124  int status = TRUE;
    109125
     126  if (TIME_START) ohana_str_to_time (TIME_START, &TIME_START_SEC); // we validate this in the args.c
     127  if (TIME_END)   ohana_str_to_time (TIME_END,   &TIME_END_SEC);   // we validate this in the args.c
     128
    110129  // NOTE for testing, just do a few objects
    111130  if (!mysql) {
     
    121140    for (j = 0; j < average[i].Nmeasure; j++) {
    122141
     142      off_t Nmeas = m + j;
     143
     144      // some filters -- these are the detections we skip (not an error, just skipped)
     145      if (TIME_START && (measure[Nmeas].t < TIME_START_SEC)) continue;
     146      if (TIME_END   && (measure[Nmeas].t >=  TIME_END_SEC)) continue;
     147 
     148      if (measure[Nmeas].photcode < PHOTCODE_START) continue;
     149      if (measure[Nmeas].photcode >=  PHOTCODE_END) continue;
     150
    123151      // XXX check return status
    124       if (!insert_detections_mysql_value (&buffer, &average[i], &measure[m+j])) {
     152      if (!insert_detections_mysql_value (&buffer, &average[i], &measure[Nmeas])) {
    125153        fprintf (stderr, "failure to insert detections in mysql\n");
    126154        status = FALSE;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/fixcat/src/gcatstats.c

    r27435 r36680  
    5252  catstats[0].coords.pc1_1 = catstats[0].coords.pc2_2 = 1.0;
    5353  catstats[0].coords.pc1_2 = catstats[0].coords.pc2_1 = 0.0;
    54   strcpy (catstats[0].coords.ctype, "RA---TAN");
     54  strcpy (catstats[0].coords.ctype, "DEC--TAN");
    5555
    5656  X1 = catstats[0].X;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/gastro/src/gstars.c

    r34088 r36680  
    7979  if (!strcasecmp (ROUGH_ASTROMETRY, "config")) {
    8080    /* default values for coords */
    81     strcpy (coords[0].ctype, "RA---TAN");
     81    strcpy (coords[0].ctype, "DEC--TAN");
    8282    coords[0].pc1_1 = CCD_PC1_1; coords[0].pc1_2 = CCD_PC1_2;
    8383    coords[0].pc2_1 = CCD_PC2_1; coords[0].pc2_2 = CCD_PC2_2;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/gastro2/src/coordtest.c

    r8300 r36680  
    8585  fit_eval ();
    8686
    87   strcpy (coords.ctype, "RA---PLY");
     87  strcpy (coords.ctype, "DEC--PLY");
    8888  coords.crval1 = 0.0;
    8989  coords.crval2 = 0.0;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/gastro2/src/gstars2.c

    r34088 r36680  
    2828
    2929  /* default values for coords */
    30   strcpy (Target[0].coords.ctype, "RA---TAN");
     30  strcpy (Target[0].coords.ctype, "DEC--TAN");
    3131  Target[0].coords.pc1_1 = CCD_PC1_1; Target[0].coords.pc1_2 = CCD_PC1_2;
    3232  Target[0].coords.pc2_1 = CCD_PC2_1; Target[0].coords.pc2_2 = CCD_PC2_2;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/getstar/src/GetFileMode.c

    r34088 r36680  
    1010  gfits_scan_alt (header, "SIMPLE", "%t", 1, &simple);
    1111  haveNaxis = gfits_scan (header, "NAXIS",  "%d", 1, &Naxis);
    12   haveCTYPE = gfits_scan (header, "CTYPE1", "%s", 1, ctype);
     12  haveCTYPE = gfits_scan (header, "CTYPE2", "%s", 1, ctype);
    1313
    1414  gfits_scan_alt (header, "EXTEND", "%t", 1, &extend);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/getstar/src/MatchImages.c

    r34430 r36680  
    3636    tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    3737    tcoords.Npolyterms = 1;
    38     strcpy (tcoords.ctype, "RA---TAN");
     38    strcpy (tcoords.ctype, "DEC--TAN");
    3939    /* register so image->sky conversions below have correct mosaic */
    4040  } else {
     
    4444    tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    4545    tcoords.Npolyterms = 1;
    46     strcpy (tcoords.ctype, "RA---TAN");
     46    strcpy (tcoords.ctype, "DEC--TAN");
    4747  }
    4848
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/getstar/src/dvoImagesAtCoords.c

    r33658 r36680  
    99static int makePoint(double ra, double dec, Point **pointsOut);
    1010static int ListImagesAtCoords (Image *dbImages, Point *points, int Npoints);
     11static int readPointFromFile(FILE *f, Point *pt);
    1112
    1213int main (int argc, char **argv) {
     
    1516  int status;
    1617  Image *dbImages;
    17   int Npoints;
    1818  FITS_DB db;
    1919
     
    2222  args_coords (argc, argv);
    2323 
    24   Point *points;
     24  Point *points = NULL;
     25  int readStdin = 0;
     26  int Npoints = 0;
    2527  if (coordsFile) {
    26       Npoints = readPoints(coordsFile, &points);
     28      if (strcmp(coordsFile, "-") == 0) {
     29        readStdin = 1;
     30      } else {
     31        Npoints = readPoints(coordsFile, &points);
     32      }
    2733  } else {
    2834      Npoints = makePoint(cmd_line_ra, cmd_line_dec, &points);
    2935  }
    30   if (!Npoints) {
     36  if (!Npoints && !readStdin) {
    3137    exit(1);
    3238  }
     
    6167  }
    6268 
    63   if (MatchCoords (dbImages, NdbImages, points, Npoints)) {
    64     ListImagesAtCoords(dbImages, points, Npoints);
    65     exit(0);
     69  if (readStdin) {
     70    Point pt;
     71    memset(&pt, 0, sizeof(pt));
     72    pt.Nmatches = 0;
     73    ALLOCATE(pt.matches, Match, 20);
     74    pt.arrayLength = 20;
     75
     76    int status;
     77    while ((status = readPointFromFile(stdin, &pt))) {
     78      if (status < 0) {
     79        fprintf(stdout, "ERROR malformed input line\n");
     80        exit(1);
     81      }
     82      if (MatchCoords (dbImages, NdbImages, &pt, 1)) {
     83        ListImagesAtCoords(dbImages, &pt, 1);
     84      }
     85      fprintf(stdout, "DONE\n");
     86      fflush(stdout);
     87      pt.Nmatches = 0;
     88    }
    6689  } else {
    67     exit(PSTAMP_NO_OVERLAP);
    68   }
     90    if (MatchCoords (dbImages, NdbImages, points, Npoints)) {
     91      ListImagesAtCoords(dbImages, points, Npoints);
     92    } else {
     93      exit(PSTAMP_NO_OVERLAP);
     94    }
     95  }
     96  exit(0);
     97}
     98
     99static int readPointFromFile(FILE *f, Point *pt) {
     100    char buf[80];
     101    char *good = fgets(buf, 80, f);
     102    if (!good) {
     103        return 0;
     104    }
     105    // fprintf(stderr, "READ: %s\n", buf);
     106    int Nread = sscanf(buf, "%d %lf %lf\n", &pt->id, &pt->ra, &pt->dec);
     107    if (Nread == 3) {
     108        // got one
     109        return 1;
     110    } else if (Nread == -1) {
     111        // all done time to go
     112        return 0;
     113    } else {
     114        // fprintf(stderr, "malformed input line: %d\n", Nread);
     115        return -1;
     116    }
    69117}
    70118
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/kapa2/include/constants.h

    r35766 r36680  
    1515// XXX for the moment, this is set to match the values in SetColorScale3D_CC
    1616# define NPIXELS_STATIC 128
    17 // # define NPIXELS_STATIC 1000
     17// # define NPIXELS_STATIC 4600 -- if we want fullcolor to work, need this
    1818
    1919# define PAD1  3
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/kapa2/src/Graphs.c

    r29539 r36680  
    6464  graph[0].data.coords.crpix2 = 0.0;
    6565  graph[0].data.coords.cdelt1 = graph[0].data.coords.cdelt2 = 1.0;
    66   strcpy (graph[0].data.coords.ctype, "RA---LIN");
     66  strcpy (graph[0].data.coords.ctype, "DEC--LIN");
    6767  strcpy (graph[0].data.axis, "2222");
    6868  strcpy (graph[0].data.ticks, "2222");
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/kapa2/src/Image.c

    r29938 r36680  
    1818  channel->coords.crpix2 = 0.0;
    1919  channel->coords.cdelt1 = channel->coords.cdelt2 = 1.0;
    20   strcpy (channel->coords.ctype, "RA---LIN");
     20  strcpy (channel->coords.ctype, "DEC--LIN");
    2121  channel->coords.Npolyterms = 0;
    2222
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/kapa2/src/bDrawObjects.c

    r35416 r36680  
    315315        D = scaleSize ? dz*z[i] : ds;
    316316        FillRectangle (buffer, sx, sy, 2*D, 2*D);
     317        // plot range saturated by bDrawRectFill
    317318      }
    318319    }
     
    335336        D = scaleSize ? dz*z[i] : ds;
    336337        DrawRectangle (buffer, sx, sy, 2*D, 2*D);
     338        // plot range saturated by bDrawRectOpen
    337339      }
    338340    }
     
    356358        DrawLine (buffer, sx - D, sy, sx + D, sy);
    357359        DrawLine (buffer, sx, sy - D, sx, sy + D);
     360        // out-of-range points skipped by bDrawPoint
    358361      }
    359362    }
     
    377380        DrawLine (buffer, sx + D, sy - D, sx - D, sy + D);
    378381        DrawLine (buffer, sx - D, sy - D, sx + D, sy + D);
     382        // out-of-range points skipped by bDrawPoint
    379383      }
    380384    }
     
    398402        // FillTriangle (buffer, sx - D, sy - 0.58*D, sx + D, sy - 0.58*D, sx, sy + 1.15*D);
    399403        FillTriangle (buffer, sx, sy + 0.58*D, D, -1.73*D);
     404        // out-of-range points skipped by bDrawPoint
    400405      }
    401406    }
     
    418423        D = scaleSize ? dz*z[i] : ds;
    419424        OpenTriangle (buffer, sx - D, sy + 0.58*D, sx + D, sy + 0.58*D, sx, sy - 1.15*D);
     425        // out-of-range points skipped by bDrawPoint
    420426      }
    421427    }
     
    440446        DrawLine (buffer, sx, sy, sx + D, sy - 0.58*D);
    441447        DrawLine (buffer, sx, sy, sx,     sy + 1.15*D);
     448        // out-of-range points skipped by bDrawPoint
    442449      }
    443450    }
     
    460467        D = scaleSize ? dz*z[i] : ds;
    461468        DrawCircle (buffer, sx, sy, D);
     469        // out-of-range points skipped by bDrawPoint
    462470      }
    463471    }
     
    484492        DrawLine (buffer, sx - 0.58*D, sy + 0.81*D, sx - 0.95*D, sy - 0.31*D);
    485493        DrawLine (buffer, sx - 0.95*D, sy - 0.31*D, sx + 0.00*D, sy - 1.00*D);
     494        // out-of-range points skipped by bDrawPoint
    486495      }
    487496    }
     
    509518        DrawLine (buffer, sx + 0.50*D, sy - 0.87*D, sx - 0.50*D, sy - 0.87*D);
    510519        DrawLine (buffer, sx - 0.50*D, sy - 0.87*D, sx -      D, sy);
     520        // out-of-range points skipped by bDrawPoint
    511521      }
    512522    }
     
    529539        D = scaleSize ? dz*z[i] : ds;
    530540        FillCircle (buffer, sx, sy, D);
     541        // out-of-range points skipped by bDrawLineHorizontal
    531542      }
    532543    }
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/Makefile

    r35416 r36680  
    103103$(SRC)/ImageMetadata.$(ARCH).o \
    104104$(SRC)/ImageOps.$(ARCH).o               \
     105$(SRC)/RegionHostTable.$(ARCH).o                \
    105106$(SRC)/match_image.$(ARCH).o            \
    106107$(SRC)/db_utils.$(ARCH).o               \
    107108$(SRC)/convert.$(ARCH).o                \
    108109$(SRC)/HostTable.$(ARCH).o              \
    109 $(SRC)/BoundaryTree.$(ARCH).o
    110 
     110$(SRC)/BoundaryTree.$(ARCH).o           \
     111$(SRC)/TessellationTable.$(ARCH).o
    111112
    112113# $(SRC)/dvo_convert_panstarrs.$(ARCH).o
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/include/dvo.h

    r35755 r36680  
    285285} HostTable;
    286286
     287// A RegionHost processes data for some region in parallel with other regions
     288typedef struct RegionHostInfo {
     289  double Rmin;        // (Rmin,Rmax),(Dmin,Dmax) arehard RA,DEC boundaries of the
     290  double Rmax;        // region for which each host is responsible.  A given host
     291  double Dmin;        // calibrates the images for which the fiducial point (center)
     292  double Dmax;        // lands in the region, and all objects in the region
     293
     294  double RminCat;      // (RminCat,RmaxCat),(DminCat,DmaxCat) are the region for which
     295  double RmaxCat;      // the catalogs need to be loaded : this is the outer bounds
     296  double DminCat;      // of the region containing all images completely
     297  double DmaxCat;
     298
     299  char *hostname;
     300
     301  int hostID;                 // remove machine ID in SkyTable
     302  int stdio[3];               // fd's for communication with the remote host
     303  int pid;                    // remote process ID
     304  int status;
     305  IOBuffer stdout;
     306  IOBuffer stderr;
     307
     308  off_t Nimage;
     309  off_t NIMAGE;
     310  Image *image;
     311  off_t *imseq;
     312
     313  int *neighbors;             // list of neighbor index values
     314  int Nneighbors;             // number of neighbors
     315  char isNeighbor;            // TRUE if I am a neighbor to the current region host
     316} RegionHostInfo;
     317
     318typedef struct {
     319  double Rmin;
     320  double Rmax;
     321  double Dmin;
     322  double Dmax;
     323
     324  int Nhosts;
     325  RegionHostInfo *hosts;
     326  short *index;
     327} RegionHostTable;
     328
    287329// special-case function:
    288330CMF_PS1_V2 *gfits_table_get_CMF_PS1_V1_Alt (FTable *ftable, off_t *Ndata, char *swapped);
     
    308350# define BOUNDARY_TREE_NAME_LENGTH 128
    309351
     352// BoundaryTree is a structure to describe the 3pi RINGS skycell boundaries in terms of lines of constant (RA,DEC)
     353// the structure is flexible for a variety of RINGS-like tessellations, but is not appropriate for the LOCAL style tess
    310354typedef struct {
    311355  int FixedGridDEC;           // is the DEC sequence linear?
     
    342386} BoundaryTree;
    343387
    344 // XXX DROP? // a reduced-subset structure for relastro
    345 // XXX DROP? typedef struct {
    346 // XXX DROP?   double         R;
    347 // XXX DROP?   double         D;
    348 // XXX DROP?   unsigned short Nmeasure;
    349 // XXX DROP?   int            measureOffset;
    350 // XXX DROP?   uint32_t       flags;
    351 // XXX DROP?   int            catID;
    352 // XXX DROP? } AverageTinyAstro;
     388typedef enum { TESS_NONE, TESS_LOCAL, TESS_RINGS } TessType;
     389
     390// TessellationTable is a structure to describe the parameters of a set of "tessellations"
     391// (these are not strictly tessellations but projection sets as only the non-local
     392// versions can cover the full sky).  For LOCAL projection cells, the structure describes
     393// the boundaries of a SINGLE projection cell with Nx * Ny skycells and includes some
     394// basic parameters (not used by the fullsky, eg RINGS, tessellations)
     395typedef struct {
     396  double Rmin; // this tessellation is valid only for RA >= Rmin
     397  double Rmax; // this tessellation is valid only for RA <  Rmax
     398  double Dmin; // this tessellation is valid only for DEC >= Dmin
     399  double Dmax; // this tessellation is valid only for DEC <  Dmax
     400
     401  double Xo;
     402  double Yo;
     403  double Ro;
     404  double Do;
     405  double dPix;
     406  int dX;
     407  int dY;
     408
     409  int NX_SUB;
     410  int NY_SUB;
     411
     412  char *basename;
     413  int Nbasename;
     414  int projectIDoff;
     415  int skycellIDoff;
     416
     417  TessType type; //
     418  BoundaryTree *tree;
     419} TessellationTable;
    353420
    354421// a reduced-subset structure for relphot
     
    360427  uint32_t       flags;
    361428  int            catID;
     429  int            objID;
     430  int            nOwn;
    362431} AverageTiny;
    363432
     
    385454  short          dYccd;
    386455  short          dRsys;
     456  char           myDet;
    387457} MeasureTiny;
     458
     459/** STRUCT DEFINITION **/
     460typedef struct {
     461  double           R;                    // RA (decimal degrees )
     462  double           D;                    // DEC (decimal degrees )
     463  float            dR;                   // RA error (arcsec)
     464  float            dD;                   // DEC error (arcsec)
     465  float            uR;                   // RA*cos(D) proper-motion (arcsec/year)
     466  float            uD;                   // DEC proper-motion (arcsec/year)
     467  float            duR;                  // RA*cos(D) p-m error (arcsec/year)
     468  float            duD;                  // DEC p-m error (arcsec/year)
     469  float            P;                    // parallax (arcsec)
     470  float            dP;                   // parallax error (arcsec)
     471  float            ChiSqAve;             // astrometry analysis chisq
     472  float            ChiSqPM;              // astrometry analysis chisq
     473  float            ChiSqPar;             // astrometry analysis chisq
     474  int              Tmean;                // mean epoch (PM,PAR ref) (unix time seconds)
     475  int              Trange;               // mean epoch (PM,PAR ref) (unix time seconds)
     476  float            Xp;                   // unused
     477  unsigned short   Npos;                 // number of detections used for astrometry
     478  unsigned short   Nmeasure;             // number of psf measurements
     479  unsigned short   Nmissing;             // number of missings
     480  unsigned short   Nextend;              // number of extended measurements
     481  uint32_t         measureOffset;        // offset to first psf measurement
     482  uint32_t         missingOffset;        // offset to first missing obs
     483  uint32_t         extendOffset;         // offset to first extended measurement
     484  uint32_t         flags;                // average object flags (star; ghost; etc)
     485  uint32_t         photFlagsUpper;       // upper bit of 2 bit summary of per-measure photflags
     486  uint32_t         photFlagsLower;       // lower bit of 2 bit summary of per-measure photflags
     487  unsigned int     objID;                // unique ID for object in table
     488  unsigned int     catID;                // unique ID for table in which object was first realized
     489  uint64_t         extID;                // external ID for object (eg PSPS objID)
     490} Average_PS1_V4alt;
     491
     492Average_PS1_V4alt *gfits_table_get_Average_PS1_V4alt (FTable *table, off_t *Ndata, char *swapped);
     493Average *Average_PS1_V4alt_ToInternal (Average_PS1_V4alt *in, off_t Nvalues);
     494
     495/** STRUCT DEFINITION **/
     496typedef struct {
     497  float            dR;                   // RA offset (arcsec)
     498  float            dD;                   // DEC offset (arcsec)
     499  float            M;                    // catalog mag (mag)
     500  float            Mcal;                 // image cal mag (mag)
     501  float            Map;                  // aperture mag (mag)
     502  float            Mkron;                // kron magnitude (mag)
     503  float            dMkron;               // kron magnitude error (mag)
     504  float            dM;                   // mag error (mag)
     505  float            dMcal;                // systematic calibration error (mag)
     506  float            dt;                   // exposure time (2.5*log(exptime))
     507  float            FluxPSF;              // flux from psf fit (counts/sec?)
     508  float            dFluxPSF;             // error on psf flux (counts/sec?)
     509  float            FluxKron;             // flux from kron ap (counts/sec?)
     510  float            dFluxKron;            // error on kron flux (counts/sec?)
     511  float            airmass;              // (airmass - 1) (airmass)
     512  float            az;                   // telescope azimuth
     513  float            Xccd;                 // X coord on chip (raw value) (pixels)
     514  float            Yccd;                 // Y coord on chip (raw value) (pixels)
     515  float            Sky;                  // local estimate of sky flux (counts/sec)
     516  float            dSky;                 // local estimate of sky flux (counts/sec)
     517  int              t;                    // time in seconds (UNIX)
     518  unsigned int     averef;               // reference to average entry     
     519  unsigned int     detID;                // detection ID
     520  unsigned int     imageID;              // reference to DVO image ID
     521  unsigned int     objID;                // unique ID for object in table
     522  unsigned int     catID;                // unique ID for table in which object was first realized
     523  uint64_t         extID;                // external ID (eg PSPS detID)
     524  float            psfQF;                // psf coverage/quality factor
     525  float            psfQFperf;            // psf coverage / quality factor (all mask bits)
     526  float            psfChisq;             // psf fit chisq
     527  int              psfNdof;              // psf degrees of freedom
     528  int              psfNpix;              // psf number of pixels
     529  float            crNsigma;             // Nsigma deviation towards CR
     530  float            extNsigma;            // Nsigma deviation towards EXT
     531  short            FWx;                  // object fwhm major axis (1/100 of pixels)
     532  short            FWy;                  // object fwhm minor axis (1/100 of pixels )
     533  short            theta;                // angle wrt ccd X dir ((0xffff/360) deg)
     534  short            Mxx;                  // second moments in pixel coords (1/100 of pixels)
     535  short            Mxy;                  // second moments in pixel coords (1/100 of pixels)
     536  short            Myy;                  // second moments in pixel coords (1/100 of pixels)
     537  unsigned short   t_msec;               // time fraction of second (milliseconds)
     538  unsigned short   photcode;             // photcode
     539  short            dXccd;                // X coord error on chip (1/100 of pixels)
     540  short            dYccd;                // Y coord error on chip (1/100 of pixels)
     541  short            dRsys;                // systematic error from astrom (1/100 of pixels)
     542  short            posangle;             // position angle sky to chip ((0xffff/360) deg)
     543  float            pltscale;             // plate scale (arcsec/pixel)
     544  unsigned int     dbFlags;              // flags supplied by analysis in database
     545  unsigned int     photFlags;            // flags supplied by photometry program
     546} Measure_PS1_V4alt;
     547
     548Measure_PS1_V4alt *gfits_table_get_Measure_PS1_V4alt (FTable *table, off_t *Ndata, char *swapped);
     549Measure *Measure_PS1_V4alt_ToInternal (Measure_PS1_V4alt *in, off_t Nvalues);
    388550
    389551/* a catalog contains this data */
     
    438600  float *X;
    439601  float *Y;
     602  int   *nOwn; // relastro uses this to count owned detections per object
    440603
    441604} Catalog;
     
    499662float PhotInst (Measure *measure);
    500663float PhotCat (Measure *measure);
    501 float PhotAper (Measure *measure);
    502 float PhotKron (Measure *measure);
    503664float PhotSys (Measure *measure, Average *average, SecFilt *secfilt);
    504665float PhotRel (Measure *measure, Average *average, SecFilt *secfilt);
     
    506667float PhotAve (PhotCode *code, Average *average, SecFilt *secfilt);
    507668float PhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure);
     669float PhotAveErr (PhotCode *code, Average *average, SecFilt *secfilt);
     670
     671float PhotAperInst (Measure *measure);
     672float PhotAperCat (Measure *measure);
     673float PhotAperSys (Measure *measure, Average *average, SecFilt *secfilt);
     674float PhotAperRel (Measure *measure, Average *average, SecFilt *secfilt);
     675float PhotAperCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
     676float PhotAperAve (PhotCode *code, Average *average, SecFilt *secfilt);
     677float PhotAperRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure);
     678
     679float PhotKronInst (Measure *measure);
     680float PhotKronCat (Measure *measure);
     681float PhotKronSys (Measure *measure, Average *average, SecFilt *secfilt);
     682float PhotKronRel (Measure *measure, Average *average, SecFilt *secfilt);
     683float PhotKronCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code);
     684float PhotKronAve (PhotCode *code, Average *average, SecFilt *secfilt);
     685float PhotKronRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure);
     686float PhotKronAveErr (PhotCode *code, Average *average, SecFilt *secfilt);
     687
    508688float PhotXm (PhotCode *code, Average *average, SecFilt *secfilt);
    509 float PhotdM (PhotCode *code, Average *average, SecFilt *secfilt);
    510 
    511 float PhotAperInst (Measure *measure);
    512 float PhotKronInst (Measure *measure);
    513 float PhotKronAve (PhotCode *code, Average *average, SecFilt *secfilt);
    514 float PhotKronAveErr (PhotCode *code, Average *average, SecFilt *secfilt);
    515689
    516690float PhotZeroPoint (Measure *measure, Average *average, SecFilt *secfilt);
     
    696870void sort_coords_index (double *X, double *Y, off_t *S, off_t N);
    697871void sort_coords_indexonly (double *X, double *Y, off_t *S, off_t N);
     872void sort_IDs_indexonly (opihi_int *X, off_t *S, off_t N);
    698873void sort_regions (SkyRegion *region, off_t N);
    699874
     
    716891int free_tiny_values (Catalog *catalog);
    717892
     893BoundaryTree *BoundaryTreeLoad(char *filename);
     894BoundaryTree *BoundaryTreeRead(Header *headerPHU, Header *headerZone, FILE *f);
     895
     896int BoundaryTreeSave(char *filename, BoundaryTree *tree);
     897int BoundaryTreeWrite(FILE *f, BoundaryTree *tree);
     898
    718899int BoundaryTreeCellCoords (BoundaryTree *tree, int *zone, int *band, double ra, double dec);
    719 int BoundaryTreeSave(char *filename, BoundaryTree *tree);
    720 BoundaryTree *BoundaryTreeLoad(char *filename);
    721900int BoundaryTreeProjection (double *x, double *y, double r, double d, BoundaryTree *tree, int zone, int band);
     901
     902TessellationTable *TessellationTableLoad(char *filename, int *Ntess);
     903int TessellationTableSave(char *filename, TessellationTable *tess, int Ntess);
     904int TessellationPrimaryCellIDs (TessellationTable *tess, int Ntess, int *tessID, int *projID, int *skycellID, double ra, double dec);
     905void TessellationTableInit (TessellationTable *tess, int Ntess);
    722906
    723907void dvo_average_init (Average *average);
     
    727911void dvo_measureT_init (MeasureTiny *measure);
    728912
     913void InitRegionHosts (RegionHostInfo *hosts, int Nhosts, int NHOSTS);
     914void FreeRegionHosts (RegionHostInfo *hosts, int Nhosts);
     915void FreeRegionHostTable (RegionHostTable *table);
     916RegionHostTable *RegionHostTableLoad (char *catdir, char *rootname);
     917int RegionHostTableWaitJobs (RegionHostTable *regionHosts, char *file, int lineno);
     918int RegionHostTableWaitJobsGetIO (RegionHostTable *regionHosts, char *file, int lineno, int VERBOSE);
     919int RegionHostFindNeighbors (RegionHostTable *table, int Nhost);
     920
    729921# endif // DVO_H
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/include/dvodb.h

    r35416 r36680  
    2323/* magnitude types */
    2424enum {MAG_NONE,
    25       MAG_INST,
    26       MAG_CAT,
    27       MAG_APER,
    28       MAG_APER_INST,
    29       MAG_KRON,
    30       MAG_KRON_INST,
    31       MAG_KRON_ERR,
    32       MAG_SYS,
    33       MAG_REL,
    34       MAG_CAL,
     25
     26      // these magnitude types are from the measurement table (or derived therein)
     27      // the following imply PSF magnitudes:
     28      MAG_INST, // -2.5*log(DN) [ie, not DN/sec]
     29      MAG_CAT,  // MAG_INST + 2.5*log(exptime) + C_lambda + K_lambda*(airmass - 1)
     30      MAG_SYS,  // MAG_CAT + \sum_i A_i * (color_i - color_o) [color correction for measure photcode]
     31      MAG_REL,  // MAG_SYS - Mcal [specific zero point for image]
     32      MAG_CAL,  // MAG_REL + \sum_i A_i * (color_i - color_o) [color correction for average photcode]
     33      MAG_ERR,  // error on PSF MAG
     34
     35      // the following imply APERTURE magnitudes:
     36      MAG_APER_INST, // -2.5*log(DN) [ie, not DN/sec]
     37      MAG_APER_CAT,  // MAG_APER_INST + 2.5*log(exptime) + C_lambda + K_lambda*(airmass - 1)
     38      MAG_APER_SYS,  // MAG_APER_CAT + \sum_i A_i * (color_i - color_o) [color correction for measure photcode]
     39      MAG_APER_REL,  // MAG_APER_SYS - Mcal [specific zero point for image]
     40      MAG_APER_CAL,  // MAG_APER_REL + \sum_i A_i * (color_i - color_o) [color correction for average photcode]
     41      MAG_APER_ERR,  // error on APER MAG (if known, else psf error)
     42      MAG_APER,      // in mextract -> MAG_APER_REL, in avextract -> MAG_APER_AVE
     43
     44      // the following imply KRON magnitudes:
     45      MAG_KRON_INST, // -2.5*log(DN) [ie, not DN/sec]
     46      MAG_KRON_CAT,  // MAG_KRON_INST + 2.5*log(exptime) + C_lambda + K_lambda*(airmass - 1)
     47      MAG_KRON_SYS,  // MAG_KRON_CAT + \sum_i A_i * (color_i - color_o) [color correction for measure photcode]
     48      MAG_KRON_REL,  // MAG_KRON_SYS - Mcal [specific zero point for image]
     49      MAG_KRON_CAL,  // MAG_KRON_REL + \sum_i A_i * (color_i - color_o) [color correction for average photcode]
     50      MAG_KRON_ERR,  // error on KRON MAG
     51      MAG_KRON,      // in mextract -> MAG_KRON_REL, in avextract -> MAG_KRON_AVE
     52
     53      // these magnitude types are from the average (secfilt) table:
     54      // the following imply PSF magnitudes (or fluxes)
    3555      MAG_AVE,
    3656      MAG_REF,
    37       MAG_ERR,
    3857      MAG_STDEV,
    3958      MAG_AVE_ERR,
     59      MAG_CHISQ,
     60      MAG_20,
     61      MAG_80,
     62      MAG_FLUX_PSF,
     63      MAG_FLUX_PSF_ERR,
     64
     65      // the following imply APERTURE magnitudes:
     66      MAG_APER_AVE,
     67      MAG_APER_REF,
     68
     69      // the following imply KRON magnitudes or fluxes:
     70      MAG_KRON_AVE,
     71      MAG_KRON_REF,
     72      MAG_FLUX_KRON,
     73      MAG_FLUX_KRON_ERR,
     74
     75      // other secfilt fields of interest
    4076      MAG_PHOT_FLAGS,
    41       MAG_CHISQ,
    4277      MAG_NCODE,
    4378      MAG_NPHOT,
    44       MAG_20,
    45       MAG_80,
    4679      MAG_UC_DIST,
    4780      MAG_STACK_DET_ID,
    48       MAG_FLUX_PSF,
    49       MAG_FLUX_PSF_ERR,
    50       MAG_FLUX_KRON,
    51       MAG_FLUX_KRON_ERR,
    5281};
    5382
     
    174203      AVE_TMEAN,
    175204      AVE_TRANGE,
     205      AVE_PSF_QF,
     206      AVE_PSF_QF_PERF,
     207      AVE_STARGAL,
    176208      AVE_Xp,
    177209      AVE_NMEAS,
     
    372404
    373405// Some values used by code moved to libdvo from opihi.
    374 enum {OPIHI_FLT, OPIHI_INT};
     406enum {OPIHI_NOTYPE, OPIHI_FLT, OPIHI_INT};
    375407#define opihi_flt double
    376408#define opihi_int int
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/BoundaryTree.c

    r35755 r36680  
    11# include "dvo.h"
    22
    3 # define GET_COLUMN_NEW(OUT,NAME,TYPE)                                  \
    4   TYPE *OUT = gfits_get_bintable_column_data (&theader, &ftable, NAME, type, &Nrow, &Ncol); \
     3# define GET_COLUMN_NEW(HEADER,FTABLE,OUT,NAME,TYPE)                            \
     4  TYPE *OUT = gfits_get_bintable_column_data (HEADER, FTABLE, NAME, type, &Nrow, &Ncol); \
    55  myAssert (!strcmp(type, #TYPE), "wrong column type");
    66
    7 # define GET_COLUMN_RAW(OUT,NAME,TYPE)                                  \
    8   OUT = gfits_get_bintable_column_data (&theader, &ftable, NAME, type, &Nrow, &Ncol); \
     7# define GET_COLUMN_RAW(HEADER,FTABLE,OUT,NAME,TYPE)                    \
     8  OUT = gfits_get_bintable_column_data (HEADER, FTABLE, NAME, type, &Nrow, &Ncol); \
    99  myAssert (!strcmp(type, #TYPE), "wrong column type");
    1010
     
    1212
    1313BoundaryTree *BoundaryTreeLoad(char *filename) {
     14
     15  Header header;
     16  Header theader;
     17  Matrix matrix;
     18
     19  header.buffer = NULL;
     20  matrix.buffer = NULL;
     21  theader.buffer = NULL;
     22  BoundaryTree *tree = NULL;
     23
     24  FILE *f = fopen (filename, "r");
     25  if (!f) {
     26    fprintf (stderr, "ERROR: cannot open boundary tree file %s\n", filename);
     27    return NULL;
     28  }
     29
     30  /* load in PHU segment (ignore) */
     31  if (!gfits_fread_header (f, &header)) {
     32    if (DEBUG) fprintf (stderr, "can't read boundary tree header\n");
     33    goto escape;
     34  }
     35  if (!gfits_fread_matrix (f, &matrix, &header)) {
     36    if (DEBUG) fprintf (stderr, "can't read boundary tree matrix\n");
     37    goto escape;
     38  }
     39
     40  // load data for this header
     41  if (!gfits_load_header (f, &theader)) {
     42    if (DEBUG) fprintf (stderr, "can't read boundary tree zone table header\n");
     43    goto escape;
     44  }
     45
     46  tree = BoundaryTreeRead (&header, &theader, f);
     47
     48escape:
     49
     50  gfits_free_header (&theader);
     51  gfits_free_header (&header);
     52  gfits_free_matrix (&matrix);
     53  fclose (f);
     54
     55  return tree;
     56}
     57
     58// assume we are pointing at the relevant table portion
     59BoundaryTree *BoundaryTreeRead(Header *headerPHU, Header *headerZone, FILE *f) {
    1460
    1561  int i, j, nz, nb, Ncol;
    1662  off_t Nrow;
    1763  char type[16];
    18   Header header;
    19   Header theader;
    20   Matrix matrix;
    21   FTable ftable;
    22 
    23   header.buffer = NULL;
    24   matrix.buffer = NULL;
    25   ftable.buffer = NULL;
    26   theader.buffer = NULL;
     64
     65  FTable ftableZone;
     66
     67  Header headerCell;
     68  FTable ftableCell;
     69
     70  ftableZone.buffer = NULL;
     71  ftableCell.buffer = NULL;
     72  headerCell.buffer = NULL;
     73
     74  // we must have already read in the Zone table header section
     75  ftableZone.header =  headerZone;
     76  ftableCell.header = &headerCell;
     77
    2778  BoundaryTree *tree = NULL;
    2879
    29   FILE *f = fopen (filename, "r");
    30   if (!f) {
    31     fprintf (stderr, "ERROR: cannot open image subset file %s\n", filename);
    32     return NULL;
    33   }
    34 
    35   /* load in PHU segment (ignore) */
    36   if (!gfits_fread_header (f, &header)) {
    37     if (DEBUG) fprintf (stderr, "can't read image subset header\n");
    38     goto escape;
    39   }
    40   if (!gfits_fread_matrix (f, &matrix, &header)) {
    41     if (DEBUG) fprintf (stderr, "can't read image subset matrix\n");
    42     goto escape;
    43   }
    44 
    4580  ALLOCATE (tree, BoundaryTree, 1);
    4681
    47   gfits_scan (&header, "DEC_ORI", "%lf", 1, &tree->DEC_origin);
    48   gfits_scan (&header, "DEC_OFF", "%lf", 1, &tree->DEC_offset);
    49 
    50   gfits_scan (&header, "NX_SUB", "%d", 1, &tree->NX_SUB);
    51   gfits_scan (&header, "NY_SUB", "%d", 1, &tree->NY_SUB);
    52   gfits_scan (&header, "PIXSCALE", "%lf", 1, &tree->dPix);
    53 
    54   ftable.header = &theader;
     82  // we need to read the boundary tree parameters from the correct header
     83  // put them in the PHU header in any case?
     84  gfits_scan (headerPHU, "DEC_ORI",  "%lf", 1, &tree->DEC_origin);
     85  gfits_scan (headerPHU, "DEC_OFF",  "%lf", 1, &tree->DEC_offset);
     86  gfits_scan (headerPHU, "NX_SUB",   "%d",  1, &tree->NX_SUB);
     87  gfits_scan (headerPHU, "NY_SUB",   "%d",  1, &tree->NY_SUB);
     88  gfits_scan (headerPHU, "PIXSCALE", "%lf", 1, &tree->dPix);
    5589
    5690  /*** zone information table ***/
    57   {
    58     // load data for this header
    59     if (!gfits_load_header (f, &theader)) goto escape;
    60 
    61     // read the fits table bytes
    62     if (!gfits_fread_ftable_data (f, &ftable, FALSE)) goto escape;
     91
     92  // read the fits table bytes
     93  if (!gfits_fread_ftable_data (f, &ftableZone, FALSE)) goto escape;
    6394 
    64     // need to create and assign to flat-field correction
    65     GET_COLUMN_RAW(tree->Nband,       "NBAND",           int);
    66     GET_COLUMN_RAW(tree->RA_origin,   "RA_ORIGIN",   double);
    67     GET_COLUMN_RAW(tree->RA_offset,   "RA_OFFSET",   double);
    68     GET_COLUMN_RAW(tree->DEC_min  ,   "DEC_MIN",     double);
    69     GET_COLUMN_RAW(tree->DEC_max  ,   "DEC_MAX",     double);
    70     GET_COLUMN_RAW(tree->DEC_min_raw, "DEC_MIN_RAW", double);
    71     GET_COLUMN_RAW(tree->DEC_max_raw, "DEC_MAX_RAW", double);
    72     gfits_free_header (&theader);
    73     gfits_free_table  (&ftable);
    74 
    75     fprintf (stderr, "loaded data for %lld zones\n", (long long) Nrow);
    76     tree->Nzone = Nrow;
    77 
    78     // allocate the storage arrays
    79     ALLOCATE (tree->ra,   double *, tree->Nzone);
    80     ALLOCATE (tree->dec,  double *, tree->Nzone);
    81     ALLOCATE (tree->Xo,   double *, tree->Nzone);
    82     ALLOCATE (tree->Yo,   double *, tree->Nzone);
    83     ALLOCATE (tree->dX,      int *, tree->Nzone);
    84     ALLOCATE (tree->dY,      int *, tree->Nzone);
    85     ALLOCATE (tree->cell,    int *, tree->Nzone);
    86     ALLOCATE (tree->projID,  int *, tree->Nzone);
    87     ALLOCATE (tree->name,  char **, tree->Nzone);
    88     for (i = 0; i < tree->Nzone; i++) {
    89       ALLOCATE (tree->ra[i],   double, tree->Nband[i]);
    90       ALLOCATE (tree->dec[i],  double, tree->Nband[i]);
    91       ALLOCATE (tree->Xo[i],   double, tree->Nband[i]);
    92       ALLOCATE (tree->Yo[i],   double, tree->Nband[i]);
    93       ALLOCATE (tree->dX[i],      int, tree->Nband[i]);
    94       ALLOCATE (tree->dY[i],      int, tree->Nband[i]);
    95       ALLOCATE (tree->cell[i],    int, tree->Nband[i]);
    96       ALLOCATE (tree->projID[i],  int, tree->Nband[i]);
    97       ALLOCATE (tree->name[i], char *, tree->Nband[i]);
    98       for (j = 0; j < tree->Nband[i]; j++) {
    99         ALLOCATE (tree->name[i][j], char, BOUNDARY_TREE_NAME_LENGTH);
    100       }
     95  // need to create and assign to flat-field correction
     96  GET_COLUMN_RAW(headerZone, &ftableZone, tree->Nband,       "NBAND",       int);
     97  GET_COLUMN_RAW(headerZone, &ftableZone, tree->RA_origin,   "RA_ORIGIN",   double);
     98  GET_COLUMN_RAW(headerZone, &ftableZone, tree->RA_offset,   "RA_OFFSET",   double);
     99  GET_COLUMN_RAW(headerZone, &ftableZone, tree->DEC_min  ,   "DEC_MIN",     double);
     100  GET_COLUMN_RAW(headerZone, &ftableZone, tree->DEC_max  ,   "DEC_MAX",     double);
     101  GET_COLUMN_RAW(headerZone, &ftableZone, tree->DEC_min_raw, "DEC_MIN_RAW", double);
     102  GET_COLUMN_RAW(headerZone, &ftableZone, tree->DEC_max_raw, "DEC_MAX_RAW", double);
     103  gfits_free_table  (&ftableZone);
     104
     105  fprintf (stderr, "loaded data for %lld zones\n", (long long) Nrow);
     106  tree->Nzone = Nrow;
     107
     108  // allocate the storage arrays
     109  ALLOCATE (tree->ra,   double *, tree->Nzone);
     110  ALLOCATE (tree->dec,  double *, tree->Nzone);
     111  ALLOCATE (tree->Xo,   double *, tree->Nzone);
     112  ALLOCATE (tree->Yo,   double *, tree->Nzone);
     113  ALLOCATE (tree->dX,      int *, tree->Nzone);
     114  ALLOCATE (tree->dY,      int *, tree->Nzone);
     115  ALLOCATE (tree->cell,    int *, tree->Nzone);
     116  ALLOCATE (tree->projID,  int *, tree->Nzone);
     117  ALLOCATE (tree->name,  char **, tree->Nzone);
     118  for (i = 0; i < tree->Nzone; i++) {
     119    ALLOCATE (tree->ra[i],   double, tree->Nband[i]);
     120    ALLOCATE (tree->dec[i],  double, tree->Nband[i]);
     121    ALLOCATE (tree->Xo[i],   double, tree->Nband[i]);
     122    ALLOCATE (tree->Yo[i],   double, tree->Nband[i]);
     123    ALLOCATE (tree->dX[i],      int, tree->Nband[i]);
     124    ALLOCATE (tree->dY[i],      int, tree->Nband[i]);
     125    ALLOCATE (tree->cell[i],    int, tree->Nband[i]);
     126    ALLOCATE (tree->projID[i],  int, tree->Nband[i]);
     127    ALLOCATE (tree->name[i], char *, tree->Nband[i]);
     128    for (j = 0; j < tree->Nband[i]; j++) {
     129      ALLOCATE (tree->name[i][j], char, BOUNDARY_TREE_NAME_LENGTH);
    101130    }
    102131  }
    103132
    104133  /*** cell information table ***/
    105   {
    106     // load data for this header
    107     if (!gfits_load_header (f, &theader)) goto escape;
    108 
    109     // read the fits table bytes
    110     if (!gfits_fread_ftable_data (f, &ftable, FALSE)) goto escape;
     134
     135  // load data for this header
     136  if (!gfits_load_header (f, &headerCell)) goto escape;
     137
     138  // read the fits table bytes
     139  if (!gfits_fread_ftable_data (f, &ftableCell, FALSE)) goto escape;
    111140 
    112     // need to create and assign to flat-field correction
    113     GET_COLUMN_NEW(R,     "RA",          double);
    114     GET_COLUMN_NEW(D,     "DEC",         double);
    115     GET_COLUMN_NEW(zone,  "ZONE",        int);
    116     GET_COLUMN_NEW(band,  "BAND",        int);
    117     GET_COLUMN_NEW(index, "INDEX",       int);
    118     GET_COLUMN_NEW(Xo,    "X_CENT",      double);
    119     GET_COLUMN_NEW(Yo,    "Y_CENT",      double);
    120     GET_COLUMN_NEW(dX,    "X_GRID",      int);
    121     GET_COLUMN_NEW(dY,    "Y_GRID",      int);
    122     GET_COLUMN_NEW(name,  "NAME",        char); // XXX how is this done?
    123     gfits_free_header (&theader);
    124     gfits_free_table  (&ftable);
    125     fprintf (stderr, "loaded data for %lld cells\n", (long long) Nrow);
    126 
    127     // assign the storage arrays
    128     for (i = 0; i < Nrow; i++) {
    129       nz = zone[i];
    130       nb = band[i];
    131       tree->ra[nz][nb] = R[i];
    132       tree->dec[nz][nb] = D[i];
    133       tree->Xo[nz][nb] = Xo[i];
    134       tree->Yo[nz][nb] = Yo[i];
    135       tree->dX[nz][nb] = dX[i];
    136       tree->dY[nz][nb] = dY[i];
    137       tree->cell[nz][nb] = i; // XXX ?
    138       memcpy(tree->name[nz][nb], &name[i*BOUNDARY_TREE_NAME_LENGTH], BOUNDARY_TREE_NAME_LENGTH);
    139       // XXX parse out the ID from the name (skycell.NNNN)
    140       tree->projID[nz][nb] = atoi(&tree->name[nz][nb][8]);
    141     }
    142 
    143     free (R     );
    144     free (D     );
    145     free (zone  );
    146     free (band  );
    147     free (Xo    );
    148     free (Yo    );
    149     free (dX    );
    150     free (dY    );
    151     free (index );
    152     free (name  );
    153   }
    154 
    155   gfits_free_header (&header);
    156   gfits_free_matrix (&matrix);
    157   fclose (f);
     141  // need to create and assign to flat-field correction
     142  GET_COLUMN_NEW(&headerCell, &ftableCell, R,     "RA",          double);
     143  GET_COLUMN_NEW(&headerCell, &ftableCell, D,     "DEC",         double);
     144  GET_COLUMN_NEW(&headerCell, &ftableCell, zone,  "ZONE",        int);
     145  GET_COLUMN_NEW(&headerCell, &ftableCell, band,  "BAND",        int);
     146  GET_COLUMN_NEW(&headerCell, &ftableCell, index, "INDEX",       int);
     147  GET_COLUMN_NEW(&headerCell, &ftableCell, Xo,    "X_CENT",      double);
     148  GET_COLUMN_NEW(&headerCell, &ftableCell, Yo,    "Y_CENT",      double);
     149  GET_COLUMN_NEW(&headerCell, &ftableCell, dX,    "X_GRID",      int);
     150  GET_COLUMN_NEW(&headerCell, &ftableCell, dY,    "Y_GRID",      int);
     151  GET_COLUMN_NEW(&headerCell, &ftableCell, name,  "NAME",        char); // XXX how is this done?
     152  gfits_free_header (&headerCell);
     153  gfits_free_table  (&ftableCell);
     154
     155  fprintf (stderr, "loaded data for %lld cells\n", (long long) Nrow);
     156
     157  // assign the storage arrays
     158  for (i = 0; i < Nrow; i++) {
     159    nz = zone[i];
     160    nb = band[i];
     161    tree->ra[nz][nb] = R[i];
     162    tree->dec[nz][nb] = D[i];
     163    tree->Xo[nz][nb] = Xo[i];
     164    tree->Yo[nz][nb] = Yo[i];
     165    tree->dX[nz][nb] = dX[i];
     166    tree->dY[nz][nb] = dY[i];
     167    tree->cell[nz][nb] = i; // XXX ?
     168    memcpy(tree->name[nz][nb], &name[i*BOUNDARY_TREE_NAME_LENGTH], BOUNDARY_TREE_NAME_LENGTH);
     169    // XXX parse out the ID from the name (skycell.NNNN)
     170    tree->projID[nz][nb] = atoi(&tree->name[nz][nb][8]);
     171  }
     172
     173  free (R     );
     174  free (D     );
     175  free (zone  );
     176  free (band  );
     177  free (Xo    );
     178  free (Yo    );
     179  free (dX    );
     180  free (dY    );
     181  free (index );
     182  free (name  );
    158183
    159184  return tree;
    160185
    161186escape:
    162   gfits_free_header (&header);
    163   gfits_free_matrix (&matrix);
    164   gfits_free_header (&theader);
    165   gfits_free_table  (&ftable);
     187  gfits_free_header (&headerCell);
     188  gfits_free_table  (&ftableCell);
     189  gfits_free_table  (&ftableZone);
    166190  if (tree) free (tree);
    167191
    168   fclose (f);
    169192  return NULL;
    170193}
     
    173196int BoundaryTreeSave(char *filename, BoundaryTree *tree) {
    174197
    175   int i, nz, nb;
    176198  Header header;
    177   Header theader;
    178199  Matrix matrix;
    179   FTable ftable;
    180200
    181201  gfits_init_header (&header);
     
    202222  gfits_free_header (&header);
    203223  gfits_free_matrix (&matrix);
     224
     225  BoundaryTreeWrite (f, tree);
     226  fclose (f);
     227
     228  return TRUE;
     229}
     230
     231int BoundaryTreeWrite(FILE *f, BoundaryTree *tree) {
     232
     233  int i, nz, nb;
     234  Header theader;
     235  FTable ftable;
    204236
    205237  /*** zone information table ***/
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/ImageMetadataSelection.c

    r35416 r36680  
    1818  field.pc1_2  = field.pc2_1  = 0.0;
    1919  field.Npolyterms = 0;
    20   strcpy (field.ctype, "RA---SIN");
     20  strcpy (field.ctype, "DEC--SIN");
    2121
    2222  /* mosaic defines a frame with 0,0 at the mosaic center, and 1 arcsec / pixel */
     
    2626  mosaic.pc1_2  = mosaic.pc2_1  = 0.0;
    2727  mosaic.Npolyterms = 0;
    28   strcpy (mosaic.ctype, "RA---SIN");
     28  strcpy (mosaic.ctype, "DEC--SIN");
    2929
    3030  if ((image = ImageMetadataLoad (filename, &Nimage)) == NULL) return (FALSE);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/ImageSelection.c

    r35416 r36680  
    2828      mosaic.pc1_2  = mosaic.pc2_1  = 0.0;
    2929      mosaic.Npolyterms = 0;
    30       strcpy (mosaic.ctype, "RA---SIN");
     30      strcpy (mosaic.ctype, "DEC--SIN");
    3131  }
    3232
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/coordops.c

    r34088 r36680  
    11# include <dvo.h>
     2
     3/* note that Coords.ctype carries the DEC (ctype2) value */
    24
    35static Coords mosaic;
     
    621623
    622624  /* modifications to the ctype? */
     625  /* note that Coords.ctype carries the DEC (ctype2) value */
    623626  OldAIPS = FALSE;
    624627  gfits_modify (header, "CTYPE2",   "%s",  1, coords[0].ctype);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dbCheckStack.c

    r35755 r36680  
    77// these would be better done using bit values to test for field? temp? float?
    88//
    9 
    10 #define OPIHI_INT 1
    119
    1210int dbCheckStack (dbStack *stack, int Nstack, int table, dbField **inFields, int *inNfields) {
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dbExtractAverages.c

    r35416 r36680  
    151151    case AVE_TRANGE:
    152152      value.Flt = TimeValue (average[0].Trange, 0, TimeFormat);
     153      break;
     154
     155    case AVE_PSF_QF:
     156      value.Flt = average[0].psfQF;
     157      break;
     158    case AVE_PSF_QF_PERF:
     159      value.Flt = average[0].psfQFperf;
     160      break;
     161    case AVE_STARGAL:
     162      value.Flt = average[0].stargal;
    153163      break;
    154164
     
    201211            }
    202212          } else {
    203             value.Flt = PhotdM (field->photcode, average, secfilt);
     213            value.Flt = PhotAveErr (field->photcode, average, secfilt);
    204214          }
    205215          break;
     
    233243          break;
    234244
     245        case MAG_APER:
     246        case MAG_APER_AVE:
     247          value.Flt = PhotAperAve (field->photcode, average, secfilt);
     248          break;
     249
     250        case MAG_APER_REF:
     251          value.Flt = PhotAperRef (field->photcode, average, secfilt, measure);
     252          break;
     253
    235254        case MAG_KRON:
     255        case MAG_KRON_AVE:
    236256          value.Flt = PhotKronAve (field->photcode, average, secfilt);
     257          break;
     258
     259        case MAG_KRON_REF:
     260          value.Flt = PhotKronRef (field->photcode, average, secfilt, measure);
    237261          break;
    238262
     
    269293      break;
    270294    case AVE_dMAG:
    271       value.Flt = PhotdM (field->photcode, average, secfilt);
     295      value.Flt = PhotAveErr (field->photcode, average, secfilt);
    272296      break;
    273297    case AVE_Xm:
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dbExtractMeasures.c

    r35508 r36680  
    123123          case MAG_REL:
    124124          case MAG_CAL:
    125           case MAG_APER:
     125          case MAG_ERR:
     126
    126127          case MAG_APER_INST:
    127           case MAG_KRON:
     128          case MAG_APER_CAT:
     129          case MAG_APER_SYS:
     130          case MAG_APER_REL:
     131          case MAG_APER_CAL:
     132          case MAG_APER_ERR:
     133
    128134          case MAG_KRON_INST:
     135          case MAG_KRON_CAT:
     136          case MAG_KRON_SYS:
     137          case MAG_KRON_REL:
     138          case MAG_KRON_CAL:
    129139          case MAG_KRON_ERR:
    130           case MAG_ERR:
     140
    131141          case MAG_PHOT_FLAGS:
    132142            equiv = myEquiv;
     
    137147          case MAG_AVE:
    138148          case MAG_REF:
     149          case MAG_STDEV:
     150          case MAG_AVE_ERR:
    139151          case MAG_CHISQ:
    140           case MAG_AVE_ERR:
     152          case MAG_FLUX_PSF:
     153          case MAG_FLUX_PSF_ERR:
     154
     155          case MAG_APER_AVE:
     156
     157          case MAG_KRON_AVE:
     158          case MAG_FLUX_KRON:
     159          case MAG_FLUX_KRON_ERR:
     160
     161          case MAG_20:
     162          case MAG_80:
     163          case MAG_UC_DIST:
     164          case MAG_STACK_DET_ID:
     165
    141166          case MAG_NCODE:
    142167          case MAG_NPHOT:
    143           case MAG_FLUX_PSF:
    144           case MAG_FLUX_PSF_ERR:
    145           case MAG_FLUX_KRON:
    146           case MAG_FLUX_KRON_ERR:
    147168            equiv = field->photcode;
    148169            goto valid_photcode;
     
    178199          value.Flt = PhotRef  (equiv, average, secfilt, measure);
    179200          break;
    180         case MAG_APER:
    181           value.Flt = PhotAper (measure);
    182           break;
     201        case MAG_ERR:
     202          value.Flt = measure[0].dM;
     203          break;
     204        case MAG_AVE_ERR:
     205          value.Flt = PhotAveErr  (equiv, average, secfilt);
     206          break;
     207
    183208        case MAG_APER_INST:
    184209          value.Flt = PhotAperInst (measure);
    185210          break;
    186         case MAG_KRON:
    187           value.Flt = PhotKron (measure);
    188           break;
     211        case MAG_APER_CAT:
     212          value.Flt = PhotAperCat (measure);
     213          break;
     214        case MAG_APER_SYS:
     215          value.Flt = PhotAperSys (measure, average, secfilt);
     216          break;
     217        case MAG_APER:
     218        case MAG_APER_REL:
     219          value.Flt = PhotAperRel (measure, average, secfilt);
     220          break;
     221        case MAG_APER_CAL:
     222          value.Flt = PhotAperCal (measure, average, secfilt, measure, equiv);
     223          break;
     224        case MAG_APER_AVE:
     225          value.Flt = PhotAperAve (equiv, average, secfilt);
     226          break;
     227        case MAG_APER_REF:
     228          value.Flt = PhotAperRef (equiv, average, secfilt, measure);
     229          break;
     230        case MAG_APER_ERR:
     231          value.Flt = measure[0].dM;
     232          break;
     233
    189234        case MAG_KRON_INST:
    190235          value.Flt = PhotKronInst (measure);
    191236          break;
     237        case MAG_KRON_CAT:
     238          value.Flt = PhotKronCat (measure);
     239          break;
     240        case MAG_KRON_SYS:
     241          value.Flt = PhotKronSys (measure, average, secfilt);
     242          break;
     243        case MAG_KRON:
     244        case MAG_KRON_REL:
     245          value.Flt = PhotKronRel (measure, average, secfilt);
     246          break;
     247        case MAG_KRON_CAL:
     248          value.Flt = PhotKronCal (measure, average, secfilt, measure, equiv);
     249          break;
     250        case MAG_KRON_AVE:
     251          value.Flt = PhotKronAve (equiv, average, secfilt);
     252          break;
     253        case MAG_KRON_REF:
     254          value.Flt = PhotKronRef (equiv, average, secfilt, measure);
     255          break;
    192256        case MAG_KRON_ERR:
    193           value.Flt = measure[0].dMkron;
    194           break;
    195         case MAG_ERR:
    196           value.Flt = measure[0].dM;
    197           break;
    198         case MAG_AVE_ERR:
    199           value.Flt = PhotdM  (equiv, average, secfilt);
    200           break;
     257          value.Flt = measure[0].dMkron;
     258          break;
     259
    201260        case MAG_PHOT_FLAGS:
    202261          if ((field->photcode->type == PHOT_REF) || (field->photcode->type == PHOT_DEP)) {
    203262            value.Int = measure[0].photFlags;
    204           } else {
    205             value.Int = 0;
    206263          }
    207264          break;
    208         case MAG_CHISQ:
    209           value.Flt = PhotXm  (equiv, average, secfilt);
    210           break;
     265
    211266        case MAG_NCODE:
    212           if (equiv == NULL) {
    213             value.Int = 0;
    214             break;
    215           }
     267          if (equiv == NULL) break;
    216268          Nsec = GetPhotcodeNsec (equiv->code);
    217269          if (Nsec == -1) break;
     
    219271          break;
    220272        case MAG_NPHOT:
    221           if (equiv == NULL) {
    222             value.Int = 0;
    223             break;
    224           }
     273          if (equiv == NULL) break;
    225274          Nsec = GetPhotcodeNsec (equiv->code);
    226275          if (Nsec == -1) break;
    227276          value.Int = secfilt[Nsec].Nused;
    228277          break;
     278
     279        case MAG_CHISQ:
     280          value.Flt = PhotXm (equiv, average, secfilt);
     281          break;
     282        case MAG_STDEV:
     283          value.Flt = PhotMstdev (equiv, average, secfilt);
     284          break;
     285        case MAG_20:
     286          value.Flt = PhotM20 (equiv, average, secfilt);
     287          break;
     288        case MAG_80:
     289          value.Flt = PhotM80 (equiv, average, secfilt);
     290          break;
     291        case MAG_UC_DIST:
     292          value.Flt = PhotUCdist (equiv, average, secfilt);
     293          break;
     294
    229295        case MAG_FLUX_PSF:
    230296          value.Flt = PhotAveFluxPSF (field->photcode, average, secfilt);
     
    531597          fieldc = MatchFieldMetadata (measure[0].imageID);
    532598        } else {
    533           fprintf (stderr, "non-parallel Xmos broken\n");
    534           abort();
     599          // fprintf (stderr, "non-parallel Xmos broken\n");
     600          // abort();
    535601          // fieldc = MatchField (measure[0].t, measure[0].photcode);
     602          fieldc = MatchFieldMetadata (measure[0].imageID);
    536603        }
    537604        if (fieldc == NULL) break;
     
    547614          fieldc = MatchFieldMetadata (measure[0].imageID);
    548615        } else {
    549           fprintf (stderr, "non-parallel Xmos broken\n");
    550           abort();
     616          // fprintf (stderr, "non-parallel Xmos broken\n");
     617          // abort();
    551618          // fieldc = MatchField (measure[0].t, measure[0].photcode);
     619          fieldc = MatchFieldMetadata (measure[0].imageID);
    552620        }
    553621        if (fieldc == NULL) break;
     
    564632          mosaic = MatchMosaicMetadata (measure[0].imageID);
    565633        } else {
    566           fprintf (stderr, "non-parallel Xmos broken\n");
    567           abort();
    568           mosaic = MatchMosaic (measure[0].t, measure[0].photcode);
     634          // fprintf (stderr, "non-parallel Xmos broken\n");
     635          // abort();
     636          // mosaic = MatchMosaic (measure[0].t, measure[0].photcode);
     637          mosaic = MatchMosaicMetadata (measure[0].imageID);
    569638        }
    570639        if (mosaic == NULL) break;
     
    580649          mosaic = MatchMosaicMetadata (measure[0].imageID);
    581650        } else {
    582           fprintf (stderr, "non-parallel Xmos broken\n");
    583           abort();
    584           mosaic = MatchMosaic (measure[0].t, measure[0].photcode);
     651          // fprintf (stderr, "non-parallel Xmos broken\n");
     652          // abort();
     653          // mosaic = MatchMosaic (measure[0].t, measure[0].photcode);
     654          mosaic = MatchMosaicMetadata (measure[0].imageID);
    585655        }
    586656        if (mosaic == NULL) break;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dbFields.c

    r35416 r36680  
    3030int GetMagMode (char *string) {
    3131
     32  // these all imply PSF mags:
    3233  if (!strcasecmp (string, "inst"))        return (MAG_INST);
    3334  if (!strcasecmp (string, "cat"))         return (MAG_CAT);
     
    3738  if (!strcasecmp (string, "ave"))         return (MAG_AVE);
    3839  if (!strcasecmp (string, "ref"))         return (MAG_REF);
     40  if (!strcasecmp (string, "err"))         return (MAG_ERR);
     41  if (!strcasecmp (string, "aveerr"))      return (MAG_AVE_ERR);
     42
     43  // these are explicit PSF mags:
     44  if (!strcasecmp (string, "psf_inst"))    return (MAG_INST);
     45  if (!strcasecmp (string, "psf_cat"))     return (MAG_CAT);
     46  if (!strcasecmp (string, "psf_sys"))     return (MAG_SYS);
     47  if (!strcasecmp (string, "psf_rel"))     return (MAG_REL);
     48  if (!strcasecmp (string, "psf_cal"))     return (MAG_CAL);
     49  if (!strcasecmp (string, "psf_ave"))     return (MAG_AVE);
     50  if (!strcasecmp (string, "psf_ref"))     return (MAG_REF);
     51  if (!strcasecmp (string, "psf_err"))     return (MAG_ERR);
     52  if (!strcasecmp (string, "psf_aveerr"))  return (MAG_AVE_ERR);
     53
     54  // these are aper mags:
    3955  if (!strcasecmp (string, "ap"))          return (MAG_APER);
    4056  if (!strcasecmp (string, "aper"))        return (MAG_APER);
    4157  if (!strcasecmp (string, "aperinst"))    return (MAG_APER_INST);
    4258  if (!strcasecmp (string, "aper_inst"))   return (MAG_APER_INST);
     59  if (!strcasecmp (string, "aper_cat"))    return (MAG_APER_CAT);
     60  if (!strcasecmp (string, "aper_sys"))    return (MAG_APER_SYS);
     61  if (!strcasecmp (string, "aper_rel"))    return (MAG_APER_REL);
     62  if (!strcasecmp (string, "aper_cal"))    return (MAG_APER_CAL);
     63  if (!strcasecmp (string, "aper_ave"))    return (MAG_APER_AVE);
     64  if (!strcasecmp (string, "aper_ref"))    return (MAG_APER_REF);
     65  if (!strcasecmp (string, "aper_err"))    return (MAG_APER_ERR);
     66
     67  // these are kron mags:
    4368  if (!strcasecmp (string, "kron"))        return (MAG_KRON);
     69  if (!strcasecmp (string, "kron_inst"))   return (MAG_KRON_INST);
     70  if (!strcasecmp (string, "kron_cat"))    return (MAG_KRON_CAT);
     71  if (!strcasecmp (string, "kron_sys"))    return (MAG_KRON_SYS);
     72  if (!strcasecmp (string, "kron_rel"))    return (MAG_KRON_REL);
     73  if (!strcasecmp (string, "kron_cal"))    return (MAG_KRON_CAL);
     74  if (!strcasecmp (string, "kron_ave"))    return (MAG_KRON_AVE);
     75  if (!strcasecmp (string, "kron_ref"))    return (MAG_KRON_REF);
     76  if (!strcasecmp (string, "kron_err"))    return (MAG_KRON_ERR);
    4477  if (!strcasecmp (string, "kroninst"))    return (MAG_KRON_INST);
    45   if (!strcasecmp (string, "kron_inst"))   return (MAG_KRON_INST);
    4678  if (!strcasecmp (string, "kronerr"))     return (MAG_KRON_ERR);
    47   if (!strcasecmp (string, "err"))         return (MAG_ERR);
    48   if (!strcasecmp (string, "aveerr"))      return (MAG_AVE_ERR);
     79
     80  // other fields:
    4981  if (!strcasecmp (string, "photflags"))   return (MAG_PHOT_FLAGS);
    5082  if (!strcasecmp (string, "flags"))       return (MAG_PHOT_FLAGS);
     
    314346  }
    315347
    316   if (!strcasecmp (fieldName, "RA"))        ESCAPE (AVE_RA,        MAG_NONE, OPIHI_FLT);
    317   if (!strcasecmp (fieldName, "DEC"))       ESCAPE (AVE_DEC,       MAG_NONE, OPIHI_FLT);
    318   if (!strcasecmp (fieldName, "GLON"))      ESCAPE (AVE_GLON,      MAG_NONE, OPIHI_FLT);
    319   if (!strcasecmp (fieldName, "GLAT"))      ESCAPE (AVE_GLAT,      MAG_NONE, OPIHI_FLT);
    320   if (!strcasecmp (fieldName, "ELON"))      ESCAPE (AVE_ELON,      MAG_NONE, OPIHI_FLT);
    321   if (!strcasecmp (fieldName, "ELAT"))      ESCAPE (AVE_ELAT,      MAG_NONE, OPIHI_FLT);
    322   if (!strcasecmp (fieldName, "dRA"))       ESCAPE (AVE_RA_ERR,    MAG_NONE, OPIHI_FLT);
    323   if (!strcasecmp (fieldName, "dDEC"))      ESCAPE (AVE_DEC_ERR,   MAG_NONE, OPIHI_FLT);
    324   if (!strcasecmp (fieldName, "uRA"))       ESCAPE (AVE_U_RA,      MAG_NONE, OPIHI_FLT);
    325   if (!strcasecmp (fieldName, "uDEC"))      ESCAPE (AVE_U_DEC,     MAG_NONE, OPIHI_FLT);
    326   if (!strcasecmp (fieldName, "duRA"))      ESCAPE (AVE_U_RA_ERR,  MAG_NONE, OPIHI_FLT);
    327   if (!strcasecmp (fieldName, "duDEC"))     ESCAPE (AVE_U_DEC_ERR, MAG_NONE, OPIHI_FLT);
    328   if (!strcasecmp (fieldName, "PAR"))       ESCAPE (AVE_PAR,       MAG_NONE, OPIHI_FLT);
    329   if (!strcasecmp (fieldName, "dPAR"))      ESCAPE (AVE_PAR_ERR,   MAG_NONE, OPIHI_FLT);
    330   if (!strcasecmp (fieldName, "ChiSqPos"))  ESCAPE (AVE_CHISQ_POS, MAG_NONE, OPIHI_FLT);
    331   if (!strcasecmp (fieldName, "ChiSqPM"))   ESCAPE (AVE_CHISQ_PM,  MAG_NONE, OPIHI_FLT);
    332   if (!strcasecmp (fieldName, "ChiSqPar"))  ESCAPE (AVE_CHISQ_PAR, MAG_NONE, OPIHI_FLT);
    333   if (!strcasecmp (fieldName, "Tmean"))     ESCAPE (AVE_TMEAN,     MAG_NONE, OPIHI_FLT);
    334   if (!strcasecmp (fieldName, "Trange"))    ESCAPE (AVE_TRANGE,    MAG_NONE, OPIHI_FLT);
    335   if (!strcasecmp (fieldName, "NMEAS"))     ESCAPE (AVE_NMEAS,     MAG_NONE, OPIHI_INT);
    336   if (!strcasecmp (fieldName, "NMISS"))     ESCAPE (AVE_NMISS,     MAG_NONE, OPIHI_INT);
    337   if (!strcasecmp (fieldName, "NPOS"))      ESCAPE (AVE_NPOS,      MAG_NONE, OPIHI_INT);
    338   if (!strcasecmp (fieldName, "NASTROM"))   ESCAPE (AVE_NPOS,      MAG_NONE, OPIHI_INT);
    339   if (!strcasecmp (fieldName, "FLAGS"))     ESCAPE (AVE_OBJ_FLAGS, MAG_NONE, OPIHI_INT);
    340   if (!strcasecmp (fieldName, "OBJ_FLAGS")) ESCAPE (AVE_OBJ_FLAGS, MAG_NONE, OPIHI_INT);
    341   if (!strcasecmp (fieldName, "OBJFLAGS"))  ESCAPE (AVE_OBJ_FLAGS, MAG_NONE, OPIHI_INT);
    342   if (!strcasecmp (fieldName, "OBJID"))     ESCAPE (AVE_OBJID,     MAG_NONE, OPIHI_INT);
    343   if (!strcasecmp (fieldName, "CATID"))     ESCAPE (AVE_CATID,     MAG_NONE, OPIHI_INT);
    344   if (!strcasecmp (fieldName, "EXTID_HI"))  ESCAPE (AVE_EXTID_HI,  MAG_NONE, OPIHI_INT);
    345   if (!strcasecmp (fieldName, "EXTID_LO"))  ESCAPE (AVE_EXTID_LO,  MAG_NONE, OPIHI_INT);
     348  if (!strcasecmp (fieldName, "RA"))          ESCAPE (AVE_RA,          MAG_NONE, OPIHI_FLT);
     349  if (!strcasecmp (fieldName, "DEC"))         ESCAPE (AVE_DEC,         MAG_NONE, OPIHI_FLT);
     350  if (!strcasecmp (fieldName, "GLON"))        ESCAPE (AVE_GLON,        MAG_NONE, OPIHI_FLT);
     351  if (!strcasecmp (fieldName, "GLAT"))        ESCAPE (AVE_GLAT,        MAG_NONE, OPIHI_FLT);
     352  if (!strcasecmp (fieldName, "ELON"))        ESCAPE (AVE_ELON,        MAG_NONE, OPIHI_FLT);
     353  if (!strcasecmp (fieldName, "ELAT"))        ESCAPE (AVE_ELAT,        MAG_NONE, OPIHI_FLT);
     354  if (!strcasecmp (fieldName, "dRA"))         ESCAPE (AVE_RA_ERR,      MAG_NONE, OPIHI_FLT);
     355  if (!strcasecmp (fieldName, "dDEC"))        ESCAPE (AVE_DEC_ERR,     MAG_NONE, OPIHI_FLT);
     356  if (!strcasecmp (fieldName, "uRA"))         ESCAPE (AVE_U_RA,        MAG_NONE, OPIHI_FLT);
     357  if (!strcasecmp (fieldName, "uDEC"))        ESCAPE (AVE_U_DEC,       MAG_NONE, OPIHI_FLT);
     358  if (!strcasecmp (fieldName, "duRA"))        ESCAPE (AVE_U_RA_ERR,    MAG_NONE, OPIHI_FLT);
     359  if (!strcasecmp (fieldName, "duDEC"))       ESCAPE (AVE_U_DEC_ERR,   MAG_NONE, OPIHI_FLT);
     360  if (!strcasecmp (fieldName, "PAR"))         ESCAPE (AVE_PAR,         MAG_NONE, OPIHI_FLT);
     361  if (!strcasecmp (fieldName, "dPAR"))        ESCAPE (AVE_PAR_ERR,     MAG_NONE, OPIHI_FLT);
     362  if (!strcasecmp (fieldName, "ChiSqPos"))    ESCAPE (AVE_CHISQ_POS,   MAG_NONE, OPIHI_FLT);
     363  if (!strcasecmp (fieldName, "ChiSqPM"))     ESCAPE (AVE_CHISQ_PM,    MAG_NONE, OPIHI_FLT);
     364  if (!strcasecmp (fieldName, "ChiSqPar"))    ESCAPE (AVE_CHISQ_PAR,   MAG_NONE, OPIHI_FLT);
     365  if (!strcasecmp (fieldName, "Tmean"))       ESCAPE (AVE_TMEAN,       MAG_NONE, OPIHI_FLT);
     366  if (!strcasecmp (fieldName, "Trange"))      ESCAPE (AVE_TRANGE,      MAG_NONE, OPIHI_FLT);
     367  if (!strcasecmp (fieldName, "psfqf"))       ESCAPE (AVE_PSF_QF,      MAG_NONE, OPIHI_FLT);
     368  if (!strcasecmp (fieldName, "psfqfperf"))   ESCAPE (AVE_PSF_QF_PERF, MAG_NONE, OPIHI_FLT);
     369  if (!strcasecmp (fieldName, "psf_qf"))      ESCAPE (AVE_PSF_QF,      MAG_NONE, OPIHI_FLT);
     370  if (!strcasecmp (fieldName, "psf_qf_perf")) ESCAPE (AVE_PSF_QF_PERF, MAG_NONE, OPIHI_FLT);
     371  if (!strcasecmp (fieldName, "stargal"))     ESCAPE (AVE_STARGAL,     MAG_NONE, OPIHI_FLT);
     372  if (!strcasecmp (fieldName, "NMEAS"))       ESCAPE (AVE_NMEAS,       MAG_NONE, OPIHI_INT);
     373  if (!strcasecmp (fieldName, "NMISS"))       ESCAPE (AVE_NMISS,       MAG_NONE, OPIHI_INT);
     374  if (!strcasecmp (fieldName, "NPOS"))        ESCAPE (AVE_NPOS,        MAG_NONE, OPIHI_INT);
     375  if (!strcasecmp (fieldName, "NASTROM"))     ESCAPE (AVE_NPOS,        MAG_NONE, OPIHI_INT);
     376  if (!strcasecmp (fieldName, "FLAGS"))       ESCAPE (AVE_OBJ_FLAGS,   MAG_NONE, OPIHI_INT);
     377  if (!strcasecmp (fieldName, "OBJ_FLAGS"))   ESCAPE (AVE_OBJ_FLAGS,   MAG_NONE, OPIHI_INT);
     378  if (!strcasecmp (fieldName, "OBJFLAGS"))    ESCAPE (AVE_OBJ_FLAGS,   MAG_NONE, OPIHI_INT);
     379  if (!strcasecmp (fieldName, "OBJID"))       ESCAPE (AVE_OBJID,       MAG_NONE, OPIHI_INT);
     380  if (!strcasecmp (fieldName, "CATID"))       ESCAPE (AVE_CATID,       MAG_NONE, OPIHI_INT);
     381  if (!strcasecmp (fieldName, "EXTID_HI"))    ESCAPE (AVE_EXTID_HI,    MAG_NONE, OPIHI_INT);
     382  if (!strcasecmp (fieldName, "EXTID_LO"))    ESCAPE (AVE_EXTID_LO,    MAG_NONE, OPIHI_INT);
    346383
    347384  // check for code:mode in photcode name
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_catalog.c

    r35416 r36680  
    119119  average->measureOffset   = -1;
    120120  average->catID           = 0;
     121  average->nOwn            = 0;
    121122}
    122123
     
    242243 measure->dYccd     = 0;
    243244 measure->dRsys     = 0;
     245 measure->myDet     = FALSE;
    244246}
    245247
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_convert.c

    r35172 r36680  
    6565  }
    6666
     67  // block to convert broken tables (PS1_V4 made before the Xfix addition)
     68  if (!strcmp (extname, "DVO_AVERAGE_PS1_V4") && (ftable[0].header[0].Naxis[0] == 120)) {
     69    Average_PS1_V4alt *tmpAverage;
     70    tmpAverage = gfits_table_get_Average_PS1_V4alt (ftable, Naverage, NULL);
     71    if (!tmpAverage) {
     72      fprintf (stderr, "ERROR: failed to read averages\n");
     73      exit (2);
     74    }
     75    average = Average_PS1_V4alt_ToInternal (tmpAverage, *Naverage);
     76    free (tmpAverage);
     77    *format = DVO_FORMAT_PS1_V4;
     78    return (average);
     79  }
     80
    6781# define CONVERT_FORMAT(NAME, FORMAT, TYPE) \
    6882  if (!strcmp (extname, NAME)) { \
     
    154168    fprintf (stderr, "EXTNAME missing for measure table\n");
    155169    return (FALSE);
     170  }
     171
     172  // block to convert broken tables (PS1_V4 made before the Xfix addition)
     173  if (!strcmp (extname, "DVO_MEASURE_PS1_V4") && (ftable[0].header[0].Naxis[0] == 176)) {
     174    fprintf (stderr, "reading alt PS1_V4 format\n");
     175    Measure_PS1_V4alt *tmpMeasure;
     176    tmpMeasure = gfits_table_get_Measure_PS1_V4alt (ftable, Nmeasure, NULL);
     177    if (!tmpMeasure) {
     178      fprintf (stderr, "ERROR: failed to read measures\n");
     179      exit (2);
     180    }
     181    measure = Measure_PS1_V4alt_ToInternal (tmpMeasure, *Nmeasure);
     182    free (tmpMeasure);
     183    *format = DVO_FORMAT_PS1_V4;
     184    return (measure);
    156185  }
    157186
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_convert_PS1_V4.c

    r35162 r36680  
    481481  return (out);
    482482}
     483
     484/*** there are some mini dvodbs with the wrong PS1_V4 format (missing Xoff,Yoff / Xfix,Yfix) ************/
     485
     486Measure *Measure_PS1_V4alt_ToInternal (Measure_PS1_V4alt *in, off_t Nvalues) {
     487
     488  off_t i;
     489  Measure *out;
     490
     491  ALLOCATE_ZERO (out, Measure, Nvalues);
     492
     493  for (i = 0; i < Nvalues; i++) {
     494    dvo_measure_init (&out[i]);
     495
     496    out[i].dR         = in[i].dR;
     497    out[i].dD         = in[i].dD;
     498    out[i].M          = in[i].M;
     499    out[i].Mcal       = in[i].Mcal;
     500    out[i].Map        = in[i].Map;
     501    out[i].Mkron      = in[i].Mkron;
     502    out[i].dMkron     = in[i].dMkron;
     503    out[i].dM         = in[i].dM;
     504    out[i].dMcal      = in[i].dMcal;
     505    out[i].dt         = in[i].dt;
     506    out[i].FluxPSF    = in[i].FluxPSF;
     507    out[i].dFluxPSF   = in[i].dFluxPSF;
     508    out[i].FluxKron   = in[i].FluxKron;
     509    out[i].dFluxKron  = in[i].dFluxKron;
     510    out[i].airmass    = in[i].airmass;
     511    out[i].az         = in[i].az;
     512    out[i].Xccd       = in[i].Xccd;
     513    out[i].Yccd       = in[i].Yccd;
     514    out[i].Xfix       = in[i].Xccd;
     515    out[i].Yfix       = in[i].Yccd;
     516    out[i].Sky        = in[i].Sky;
     517    out[i].dSky       = in[i].dSky;
     518    out[i].t          = in[i].t;
     519    out[i].t_msec     = in[i].t_msec;
     520    out[i].averef     = in[i].averef;
     521    out[i].detID      = in[i].detID;
     522    out[i].imageID    = in[i].imageID;
     523    out[i].objID      = in[i].objID;
     524    out[i].catID      = in[i].catID;
     525    out[i].extID      = in[i].extID;
     526    out[i].psfQF      = in[i].psfQF;
     527    out[i].psfQFperf  = in[i].psfQFperf;
     528    out[i].psfChisq   = in[i].psfChisq;
     529    out[i].psfNdof    = in[i].psfNdof;
     530    out[i].psfNpix    = in[i].psfNpix;
     531    out[i].crNsigma   = in[i].crNsigma;
     532    out[i].extNsigma  = in[i].extNsigma;
     533    out[i].FWx        = in[i].FWx;
     534    out[i].FWy        = in[i].FWy;
     535    out[i].theta      = in[i].theta;
     536    out[i].Mxx        = in[i].Mxx;
     537    out[i].Mxy        = in[i].Mxy;
     538    out[i].Myy        = in[i].Myy;
     539    out[i].dXccd      = in[i].dXccd;
     540    out[i].dYccd      = in[i].dYccd;
     541    out[i].dRsys      = in[i].dRsys;
     542    out[i].posangle   = in[i].posangle;
     543    out[i].pltscale   = in[i].pltscale;
     544    out[i].photcode   = in[i].photcode;
     545    out[i].dbFlags    = in[i].dbFlags;
     546    out[i].photFlags  = in[i].photFlags;
     547  }
     548  return (out);
     549}
     550
     551// XXX note that there are 2 bad versions of PS1_V4 : the other one does have have PSF_QF_PERFECT, but has PAD instead
     552int gfits_convert_Measure_PS1_V4alt (Measure_PS1_V4alt *data, off_t size, off_t nitems) {
     553
     554  off_t i;
     555  unsigned char *byte, tmp;
     556
     557  if (size != 176) {
     558    fprintf (stderr, "WARNING: mismatch in data types Measure_PS1_V4alt: "OFF_T_FMT" vs %d\n",  size,  176);
     559    return (FALSE);
     560  }
     561
     562  /* provide initial values to avoid compiler warnings for non-BYTE_SWAP arch */
     563  i = tmp = 0;
     564  byte = NULL;
     565
     566# ifdef BYTE_SWAP
     567  byte = (unsigned char *) data;
     568  for (i = 0; i < nitems; i++, byte += 176) {
     569    /** BYTE SWAP **/
     570    SWAP_WORD (0); // D_RA
     571    SWAP_WORD (4); // D_DEC
     572    SWAP_WORD (8); // MAG
     573    SWAP_WORD (12); // M_CAL
     574    SWAP_WORD (16); // M_APER
     575    SWAP_WORD (20); // M_KRON
     576    SWAP_WORD (24); // M_KRON_ERR
     577    SWAP_WORD (28); // MAG_ERR
     578    SWAP_WORD (32); // MAG_CAL_ERR
     579    SWAP_WORD (36); // M_TIME
     580    SWAP_WORD (40); // FLUX_PSF
     581    SWAP_WORD (44); // FLUX_PSF_ERR
     582    SWAP_WORD (48); // FLUX_KRON
     583    SWAP_WORD (52); // FLUX_KRON_ERR
     584    SWAP_WORD (56); // AIRMASS
     585    SWAP_WORD (60); // AZ
     586    SWAP_WORD (64); // X_CCD
     587    SWAP_WORD (68); // Y_CCD
     588    SWAP_WORD (72); // SKY_FLUX   
     589    SWAP_WORD (76); // SKY_FLUX_ERR
     590    SWAP_WORD (80); // TIME
     591    SWAP_WORD (84); // AVE_REF
     592    SWAP_WORD (88); // DET_ID
     593    SWAP_WORD (92); // IMAGE_ID
     594    SWAP_WORD (96); // OBJ_ID
     595    SWAP_WORD (100); // CAT_ID
     596    SWAP_DBLE (104); // EXT_ID
     597    SWAP_WORD (112); // PSF_QF       
     598    SWAP_WORD (116); // PSF_QF_PERFECT
     599    SWAP_WORD (120); // PSF_CHISQ     
     600    SWAP_WORD (124); // PSF_NDOF     
     601    SWAP_WORD (128); // PSF_NPIX     
     602    SWAP_WORD (132); // CR_NSIGMA     
     603    SWAP_WORD (136); // EXT_NSIGMA   
     604    SWAP_BYTE (140); // FWHM_MAJOR
     605    SWAP_BYTE (142); // FWHM_MINOR
     606    SWAP_BYTE (144); // PSF_THETA 
     607    SWAP_BYTE (146); // MXX       
     608    SWAP_BYTE (148); // MXY       
     609    SWAP_BYTE (150); // MYY       
     610    SWAP_BYTE (152); // TIME_MSEC 
     611    SWAP_BYTE (154); // PHOTCODE   
     612    SWAP_BYTE (156); // X_CCD_ERR 
     613    SWAP_BYTE (158); // Y_CCD_ERR 
     614    SWAP_BYTE (160); // POS_SYS_ERR
     615    SWAP_BYTE (162); // POSANGLE   
     616    SWAP_WORD (164); // PLTSCALE 
     617    SWAP_WORD (168); // DB_FLAGS 
     618    SWAP_WORD (172); // PHOT_FLAGS
     619  }
     620# endif 
     621
     622  return (TRUE);
     623}
     624
     625/*** add test of EXTNAME and header-defined columns? ***/
     626/* return internal structure representation */
     627Measure_PS1_V4alt *gfits_table_get_Measure_PS1_V4alt (FTable *ftable, off_t *Ndata, char *swapped) {
     628
     629  int Ncols;
     630  Measure_PS1_V4alt *data;
     631
     632  Ncols = ftable[0].header[0].Naxis[0];
     633  if (Ncols != 176) {
     634    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, 176);
     635    return NULL;
     636  }
     637
     638  *Ndata = ftable[0].header[0].Naxis[1];
     639  data = (Measure_PS1_V4alt *) ftable[0].buffer;
     640  if ((swapped == NULL) || (*swapped == FALSE)) {
     641    if (!gfits_convert_Measure_PS1_V4alt (data, sizeof (Measure_PS1_V4alt), *Ndata)) {
     642      return NULL;
     643    }
     644    gfits_table_scale_data (ftable);
     645    if (swapped != NULL) *swapped = TRUE;
     646  }
     647  return (data);
     648}
     649
     650// 'primary' is needed to conform with the API for Loneos and Elixir, but is not used
     651Average *Average_PS1_V4alt_ToInternal (Average_PS1_V4alt *in, off_t Nvalues) {
     652
     653  off_t i;
     654  Average *out;
     655
     656  ALLOCATE_ZERO (out, Average, Nvalues);
     657
     658  for (i = 0; i < Nvalues; i++) {
     659    dvo_average_init (&out[i]);
     660
     661    out[i].R             = in[i].R;     
     662    out[i].D             = in[i].D;     
     663    out[i].dR            = in[i].dR;
     664    out[i].dD            = in[i].dD;
     665    out[i].uR            = in[i].uR;
     666    out[i].uD            = in[i].uD;
     667    out[i].duR           = in[i].duR;
     668    out[i].duD           = in[i].duD;
     669    out[i].P             = in[i].P;
     670    out[i].dP            = in[i].dP;
     671    out[i].ChiSqAve      = in[i].ChiSqAve;     
     672    out[i].ChiSqPM       = in[i].ChiSqPM;     
     673    out[i].ChiSqPar      = in[i].ChiSqPar;     
     674    out[i].Tmean         = in[i].Tmean;     
     675    out[i].Trange        = in[i].Trange;     
     676    out[i].Npos          = in[i].Npos;     
     677    out[i].Nmeasure      = in[i].Nmeasure;     
     678    out[i].Nmissing      = in[i].Nmissing;     
     679    out[i].Nextend       = in[i].Nextend;     
     680    out[i].measureOffset = in[i].measureOffset;
     681    out[i].missingOffset = in[i].missingOffset;
     682    out[i].extendOffset  = in[i].extendOffset;
     683    out[i].flags         = in[i].flags;   
     684    out[i].photFlagsUpper = in[i].photFlagsUpper;   
     685    out[i].photFlagsLower = in[i].photFlagsLower;   
     686    out[i].objID         = in[i].objID;
     687    out[i].catID         = in[i].catID;
     688    out[i].extID         = in[i].extID;
     689  }
     690  return (out);
     691}
     692
     693/******/
     694
     695int gfits_convert_Average_PS1_V4alt (Average_PS1_V4alt *data, off_t size, off_t nitems) {
     696
     697  off_t i;
     698  unsigned char *byte, tmp;
     699
     700  if (size != 120) {
     701    fprintf (stderr, "WARNING: mismatch in data types Average_PS1_V4alt: "OFF_T_FMT" vs %d\n",  size,  120);
     702    return (FALSE);
     703  }
     704
     705  /* provide initial values to avoid compiler warnings for non-BYTE_SWAP arch */
     706  i = tmp = 0;
     707  byte = NULL;
     708
     709# ifdef BYTE_SWAP
     710  byte = (unsigned char *) data;
     711  for (i = 0; i < nitems; i++, byte += 120) {
     712    /** BYTE SWAP **/
     713    SWAP_DBLE (0); // RA
     714    SWAP_DBLE (8); // DEC
     715    SWAP_WORD (16); // RA_ERR
     716    SWAP_WORD (20); // DEC_ERR
     717    SWAP_WORD (24); // U_RA
     718    SWAP_WORD (28); // U_DEC
     719    SWAP_WORD (32); // V_RA_ERR
     720    SWAP_WORD (36); // V_DEC_ERR
     721    SWAP_WORD (40); // PAR
     722    SWAP_WORD (44); // PAR_ERR
     723    SWAP_WORD (48); // CHISQ_POS
     724    SWAP_WORD (52); // CHISQ_PM
     725    SWAP_WORD (56); // CHISQ_PAP
     726    SWAP_WORD (60); // MEAN_EPOCH
     727    SWAP_WORD (64); // TIME_RANGE
     728    SWAP_WORD (68); // SIGMA
     729    SWAP_BYTE (72); // NUMBER_POS
     730    SWAP_BYTE (74); // NMEASURE
     731    SWAP_BYTE (76); // NMISSING
     732    SWAP_BYTE (78); // NEXTEND
     733    SWAP_WORD (80); // OFF_MEASURE
     734    SWAP_WORD (84); // OFF_MISSING
     735    SWAP_WORD (88); // OFF_EXTEND
     736    SWAP_WORD (92); // FLAGS
     737    SWAP_WORD (96); // PHOTFLAGS_U
     738    SWAP_WORD (100); // PHOTFLAGS_L
     739    SWAP_WORD (104); // OBJ_ID
     740    SWAP_WORD (108); // CAT_ID
     741    SWAP_DBLE (112); // EXT_ID
     742  }
     743# endif 
     744
     745  return (TRUE);
     746}
     747
     748/*** add test of EXTNAME and header-defined columns? ***/
     749/* return internal structure representation */
     750Average_PS1_V4alt *gfits_table_get_Average_PS1_V4alt (FTable *ftable, off_t *Ndata, char *swapped) {
     751
     752  int Ncols;
     753  Average_PS1_V4alt *data;
     754
     755  Ncols = ftable[0].header[0].Naxis[0];
     756  if (Ncols != 120) {
     757    fprintf (stderr, "ERROR: mis-match in table size: width is %d but should be %d bytes\n", Ncols, 120);
     758    return NULL;
     759  }
     760
     761  *Ndata = ftable[0].header[0].Naxis[1];
     762  data = (Average_PS1_V4alt *) ftable[0].buffer;
     763  if ((swapped == NULL) || (*swapped == FALSE)) {
     764    if (!gfits_convert_Average_PS1_V4alt (data, sizeof (Average_PS1_V4alt), *Ndata)) {
     765      return NULL;
     766    }
     767    gfits_table_scale_data (ftable);
     768    if (swapped != NULL) *swapped = TRUE;
     769  }
     770  return (data);
     771}
     772
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_photcode_ops.c

    r34844 r36680  
    169169}
    170170
     171// returns Nsec if code is PRI/SEC, else -1
    171172int GetPhotcodeNsec (int code) {
    172173 
     
    259260}
    260261
    261 float PhotAper (Measure *measure) {
    262 
    263   int Np;
    264   float Mcat;
    265   PhotCode *code;
    266 
    267   Np = photcodes[0].hashcode[measure[0].photcode];
    268   if (Np == -1) return (NAN);
    269 
    270   if (photcodes[0].code[Np].type == PHOT_REF) {
    271     Mcat = measure[0].Map;
    272     return (Mcat);
    273   }
    274   code = &photcodes[0].code[Np];
    275   Mcat = measure[0].Map - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    276  
    277   return (Mcat);
    278 }
    279 
    280 float PhotAperInst (Measure *measure) {
    281 
    282   int Np;
    283   float Minst;
    284 
    285   Np = photcodes[0].hashcode[measure[0].photcode];
    286   if (Np == -1) return (NAN);
    287 
    288   if (photcodes[0].code[Np].type == PHOT_REF) {
    289     Minst = measure[0].Map;
    290     return (Minst);
    291   }
    292   Minst = measure[0].Map - measure[0].dt - ZERO_POINT;
    293  
    294   return (Minst);
    295 }
    296 
    297 float PhotKron (Measure *measure) {
    298 
    299   int Np;
    300   float Mcat;
    301   PhotCode *code;
    302 
    303   Np = photcodes[0].hashcode[measure[0].photcode];
    304   if (Np == -1) return (NAN);
    305 
    306   if (photcodes[0].code[Np].type == PHOT_REF) {
    307     Mcat = measure[0].Mkron;
    308     return (Mcat);
    309   }
    310   code = &photcodes[0].code[Np];
    311   Mcat = measure[0].Mkron - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    312  
    313   return (Mcat);
    314 }
    315 
    316 float PhotKronInst (Measure *measure) {
    317 
    318   int Np;
    319   float Minst;
    320 
    321   Np = photcodes[0].hashcode[measure[0].photcode];
    322   if (Np == -1) return (NAN);
    323 
    324   if (photcodes[0].code[Np].type == PHOT_REF) {
    325     Minst = measure[0].Mkron;
    326     return (Minst);
    327   }
    328   Minst = measure[0].Mkron - measure[0].dt - ZERO_POINT;
    329  
    330   return (Minst);
    331 }
    332 
    333262float PhotSys (Measure *measure, Average *average, SecFilt *secfilt) {
    334263
     
    362291}
    363292
    364 float PhotZeroPoint (Measure *measure, Average *average, SecFilt *secfilt) {
    365 
    366   int Np;
    367   float ZP;
    368   PhotCode *code;
    369 
    370   Np = photcodes[0].hashcode[measure[0].photcode];
    371   if (Np == -1) return (NAN);
    372 
    373   if (photcodes[0].code[Np].type == PHOT_REF) {
    374     ZP = 0.0;
    375     return (ZP);
    376   }
    377   code = &photcodes[0].code[Np];
    378   ZP = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
    379 
    380   return (ZP);
    381 }
    382 
    383293float PhotRel (Measure *measure, Average *average, SecFilt *secfilt) {
    384294
     
    444354  Mcal += Mcol;
    445355  return (Mcal);
     356}
     357
     358/***/
     359float PhotAve (PhotCode *code, Average *average, SecFilt *secfilt) {
     360
     361  int Ns;
     362  float Mave;
     363
     364  if (code == NULL) return NAN;
     365
     366  Ns = photcodes[0].hashNsec[code[0].code];
     367  Mave = (Ns == -1) ? NAN : secfilt[Ns].M;
     368  return (Mave);
     369}
     370
     371/* return calibrated magnitude from average/secfilt for given photcode */
     372float PhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure) {
     373
     374  int i, Ns;
     375  float Mave, Mref, Mcol, mc;
     376  double Mc;
     377
     378  if (code == NULL) return NAN;
     379
     380  Ns = photcodes[0].hashNsec[code[0].code];
     381  Mave = (Ns == -1) ? NAN : secfilt[Ns].M;
     382  Mref = Mave + SCALE*code[0].C;
     383
     384  mc = PhotColorForCode (average, secfilt, measure, code);
     385  if (isnan(mc)) return (Mref);
     386  mc = mc - SCALE*code[0].dX;
     387
     388  Mc = mc;
     389  Mcol = 0;
     390  for (i = 0; i < code[0].Nc; i++) {
     391    Mcol += code[0].X[i]*Mc;
     392    Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
     393  }
     394  Mref += Mcol;
     395  return (Mref);
     396}
     397
     398float PhotAveErr (PhotCode *code, Average *average, SecFilt *secfilt) {
     399
     400  int Ns;
     401  float dM;
     402
     403  if (code == NULL) return NAN;
     404
     405  Ns = photcodes[0].hashNsec[code[0].code];
     406  dM  = (Ns == -1) ? NAN : secfilt[Ns].dM;
     407  return (dM);
     408}
     409
     410/************************************** APERTURE-related Magnitudes ***********************************************/
     411
     412float PhotAperInst (Measure *measure) {
     413
     414  int Np;
     415  float Minst;
     416
     417  Np = photcodes[0].hashcode[measure[0].photcode];
     418  if (Np == -1) return (NAN);
     419
     420  if (photcodes[0].code[Np].type == PHOT_REF) {
     421    Minst = measure[0].Map;
     422    return (Minst);
     423  }
     424  Minst = measure[0].Map - measure[0].dt - ZERO_POINT;
     425 
     426  return (Minst);
     427}
     428
     429float PhotAperCat (Measure *measure) {
     430
     431  int Np;
     432  float Mcat;
     433  PhotCode *code;
     434
     435  Np = photcodes[0].hashcode[measure[0].photcode];
     436  if (Np == -1) return (NAN);
     437
     438  if (photcodes[0].code[Np].type == PHOT_REF) {
     439    Mcat = measure[0].Map;
     440    return (Mcat);
     441  }
     442  code = &photcodes[0].code[Np];
     443  Mcat = measure[0].Map - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     444 
     445  return (Mcat);
     446}
     447
     448float PhotAperSys (Measure *measure, Average *average, SecFilt *secfilt) {
     449
     450  int i, Np;
     451  float Mcat, Mcol, Msys, mc, Mc;
     452  PhotCode *code;
     453
     454  Np = photcodes[0].hashcode[measure[0].photcode];
     455  if (Np == -1) return (NAN);
     456
     457  if (photcodes[0].code[Np].type == PHOT_REF) {
     458    Mcat = measure[0].Map;
     459    return (Mcat);
     460  }
     461  code = &photcodes[0].code[Np];
     462  Mcat = measure[0].Map - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     463 
     464  /* for DEP, color must be made of PRI/SEC */
     465  mc = PhotColorForCode (average, secfilt, NULL, code);
     466  if (isnan(mc)) return (Mcat);
     467  mc = mc - SCALE*code[0].dX;
     468
     469  Mc = mc;
     470  Mcol = 0;
     471  for (i = 0; i < code[0].Nc; i++) {
     472    Mcol += code[0].X[i]*Mc;
     473    Mc *= mc;
     474  }
     475  Msys = Mcat + Mcol;
     476  return (Msys);
     477}
     478
     479float PhotAperRel (Measure *measure, Average *average, SecFilt *secfilt) {
     480
     481  int i, Np;
     482  float Mcat, Mcol, Mrel, mc, Mc;
     483  PhotCode *code;
     484
     485  Np = photcodes[0].hashcode[measure[0].photcode];
     486  if (Np == -1) return (NAN);
     487
     488  if (photcodes[0].code[Np].type == PHOT_REF) {
     489    Mcat = measure[0].Map;
     490    return (Mcat);
     491  }
     492  code = &photcodes[0].code[Np];
     493  Mrel = measure[0].Map - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
     494
     495  /* for DEP, color must be made of PRI/SEC */
     496  mc = PhotColorForCode (average, secfilt, NULL, code);
     497  if (isnan(mc)) return (Mrel);
     498  mc = mc - SCALE*code[0].dX;
     499
     500  Mc = mc;
     501  Mcol = 0;
     502  for (i = 0; i < code[0].Nc; i++) {
     503    Mcol += code[0].X[i]*Mc;
     504    Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
     505  }
     506  Mrel += Mcol;
     507  return (Mrel);
     508}
     509
     510/* return calibrated magnitude from measure for given photcode */
     511float PhotAperCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code) {
     512
     513  int i, Np;
     514  float Mcal, Mrel, Mcol, mc, Mc;
     515
     516  if (code == NULL) return NAN;
     517
     518  /* code must be the matching PRI/SEC code for this measurement or an equivalent ALT */
     519  Np = photcodes[0].hashcode[thisone[0].photcode];
     520  if (Np == -1) return (NAN);
     521
     522  if (photcodes[0].code[Np].type == PHOT_REF) {
     523    Mrel = thisone[0].Map;
     524    return (Mrel);
     525  }
     526  if (code[0].code != photcodes[0].code[Np].equiv) return (NAN);
     527
     528  Mcal = PhotAperRel (thisone, average, secfilt) + SCALE*code[0].C;
     529
     530  mc = PhotColorForCode (average, secfilt, measure, code);
     531  if (isnan(mc)) return (Mcal);
     532  mc = mc - SCALE*code[0].dX;
     533
     534  Mc = mc;
     535  Mcol = 0;
     536  for (i = 0; i < code[0].Nc; i++) {
     537    Mcol += code[0].X[i]*Mc;
     538    Mc *= mc;
     539  }
     540  Mcal += Mcol;
     541  return (Mcal);
     542}
     543
     544float PhotAperAve (PhotCode *code, Average *average, SecFilt *secfilt) {
     545
     546  int Ns;
     547  float Maper;
     548
     549  if (code == NULL) return NAN;
     550
     551  Ns = photcodes[0].hashNsec[code[0].code];
     552  Maper = (Ns == -1) ? NAN : secfilt[Ns].Map;
     553  return (Maper);
     554}
     555
     556/* return calibrated magnitude from average/secfilt for given photcode */
     557float PhotAperRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure) {
     558
     559  int i, Ns;
     560  float Mave, Mref, Mcol, mc;
     561  double Mc;
     562
     563  if (code == NULL) return NAN;
     564
     565  Ns = photcodes[0].hashNsec[code[0].code];
     566  Mave = (Ns == -1) ? NAN : secfilt[Ns].Map;
     567  Mref = Mave + SCALE*code[0].C;
     568
     569  mc = PhotColorForCode (average, secfilt, measure, code);
     570  if (isnan(mc)) return (Mref);
     571  mc = mc - SCALE*code[0].dX;
     572
     573  Mc = mc;
     574  Mcol = 0;
     575  for (i = 0; i < code[0].Nc; i++) {
     576    Mcol += code[0].X[i]*Mc;
     577    Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
     578  }
     579  Mref += Mcol;
     580  return (Mref);
     581}
     582
     583/************************************** KRON-related Magnitudes ***********************************************/
     584
     585float PhotKronInst (Measure *measure) {
     586
     587  int Np;
     588  float Minst;
     589
     590  Np = photcodes[0].hashcode[measure[0].photcode];
     591  if (Np == -1) return (NAN);
     592
     593  if (photcodes[0].code[Np].type == PHOT_REF) {
     594    Minst = measure[0].Mkron;
     595    return (Minst);
     596  }
     597  Minst = measure[0].Mkron - measure[0].dt - ZERO_POINT;
     598 
     599  return (Minst);
     600}
     601
     602float PhotKronCat (Measure *measure) {
     603
     604  int Np;
     605  float Mcat;
     606  PhotCode *code;
     607
     608  Np = photcodes[0].hashcode[measure[0].photcode];
     609  if (Np == -1) return (NAN);
     610
     611  if (photcodes[0].code[Np].type == PHOT_REF) {
     612    Mcat = measure[0].Mkron;
     613    return (Mcat);
     614  }
     615  code = &photcodes[0].code[Np];
     616  Mcat = measure[0].Mkron - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     617 
     618  return (Mcat);
     619}
     620
     621float PhotKronSys (Measure *measure, Average *average, SecFilt *secfilt) {
     622
     623  int i, Np;
     624  float Mcat, Mcol, Msys, mc, Mc;
     625  PhotCode *code;
     626
     627  Np = photcodes[0].hashcode[measure[0].photcode];
     628  if (Np == -1) return (NAN);
     629
     630  if (photcodes[0].code[Np].type == PHOT_REF) {
     631    Msys = measure[0].Mkron;
     632    return (Msys);
     633  }
     634  code = &photcodes[0].code[Np];
     635  Mcat = measure[0].Mkron - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     636
     637  /* for DEP, color must be made of PRI/SEC */
     638  mc = PhotColorForCode (average, secfilt, NULL, code);
     639  if (isnan(mc)) return (Mcat);
     640  mc = mc - SCALE*code[0].dX;
     641
     642  Mc = mc;
     643  Mcol = 0;
     644  for (i = 0; i < code[0].Nc; i++) {
     645    Mcol += code[0].X[i]*Mc;
     646    Mc *= mc;
     647  }
     648  Msys = Mcat + Mcol;
     649  return (Msys);
     650}
     651
     652float PhotKronRel (Measure *measure, Average *average, SecFilt *secfilt) {
     653
     654  int i, Np;
     655  float Mcat, Mcol, Mrel, mc, Mc;
     656  PhotCode *code;
     657
     658  Np = photcodes[0].hashcode[measure[0].photcode];
     659  if (Np == -1) return (NAN);
     660
     661  if (photcodes[0].code[Np].type == PHOT_REF) {
     662    Mcat = measure[0].Mkron;
     663    return (Mcat);
     664  }
     665  code = &photcodes[0].code[Np];
     666  Mrel = measure[0].Mkron - ZERO_POINT + code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C - measure[0].Mcal;
     667
     668  /* for DEP, color must be made of PRI/SEC */
     669  mc = PhotColorForCode (average, secfilt, NULL, code);
     670  if (isnan(mc)) return (Mrel);
     671  mc = mc - SCALE*code[0].dX;
     672
     673  Mc = mc;
     674  Mcol = 0;
     675  for (i = 0; i < code[0].Nc; i++) {
     676    Mcol += code[0].X[i]*Mc;
     677    Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
     678  }
     679  Mrel += Mcol;
     680  return (Mrel);
     681}
     682
     683/* return calibrated magnitude from measure for given photcode */
     684float PhotKronCal (Measure *thisone, Average *average, SecFilt *secfilt, Measure *measure, PhotCode *code) {
     685
     686  int i, Np;
     687  float Mcal, Mrel, Mcol, mc, Mc;
     688
     689  if (code == NULL) return NAN;
     690
     691  /* code must be the matching PRI/SEC code for this measurement or an equivalent ALT */
     692  Np = photcodes[0].hashcode[thisone[0].photcode];
     693  if (Np == -1) return (NAN);
     694
     695  if (photcodes[0].code[Np].type == PHOT_REF) {
     696    Mrel = thisone[0].Mkron;
     697    return (Mrel);
     698  }
     699  if (code[0].code != photcodes[0].code[Np].equiv) return (NAN);
     700
     701  Mcal = PhotKronRel (thisone, average, secfilt) + SCALE*code[0].C;
     702
     703  mc = PhotColorForCode (average, secfilt, measure, code);
     704  if (isnan(mc)) return (Mcal);
     705  mc = mc - SCALE*code[0].dX;
     706
     707  Mc = mc;
     708  Mcol = 0;
     709  for (i = 0; i < code[0].Nc; i++) {
     710    Mcol += code[0].X[i]*Mc;
     711    Mc *= mc;
     712  }
     713  Mcal += Mcol;
     714  return (Mcal);
     715}
     716
     717float PhotKronAve (PhotCode *code, Average *average, SecFilt *secfilt) {
     718
     719  int Ns;
     720  float Mkron;
     721
     722  if (code == NULL) return NAN;
     723
     724  Ns = photcodes[0].hashNsec[code[0].code];
     725  Mkron = (Ns == -1) ? NAN : secfilt[Ns].Mkron;
     726  return (Mkron);
     727}
     728
     729/* return calibrated magnitude from average/secfilt for given photcode */
     730float PhotKronRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure) {
     731
     732  int i, Ns;
     733  float Mave, Mref, Mcol, mc;
     734  double Mc;
     735
     736  if (code == NULL) return NAN;
     737
     738  Ns = photcodes[0].hashNsec[code[0].code];
     739  Mave = (Ns == -1) ? NAN : secfilt[Ns].Mkron;
     740  Mref = Mave + SCALE*code[0].C;
     741
     742  mc = PhotColorForCode (average, secfilt, measure, code);
     743  if (isnan(mc)) return (Mref);
     744  mc = mc - SCALE*code[0].dX;
     745
     746  Mc = mc;
     747  Mcol = 0;
     748  for (i = 0; i < code[0].Nc; i++) {
     749    Mcol += code[0].X[i]*Mc;
     750    Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
     751  }
     752  Mref += Mcol;
     753  return (Mref);
     754}
     755
     756float PhotKronAveErr (PhotCode *code, Average *average, SecFilt *secfilt) {
     757
     758  int Ns;
     759  float dMkron;
     760
     761  if (code == NULL) return NAN;
     762
     763  Ns = photcodes[0].hashNsec[code[0].code];
     764  dMkron = (Ns == -1) ? NAN : secfilt[Ns].dMkron;
     765  return (dMkron);
     766}
     767
     768/********************* other support functions ********************************/
     769
     770float PhotZeroPoint (Measure *measure, Average *average, SecFilt *secfilt) {
     771
     772  int Np;
     773  float ZP;
     774  PhotCode *code;
     775
     776  Np = photcodes[0].hashcode[measure[0].photcode];
     777  if (Np == -1) return (NAN);
     778
     779  if (photcodes[0].code[Np].type == PHOT_REF) {
     780    ZP = 0.0;
     781    return (ZP);
     782  }
     783  code = &photcodes[0].code[Np];
     784  ZP = code[0].K*(measure[0].airmass - 1.000) + SCALE*code[0].C;
     785
     786  return (ZP);
    446787}
    447788
     
    496837}
    497838
    498 /* return calibrated magnitude from average/secfilt for given photcode */
    499 float PhotRef (PhotCode *code, Average *average, SecFilt *secfilt, Measure *measure) {
    500 
    501   int i, Ns;
    502   float Mave, Mref, Mcol, mc;
    503   double Mc;
    504 
    505   if (code == NULL) return NAN;
    506 
    507   Ns = photcodes[0].hashNsec[code[0].code];
    508   Mave = (Ns == -1) ? NAN : secfilt[Ns].M;
    509   Mref = Mave + SCALE*code[0].C;
    510 
    511   mc = PhotColorForCode (average, secfilt, measure, code);
    512   if (isnan(mc)) return (Mref);
    513   mc = mc - SCALE*code[0].dX;
    514 
    515   Mc = mc;
    516   Mcol = 0;
    517   for (i = 0; i < code[0].Nc; i++) {
    518     Mcol += code[0].X[i]*Mc;
    519     Mc *= mc;    /* the 0.001 is needed for higher order terms to keep the units mag = mag^n */
    520   }
    521   Mref += Mcol;
    522   return (Mref);
    523 }
    524 
    525 /***/
    526 float PhotAve (PhotCode *code, Average *average, SecFilt *secfilt) {
    527 
    528   int Ns;
    529   float Mave;
    530 
    531   if (code == NULL) return NAN;
    532 
    533   Ns = photcodes[0].hashNsec[code[0].code];
    534   Mave = (Ns == -1) ? NAN : secfilt[Ns].M;
    535   return (Mave);
    536 }
    537 
    538 float PhotdM (PhotCode *code, Average *average, SecFilt *secfilt) {
    539 
    540   int Ns;
    541   float dM;
    542 
    543   if (code == NULL) return NAN;
    544 
    545   Ns = photcodes[0].hashNsec[code[0].code];
    546   dM  = (Ns == -1) ? NAN : secfilt[Ns].dM;
    547   return (dM);
    548 }
    549 
    550839float PhotMstdev (PhotCode *code, Average *average, SecFilt *secfilt) {
    551840
     
    558847  Mstdev  = (Ns == -1) ? NAN : 0.001*secfilt[Ns].Mstdev;
    559848  return (Mstdev);
    560 }
    561 
    562 float PhotKronAve (PhotCode *code, Average *average, SecFilt *secfilt) {
    563 
    564   int Ns;
    565   float Mkron;
    566 
    567   if (code == NULL) return NAN;
    568 
    569   Ns = photcodes[0].hashNsec[code[0].code];
    570   Mkron = (Ns == -1) ? NAN : secfilt[Ns].Mkron;
    571   return (Mkron);
    572 }
    573 
    574 float PhotKronAveErr (PhotCode *code, Average *average, SecFilt *secfilt) {
    575 
    576   int Ns;
    577   float dMkron;
    578 
    579   if (code == NULL) return NAN;
    580 
    581   Ns = photcodes[0].hashNsec[code[0].code];
    582   dMkron = (Ns == -1) ? NAN : secfilt[Ns].dMkron;
    583   return (dMkron);
    584849}
    585850
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvo_tiny_values.c

    r35102 r36680  
    88  averageT[0].measureOffset = average[0].measureOffset;
    99  averageT[0].catID         = average[0].catID;
     10  averageT[0].objID         = average[0].objID;
     11  averageT[0].nOwn          = -1;
    1012  return;
    1113}
     
    3335  measureT[0].dYccd      = measure[0].dYccd;
    3436  measureT[0].dRsys      = measure[0].dRsys;
     37  measureT[0].myDet      = 0;
    3538  return ;
    3639}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libdvo/src/dvosorts.c

    r35263 r36680  
    6060
    6161/* sort a coordinate pair (X,Y) and the associated index (S) */
     62void sort_IDs_indexonly (opihi_int *X, off_t *S, off_t N) {
     63 
     64# define SWAPFUNC(A,B){ off_t itmp; \
     65  itmp = S[A]; S[A] = S[B]; S[B] = itmp; \
     66}
     67# define COMPARE(A,B)(X[S[A]] < X[S[B]])
     68
     69  OHANA_SORT (N, COMPARE, SWAPFUNC);
     70
     71# undef SWAPFUNC
     72# undef COMPARE
     73
     74}
     75
     76/* sort a coordinate pair (X,Y) and the associated index (S) */
    6277void sort_coords_indexonly (double *X, double *Y, off_t *S, off_t N) {
    6378 
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libfits/table/F_get_column.c

    r35101 r36680  
    174174int gfits_get_bintable_column (Header *header, FTable *table, char *label, void **data) {
    175175
    176   off_t Nx, Ny;
    177   int i, N, Nfields, Nval, Nbytes, Nstart, Nv, Nb;
    178   char tlabel[80], field[80], format[80], type[16], tmpline[16];
    179   char *Pin, *Pout, *array;
    180   double Bscale, Bzero;
    181 
    182   if (label == (char *) NULL) return (FALSE);
    183   if (label[0] == 0) return (FALSE);
    184 
    185   /* find label in header */
    186   tlabel[0] = 0;
    187   gfits_scan (header, "TFIELDS", "%d", 1, &Nfields);
    188   for (i = 1; strcasecmp (label, tlabel) && (i < Nfields + 1); i++) {
    189     sprintf (field, "TTYPE%d", i);
    190     gfits_scan (header, field, "%s", 1, tlabel);
    191   }
    192   if (strcasecmp (label, tlabel)) return (FALSE);
    193   N = i - 1;
    194 
    195   Bscale = 1;
    196   Bzero  = 0;
    197 
    198   /* interpret format */
    199   sprintf (field, "TSCAL%d", N);
    200   gfits_scan (header, field, "%lf", 1, &Bscale);
    201   sprintf (field, "TZERO%d", N);
    202   gfits_scan (header, field, "%lf", 1, &Bzero);
    203   sprintf (field, "TFORM%d", N);
    204   gfits_scan (header, field, "%s", 1, format);
    205 
    206   if (!gfits_bintable_format (format, type, &Nval, &Nbytes)) return (FALSE);
    207  
    208   /* check existing table dimensions */
    209   gfits_scan (header, "NAXIS1",  OFF_T_FMT, 1,  &Nx);
    210   gfits_scan (header, "NAXIS2",  OFF_T_FMT, 1,  &Ny);
    211 
    212   /* scan columns to find insert point */
    213   Nstart = 0;
    214   for (i = 1; i < N; i++) {
    215     sprintf (field, "TFORM%d", i);
    216     gfits_scan (header, field, "%s", 1, format);
    217     gfits_bintable_format (format, tmpline, &Nv, &Nb);
    218     Nstart += Nv*Nb;
    219   }
    220 
    221   /* extract bytes from table into temporary array */
    222   ALLOCATE (array, char, Nbytes*Nval*Ny);
    223   Pin  = table[0].buffer + Nstart;
    224   Pout = array;
    225   for (i = 0; i < Ny; i++, Pin += Nx, Pout += Nval*Nbytes) {
    226     memcpy (Pout, Pin, Nval*Nbytes);
    227   }
    228 
    229   /* convert data in-situ with correct type, byte swap and Bzero/Bscale */
    230   Pin  = array;
    231   Pout = array;
    232   if (!strcmp (type, "char")) {
    233     for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    234       *(char *)Pout = *(char *)Pin*Bscale + Bzero;
    235     }
    236   }
    237   if (!strcmp (type, "short")) {
    238     for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    239 # ifdef BYTE_SWAP
    240       SWAP_BYTE;
    241 # endif
    242       *(short *)Pout = *(short *)Pin*Bscale + Bzero;
    243     } 
    244   }
    245   if (!strcmp (type, "int")) {
    246     for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    247 # ifdef BYTE_SWAP
    248       SWAP_WORD;
    249 # endif
    250       *(int *)Pout = *(int *)Pin*Bscale + Bzero;
    251     }
    252   }
    253   if (!strcmp (type, "int64_t")) {
    254     // XXX 64 bit int operations with Bzero & Bscale are inaccurate even with doubles
    255     if ((Bzero == 0.0) && (Bscale == 1.0)) {
    256       for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    257 # ifdef BYTE_SWAP
    258         SWAP_DBLE;
    259 # endif
    260         *(int64_t *)Pout = *(int64_t *)Pin;
    261       }
    262     } else {
    263       for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    264 # ifdef BYTE_SWAP
    265         SWAP_DBLE;
    266 # endif
    267         *(int64_t *)Pout = *(int64_t *)Pin*Bscale + Bzero;
    268       }
    269     }
    270   }
    271   if (!strcmp (type, "float")) {
    272     for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    273 # ifdef BYTE_SWAP
    274       SWAP_WORD;
    275 # endif
    276       *(float *)Pout = *(float *)Pin*Bscale + Bzero;
    277     }
    278   }
    279   if (!strcmp (type, "double")) {
    280     for (i = 0; i < Nval*Ny; i++, Pin+=Nbytes, Pout+=Nbytes) {
    281 # ifdef BYTE_SWAP
    282       SWAP_DBLE;
    283 # endif
    284       *(double *)Pout = *(double *)Pin*Bscale + Bzero;
    285     }
    286   }
     176  char type[16];
     177  off_t Nrow;
     178  int Ncol;
     179
     180  char *array = gfits_get_bintable_column_data (header, table, label, type, &Nrow, &Ncol);
     181  if (array == NULL) return (FALSE);
    287182
    288183  *data = array;
    289   return (TRUE);
     184  return TRUE;
    290185}
    291186
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libkapa/src/IOfuncs.c

    r35761 r36680  
    5454  va_end (argp);
    5555
    56   if (!Nbyte) return (FALSE);
     56  if (!Nbyte) {
     57    KiiSendCommand (device, 16, "LEN: %11d", 0);
     58    return (FALSE);
     59  }
    5760
    5861  /* the message may contain up to 99,999,999,999 bytes (100MB) */
     
    8487  /* find the message length, allocate space */
    8588  sscanf (buffer, "%*s %d", &Nbytes);
     89  if (Nbytes == 0) {
     90    return TRUE;
     91  }
     92
    8693  ALLOCATE (message, char, Nbytes + 1);
    8794  memset (message, 0, Nbytes + 1);
     95
    8896
    8997  /* read Nbytes from the device */
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libkapa/src/KapaWindow.c

    r35761 r36680  
    100100  graphdata[0].coords.pc1_1 = graphdata[0].coords.pc2_2 = 1.0;
    101101  graphdata[0].coords.pc1_2 = graphdata[0].coords.pc2_1 = 0.0;
    102   strcpy (graphdata[0].coords.ctype, "RA---LIN");
     102  strcpy (graphdata[0].coords.ctype, "DEC--LIN");
    103103  graphdata[0].coords.crval1 = 0.0;
    104104  graphdata[0].coords.crval2 = 0.0;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libkapa/src/bDrawFuncs.c

    r33956 r36680  
    247247  int i;
    248248
     249  if (Y <  0) return;
     250  if (Y >= buffer[0].Ny) return;
     251
    249252  for (i = X1; i < X2; i++) {
     253    if (i <  0) continue;
     254    if (i >= buffer[0].Nx) continue;
    250255    if (buffer[0].Nbyte == 1) {
    251256      buffer[0].pixels[Y][i] = buffer->bColor;
     
    263268  int i;
    264269
     270  if (X <  0) return;
     271  if (X >= buffer[0].Nx) return;
     272
    265273  for (i = Y1; i < Y2; i++) {
     274    if (i <  0) continue;
     275    if (i >= buffer[0].Ny) continue;
    266276    if (buffer[0].Nbyte == 1) {
    267277      buffer[0].pixels[i][X] = buffer->bColor;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libohana/src

  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/libohana/src/gaussj.c

    r24080 r36680  
    11# include <ohana.h>
    22# define GROWTHTEST 0
    3 # define MAX_RANGE 1.0e7
     3# define MAX_RANGE 1.0e9
    44
    55// Gauss-Jordan elimination using full pivots based on Press et al's description.  Substantially
     
    9191    /* rescale by pivot reciprocal */
    9292    double tmpval = 1.0 / A[maxcol][maxcol];
     93    // XXX why is this here (don't I double count this element?) A[maxcol][maxcol] = 1.0;
    9394    A[maxcol][maxcol] = 1.0;
    9495    for (col = 0; col < N; col++) A[maxcol][col] *= tmpval;
     
    117118    }
    118119  }
     120
     121# if (GROWTHTEST)
     122    fprintf (stderr, "final A matrix:\n");
     123    for (row = 0; row < N; row++) {
     124        for (col = 0; col < N; col++) {
     125            fprintf (stderr, "%10.3e ", A[row][col]);
     126        }
     127        fprintf (stderr, "\n");
     128    }
     129    fprintf (stderr, "\n");
     130# endif
    119131
    120132  // swap back the inverse matrix based on the row swaps above
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/markrock/src/gcatstats.c

    r27435 r36680  
    4040  catstats[0].coords.pc1_1 = catstats[0].coords.pc2_2 = 1.0;
    4141  catstats[0].coords.pc1_2 = catstats[0].coords.pc2_1 = 0.0;
    42   strcpy (catstats[0].coords.ctype, "RA---TAN");
     42  strcpy (catstats[0].coords.ctype, "DEC--TAN");
    4343
    4444  X1 = catstats[0].X;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/markstar/src/gcatstats.c

    r27435 r36680  
    5050  catstats[0].coords.pc1_1 = catstats[0].coords.pc2_2 = 1.0;
    5151  catstats[0].coords.pc1_2 = catstats[0].coords.pc2_1 = 0.0;
    52   strcpy (catstats[0].coords.ctype, "RA---TAN");
     52  strcpy (catstats[0].coords.ctype, "DEC--TAN");
    5353
    5454  X1 = catstats[0].X;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/mosastro/src/warptest.c

    r3323 r36680  
    1515
    1616  /* bore site center guess */
    17   sprintf (coords.ctype, "RA---%s", argv[1]);
     17  sprintf (coords.ctype, "DEC--%s", argv[1]);
    1818  coords.crval1 = 0.0;
    1919  coords.crval2 = 0.0;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.astro

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.astro/Makefile

    r35416 r36680  
    2828$(SRC)/cval.$(ARCH).o              \
    2929$(SRC)/czplot.$(ARCH).o    \
     30$(SRC)/cdensify.$(ARCH).o          \
    3031$(SRC)/drizzle.$(ARCH).o           \
    3132$(SRC)/flux.$(ARCH).o              \
    3233$(SRC)/fitplx.$(ARCH).o    \
     34$(SRC)/fitpm.$(ARCH).o     \
    3335$(SRC)/fixwrap.$(ARCH).o           \
    3436$(SRC)/fixcols.$(ARCH).o           \
     
    6062$(SRC)/scale.$(ARCH).o             \
    6163$(SRC)/sexigesimal.$(ARCH).o       \
     64$(SRC)/sersic.$(ARCH).o    \
    6265$(SRC)/spec.$(ARCH).o              \
    6366$(SRC)/specpairfit.$(ARCH).o       \
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.astro/fitplx.c

    r35416 r36680  
    4141    remove_argument (N, &argc, argv);
    4242    VERBOSE = TRUE;
     43  }
     44  if ((N = get_argument (argc, argv, "-vv"))) {
     45    remove_argument (N, &argc, argv);
     46    VERBOSE = 2;
    4347  }
    4448
     
    108112  coords.pc1_2  = coords.pc2_1 = 0.0;
    109113  coords.Npolyterms = 1;
    110   strcpy (coords.ctype, "RA---SIN");
     114  strcpy (coords.ctype, "DEC--SIN");
    111115
    112116  double *X, *Y, *t, *pX, *pY, *dX, *dY;
     
    145149
    146150  PlxFit fit;
    147   FitPMandPar (&fit, X, dX, Y, dY, t, pX, pY, n, VERBOSE);
     151  if (!FitPMandPar (&fit, X, dX, Y, dY, t, pX, pY, n, VERBOSE)) {
     152    return FALSE;
     153  }
    148154
    149155  // fprintf (stderr, "Roff, Doff: %f, %f; dRo, dDo: %f, %f\n", fit.Ro, fit.Do, fit.dRo, fit.dDo);
     
    204210  for (i = 0; i < Npts; i++) {
    205211
    206     if (VERBOSE) fprintf (stderr, "%f %f : %f %f : %f : %f %f\n", X[i], dX[i], Y[i], dY[i], T[i], pR[i], pD[i]);
     212    if (VERBOSE == 2) fprintf (stderr, "%f %f : %f %f : %f : %f %f\n", X[i], dX[i], Y[i], dY[i], T[i], pR[i], pD[i]);
    207213
    208214    /* handle case where dX or dY = 0.0 */
    209     wx = 1.0 / SQ(dX[i]);
    210     wy = 1.0 / SQ(dY[i]);
     215    wx = (fabs(dX[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dX[i]);
     216    wy = (fabs(dY[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dY[i]);
    211217
    212218    Wx += wx;
     
    266272  B[4][0] = PRX + PDY;
    267273
    268   dgaussjordan ((double **)A, (double **)B, 5, 1);
     274  if (!dgaussjordan ((double **)A, (double **)B, 5, 1)) {
     275    if (VERBOSE) fprintf (stderr, "error in fit\n");
     276    if (VERBOSE == 2) {
     277      int j;
     278      for (i = 0; i < 5; i++) {
     279        for (j = 0; j < 5; j++) {
     280          fprintf (stderr, "%e ", A[i][j]);
     281        }
     282        fprintf (stderr, " : %e\n", A[i][0]);
     283      }
     284    }
     285    return FALSE;
     286  }
    269287
    270288  fit[0].Ro = B[0][0];
     
    285303    Xf = fit[0].Ro + fit[0].uR*T[i] + fit[0].p*pR[i];
    286304    Yf = fit[0].Do + fit[0].uD*T[i] + fit[0].p*pD[i];
    287     chisq += SQ(X[i] - Xf) / SQ(dX[i]);
    288     chisq += SQ(Y[i] - Yf) / SQ(dY[i]);
    289     if (VERBOSE) fprintf (stderr, "chisq contrib : %f %f : %f %f : %f %f : %f %f : %f\n", Xf, Yf, X[i] - Xf, Y[i] - Yf, dX[i], dY[i], (X[i] - Xf) / dX[i], (Y[i] - Yf) / dY[i], chisq);
     305    wx = (fabs(dX[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dX[i]);
     306    wy = (fabs(dY[i]) < 0.0001) ? 1.0 : 1.0 / SQ(dY[i]);
     307    chisq += SQ(X[i] - Xf) * wx;
     308    chisq += SQ(Y[i] - Yf) * wy;
     309    // if (VERBOSE) fprintf (stderr, "chisq contrib : %f %f : %f %f : %f %f : %f %f : %f\n", Xf, Yf, X[i] - Xf, Y[i] - Yf, dX[i], dY[i], (X[i] - Xf) / dX[i], (Y[i] - Yf) / dY[i], chisq);
    290310  }
    291311  fit[0].Nfit = Npts;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.astro/gauss.c

    r34088 r36680  
    1010  Buffer *buf;
    1111  KapaImageData data;
     12  int VERBOSE;
     13
     14  VERBOSE = TRUE;
     15  if ((N = get_argument (argc, argv, "-q"))) {
     16    VERBOSE = FALSE;
     17    remove_argument (N, &argc, argv);
     18  }
     19  if ((N = get_argument (argc, argv, "-quiet"))) {
     20    VERBOSE = FALSE;
     21    remove_argument (N, &argc, argv);
     22  }
    1223
    1324  name = NULL;
     
    5869    KiiCursorRead (kapa, &X, &Y, &ZP, &RA, &DEC, key);
    5970    if (!strcasecmp (key, "Q")) break;
    60     get_aperture_stats (&buf[0].matrix, (int)(X+0.5), (int)(Y+0.5), Npix, Nborder, max);
     71    get_aperture_stats (&buf[0].matrix, (int)(X+0.5), (int)(Y+0.5), Npix, Nborder, max, VERBOSE);
    6172  }
    6273  KiiCursorOff (kapa);
     
    6475}
    6576
     77
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.astro/init.c

    r35757 r36680  
    1313int czplot                  PROTO((int, char **));
    1414int czcplot                 PROTO((int, char **));
     15int cdensify                PROTO((int, char **));
    1516int drizzle                 PROTO((int, char **));
    1617int flux                    PROTO((int, char **));
    1718int fitplx                  PROTO((int, char **));
     19int fitpm                   PROTO((int, char **));
    1820int fixwrap                 PROTO((int, char **));
    1921int fiximage                PROTO((int, char **));
     
    4951int scale                   PROTO((int, char **));
    5052int sexigesimal             PROTO((int, char **));
     53int sersic                  PROTO((int, char **));
    5154int spec                    PROTO((int, char **));
    5255int specpairfit             PROTO((int, char **));
     
    7275  {1, "czplot",      czplot,       "plot scaled vectors in sky coordinates"},
    7376  {1, "czcplot",     czcplot,      "plot color-scaled vectors in sky coordinates"},
     77  {1, "cdensify",    cdensify,      "vectors to density history on projection"},
    7478  {1, "drizzle",     drizzle,      "transform image to image"},
    7579  {1, "flux",        flux,         "flux in a convex contour"},
    7680  {1, "fitplx",      fitplx,       "fit proper motion and parallax"},
     81  {1, "fitpm",       fitpm,        "fit proper motion only"},
    7782  {1, "fixwrap",     fixwrap,      "fix megacam over-wrapped pixels"},
    7883  {1, "fiximage",    fiximage,     "fix pixels in an image by interpolation"},
     
    107112  {1, "scale",       scale,        "get / set real bzero / bscale values"},
    108113  {1, "sexigesimal", sexigesimal,  "convert to/from sexigesimal/decimal"},
     114  {1, "sersic",      sersic,       "generate sub-pixel resolved sersic model"},
    109115  {1, "spec",        spec,         "extract a spectrum"},
    110116  {1, "specpairfit", specpairfit,  "fit spectrum to another spectrum"},
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.astro/region.c

    r31160 r36680  
    8080  if (!ohana_str_to_radec (&Ra, &Dec, argv[1], argv[2])) return (FALSE);
    8181  Radius = atof (argv[3]);
    82   strcpy (graphmode.coords.ctype, "RA---TAN");
     82  strcpy (graphmode.coords.ctype, "DEC--TAN");
    8383  if (argc == 5) {
    8484    if (!strcasecmp (argv[4], "TAN"))
    85       strcpy (graphmode.coords.ctype, "RA---TAN");
     85      strcpy (graphmode.coords.ctype, "DEC--TAN");
    8686    if (!strcasecmp (argv[4], "SIN"))
    87       strcpy (graphmode.coords.ctype, "RA---SIN");
     87      strcpy (graphmode.coords.ctype, "DEC--SIN");
    8888    if (!strcasecmp (argv[4], "ARC"))
    89       strcpy (graphmode.coords.ctype, "RA---ARC");
     89      strcpy (graphmode.coords.ctype, "DEC--ARC");
    9090    if (!strcasecmp (argv[4], "STG"))
    91       strcpy (graphmode.coords.ctype, "RA---STG");
     91      strcpy (graphmode.coords.ctype, "DEC--STG");
    9292    if (!strcasecmp (argv[4], "ZEA"))
    93       strcpy (graphmode.coords.ctype, "RA---ZEA");
     93      strcpy (graphmode.coords.ctype, "DEC--ZEA");
    9494    if (!strcasecmp (argv[4], "AIT"))
    95       strcpy (graphmode.coords.ctype, "RA---AIT");
     95      strcpy (graphmode.coords.ctype, "DEC--AIT");
    9696    if (!strcasecmp (argv[4], "GLS"))
    97       strcpy (graphmode.coords.ctype, "RA---GLS");
     97      strcpy (graphmode.coords.ctype, "DEC--GLS");
    9898    if (!strcasecmp (argv[4], "PAR"))
    99       strcpy (graphmode.coords.ctype, "RA---PAR");
     99      strcpy (graphmode.coords.ctype, "DEC--PAR");
    100100  }
    101101
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.astro/star.c

    r34088 r36680  
    66  double max;
    77  Buffer *buf;
     8  int VERBOSE;
     9
     10  VERBOSE = TRUE;
     11  if ((N = get_argument (argc, argv, "-q"))) {
     12    VERBOSE = FALSE;
     13    remove_argument (N, &argc, argv);
     14  }
     15  if ((N = get_argument (argc, argv, "-quiet"))) {
     16    VERBOSE = FALSE;
     17    remove_argument (N, &argc, argv);
     18  }
    819
    920  Nborder = 3;
     
    3647  }
    3748
    38   get_aperture_stats (&buf[0].matrix, x, y, dx, Nborder, max);
     49  get_aperture_stats (&buf[0].matrix, x, y, dx, Nborder, max, VERBOSE);
    3950 
    4051  return (TRUE);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.basic/list.c

    r33662 r36680  
    22# define D_NLINES 100
    33static char prompt[] = ">> ";
     4
     5static int set_list_varname (char *line, char *base, int N, int excelStyle);
    46
    57int list (int argc, char **argv) {
     
    2123  }
    2224
     25  int EXCEL_STYLE = FALSE;
     26  if ((N = get_argument (argc, argv, "-excel-style"))) {
     27    remove_argument (N, &argc, argv);
     28    EXCEL_STYLE = TRUE;
     29  }
     30  if ((N = get_argument (argc, argv, "-excel"))) {
     31    remove_argument (N, &argc, argv);
     32    EXCEL_STYLE = TRUE;
     33  }
     34
    2335  if ((N = get_argument (argc, argv, "-vectors"))) {
    2436    remove_argument (N, &argc, argv);
     
    4961   
    5062    for (i = 0; i < argc - 3; i++) {
    51       sprintf (line, "%s:%d", argv[1], i);
     63      set_list_varname (line, argv[1], i, EXCEL_STYLE);
    5264      set_str_variable (line, argv[i+3]);
    5365    }
     
    8395        if (!word) break;
    8496       
    85         sprintf (line, "%s:%d", argv[1], nWords);
     97        // sprintf (line, "%s:%d", argv[1], nWords);
     98        set_list_varname (line, argv[1], nWords, EXCEL_STYLE);
     99
    86100        set_str_variable (line, word);
    87101        FREE (word);
     
    120134      sprintf (line, "%s:%d", argv[3], i);
    121135      value = get_variable (line);
    122       sprintf (line, "%s:%d", argv[1], i);
     136      // sprintf (line, "%s:%d", argv[1], i);
     137      set_list_varname (line, argv[1], i, EXCEL_STYLE);
    123138      set_str_variable (line, value);
    124139    }
     
    136151    N = get_int_variable (line, &found);
    137152    for (i = 0; i < argc - 3; i++) {
    138       sprintf (line, "%s:%d", argv[1], N + i);
     153      // sprintf (line, "%s:%d", argv[1], N + i);
     154      set_list_varname (line, argv[1], N + i, EXCEL_STYLE);
    139155      set_str_variable (line, argv[i+3]);
    140156    }
     
    159175    N = get_int_variable (line, &found);
    160176    for (i = 0; i < N; i++) {
    161       sprintf (line, "%s:%d", argv[1], i);
     177      // sprintf (line, "%s:%d", argv[1], i);
     178      set_list_varname (line, argv[1], i, EXCEL_STYLE);
    162179      value = get_variable (line);
    163180      if (value == NULL) continue;
     
    165182        free (value);
    166183        for (j = i + 1; j < N; j++) {
    167           sprintf (line2, "%s:%d", argv[1], j);
     184          // sprintf (line2, "%s:%d", argv[1], j);
     185          set_list_varname (line2, argv[1], j, EXCEL_STYLE);
    168186          next_value = get_variable (line2);
    169187          set_str_variable (line, next_value);
     
    235253      if (B != (char *) NULL) { *B = 0; }
    236254      if (*A != 0) {
    237         sprintf (line, "%s:%d", argv[1], i);
     255        // sprintf (line, "%s:%d", argv[1], i);
     256        set_list_varname (line, argv[1], i, EXCEL_STYLE);
    238257        set_str_variable (line, A);
    239258        A = B + 1;
     
    283302
    284303    if (*input) {
    285       sprintf (line, "%s:%d", argv[1], i);
     304      // sprintf (line, "%s:%d", argv[1], i);
     305      set_list_varname (line, argv[1], i, EXCEL_STYLE);
    286306      set_str_variable (line, input);
    287307      free (input);
    288308      i++;
    289    }
     309    }
    290310  }
    291311  return (TRUE);
    292312}
     313
     314static int set_list_varname (char *line, char *base, int N, int excelStyle) {
     315
     316  int i;
     317   
     318  // A-Z correspond to 0 - 25
     319
     320  if (excelStyle) {
     321    float f = log(26.0);
     322    float g = (N == 0) ? 0.0 : log(1.0*N);
     323    int Ndigit = (int) (g / f) + 1;
     324    if (Ndigit > 10) {
     325      sprintf (line, "%s:ZZZZZZZZZZ", base);
     326      return FALSE;
     327    }
     328    char name[12];
     329    memset (name, 0, 12);
     330    for (i = 0; i < Ndigit; i++) {
     331      float Npow = Ndigit - i - 1;
     332      float g = pow(26.0, Npow);
     333      int V = (int) (N / g);
     334      name[i] = (Npow == 0.0) ? 'A' + V : 'A' + V - 1;
     335      N -= V * g;
     336    }
     337    sprintf (line, "%s:%s", base, name);
     338  } else {
     339    sprintf (line, "%s:%d", base, N);
     340  }
     341  return TRUE;
     342}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.data

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.data/Makefile

    r35416 r36680  
    2525$(SRC)/book.$(ARCH).o           \
    2626$(SRC)/book_commands.$(ARCH).o  \
     27$(SRC)/cast.$(ARCH).o           \
    2728$(SRC)/center.$(ARCH).o \
    2829$(SRC)/clear.$(ARCH).o          \
     
    6364$(SRC)/imcut.$(ARCH).o          \
    6465$(SRC)/imhist.$(ARCH).o \
     66$(SRC)/impeaks.$(ARCH).o        \
    6567$(SRC)/imsmooth.$(ARCH).o       \
     68$(SRC)/imsmooth.generic.$(ARCH).o       \
     69$(SRC)/imsmooth.2d.$(ARCH).o    \
    6670$(SRC)/integrate.$(ARCH).o      \
    6771$(SRC)/interpolate.$(ARCH).o    \
     72$(SRC)/join.$(ARCH).o           \
    6873$(SRC)/jpeg.$(ARCH).o           \
    6974$(SRC)/kern.$(ARCH).o           \
     
    8489$(SRC)/mget.$(ARCH).o           \
    8590$(SRC)/minterpolate.$(ARCH).o   \
     91$(SRC)/medimage.$(ARCH).o       \
     92$(SRC)/medimage_commands.$(ARCH).o \
    8693$(SRC)/mset.$(ARCH).o           \
    8794$(SRC)/peak.$(ARCH).o           \
     
    143150$(SRC)/vmaxwell.$(ARCH).o          \
    144151$(SRC)/vgrid.$(ARCH).o             \
     152$(SRC)/vlist.$(ARCH).o             \
    145153$(SRC)/vload.$(ARCH).o             \
    146154$(SRC)/vzload.$(ARCH).o            \
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.data/densify.c

    r34088 r36680  
    22
    33# define CHECKVAL(ARG) if (!isfinite(ARG)) { gprint (GP_ERR, "illegal value for %s: %f\n", #ARG, ARG); return (FALSE); }
     4enum {IS_DOT, IS_SQUARE, IS_CIRCLE, IS_GAUSS};
    45
    56int densify (int argc, char **argv) {
    67
    7   int i, Nx, Ny, Xb, Yb, N, Xpix, Ypix, good, UseGraph;
     8  int i, Nx, Ny, Xb, Yb, ix, iy, N, Xpix, Ypix, good, UseGraph;
    89  double Xmin, Xmax, dX, Ymin, Ymax, dY;
    910  float *val;
     
    2425  }
    2526
     27  float scale = 0.0;
     28  if ((N = get_argument (argc, argv, "-scale"))) {
     29    remove_argument (N, &argc, argv);
     30    scale = atof(argv[N]);
     31    remove_argument (N, &argc, argv);
     32  }
     33
     34  int PSFTYPE = IS_DOT;
     35  if ((N = get_argument (argc, argv, "-psf"))) {
     36    remove_argument (N, &argc, argv);
     37    if (!strcasecmp(argv[N], "dot"))    PSFTYPE = IS_DOT;
     38    if (!strcasecmp(argv[N], "square")) PSFTYPE = IS_SQUARE;
     39    if (!strcasecmp(argv[N], "circle")) PSFTYPE = IS_CIRCLE;
     40    if (!strcasecmp(argv[N], "gauss"))  PSFTYPE = IS_GAUSS;
     41    remove_argument (N, &argc, argv);
     42  }
     43
    2644  good = UseGraph ? (argc == 4) : (argc == 10);
    2745  if (!good) {
    2846    gprint (GP_ERR, "USAGE: densify buffer x y Xmin Xmax dX Ymin Ymax dY\n");
    2947    gprint (GP_ERR, "   OR: densify buffer x y -graph\n");
     48    gprint (GP_ERR, " option: -psf [dot] (circle) (square) (gauss)\n");
    3049    return (FALSE);
    3150  }
     
    6988  CHECKVAL(dY);
    7089
     90  float scaleX = (scale > 0.0) ? scale / dX : 3.0;
     91  float scaleY = (scale > 0.0) ? scale / dY : 3.0;
     92
    7193  Nx = (Xmax - Xmin) / dX + 1;
    7294  Ny = (Ymax - Ymin) / dY + 1;
     
    7698  CreateBuffer (bf, Nx, Ny, -32, 0.0, 1.0);
    7799  strcpy (bf[0].file, "(empty)");
     100 
     101  float scale2 = (scaleX + 1.0) * (scaleY + 1.0);
     102  float fSquare = 1.0 / scale2;
     103  float fCircle = 1.0 / (3.141592 * scale2);
     104  float fSigma  = 0.5 / scale2;
     105  float fGauss  = 1.0 / (2.0 * 3.141592 * scale2);
    78106
    79107  x = vx[0].elements.Flt;
     
    83111    Xb = (*x - Xmin) / dX;
    84112    Yb = (*y - Ymin) / dY;
    85     if (Xb >= Nx) continue;
    86     if (Yb >= Ny) continue;
    87     if (Xb < 0) continue;
    88     if (Yb < 0) continue;
    89     val[Xb + Yb*Nx] ++;
     113    switch (PSFTYPE) {
     114      case IS_DOT:
     115        if (Xb >= Nx) continue;
     116        if (Yb >= Ny) continue;
     117        if (Xb < 0) continue;
     118        if (Yb < 0) continue;
     119        val[Xb + Yb*Nx] ++;
     120        break;
     121      case IS_SQUARE:
     122        for (ix = Xb - scaleX; ix <= Xb + scaleX; ix++) {
     123          for (iy = Yb - scaleY; iy <= Yb + scaleY; iy++) {
     124            if (ix >= Nx) continue;
     125            if (iy >= Ny) continue;
     126            if (ix < 0) continue;
     127            if (iy < 0) continue;
     128            val[ix + iy*Nx] += fSquare;
     129          }
     130        }
     131        break;
     132      case IS_CIRCLE:
     133        for (ix = Xb - scaleX; ix <= Xb + scaleX; ix++) {
     134          float dX = ix - Xb;
     135          for (iy = Yb - scaleY; iy <= Yb + scaleY; iy++) {
     136            float dY = iy - Yb;
     137            float r2 = dX*dX + dY*dY;
     138            if (r2 > 9) continue;
     139            if (ix >= Nx) continue;
     140            if (iy >= Ny) continue;
     141            if (ix < 0) continue;
     142            if (iy < 0) continue;
     143            val[ix + iy*Nx] += fCircle;
     144          }
     145        }
     146        break;
     147      case IS_GAUSS:
     148        for (ix = Xb - scaleX; ix <= Xb + scaleX; ix++) {
     149          float dX = ix - Xb;
     150          for (iy = Yb - scaleY; iy <= Yb + scaleY; iy++) {
     151            float dY = iy - Yb;
     152            float r2 = dX*dX + dY*dY;
     153            if (ix >= Nx) continue;
     154            if (iy >= Ny) continue;
     155            if (ix < 0) continue;
     156            if (iy < 0) continue;
     157            val[ix + iy*Nx] += fGauss*exp(-fSigma*r2);
     158          }
     159        }
     160        break;
     161    }
    90162  }
    91163  return (TRUE);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.data/init.c

    r35416 r36680  
    1010int center           PROTO((int, char **));
    1111int parity           PROTO((int, char **));
     12int cast             PROTO((int, char **));
    1213int circstats        PROTO((int, char **));
    1314int clear            PROTO((int, char **));
     
    5253int imcut            PROTO((int, char **));
    5354int imhist           PROTO((int, char **));
     55int impeaks          PROTO((int, char **));
    5456int imsmooth         PROTO((int, char **));
     57int imsmooth_generic PROTO((int, char **));
     58int imsmooth_2d      PROTO((int, char **));
    5559int integrate        PROTO((int, char **));
    5660int interpolate      PROTO((int, char **));
     61int join             PROTO((int, char **));
    5762int jpeg             PROTO((int, char **));
    5863int kern             PROTO((int, char **));
     
    7479int mget             PROTO((int, char **));
    7580int minterp          PROTO((int, char **));
     81int medimage_command PROTO((int, char **));
    7682int mset             PROTO((int, char **));
    7783int peak             PROTO((int, char **));
     
    133139int vmaxwell         PROTO((int, char **));
    134140int vload            PROTO((int, char **));
     141int vlist            PROTO((int, char **));
    135142int vzload           PROTO((int, char **));
    136143int vstats           PROTO((int, char **));
     
    160167  {1, "buffers",      list_buffers,     "list the currently allocated buffers (images)"},
    161168  {1, "center",       center,           "center image on coords"},
     169  {1, "cast",         cast,             "cast input vector to specified type"},
    162170  {1, "circstats",    circstats,        "circular statistics"},
    163171  {1, "clear",        clear,            "erase plot"},
     
    205213  {1, "imcut",        imcut,            "linear image cut between arbitrary coords"},
    206214  {1, "imhistogram",  imhist,           "histogram of an image region"},
     215  {1, "impeaks",      impeaks,          "find peaks in an image (return vectors)"},
    207216  {1, "imsmooth",     imsmooth,         "circular gaussian smoothing"},
     217  {1, "imsmooth.generic", imsmooth_generic, "circular non-gaussian smoothing"},
     218  {1, "imsmooth.2d",  imsmooth_2d,      "circular non-gaussian smoothing"},
    208219  {1, "imstats",      imstats,          "statistics on a portion of an image"},
    209220  {1, "integrate",    integrate,        "integrate a vector"},
    210221  {1, "interpolate",  interpolate,      "interpolate between vector pairs"},
     222  {1, "join",         join,             "find the join of two ID vectors"},
    211223  {1, "jpeg",         jpeg,             "convert display image to JPEG"},
    212224  {1, "kern",         kern,             "convolve with 3x3 kernel"},
     
    224236  {1, "minterp",      minterp,          "interpolate image pixels"},
    225237  {1, "iminterp",     minterp,          "interpolate image pixels"},
     238  {1, "medimage",     medimage_command, "median image manipulation"},
    226239  {1, "matrix",       matrix,           "matrix math operations"},
    227240  {1, "match2d",      match2d,          "match 2 pairs of X,Y vectors and return matched indexes"},
     
    290303  {1, "vgrid",        vgrid,            "generate an image from a triplet of vectors"},
    291304  {1, "vhistogram",   histogram,        "generate histogram from vector"},
     305  {1, "vlist",        vlist,            "append values to a vector from command line"},
    292306  {1, "vload",        vload,            "load vectors as overlay on image display"},
    293307  {1, "vmaxwell",     vmaxwell,         "fit a Maxwellian to a vector"},
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.data/match2d.c

    r33963 r36680  
    1414  Vector *index1, *index2;
    1515
     16  if ((N = get_argument (argc, argv, "-h"))) goto usage;
     17  if ((N = get_argument (argc, argv, "--help"))) goto usage;
     18
    1619  CLOSEST = FALSE;
    1720  if ((N = get_argument (argc, argv, "-closest"))) {
     
    3841  if (argc != 6) {
    3942    gprint (GP_ERR, "USAGE: match2d X1 Y1 X2 Y2 Radius [-index1 (index1)] [-index2 (index2)] [-closest]\n");
    40     gprint (GP_ERR, "  if -closest is provided, index1 & index2 will have the same length as X1 and X2 (respectively)\n");
    41     gprint (GP_ERR, "    with either the index of the match or a value of -1 for non-matches\n");
     43    gprint (GP_ERR, "  use -h or --help for more detail\n");
    4244    return (FALSE);
    4345  }
     
    9092
    9193  return (TRUE);
     94
     95usage:
     96  gprint (GP_ERR, "we have two modes of operation:\n\n");
     97
     98  gprint (GP_ERR, "without -closest, we are finding all matched pairs within the match radius.  in this\n");
     99  gprint (GP_ERR, "case, the two index vectors have the same length, one entry per matched pair.\n");
     100  gprint (GP_ERR, "x1[index1],y1[index1] matches to x2[index2],y2[index2].\n\n");
     101
     102  gprint (GP_ERR, "with -closest selected, we are finding the closest element of set 1 to each of set 2\n");
     103  gprint (GP_ERR, "and vice versa.  in this case, index1 is always the same length as x1,y1, while index2\n");
     104  gprint (GP_ERR, "is the same lengths as x2,y2.  x2[index1],y2[index1] matches x1,y1 while\n");
     105  gprint (GP_ERR, "x1[index2],y1[index2] matches x2,y2\n\n");
     106
     107  gprint (GP_ERR, "if -index1 or -index2 is not supplied, the vectors are created with names index1 or index2\n");
     108  gprint (GP_ERR, "use 'reindex' to generate new vectors based on these index vectors\n");
     109
     110  return FALSE;
    92111}
    93112
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.data/read_vectors.c

    r34753 r36680  
    2323// vector types
    2424enum {COLTYPE_NONE, COLTYPE_FLT, COLTYPE_INT, COLTYPE_TIME, COLTYPE_CHAR};
     25static int FITS_TRANSPOSE;
    2526
    2627int read_vectors (int argc, char **argv) {
     
    3435
    3536  char *buffer = NULL;
     37
     38  FITS_TRANSPOSE = FALSE;
     39  if ((Narg = get_argument (argc, argv, "-transpose"))) {
     40    remove_argument (Narg, &argc, argv);
     41    FITS_TRANSPOSE = TRUE;
     42  }
    3643
    3744  /* auto-sense table type */
     
    410417    }
    411418       
    412     // define the multifield vector names
    413     ALLOCATE (vec, Vector *, Nval);
    414     for (j = 0; j < Nval; j++) {
    415       if (Nval == 1)
    416         sprintf (name, "%s", argv[i]);
    417       else
    418         sprintf (name, "%s:%d", argv[i], j);
    419       if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
    420       ResetVector (vec[j], vecType, Ny);
    421     }
    422 
    423     if (!strcmp (type, "char")) {
    424       char *Ptr = data;
     419    if (!FITS_TRANSPOSE) {
     420      // define the multifield vector names (Nval vectors x Ny elements)
     421      ALLOCATE (vec, Vector *, Nval);
     422      for (j = 0; j < Nval; j++) {
     423        if (Nval == 1)
     424          sprintf (name, "%s", argv[i]);
     425        else
     426          sprintf (name, "%s:%d", argv[i], j);
     427        if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
     428        ResetVector (vec[j], vecType, Ny);
     429      }
     430
     431      if (!strcmp (type, "char")) {
     432        char *Ptr = data;
     433        for (j = 0; j < Ny; j++) {
     434          for (k = 0; k < Nval; k++, Ptr++) {
     435            vec[k][0].elements.Int[j] = *Ptr;
     436          }
     437        }
     438      }
     439      if (!strcmp (type, "short")) {
     440        short *Ptr = data;
     441        for (j = 0; j < Ny; j++) {
     442          for (k = 0; k < Nval; k++, Ptr++) {
     443            vec[k][0].elements.Int[j] = *Ptr;
     444          }
     445        }
     446      }
     447      if (!strcmp (type, "int")) {
     448        int *Ptr = data;
     449        for (j = 0; j < Ny; j++) {
     450          for (k = 0; k < Nval; k++, Ptr++) {
     451            vec[k][0].elements.Int[j] = *Ptr;
     452          }
     453        }
     454      }
     455      if (!strcmp (type, "int64_t")) {
     456        int64_t *Ptr = data;
     457        for (j = 0; j < Ny; j++) {
     458          for (k = 0; k < Nval; k++, Ptr++) {
     459            vec[k][0].elements.Int[j] = *Ptr;
     460          }
     461        }
     462      }
     463      if (!strcmp (type, "float")) {
     464        float *Ptr = data;
     465        for (j = 0; j < Ny; j++) {
     466          for (k = 0; k < Nval; k++, Ptr++) {
     467            vec[k][0].elements.Flt[j] = *Ptr;
     468          }
     469        }
     470      }
     471      if (!strcmp (type, "double")) {
     472        double *Ptr = data;
     473        for (j = 0; j < Ny; j++) {
     474          for (k = 0; k < Nval; k++, Ptr++) {
     475            vec[k][0].elements.Flt[j] = *Ptr;
     476          }
     477        }
     478      }
     479    } else {
     480      // define the multifield vector names (Ny vectors x Nval elements)
     481      ALLOCATE (vec, Vector *, Ny);
    425482      for (j = 0; j < Ny; j++) {
    426         for (k = 0; k < Nval; k++, Ptr++) {
    427           vec[k][0].elements.Int[j] = *Ptr;
    428         }
    429       }
    430     }
    431     if (!strcmp (type, "short")) {
    432       short *Ptr = data;
    433       for (j = 0; j < Ny; j++) {
    434         for (k = 0; k < Nval; k++, Ptr++) {
    435           vec[k][0].elements.Int[j] = *Ptr;
    436         }
    437       }
    438     }
    439     if (!strcmp (type, "int")) {
    440       int *Ptr = data;
    441       for (j = 0; j < Ny; j++) {
    442         for (k = 0; k < Nval; k++, Ptr++) {
    443           vec[k][0].elements.Int[j] = *Ptr;
    444         }
    445       }
    446     }
    447     if (!strcmp (type, "int64_t")) {
    448       int64_t *Ptr = data;
    449       for (j = 0; j < Ny; j++) {
    450         for (k = 0; k < Nval; k++, Ptr++) {
    451           vec[k][0].elements.Int[j] = *Ptr;
    452         }
    453       }
    454     }
    455     if (!strcmp (type, "float")) {
    456       float *Ptr = data;
    457       for (j = 0; j < Ny; j++) {
    458         for (k = 0; k < Nval; k++, Ptr++) {
    459           vec[k][0].elements.Flt[j] = *Ptr;
    460         }
    461       }
    462     }
    463     if (!strcmp (type, "double")) {
    464       double *Ptr = data;
    465       for (j = 0; j < Ny; j++) {
    466         for (k = 0; k < Nval; k++, Ptr++) {
    467           vec[k][0].elements.Flt[j] = *Ptr;
     483        if (Ny == 1)
     484          sprintf (name, "%s", argv[i]);
     485        else
     486          sprintf (name, "%s:%d", argv[i], j);
     487        if ((vec[j] = SelectVector (name, ANYVECTOR, TRUE)) == NULL) ESCAPE ("bad vector name");
     488        ResetVector (vec[j], vecType, Nval);
     489      }
     490
     491      if (!strcmp (type, "char")) {
     492        char *Ptr = data;
     493        for (j = 0; j < Ny; j++) {
     494          for (k = 0; k < Nval; k++, Ptr++) {
     495            vec[j][0].elements.Int[k] = *Ptr;
     496          }
     497        }
     498      }
     499      if (!strcmp (type, "short")) {
     500        short *Ptr = data;
     501        for (j = 0; j < Ny; j++) {
     502          for (k = 0; k < Nval; k++, Ptr++) {
     503            vec[j][0].elements.Int[k] = *Ptr;
     504          }
     505        }
     506      }
     507      if (!strcmp (type, "int")) {
     508        int *Ptr = data;
     509        for (j = 0; j < Ny; j++) {
     510          for (k = 0; k < Nval; k++, Ptr++) {
     511            vec[j][0].elements.Int[k] = *Ptr;
     512          }
     513        }
     514      }
     515      if (!strcmp (type, "int64_t")) {
     516        int64_t *Ptr = data;
     517        for (j = 0; j < Ny; j++) {
     518          for (k = 0; k < Nval; k++, Ptr++) {
     519            vec[j][0].elements.Int[k] = *Ptr;
     520          }
     521        }
     522      }
     523      if (!strcmp (type, "float")) {
     524        float *Ptr = data;
     525        for (j = 0; j < Ny; j++) {
     526          for (k = 0; k < Nval; k++, Ptr++) {
     527            vec[j][0].elements.Flt[k] = *Ptr;
     528          }
     529        }
     530      }
     531      if (!strcmp (type, "double")) {
     532        double *Ptr = data;
     533        for (j = 0; j < Ny; j++) {
     534          for (k = 0; k < Nval; k++, Ptr++) {
     535            vec[j][0].elements.Flt[k] = *Ptr;
     536          }
    468537        }
    469538      }
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.data/rebin.c

    r28241 r36680  
    133133              *Vout += *Vin;
    134134              if (Normalize) {(*Vn) ++;}
     135              // if ((i == 1) && (j == 1)) fprintf (stderr, "%d,%d : %d,%d : %f : %f : %d\n", i, j, x, y, *Vin, *Vout, *Vn);
    135136            }
    136137            if (Normalize) {Vn ++;}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.data/vellipse.c

    r25757 r36680  
    228228 */
    229229
     230// XXX NOTE that PHI is defined with the wrong sign, should fix this...
    230231opihi_flt fellipseOD (opihi_flt alpha, opihi_flt *par, int Npar, opihi_flt *dpar) {
    231232 
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/cmd.data/vgauss.c

    r35109 r36680  
    4848  if ((ovec = SelectVector (argv[4], ANYVECTOR, TRUE)) == NULL) return (FALSE);
    4949
     50  CastVector (xvec, OPIHI_FLT);
     51  CastVector (yvec, OPIHI_FLT);
     52
    5053  int Nsvec = strlen(argv[3]);
    5154
     
    6972  }
    7073
    71   CastVector (xvec, OPIHI_FLT);
    72   CastVector (yvec, OPIHI_FLT);
    7374  CastVector (svec, OPIHI_FLT);
    7475  // XXX Cast is failing.
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/dvo/Makefile

    r34461 r36680  
    4040$(SRC)/cmpload.$(ARCH).o                \
    4141$(SRC)/cmpread.$(ARCH).o                \
     42$(SRC)/coordimage.$(ARCH).o             \
    4243$(SRC)/ddmags.$(ARCH).o         \
    4344$(SRC)/detrend.$(ARCH).o                \
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/dvo/avmatch.c

    r35416 r36680  
    7070  dbExtractAveragesInit ();
    7171
    72   // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results
    7372  RAvec  = NULL;
    7473  DECvec = NULL;
    75   if (PARALLEL && !HOST_ID) {
    76     if (!CoordsFile) {
    77       // get vectors corresponding to coordinates of interest
    78       if ((RAvec  = SelectVector (argv[1], ANYVECTOR, TRUE)) == NULL) goto help;
    79       if ((DECvec = SelectVector (argv[2], ANYVECTOR, TRUE)) == NULL) goto help;
    80      
    81       ALLOCATE (vec, Vector *, 2);
    82       vec[0] = RAvec;
    83       vec[1] = DECvec;
    84 
    85       CoordsFile = abspath("coords.fits", 1024);
    86       int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL);
    87       if (!status) goto escape;
    88     }
    89 
    90     char *targv1 = argv[1];
    91     char *targv2 = argv[2];
    92     argv[1] = strcreate ("-coords");
    93     argv[2] = strcreate (CoordsFile);
    94     free (CoordsFile);
    95 
    96     // I need to pass the RA & DEC vectors to the remote clients...
    97     int status = HostTableParallelOps (skylist, argc, argv, RESULT_FILE, TRUE, RAvec->Nelements, VERBOSE);
    98     if (vec) free (vec);
    99    
    100     free (argv[1]);
    101     free (argv[2]);
    102     argv[1] = targv1;
    103     argv[2] = targv2;
    104 
    105     return status;
    106   }
    107 
    10874  // get vectors corresponding to coordinates of interest
    10975  if (CoordsFile) {
     
    12086    remove_argument (1, &argc, argv);
    12187  }
     88
     89  /* load regions which contain all supplied RA,DEC coordinates */
     90  if ((skylist = SelectRegionsByCoordVectors (RAvec, DECvec)) == NULL) goto escape;
     91
     92  // this does all the work of re-packaging the command, calling it on the remote machines, then loading in the results
     93  if (PARALLEL && !HOST_ID) {
     94
     95    // We need to copy the args to a temp array and modify them so that we send the
     96    // correct set to the remote client.  The args list looks like this:
     97    // if (!CoordsFile) : avmatch (RADIUS) field, ... [we removed RA & DEC above]
     98    // if ( CoordsFile) : avmatch (RADIUS) field, ... [because we stripped off the -coords filename elements]
     99
     100    // allocate the temp array and copy all but (RA) (DEC)
     101    int targc = 0;
     102    char **targv = NULL;
     103    ALLOCATE (targv, char *, argc + 2);
     104    for (i = 0; i < argc; i++) {
     105      targv[targc] = strcreate (argv[i]);
     106      targc ++;
     107    }
     108
     109    // if not specified, create the coords.fits input file
     110    // NOTE: RAvec, DECvec were set above
     111    if (!CoordsFile) {
     112      ALLOCATE (vec, Vector *, 2);
     113      vec[0] = RAvec;
     114      vec[1] = DECvec;
     115
     116      CoordsFile = abspath("coords.fits", 1024);
     117      int status = WriteVectorTableFITS (CoordsFile, "COORDS", vec, 2, FALSE, NULL);
     118      if (!status) goto escape;
     119    }
     120
     121    // add the coords file to the args list
     122    targv[targc+0] = strcreate ("-coords");
     123    targv[targc+1] = CoordsFile; // this gets freed with targv
     124    targc += 2;
     125   
     126    // I need to pass the RA & DEC vectors to the remote clients...
     127    int status = HostTableParallelOps (skylist, targc, targv, RESULT_FILE, TRUE, RAvec->Nelements, VERBOSE);
     128    if (vec) free (vec);
     129   
     130    // free up targv
     131    for (i = 0; i < targc; i++) {
     132      free (targv[i]);
     133    }
     134    free (targv);
     135
     136    return status;
     137  }
     138
    122139  RADIUS = atof (argv[1]);
    123140  remove_argument (1, &argc, argv);
     
    140157    if (fields[i].photcode[0].type == PHOT_DEP) needMeasures = TRUE;
    141158  }
    142 
    143   /* load regions which contain all supplied RA,DEC coordinates */
    144   if ((skylist = SelectRegionsByCoordVectors (RAvec, DECvec)) == NULL) goto escape;
    145159
    146160  /* create output storage vectors */
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/dvo/dvo_client.c

    r35263 r36680  
    9090  }
    9191
     92  // these are set in 'startup.c' for readline-based programs
     93  set_variable ("PID", getpid());
     94  set_str_variable ("KAPA", "kapa");
     95  set_int_variable ("UNSIGN", 0);
     96  gfits_set_unsign_mode (FALSE);
     97
    9298  return;
    9399}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/dvo/find_matches.c

    r29759 r36680  
    5050  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    5151  tcoords.Npolyterms = 1;
    52   strcpy (tcoords.ctype, "RA---ARC");
     52  strcpy (tcoords.ctype, "DEC--ARC");
    5353
    5454  // this region includes a boundary layer of size RADIUS
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/dvo/gimages.c

    r34844 r36680  
    136136      local.pc2_1 = local.pc1_2 = 0.0;
    137137      local.Npolyterms = 1;
    138       strcpy (local.ctype, "RA---TAN");
     138      strcpy (local.ctype, "DEC--TAN");
    139139
    140140      if (typehash == DistortImage) {
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/dvo/hosts.c

    r35757 r36680  
    1212    gprint (GP_ERR, "  commands:\n");
    1313    gprint (GP_ERR, "    purge-temp : delete all tempfiles for this shell\n");
    14     gprint (GP_ERR, "               : [-old-pid] [-all-pid] [-v] [-verbose] [-commit] [-type type]\n");
     14    gprint (GP_ERR, "               : [-old-pid] [-all-pid] [-v] [-verbose] [-commit] [-type type] [-age hours]\n");
    1515    gprint (GP_ERR, "    get-results : determine name of RESULTS file\n");
    1616    return FALSE;
     
    3333    }
    3434   
     35    struct timeval now;
     36    gettimeofday (&now, NULL);
     37
     38    float AGE = 0;
     39    int NOW = now.tv_sec;
     40    if ((N = get_argument (argc, argv, "-age"))) {
     41      remove_argument (N, &argc, argv);
     42      AGE = atof(argv[N]);
     43      remove_argument (N, &argc, argv);
     44    }
     45
    3546    int VERBOSE = FALSE;
    3647    if ((N = get_argument (argc, argv, "-v"))) {
     
    121132      glob (name, 0, NULL, &pglob);
    122133      int j;
     134      struct stat filestats;
    123135      for (j = 0; j < pglob.gl_pathc; j++) {
     136        if (AGE > 0) {
     137          if (stat(pglob.gl_pathv[j], &filestats)) {
     138            gprint (GP_ERR, "failed to get stats for %s\n", pglob.gl_pathv[j]);
     139            continue;
     140          }
     141          float myAge = (NOW - filestats.st_mtime) / 3600.0;
     142          if (myAge < AGE) continue;
     143        }
    124144        if (VERBOSE) gprint (GP_ERR, "unlink %s\n", pglob.gl_pathv[j]);
    125145        if (!DRYRUN) unlink (pglob.gl_pathv[j]);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/dvo/init.c

    r34461 r36680  
    1313int cmpload         PROTO((int, char **));
    1414int cmpread         PROTO((int, char **));
     15int coordimage      PROTO((int, char **));
    1516int ddmags          PROTO((int, char **));
    1617int detrend         PROTO((int, char **));
     
    7172  {1, "cmpload",     cmpload,      "load cmp file into ?"},
    7273  {1, "cmpread",     cmpread,      "read data from cmp format files"},
     74  {1, "coordimage",  coordimage,   "generate a map of the transformation residuals"},
    7375  {1, "ddmags",      ddmags,       "plot magnitude differences"},
    7476  {1, "detrend",     detrend,      "extract from detrend database?"},
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/dvo/photometry.c

    r35416 r36680  
    662662      break;
    663663    case AVE_dMAG:
    664       value = PhotdM (code, average, secfilt);
     664      value = PhotAveErr (code, average, secfilt);
    665665      break;
    666666    case AVE_Xm:
     
    865865  /* for ErrSelect, check average errors */
    866866  if (ErrSelect) {
    867     dM = PhotdM (code, average, secfilt);
     867    dM = PhotAveErr (code, average, secfilt);
    868868    if (dM > ErrValue) return (FALSE);
    869869  }
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/dvo/showtile.c

    r34584 r36680  
    3434  coords.pc1_2  = coords.pc2_1  = 0.0;
    3535  coords.Npolyterms = 0;
    36   strcpy (coords.ctype, "RA---TAN");
     36  strcpy (coords.ctype, "DEC--TAN");
    3737 
    3838  /* fill in top-left region */
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/dvo/simage.c

    r34584 r36680  
    4343  /* get astrometry information */
    4444  strcpy (coords.ctype, "NONE");
    45   gfits_scan (&header, "CTYPE1",   "%s",  1, coords.ctype);
    46   if (strcmp (coords.ctype, "RA---PLY")) {
     45  gfits_scan (&header, "CTYPE2",   "%s",  1, coords.ctype);
     46  if (strcmp (coords.ctype, "DEC--PLY")) {
    4747    gprint (GP_ERR, "ERROR: wrong astrometric info in header\n");
    4848    return (FALSE);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/include/data.h

    r34584 r36680  
    3333  char **pageIDs;
    3434} Book;
     35
     36// the interpolating spline has valu
     37typedef struct {
     38  int Nknots;
     39  opihi_flt *xk;
     40  opihi_flt *yk;
     41  opihi_flt *y2;
     42  char *name;
     43} Spline;
     44
     45typedef struct {
     46  char *name;
     47  int Ninput;
     48  int Nx;
     49  int Ny;
     50  float **buffers;
     51} MedImageType;
    3552
    3653void InitData (void);
     
    144161
    145162/* starfuncs.c */
    146 double get_aperture_stats (Matrix *matrix, int X, int Y, int Npix, int Nborder, double max);
     163double get_aperture_stats (Matrix *matrix, int X, int Y, int Npix, int Nborder, double max, int VERBOSE);
    147164int set_rough_radii (double Ra, double Ri, double Ro);
    148165int get_rough_star (float *data, int Nx, int Ny, int x, int y, opihi_flt *xc, opihi_flt *yc, opihi_flt *sx, opihi_flt *sy, opihi_flt *sxy, opihi_flt *zs, opihi_flt *zp, opihi_flt *sk);
     
    170187void FreeQueues (void);
    171188void FreeBooks (void);
    172 
    173 // the interpolating spline has valu
    174 typedef struct {
    175   int Nknots;
    176   opihi_flt *xk;
    177   opihi_flt *yk;
    178   opihi_flt *y2;
    179   char *name;
    180 } Spline;
    181189
    182190/* in SplineOps.c */
     
    207215double hermitian_10(double x);
    208216
     217/* in MedImageOps.c */
     218void InitMedImages ();
     219void FreeMedImages ();
     220void FreeMedImage (MedImageType *medimage);
     221MedImageType *FindMedImage (char *name);
     222MedImageType *CreateMedImage (char *name, int Nx, int Ny);
     223int DeleteMedImage (MedImageType *medimage);
     224void ListMedImages ();
     225
    209226# endif
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/include/dvomath.h

    r33662 r36680  
    5555} Buffer;
    5656
     57typedef enum {
     58  ST_NONE,
     59  ST_LEFT,
     60  ST_RIGHT,
     61  ST_COMMA,
     62  ST_TRINARY,
     63  ST_OR,
     64  ST_AND,
     65  ST_LOGIC,
     66  ST_BITWISE,
     67  ST_ADD,
     68  ST_TIMES,
     69  ST_POWER,
     70  ST_UNARY,
     71  ST_BINARY,
     72
     73  ST_VALUE,
     74  ST_SCALAR_INT,
     75  ST_SCALAR_FLT,
     76  ST_VECTOR,
     77  ST_VECTOR_TMP,
     78  ST_MATRIX,
     79  ST_MATRIX_TMP,
     80
     81  ST_STRING,
     82  ST_STRING_TMP,
     83} StackVarType;
     84
    5785typedef struct {                        /* math stack structure */
    5886  char   *name;
    59   char    type;
     87  StackVarType type;
    6088  Buffer *buffer;
    6189  Vector *vector;
     
    77105void          delete_stack          PROTO((StackVar *stack, int Nstack));
    78106void          clear_stack           PROTO((StackVar *stack));
    79 void          assign_stack          PROTO((StackVar *stack, char *name, int type));
     107void          assign_stack          PROTO((StackVar *stack, char *name, StackVarType type));
     108
     109int           SSS_trinary           PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op));
     110int           VVV_trinary           PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op));
     111int           MMM_trinary           PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op));
    80112
    81113int           VV_binary             PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op));
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/include/pantasks.h

    r32632 r36680  
    116116
    117117  int active;
    118   int priority;
     118  int nicelevel;
    119119
    120120} Task;
     
    161161
    162162  JobMode     mode;                     /* local or controller? */
    163   int     priority;
     163  int     nicelevel;
    164164  char   *realhost;
    165165
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/include/pcontrol.h

    r33662 r36680  
    88/** job status values **/
    99typedef enum {
     10  PCONTROL_JOB_NONE, // XXX OK?
    1011  PCONTROL_JOB_ALLJOBS,
    1112  PCONTROL_JOB_PENDING,
     
    119120  int          exit_status;
    120121  int          Reset;
    121   int          priority;
     122  int          nicelevel;
    122123  JobMode      mode;
    123124  JobStat      state;
     
    309310char  *GetJobStackName (int StackID);
    310311Stack *GetJobStackByName (char *name);
     312int GetJobStackIDbyName (char *name);
    311313int    PutJob (Job *job, int StackID, int where);
    312314int    PutJobSetState (Job *job, int StackID, int where, int state);
    313315Job   *PullJobByID (IDtype JobID, int *StackID);
    314316Job   *PullJobFromStackByID (int StackID, int ID);
    315 IDtype AddJob (char *hostname, JobMode mode, int timeout, int priority, int argc, char **argv, int Nxhosts, char **xhosts);
     317IDtype AddJob (char *hostname, JobMode mode, int timeout, int nicelevel, int argc, char **argv, int Nxhosts, char **xhosts);
    316318void   DelJob (Job *job);
    317319Host  *UnlinkJobAndHost (Job *job);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/lib.data/Makefile

    r34584 r36680  
    2424$(SDIR)/spline.$(ARCH).o                \
    2525$(SDIR)/SplineOps.$(ARCH).o             \
     26$(SDIR)/MedImageOps.$(ARCH).o           \
    2627$(SDIR)/mrqmin.$(ARCH).o                \
    2728$(SDIR)/mrq2dmin.$(ARCH).o              \
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/lib.data/starfuncs.c

    r34088 r36680  
    11# include "data.h"
    22
    3 double get_aperture_stats (Matrix *matrix, int X, int Y, int Npix, int Nborder, double max) {
     3double get_aperture_stats (Matrix *matrix, int X, int Y, int Npix, int Nborder, double max, int VERBOSE) {
    44
    55  double *ring;
     
    9595  set_int_variable ("Npts", Npts);
    9696 
    97   gprint (GP_LOG, "%f %f %f %f %f %f %f %f\n", x, y, FWHMx, FWHMy, sky, I, mag, dmag);
     97  if (VERBOSE) gprint (GP_LOG, "%f %f %f %f %f %f %f %f\n", x, y, FWHMx, FWHMy, sky, I, mag, dmag);
    9898
    9999  return (mag);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/lib.shell/ListOps.c

    r33963 r36680  
    189189int is_list_data (char *line) {
    190190
    191   char *comm, *temp;
    192 
    193   temp = thisword (nextword (nextword (line)));
    194   comm = thisword (line);
    195 
     191  char *comm = NULL;
     192  char *temp = NULL;
     193  char *ptr  = NULL;
     194
     195  comm = thisword (line);
    196196  if (comm == NULL) goto escape;
    197 
    198197  if (strcmp (comm, "list")) goto escape;
     198
     199  ptr = nextword (line);
     200  if (!strncmp("-excel", ptr, strlen("-excel"))) ptr = nextword (ptr);
     201  if (!strncmp("-excel-style", ptr, strlen("-excel-style"))) ptr = nextword (ptr);
     202  temp = thisword (ptr);
    199203
    200204  /* if (cond) (command) does not define a complete block */
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/lib.shell/check_stack.c

    r34260 r36680  
    1212
    1313  for (i = 0; i < Nstack; i++) {
    14     if (stack[i].type == 'X') {
     14    if (stack[i].type == ST_VALUE) {
    1515
    1616      /** if this is a number, put it on the list of scalars and move on.  assume value is
     
    2727      stack[i].IntValue = strtol (stack[i].name, &c2, 0);
    2828      if ((fabs(stack[i].FltValue) > MAX_INT) && (c1 == stack[i].name + strlen (stack[i].name))) {
    29         stack[i].type  = 'S'; // 'S' == (float)
     29        stack[i].type  = ST_SCALAR_FLT; // (float)
    3030        continue;
    3131      }
    3232      if (c2 == stack[i].name + strlen (stack[i].name)) {
    33         stack[i].type  = 's'; // 's' == (int)
     33        stack[i].type  = ST_SCALAR_INT; // (int)
    3434        continue;
    3535      }
    3636      if (c1 == stack[i].name + strlen (stack[i].name)) {
    37         stack[i].type  = 'S'; // 'S' == (float)
     37        stack[i].type  = ST_SCALAR_FLT; // (float)
    3838        continue;
    3939      }
     
    4242      if (IsBuffer (stack[i].name)) {
    4343        stack[i].buffer = SelectBuffer (stack[i].name, OLDBUFFER, TRUE);
    44         stack[i].type   = 'M';
     44        stack[i].type   = ST_MATRIX;
    4545        if (Nx == -1) {
    4646          Nx = stack[i].buffer[0].matrix.Naxis[0];
     
    6363      if (IsVector (stack[i].name)) {
    6464        stack[i].vector = SelectVector (stack[i].name, OLDVECTOR, FALSE);
    65         stack[i].type   = 'V';
     65        stack[i].type   = ST_VECTOR;
    6666
    6767        if (Nv == -1) Nv = stack[i].vector[0].Nelements;
     
    8080
    8181      /* this is not a scalar, vector, or matrix.  must be string */
    82       stack[i].type  = 'W';
     82      stack[i].type  = ST_STRING;
    8383    }
    8484  }
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/lib.shell/convert_to_RPN.c

    r34088 r36680  
    44StackVar *convert_to_RPN (int argc, char **argv, int *nstack) {
    55 
    6   int type;
     6 StackVarType type;
    77  int i, j, Nstack, Nop_stack, NSTACK;
    88  StackVar *stack, *op_stack;
     
    2121   
    2222    /* decide on priority of object */
    23     type = 0;
     23    type = ST_NONE;
     24
     25    /* trinary operations */
     26    if (!strcmp (argv[i], "?"))      { type = ST_TRINARY; goto gotit; }
     27    if (!strcmp (argv[i], ":"))      { type = ST_COMMA; goto gotit; }
     28
    2429    /* unary operations */
    25     if (!strcmp (argv[i], "abs"))    { type = 9; goto gotit; }
    26     if (!strcmp (argv[i], "int"))    { type = 9; goto gotit; }
    27     if (!strcmp (argv[i], "exp"))    { type = 9; goto gotit; }
    28     if (!strcmp (argv[i], "ten"))    { type = 9; goto gotit; }
    29     if (!strcmp (argv[i], "log"))    { type = 9; goto gotit; }
    30     if (!strcmp (argv[i], "ln"))     { type = 9; goto gotit; }
    31     if (!strcmp (argv[i], "sqrt"))   { type = 9; goto gotit; }
    32     if (!strcmp (argv[i], "erf"))    { type = 9; goto gotit; }
    33 
    34     if (!strcmp (argv[i], "sinh"))   { type = 9; goto gotit; }
    35     if (!strcmp (argv[i], "cosh"))   { type = 9; goto gotit; }
    36     if (!strcmp (argv[i], "asinh"))  { type = 9; goto gotit; }
    37     if (!strcmp (argv[i], "acosh"))  { type = 9; goto gotit; }
    38 
    39     if (!strcmp (argv[i], "sin"))    { type = 9; goto gotit; }
    40     if (!strcmp (argv[i], "cos"))    { type = 9; goto gotit; }
    41     if (!strcmp (argv[i], "tan"))    { type = 9; goto gotit; }
    42     if (!strcmp (argv[i], "dsin"))   { type = 9; goto gotit; }
    43     if (!strcmp (argv[i], "dcos"))   { type = 9; goto gotit; }
    44     if (!strcmp (argv[i], "dtan"))   { type = 9; goto gotit; }
    45     if (!strcmp (argv[i], "asin"))   { type = 9; goto gotit; }
    46     if (!strcmp (argv[i], "acos"))   { type = 9; goto gotit; }
    47     if (!strcmp (argv[i], "atan"))   { type = 9; goto gotit; }
    48     if (!strcmp (argv[i], "dasin"))  { type = 9; goto gotit; }
    49     if (!strcmp (argv[i], "dacos"))  { type = 9; goto gotit; }
    50     if (!strcmp (argv[i], "datan"))  { type = 9; goto gotit; }
    51 
    52     if (!strcmp (argv[i], "lgamma")) { type = 9; goto gotit; }
    53 
    54     if (!strcmp (argv[i], "rnd"))    { type = 9; goto gotit; }
    55     if (!strcmp (argv[i], "xramp"))  { type = 9; goto gotit; }
    56     if (!strcmp (argv[i], "yramp"))  { type = 9; goto gotit; }
    57     if (!strcmp (argv[i], "ramp"))   { type = 9; goto gotit; }
    58     if (!strcmp (argv[i], "zero"))   { type = 9; goto gotit; }
    59     if (!strcmp (argv[i], "--"))     { type = 9; goto gotit; }
    60     if (!strcmp (argv[i], "not"))    { type = 9; goto gotit; }
    61     if (!strcmp (argv[i], "isinf"))  { type = 9; goto gotit; }
    62     if (!strcmp (argv[i], "isnan"))  { type = 9; goto gotit; }
     30    if (!strcmp (argv[i], "abs"))    { type = ST_UNARY; goto gotit; }
     31    if (!strcmp (argv[i], "int"))    { type = ST_UNARY; goto gotit; }
     32    if (!strcmp (argv[i], "floor"))  { type = ST_UNARY; goto gotit; }
     33    if (!strcmp (argv[i], "round"))  { type = ST_UNARY; goto gotit; }
     34    if (!strcmp (argv[i], "ceil"))   { type = ST_UNARY; goto gotit; }
     35    if (!strcmp (argv[i], "rint"))   { type = ST_UNARY; goto gotit; }
     36    if (!strcmp (argv[i], "exp"))    { type = ST_UNARY; goto gotit; }
     37    if (!strcmp (argv[i], "ten"))    { type = ST_UNARY; goto gotit; }
     38    if (!strcmp (argv[i], "log"))    { type = ST_UNARY; goto gotit; }
     39    if (!strcmp (argv[i], "ln"))     { type = ST_UNARY; goto gotit; }
     40    if (!strcmp (argv[i], "sqrt"))   { type = ST_UNARY; goto gotit; }
     41    if (!strcmp (argv[i], "erf"))    { type = ST_UNARY; goto gotit; }
     42    if (!strcmp (argv[i], "sinh"))   { type = ST_UNARY; goto gotit; }
     43    if (!strcmp (argv[i], "cosh"))   { type = ST_UNARY; goto gotit; }
     44    if (!strcmp (argv[i], "asinh"))  { type = ST_UNARY; goto gotit; }
     45    if (!strcmp (argv[i], "acosh"))  { type = ST_UNARY; goto gotit; }
     46    if (!strcmp (argv[i], "sin"))    { type = ST_UNARY; goto gotit; }
     47    if (!strcmp (argv[i], "cos"))    { type = ST_UNARY; goto gotit; }
     48    if (!strcmp (argv[i], "tan"))    { type = ST_UNARY; goto gotit; }
     49    if (!strcmp (argv[i], "dsin"))   { type = ST_UNARY; goto gotit; }
     50    if (!strcmp (argv[i], "dcos"))   { type = ST_UNARY; goto gotit; }
     51    if (!strcmp (argv[i], "dtan"))   { type = ST_UNARY; goto gotit; }
     52    if (!strcmp (argv[i], "asin"))   { type = ST_UNARY; goto gotit; }
     53    if (!strcmp (argv[i], "acos"))   { type = ST_UNARY; goto gotit; }
     54    if (!strcmp (argv[i], "atan"))   { type = ST_UNARY; goto gotit; }
     55    if (!strcmp (argv[i], "dasin"))  { type = ST_UNARY; goto gotit; }
     56    if (!strcmp (argv[i], "dacos"))  { type = ST_UNARY; goto gotit; }
     57    if (!strcmp (argv[i], "datan"))  { type = ST_UNARY; goto gotit; }
     58    if (!strcmp (argv[i], "lgamma")) { type = ST_UNARY; goto gotit; }
     59    if (!strcmp (argv[i], "rnd"))    { type = ST_UNARY; goto gotit; }
     60    if (!strcmp (argv[i], "xramp"))  { type = ST_UNARY; goto gotit; }
     61    if (!strcmp (argv[i], "yramp"))  { type = ST_UNARY; goto gotit; }
     62    if (!strcmp (argv[i], "ramp"))   { type = ST_UNARY; goto gotit; }
     63    if (!strcmp (argv[i], "zero"))   { type = ST_UNARY; goto gotit; }
     64    if (!strcmp (argv[i], "--"))     { type = ST_UNARY; goto gotit; }
     65    if (!strcmp (argv[i], "not"))    { type = ST_UNARY; goto gotit; }
     66    if (!strcmp (argv[i], "isinf"))  { type = ST_UNARY; goto gotit; }
     67    if (!strcmp (argv[i], "isnan"))  { type = ST_UNARY; goto gotit; }
    6368
    6469    /* binary operations */
    65     if (!strcmp (argv[i], "^"))      { type = 8; goto gotit; }
    66 
    67     if (!strcmp (argv[i], "@"))      { type = 7; goto gotit; }
    68     if (!strcmp (argv[i], "/"))      { type = 7; goto gotit; }
    69     if (!strcmp (argv[i], "*"))      { type = 7; goto gotit; }
    70     if (!strcmp (argv[i], "%"))      { type = 7; goto gotit; }
    71 
    72     if (!strcmp (argv[i], "+"))      { type = 6; goto gotit; }
    73     if (!strcmp (argv[i], "-"))      { type = 6; goto gotit; }
     70    if (!strcmp (argv[i], "^"))      { type = ST_POWER; goto gotit; }
     71
     72    if (!strcmp (argv[i], "max"))    { type = ST_BINARY; strcpy (argv[i], "U"); goto gotit; }
     73    if (!strcmp (argv[i], "min"))    { type = ST_BINARY; strcpy (argv[i], "D"); goto gotit; }
     74    if (!strcmp (argv[i], "atan2"))  { type = ST_BINARY; goto gotit; }
     75    if (!strcmp (argv[i], ","))      { type = ST_COMMA; goto gotit; }
     76
     77    if (!strcmp (argv[i], "@"))      { type = ST_TIMES; goto gotit; }
     78    if (!strcmp (argv[i], "/"))      { type = ST_TIMES; goto gotit; }
     79    if (!strcmp (argv[i], "*"))      { type = ST_TIMES; goto gotit; }
     80    if (!strcmp (argv[i], "%"))      { type = ST_TIMES; goto gotit; }
     81
     82    if (!strcmp (argv[i], "+"))      { type = ST_ADD; goto gotit; }
     83    if (!strcmp (argv[i], "-"))      { type = ST_ADD; goto gotit; }
    7484       
    75     if (!strcmp (argv[i], "&"))      { type = 5; goto gotit; }
    76     if (!strcmp (argv[i], "|"))      { type = 5; goto gotit; }
    77 
    78     if (!strcmp (argv[i], "<"))      { type = 4; goto gotit; }
    79     if (!strcmp (argv[i], ">"))      { type = 4; goto gotit; }
    80     if (!strcmp (argv[i], "=="))     { type = 4; strcpy (argv[i], "E"); goto gotit; }
    81     if (!strcmp (argv[i], "!="))     { type = 4; strcpy (argv[i], "N"); goto gotit; }
    82     if (!strcmp (argv[i], "<="))     { type = 4; strcpy (argv[i], "L"); goto gotit; }
    83     if (!strcmp (argv[i], ">="))     { type = 4; strcpy (argv[i], "G"); goto gotit; }
    84     if (!strcmp (argv[i], ">>"))     { type = 4; strcpy (argv[i], "U"); goto gotit; }
    85     if (!strcmp (argv[i], "<<"))     { type = 4; strcpy (argv[i], "D"); goto gotit; }
    86 
    87     if (!strcmp (argv[i], "&&"))     { type = 3; strcpy (argv[i], "A"); goto gotit; }
    88     if (!strcmp (argv[i], "||"))     { type = 3; strcpy (argv[i], "O"); goto gotit; }
    89 
    90     if (!strcmp (argv[i], "("))      { type = 2; goto gotit; }
    91     if (!strcmp (argv[i], ")"))      { type = 1; goto gotit; }
     85    if (!strcmp (argv[i], "&"))      { type = ST_BITWISE; goto gotit; }
     86    if (!strcmp (argv[i], "|"))      { type = ST_BITWISE; goto gotit; }
     87
     88    if (!strcmp (argv[i], "<"))      { type = ST_LOGIC; goto gotit; }
     89    if (!strcmp (argv[i], ">"))      { type = ST_LOGIC; goto gotit; }
     90    if (!strcmp (argv[i], "=="))     { type = ST_LOGIC; strcpy (argv[i], "E"); goto gotit; }
     91    if (!strcmp (argv[i], "!="))     { type = ST_LOGIC; strcpy (argv[i], "N"); goto gotit; }
     92    if (!strcmp (argv[i], "<="))     { type = ST_LOGIC; strcpy (argv[i], "L"); goto gotit; }
     93    if (!strcmp (argv[i], ">="))     { type = ST_LOGIC; strcpy (argv[i], "G"); goto gotit; }
     94    if (!strcmp (argv[i], ">>"))     { type = ST_LOGIC; strcpy (argv[i], "U"); goto gotit; }
     95    if (!strcmp (argv[i], "<<"))     { type = ST_LOGIC; strcpy (argv[i], "D"); goto gotit; }
     96
     97    if (!strcmp (argv[i], "&&"))     { type = ST_AND; strcpy (argv[i], "A"); goto gotit; }
     98    if (!strcmp (argv[i], "||"))     { type = ST_OR ; strcpy (argv[i], "O"); goto gotit; }
     99
     100    if (!strcmp (argv[i], "("))      { type = ST_LEFT; goto gotit; }
     101    if (!strcmp (argv[i], ")"))      { type = ST_RIGHT; goto gotit; }
    92102
    93103  gotit:
    94104    /* choose how to deal with object */
    95105    switch (type) {
    96       case 8:  /* exponentiation: 2^2^3 = 64 != 256 (precedence is right-to-left, not left-to-right!) */
     106      case ST_POWER:  /* exponentiation: 2^2^3 = 64 != 256 (precedence is right-to-left, not left-to-right!) */
    97107        /* pop previous, higher operators from OP stack to stack */
    98108        for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type > type); j--) {
     
    105115        Nop_stack ++;
    106116        break;
    107       case 9: /* unary OPs */
    108       case 7: /* binary OPs */
    109       case 6:
    110       case 5:
    111       case 4:
    112       case 3:
     117      case ST_UNARY:
     118      case ST_BINARY:
     119      case ST_TRINARY:
     120      case ST_TIMES:
     121      case ST_ADD:
     122      case ST_BITWISE:
     123      case ST_LOGIC:
     124      case ST_AND:
     125      case ST_OR:
    113126        /* pop previous, higher or equal operators from OP stack to stack */
    114127        for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type >= type); j--) {
     
    121134        Nop_stack ++;
    122135        break;
    123       case 2
     136      case ST_LEFT
    124137        /* push operator on OP stack */
    125138        assign_stack (&op_stack[Nop_stack], argv[i], type);
     
    127140        Nop_stack ++;
    128141        break;
    129       case 1:
     142      case ST_RIGHT:
    130143        /* pop rest of operators from OP stack to stack, looking for '(' */
    131         for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != 2); j--) {
    132           move_stack (&stack[Nstack], &op_stack[j]);
    133           Nstack ++;
    134           Nop_stack --;
    135         }
    136         if ((j == -1) || (op_stack[j].type != 2)) {
     144        for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != ST_LEFT); j--) {
     145          move_stack (&stack[Nstack], &op_stack[j]);
     146          Nstack ++;
     147          Nop_stack --;
     148        }
     149        if ((j == -1) || (op_stack[j].type != ST_LEFT)) {
    137150          push_error ("syntax error: mismatched parenthesis");
    138151          Nstack = 0;
     
    144157        Nop_stack --;
    145158        break;
    146       case 0:
     159      case ST_COMMA:
     160        /* pop rest of operators from OP stack to stack, looking for '(' (but do not pop the '(')*/
     161        for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != ST_LEFT) && (op_stack[j].type != ST_TRINARY); j--) {
     162          move_stack (&stack[Nstack], &op_stack[j]);
     163          Nstack ++;
     164          Nop_stack --;
     165        }
     166        break;
     167      case ST_NONE:
    147168        /* place the value (number or vector/matrix name) on stack */
    148169        /* value of 'X' is used as sentinel until we sort out values */
    149         assign_stack (&stack[Nstack], argv[i], 'X');
     170        assign_stack (&stack[Nstack], argv[i], ST_VALUE);
    150171        Nstack ++;
    151172        break;
     173
     174      default:
     175        push_error ("invalid stack typ");
     176        Nstack = 0;
     177        goto cleanup;
    152178    }
    153179  }
    154180
    155   /* dump remaining operators on stack, checking for ')' */
     181  /* dump remaining operators on stack, checking for '(' */
    156182  for (j = Nop_stack - 1; j >= 0; j--) {
    157     if (op_stack[j].type == 2) {
     183    if (op_stack[j].type == ST_LEFT) {
    158184      push_error ("syntax error: mismatched parenthesis");
    159185      Nstack = 0;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/lib.shell/dvomath.c

    r31635 r36680  
    8080        sprintf (outname, "%s", stack[0].name);
    8181      } else {
    82         if (stack[0].type == 's') {
     82        if (stack[0].type == ST_SCALAR_INT) {
    8383          sprintf (outname, "%d", stack[0].IntValue);
    8484        } else {
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/lib.shell/evaluate_stack.c

    r34088 r36680  
    22# define VERBOSE 0
    33
    4 # define TWO_OP(A,B,FUNC) \
    5   if (!strncasecmp (&stack[i - 2].type, A, 1) && !strncasecmp (&stack[i - 1].type, B, 1)) \
    6     status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
    7 
    8 # define ONE_OP(A,FUNC) \
    9   if (!strncasecmp (&stack[i - 1].type, A, 1)) \
    10     status = FUNC (&tmp_stack, &stack[i - 1], stack[i].name);
     4// all three operands must have the same type
     5# define THREE_OP(A,FUNC)                                               \
     6  if ((stack[i - 3].type == A) && (stack[i - 2].type == A) && (stack[i - 1].type == A)) { \
     7    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     8    goto got_three_op; } \
     9  if ((stack[i - 3].type == A+1) && (stack[i - 2].type == A) && (stack[i - 1].type == A)) { \
     10    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     11    goto got_three_op; } \
     12  if ((stack[i - 3].type == A) && (stack[i - 2].type == A+1) && (stack[i - 1].type == A)) { \
     13    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     14    goto got_three_op; } \
     15  if ((stack[i - 3].type == A+1) && (stack[i - 2].type == A+1) && (stack[i - 1].type == A)) { \
     16    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     17    goto got_three_op; } \
     18  if ((stack[i - 3].type == A) && (stack[i - 2].type == A) && (stack[i - 1].type == A+1)) { \
     19    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     20    goto got_three_op; } \
     21  if ((stack[i - 3].type == A+1) && (stack[i - 2].type == A) && (stack[i - 1].type == A+1)) { \
     22    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     23    goto got_three_op; } \
     24  if ((stack[i - 3].type == A) && (stack[i - 2].type == A+1) && (stack[i - 1].type == A+1)) { \
     25    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     26    goto got_three_op; } \
     27  if ((stack[i - 3].type == A+1) && (stack[i - 2].type == A+1) && (stack[i - 1].type == A+1)) { \
     28    status = FUNC (&tmp_stack, &stack[i - 3], &stack[i - 2], &stack[i - 1], stack[i].name); \
     29    goto got_three_op; } \
     30
     31// A & B value types all have 2 possible values
     32# define TWO_OP(A,B,FUNC) {                                             \
     33    if ((stack[i - 2].type == A) && (stack[i - 1].type == B)) {         \
     34      status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); \
     35      goto got_two_op; }                                                \
     36    if ((stack[i - 2].type == A+1) && (stack[i - 1].type == B)) {       \
     37      status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); \
     38      goto got_two_op; }                                                \
     39    if ((stack[i - 2].type == A) && (stack[i - 1].type == B+1)) {       \
     40      status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); \
     41      goto got_two_op; }                                                \
     42    if ((stack[i - 2].type == A+1) && (stack[i - 1].type == B+1)) {     \
     43      status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name); \
     44      goto got_two_op; } \
     45  }
     46
     47# define ONE_OP(A,FUNC)                                         \
     48  if (stack[i - 1].type == A) {                                 \
     49    status = FUNC (&tmp_stack, &stack[i - 1], stack[i].name);   \
     50    goto got_one_op; }
    1151
    1252int evaluate_stack (StackVar *stack, int *Nstack) {
     
    2060
    2161  if (*Nstack == 1) {
    22     if ((stack[0].type == 'S') || (stack[0].type == 's')) {
     62    if ((stack[0].type == ST_SCALAR_INT) || (stack[0].type == ST_SCALAR_FLT)) {
    2363      clear_stack (&tmp_stack);
    2464      return (TRUE);
    2565    }
    26     if (stack[0].type == 'V') {
     66    if (stack[0].type == ST_VECTOR) {
    2767      /* need to make a copy so we set output value? */
    2868      V_unary (&tmp_stack, &stack[0], "=");
     
    3070      return (TRUE);
    3171    }
    32     if (stack[0].type == 'M') {
     72    if (stack[0].type == ST_MATRIX) {
    3373      /* need to make a copy so we set output value? */
    3474      M_unary (&tmp_stack, &stack[0], "=");
     
    5696    }
    5797
    58     /***** binary operators *****/
    59     if ((stack[i].type >= 3) && (stack[i].type <= 8)) {
    60 
    61       if (i < 2) {  /* need two variables to operate on */
    62         sprintf (line, "syntax error: binary operator with one operand: %s\n", stack[i].name);
     98    /***** trinary operators *****/
     99    switch (stack[i].type) {
     100      case ST_TRINARY:
     101
     102        if (i < 3) {  /* need two variables to operate on */
     103          snprintf (line, 512, "syntax error: trinary operator without three operands: %s\n", stack[i].name);
     104          push_error (line);
     105          clear_stack (&tmp_stack);
     106          return (FALSE);
     107        }
     108
     109        status = FALSE;
     110        THREE_OP (ST_MATRIX,MMM_trinary);
     111        THREE_OP (ST_VECTOR,VVV_trinary);
     112
     113        THREE_OP (ST_SCALAR_FLT,SSS_trinary);
     114        THREE_OP (ST_SCALAR_INT,SSS_trinary);
     115
     116        /* there are no valid unary string operators */
     117        push_error ("invalid operands for trinary operator (mismatch types?)");
     118        clear_stack (&tmp_stack);
     119        return (FALSE);
     120
     121      got_three_op:
     122        if (!status) {
     123          snprintf (line, 512, "syntax error: invalid operand for binary operation: %s or %s or %s\n", stack[i-1].name, stack[i-2].name, stack[i-3].name);
     124          push_error (line);
     125          clear_stack (&tmp_stack);
     126          return (FALSE);
     127        }
     128        move_stack (&stack[i-3], &tmp_stack);
     129        delete_stack (&stack[i-2], 3);
     130        for (j = i + 1; j < *Nstack; j++) {
     131          move_stack (&stack[j-3], &stack[j]);
     132        }
     133        *Nstack -= 3;
     134        i -= 3;
     135        init_stack (&tmp_stack);
     136        continue;
     137
     138        /***** binary operators *****/
     139      case ST_OR:
     140      case ST_AND:
     141      case ST_LOGIC:
     142      case ST_BITWISE:
     143      case ST_ADD:
     144      case ST_TIMES:
     145      case ST_POWER:
     146      case ST_BINARY:
     147
     148        if (i < 2) {  /* need two variables to operate on */
     149          snprintf (line, 512, "syntax error: binary operator with one operand: %s\n", stack[i].name);
     150          push_error (line);
     151          clear_stack (&tmp_stack);
     152          return (FALSE);
     153        }
     154
     155        status = FALSE;
     156        TWO_OP (ST_MATRIX,ST_MATRIX,MM_binary);
     157        TWO_OP (ST_MATRIX,ST_VECTOR,MV_binary);
     158        TWO_OP (ST_MATRIX,ST_SCALAR_INT,MS_binary);
     159
     160        TWO_OP (ST_VECTOR,ST_MATRIX,VM_binary);
     161        TWO_OP (ST_VECTOR,ST_VECTOR,VV_binary);
     162        TWO_OP (ST_VECTOR,ST_SCALAR_INT,VS_binary);
     163
     164        TWO_OP (ST_SCALAR_INT,ST_MATRIX,SM_binary);
     165        TWO_OP (ST_SCALAR_INT,ST_VECTOR,SV_binary);
     166        TWO_OP (ST_SCALAR_INT,ST_SCALAR_INT,SS_binary);     
     167
     168        TWO_OP (ST_SCALAR_FLT,ST_MATRIX,SM_binary);
     169        TWO_OP (ST_SCALAR_FLT,ST_VECTOR,SV_binary);
     170        TWO_OP (ST_SCALAR_FLT,ST_SCALAR_INT,SS_binary);     
     171
     172        TWO_OP (ST_STRING,ST_STRING,WW_binary);     
     173        TWO_OP (ST_STRING,ST_SCALAR_INT,WW_binary);     
     174        TWO_OP (ST_SCALAR_INT,ST_STRING,WW_binary);     
     175     
     176      got_two_op:
     177        if (!status) {
     178          snprintf (line, 512, "syntax error: invalid operand for binary operation: %s or %s\n", stack[i-1].name, stack[i-2].name);
     179          push_error (line);
     180          clear_stack (&tmp_stack);
     181          return (FALSE);
     182        }
     183        move_stack (&stack[i-2], &tmp_stack);
     184        delete_stack (&stack[i-1], 2);
     185        for (j = i + 1; j < *Nstack; j++) {
     186          move_stack (&stack[j - 2], &stack[j]);
     187        }
     188        *Nstack -= 2;
     189        i -= 2;
     190        init_stack (&tmp_stack);
     191        continue;
     192
     193        /***** unary operators **/
     194      case ST_UNARY:
     195
     196        if (i < 1) {  /* need one variable to operate on */
     197          push_error ("syntax error: unary operator with no operand");
     198          clear_stack (&tmp_stack);
     199          return (FALSE);
     200        }
     201
     202        ONE_OP (ST_MATRIX, M_unary);
     203        ONE_OP (ST_MATRIX_TMP, M_unary);
     204
     205        ONE_OP (ST_VECTOR, V_unary);
     206        ONE_OP (ST_VECTOR_TMP, V_unary);
     207
     208        ONE_OP (ST_SCALAR_INT, S_unary);
     209        ONE_OP (ST_SCALAR_FLT, S_unary);
     210
     211        /* there are no valid unary string operators */
     212        push_error ("syntax error: no valid string unary ops");
     213        clear_stack (&tmp_stack);
     214        return (FALSE);
     215
     216      got_one_op:
     217        move_stack (&stack[i-1], &tmp_stack);
     218        delete_stack (&stack[i], 1);
     219        for (j = i + 1; j < *Nstack; j++) {
     220          move_stack (&stack[j - 1], &stack[j]);
     221        }
     222        init_stack (&tmp_stack);
     223        *Nstack -= 1;
     224        i -= 1;
     225        continue;
     226
     227      case ST_SCALAR_INT:
     228      case ST_SCALAR_FLT:
     229      case ST_VECTOR:
     230      case ST_VECTOR_TMP:
     231      case ST_MATRIX:
     232      case ST_MATRIX_TMP:
     233      case ST_STRING:
     234        continue;
     235
     236      default:
     237        snprintf (line, 512, "syntax error: unexpected operator type %s", stack[i].name);
    63238        push_error (line);
    64239        clear_stack (&tmp_stack);
    65240        return (FALSE);
    66       }
    67 
    68       status = FALSE;
    69       TWO_OP ("M","M",MM_binary);
    70       TWO_OP ("M","V",MV_binary);
    71       TWO_OP ("M","S",MS_binary);
    72       TWO_OP ("V","M",VM_binary);
    73       TWO_OP ("V","V",VV_binary);
    74       TWO_OP ("V","S",VS_binary);
    75       TWO_OP ("S","M",SM_binary);
    76       TWO_OP ("S","V",SV_binary);
    77       TWO_OP ("S","S",SS_binary);     
    78       TWO_OP ("W","W",WW_binary);     
    79       TWO_OP ("W","S",WW_binary);     
    80       TWO_OP ("S","W",WW_binary);     
    81      
    82       if (!status) {
    83         sprintf (line, "syntax error: invalid operand for binary operation: %s or %s\n", stack[i-1].name, stack[i-2].name);
    84         push_error (line);
    85         clear_stack (&tmp_stack);
    86         return (FALSE);
    87       }
    88       move_stack (&stack[i-2], &tmp_stack);
    89       delete_stack (&stack[i-1], 2);
    90       for (j = i + 1; j < *Nstack; j++) {
    91         move_stack (&stack[j - 2], &stack[j]);
    92       }
    93       *Nstack -= 2;
    94       i -= 2;
    95       init_stack (&tmp_stack);
    96       continue;
    97     }
    98 
    99     /***** unary operators **/
    100     if (stack[i].type == 9) {
    101 
    102       if (i < 1) {  /* need one variable to operate on */
    103         push_error ("syntax error: unary operator with no operand");
    104         clear_stack (&tmp_stack);
    105         return (FALSE);
    106       }
    107 
    108       ONE_OP ("M", M_unary);
    109       ONE_OP ("V", V_unary);
    110       ONE_OP ("S", S_unary);
    111 
    112       /* there are no valid unary string operators */
    113       if (!strncasecmp (&stack[i - 1].type, "W", 1)) {
    114         push_error ("syntax error: no valid string unary ops");
    115         clear_stack (&tmp_stack);
    116         return (FALSE);
    117       }
    118 
    119       move_stack (&stack[i-1], &tmp_stack);
    120       delete_stack (&stack[i], 1);
    121       for (j = i + 1; j < *Nstack; j++) {
    122         move_stack (&stack[j - 1], &stack[j]);
    123       }
    124       init_stack (&tmp_stack);
    125       *Nstack -= 1;
    126       i -= 1;
    127       continue;
    128     }
     241    }
    129242  }
    130243  clear_stack (&tmp_stack);
     
    160273
    161274  for (i = 0; i < Nstack; i++) {
    162     if (IsBufferPtr (stack[i].buffer) && (stack[i].type == 'm')) {
     275    if (IsBufferPtr (stack[i].buffer) && (stack[i].type == ST_MATRIX_TMP)) {
    163276      if (VERBOSE) gprint (GP_ERR, "free %s (buff) (%lx)\n", stack[i].name, (long) stack[i].buffer);
    164277      free (stack[i].buffer[0].header.buffer);
     
    167280      stack[i].buffer = NULL;
    168281    }   
    169     if (IsVectorPtr (stack[i].vector) && (stack[i].type == 'v')) {
     282    if (IsVectorPtr (stack[i].vector) && (stack[i].type == ST_VECTOR_TMP)) {
    170283      if (VERBOSE) gprint (GP_ERR, "free %s (vect) (%lx)\n", stack[i].name, (long) stack[i].vector);
    171284      free (stack[i].vector[0].elements.Ptr);
     
    193306}
    194307
    195 void assign_stack (StackVar *stack, char *name, int type) {
     308void assign_stack (StackVar *stack, char *name, StackVarType type) {
    196309  stack->name = strcreate (name);
    197310  stack->type = type;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/lib.shell/stack_math.c

    r34342 r36680  
    66*/
    77
    8 // XXX we temporarily drop the concept of using one of the temporary input vectors for
    9 // the output vector (thus saving an ALLOC): we have to juggle the size of the input vectors
    10 // as well as their temporary state
    11 
    12 int VV_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) {
     8int SSS_trinary (StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op) {
     9
     10  char line[512]; // this is only used to report an error
     11 
     12  // set up the possible operations : int OP int -> int, all else yield float
     13  // OP is the operation performed on *M1 and *M2
     14# define SSS_FUNC(OP) {                                         \
     15    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT) && (V3->type == ST_SCALAR_FLT)) { \
     16      opihi_flt M1  =  V1[0].FltValue;                  \
     17      opihi_flt M2  =  V2[0].FltValue;                  \
     18      opihi_flt M3  =  V3[0].FltValue;                  \
     19      OUT[0].type = ST_SCALAR_FLT;                      \
     20      OUT[0].FltValue = OP;                                                     \
     21      break;                                                            \
     22    }                                                                   \
     23    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT) && (V3->type == ST_SCALAR_INT)) { \
     24      opihi_int M1  =  V1[0].IntValue;                  \
     25      opihi_int M2  =  V2[0].IntValue;                  \
     26      opihi_int M3  =  V3[0].IntValue;                  \
     27      OUT[0].type = ST_SCALAR_INT;                      \
     28      OUT[0].IntValue = OP;                                                     \
     29      break;                                                            \
     30    }                                                                   \
     31  }
     32
     33  switch (op[0]) {
     34    case '?': SSS_FUNC(M1 ? M2: M3);
     35    default:
     36      snprintf (line, 512, "error: op %c not defined!", op[0]);
     37      push_error (line);
     38      return (FALSE);
     39  }
     40# undef SSS_FUNC
     41
     42  clear_stack (V1);
     43  clear_stack (V2);
     44  clear_stack (V3);
     45  return (TRUE);
     46
     47}
     48
     49int VVV_trinary (StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op) {
    1350
    1451  int i, Nx;
     
    1956    return (FALSE);
    2057  }
     58  if (V1[0].vector[0].Nelements != V3[0].vector[0].Nelements) {
     59    return (FALSE);
     60  }
    2161
    2262  Nx = V1[0].vector[0].Nelements;
     
    2464  // create the output vector guaranteed to be temporary until the very end
    2565  OUT[0].vector = InitVector ();
    26   OUT[0].type = 'v';
     66  OUT[0].type = ST_VECTOR_TMP;
     67
     68  // set up the possible operations : int OP int -> int, all else yield float
     69  // OP is the operation performed on *M1 and *M2
     70# define VVV_FUNC(OP) {                                         \
     71    if ((V1->vector->type == OPIHI_FLT) && (V2->vector->type == OPIHI_FLT) && (V3->vector->type == OPIHI_FLT)) { \
     72      CopyVector (OUT[0].vector, V1[0].vector);                         \
     73      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;                   \
     74      opihi_flt *M2  =  V2[0].vector[0].elements.Flt;                   \
     75      opihi_flt *M3  =  V3[0].vector[0].elements.Flt;                   \
     76      opihi_flt *out = OUT[0].vector[0].elements.Flt;                   \
     77      for (i = 0; i < Nx; i++, out++, M1++, M2++, M3++) {               \
     78        *out = OP;                                                      \
     79      }                                                                 \
     80      break;                                                            \
     81    }                                                                   \
     82    if ((V1->vector->type == OPIHI_INT) && (V2->vector->type == OPIHI_INT) && (V3->vector->type == OPIHI_INT)) { \
     83      CopyVector (OUT[0].vector, V1[0].vector);                         \
     84      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     85      opihi_int *M2  =  V2[0].vector[0].elements.Int;                   \
     86      opihi_int *M3  =  V3[0].vector[0].elements.Int;                   \
     87      opihi_int *out = OUT[0].vector[0].elements.Int;                   \
     88      for (i = 0; i < Nx; i++, out++, M1++, M2++, M3++) {               \
     89        *out = OP;                                                      \
     90      }                                                                 \
     91      break;                                                            \
     92    }                                                                   \
     93  }
     94
     95  switch (op[0]) {
     96    case '?': VVV_FUNC(*M1 ? *M2: *M3);
     97    default:
     98      snprintf (line, 512, "error: op %c not defined!", op[0]);
     99      push_error (line);
     100      return (FALSE);
     101  }
     102# undef VVV_FUNC
     103
     104  /** free up any temporary buffers: **/
     105
     106  if (V1[0].type == ST_VECTOR_TMP) {
     107    free (V1[0].vector[0].elements.Ptr);
     108    free (V1[0].vector);
     109  }
     110  if (V2[0].type == ST_VECTOR_TMP) {
     111    free (V2[0].vector[0].elements.Ptr);
     112    free (V2[0].vector);
     113  }
     114  if (V3[0].type == ST_VECTOR_TMP) {
     115    free (V3[0].vector[0].elements.Ptr);
     116    free (V3[0].vector);
     117  }
     118  /* at the end, V1 and V2 are deleted only if they were temporary */
     119
     120  clear_stack (V1);
     121  clear_stack (V2);
     122  clear_stack (V3);
     123  return (TRUE);
     124
     125}
     126
     127int MMM_trinary (StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op) {
     128
     129  int i, Nx, Ny;
     130  float *out, *M1, *M2, *M3;
     131  char line[512]; // this is only used to report an error
     132 
     133  Nx = V1[0].buffer[0].matrix.Naxis[0];
     134  Ny = V1[0].buffer[0].matrix.Naxis[1];
     135
     136  if (V1[0].type == ST_MATRIX_TMP) {  /** use V1 as temp buffer **/
     137    OUT[0].buffer = V1[0].buffer;
     138    V1[0].type = ST_MATRIX; /* prevent it from being freed below */
     139  } else {
     140    if (V2[0].type == ST_MATRIX_TMP) { /** use V2 as temp buffer, but header of V1 **/
     141      OUT[0].buffer = V2[0].buffer;
     142      V2[0].type = ST_MATRIX; /* prevent it from being freed below */
     143    } else {  /* no spare temp buffer */
     144      OUT[0].buffer = InitBuffer ();
     145      CopyBuffer (OUT[0].buffer, V1[0].buffer);
     146    }
     147  }
     148  OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/
     149
     150  M1  = (float *)V1[0].buffer[0].matrix.buffer;
     151  M2  = (float *)V2[0].buffer[0].matrix.buffer;
     152  M3  = (float *)V3[0].buffer[0].matrix.buffer;
     153  out = (float *)OUT[0].buffer[0].matrix.buffer;
     154
     155# define MMM_FUNC(OP)                                   \
     156  for (i = 0; i < Nx*Ny; i++, out++, M1++, M2++, M3++) {        \
     157    *out = OP;                                          \
     158  }                                                     \
     159  break;
     160
     161  switch (op[0]) {
     162    case '?': MMM_FUNC(*M1 ? *M2: *M3);
     163    default:
     164      snprintf (line, 512, "error: op %c not defined!", op[0]);
     165      push_error (line);
     166      return (FALSE);
     167  }
     168# undef MMM_FUNC
     169
     170  /** free up any temporary buffers: **/
     171
     172  if (V1[0].type == ST_MATRIX_TMP) {
     173    free (V1[0].buffer[0].header.buffer);
     174    free (V1[0].buffer[0].matrix.buffer);
     175    free (V1[0].buffer);
     176  }
     177  if (V2[0].type == ST_MATRIX_TMP) {
     178    free (V2[0].buffer[0].header.buffer);
     179    free (V2[0].buffer[0].matrix.buffer);
     180    free (V2[0].buffer);
     181  }
     182  if (V3[0].type == ST_MATRIX_TMP) {
     183    free (V3[0].buffer[0].header.buffer);
     184    free (V3[0].buffer[0].matrix.buffer);
     185    free (V3[0].buffer);
     186  }
     187
     188  /* at the end, V1 and V2 are deleted only if they were temporary */
     189
     190  clear_stack (V1);
     191  clear_stack (V2);
     192  clear_stack (V3);
     193  return (TRUE);
     194
     195}
     196
     197// XXX we temporarily drop the concept of using one of the temporary input vectors for
     198// the output vector (thus saving an ALLOC): we have to juggle the size of the input vectors
     199// as well as their temporary state
     200
     201int VV_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) {
     202
     203  int i, Nx;
     204  char line[512]; // this is only used to report an error
     205 
     206  // the vectors have to match in length
     207  if (V1[0].vector[0].Nelements != V2[0].vector[0].Nelements) {
     208    return (FALSE);
     209  }
     210
     211  Nx = V1[0].vector[0].Nelements;
     212
     213  // create the output vector guaranteed to be temporary until the very end
     214  OUT[0].vector = InitVector ();
     215  OUT[0].type = ST_VECTOR_TMP;
    27216
    28217  // set up the possible operations : int OP int -> int, all else yield float
     
    59248      break;                                                            \
    60249    }                                                                   \
    61     if ((FTYPE == 'S') && (V1->vector->type != OPIHI_FLT) && (V2->vector->type != OPIHI_FLT)) { \
     250    if ((FTYPE == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT) && (V2->vector->type != OPIHI_FLT)) { \
    62251      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);             \
    63252      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    82271
    83272  switch (op[0]) {
    84     case '+': VV_FUNC('s', *M1 + *M2);
    85     case '-': VV_FUNC('s', *M1 - *M2);
    86     case '*': VV_FUNC('s', *M1 * *M2);
    87     case '/': VV_FUNC('S', *M1 / (opihi_flt) *M2);
    88     case '%': VV_FUNC('s', (long long)*M1 % (long long)*M2);
    89     case '^': VV_FUNC('S', pow (*M1, *M2));
    90     case '@': VV_FUNC('S', DEG_RAD*atan2 (*M1, *M2));
    91     case 'D': VV_FUNC('s', MIN (*M1, *M2));
    92     case 'U': VV_FUNC('s', MAX (*M1, *M2));
    93     case '<': VV_FUNC('s', (*M1 < *M2) ? 1 : 0);
    94     case '>': VV_FUNC('s', (*M1 > *M2) ? 1 : 0);
    95     case '&': VV_FUNC('s', ((long long)*M1 & (long long)*M2));
    96     case '|': VV_FUNC('s', ((long long)*M1 | (long long)*M2));
    97     case 'E': VV_FUNC('s', (*M1 == *M2) ? 1 : 0);
    98     case 'N': VV_FUNC('s', (*M1 != *M2) ? 1 : 0);
    99     case 'L': VV_FUNC('s', (*M1 <= *M2) ? 1 : 0);
    100     case 'G': VV_FUNC('s', (*M1 >= *M2) ? 1 : 0);
    101     case 'A': VV_FUNC('s', (*M1 && *M2) ? 1 : 0);
    102     case 'O': VV_FUNC('s', (*M1 || *M2) ? 1 : 0);
     273    case '+': VV_FUNC(ST_SCALAR_INT, *M1 + *M2);
     274    case '-': VV_FUNC(ST_SCALAR_INT, *M1 - *M2);
     275    case '*': VV_FUNC(ST_SCALAR_INT, *M1 * *M2);
     276    case '/': VV_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) *M2);
     277    case '%': VV_FUNC(ST_SCALAR_INT, (long long)*M1 % (long long)*M2);
     278    case '^': VV_FUNC(ST_SCALAR_FLT, pow (*M1, *M2));
     279    case '@': VV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, *M2));
     280    case 'a': VV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, *M2));
     281    case 'D': VV_FUNC(ST_SCALAR_INT, MIN (*M1, *M2));
     282    case 'U': VV_FUNC(ST_SCALAR_INT, MAX (*M1, *M2));
     283    case '<': VV_FUNC(ST_SCALAR_INT, (*M1 < *M2) ? 1 : 0);
     284    case '>': VV_FUNC(ST_SCALAR_INT, (*M1 > *M2) ? 1 : 0);
     285    case '&': VV_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)*M2));
     286    case '|': VV_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)*M2));
     287    case 'E': VV_FUNC(ST_SCALAR_INT, (*M1 == *M2) ? 1 : 0);
     288    case 'N': VV_FUNC(ST_SCALAR_INT, (*M1 != *M2) ? 1 : 0);
     289    case 'L': VV_FUNC(ST_SCALAR_INT, (*M1 <= *M2) ? 1 : 0);
     290    case 'G': VV_FUNC(ST_SCALAR_INT, (*M1 >= *M2) ? 1 : 0);
     291    case 'A': VV_FUNC(ST_SCALAR_INT, (*M1 && *M2) ? 1 : 0);
     292    case 'O': VV_FUNC(ST_SCALAR_INT, (*M1 || *M2) ? 1 : 0);
    103293    default:
    104       sprintf (line, "error: op %c not defined!", op[0]);
     294      snprintf (line, 512, "error: op %c not defined!", op[0]);
    105295      push_error (line);
    106296      return (FALSE);
     
    110300  /** free up any temporary buffers: **/
    111301
    112   if (V1[0].type == 'v') {
     302  if (V1[0].type == ST_VECTOR_TMP) {
    113303    free (V1[0].vector[0].elements.Ptr);
    114304    free (V1[0].vector);
    115305  }
    116   if (V2[0].type == 'v') {
     306  if (V2[0].type == ST_VECTOR_TMP) {
    117307    free (V2[0].vector[0].elements.Ptr);
    118308    free (V2[0].vector);
     
    134324
    135325  OUT[0].vector = InitVector ();
    136   OUT[0].type = 'v';   /*** <<--- says this is a temporary matrix ***/
     326  OUT[0].type = ST_VECTOR_TMP;   /*** <<--- says this is a temporary matrix ***/
    137327
    138328  // set up the possible operations : int OP int -> int, all else yield float
    139329  // OP is the operation performed on *M1 and *M2
    140330# define SV_FUNC(FTYPE,OP) {                                            \
    141     if ((V1->type == 'S') && (V2->vector->type == OPIHI_FLT)) {         \
     331    if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type == OPIHI_FLT)) {               \
    142332      CopyVector (OUT[0].vector, V2[0].vector);                         \
    143333      opihi_flt  M1  =  V1[0].FltValue;                                 \
     
    149339      break;                                                            \
    150340    }                                                                   \
    151     if ((V1->type == 'S') && (V2->vector->type != OPIHI_FLT)) {         \
     341    if ((V1->type == ST_SCALAR_FLT) && (V2->vector->type != OPIHI_FLT)) {               \
    152342      MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT);             \
    153343      opihi_flt  M1  =  V1[0].FltValue;                                 \
     
    159349      break;                                                            \
    160350    }                                                                   \
    161     if ((V1->type == 's') && (V2->vector->type == OPIHI_FLT)) {         \
     351    if ((V1->type == ST_SCALAR_INT) && (V2->vector->type == OPIHI_FLT)) {               \
    162352      CopyVector (OUT[0].vector, V2[0].vector);                         \
    163353      opihi_int  M1  =  V1[0].IntValue;                                 \
     
    169359      break;                                                            \
    170360    }                                                                   \
    171     if ((FTYPE == 'S') && (V1->type == 's') && (V2->vector->type != OPIHI_FLT)) { \
     361    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) { \
    172362      MatchVector (OUT[0].vector, V2[0].vector, OPIHI_FLT);             \
    173363      opihi_int  M1  =  V1[0].IntValue;                                 \
     
    179369      break;                                                            \
    180370    }                                                                   \
    181     if ((V1->type == 's') && (V2->vector->type != OPIHI_FLT)) {         \
     371    if ((V1->type == ST_SCALAR_INT) && (V2->vector->type != OPIHI_FLT)) {               \
    182372      CopyVector (OUT[0].vector, V2[0].vector);                         \
    183373      opihi_int  M1  =  V1[0].IntValue;                                 \
     
    192382
    193383  switch (op[0]) {
    194     case '+': SV_FUNC('s', M1 + *M2);
    195     case '-': SV_FUNC('s', M1 - *M2);
    196     case '*': SV_FUNC('s', M1 * *M2);
    197     case '/': SV_FUNC('S', M1 / (opihi_flt) *M2);
    198     case '%': SV_FUNC('s', (long long) M1 % (long long) *M2);
    199     case '^': SV_FUNC('S', pow (M1, *M2));
    200     case '@': SV_FUNC('S', DEG_RAD*atan2 (M1, *M2));
    201     case 'D': SV_FUNC('s', MIN (M1, *M2));
    202     case 'U': SV_FUNC('s', MAX (M1, *M2));
    203     case '<': SV_FUNC('s', (M1 < *M2) ? 1 : 0);
    204     case '>': SV_FUNC('s', (M1 > *M2) ? 1 : 0);
    205     case '&': SV_FUNC('s', ((long long)M1 & (long long)*M2));
    206     case '|': SV_FUNC('s', ((long long)M1 | (long long)*M2));
    207     case 'E': SV_FUNC('s', (M1 == *M2) ? 1 : 0);
    208     case 'N': SV_FUNC('s', (M1 != *M2) ? 1 : 0);
    209     case 'L': SV_FUNC('s', (M1 <= *M2) ? 1 : 0);
    210     case 'G': SV_FUNC('s', (M1 >= *M2) ? 1 : 0);
    211     case 'A': SV_FUNC('s', (M1 && *M2) ? 1 : 0);
    212     case 'O': SV_FUNC('s', (M1 || *M2) ? 1 : 0);
     384    case '+': SV_FUNC(ST_SCALAR_INT, M1 + *M2);
     385    case '-': SV_FUNC(ST_SCALAR_INT, M1 - *M2);
     386    case '*': SV_FUNC(ST_SCALAR_INT, M1 * *M2);
     387    case '/': SV_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) *M2);
     388    case '%': SV_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) *M2);
     389    case '^': SV_FUNC(ST_SCALAR_FLT, pow (M1, *M2));
     390    case '@': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
     391    case 'a': SV_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, *M2));
     392    case 'D': SV_FUNC(ST_SCALAR_INT, MIN (M1, *M2));
     393    case 'U': SV_FUNC(ST_SCALAR_INT, MAX (M1, *M2));
     394    case '<': SV_FUNC(ST_SCALAR_INT, (M1 < *M2) ? 1 : 0);
     395    case '>': SV_FUNC(ST_SCALAR_INT, (M1 > *M2) ? 1 : 0);
     396    case '&': SV_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)*M2));
     397    case '|': SV_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)*M2));
     398    case 'E': SV_FUNC(ST_SCALAR_INT, (M1 == *M2) ? 1 : 0);
     399    case 'N': SV_FUNC(ST_SCALAR_INT, (M1 != *M2) ? 1 : 0);
     400    case 'L': SV_FUNC(ST_SCALAR_INT, (M1 <= *M2) ? 1 : 0);
     401    case 'G': SV_FUNC(ST_SCALAR_INT, (M1 >= *M2) ? 1 : 0);
     402    case 'A': SV_FUNC(ST_SCALAR_INT, (M1 && *M2) ? 1 : 0);
     403    case 'O': SV_FUNC(ST_SCALAR_INT, (M1 || *M2) ? 1 : 0);
    213404    default:
    214       sprintf (line, "error: op %c not defined!", op[0]);
     405      snprintf (line, 512, "error: op %c not defined!", op[0]);
    215406      push_error (line);
    216407      return (FALSE);
     
    219410
    220411  /** free up any temporary buffers: **/
    221   if (V2[0].type == 'v') {
     412  if (V2[0].type == ST_VECTOR_TMP) {
    222413    free (V2[0].vector[0].elements.Ptr);
    223414    free (V2[0].vector);
     
    240431
    241432  OUT[0].vector = InitVector ();
    242   OUT[0].type = 'v';   /*** <<--- says this is a temporary matrix ***/
     433  OUT[0].type = ST_VECTOR_TMP;   /*** <<--- says this is a temporary matrix ***/
    243434
    244435  // set up the possible operations : int OP int -> int, all else yield float
    245436  // OP is the operation performed on *M1 and *M2
    246437# define VS_FUNC(FTYPE,OP) {                                            \
    247     if ((V2->type == 'S') && (V1->vector->type == OPIHI_FLT)) {         \
     438    if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type == OPIHI_FLT)) {               \
    248439      CopyVector (OUT[0].vector, V1[0].vector);                         \
    249440      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;                   \
     
    255446      break;                                                            \
    256447    }                                                                   \
    257     if ((V2->type == 'S') && (V1->vector->type != OPIHI_FLT)) {         \
     448    if ((V2->type == ST_SCALAR_FLT) && (V1->vector->type != OPIHI_FLT)) {               \
    258449      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);             \
    259450      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    265456      break;                                                            \
    266457    }                                                                   \
    267     if ((V2->type == 's') && (V1->vector->type == OPIHI_FLT)) {         \
     458    if ((V2->type == ST_SCALAR_INT) && (V1->vector->type == OPIHI_FLT)) {               \
    268459      CopyVector (OUT[0].vector, V1[0].vector);                         \
    269460      opihi_flt *M1  =  V1[0].vector[0].elements.Flt;                   \
     
    275466      break;                                                            \
    276467    }                                                                   \
    277     if ((FTYPE == 'S') && (V2->type == 's') && (V1->vector->type != OPIHI_FLT)) { \
     468    if ((FTYPE == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) { \
    278469      CopyVector (OUT[0].vector, V1[0].vector);                         \
    279470      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    285476      break;                                                            \
    286477    }                                                                   \
    287     if ((V2->type == 's') && (V1->vector->type != OPIHI_FLT)) {         \
     478    if ((V2->type == ST_SCALAR_INT) && (V1->vector->type != OPIHI_FLT)) {               \
    288479      CopyVector (OUT[0].vector, V1[0].vector);                         \
    289480      opihi_int *M1  =  V1[0].vector[0].elements.Int;                   \
     
    298489
    299490  switch (op[0]) {
    300     case '+': VS_FUNC('s', *M1 + M2);
    301     case '-': VS_FUNC('s', *M1 - M2);
    302     case '*': VS_FUNC('s', *M1 * M2);
    303     case '/': VS_FUNC('S', *M1 / (opihi_flt) M2);
    304     case '%': VS_FUNC('s', (long long) *M1 % (long long) M2);
    305     case '^': VS_FUNC('S', pow (*M1, M2));
    306     case '@': VS_FUNC('S', DEG_RAD*atan2 (*M1, M2));
    307     case 'D': VS_FUNC('s', MIN (*M1, M2));
    308     case 'U': VS_FUNC('s', MAX (*M1, M2));
    309     case '<': VS_FUNC('s', (*M1 < M2) ? 1 : 0);
    310     case '>': VS_FUNC('s', (*M1 > M2) ? 1 : 0);
    311     case '&': VS_FUNC('s', ((long long)*M1 & (long long)M2));
    312     case '|': VS_FUNC('s', ((long long)*M1 | (long long)M2));
    313     case 'E': VS_FUNC('s', (*M1 == M2) ? 1 : 0);
    314     case 'N': VS_FUNC('s', (*M1 != M2) ? 1 : 0);
    315     case 'L': VS_FUNC('s', (*M1 <= M2) ? 1 : 0);
    316     case 'G': VS_FUNC('s', (*M1 >= M2) ? 1 : 0);
    317     case 'A': VS_FUNC('s', (*M1 && M2) ? 1 : 0);
    318     case 'O': VS_FUNC('s', (*M1 || M2) ? 1 : 0);
     491    case '+': VS_FUNC(ST_SCALAR_INT, *M1 + M2);
     492    case '-': VS_FUNC(ST_SCALAR_INT, *M1 - M2);
     493    case '*': VS_FUNC(ST_SCALAR_INT, *M1 * M2);
     494    case '/': VS_FUNC(ST_SCALAR_FLT, *M1 / (opihi_flt) M2);
     495    case '%': VS_FUNC(ST_SCALAR_INT, (long long) *M1 % (long long) M2);
     496    case '^': VS_FUNC(ST_SCALAR_FLT, pow (*M1, M2));
     497    case '@': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
     498    case 'a': VS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (*M1, M2));
     499    case 'D': VS_FUNC(ST_SCALAR_INT, MIN (*M1, M2));
     500    case 'U': VS_FUNC(ST_SCALAR_INT, MAX (*M1, M2));
     501    case '<': VS_FUNC(ST_SCALAR_INT, (*M1 < M2) ? 1 : 0);
     502    case '>': VS_FUNC(ST_SCALAR_INT, (*M1 > M2) ? 1 : 0);
     503    case '&': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 & (long long)M2));
     504    case '|': VS_FUNC(ST_SCALAR_INT, ((long long)*M1 | (long long)M2));
     505    case 'E': VS_FUNC(ST_SCALAR_INT, (*M1 == M2) ? 1 : 0);
     506    case 'N': VS_FUNC(ST_SCALAR_INT, (*M1 != M2) ? 1 : 0);
     507    case 'L': VS_FUNC(ST_SCALAR_INT, (*M1 <= M2) ? 1 : 0);
     508    case 'G': VS_FUNC(ST_SCALAR_INT, (*M1 >= M2) ? 1 : 0);
     509    case 'A': VS_FUNC(ST_SCALAR_INT, (*M1 && M2) ? 1 : 0);
     510    case 'O': VS_FUNC(ST_SCALAR_INT, (*M1 || M2) ? 1 : 0);
    319511    default:
    320       sprintf (line, "error: op %c not defined!", op[0]);
     512      snprintf (line, 512, "error: op %c not defined!", op[0]);
    321513      push_error (line);
    322514      return (FALSE);
     
    326518  /** free up any temporary buffers: **/
    327519
    328   if (V1[0].type == 'v') {
     520  if (V1[0].type == ST_VECTOR_TMP) {
    329521    free (V1[0].vector[0].elements.Ptr);
    330522    free (V1[0].vector);
     
    353545
    354546  /* if possible, use V1 as temp buffer, otherwise create new one */
    355   if (V1[0].type == 'm') { 
     547  if (V1[0].type == ST_MATRIX_TMP) { 
    356548    OUT[0].buffer = V1[0].buffer;
    357     V1[0].type = 'M'; /* prevent it from being freed below */
     549    V1[0].type = ST_MATRIX; /* prevent it from being freed below */
    358550  } else { 
    359551    /* do buffer.matrix.buffer and buffer.header.buffer get correctly zeroed? */
     
    361553    CopyBuffer (OUT[0].buffer, V1[0].buffer);
    362554  }
    363   OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
     555  OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/
    364556
    365557  float     *M1  = (float *) V1[0].buffer[0].matrix.buffer;
     
    395587    case '^': MV_FUNC(pow (*M1, *M2));
    396588    case '@': MV_FUNC(DEG_RAD*atan2 (*M1, *M2));
     589    case 'a': MV_FUNC(DEG_RAD*atan2 (*M1, *M2));
    397590    case 'D': MV_FUNC(MIN (*M1, *M2));
    398591    case 'U': MV_FUNC(MAX (*M1, *M2));
     
    408601    case 'O': MV_FUNC((*M1 || *M2) ? 1 : 0);
    409602    default:
    410       sprintf (line, "error: op %c not defined!", op[0]);
     603      snprintf (line, 512, "error: op %c not defined!", op[0]);
    411604      push_error (line);
    412605      return (FALSE);
     
    416609  /** free up any temporary buffers: **/
    417610
    418   if (V1[0].type == 'm') {
     611  if (V1[0].type == ST_MATRIX_TMP) {
    419612    free (V1[0].buffer[0].header.buffer);
    420613    free (V1[0].buffer[0].matrix.buffer);
    421614    free (V1[0].buffer);
    422615  }
    423   if (V2[0].type == 'v') {
     616  if (V2[0].type == ST_VECTOR_TMP) {
    424617    free (V2[0].vector[0].elements.Ptr);
    425618    free (V2[0].vector);
     
    446639
    447640  /* if possible, use V2 as temp buffer, otherwise create new one */
    448   if (V2[0].type == 'm') {
     641  if (V2[0].type == ST_MATRIX_TMP) {
    449642    OUT[0].buffer = V2[0].buffer;
    450     V2[0].type = 'M'; /* prevent it from being freed below */
     643    V2[0].type = ST_MATRIX; /* prevent it from being freed below */
    451644  } else {  /* no spare temp buffer */
    452645    OUT[0].buffer = InitBuffer ();
    453646    CopyBuffer (OUT[0].buffer, V2[0].buffer);
    454647  }
    455   OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
     648  OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/
    456649
    457650  float     *M2  = (float *) V2[0].buffer[0].matrix.buffer;
     
    487680    case '^': VM_FUNC(pow (*M1, *M2));
    488681    case '@': VM_FUNC(DEG_RAD*atan2 (*M1, *M2));
     682    case 'a': VM_FUNC(DEG_RAD*atan2 (*M1, *M2));
    489683    case 'D': VM_FUNC(MIN (*M1, *M2));
    490684    case 'U': VM_FUNC(MAX (*M1, *M2));
     
    500694    case 'O': VM_FUNC((*M1 || *M2) ? 1 : 0);
    501695    default:
    502       sprintf (line, "error: op %c not defined!", op[0]);
     696      snprintf (line, 512, "error: op %c not defined!", op[0]);
    503697      push_error (line);
    504698      return (FALSE);
     
    508702  /** free up any temporary buffers: **/
    509703
    510   if (V1[0].type == 'v') {
     704  if (V1[0].type == ST_VECTOR_TMP) {
    511705    free (V1[0].vector[0].elements.Ptr);
    512706    free (V1[0].vector);
    513707  }
    514   if (V2[0].type == 'm') {
     708  if (V2[0].type == ST_MATRIX_TMP) {
    515709    free (V2[0].buffer[0].header.buffer);
    516710    free (V2[0].buffer[0].matrix.buffer);
     
    535729  Ny = V1[0].buffer[0].matrix.Naxis[1];
    536730
    537   if (V1[0].type == 'm') {  /** use V1 as temp buffer **/
     731  if (V1[0].type == ST_MATRIX_TMP) {  /** use V1 as temp buffer **/
    538732    OUT[0].buffer = V1[0].buffer;
    539     V1[0].type = 'M'; /* prevent it from being freed below */
     733    V1[0].type = ST_MATRIX; /* prevent it from being freed below */
    540734  } else {
    541     if (V2[0].type == 'm') { /** use V2 as temp buffer, but header of V1 **/
     735    if (V2[0].type == ST_MATRIX_TMP) { /** use V2 as temp buffer, but header of V1 **/
    542736      OUT[0].buffer = V2[0].buffer;
    543       V2[0].type = 'M'; /* prevent it from being freed below */
     737      V2[0].type = ST_MATRIX; /* prevent it from being freed below */
    544738    } else {  /* no spare temp buffer */
    545739      OUT[0].buffer = InitBuffer ();
     
    547741    }
    548742  }
    549   OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
     743  OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/
    550744
    551745  M1  = (float *)V1[0].buffer[0].matrix.buffer;
     
    567761    case '^': MM_FUNC(pow (*M1, *M2));
    568762    case '@': MM_FUNC(DEG_RAD*atan2 (*M1, *M2));
     763    case 'a': MM_FUNC(DEG_RAD*atan2 (*M1, *M2));
    569764    case 'D': MM_FUNC(MIN (*M1, *M2));
    570765    case 'U': MM_FUNC(MAX (*M1, *M2));
     
    580775    case 'O': MM_FUNC((*M1 || *M2) ? 1 : 0);
    581776    default:
    582       sprintf (line, "error: op %c not defined!", op[0]);
     777      snprintf (line, 512, "error: op %c not defined!", op[0]);
    583778      push_error (line);
    584779      return (FALSE);
     
    588783  /** free up any temporary buffers: **/
    589784
    590   if (V1[0].type == 'm') {
     785  if (V1[0].type == ST_MATRIX_TMP) {
    591786    free (V1[0].buffer[0].header.buffer);
    592787    free (V1[0].buffer[0].matrix.buffer);
    593788    free (V1[0].buffer);
    594789  }
    595   if (V2[0].type == 'm') {
     790  if (V2[0].type == ST_MATRIX_TMP) {
    596791    free (V2[0].buffer[0].header.buffer);
    597792    free (V2[0].buffer[0].matrix.buffer);
     
    615810
    616811  /* if possible, use V1 as temp buffer, otherwise create new one */
    617   if (V1[0].type == 'm') {
     812  if (V1[0].type == ST_MATRIX_TMP) {
    618813    OUT[0].buffer = V1[0].buffer;
    619     V1[0].type = 'M'; /* prevent it from being freed below */
     814    V1[0].type = ST_MATRIX; /* prevent it from being freed below */
    620815  } else {
    621816    OUT[0].buffer = InitBuffer ();
    622817    CopyBuffer (OUT[0].buffer, V1[0].buffer);
    623818  }
    624   OUT[0].type = 'm';      /*** <<--- says this is a temporary matrix ***/
     819  OUT[0].type = ST_MATRIX_TMP;      /*** <<--- says this is a temporary matrix ***/
    625820
    626821  float *M1    = (float *)V1[0].buffer[0].matrix.buffer;
     
    628823
    629824# define MS_FUNC(OP) {                                  \
    630     if (V2->type == 'S')  {                             \
     825    if (V2->type == ST_SCALAR_FLT)  {                           \
    631826      opihi_flt M2 = V2[0].FltValue;                    \
    632827      for (i = 0; i < Nx*Ny; i++, out++, M1++) {        \
     
    635830      break;                                            \
    636831    }                                                   \
    637     if (V2->type == 's')  {                             \
     832    if (V2->type == ST_SCALAR_INT)  {                           \
    638833      opihi_int M2 = V2[0].IntValue;                    \
    639834      for (i = 0; i < Nx*Ny; i++, out++, M1++) {        \
     
    652847    case '^': MS_FUNC(pow (*M1, M2));
    653848    case '@': MS_FUNC(DEG_RAD*atan2 (*M1, M2));
     849    case 'a': MS_FUNC(DEG_RAD*atan2 (*M1, M2));
    654850    case 'D': MS_FUNC(MIN (*M1, M2));
    655851    case 'U': MS_FUNC(MAX (*M1, M2));
     
    665861    case 'O': MS_FUNC((*M1 || M2) ? 1 : 0);
    666862    default:
    667       sprintf (line, "error: op %c not defined!", op[0]);
     863      snprintf (line, 512, "error: op %c not defined!", op[0]);
    668864      push_error (line);
    669865      return (FALSE);
     
    671867# undef MS_FUNC
    672868
    673   if (V1[0].type == 'm') {
     869  if (V1[0].type == ST_MATRIX_TMP) {
    674870    free (V1[0].buffer[0].header.buffer);
    675871    free (V1[0].buffer[0].matrix.buffer);
     
    691887  Ny = V2[0].buffer[0].matrix.Naxis[1];
    692888
    693   if (V2[0].type == 'm') {  /* V2[0] is NOT temporary, we can't use it for storage */
     889  if (V2[0].type == ST_MATRIX_TMP) {  /* V2[0] is NOT temporary, we can't use it for storage */
    694890    OUT[0].buffer = V2[0].buffer;
    695     V2[0].type = 'M'; /* prevent it from being freed below */
     891    V2[0].type = ST_MATRIX; /* prevent it from being freed below */
    696892  } else {
    697893    OUT[0].buffer = InitBuffer ();
    698894    CopyBuffer (OUT[0].buffer, V2[0].buffer);
    699895  }
    700   OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
     896  OUT[0].type = ST_MATRIX_TMP; /*** <<--- says this is a temporary matrix ***/
    701897
    702898  float *M2    = (float *)V2[0].buffer[0].matrix.buffer;
     
    704900
    705901# define SM_FUNC(OP) {                                  \
    706     if (V1->type == 'S')  {                             \
     902    if (V1->type == ST_SCALAR_FLT)  {                           \
    707903      opihi_flt M1 = V1[0].FltValue;                    \
    708904      for (i = 0; i < Nx*Ny; i++, out++, M2++) {        \
     
    711907      break;                                            \
    712908    }                                                   \
    713     if (V1->type == 's')  {                             \
     909    if (V1->type == ST_SCALAR_INT)  {                           \
    714910      opihi_int M1 = V1[0].IntValue;                    \
    715911      for (i = 0; i < Nx*Ny; i++, out++, M2++) {        \
     
    728924    case '^': SM_FUNC(pow (M1, *M2));
    729925    case '@': SM_FUNC(DEG_RAD*atan2 (M1, *M2));
     926    case 'a': SM_FUNC(DEG_RAD*atan2 (M1, *M2));
    730927    case 'D': SM_FUNC(MIN (M1, *M2));
    731928    case 'U': SM_FUNC(MAX (M1, *M2));
     
    741938    case 'O': SM_FUNC((M1 || *M2) ? 1 : 0);
    742939    default:
    743       sprintf (line, "error: op %c not defined!", op[0]);
     940      snprintf (line, 512, "error: op %c not defined!", op[0]);
    744941      push_error (line);
    745942      return (FALSE);
     
    747944# undef SM_FUNC
    748945
    749   if (V2[0].type == 'm') {
     946  if (V2[0].type == ST_MATRIX_TMP) {
    750947    free (V2[0].buffer[0].header.buffer);
    751948    free (V2[0].buffer[0].matrix.buffer);
     
    764961
    765962# define SS_FUNC(FTYPE,OP) {                                            \
    766     if ((V1->type == 'S') && (V2->type == 'S')) {                       \
     963    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_FLT)) {                   \
    767964      opihi_flt M1 = V1[0].FltValue;                                    \
    768965      opihi_flt M2 = V2[0].FltValue;                                    \
    769       OUT[0].type = 'S';                                                \
     966      OUT[0].type = ST_SCALAR_FLT;                                              \
    770967      OUT[0].FltValue = OP;                                             \
    771968      break;                                                            \
    772969    }                                                                   \
    773     if ((V1->type == 'S') && (V2->type == 's')) {                       \
     970    if ((V1->type == ST_SCALAR_FLT) && (V2->type == ST_SCALAR_INT)) {                   \
    774971      opihi_flt M1 = V1[0].FltValue;                                    \
    775972      opihi_int M2 = V2[0].IntValue;                                    \
    776       OUT[0].type = 'S';                                                \
     973      OUT[0].type = ST_SCALAR_FLT;                                              \
    777974      OUT[0].FltValue = OP;                                             \
    778975      break;                                                            \
    779976    }                                                                   \
    780     if ((V1->type == 's') && (V2->type == 'S')) {                       \
     977    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_FLT)) {                   \
    781978      opihi_int M1 = V1[0].IntValue;                                    \
    782979      opihi_flt M2 = V2[0].FltValue;                                    \
    783       OUT[0].type = 'S';                                                \
     980      OUT[0].type = ST_SCALAR_FLT;                                              \
    784981      OUT[0].FltValue = OP;                                             \
    785982      break;                                                            \
    786983    }                                                                   \
    787     if ((FTYPE == 'S') && (V1->type == 's') && (V2->type == 's')) {     \
     984    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) {       \
    788985      opihi_int M1 = V1[0].IntValue;                                    \
    789986      opihi_int M2 = V2[0].IntValue;                                    \
    790       OUT[0].type = 'S';                                                \
     987      OUT[0].type = ST_SCALAR_FLT;                                              \
    791988      OUT[0].FltValue = OP;                                             \
    792989      break;                                                            \
    793990    }                                                                   \
    794     if ((V1->type == 's') && (V2->type == 's')) {                       \
     991    if ((V1->type == ST_SCALAR_INT) && (V2->type == ST_SCALAR_INT)) {                   \
    795992      opihi_int M1 = V1[0].IntValue;                                    \
    796993      opihi_int M2 = V2[0].IntValue;                                    \
    797       OUT[0].type = 's';                                                \
     994      OUT[0].type = ST_SCALAR_INT;                                              \
    798995      OUT[0].IntValue = OP;                                             \
    799996      break;                                                            \
     
    802999
    8031000  switch (op[0]) {
    804     case '+': SS_FUNC('s', M1 + M2);
    805     case '-': SS_FUNC('s', M1 - M2);
    806     case '*': SS_FUNC('s', M1 * M2);
    807     case '/': SS_FUNC('S', M1 / (opihi_flt) M2);
    808     case '%': SS_FUNC('s', (long long) M1 % (long long) M2);
    809     case '^': SS_FUNC('S', pow (M1, M2));
    810     case '@': SS_FUNC('S', DEG_RAD*atan2 (M1, M2));
    811     case 'D': SS_FUNC('s', MIN (M1, M2));
    812     case 'U': SS_FUNC('s', MAX (M1, M2));
    813     case '<': SS_FUNC('s', (M1 < M2) ? 1 : 0);
    814     case '>': SS_FUNC('s', (M1 > M2) ? 1 : 0);
    815     case '&': SS_FUNC('s', ((long long)M1 & (long long)M2));
    816     case '|': SS_FUNC('s', ((long long)M1 | (long long)M2));
    817     case 'E': SS_FUNC('s', (M1 == M2) ? 1 : 0);
    818     case 'N': SS_FUNC('s', (M1 != M2) ? 1 : 0);
    819     case 'L': SS_FUNC('s', (M1 <= M2) ? 1 : 0);
    820     case 'G': SS_FUNC('s', (M1 >= M2) ? 1 : 0);
    821     case 'A': SS_FUNC('s', (M1 && M2) ? 1 : 0);
    822     case 'O': SS_FUNC('s', (M1 || M2) ? 1 : 0);
     1001    case '+': SS_FUNC(ST_SCALAR_INT, M1 + M2);
     1002    case '-': SS_FUNC(ST_SCALAR_INT, M1 - M2);
     1003    case '*': SS_FUNC(ST_SCALAR_INT, M1 * M2);
     1004    case '/': SS_FUNC(ST_SCALAR_FLT, M1 / (opihi_flt) M2);
     1005    case '%': SS_FUNC(ST_SCALAR_INT, (long long) M1 % (long long) M2);
     1006    case '^': SS_FUNC(ST_SCALAR_FLT, pow (M1, M2));
     1007    case '@': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
     1008    case 'a': SS_FUNC(ST_SCALAR_FLT, DEG_RAD*atan2 (M1, M2));
     1009    case 'D': SS_FUNC(ST_SCALAR_INT, MIN (M1, M2));
     1010    case 'U': SS_FUNC(ST_SCALAR_INT, MAX (M1, M2));
     1011    case '<': SS_FUNC(ST_SCALAR_INT, (M1 < M2) ? 1 : 0);
     1012    case '>': SS_FUNC(ST_SCALAR_INT, (M1 > M2) ? 1 : 0);
     1013    case '&': SS_FUNC(ST_SCALAR_INT, ((long long)M1 & (long long)M2));
     1014    case '|': SS_FUNC(ST_SCALAR_INT, ((long long)M1 | (long long)M2));
     1015    case 'E': SS_FUNC(ST_SCALAR_INT, (M1 == M2) ? 1 : 0);
     1016    case 'N': SS_FUNC(ST_SCALAR_INT, (M1 != M2) ? 1 : 0);
     1017    case 'L': SS_FUNC(ST_SCALAR_INT, (M1 <= M2) ? 1 : 0);
     1018    case 'G': SS_FUNC(ST_SCALAR_INT, (M1 >= M2) ? 1 : 0);
     1019    case 'A': SS_FUNC(ST_SCALAR_INT, (M1 && M2) ? 1 : 0);
     1020    case 'O': SS_FUNC(ST_SCALAR_INT, (M1 || M2) ? 1 : 0);
    8231021    default:
    824       sprintf (line, "error: op %c not defined!", op[0]);
     1022      snprintf (line, 512, "error: op %c not defined!", op[0]);
    8251023      push_error (line);
    8261024      return (FALSE);
     
    8441042
    8451043  if ((op[0] != 'N') && (op[0] != 'E')) {
    846     sprintf (line, "error: op %c not defined for string operations!", op[0]);
     1044    snprintf (line, 512, "error: op %c not defined for string operations!", op[0]);
    8471045    push_error (line);
    8481046    return (FALSE);
     
    8531051     thus: string == number -> false */
    8541052
    855   if (!strncasecmp (&V1[0].type, "S", 1)) {
     1053  if (V1[0].type == ST_SCALAR_INT) {
    8561054    value = (op[0] == 'N');
    8571055    goto escape;
    8581056  }
    859   if (!strncasecmp (&V2[0].type, "S", 1)) {
     1057  if (V1[0].type == ST_SCALAR_FLT) {
     1058    value = (op[0] == 'N');
     1059    goto escape;
     1060  }
     1061  if (V2[0].type == ST_SCALAR_INT) {
     1062    value = (op[0] == 'N');
     1063    goto escape;
     1064  }
     1065  if (V2[0].type == ST_SCALAR_FLT) {
    8601066    value = (op[0] == 'N');
    8611067    goto escape;
     
    8701076    break;
    8711077    default:
    872       sprintf (line, "error: op %c not defined for string operations!", op[0]);
     1078      snprintf (line, 512, "error: op %c not defined for string operations!", op[0]);
    8731079      push_error (line);
    8741080      return (FALSE);
     
    8771083escape:
    8781084  OUT[0].FltValue = value;
    879   OUT[0].type = 'S';
     1085  OUT[0].type = ST_SCALAR_FLT;
    8801086
    8811087  clear_stack (V1);
     
    8911097 
    8921098# define S_FUNC(OP,FTYPE) {                     \
    893     if (V1->type == 'S') {                      \
     1099    if (V1->type == ST_SCALAR_FLT) {                    \
    8941100      opihi_flt M1  = V1[0].FltValue;           \
    895       OUT[0].type = 'S';                        \
     1101      OUT[0].type = ST_SCALAR_FLT;                      \
    8961102      OUT[0].FltValue = OP;                     \
    8971103      clear_stack (V1);                         \
    8981104      return (TRUE);                            \
    8991105    }                                           \
    900     if ((FTYPE == 'S') && (V1->type == 's')) {  \
     1106    if ((FTYPE == ST_SCALAR_FLT) && (V1->type == ST_SCALAR_INT)) {      \
    9011107      opihi_int M1  = V1[0].IntValue;           \
    902       OUT[0].type = 'S';                        \
     1108      OUT[0].type = ST_SCALAR_FLT;                      \
    9031109      OUT[0].FltValue = OP;                     \
    9041110      clear_stack (V1);                         \
    9051111      return (TRUE);                            \
    9061112    }                                           \
    907     if ((FTYPE == 's') && (V1->type == 's')) {  \
     1113    if ((FTYPE == ST_SCALAR_INT) && (V1->type == ST_SCALAR_INT)) {      \
    9081114      opihi_int M1  = V1[0].IntValue;           \
    909       OUT[0].type = 's';                        \
     1115      OUT[0].type = ST_SCALAR_INT;                      \
    9101116      OUT[0].IntValue = OP;                     \
    9111117      clear_stack (V1);                         \
     
    9141120  }
    9151121
    916   if (!strcmp (op, "="))      S_FUNC(M1, 's');
    917   if (!strcmp (op, "abs"))    S_FUNC(fabs(M1), 's');
    918   if (!strcmp (op, "int"))    S_FUNC((long long)(M1), 's');
    919   if (!strcmp (op, "exp"))    S_FUNC(exp (M1), 'S');
    920   if (!strcmp (op, "ten"))    S_FUNC(pow (10.0,M1), 'S');
    921   if (!strcmp (op, "log"))    S_FUNC(log10 (M1), 'S');
    922   if (!strcmp (op, "ln"))     S_FUNC(log (M1), 'S');
    923   if (!strcmp (op, "sqrt"))   S_FUNC(sqrt (M1), 'S');
    924   if (!strcmp (op, "erf"))    S_FUNC(erf (M1), 'S');
    925   if (!strcmp (op, "sinh"))   S_FUNC(sinh (M1), 'S');
    926   if (!strcmp (op, "cosh"))   S_FUNC(cosh (M1), 'S');
    927   if (!strcmp (op, "asinh"))  S_FUNC(asinh (M1), 'S');
    928   if (!strcmp (op, "acosh"))  S_FUNC(acosh (M1), 'S');
    929   if (!strcmp (op, "lgamma")) S_FUNC(lgamma (M1), 'S');
    930   if (!strcmp (op, "sin"))    S_FUNC(sin (M1), 'S');
    931   if (!strcmp (op, "cos"))    S_FUNC(cos (M1), 'S');
    932   if (!strcmp (op, "tan"))    S_FUNC(tan (M1), 'S');
    933   if (!strcmp (op, "dsin"))   S_FUNC(sin (M1*RAD_DEG), 'S');
    934   if (!strcmp (op, "dcos"))   S_FUNC(cos (M1*RAD_DEG), 'S');
    935   if (!strcmp (op, "dtan"))   S_FUNC(tan (M1*RAD_DEG), 'S');
    936   if (!strcmp (op, "asin"))   S_FUNC(asin (M1), 'S');
    937   if (!strcmp (op, "acos"))   S_FUNC(acos (M1), 'S');
    938   if (!strcmp (op, "atan"))   S_FUNC(atan (M1), 'S');
    939   if (!strcmp (op, "dasin"))  S_FUNC(asin (M1)*DEG_RAD, 'S');
    940   if (!strcmp (op, "dacos"))  S_FUNC(acos (M1)*DEG_RAD, 'S');
    941   if (!strcmp (op, "datan"))  S_FUNC(atan (M1)*DEG_RAD, 'S');
    942   if (!strcmp (op, "rnd"))    S_FUNC(M1*0.0 + drand48(), 'S');
    943   if (!strcmp (op, "not"))    S_FUNC(!(M1), 's');
    944   if (!strcmp (op, "--"))     S_FUNC(-1*M1, 's'); // NOTE: opihi_int is signed,
    945   if (!strcmp (op, "isinf"))  S_FUNC(!finite(M1), 'S'); // XXX modify in future
    946   if (!strcmp (op, "isnan"))  S_FUNC(isnan(M1), 'S'); // XXX modify in future   
     1122  if (!strcmp (op, "="))      S_FUNC(M1, ST_SCALAR_INT);
     1123  if (!strcmp (op, "abs"))    S_FUNC(fabs(M1), ST_SCALAR_INT);
     1124  if (!strcmp (op, "int"))    S_FUNC((long long)(M1), ST_SCALAR_INT);
     1125  if (!strcmp (op, "floor"))  S_FUNC(floor (M1), ST_SCALAR_FLT);
     1126  if (!strcmp (op, "ceil"))   S_FUNC(ceil (M1), ST_SCALAR_FLT);
     1127  // if (!strcmp (op, "rint"))   S_FUNC(nearbyint (M1), ST_SCALAR_FLT);
     1128  if (!strcmp (op, "exp"))    S_FUNC(exp (M1), ST_SCALAR_FLT);
     1129  if (!strcmp (op, "ten"))    S_FUNC(pow (10.0,M1), ST_SCALAR_FLT);
     1130  if (!strcmp (op, "log"))    S_FUNC(log10 (M1), ST_SCALAR_FLT);
     1131  if (!strcmp (op, "ln"))     S_FUNC(log (M1), ST_SCALAR_FLT);
     1132  if (!strcmp (op, "sqrt"))   S_FUNC(sqrt (M1), ST_SCALAR_FLT);
     1133  if (!strcmp (op, "erf"))    S_FUNC(erf (M1), ST_SCALAR_FLT);
     1134  if (!strcmp (op, "sinh"))   S_FUNC(sinh (M1), ST_SCALAR_FLT);
     1135  if (!strcmp (op, "cosh"))   S_FUNC(cosh (M1), ST_SCALAR_FLT);
     1136  if (!strcmp (op, "asinh"))  S_FUNC(asinh (M1), ST_SCALAR_FLT);
     1137  if (!strcmp (op, "acosh"))  S_FUNC(acosh (M1), ST_SCALAR_FLT);
     1138  if (!strcmp (op, "lgamma")) S_FUNC(lgamma (M1), ST_SCALAR_FLT);
     1139  if (!strcmp (op, "sin"))    S_FUNC(sin (M1), ST_SCALAR_FLT);
     1140  if (!strcmp (op, "cos"))    S_FUNC(cos (M1), ST_SCALAR_FLT);
     1141  if (!strcmp (op, "tan"))    S_FUNC(tan (M1), ST_SCALAR_FLT);
     1142  if (!strcmp (op, "dsin"))   S_FUNC(sin (M1*RAD_DEG), ST_SCALAR_FLT);
     1143  if (!strcmp (op, "dcos"))   S_FUNC(cos (M1*RAD_DEG), ST_SCALAR_FLT);
     1144  if (!strcmp (op, "dtan"))   S_FUNC(tan (M1*RAD_DEG), ST_SCALAR_FLT);
     1145  if (!strcmp (op, "asin"))   S_FUNC(asin (M1), ST_SCALAR_FLT);
     1146  if (!strcmp (op, "acos"))   S_FUNC(acos (M1), ST_SCALAR_FLT);
     1147  if (!strcmp (op, "atan"))   S_FUNC(atan (M1), ST_SCALAR_FLT);
     1148  if (!strcmp (op, "dasin"))  S_FUNC(asin (M1)*DEG_RAD, ST_SCALAR_FLT);
     1149  if (!strcmp (op, "dacos"))  S_FUNC(acos (M1)*DEG_RAD, ST_SCALAR_FLT);
     1150  if (!strcmp (op, "datan"))  S_FUNC(atan (M1)*DEG_RAD, ST_SCALAR_FLT);
     1151  if (!strcmp (op, "rnd"))    S_FUNC(M1*0.0 + drand48(), ST_SCALAR_FLT);
     1152  if (!strcmp (op, "not"))    S_FUNC(!(M1), ST_SCALAR_INT);
     1153  if (!strcmp (op, "--"))     S_FUNC(-1*M1, ST_SCALAR_INT); // NOTE: opihi_int is signed,
     1154  if (!strcmp (op, "isinf"))  S_FUNC(!finite(M1), ST_SCALAR_FLT); // XXX modify in future
     1155  if (!strcmp (op, "isnan"))  S_FUNC(isnan(M1), ST_SCALAR_FLT); // XXX modify in future   
    9471156
    9481157# undef S_FUNC
    9491158
    9501159  clear_stack (V1);
    951   sprintf (line, "error: op %s not defined!", op);
     1160  snprintf (line, 512, "error: op %s not defined!", op);
    9521161  push_error (line);
    9531162  return (FALSE);
     
    9621171
    9631172  OUT[0].vector = InitVector ();
    964   OUT[0].type = 'v'; /*** <<--- says this is a temporary matrix ***/
     1173  OUT[0].type = ST_VECTOR_TMP; /*** <<--- says this is a temporary matrix ***/
    9651174
    9661175# define V_FUNC(OP,FTYPE) {                                     \
     
    9741183      goto escape;                                              \
    9751184    }                                                           \
    976     if ((V1->vector->type == OPIHI_INT) && (FTYPE == 'S')) {    \
     1185    if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_FLT)) {  \
    9771186      MatchVector (OUT[0].vector, V1[0].vector, OPIHI_FLT);     \
    9781187      opihi_int *M1  = V1[0].vector[0].elements.Int;            \
     
    9831192      goto escape;                                              \
    9841193    }                                                           \
    985     if ((V1->vector->type == OPIHI_INT) && (FTYPE == 's')) {    \
     1194    if ((V1->vector->type == OPIHI_INT) && (FTYPE == ST_SCALAR_INT)) {  \
    9861195      CopyVector (OUT[0].vector, V1[0].vector);                 \
    9871196      opihi_int *M1  = V1[0].vector[0].elements.Int;            \
     
    9931202    } }                                                 
    9941203
    995   if (!strcmp (op, "="))      V_FUNC(*M1, 's');
    996   if (!strcmp (op, "abs"))    V_FUNC(fabs(*M1), 's');
    997   if (!strcmp (op, "int"))    V_FUNC((long long)(*M1), 's');
    998   if (!strcmp (op, "exp"))    V_FUNC(exp(*M1), 'S');
    999   if (!strcmp (op, "ten"))    V_FUNC(pow(10.0,*M1), 'S');
    1000   if (!strcmp (op, "log"))    V_FUNC(log10(*M1), 'S');
    1001   if (!strcmp (op, "ln"))     V_FUNC(log(*M1), 'S');
    1002   if (!strcmp (op, "sqrt"))   V_FUNC(sqrt(*M1), 'S');
    1003   if (!strcmp (op, "erf"))    V_FUNC(erf(*M1), 'S');
    1004   if (!strcmp (op, "sinh"))   V_FUNC(sinh(*M1), 'S');
    1005   if (!strcmp (op, "cosh"))   V_FUNC(cosh(*M1), 'S');
    1006   if (!strcmp (op, "asinh"))  V_FUNC(asinh(*M1), 'S');
    1007   if (!strcmp (op, "acosh"))  V_FUNC(acosh(*M1), 'S');
    1008   if (!strcmp (op, "lgamma")) V_FUNC(lgamma(*M1), 'S');
    1009   if (!strcmp (op, "sin"))    V_FUNC(sin(*M1), 'S');
    1010   if (!strcmp (op, "cos"))    V_FUNC(cos(*M1), 'S');
    1011   if (!strcmp (op, "tan"))    V_FUNC(tan(*M1), 'S');
    1012   if (!strcmp (op, "dsin"))   V_FUNC(sin(*M1*RAD_DEG), 'S');
    1013   if (!strcmp (op, "dcos"))   V_FUNC(cos(*M1*RAD_DEG), 'S');
    1014   if (!strcmp (op, "dtan"))   V_FUNC(tan(*M1*RAD_DEG), 'S');
    1015   if (!strcmp (op, "asin"))   V_FUNC(asin(*M1), 'S');
    1016   if (!strcmp (op, "acos"))   V_FUNC(acos(*M1), 'S');
    1017   if (!strcmp (op, "atan"))   V_FUNC(atan(*M1), 'S');
    1018   if (!strcmp (op, "dasin"))  V_FUNC(asin(*M1)*DEG_RAD, 'S');
    1019   if (!strcmp (op, "dacos"))  V_FUNC(acos(*M1)*DEG_RAD, 'S');
    1020   if (!strcmp (op, "datan"))  V_FUNC(atan(*M1)*DEG_RAD, 'S');
    1021   if (!strcmp (op, "rnd"))    V_FUNC(drand48(), 'S');
    1022   if (!strcmp (op, "ramp"))   V_FUNC(i, 's');
    1023   if (!strcmp (op, "zero"))   V_FUNC(0, 's');
    1024   if (!strcmp (op, "not"))    V_FUNC(!(*M1), 's');
    1025   if (!strcmp (op, "--"))     V_FUNC(-1*(*M1), 's'); // NOTE: opihi_int is signed
    1026   if (!strcmp (op, "isinf"))  V_FUNC(!finite(*M1), 'S');
    1027   if (!strcmp (op, "isnan"))  V_FUNC(isnan(*M1), 'S');
    1028   if (!strcmp (op, "xramp"))  V_FUNC(i, 's');
    1029   if (!strcmp (op, "yramp"))  V_FUNC(0, 's');
     1204  if (!strcmp (op, "="))      V_FUNC(*M1, ST_SCALAR_INT);
     1205  if (!strcmp (op, "abs"))    V_FUNC(fabs(*M1), ST_SCALAR_INT);
     1206  if (!strcmp (op, "int"))    V_FUNC((long long)(*M1), ST_SCALAR_INT);
     1207  if (!strcmp (op, "floor"))  V_FUNC(floor (*M1), ST_SCALAR_FLT);
     1208  if (!strcmp (op, "ceil"))   V_FUNC(ceil (*M1), ST_SCALAR_FLT);
     1209  // if (!strcmp (op, "rint"))   V_FUNC(nearbyint (*M1), ST_SCALAR_FLT);
     1210  if (!strcmp (op, "exp"))    V_FUNC(exp(*M1), ST_SCALAR_FLT);
     1211  if (!strcmp (op, "ten"))    V_FUNC(pow(10.0,*M1), ST_SCALAR_FLT);
     1212  if (!strcmp (op, "log"))    V_FUNC(log10(*M1), ST_SCALAR_FLT);
     1213  if (!strcmp (op, "ln"))     V_FUNC(log(*M1), ST_SCALAR_FLT);
     1214  if (!strcmp (op, "sqrt"))   V_FUNC(sqrt(*M1), ST_SCALAR_FLT);
     1215  if (!strcmp (op, "erf"))    V_FUNC(erf(*M1), ST_SCALAR_FLT);
     1216  if (!strcmp (op, "sinh"))   V_FUNC(sinh(*M1), ST_SCALAR_FLT);
     1217  if (!strcmp (op, "cosh"))   V_FUNC(cosh(*M1), ST_SCALAR_FLT);
     1218  if (!strcmp (op, "asinh"))  V_FUNC(asinh(*M1), ST_SCALAR_FLT);
     1219  if (!strcmp (op, "acosh"))  V_FUNC(acosh(*M1), ST_SCALAR_FLT);
     1220  if (!strcmp (op, "lgamma")) V_FUNC(lgamma(*M1), ST_SCALAR_FLT);
     1221  if (!strcmp (op, "sin"))    V_FUNC(sin(*M1), ST_SCALAR_FLT);
     1222  if (!strcmp (op, "cos"))    V_FUNC(cos(*M1), ST_SCALAR_FLT);
     1223  if (!strcmp (op, "tan"))    V_FUNC(tan(*M1), ST_SCALAR_FLT);
     1224  if (!strcmp (op, "dsin"))   V_FUNC(sin(*M1*RAD_DEG), ST_SCALAR_FLT);
     1225  if (!strcmp (op, "dcos"))   V_FUNC(cos(*M1*RAD_DEG), ST_SCALAR_FLT);
     1226  if (!strcmp (op, "dtan"))   V_FUNC(tan(*M1*RAD_DEG), ST_SCALAR_FLT);
     1227  if (!strcmp (op, "asin"))   V_FUNC(asin(*M1), ST_SCALAR_FLT);
     1228  if (!strcmp (op, "acos"))   V_FUNC(acos(*M1), ST_SCALAR_FLT);
     1229  if (!strcmp (op, "atan"))   V_FUNC(atan(*M1), ST_SCALAR_FLT);
     1230  if (!strcmp (op, "dasin"))  V_FUNC(asin(*M1)*DEG_RAD, ST_SCALAR_FLT);
     1231  if (!strcmp (op, "dacos"))  V_FUNC(acos(*M1)*DEG_RAD, ST_SCALAR_FLT);
     1232  if (!strcmp (op, "datan"))  V_FUNC(atan(*M1)*DEG_RAD, ST_SCALAR_FLT);
     1233  if (!strcmp (op, "rnd"))    V_FUNC(drand48(), ST_SCALAR_FLT);
     1234  if (!strcmp (op, "ramp"))   V_FUNC(i, ST_SCALAR_INT);
     1235  if (!strcmp (op, "zero"))   V_FUNC(0, ST_SCALAR_INT);
     1236  if (!strcmp (op, "not"))    V_FUNC(!(*M1), ST_SCALAR_INT);
     1237  if (!strcmp (op, "--"))     V_FUNC(-1*(*M1), ST_SCALAR_INT); // NOTE: opihi_int is signed
     1238  if (!strcmp (op, "isinf"))  V_FUNC(!finite(*M1), ST_SCALAR_FLT);
     1239  if (!strcmp (op, "isnan"))  V_FUNC(isnan(*M1), ST_SCALAR_FLT);
     1240  if (!strcmp (op, "xramp"))  V_FUNC(i, ST_SCALAR_INT);
     1241  if (!strcmp (op, "yramp"))  V_FUNC(0, ST_SCALAR_INT);
    10301242  /* xramp and yramp above only make sense for matrices. for vectors, xramp = ramp, yramp = zero */
    10311243
     
    10341246escape:
    10351247
    1036   if (V1[0].type == 'v') {
     1248  if (V1[0].type == ST_VECTOR_TMP) {
    10371249    free (V1[0].vector[0].elements.Ptr);
    10381250    free (V1[0].vector);
     
    10531265  Ny = V1[0].buffer[0].matrix.Naxis[1];
    10541266
    1055   if (V1[0].type == 'm') {
     1267  if (V1[0].type == ST_MATRIX_TMP) {
    10561268    OUT[0].buffer = V1[0].buffer;
    1057     V1[0].type = 'M'; /* prevent it from being freed below */
     1269    V1[0].type = ST_MATRIX; /* prevent it from being freed below */
    10581270  } else {
    10591271    OUT[0].buffer = InitBuffer ();
    10601272    CopyBuffer (OUT[0].buffer, V1[0].buffer);
    10611273  }
    1062   OUT[0].type = 'm';      /*** <<--- says this is a temporary matrix ***/
     1274  OUT[0].type = ST_MATRIX_TMP;      /*** <<--- says this is a temporary matrix ***/
    10631275  M1  = (float *) V1[0].buffer[0].matrix.buffer;
    10641276  out = (float *)OUT[0].buffer[0].matrix.buffer;
     
    10671279  if (!strcmp (op, "abs"))   { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = fabs(*M1);         }}
    10681280  if (!strcmp (op, "int"))   { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = (opihi_flt)(long long)(*M1); }}
     1281
     1282  if (!strcmp (op, "floor")) { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = floor (*M1); }}
     1283  if (!strcmp (op, "ceil"))  { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = ceil (*M1); }}
     1284  // if (!strcmp (op, "rint"))  { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = nearbyint (*M1); }}
     1285
    10691286  if (!strcmp (op, "exp"))   { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = exp(*M1);          }}
    10701287  if (!strcmp (op, "ten"))   { for (i = 0; i < Nx*Ny; i++, out++, M1++) { *out = pow(10.0,*M1);     }}
     
    11161333  }
    11171334 
    1118   if (V1[0].type == 'm') {
     1335  if (V1[0].type == ST_MATRIX_TMP) {
    11191336    free (V1[0].buffer[0].header.buffer);
    11201337    free (V1[0].buffer[0].matrix.buffer);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/pantasks/CheckController.c

    r23530 r36680  
    2929  if (p != NULL) goto escape;
    3030
     31  /** skip past any leading garbage? ***/
     32
     33  /** find "Njobs: **/
     34  p = memstr (buffer.buffer, "BEGIN BLOCK Njobs:", MIN(buffer.Nbuffer, 256));
     35  p += strlen("BEGIN BLOCK Njobs:");
     36
    3137  /** parse job list **/
    32   status = sscanf (buffer.buffer, "%*s %d", &Njobs);
     38  status = sscanf (p, "%d", &Njobs);
    3339  if (status != 1) goto escape;
    3440  if (VerboseMode()) gprint (GP_ERR, "parse %d jobs on stack %f\n", Njobs, TimerElapsed(&start, TRUE));
    3541
    36   p = buffer.buffer;
     42  /* output looks like:
     43     BEGIN BLOCK Njobs: NN\n
     44     ID name machine\n
     45     ID name machine\n
     46  */
     47
     48  // p is currently pointing at "BEGIN BLOCK Njobs"
     49
    3750  for (i = 0; i < Njobs; i++) {
    3851    q = strchr (p, '\n');
     
    6780  if (p != NULL) goto escape;
    6881
     82  /** skip past any leading garbage? ***/
     83
     84  /** find "Njobs: **/
     85  p = memstr (buffer.buffer, "BEGIN BLOCK Njobs:", MIN(buffer.Nbuffer, 256));
     86  p += strlen("BEGIN BLOCK Njobs:");
     87
    6988  /** parse job list **/
    70   status = sscanf (buffer.buffer, "%*s %d", &Njobs);
     89  status = sscanf (p, "%d", &Njobs);
    7190  if (status != 1) goto escape;
    7291  if (VerboseMode()) gprint (GP_ERR, "check crash stack %f\n", TimerElapsed(&start, TRUE));
    7392
    74   p = buffer.buffer;
     93  /* output looks like:
     94     BEGIN BLOCK Njobs: NN\n
     95     ID name machine\n
     96     ID name machine\n
     97  */
     98
     99  // p is currently pointing at "BEGIN BLOCK Njobs"
     100
    75101  for (i = 0; i < Njobs; i++) {
    76102    q = strchr (p, '\n');
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/pantasks/ControllerOps.c

    r34088 r36680  
    259259  }
    260260 
    261   if (job[0].priority) {
     261  if (job[0].nicelevel) {
    262262    char tmp[64];
    263     snprintf (tmp, 64, " -nice %d", job[0].priority);
     263    snprintf (tmp, 64, " -nice %d", job[0].nicelevel);
    264264    strcat (cmd, tmp);
    265265  }
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/pantasks/JobOps.c

    r32632 r36680  
    107107    job[0].mode = JOB_CONTROLLER;
    108108  }
    109   job[0].priority = task[0].priority;
     109  job[0].nicelevel = task[0].nicelevel;
    110110
    111111  /* we need our own copy of task[0].argv argc is the number of valid args, like the usual command line.  we
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/pantasks/LocalJob.c

    r32632 r36680  
    162162
    163163  /* set nice level for the child process -- maybe I should not exit here... */
    164   if (job[0].priority) {
    165       status = setpriority (PRIO_PROCESS, pid, job[0].priority);
     164  if (job[0].nicelevel) {
     165      status = setpriority (PRIO_PROCESS, pid, job[0].nicelevel);
    166166      if (status == -1) {
    167           gprint (GP_ERR, "error setting priority\n");
     167          gprint (GP_ERR, "error setting nice level\n");
    168168          perror ("setpriority: ");
    169169          exit (2);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/pantasks/TaskOps.c

    r32632 r36680  
    487487
    488488  NewTask[0].active = TRUE;
    489   NewTask[0].priority = 0;
     489  NewTask[0].nicelevel = 0;
    490490  return (NewTask);
    491491}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/pantasks/init.c

    r32632 r36680  
    3434  {1, "halt",       halt,          "halt the scheduler (no job harvesting)"},
    3535  {1, "host",       task_host,     "define host machine for a task"},
    36   {1, "nice",       task_nice,     "set nice priority level for a task"},
     36  {1, "nice",       task_nice,     "set nice level for a task"},
    3737  {1, "ipptool2book", ipptool2book, "convert queue with ipptool output to book"},
    3838  {1, "kill",       kill_job,      "kill job"},
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/pantasks/init_server.c

    r32632 r36680  
    3535  {1, "delete",     delete_job,    "delete job"},
    3636  {1, "host",       task_host,     "define host machine for a task"},
    37   {1, "nice",       task_nice,     "set nice priority level for a task"},
     37  {1, "nice",       task_nice,     "set nice level for a task"},
    3838  {1, "ipptool2book", ipptool2book, "convert queue with ipptool output to book"},
    3939  {1, "kill",       kill_job,      "kill job"},
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/pantasks/task_nice.c

    r32632 r36680  
    44
    55  char *endptr = NULL;
    6   int priority;
     6  int nicelevel;
    77  Task *task;
    88
    99  if (argc != 2) {
    10     gprint (GP_ERR, "USAGE: nice (priority)\n");
     10    gprint (GP_ERR, "USAGE: nice (nicelevel)\n");
    1111    return (FALSE);
    1212  }
     
    2020  }
    2121
    22   priority = strtol (argv[1], &endptr, 10);
     22  nicelevel = strtol (argv[1], &endptr, 10);
    2323  if (*endptr) goto fail;
    24   if (priority < 0) goto fail;
    25   if (priority > 20) goto fail;
     24  if (nicelevel < 0) goto fail;
     25  if (nicelevel > 20) goto fail;
    2626
    27   task[0].priority = priority;
     27  task[0].nicelevel = nicelevel;
    2828  JobTaskUnlock();
    2929  return (TRUE);
    3030
    3131fail:
    32     gprint (GP_ERR, "ERROR: nice (priority) -- priority must be an integer 0 to 20\n");
     32    gprint (GP_ERR, "ERROR: nice (nicelevel) -- nicelevel must be an integer 0 to 20\n");
    3333    return (FALSE);
    3434}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/pclient/job.c

    r32632 r36680  
    33int job (int argc, char **argv) {
    44
    5   int i, N, pid, status, priority;
     5  int i, N, pid, status, nicelevel;
    66  char **targv;
    77
    8   priority = 0;
     8  nicelevel = 0;
    99  if ((N = get_argument (argc, argv, "-nice"))) {
    1010    remove_argument (N, &argc, argv);
    11     priority = atoi (argv[N]);
     11    nicelevel = atoi (argv[N]);
    1212    remove_argument (N, &argc, argv);
    1313  }
     
    6262
    6363  /* set nice level for the child process */
    64   if (priority) {
    65       status = setpriority (PRIO_PROCESS, pid, priority);
     64  if (nicelevel) {
     65      status = setpriority (PRIO_PROCESS, pid, nicelevel);
    6666      if (status == -1) {
    67           gprint (GP_ERR, "error setting priority\n");
     67          gprint (GP_ERR, "error setting nicelevel\n");
    6868          perror ("setpriority: ");
    6969          exit (2);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/pcontrol/CheckBusyJob.c

    r28242 r36680  
    9999
    100100  // XXX runaway job if output too large?
    101   if (job[0].stdout_buf.size > 0x1000000) abort();
    102   if (job[0].stderr_buf.size > 0x1000000) abort();
     101  if (job[0].stdout_buf.size > 0x10000000) abort();
     102  if (job[0].stderr_buf.size > 0x10000000) abort();
    103103
    104104  // job has exited : move to DONE stack
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/pcontrol/JobOps.c

    r32632 r36680  
    6161}
    6262
     63int GetJobStackIDbyName (char *name) {
     64  if (!strcasecmp (name, "ALLJOBS"))  return PCONTROL_JOB_ALLJOBS;
     65  if (!strcasecmp (name, "PENDING"))  return PCONTROL_JOB_PENDING;
     66  if (!strcasecmp (name, "BUSY"))     return PCONTROL_JOB_BUSY   ;
     67  if (!strcasecmp (name, "RESP"))     return PCONTROL_JOB_RESP   ;
     68  if (!strcasecmp (name, "DONE"))     return PCONTROL_JOB_DONE   ;
     69  if (!strcasecmp (name, "KILL"))     return PCONTROL_JOB_KILL   ;
     70  if (!strcasecmp (name, "EXIT"))     return PCONTROL_JOB_EXIT   ;
     71  if (!strcasecmp (name, "CRASH"))    return PCONTROL_JOB_CRASH  ;
     72  return (PCONTROL_JOB_NONE);
     73}
     74
    6375Stack *GetJobStack (int StackID) {
    6476  switch (StackID) {
     
    195207}
    196208
    197 IDtype AddJob (char *hostname, JobMode mode, int timeout, int priority, int argc, char **argv, int Nxhosts, char **xhosts) {
     209IDtype AddJob (char *hostname, JobMode mode, int timeout, int nicelevel, int argc, char **argv, int Nxhosts, char **xhosts) {
    198210
    199211  int JobID;
     
    220232
    221233  job[0].mode     = mode;
    222   job[0].priority = priority;
     234  job[0].nicelevel = nicelevel;
    223235
    224236  job[0].state = 0;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/pcontrol/StartJob.c

    r32632 r36680  
    2525  bzero (line, Nline);
    2626  strcpy (line, "job");
    27   if (job[0].priority) {
     27  if (job[0].nicelevel) {
    2828    char tmp[64];
    29     snprintf (tmp, 64, " -nice %d", job[0].priority);
     29    snprintf (tmp, 64, " -nice %d", job[0].nicelevel);
    3030    strcat (line, tmp);
    3131  }
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/pcontrol/job.c

    r32632 r36680  
    55  char *Host = NULL;
    66  char **targv = NULL;
    7   int i, N, Mode, targc, Timeout, priority;
     7  int i, N, Mode, targc, Timeout, nicelevel;
    88  IDtype JobID;
    99  char **xhosts = NULL;
     
    4343  }
    4444
    45   priority = 0;
     45  nicelevel = 0;
    4646  if ((N = get_argument (argc, argv, "-nice"))) {
    4747    remove_argument (N, &argc, argv);
    48     priority = atoi (argv[N]);
     48    nicelevel = atoi (argv[N]);
    4949    remove_argument (N, &argc, argv);
    5050  }
     
    7676
    7777  // a JobID < 0 mean the job was not accepted
    78   JobID = AddJob (Host, Mode, Timeout, priority, targc, targv, Nxhosts, xhosts);
     78  JobID = AddJob (Host, Mode, Timeout, nicelevel, targc, targv, Nxhosts, xhosts);
    7979  gprint (GP_LOG, "JobID: %d\n", (int) JobID);
    8080  return (TRUE);
     
    8282 usage:
    8383    gprint (GP_ERR, "USAGE: job [options] (arg0) (arg1) ... (argN)\n");
    84     gprint (GP_ERR, "  options: -host, +host, -timeout, -xhost (host)\n");
     84    gprint (GP_ERR, "  options: -host, +host, -timeout, -xhost (host) -nice (level)\n");
    8585    gprint (GP_ERR, "  arguments of the form @MAX_THREADS@ will be replaced when the job is launched\n");
    8686
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/pcontrol/jobstack.c

    r12470 r36680  
    2222  /* print list */
    2323  LockStack (stack);
    24   gprint (GP_LOG, "Njobs: %d\n", stack[0].Nobject);
     24  gprint (GP_LOG, "BEGIN BLOCK Njobs: %d\n", stack[0].Nobject);
    2525  for (i = 0; i < stack[0].Nobject; i++) {
    2626    job = stack[0].object[i];
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/opihi/pcontrol/status.c

    r32632 r36680  
    11# include "pcontrol.h"
    22
    3 int PrintJobStack (int Nstack);
     3int PrintJobStack (int Nstack, char *command, char *hostname, int state, float age);
    44int PrintHostStack (int Nstack);
    55
    66int status (int argc, char **argv) {
    77
    8   PrintJobStack (PCONTROL_JOB_ALLJOBS);
    9   PrintHostStack (PCONTROL_HOST_ALLHOSTS);
     8  int N;
     9
     10  if (get_argument (argc, argv, "-h")) goto usage;
     11  if (get_argument (argc, argv, "-help")) goto usage;
     12  if (get_argument (argc, argv, "--help")) goto usage;
     13
     14  /* I would like to add the following options:
     15   * strsub on argv[0]
     16   * strsub on hostname, realhost
     17   * list hostname and realhost
     18   * filter by state
     19   * filter by dtime
     20  */
     21
     22  // -cmd (cmd)
     23  // -host (hostname)
     24  // -state (busy, pending, done, kill, exit, crash, resp, hung
     25  // -age (seconds?) (minutes?)
     26  // -nohost
     27
     28  char *COMMAND = NULL;
     29  if ((N = get_argument (argc, argv, "-cmd"))) {
     30    remove_argument (N, &argc, argv);
     31    COMMAND = strcreate (argv[N]);
     32    remove_argument (N, &argc, argv);
     33  }
     34
     35  char *HOSTNAME = NULL;
     36  if ((N = get_argument (argc, argv, "-host"))) {
     37    remove_argument (N, &argc, argv);
     38    HOSTNAME = strcreate (argv[N]);
     39    remove_argument (N, &argc, argv);
     40  }
     41
     42  int STATE = PCONTROL_JOB_ALLJOBS;
     43  if ((N = get_argument (argc, argv, "-state"))) {
     44    remove_argument (N, &argc, argv);
     45    STATE = GetJobStackIDbyName (argv[N]);
     46    remove_argument (N, &argc, argv);
     47    if (STATE == PCONTROL_JOB_NONE) goto usage;
     48  }
     49
     50  float AGE = 0.0;
     51  if ((N = get_argument (argc, argv, "-age"))) {
     52    remove_argument (N, &argc, argv);
     53    AGE = atof (argv[N]);
     54    remove_argument (N, &argc, argv);
     55  }
     56
     57  int SHOWHOST = TRUE;
     58  if ((N = get_argument (argc, argv, "-nohost"))) {
     59    remove_argument (N, &argc, argv);
     60    SHOWHOST = FALSE;
     61  }
     62  if ((N = get_argument (argc, argv, "+jobs"))) {
     63    remove_argument (N, &argc, argv);
     64    SHOWHOST = FALSE;
     65  }
     66
     67  int SHOWJOBS = TRUE;
     68  if ((N = get_argument (argc, argv, "-nojobs"))) {
     69    remove_argument (N, &argc, argv);
     70    SHOWJOBS = FALSE;
     71  }
     72  if ((N = get_argument (argc, argv, "+host"))) {
     73    remove_argument (N, &argc, argv);
     74    SHOWJOBS = FALSE;
     75  }
     76
     77  if (SHOWJOBS) {
     78    PrintJobStack (PCONTROL_JOB_ALLJOBS, COMMAND, HOSTNAME, STATE, AGE);
     79  }
     80  if (SHOWHOST) {
     81    PrintHostStack (PCONTROL_HOST_ALLHOSTS);
     82  }
    1083
    1184  return (TRUE);
     85
     86usage:
     87  gprint (GP_ERR, "USAGE: status [-cmd command] [-host hostname] [-state state] [-age seconds] [+jobs,-nohost] [+host,-nojobs]\n");
     88  return FALSE;
    1289}
    1390
    14 int PrintJobStack (int Nstack) {
     91int PrintJobStack (int Nstack, char *command, char *hostname, int state, float age) {
    1592
    1693  int i, j, Nobject;
     
    30107    job = stack[0].object[i];
    31108    ASSERT (job != NULL, "programming error");
    32     if (job[0].realhost == NULL) {
    33         gprint (GP_LOG, "%3d %9s ", i, job[0].hostname);
    34     } else {
    35         gprint (GP_LOG, "%3d %9s ", i, job[0].realhost);
    36     }
    37     gprint (GP_LOG, "%7s  ", GetJobStackName (job[0].state));
     109
     110    char *thishost = (job[0].realhost == NULL) ? job[0].hostname : job[0].realhost;
    38111
    39112    switch (job[0].state) {
     
    45118        gettimeofday (&now, (void *) NULL);
    46119        dtime = DTIME (now, job[0].start);
    47         gprint (GP_LOG, "%8.2f ", dtime);
    48120        break;
    49121
     
    55127      default:
    56128        dtime = DTIME (job[0].stop, job[0].start);
    57         gprint (GP_LOG, "%8.2f ", dtime);
    58129        break;
    59130    }
    60131
     132    // check on the filters
     133    if (command) {
     134      if (!strstr (job[0].argv[0], command)) continue;
     135    }
     136    if (hostname) {
     137      if (!strstr (thishost, hostname)) continue;
     138    }
     139    if (age > 0.0) {
     140      if (dtime < age) continue;
     141    }
     142    if (state != PCONTROL_JOB_ALLJOBS) {
     143      // allow PCONTROL_JOB_RESP == BUSY
     144      int validState = FALSE;
     145      validState |= (state == PCONTROL_JOB_RESP) && (job[0].state == PCONTROL_JOB_BUSY);
     146      validState |= (state == PCONTROL_JOB_BUSY) && (job[0].state == PCONTROL_JOB_RESP);
     147      validState |= (state == job[0].state);
     148      if (!validState) continue;
     149    }
     150
     151    gprint (GP_LOG, "%3d %9s ", i, thishost);
     152    gprint (GP_LOG, "%7s  ", GetJobStackName (job[0].state));
     153    gprint (GP_LOG, "%8.2f ", dtime);
     154
    61155    PrintID (GP_LOG, job[0].JobID);
    62     gprint (GP_LOG, " %2d ", job[0].priority);
     156    gprint (GP_LOG, " %2d ", job[0].nicelevel);
    63157    for (j = 0; j < job[0].argc; j++) {
    64158      gprint (GP_LOG, "%s ", job[0].argv[j]);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/photdbc/src/find_images.c

    r30616 r36680  
    2525  tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    2626  tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    27   strcpy (tcoords.ctype, "RA---TAN");
     27  strcpy (tcoords.ctype, "DEC--TAN");
    2828
    2929  timage = gfits_table_get_Image (&db[0].ftable, &Ntimage, &db[0].swapped);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/photdbc/src/join_stars.c

    r29938 r36680  
    5757  tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    5858  tcoords.Npolyterms = 0;
    59   strcpy (tcoords.ctype, "RA---TAN");
     59  strcpy (tcoords.ctype, "DEC--TAN");
    6060 
    6161  /* project & sort coordinates in local linear frame */
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/Makefile

    r35416 r36680  
    6969$(SRC)/resort_catalog.$(ARCH).o  \
    7070$(SRC)/BrightCatalog.$(ARCH).o  \
     71$(SRC)/assign_images.$(ARCH).o \
     72$(SRC)/launch_region_hosts.$(ARCH).o \
     73$(SRC)/relastro_parallel_images.$(ARCH).o \
     74$(SRC)/relastro_parallel_regions.$(ARCH).o \
     75$(SRC)/MeanPosIO.$(ARCH).o \
     76$(SRC)/share_mean_pos.$(ARCH).o \
     77$(SRC)/share_images_pos.$(ARCH).o \
     78$(SRC)/ImagePosIO.$(ARCH).o \
     79$(SRC)/ImageTable.$(ARCH).o \
     80$(SRC)/markObjects.$(ARCH).o \
     81$(SRC)/indexCatalogs.$(ARCH).o \
     82$(SRC)/syncfile.$(ARCH).o \
    7183$(SRC)/relastroVisual.$(ARCH).o
    7284
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/include/relastro.h

    r35763 r36680  
    66# include <pthread.h>
    77
     8# define MARKTIME(MSG,...) {                    \
     9    gettimeofday (&stopTimer, (void *) NULL);   \
     10    float dtime = DTIME (stopTimer, startTimer);        \
     11    fprintf (stderr, MSG, __VA_ARGS__); }
     12
     13# define INITTIME \
     14  struct timeval startTimer, stopTimer; \
     15  gettimeofday (&startTimer, (void *) NULL);
     16
    817// choose off_t or int depending on full-scale relphot analysis resources
    918// # define IDX_T off_t
     
    2029typedef enum {FIT_NONE, FIT_AVERAGE, FIT_PM_ONLY, FIT_PAR_ONLY, FIT_PM_AND_PAR} FitMode;
    2130
    22 typedef enum {TARGET_NONE, TARGET_SIMPLE, TARGET_CHIPS, TARGET_MOSAICS, TARGET_HIGH_SPEED, TARGET_MERGE_SOURCE, TARGET_UPDATE_OBJECTS, TARGET_UPDATE_OFFSETS, TARGET_LOAD_OBJECTS, TARGET_HPM} FitTarget;
     31typedef enum {OP_NONE, OP_IMAGES, OP_HIGH_SPEED, OP_MERGE_SOURCE, OP_UPDATE_OBJECTS, OP_UPDATE_OFFSETS, OP_LOAD_OBJECTS, OP_HPM, OP_PARALLEL_REGIONS, OP_PARALLEL_IMAGES} RelastroOp;
     32
     33typedef enum {TARGET_NONE, TARGET_SIMPLE, TARGET_CHIPS, TARGET_MOSAICS} FitTarget;
    2334
    2435typedef enum {
     
    3041  MARK_BIG_OFFSET    = 0x0010,
    3142} MeasurementMask;
     43
     44typedef struct {
     45  float R;
     46  float D;
     47  unsigned int objID;
     48  unsigned int catID;
     49} MeanPos;
     50
     51typedef struct {
     52  Coords coords;
     53  float dXpixSys;
     54  float dYpixSys;
     55  unsigned int imageID;
     56  int nFitAstrom;
     57  int flags;
     58} ImagePos;
    3259
    3360typedef struct {
     
    93120  unsigned int start;
    94121  unsigned int stop;
     122  off_t myImage;
    95123  float Mcal;
    96124  float dMcal;
     
    113141} StatType;
    114142
    115 # define MARKTIME(MSG,...) { \
    116   float dtime; \
    117   gettimeofday (&stop, (void *) NULL); \
    118   dtime = DTIME (stop, start); \
    119   fprintf (stderr, MSG, __VA_ARGS__); }
    120 
    121143/* global variables set in parameter file */
    122144# define DVO_MAX_PATH 1024
     
    129151char   SKY_TABLE[DVO_MAX_PATH];
    130152int    SKY_DEPTH;  /** XXX EAM : depth of catalog tables, fix usage */
     153
     154// globals for parallel region operations
     155char  *REGION_FILE;
     156char  *IMAGE_TABLE;
     157int    REGION_HOST_ID;
     158int    PARALLEL_REGIONS_MANUAL;
    131159
    132160int          HOST_ID;
     
    208236FitMode FIT_MODE;
    209237
     238RelastroOp RELASTRO_OP;
    210239FitTarget FIT_TARGET;
    211240
     
    450479int hpm_catalogs_parallel (SkyList *skylist);
    451480int hpm_objects (SkyRegion *region, Catalog *catalog);
     481
     482int strextend (char *input, char *format,...);
     483int launch_region_hosts (RegionHostTable *regionHosts);
     484
     485int assign_images (FITS_DB *db, RegionHostTable *regionHosts);
     486int select_images_hostregion (RegionHostTable *regionHosts, Image *image, off_t Nimage);
     487int calculate_image_bounds (Image *image, double *rmin, double *rmax, double *dmin, double *dmax, double Rmid);
     488int calculate_host_image_bounds (RegionHostTable *regionHosts);
     489int find_host_for_coords (RegionHostTable *regionHosts, double Rc, double Dc);
     490
     491int relastro_parallel_regions ();
     492int relastro_parallel_images ();
     493
     494char *make_filename (char *dirname, char *hostname, int hostID, char *tailname);
     495int check_sync_file (char *filename, int nloop);
     496int clear_sync_file (char *filename);
     497int update_sync_file (char *filename, int nloop);
     498
     499int share_mean_pos (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     500int slurp_mean_pos (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     501int set_mean_pos (MeanPos *meanpos, Average *average);
     502MeanPos *merge_mean_pos (MeanPos *target, int *ntarget, MeanPos *source, int Nsource);
     503
     504int MeanPosSave(char *filename, MeanPos *meanpos, off_t Nmeanpos);
     505MeanPos *MeanPosLoad(char *filename, off_t *nmeanpos);
     506
     507int indexCatalogs (Catalog *catalog, int Ncatalog);
     508int catID_and_objID_to_seq (int catID, int objID, int *catSeq, off_t *objSeq);
     509
     510int markObjects (Catalog *catalog, int Ncatalog);
     511
     512int ImagePosSave(char *filename, ImagePos *image_pos, off_t Nimage_pos);
     513ImagePos *ImagePosLoad(char *filename, off_t *nimage_pos);
     514
     515int share_image_pos (RegionHostTable *regionHosts, int nloop);
     516int slurp_image_pos (RegionHostTable *regionHosts, int nloop);
     517ImagePos *merge_image_pos (ImagePos *target, int *ntarget, ImagePos *source, int Nsource);
     518int set_image_pos (ImagePos *image_pos, Image *image);
     519
     520Image *ImageTableLoad(char *filename, off_t *nimage);
     521int ImageTableSave (char *filename, Image *images, off_t Nimages);
     522int select_mosaics_hostregion (RegionHostTable *regionHosts, Image *image, off_t Nimage);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/ConfigInit.c

    r35105 r36680  
    1818  if (VERBOSE) fprintf (stderr, "loaded config file: %s\n", file);
    1919
    20   GetConfig (config, "RELASTRO_SIGMA_LIM",         "%lf", 0, &SIGMA_LIM); // exclude measurements on this basis
    21   GetConfig (config, "RELASTRO_SRC_MEAS_TOOFEW",   "%d",  0, &SRC_MEAS_TOOFEW);
     20  // set defaults for all of these if they are not used by parallel / remote clients
     21  if (!ScanConfig (config, "RELASTRO_SIGMA_LIM",         "%lf", 0, &SIGMA_LIM))       SIGMA_LIM = 0.01;
     22  if (!ScanConfig (config, "RELASTRO_SRC_MEAS_TOOFEW",   "%d",  0, &SRC_MEAS_TOOFEW)) SRC_MEAS_TOOFEW = 3;
    2223
    2324  if (!ScanConfig (config, "RELASTRO_IMFIT_CLIP_NITER",    "%d",  0, &IMFIT_CLIP_NITER))    IMFIT_CLIP_NITER  = 3;
     
    2526  if (!ScanConfig (config, "RELASTRO_IMFIT_SYS_SIGMA_LIM", "%lf", 0, &IMFIT_SYS_SIGMA_LIM)) IMFIT_SYS_SIGMA_LIM = 0.01;
    2627
    27   GetConfig (config, "PM_DT_MIN",              "%lf", 0, &PM_DT_MIN);
    28   GetConfig (config, "PM_TOOFEW",              "%d",  0, &PM_TOOFEW);
    29   GetConfig (config, "POS_TOOFEW",             "%d",  0, &POS_TOOFEW);
     28  if (!ScanConfig (config, "PM_DT_MIN",              "%lf", 0, &PM_DT_MIN))        PM_DT_MIN = 0.25;   
     29  if (!ScanConfig (config, "PM_TOOFEW",              "%d",  0, &PM_TOOFEW))        PM_TOOFEW = 4;   
     30  if (!ScanConfig (config, "POS_TOOFEW",             "%d",  0, &POS_TOOFEW))       POS_TOOFEW = 1; 
     31  if (!ScanConfig (config, "PAR_FACTOR_MIN",         "%lf", 0, &PAR_FACTOR_MIN))   PAR_FACTOR_MIN = 0.2;
     32  if (!ScanConfig (config, "RELASTRO_MAP_NX",        "%d",  0, &NX_MAP))           NX_MAP = 5;
     33  if (!ScanConfig (config, "RELASTRO_MAP_NY",        "%d",  0, &NY_MAP))           NY_MAP = 5;
     34  if (!ScanConfig (config, "RELASTRO_DPOS_MAX",      "%lf", 0, &DPOS_MAX))         DPOS_MAX = 6.0;   
     35  if (!ScanConfig (config, "ADDSTAR_RADIUS",         "%lf", 0, &ADDSTAR_RADIUS))   ADDSTAR_RADIUS = 1.0;
    3036
    31   GetConfig (config, "PAR_FACTOR_MIN",         "%lf", 0, &PAR_FACTOR_MIN);
    32 
    33   GetConfig (config, "RELASTRO_MAP_NX",        "%d",  0, &NX_MAP);
    34   GetConfig (config, "RELASTRO_MAP_NY",        "%d",  0, &NY_MAP);
    35   GetConfig (config, "RELASTRO_DPOS_MAX",      "%lf", 0, &DPOS_MAX);
    36   GetConfig (config, "ADDSTAR_RADIUS",         "%lf", 0, &ADDSTAR_RADIUS);
    37 
    38   if (!ScanConfig (config, "USE_FIXED_PIXCOORDS", "%d", 0, &USE_FIXED_PIXCOORDS)) {
    39     USE_FIXED_PIXCOORDS = FALSE;
    40   }
     37  if (!ScanConfig (config, "USE_FIXED_PIXCOORDS", "%d", 0, &USE_FIXED_PIXCOORDS))  USE_FIXED_PIXCOORDS = FALSE;
    4138
    4239  // force CATDIR to be absolute (so parallel mode will work)
     
    5653  sprintf (ImageCat, "%s/Images.dat", CATDIR);
    5754
    58   if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) {
    59     SKY_DEPTH = 2;
    60   }
    61   if (!ScanConfig (config, "SKY_TABLE",         "%s",  0, SKY_TABLE)) {
    62     SKY_TABLE[0] = 0;
    63   }
     55  if (!ScanConfig (config, "SKY_DEPTH",         "%d",  0, &SKY_DEPTH)) SKY_DEPTH = 2;
     56  if (!ScanConfig (config, "SKY_TABLE",         "%s",  0, SKY_TABLE)) SKY_TABLE[0] = 0;
    6457
    6558  if (*CATMODE == 0) strcpy (CATMODE, "RAW");
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/ImageOps.c

    r35763 r36680  
    226226    Measure *measureBig = &catalog[cat].measure[meas];
    227227    int TESTPT = FALSE;
    228     TESTPT |= (measureBig->imageID == CAT_ID_SRC) && (measureBig->detID == OBJ_ID_SRC);
    229     TESTPT |= (measureBig->imageID == CAT_ID_DST) && (measureBig->detID == OBJ_ID_DST);
     228    TESTPT |= CAT_ID_SRC && OBJ_ID_SRC && (measureBig->imageID == CAT_ID_SRC) && (measureBig->detID == OBJ_ID_SRC);
     229    TESTPT |= CAT_ID_DST && OBJ_ID_DST && (measureBig->imageID == CAT_ID_DST) && (measureBig->detID == OBJ_ID_DST);
    230230    if (TESTPT) {
    231231      fprintf (stderr, "got test det\n");
     
    462462    int TESTPT = FALSE;
    463463
    464     TESTPT |= (measure->imageID == CAT_ID_SRC) && (measure->detID == OBJ_ID_SRC);
    465     TESTPT |= (measure->imageID == CAT_ID_DST) && (measure->detID == OBJ_ID_DST);
     464    TESTPT |= CAT_ID_SRC && OBJ_ID_SRC && (measure->imageID == CAT_ID_SRC) && (measure->detID == OBJ_ID_SRC);
     465    TESTPT |= CAT_ID_DST && OBJ_ID_DST && (measure->imageID == CAT_ID_DST) && (measure->detID == OBJ_ID_DST);
    466466    if (TESTPT) {
    467467      fprintf (stderr, "got test det\n");
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/MosaicOps.c

    r27581 r36680  
    1111
    1212// list of mosaic associated with each image 
    13 static off_t    Nmosaic_for_images; // number of images (for off_ternal checks)
     13static off_t    Nmosaic_for_images; // number of images (for internal checks)
    1414static off_t    *mosaic_for_images; // array of: image -> mosaic
    1515
     
    105105    mosaic[Nmosaic].secz  = image[i].secz;
    106106    mosaic[Nmosaic].coords = image[i].coords;
     107    mosaic[Nmosaic].myImage = i;
    107108
    108109    // init the mosaic_own_images array data
     
    135136  ALLOCATE (mosaic_for_images, off_t, Nmosaic_for_images);
    136137
     138  // emit an error if we miss mosaics, but stop if we miss too many
     139  int NmissMosaic = 0;
     140  int NtestMosaic = 0;
     141
    137142  /* now assign the WRP images to these mosaics */
    138143  for (i = 0; i < Nimage; i++) {
     
    140145
    141146    if (strcmp(&image[i].coords.ctype[4], "-WRP")) continue;
     147    NtestMosaic ++;
    142148
    143149    /* set image time range */
     
    147153    Nmos = getMosaicByTimes (start, stop, startMos, stopMos, indexMos);
    148154    if (Nmos == -1) {
    149       fprintf (stderr, "cannot match mosaic for %s\n", image[i].name);
     155      if (NmissMosaic < 1000) {
     156        fprintf (stderr, "cannot match mosaic for %s\n", image[i].name);
     157      }
     158      NmissMosaic ++;
    150159      continue;
    151160    }
     
    164173  }
    165174
     175  fprintf (stderr, "mosaic matching : %d of possible %d failed to match\n", NmissMosaic, NtestMosaic);
     176  if (NmissMosaic > 0.5*NtestMosaic) {
     177    fprintf (stderr, "serious problem with mosaic matching\n");
     178    exit (5);
     179  }
     180
    166181  free (startMos);
    167182  free (stopMos);
     
    250265  if (im >= Nmosaic_for_images) abort();
    251266
    252   // search for the mosaic that
     267  // search for the mosaic that matches this image
    253268  mos = mosaic_for_images[im];
    254269  if (mos < 0) return NULL;
     
    256271  return &mosaic[mos];
    257272}
     273
     274// extend each host image table to include the mosaic 'images' needed by the host
     275int select_mosaics_hostregion (RegionHostTable *regionHosts, Image *image, off_t Nimage) {
     276
     277  int i;
     278  off_t j;
     279  char *mosaicUsed;
     280
     281  ALLOCATE (mosaicUsed, char, Nmosaic);
     282
     283  // we need to add the mosaics to each of the region hosts lists of images
     284  for (i = 0; i < regionHosts->Nhosts; i++) {
     285
     286    int Nadd = 0;
     287    int NADD = 100;
     288    off_t *addMosaic = NULL;
     289    ALLOCATE (addMosaic, off_t, NADD);
     290
     291    // reset the mosaicUsed flags (valid only for this host)
     292    memset (mosaicUsed, 0, Nmosaic * sizeof(char));
     293
     294    RegionHostInfo *host = &regionHosts->hosts[i];
     295
     296    // find the mosaics associated with a given
     297    for (j = 0; j < host->Nimage; j++) {
     298
     299      int im = host->imseq[j];
     300     
     301      if (im < 0) abort();
     302      if (im >= Nmosaic_for_images) abort();
     303
     304      // search for the mosaic that matches this image (skip unmatched images)
     305      off_t mos = mosaic_for_images[im];
     306      if (mos < 0) continue;
     307
     308      if (mosaicUsed[mos]) continue;
     309
     310      mosaicUsed[mos] = TRUE;
     311      addMosaic[Nadd] = mos;
     312      Nadd ++;
     313     
     314      CHECK_REALLOCATE (addMosaic, off_t, NADD, Nadd, 100);
     315    }
     316
     317    REALLOCATE (host->image, Image, host->Nimage + Nadd);
     318
     319    for (j = 0; j < Nadd; j++) {
     320      off_t mos = addMosaic[j];
     321      off_t mos_im = mosaic[mos].myImage;
     322
     323      host->image[host->Nimage + j] = image[mos_im];
     324    }
     325   
     326    host->Nimage += Nadd;
     327  }
     328  return TRUE;
     329}
     330
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/StarMaps.c

    r35105 r36680  
    5959  off_t i, N, Nimages;
    6060  int xbin, ybin;
    61   struct timeval start, stop;
    6261
    63   gettimeofday (&start, (void *) NULL);
     62  INITTIME;
    6463
    6564  // Images *images = getimages(&Nimages, NULL); return value ignored
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/UpdateObjects.c

    r35763 r36680  
    11# include "relastro.h"
    22
    3 static off_t   Nmax;
     3static off_t Nmax;
    44static double *X, *dX;
    55static double *Y, *dY;
     
    3636  ALLOCATE (pX, double, MAX (1, Nmax));
    3737  ALLOCATE (pY, double, MAX (1, Nmax));
     38
     39
     40void freeObjectData () {
     41
     42  free (R);
     43  free (D);
     44  free (T);
     45  free (X);
     46  free (Y);
     47
     48  free (dR);
     49  free (dD);
     50  free (dT);
     51  free (dX);
     52  free (dY);
     53
     54  free (pX);
     55  free (pY);
    3856
    3957
     
    6785  coords.pc1_2  = coords.pc2_1 = 0.0;
    6886  coords.Npolyterms = 1;
    69   strcpy (coords.ctype, "RA---SIN");
     87  strcpy (coords.ctype, "DEC--SIN");
    7088
    7189  XVERB = FALSE;
     
    205223      if (((mode == FIT_PM_ONLY) || (mode == FIT_PM_AND_PAR)) && (N <= PM_TOOFEW)) mode = FIT_AVERAGE;
    206224
    207       if (FIT_TARGET == TARGET_HIGH_SPEED) {
     225      if (RELASTRO_OP == OP_HIGH_SPEED) {
    208226          Tmean = 0.5*(Tmax - Tmin);
    209227      } else {
     
    412430  }
    413431
     432  freeObjectData ();
     433
    414434  if (VERBOSE) fprintf (stderr, "fitted "OFF_T_FMT" objects ("OFF_T_FMT" ave, "OFF_T_FMT" pm, "OFF_T_FMT" par), skipped "OFF_T_FMT", "OFF_T_FMT" have too large an offset\n",  (NaveSum + NpmSum + NparSum),  NaveSum,  NpmSum,  NparSum,  NskipSum, NoffSum);
    415435  return (TRUE);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/args.c

    r35763 r36680  
    1313  /* possible operations */
    1414  FIT_TARGET = TARGET_NONE;
     15  RELASTRO_OP = OP_NONE;
    1516  FIT_MODE = FIT_AVERAGE;
    1617
     
    2122    if (N > argc - 6) usage_merge_source();
    2223    if (strcmp(argv[N+3], "into")) usage_merge_source();
    23     FIT_TARGET = TARGET_MERGE_SOURCE;
     24    RELASTRO_OP = OP_MERGE_SOURCE;
    2425    remove_argument (N, &argc, argv);
    2526    OBJ_ID_SRC = strtol(argv[N], &endptr, 0);
     
    4344  if ((N = get_argument (argc, argv, "-update-objects"))) {
    4445    remove_argument (N, &argc, argv);
    45     FIT_TARGET = TARGET_UPDATE_OBJECTS;
     46    RELASTRO_OP = OP_UPDATE_OBJECTS;
    4647  }
    4748
    4849  if ((N = get_argument (argc, argv, "-update-offsets"))) {
    4950    remove_argument (N, &argc, argv);
    50     FIT_TARGET = TARGET_UPDATE_OFFSETS;
     51    RELASTRO_OP = OP_UPDATE_OFFSETS;
     52  }
     53
     54  // elements needed for parallel regions / parallel images
     55  REGION_FILE = NULL;
     56  if ((N = get_argument (argc, argv, "-region-hosts"))) {
     57    remove_argument (N, &argc, argv);
     58    REGION_FILE = strcreate (argv[N]);
     59    remove_argument (N, &argc, argv);
     60  }
     61
     62  REGION_HOST_ID = 0;
     63  if ((N = get_argument (argc, argv, "-region-hostID"))) {
     64    remove_argument (N, &argc, argv);
     65    REGION_HOST_ID = atoi (argv[N]);
     66    remove_argument (N, &argc, argv);
     67  }
     68
     69  IMAGE_TABLE = NULL;
     70  if ((N = get_argument (argc, argv, "-parallel-images"))) {
     71    remove_argument (N, &argc, argv);
     72    RELASTRO_OP = OP_PARALLEL_IMAGES;
     73    if (N >= argc) usage();
     74    IMAGE_TABLE = strcreate (argv[N]);
     75    remove_argument (N, &argc, argv);
     76    if (!REGION_FILE) usage();
     77  }
     78
     79  if ((N = get_argument (argc, argv, "-images"))) {
     80    remove_argument (N, &argc, argv);
     81    RELASTRO_OP = OP_IMAGES;
     82  }
     83
     84  PARALLEL_REGIONS_MANUAL = FALSE;
     85  if ((N = get_argument (argc, argv, "-parallel-regions"))) {
     86    remove_argument (N, &argc, argv);
     87    RELASTRO_OP = OP_PARALLEL_REGIONS;
     88    if (!REGION_FILE) usage();
     89    if ((N = get_argument (argc, argv, "-parallel-regions-manual"))) {
     90      remove_argument (N, &argc, argv);
     91      PARALLEL_REGIONS_MANUAL = TRUE;
     92    }
    5193  }
    5294
     
    90132    // XXX include a parallax / no-parallax option
    91133    if (N >= argc - 4) usage();
    92     FIT_TARGET = TARGET_HIGH_SPEED;
     134    RELASTRO_OP = OP_HIGH_SPEED;
    93135    remove_argument (N, &argc, argv);
    94136    PHOTCODE_A_LIST = strcreate(argv[N]);
     
    104146  if ((N = get_argument (argc, argv, "-hpm"))) {
    105147    if (N >= argc - 2) usage();
    106     FIT_TARGET = TARGET_HPM;
     148    RELASTRO_OP = OP_HPM;
    107149    remove_argument (N, &argc, argv);
    108150    RADIUS = atof(argv[N]);
     
    116158    remove_argument (N, &argc, argv);
    117159    PARALLEL_OUTPUT = TRUE;
    118     if ((FIT_TARGET != TARGET_HIGH_SPEED) && (FIT_TARGET != TARGET_HPM)) {
     160    if ((RELASTRO_OP != OP_HIGH_SPEED) && (RELASTRO_OP != OP_HPM)) {
    119161      fprintf (stderr, "-parallel-output only valid for -high-speed or -hpm modes\n");
    120162      exit (1);
     
    143185  }
    144186
    145   if (FIT_TARGET == TARGET_NONE) usage();
     187  if (RELASTRO_OP == OP_NONE) usage();
     188
     189  if (((RELASTRO_OP == OP_IMAGES) || (RELASTRO_OP == OP_PARALLEL_REGIONS) || (RELASTRO_OP == OP_PARALLEL_IMAGES)) && (FIT_TARGET == TARGET_NONE)) usage();
    146190
    147191  /* specify portion of the sky : allow default of all sky? */
     
    427471
    428472  /* possible operations */
    429   FIT_TARGET = TARGET_NONE;
     473  RELASTRO_OP = TARGET_NONE;
    430474  FIT_MODE = FIT_AVERAGE;
    431475
     
    437481  BCATALOG = NULL;
    438482
     483  REGION_FILE = NULL;
     484  REGION_HOST_ID = 0;
     485  IMAGE_TABLE = NULL;
     486  PARALLEL_REGIONS_MANUAL = FALSE;
     487
    439488  HOST_ID = 0;
    440489  if ((N = get_argument (argc, argv, "-hostID"))) {
     
    457506    BCATALOG = strcreate(argv[N]);
    458507    remove_argument (N, &argc, argv);
    459     FIT_TARGET = TARGET_LOAD_OBJECTS;
     508    RELASTRO_OP = OP_LOAD_OBJECTS;
    460509  }
    461510
    462511  if ((N = get_argument (argc, argv, "-update-objects"))) {
    463512    remove_argument (N, &argc, argv);
    464     FIT_TARGET = TARGET_UPDATE_OBJECTS;
     513    RELASTRO_OP = OP_UPDATE_OBJECTS;
    465514  }
    466515
    467516  if ((N = get_argument (argc, argv, "-update-offsets"))) {
    468517    remove_argument (N, &argc, argv);
    469     FIT_TARGET = TARGET_UPDATE_OFFSETS;
     518    RELASTRO_OP = OP_UPDATE_OFFSETS;
    470519  }
    471520
     
    487536    // XXX include a parallax / no-parallax option
    488537    if (N >= argc - 5) usage_client();
    489     FIT_TARGET = TARGET_HIGH_SPEED;
     538    RELASTRO_OP = OP_HIGH_SPEED;
    490539    remove_argument (N, &argc, argv);
    491540    PHOTCODE_A_LIST = strcreate(argv[N]);
     
    501550  if ((N = get_argument (argc, argv, "-hpm"))) {
    502551    if (N >= argc - 3) usage();
    503     FIT_TARGET = TARGET_HPM;
     552    RELASTRO_OP = OP_HPM;
    504553    remove_argument (N, &argc, argv);
    505554    RADIUS = atof(argv[N]);
     
    539588  }
    540589
    541   if (FIT_TARGET == TARGET_NONE) usage_client();
     590  if (RELASTRO_OP == OP_NONE) usage_client();
    542591
    543592  /* specify portion of the sky : allow default of all sky? */
     
    718767
    719768void usage () {
    720   fprintf (stderr, "ERROR: USAGE: relastro -update-simple [options]\n");
    721   fprintf (stderr, "       OR:    relastro -update-chips [options]\n");
    722   fprintf (stderr, "       OR:    relastro -update-mosaic [options]\n");
     769  fprintf (stderr, "ERROR: USAGE: relastro -images -update-simple [options]\n");
     770  fprintf (stderr, "       OR:    relastro -images -update-chips [options]\n");
     771  fprintf (stderr, "       OR:    relastro -images -update-mosaic [options]\n");
     772  fprintf (stderr, "       OR:    relastro -parallel-regions -update-simple [options]\n");
     773  fprintf (stderr, "       OR:    relastro -parallel-regions -update-chips [options]\n");
     774  fprintf (stderr, "       OR:    relastro -parallel-regions -update-mosaic [options]\n");
     775  fprintf (stderr, "       OR:    relastro -parallel-images -update-simple [options]\n");
     776  fprintf (stderr, "       OR:    relastro -parallel-images -update-chips [options]\n");
     777  fprintf (stderr, "       OR:    relastro -parallel-images -update-mosaic [options]\n");
    723778  fprintf (stderr, "       OR:    relastro -update-objects [options]\n");
    724779  fprintf (stderr, "       OR:    relastro -high-speed [options]\n");
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/high_speed_objects.c

    r35494 r36680  
    161161  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    162162  tcoords.Npolyterms = 1;
    163   strcpy (tcoords.ctype, "RA---ARC");
     163  strcpy (tcoords.ctype, "DEC--ARC");
    164164
    165165  /* build spatial index (RA sort) referencing input array sequence */
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/hpm_objects.c

    r35494 r36680  
    138138  tcoords.pc1_2 = tcoords.pc2_1 = 0.0;
    139139  tcoords.Npolyterms = 1;
    140   strcpy (tcoords.ctype, "RA---ARC");
     140  strcpy (tcoords.ctype, "DEC--ARC");
    141141
    142142  /* build spatial index (RA sort) referencing input array sequence */
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/initialize.c

    r34429 r36680  
    66  args (argc, argv);
    77
    8   if (FIT_TARGET == TARGET_MERGE_SOURCE) return;
     8  if (RELASTRO_OP == OP_MERGE_SOURCE) return;
    99
    1010  fprintf (stderr, "PHOTCODE_KEEP_LIST: %s\n", PHOTCODE_KEEP_LIST);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/load_catalogs.c

    r35105 r36680  
    115115Catalog *load_catalogs_parallel (SkyList *sky, int *Ncatalog) {
    116116
     117  char uniquer[12];
     118  int TIME = time(NULL);
     119  int PID = getpid();
     120  snprintf (uniquer, 12, "%05d.%05d", PID, TIME % 100000);
     121
    117122  // load the list of hosts
    118123  HostTable *table = HostTableLoad (CATDIR, sky->hosts);
     
    131136
    132137    ALLOCATE (table->hosts[i].results, char, 1024);
    133     snprintf (table->hosts[i].results, 1024, "%s/relastro.catalog.subset.dat", table->hosts[i].pathname);
     138    snprintf (table->hosts[i].results, 1024, "%s/relastro.catalog.%s.dat", table->hosts[i].pathname, uniquer);
    134139
    135140    // options / arguments that can affect relastro_client -load:
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/load_images.c

    r35763 r36680  
    11# include "relastro.h"
    2 
    3 # define MARKTIME(MSG,...) { \
    4   float dtime; \
    5   gettimeofday (&stop, (void *) NULL); \
    6   dtime = DTIME (stop, start); \
    7   fprintf (stderr, MSG, __VA_ARGS__); }
    82
    93int load_images (FITS_DB *db, SkyList *skylist, int UseFullOverlap) {
     
    126  off_t      Nimage, Nsubset;
    137  off_t     *LineNumber;
    14   struct timeval start, stop;
    158
    16   gettimeofday (&start, (void *) NULL);
     9  INITTIME;
    1710
    1811  // convert database table to internal structure
     
    3528 
    3629  /* unlock, if we can (else, unlocked below) */
    37   int unlockImages = !UPDATE || (FIT_TARGET == TARGET_UPDATE_OFFSETS);
     30  int unlockImages = !UPDATE || (RELASTRO_OP == OP_UPDATE_OFFSETS);
    3831  if (unlockImages) dvo_image_unlock (db);
    3932
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/relastro.c

    r35763 r36680  
    1010  SkyList *skylist = SkyListByPatch (sky, -1, &UserPatch);
    1111
    12   switch (FIT_TARGET) {
    13     case TARGET_UPDATE_OBJECTS:
     12  switch (RELASTRO_OP) {
     13    case OP_UPDATE_OBJECTS:
    1414      /* the object analysis is a separate process iterating over catalogs */
    1515      relastro_objects (skylist, 0, NULL);
    1616      exit (0);
    1717
    18     case TARGET_HIGH_SPEED:
     18    case OP_HIGH_SPEED:
    1919      /* high-speed is a 2pt cross-correlation process for linking moving objects (high PM) */
    2020      high_speed_catalogs (sky, skylist, 0, NULL);
    2121      exit (0);
    2222
    23     case TARGET_HPM:
     23    case OP_HPM:
    2424      hpm_catalogs (sky, skylist, 0, NULL);
    2525      exit (0);
    2626
    27     case TARGET_MERGE_SOURCE:
     27    case OP_MERGE_SOURCE:
    2828      /* a special method to manually merge unlinked detections of sources togther (not parallel) */
    2929      relastro_merge_source (sky);
    3030      exit (0);
    3131
    32     case TARGET_SIMPLE:
    33     case TARGET_CHIPS:
    34     case TARGET_MOSAICS:
     32    case OP_IMAGES:
    3533      relastro_images (skylist);
    3634      exit (0);
    3735
    38     case TARGET_UPDATE_OFFSETS:
     36    case OP_UPDATE_OFFSETS:
    3937      // iterate over catalogs to make detection coordinates consistant
    4038      UpdateObjectOffsets (skylist, 0, NULL);
     39      exit (0);
     40
     41    case OP_PARALLEL_REGIONS:
     42      // run image updates in parallel across multiple remote machines
     43      relastro_parallel_regions ();
     44      exit (0);
     45
     46    case OP_PARALLEL_IMAGES:
     47      // operation on the remote machines in the PARALLEL_REGION mode
     48      relastro_parallel_images ();
    4149      exit (0);
    4250
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/relastro_client.c

    r35763 r36680  
    2828  SkyList *skylist = SkyListByPatch (sky, -1, &UserPatch);
    2929
    30   switch (FIT_TARGET) {
     30  switch (RELASTRO_OP) {
    3131
    32     case TARGET_LOAD_OBJECTS: {
     32    case OP_LOAD_OBJECTS: {
    3333      // USAGE: relastro_client -load-objects
    3434      int Ncatalog;
    3535      Catalog *catalog = load_catalogs (skylist, &Ncatalog, TRUE, HOST_ID, HOSTDIR);
    3636      if (!catalog) {
    37           fprintf (stderr, "ERROR loading catalogs from %s\n", CATDIR);
    38           exit (2);
     37        fprintf (stderr, "ERROR loading catalogs from %s\n", CATDIR);
     38        exit (2);
    3939      }
    4040      BrightCatalog *bcatalog = BrightCatalogMerge (catalog, Ncatalog);
    4141      if (!BrightCatalogSave (BCATALOG, bcatalog)) {
    42           fprintf (stderr, "ERROR saving bright catalog from %s\n", CATDIR);
    43           exit (2);
     42        fprintf (stderr, "ERROR saving bright catalog from %s\n", CATDIR);
     43        exit (2);
    4444      }
    4545      break;
    4646    }
    4747     
    48     case TARGET_UPDATE_OBJECTS: {
     48    case OP_UPDATE_OBJECTS: {
    4949      // USAGE: relastro_client -update-objects
    5050      relastro_objects (skylist, HOST_ID, HOSTDIR);
     
    5252    }
    5353
    54     case TARGET_HIGH_SPEED: {
     54    case OP_HIGH_SPEED: {
    5555      // USAGE: relastro_client -high-speed
    5656      high_speed_catalogs (sky, skylist, HOST_ID, HOSTDIR);
     
    5858    }
    5959
    60     case TARGET_HPM: {
     60    case OP_HPM: {
    6161      // USAGE: relastro_client -high-speed
    6262      hpm_catalogs (sky, skylist, HOST_ID, HOSTDIR);
     
    6464    }
    6565
    66       // XXX loading the images is fairly costly -- see if we can do an image subset
    67     case TARGET_UPDATE_OFFSETS: {
     66      // XXX loading the images is fairly costly -- see if we can do an image subset?
     67    case OP_UPDATE_OFFSETS: {
    6868      FITS_DB db;
    6969     
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/relastro_images.c

    r35763 r36680  
    66  Catalog *catalog;
    77  FITS_DB db;
    8   struct timeval start, stop;
    98
    10   gettimeofday (&start, (void *) NULL);
     9  INITTIME;
    1110
    1211  /* register database handle with shutdown procedure */
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/relastro_objects.c

    r35763 r36680  
    144144    // PM_TOOFEW
    145145    // SRC_MEAS_TOOFEW
    146     // FIT_TARGET
    147146
    148147    char command[1024];
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/resort_catalog.c

    r34088 r36680  
    3030  if (catalog[0].sorted == TRUE) return;
    3131
    32   // struct timeval start, stop;
    33   // gettimeofday (&start, NULL);
     32  // INITTIME;
    3433
    3534  /* internal counters */
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/select_images.c

    r35763 r36680  
    1515void dsortindex (double *X, off_t *Y, int N);
    1616off_t getRegionStartByRA (double R, double *Rref, off_t Nregions);
    17 
    18 # define MARKTIME(MSG,...) { \
    19   float dtime; \
    20   gettimeofday (&stop, (void *) NULL); \
    21   dtime = DTIME (stop, start); \
    22   fprintf (stderr, MSG, __VA_ARGS__); }
    2317
    2418Image *select_images (SkyList *skylist, Image *timage, off_t Ntimage, off_t **LineNumber, off_t *Nimage, int UseFullOverlap) {
     
    3125  Coords tcoords;
    3226  SkyRegionCoords *skycoords;
    33   struct timeval start, stop;
    3427 
    3528  double RmaxSkyRegion, RminSkyRegion, RmidSkyRegion, DminSkyRegion, DmaxSkyRegion;
     
    5043  }
    5144
    52   gettimeofday (&start, (void *) NULL);
     45  INITTIME;
    5346
    5447  // the comparison is made in the catalog local projection. below we set crval1,2
     
    5750  tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    5851  tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    59   strcpy (tcoords.ctype, "RA---TAN");
     52  strcpy (tcoords.ctype, "DEC--TAN");
    6053
    6154  ALLOCATE (skycoords, SkyRegionCoords, skylist[0].Nregions);
     
    132125    if (NphotcodesKeep > 0) {
    133126      found = FALSE;
    134       // XXX this bit of code excludes DIS mosaics and should be fixed
     127      // we have to keep DIS mosaics explicitly (photcode = 0)
     128      if (!strcmp(&timage[i].coords.ctype[4], "-DIS")) found = TRUE;
    135129      for (k = 0; (k < NphotcodesKeep) && !found; k++) {
    136130        if (photcodesKeep[k][0].code == timage[i].photcode) found = TRUE;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relastro/src/testparallax.c

    r34088 r36680  
    5757  coords.pc1_2  = coords.pc2_1 = 0.0;
    5858  coords.Npolyterms = 1;
    59   strcpy (coords.ctype, "RA---SIN");
     59  strcpy (coords.ctype, "DEC--SIN");
    6060
    6161  // use one point as a local reference
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/Makefile

    r35416 r36680  
    4747$(SRC)/relphot_images.$(ARCH).o  \
    4848$(SRC)/relphot_objects.$(ARCH).o         \
     49$(SRC)/relphot_parallel_regions.$(ARCH).o \
     50$(SRC)/relphot_parallel_images.$(ARCH).o \
    4951$(SRC)/select_images.$(ARCH).o   \
     52$(SRC)/assign_images.$(ARCH).o   \
     53$(SRC)/launch_region_hosts.$(ARCH).o     \
     54$(SRC)/ImageTable.$(ARCH).o      \
     55$(SRC)/ImageMagIO.$(ARCH).o      \
     56$(SRC)/syncfile.$(ARCH).o        \
     57$(SRC)/share_image_mags.$(ARCH).o        \
     58$(SRC)/share_mean_mags.$(ARCH).o         \
     59$(SRC)/MeanMagIO.$(ARCH).o       \
     60$(SRC)/indexCatalog.$(ARCH).o    \
    5061$(SRC)/client_logger.$(ARCH).o   \
    5162$(SRC)/setExclusions.$(ARCH).o   \
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/doc/parallel.txt

    r33651 r36680  
     1
     22014.02.15
     3
     4Nearly done with the relphot mods.  some outstanding questions;
     5
     6 * image vs mosaic?
     7 * how do decide which images need to be shared?
     8
     92014.02.14
     10
     11 more relphot notes:
     12
     13 * I load the catalogs, with a 
     14
     152014.02.12
     16
     17I am making progess on the relphot -parallel-regions implementation.  some things I need to deal with:
     18
     19 * assign_images: select mosaics for all images saved for a given host (need to supply them as well)
     20   ** I need to decide on the Image / Mosaic split.  If I am calibrating by image, then the image center defines ownership
     21   ** if I am calibrating by exposure, then the mosaic center must define ownership
     22 o determine SkyList covering the images for region host
     23 o tag detections and objects which I own or do not own
     24   o ImageOps.c / matchImage matches detections to images and needs to handle mine / not mine cases
     25   o ditto for matchMosaics
     26 o load_catalogs : I need to make my requested catalogs unique (just add uniquer to load_catalogs.c:130
     27 o figure out what fields I'm saving in meanmags and how to construct it
     28   -- mag, objID, catID, photcode, (dmag or other stats?)
     29 * from which hosts do I slurp mean mags?
     30 o function to merge a new meanmag array into the existing one
     31 o how to go from (objID,catID) to a given catalog[i].average[j]
     32
     332014.02.06
     34
     35** a single region-level host owns images for which the center lands
     36   in its region.
     37
     38** it owns detections which come from images which it owns
     39   
     40** it owns objects which land in its region
     41
     42Extending parallel relphot processing to split the sky (and images)
     43into regions, each of which runs in parallel at the same time:
     44
     45Top Level (relphot -parallel-images):
     46 * define regions of the sky -> hosts
     47 * load images, assign to hosts
     48 * launch region-level jobs on remote hosts
     49
     50 Region Level (relphot -parallel-images-region)
     51  * load my image subset table
     52  * request objects and detections for my skyregion
     53  * match images & objects, etc
     54
     55  * update my image parameters
     56  * update my detections
     57  * write out detections
     58  * load detections from my border hosts
     59  * match to my objects
     60  * update my objects
     61  * write out objects
     62  * load objects from my border hosts
     63  * update images
     64    (iterate N times)
     65  * write out image parameters
     66
     67Top Level
     68  * read image parameters, update
     69  * update objects
    170
    2712012.02.13
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/include/relphot.h

    r35806 r36680  
    2323// # define IDX_T off_t
    2424# define IDX_T int
     25
     26typedef enum {
     27  MODE_ERROR = 0,
     28  UPDATE_IMAGES,
     29  UPDATE_AVERAGES,
     30  PARALLEL_REGIONS,
     31  PARALLEL_IMAGES,
     32  APPLY_OFFSETS,
     33} RelphotMode;
    2534
    2635typedef enum {
     
    8695  // others are only used on the final output steps.
    8796
    88   double *list;               // list of measure.mag values for a given star
    89   double *dlist;              // mag errors for a star
    90   double *wlist;              // weights to use for mean mags
    91   double *aplist;             // ap mags for a star
    92   double *kronlist;           // kron mags for a star
     97  double *Mpsflist;           // list of measure.mag values for a given star
     98  double *dpsflist;           // mag errors for a star
     99  double *wpsflist;           // weights to use for mean mags
     100
     101  double *Maplist;            // ap mags for a star
     102  double *daplist;            // ap mags for a star
     103  double *waplist;            // ap mags for a star
     104
     105  double *Mkronlist;          // kron mags for a star
    93106  double *dkronlist;          // kron mag errors
     107  double *wkronlist;          // kron mag errors
    94108
    95109  double *psfqf_list;         // psfqf for all filters
     
    97111  double *stargal_list;       // stargal for all filters
    98112
    99   StatType stats;
     113  StatType psfstats;
    100114  StatType apstats;
    101115  StatType kronstats;
    102116} SetMrelInfo;
     117
     118typedef struct {
     119  float M;
     120  float dM;
     121  float Xm;
     122  int Nsec;
     123  unsigned int objID;
     124  unsigned int catID;
     125  int photcode;
     126} MeanMag;
     127
     128typedef struct {
     129  float Mcal;
     130  float dMcal;
     131  float dMagSys;
     132  float Xm;
     133  int nFitPhotom;
     134  int flags;
     135  unsigned int imageID;
     136  short ubercalDist;
     137} ImageMag;
    103138
    104139typedef struct {
     
    116151  unsigned int photom_map_id;
    117152  unsigned int flags;
     153  int tessID;
    118154  int projID;
    119155  int skycellID;
     
    149185int    SKY_DEPTH;  /** XXX EAM : depth of catalog tables, fix usage */
    150186
     187// globals for parallel region operations
     188char  *REGION_FILE;
     189char  *IMAGE_TABLE;
     190int    REGION_HOST_ID;
     191
    151192int          HOST_ID;
    152193char        *HOSTDIR;
     
    173214int    PARALLEL_MANUAL;
    174215int    PARALLEL_SERIAL;
     216
     217int    PARALLEL_REGIONS_MANUAL;
    175218
    176219int    NTHREADS;
     
    260303void          InterpolateGrid     PROTO((float *buffer, int Nx, int Ny, Coords *ccd, Coords *gcoords));
    261304off_t        *SelectRefMosaic     PROTO((Mosaic **refmosaic, off_t *Nimage));
    262 int           args                PROTO((int argc, char **argv));
     305RelphotMode   args                PROTO((int argc, char **argv));
    263306int           args_client         PROTO((int argc, char **argv));
    264307int           bcatalog            PROTO((Catalog *subcatalog, Catalog *catalog, int Ncat));
     
    273316void          findImages          PROTO((Catalog *catalog, int Ncatalog, int doImageList));
    274317int           findMosaics         PROTO((Catalog *catalog, int Ncatalog, int doMosaicList));
     318
     319void makeMosaics (Image *image, off_t Nimage);
     320Mosaic *getMosaicForImage (off_t im);
     321void setMosaicCenters (Image *image, off_t Nimage);
    275322
    276323void set_db (FITS_DB *in);
     
    309356void          initMosaics         PROTO((Image *subset, off_t Nsubset, Image *image, char *inSubset, off_t Nimage));
    310357void          initMrel            PROTO((Catalog *catalog, int Ncatalog));
    311 void          initialize          PROTO((int argc, char **argv));
     358RelphotMode   initialize          PROTO((int argc, char **argv));
    312359void          initialize_client   PROTO((int argc, char **argv));
    313360void          liststats_setmode   PROTO((StatType *stats, char *strmode));
     
    397444ImageSubset *ImageSubsetLoad(char *filename, off_t *nimage);
    398445
    399 int client_logger_init ();
     446int client_logger_init (char *dirname);
    400447int client_logger_message (char *format,...);
    401448
    402449int MatchImageName (off_t meas, int cat, char *name);
    403 int MatchImageSkycellID (off_t meas, int cat, int myProjectionID, int mySkycellID);
    404 
    405 int load_tree (char *treefile);
    406 int BoundaryTreePrimaryCell (char *primaryCellName, double ra, double dec);
    407 int BoundaryTreePrimaryCellIDs (int *projID, int *skycellID, double ra, double dec);
     450int MatchImageSkycellID (off_t meas, int cat, int myTessID, int myProjectionID, int mySkycellID);
     451
     452int load_tess (char *treefile);
     453int get_tess_ids (int *tessID, int *projID, int *skycellID, double ra, double dec);
     454int TessellationIDsByImageName (int *tessID, int *projID, int *skycellID, char *name);
     455
     456// int BoundaryTreePrimaryCell (char *primaryCellName, double ra, double dec);
     457// int BoundaryTreePrimaryCellIDs (int *projID, int *skycellID, double ra, double dec);
    408458
    409459int print_measure_set_alt (Average *average, SecFilt *secfilt, Measure *measure);
     
    417467int init_synthetic_mags ();
    418468int add_synthetic_mags (AverageTiny *average, SecFilt *secfilt, MeasureTiny *measure, off_t *Nmeasure, off_t *Nm);
     469
     470int relphot_parallel_regions ();
     471
     472int assign_images (FITS_DB *db, RegionHostTable *regionHosts);
     473int select_images_hostregion (RegionHostTable *hosts, Image *image, off_t Nimage);
     474int find_host_for_coords (RegionHostTable *regionHosts, double R, double d);
     475int calculate_image_bounds (Image *image, double *rmin, double *rmax, double *dmin, double *dmax, double Rmid);
     476
     477int launch_region_hosts (RegionHostTable *regionHosts);
     478int strextend (char *input, char *format,...);
     479
     480Image *ImageTableLoad(char *filename, off_t *nimage);
     481int ImageTableSave (char *filename, Image *images, off_t Nimages);
     482
     483int indexCatalogs (Catalog *catalog, int Ncatalog);
     484int catID_and_objID_to_seq (int catID, int objID, int *catSeq, off_t *objSeq);
     485
     486int check_sync_file (char *filename, int nloop);
     487int clear_sync_file (char *filename);
     488int update_sync_file (char *filename, int nloop);
     489char *make_filename (char *dirname, char *hostname, int hostID, char *tailname);
     490
     491int share_mean_mags (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     492int slurp_mean_mags (Catalog *catalog, int Ncatalog, RegionHostTable *regionHosts, int nloop);
     493int set_mean_mags (MeanMag *meanmags, AverageTiny *average, SecFilt *secfilt, int Nsec);
     494MeanMag *merge_mean_mags (MeanMag *target, int *ntarget, MeanMag *source, int Nsource);
     495
     496MeanMag *MeanMagLoad(char *filename, off_t *nmeanmags);
     497int MeanMagSave(char *filename, MeanMag *meanmags, off_t Nmeanmags);
     498
     499int share_image_mags (RegionHostTable *regionHosts, int nloop);
     500int slurp_image_mags (RegionHostTable *regionHosts, int nloop);
     501int set_image_mags (ImageMag *image_mags, Image *image);
     502ImageMag *merge_image_mags (ImageMag *target, int *ntarget, ImageMag *source, int Nsource);
     503
     504ImageMag *ImageMagLoad(char *filename, off_t *nimage_mags);
     505int ImageMagSave(char *filename, ImageMag *image_mags, off_t Nimage_mags);
     506
     507int markObjects (Catalog *catalog, int Ncatalog);
     508
     509int relphot_parallel_images ();
     510int relphot_parallel_regions ();
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/BoundaryTreeOps.c

    r35759 r36680  
    11# include "relphot.h"
    22
    3 // XXX for the moment, only load one boundary tree at a time
    4 // XXX in fact, only allow RINGS.V3...
     3static int Ntess = 0;
     4static TessellationTable *tess = NULL;
    55
    6 static BoundaryTree *tree = NULL;
     6int TessellationIDsByImageName (int *tessID, int *projID, int *skycellID, char *name) {
    77
    8 int BoundaryTreePrimaryCell (char *primaryCellName, double ra, double dec) {
     8  int i;
    99
    10   int zone, band;
    11 
    12   if (!primaryCellName) return FALSE;
    13 
    14   primaryCellName[0] = 0;
    15 
    16   if (!tree) return FALSE;
    17 
    18   if (!BoundaryTreeCellCoords (tree, &zone, &band, ra, dec)) {
    19     fprintf (stderr, "mismatch!\n");
    20     return FALSE;
    21   }
    22  
    23 # define USE_PROJECTION_CELL 0
    24 # if (USE_PROJECTION_CELL)
    25   snprintf (primaryCellName, DVO_MAX_PATH, "RINGS.V3.%s", tree->name[zone][band]);
    26 # else
    27 
    28   // I have ra, dec, and the primary projection cell.  In order to choose the primary skycell,
    29   // I just need to project to ra,dec to X,Y based on the center of the cell and then get the subdivision right.
    30    
    31   double x = 0.0;
    32   double y = 0.0;
    33   BoundaryTreeProjection (&x, &y, ra, dec, tree, zone, band);
    34  
    35   int xi = x / tree->dX[zone][band];
    36   int yi = y / tree->dY[zone][band];
    37   int N = xi + tree->NX_SUB * yi;
    38  
    39   // XXX short-circuit this for now (we should use this code if we make tree have more variable NX,NY values
    40   // char format[24], skycellname[128];
    41   // int Ndigit = (int)(log10(tree->NX_SUB*tree->NY_SUB)) + 1 ;
    42   // snprintf (format, 24, "%s.%%0%dd", tree->name[zone][band], Ndigit);
    43   // snprintf (skycellname, 128, format, N);
    44 
    45   snprintf (primaryCellName, DVO_MAX_PATH, "RINGS.V3.%s.%03d", tree->name[zone][band], N);
    46 # endif
    47 
    48   return TRUE;
    49 }
    50 
    51 int BoundaryTreePrimaryCellIDs (int *projID, int *skycellID, double ra, double dec) {
    52 
    53   int zone, band;
    54 
     10  *tessID = -1;
    5511  *projID = -1;
    5612  *skycellID = -1;
    5713
    58   if (!tree) return FALSE;
     14  if (!tess) return FALSE;
    5915
    60   if (!BoundaryTreeCellCoords (tree, &zone, &band, ra, dec)) {
    61     fprintf (stderr, "mismatch!\n");
    62     return FALSE;
     16  for (i = 0; i < Ntess; i++) {
     17    // do this with a strhash of some kind?
     18    if (!strncmp (name, tess[i].basename, tess[i].Nbasename)) {
     19      *tessID    = i;
     20      if (tess[i].projectIDoff >= 0) {
     21        *projID    = atoi(&name[tess[i].projectIDoff]);
     22      } else {
     23        *projID    = 0;
     24      }
     25      if (tess[i].skycellIDoff >= 0) {
     26        *skycellID = atoi(&name[tess[i].skycellIDoff]);
     27      } else {
     28        *skycellID = 0;
     29      }
     30      return TRUE;
     31    }
    6332  }
    64  
    65   // I have ra, dec, and the primary projection cell.  In order to choose the primary skycell,
    66   // I just need to project to ra,dec to X,Y based on the center of the cell and then get the subdivision right.
    67    
    68   double x = 0.0;
    69   double y = 0.0;
    70   BoundaryTreeProjection (&x, &y, ra, dec, tree, zone, band);
    71  
    72   int xi = x / tree->dX[zone][band];
    73   int yi = y / tree->dY[zone][band];
    74   int N = xi + tree->NX_SUB * yi;
    75  
    76   *projID = tree->projID[zone][band];
    77   *skycellID = N;
    78 
    79   return TRUE;
     33  return FALSE;
    8034}
    8135
    82 int load_tree (char *treefile) {
     36int load_tess (char *tessfile) {
    8337
    84   tree = BoundaryTreeLoad (treefile);
    85   if (!tree) {
    86     fprintf (stderr, "failed to load boundary tree %s\n", treefile);
     38  tess = TessellationTableLoad (tessfile, &Ntess);
     39  if (!tess) {
     40    fprintf (stderr, "failed to load tessellation boundary file %s\n", tessfile);
    8741    exit (2);
    8842  }
     
    9044  return TRUE;
    9145}
     46
     47int get_tess_ids (int *tessID, int *projID, int *skycellID, double ra, double dec) {
     48
     49  int status;
     50
     51  if (!tess) return FALSE;
     52
     53  status = TessellationPrimaryCellIDs(tess, Ntess, tessID, projID, skycellID, ra, dec);
     54  return status;
     55}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/BrightCatalog.c

    r33651 r36680  
    101101      measure[i].catID     = catID[i];
    102102      measure[i].photcode  = photcode[i];
     103      measure[i].myDet     = FALSE;
    103104    }
    104105    fprintf (stderr, "loaded data for %lld measure\n", (long long) Nrow);
     
    141142    GET_COLUMN(flags,         "FLAGS",       int);
    142143    GET_COLUMN(catID,         "CAT_ID",      int);
     144    GET_COLUMN(objID,         "OBJ_ID",      int);
    143145    gfits_free_header (&theader);
    144146    gfits_free_table  (&ftable);
     
    153155      average[i].flags          = flags[i];
    154156      average[i].catID          = catID[i];
     157      average[i].objID          = objID[i];
     158      average[i].nOwn           = 0;
    155159    }
    156160    fprintf (stderr, "loaded data for %lld average\n", (long long) Nrow);
     
    162166    free (flags         );
    163167    free (catID         );
     168    free (objID         );
    164169
    165170    catalog->average = average;
     
    370375    gfits_define_bintable_column (&theader, "J", "FLAGS",       "flags",                  NULL,    1.0, 0.0);
    371376    gfits_define_bintable_column (&theader, "J", "CAT_ID",      "catalog ref",            NULL,    1.0, 0.0);
     377    gfits_define_bintable_column (&theader, "J", "OBJ_ID",      "object ref",             NULL,    1.0, 0.0);
    372378
    373379    // generate the output array that carries the data
     
    381387    int   *flags          ; ALLOCATE (flags,         int,    catalog->Naverage);
    382388    int   *catID          ; ALLOCATE (catID,         int,    catalog->Naverage);
     389    int   *objID          ; ALLOCATE (objID,         int,    catalog->Naverage);
    383390
    384391    // assign the storage arrays
     
    391398      flags[i]          = average[i].flags;
    392399      catID[i]          = average[i].catID;
     400      objID[i]          = average[i].objID;
    393401    }
    394402
     
    400408    gfits_set_bintable_column (&theader, &ftable, "FLAGS",       flags,         catalog->Naverage);
    401409    gfits_set_bintable_column (&theader, &ftable, "CAT_ID",      catID,         catalog->Naverage);
     410    gfits_set_bintable_column (&theader, &ftable, "OBJ_ID",      objID,         catalog->Naverage);
    402411
    403412    free (R             );
     
    407416    free (flags         );
    408417    free (catID         );
     418    free (objID         );
    409419
    410420    gfits_fwrite_Theader (f, &theader);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/ImageOps.c

    r35759 r36680  
    4848// stack image.  for now, we generate these ID arrays based on the image names when we load in the image table (initImages).
    4949// When we pass data to the remote clients via the ImageSubset, the projID/skycellID values are carried directly in the table.
     50int *tessID    = NULL;
    5051int *projectID = NULL;
    5152int *skycellID = NULL;
     
    8182
    8283  // for stack images, assign projection cell ID and skycell ID based on filenames
     84  ALLOCATE (tessID,      int, Nimage);
    8385  ALLOCATE (projectID,   int, Nimage);
    8486  ALLOCATE (skycellID,   int, Nimage);
     
    8789    imageIdx[i] = i;
    8890    imageIDs[i] = image[i].imageID;
     91
     92    tessID[i]    = -1;
    8993    projectID[i] = -1;
    9094    skycellID[i] = -1;
    91     if (!strncmp (image[i].name, "RINGS.V3.skycell", strlen("RINGS.V3.skycell"))) {
    92       projectID[i] = atoi(&image[i].name[17]);
    93       skycellID[i] = atoi(&image[i].name[22]);
    94     }
     95
     96    TessellationIDsByImageName (&tessID[i], &projectID[i], &skycellID[i], image[i].name);
    9597  }
    9698
    9799  // sort the image index by the IDs
     100  // XXX does this break the imageID <-> projectID, etc match?
    98101  llsortpair (imageIDs, imageIdx, Nimage);
    99102}
     
    106109  // create full a Image array and save the needed values
    107110  ALLOCATE (image, Image, N);
     111
     112  ALLOCATE (tessID,    int, N);
    108113  ALLOCATE (projectID, int, N);
    109114  ALLOCATE (skycellID, int, N);
     
    118123    image[i].trate         = input[i].trate        ;
    119124    image[i].ubercalDist   = input[i].ubercalDist  ;
     125    tessID[i]              = input[i].tessID       ;
    120126    projectID[i]           = input[i].projID       ;
    121127    skycellID[i]           = input[i].skycellID    ;
     
    153159    subset[i].trate         = image[i].trate        ;
    154160    subset[i].ubercalDist   = image[i].ubercalDist  ;
     161    subset[i].tessID        = tessID[i];
    155162    subset[i].projID        = projectID[i];
    156163    subset[i].skycellID     = skycellID[i];
     
    237244 
    238245  int Nmatch = 0;
    239  for (i = 0; i < Ncatalog; i++) {
     246  for (i = 0; i < Ncatalog; i++) {
    240247    for (j = 0; j < catalog[i].Nmeasure; j++) {
     248      catalog[i].measureT[j].myDet = FALSE; // a detetion is not mine until proven otherwise
    241249      ecode = GetPhotcodeEquivCodebyCode (catalog[i].measureT[j].photcode);
     250
     251      // skip measurements which do not match one of the requested photcodes (
     252      // (do we not already exclude in bcatalog -- maybe needed for reload_objects?
    242253      found = FALSE;
    243254      for (Ns = 0; !found && (Ns < Nphotcodes); Ns++) {
     
    245256      }
    246257      if (!found) continue;
     258
     259      // if we match one of our images, myDet gets set to TRUE
    247260      matchImage (catalog, j, i, doImageList);
    248261      Nmatch ++;
     
    315328    return;
    316329  }
     330  catalog[cat].measureT[meas].myDet = TRUE;
    317331
    318332  if (USE_GRID) {
     
    461475
    462476// returns image.Mcal - ff(x,y)
    463 int MatchImageSkycellID (off_t meas, int cat, int myProjectionID, int mySkycellID) {
     477int MatchImageSkycellID (off_t meas, int cat, int myTessID, int myProjectionID, int mySkycellID) {
    464478
    465479  off_t i;
     
    470484  if (i == -1) return FALSE;
    471485
     486  if (tessID[i]    == -1) return FALSE;
    472487  if (projectID[i] == -1) return FALSE;
    473488  if (skycellID[i] == -1) return FALSE;
    474489
     490  if (tessID[i]    != myTessID) return FALSE;
    475491  if (projectID[i] != myProjectionID) return FALSE;
    476492  if (skycellID[i] != mySkycellID) return FALSE;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/ImageSubset.c

    r35759 r36680  
    6363  GET_COLUMN (map,       "PHOTOM_MAP",   int);
    6464  GET_COLUMN (flags,     "FLAGS",        int);
     65  GET_COLUMN (tessID,    "TESS_ID",      int);
    6566  GET_COLUMN (projID,    "PROJ_ID",      int);
    6667  GET_COLUMN (skycellID, "SKYCELL_ID",   int);
     
    7879    image[i].photom_map_id = map[i];
    7980    image[i].flags         = flags[i];
     81    image[i].tessID        = tessID[i];
    8082    image[i].projID        = projID[i];
    8183    image[i].skycellID     = skycellID[i];
     
    9193  free (map);
    9294  free (flags);
     95  free (tessID);
    9396  free (projID);
    9497  free (skycellID);
     
    130133  gfits_define_bintable_column (&theader, "J", "FLAGS", "flags", NULL, 1.0, 1.0*0x8000);
    131134
     135  gfits_define_bintable_column (&theader, "J", "TESS_ID", "ID", NULL, 1.0, 0.0);
    132136  gfits_define_bintable_column (&theader, "J", "PROJ_ID", "ID", NULL, 1.0, 0.0);
    133137  gfits_define_bintable_column (&theader, "J", "SKYCELL_ID", "ID", NULL, 1.0, 0.0);
     
    143147  float *Mcal, *dMcal;
    144148  unsigned int *imageID, *map, *flags, *tzero;
    145   int *projID, *skycellID;
     149  int *tessID, *projID, *skycellID;
    146150  unsigned short *trate;
    147151  short *ucdist;
     
    153157  ALLOCATE (map,       unsigned int,   Nimage);
    154158  ALLOCATE (flags,     unsigned int,   Nimage);
     159  ALLOCATE (tessID,    int,            Nimage);
    155160  ALLOCATE (projID,    int,            Nimage);
    156161  ALLOCATE (skycellID, int,            Nimage);
     
    169174    trate[i]     = image[i].trate;
    170175    ucdist[i]    = image[i].ubercalDist;
     176    tessID[i]    = image[i].tessID;
    171177    projID[i]    = image[i].projID;
    172178    skycellID[i] = image[i].skycellID;
     
    179185  gfits_set_bintable_column (&theader, &ftable, "PHOTOM_MAP",   map,       Nimage);
    180186  gfits_set_bintable_column (&theader, &ftable, "FLAGS",        flags,     Nimage);
     187  gfits_set_bintable_column (&theader, &ftable, "TESS_ID",      tessID,    Nimage);
    181188  gfits_set_bintable_column (&theader, &ftable, "PROJ_ID",      projID,    Nimage);
    182189  gfits_set_bintable_column (&theader, &ftable, "SKYCELL_ID",   skycellID, Nimage);
     
    190197  free (map);
    191198  free (flags);
     199  free (tessID);
    192200  free (projID);
    193201  free (skycellID);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/MosaicOps.c

    r35806 r36680  
    320320}
    321321
     322/* find mosaic frames (unique time periods) (NOTE : we do NOT require matching photcodes but we
     323   match images by MOSAICNAME.  this last point is weak: it forces a single camera at a time.
     324   we can extend the logic to multiple cameras if we make list of MOSAICNAMES (better to assign a camera ID)
     325 */
     326void makeMosaics (Image *image, off_t Nimage) {
     327
     328  off_t i, j, status, found, NMOSAIC, *MosaicN_IMAGE;
     329  unsigned int start, stop, *startTimes, *startTimesMosaic;
     330  char *pname;
     331
     332  if (!MOSAIC_ZEROPT) return;
     333
     334  INITTIME;
     335
     336  /* a 'mosaic' in relphot is (unlike relastro) a virtual concept: there is no
     337   * entry in the image table that represents this mosaic.  Instead, it is an
     338   * internal construct that defines a group of related images
     339   */
     340
     341  // generate a list of all image start times
     342  ALLOCATE (startTimes, unsigned int, Nimage);
     343  for (i = 0; i < Nimage; i++) {
     344    startTimes[i] = image[i].tzero;
     345  }
     346  sort_times (startTimes, Nimage);
     347  MARKTIME("create array of all image obstimes: %f sec\n", dtime);
     348 
     349  Nmosaic = 0;
     350  NMOSAIC = 1000;
     351  ALLOCATE (startTimesMosaic, unsigned int, NMOSAIC);
     352  startTimesMosaic[0] = startTimes[0];
     353
     354  // generate a list of the unique start times (these define the mosaics)
     355  for (i = 0; i < Nimage; i++) {
     356    if (startTimes[i] < startTimesMosaic[Nmosaic]) {
     357      fprintf (stderr, "error?\n");
     358      abort();
     359    }
     360    if (startTimes[i] == startTimesMosaic[Nmosaic]) continue;
     361    Nmosaic ++;
     362    if (Nmosaic >= NMOSAIC) {
     363      NMOSAIC += 1000;
     364      REALLOCATE (startTimesMosaic, unsigned int, NMOSAIC);
     365    }
     366    startTimesMosaic[Nmosaic] = startTimes[i];
     367  }
     368  Nmosaic ++;
     369  MARKTIME("create array of mosaic obstimes: %f sec\n", dtime);
     370
     371  // now I have a list of uniq start times, and they are in order
     372  // create the mosaic arrays for these times
     373  ALLOCATE (mosaic, Mosaic, Nmosaic);
     374
     375  ALLOCATE (MosaicToImage, off_t *, Nmosaic);
     376  ALLOCATE (MosaicN_Image, off_t,   Nmosaic);
     377  ALLOCATE (MosaicN_IMAGE, off_t,   Nmosaic);
     378
     379  // init the mosaic array values
     380  for (i = 0; i < Nmosaic; i++) {
     381    mosaic[i].start = startTimesMosaic[i];
     382    mosaic[i].stop  = 0;
     383    mosaic[i].Mcal  = 0.0;
     384    mosaic[i].dMcal = 0.0;
     385    mosaic[i].dMsys = 0.0;
     386    mosaic[i].Xm    = 0.0;
     387    mosaic[i].flags = 0;
     388    mosaic[i].secz  = NAN;
     389    mosaic[i].photcode = 0;
     390    mosaic[i].skipCal = FALSE;
     391   
     392    memset (&mosaic[i].coords, 0, sizeof(Coords));
     393
     394    MosaicN_IMAGE[i] = 10;
     395    MosaicN_Image[i] = 0;
     396    ALLOCATE (MosaicToImage[i], off_t, MosaicN_IMAGE[i]);
     397    MosaicToImage[i][0] = -1;
     398  }
     399
     400  ALLOCATE (ImageToMosaic, off_t, Nimage); // mosaic to which image belongs
     401
     402  // assign each image to a mosaic
     403  for (i = 0; i < Nimage; i++) {
     404    ImageToMosaic[i] = -1;
     405
     406    /* select valid mosaic images by photcode */
     407    pname = GetPhotcodeNamebyCode (image[i].photcode);
     408    if (!pname) continue;
     409
     410    status = strncmp (pname, MOSAICNAME, strlen (MOSAICNAME));
     411    if (status) continue;
     412
     413    start = image[i].tzero;
     414    stop  = image[i].tzero + MAX(1.01*image[i].trate*image[i].NY, 1);
     415
     416    j = findMosaic(startTimesMosaic, Nmosaic, start);
     417    if (j == -1) {
     418      fprintf (stderr, "programming error? all image images should belong to a mosaic\n");
     419      abort();
     420    }
     421
     422    // add reference from image to mosaic
     423    ImageToMosaic[i] = j;
     424
     425    // have we already found this mosaic?
     426    found = (MosaicN_Image[j] > 0);
     427
     428    /* add image to mosaic image list */
     429    MosaicToImage[j][MosaicN_Image[j]] = i;
     430    MosaicN_Image[j] ++;
     431    if (MosaicN_Image[j] == MosaicN_IMAGE[j]) {
     432      MosaicN_IMAGE[j] += 10;
     433      REALLOCATE (MosaicToImage[j], off_t, MosaicN_IMAGE[j]);
     434    }
     435    if (found) continue;
     436   
     437    /* a new mosaic, define ranges */
     438    if (mosaic[j].start != start) {
     439      fprintf (stderr, "error?\n");
     440      abort();
     441    }
     442    mosaic[j].stop  = stop;
     443    mosaic[j].Mcal  = 0.0;
     444    mosaic[j].dMcal = 0.0;
     445    mosaic[j].Xm    = 0.0;
     446    mosaic[j].dMsys = image[i].flags;
     447    mosaic[j].flags = image[i].flags;
     448    mosaic[j].secz  = image[i].secz;
     449    mosaic[j].photcode = GetPhotcodeEquivCodebyCode (image[i].photcode);
     450  }
     451  MARKTIME("assign images to mosaic: %f sec\n", dtime);
     452
     453  // free this or not?
     454  free (MosaicN_IMAGE);
     455  free (startTimes);
     456  free (startTimesMosaic);
     457
     458  fprintf (stderr, "matched %d images to %d mosaics\n", (int) Nimage, (int) Nmosaic);
     459
     460  return;
     461}
     462
     463Mosaic *getMosaicForImage (off_t im) {
     464
     465  if (im < 0) return NULL;
     466  if (!ImageToMosaic) return NULL;
     467
     468  off_t m = ImageToMosaic[im];
     469  if (m < 0) return NULL;
     470  if (m >= Nmosaic) return NULL;
     471
     472  return (&mosaic[m]);
     473}
     474
    322475// use bisection to find the overlapping mosaic (returns exact match)
    323476// startTimes is a sorted, unique list of times
     
    350503  }
    351504  return (-1);
     505}
     506
     507void setMosaicCenters (Image *image, off_t Nimage) {
     508
     509  /* find max dR, dD range for all mosaics */
     510  /* define mosaic.coords to cover dR, dD */
     511  /* send results to initGridBins */
     512
     513  off_t i, j, m, NX, NY, NC, Nc;
     514  double R, D, Rmid, Dmid;
     515  double Mcal, dMcal, Xm;
     516  double *Rc, *Dc;
     517
     518  NC = 100;
     519  ALLOCATE (Rc, double, NC);
     520  ALLOCATE (Dc, double, NC);
     521
     522  for (i = 0; i < Nmosaic; i++) {
     523    Nc = 0;
     524    Rmid = Dmid = NAN;
     525    Mcal = dMcal = Xm = 0;
     526    for (j = 0; j < MosaicN_Image[i]; j++) {
     527      m = MosaicToImage[i][j];
     528
     529      if (!FindMosaicForImage (image, Nimage, m)) {
     530        if (VERBOSE2) fprintf (stderr, "cannot find mosaic for "OFF_T_FMT"\n", i);
     531        continue;
     532      }
     533
     534      NX = image[m].NX;
     535      NY = image[m].NY;
     536      XY_to_RD (&R, &D, 0.5*NX, 0.5*NY, &image[m].coords);
     537      R = ohana_normalize_angle_to_midpoint (R, 180.0);
     538
     539      // Exclude images with crazy astrometry
     540      // XXX NOTE : this is gpc1-specific
     541      {
     542        double dP1 = hypot(image[m].coords.pc1_1, image[m].coords.pc1_2);
     543        double dP2 = hypot(image[m].coords.pc2_1, image[m].coords.pc2_2);
     544        if (fabs(dP1 - 1.0) > 0.02) continue;
     545        if (fabs(dP2 - 1.0) > 0.02) continue;
     546
     547        double X00, Y00, X10, Y10, X01, Y01;
     548        XY_to_LM (&X00, &Y00, 0.0, 0.0, &image[m].coords);
     549        XY_to_LM (&X10, &Y10, image[m].NX, 0.0, &image[m].coords);
     550        XY_to_LM (&X01, &Y01, 0.0, image[m].NY, &image[m].coords);
     551        double dS0 = hypot ((X00 - X10), (Y00 - Y10));
     552        double dS1 = hypot ((X00 - X01), (Y00 - Y01));
     553        if (dS0 > 6000) continue;
     554        if (dS1 > 6500) continue;
     555      }
     556
     557      Rc[Nc] = R;
     558      Dc[Nc] = D;
     559      Nc ++;
     560      if (Nc >= NC) {
     561        NC += 100;
     562        REALLOCATE (Rc, double, NC);
     563        REALLOCATE (Dc, double, NC);
     564      }
     565
     566      Mcal  += image[m].Mcal;
     567      dMcal += image[m].dMcal;
     568      Xm    += image[m].Xm;
     569
     570      // for ubercal images, we (elsewhere) keep Mcal frozen
     571
     572      /* we are using mosaic.Mcal, not image.Mcal. reset image.Mcal */
     573      image[m].Mcal  = 0.0;
     574      image[m].dMcal = NAN;
     575      image[m].Xm    = NAN_S_SHORT;
     576    }
     577
     578    if (Nc > 0) {
     579      dsort (Rc, Nc);
     580      if (Rc[Nc-1] - Rc[0] > 180.0) {
     581        // in our list, Rc is in the range 0.0 to 360.0. 
     582        // any mosaic which is close to the 0.0, 360.0 boundary may have some on
     583        // one side or the other.  count how many have values more than Rc[0] + 180.
     584        // if more than half are at the large end, re-normalize to that range
     585        int Nbig = 0;
     586        for (j = 1; j < Nc; j++) {
     587          if (Rc[j] - Rc[0] > 180.0) Nbig ++;
     588        }
     589        if (Nbig  > 0.5*Nc) {
     590          for (j = 0; j < Nc; j++) {
     591            Rc[j] = ohana_normalize_angle_to_midpoint (Rc[j], 360.0);
     592          }
     593          dsort (Rc, Nc);
     594        } else if (Nbig > 0) {
     595          for (j = 0; j < Nc; j++) {
     596            Rc[j] = ohana_normalize_angle_to_midpoint (Rc[j], 0.0);
     597          }
     598          dsort (Rc, Nc);
     599        }
     600      }
     601      dsort (Dc, Nc);
     602
     603      Rmid = Rc[(int)(0.5*Nc)];
     604      Dmid = Dc[(int)(0.5*Nc)];
     605    }
     606
     607    strcpy (mosaic[i].coords.ctype, "DEC--TAN");
     608    mosaic[i].coords.crval1 = Rmid;
     609    mosaic[i].coords.crval2 = Dmid;
     610    mosaic[i].coords.crpix1 = 0.0;
     611    mosaic[i].coords.crpix2 = 0.0;
     612    mosaic[i].coords.cdelt1 = 1.0 / 3600.0;
     613    mosaic[i].coords.cdelt2 = 1.0 / 3600.0;
     614    mosaic[i].coords.pc1_1  = 1.0;
     615    mosaic[i].coords.pc2_2  = 1.0;
     616    mosaic[i].coords.pc1_2  = 0.0;
     617    mosaic[i].coords.pc2_1  = 0.0;
     618
     619    mosaic[i].Mcal  = Mcal / MosaicN_Image[i];
     620    mosaic[i].dMcal = dMcal / MosaicN_Image[i];
     621    mosaic[i].Xm    = Xm / MosaicN_Image[i];
     622  }
     623  return;
    352624}
    353625
     
    412684    }
    413685    dS /= MosaicN_Image[i];
    414     strcpy (mosaic[i].coords.ctype, "RA---TAN");
     686    strcpy (mosaic[i].coords.ctype, "DEC--TAN");
    415687    mosaic[i].coords.crval1 = Rmin;
    416688    mosaic[i].coords.crval2 = Dmin;
     
    527799
    528800  if (!MOSAIC_ZEROPT) return (FALSE);
     801  // if we are calibrating by mosaic, redefine myDet == on one of my mosaics
    529802
    530803  int Nmatch = 0;
    531804  for (i = 0; i < Ncatalog; i++) {
    532805    for (j = 0; j < catalog[i].Nmeasure; j++) {
     806      catalog[i].measureT[j].myDet = FALSE; // a detetion is not mine until proven otherwise
     807
    533808      if (TimeSelect) {
    534809        if (catalog[i].measureT[j].t < TSTART) continue;
     
    582857  }
    583858
     859  // this measurement is on one of my mosaics, mark it as mine.
     860  catalog[cat].measureT[meas].myDet = TRUE;
    584861  MeasureToMosaic[cat][meas] = mosID;
    585862
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/StarOps.c

    r35759 r36680  
    6363  results->Ngrid = 0;
    6464  if (allocLists) {
    65     ALLOCATE (results->list, double, Nmax);
    66     ALLOCATE (results->dlist, double, Nmax);
    67     ALLOCATE (results->wlist, double, Nmax);
     65    ALLOCATE (results->Mpsflist, double, Nmax);
     66    ALLOCATE (results->dpsflist, double, Nmax);
     67    ALLOCATE (results->wpsflist, double, Nmax);
    6868  }
    6969}
    7070
    7171void SetMrelInfoFree (SetMrelInfo *results) {
    72   free (results->list);
    73   free (results->dlist);
    74   free (results->wlist);
     72  free (results->Mpsflist);
     73  free (results->dpsflist);
     74  free (results->wpsflist);
    7575}
    7676
    7777void SetMrelInfoAccum (SetMrelInfo *summary, SetMrelInfo *results) {
    7878  summary->Nfew  += results->Nfew ;
    79   summary->Ncode  += results->Ncode ;
     79  summary->Ncode += results->Ncode ;
    8080  summary->Nsys  += results->Nsys ;
    8181  summary->Nbad  += results->Nbad ;
     
    158158  SetMrelInfoInit (&summary, FALSE);
    159159  SetMrelInfoInit (&results, TRUE); // allocates results->list,dlist,wlist
    160   ALLOCATE (results.aplist, double, Nmax);
    161   ALLOCATE (results.kronlist, double, Nmax);
     160
     161  ALLOCATE (results.Maplist,  double, Nmax);
     162  ALLOCATE (results.daplist,  double, Nmax);
     163  ALLOCATE (results.waplist,  double, Nmax);
     164
     165  ALLOCATE (results.Mkronlist, double, Nmax);
    162166  ALLOCATE (results.dkronlist, double, Nmax);
     167  ALLOCATE (results.wkronlist, double, Nmax);
    163168
    164169  ALLOCATE (results.psfqf_list, double, Nmax);
     
    183188
    184189  SetMrelInfoFree (&results);
    185   free (results.aplist);
    186   free (results.kronlist);
     190  free (results.Maplist);
     191  free (results.daplist);
     192  free (results.waplist);
     193
     194  free (results.Mkronlist);
    187195  free (results.dkronlist);
     196  free (results.wkronlist);
    188197
    189198  free (results.psfqf_list);
     
    328337int setMrel_catalog (Catalog *catalog, int Nc, int pass, FlatCorrectionTable *flatcorr, SetMrelInfo *results, int Nsecfilt) {
    329338
     339  fprintf (stderr, "??? should you still be using the old version of setMrel_catalog??\n");
     340  exit (3);
     341
     342# if (0)
     343
    330344  off_t j, k, m, ID;
    331345  int N;
     
    333347
    334348  StatType stats, apstats, kronstats;
    335   liststats_setmode (&stats, STATMODE);
     349  liststats_setmode (&psfstats, STATMODE);
    336350  liststats_setmode (&apstats, STATMODE);
    337351  liststats_setmode (&kronstats, STATMODE);
     
    366380    if (isSetMrelFinal) {
    367381      // set the name of the primary skycell (this is used in a strcmp to match the skycells in stack detections)
    368       BoundaryTreePrimaryCell(primaryCell, catalog[Nc].average[j].R, catalog[Nc].average[j].D);
     382      // XXX : this whole function is deprecated
     383      // BoundaryTreePrimaryCell(primaryCell, catalog[Nc].average[j].R, catalog[Nc].average[j].D);
    369384    }
    370385
     
    833848  if (primaryCell) free (primaryCell);
    834849  return (TRUE);
     850# endif
    835851}
    836852
     
    890906  }
    891907  return (TRUE);
     908}
     909
     910int markObjects (Catalog *catalog, int Ncatalog) {
     911
     912  int i, n;
     913  off_t j;
     914
     915  // How strongly do I own this object?
     916  for (i = 0; i < Ncatalog; i++) {
     917    for (j = 0; j < catalog[i].Naverage; j++) {
     918      int nOwn = 0;
     919      int m = catalog[i].averageT[j].measureOffset;
     920      for (n = 0; n < catalog[i].averageT[j].Nmeasure; n++) {
     921        if (!catalog[i].measureT[m+n].myDet) continue;
     922        nOwn ++;
     923      }
     924      catalog[i].averageT[j].nOwn = nOwn;
     925    }
     926  }
     927  return TRUE;
     928}
     929
     930int dumpObjects (char *filename, Catalog *catalog, int Ncatalog) {
     931
     932  int i, n;
     933  off_t j;
     934
     935  FILE *ftest = fopen (filename, "w");
     936
     937  for (i = 0; i < Ncatalog; i++) {
     938    for (j = 0; j < catalog[i].Naverage; j++) {
     939      int m = catalog[i].averageT[j].measureOffset;
     940      for (n = 0; n < catalog[i].averageT[j].Nmeasure; n++) {
     941        fprintf (ftest, "%08x %08x %10.6f %10.6f  %3d %1d\n", catalog[i].averageT[j].catID, catalog[i].averageT[j].objID, catalog[i].averageT[j].R, catalog[i].averageT[j].D, catalog[i].averageT[j].Nmeasure, catalog[i].measureT[m+n].myDet);
     942      }
     943    }
     944  }
     945  fclose (ftest);
     946  return TRUE;
    892947}
    893948
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/args.c

    r35806 r36680  
    11# include "relphot.h"
    22
    3 int args (int argc, char **argv) {
     3RelphotMode args (int argc, char **argv) {
    44
    55  int N;
    66  double trange;
     7
     8  /* define time */
     9  TimeSelect = FALSE;
     10  if ((N = get_argument (argc, argv, "-time"))) {
     11    remove_argument (N, &argc, argv);
     12    if (!ohana_str_to_time (argv[N], &TSTART)) {
     13      fprintf (stderr, "ERROR: syntax error\n");
     14      return (MODE_ERROR);
     15    }
     16    remove_argument (N, &argc, argv);
     17    if (!ohana_str_to_dtime (argv[N], &trange)) {
     18      if (!ohana_str_to_time (argv[N], &TSTOP)) {
     19        fprintf (stderr, "ERROR: syntax error\n");
     20        return (MODE_ERROR);
     21      }
     22    } else {
     23      if (trange < 0) {
     24        trange = fabs (trange);
     25        TSTOP = TSTART;
     26        TSTART -= trange;
     27      } else {
     28        TSTOP = TSTART + trange;
     29      }
     30    }
     31    remove_argument (N, &argc, argv);
     32    TimeSelect = TRUE;
     33  }
     34
     35  /* specify portion of the sky */
     36  UserPatch.Rmin = 0;
     37  UserPatch.Rmax = 360;
     38  UserPatch.Dmin = -90;
     39  UserPatch.Dmax = +90;
     40  if ((N = get_argument (argc, argv, "-region"))) {
     41    remove_argument (N, &argc, argv);
     42    UserPatch.Rmin = atof (argv[N]);
     43    remove_argument (N, &argc, argv);
     44    UserPatch.Rmax = atof (argv[N]);
     45    remove_argument (N, &argc, argv);
     46    UserPatch.Dmin = atof (argv[N]);
     47    remove_argument (N, &argc, argv);
     48    UserPatch.Dmax = atof (argv[N]);
     49    remove_argument (N, &argc, argv);
     50  }
     51
     52  /* specify region file by name (eg n0000/0000.00) */
     53  UserCatalog = NULL;
     54  if ((N = get_argument (argc, argv, "-catalog"))) {
     55    remove_argument (N, &argc, argv);
     56    UserCatalog = strcreate (argv[N]);
     57    remove_argument (N, &argc, argv);
     58  }
     59
     60  USE_BASIC_CHECK = FALSE;
     61  if ((N = get_argument (argc, argv, "-basic-image-search"))) {
     62    remove_argument (N, &argc, argv);
     63    USE_BASIC_CHECK = TRUE;
     64  }
     65
     66  USE_FULL_OVERLAP = TRUE;
     67  if ((N = get_argument (argc, argv, "-sloppy-image-overlap"))) {
     68    remove_argument (N, &argc, argv);
     69    USE_FULL_OVERLAP = FALSE;
     70  }
     71
     72  SET_MREL_VERSION = 1;
     73  if ((N = get_argument (argc, argv, "-set-mrel-version"))) {
     74    remove_argument (N, &argc, argv);
     75    SET_MREL_VERSION = atof(argv[N]);
     76    remove_argument (N, &argc, argv);
     77  }
     78
     79  VERBOSE = VERBOSE2 = FALSE;
     80  if ((N = get_argument (argc, argv, "-v"))) {
     81    VERBOSE = TRUE;
     82    remove_argument (N, &argc, argv);
     83  }
     84  if ((N = get_argument (argc, argv, "-vv"))) {
     85    VERBOSE2 = VERBOSE = TRUE;
     86    remove_argument (N, &argc, argv);
     87  }
     88
     89  NTHREADS = 0;
     90  if ((N = get_argument (argc, argv, "-threads"))) {
     91    remove_argument (N, &argc, argv);
     92    NTHREADS = atof (argv[N]);
     93    remove_argument (N, &argc, argv);
     94  }
     95
     96  // XXX for the moment, make this selection manual.  it needs to be automatic
     97  // based on the state of the SkyTable
     98  HOST_ID = 0;
     99  PARALLEL = FALSE;
     100  if ((N = get_argument (argc, argv, "-parallel"))) {
     101    PARALLEL = TRUE;
     102    remove_argument (N, &argc, argv);
     103  }
     104  // this is a test mode : rather than launching the remote jobs and waiting for completion,
     105  // relphot will simply list the remote command and wait for the user to signal completion
     106  PARALLEL_MANUAL = FALSE;
     107  if ((N = get_argument (argc, argv, "-parallel-manual"))) {
     108    PARALLEL = TRUE; // -parallel-manual implies -parallel
     109    PARALLEL_MANUAL = TRUE;
     110    remove_argument (N, &argc, argv);
     111  }
     112  // this is a test mode : rather than launching the relphot_client jobs remotely, they are
     113  // run in serial via 'system'
     114  PARALLEL_SERIAL = FALSE;
     115  if ((N = get_argument (argc, argv, "-parallel-serial"))) {
     116    if (PARALLEL_MANUAL) {
     117      fprintf (stderr, "ERROR: cannot mix -parallel-manual and -parallel-serial\n");
     118      exit (1);
     119    }
     120    PARALLEL = TRUE; // -parallel-serial implies -parallel
     121    PARALLEL_SERIAL = TRUE;
     122    remove_argument (N, &argc, argv);
     123  }
     124
     125  PLOTSTUFF = FALSE;
     126  if ((N = get_argument (argc, argv, "-plot"))) {
     127    PLOTSTUFF = TRUE;
     128    remove_argument (N, &argc, argv);
     129  }
     130
     131  PLOTDELAY = 500000;
     132  if ((N = get_argument (argc, argv, "-plotdelay"))) {
     133    remove_argument (N, &argc, argv);
     134    PLOTDELAY = 1e6*atof(argv[N]);
     135    PLOTSTUFF = TRUE; // always turn on plotting if i request a plot delay
     136    remove_argument (N, &argc, argv);
     137  }
     138
     139  if ((N = get_argument (argc, argv, "-outroot"))) {
     140    remove_argument (N, &argc, argv);
     141    OUTROOT = strcreate (argv[N]);
     142    remove_argument (N, &argc, argv);
     143  } else {
     144    OUTROOT = strcreate ("relphot");
     145  }     
     146
     147  strcpy (STATMODE, "WT_MEAN");
     148  if ((N = get_argument (argc, argv, "-statmode"))) {
     149    remove_argument (N, &argc, argv);
     150    strcpy (STATMODE, argv[N]);
     151    remove_argument (N, &argc, argv);
     152  }
     153
     154  NLOOP = 8;
     155  if ((N = get_argument (argc, argv, "-n"))) {
     156    remove_argument (N, &argc, argv);
     157    NLOOP = atof (argv[N]);
     158    remove_argument (N, &argc, argv);
     159  }
     160  if ((N = get_argument (argc, argv, "-nloop"))) {
     161    remove_argument (N, &argc, argv);
     162    NLOOP = atof (argv[N]);
     163    remove_argument (N, &argc, argv);
     164  }
     165
     166  NGRID = 8;
     167  if ((N = get_argument (argc, argv, "-ngrid"))) {
     168    remove_argument (N, &argc, argv);
     169    NGRID = atof (argv[N]);
     170    remove_argument (N, &argc, argv);
     171  }
     172
     173  RESET = FALSE;
     174  if ((N = get_argument (argc, argv, "-reset"))) {
     175    remove_argument (N, &argc, argv);
     176    RESET = TRUE;
     177  }
     178
     179  RESET_ZEROPTS = FALSE;
     180  if ((N = get_argument (argc, argv, "-reset-zpts"))) {
     181    remove_argument (N, &argc, argv);
     182    RESET_ZEROPTS = TRUE;
     183  }
     184
     185  UPDATE = FALSE;
     186  if ((N = get_argument (argc, argv, "-update"))) {
     187    remove_argument (N, &argc, argv);
     188    UPDATE = TRUE;
     189  }
     190
     191  UPDATE_CATFORMAT = NULL;
     192  if ((N = get_argument (argc, argv, "-update-catformat"))) {
     193    remove_argument (N, &argc, argv);
     194    UPDATE_CATFORMAT = strcreate (argv[N]);
     195    remove_argument (N, &argc, argv);
     196  }
     197
     198  SAVE_IMAGE_UPDATES = TRUE;
     199  if ((N = get_argument (argc, argv, "-skip-image-updates"))) {
     200    remove_argument (N, &argc, argv);
     201    SAVE_IMAGE_UPDATES = FALSE;
     202  }
     203
     204  MaxDensityUse = FALSE;
     205  if ((N = get_argument (argc, argv, "-max-density"))) {
     206    remove_argument (N, &argc, argv);
     207    MaxDensityValue = atof(argv[N]);
     208    remove_argument (N, &argc, argv);
     209    MaxDensityUse = TRUE;
     210  }
     211
     212  CLOUD_TOLERANCE = 0.02;
     213  if ((N = get_argument (argc, argv, "-cloud-limit"))) {
     214    remove_argument (N, &argc, argv);
     215    CLOUD_TOLERANCE = atof(argv[N]);
     216    remove_argument (N, &argc, argv);
     217  }
     218
     219  // XXX should we load a tree from CATDIR by default?
     220  // NOTE: a given catdir needs an appropriate boundary tree
     221  BOUNDARY_TREE = NULL;
     222  if ((N = get_argument (argc, argv, "-boundary-tree"))) {
     223    remove_argument (N, &argc, argv);
     224    BOUNDARY_TREE = strcreate(argv[N]);
     225    load_tess (BOUNDARY_TREE);
     226    remove_argument (N, &argc, argv);
     227  }
     228
     229  SHOW_PARAMS = FALSE;
     230  if ((N = get_argument (argc, argv, "-params"))) {
     231    remove_argument (N, &argc, argv);
     232    SHOW_PARAMS = TRUE;
     233  }
     234
     235  PlotMmin = 10.0; PlotMmax = 20.0; PlotdMmin = -1.0; PlotdMmax = 1.0;
     236  if ((N = get_argument (argc, argv, "-plrange"))) {
     237    remove_argument (N, &argc, argv);
     238    PlotMmin = atof (argv[N]);
     239    remove_argument (N, &argc, argv);
     240    PlotMmax = atof (argv[N]);
     241    remove_argument (N, &argc, argv);
     242    PlotdMmin = atof (argv[N]);
     243    remove_argument (N, &argc, argv);
     244    PlotdMmax = atof (argv[N]);
     245    remove_argument (N, &argc, argv);
     246  }
     247
     248  /* XXX this argument used to do two things: specify the camera name and tell the analysis to
     249     calculate a common zero point for a single mosaic.  I've moved the MOSAICNAME concept into the
     250     config system, but need to use this argument to specify that the mosaic zeropoints should be
     251     calculated. */
     252  MOSAIC_ZEROPT = FALSE;
     253  if ((N = get_argument (argc, argv, "-mosaic"))) {
     254    remove_argument (N, &argc, argv);
     255    MOSAIC_ZEROPT = TRUE;
     256    if (!strcasecmp (MOSAICNAME, "none")) {
     257      fprintf (stderr, "mosaic astrometry selected by MOSAICNAME not defined\n");
     258      exit (2);
     259    }
     260  }
     261
     262  FREEZE_IMAGES = FALSE;
     263  if ((N = get_argument (argc, argv, "-imfreeze"))) {
     264    remove_argument (N, &argc, argv);
     265    FREEZE_IMAGES = TRUE;
     266  }
     267
     268  FREEZE_MOSAICS = FALSE;
     269  if ((N = get_argument (argc, argv, "-mosfreeze"))) {
     270    remove_argument (N, &argc, argv);
     271    FREEZE_MOSAICS = TRUE;
     272  }
     273
     274  // USE_GRID is not valid for all cases, probably should be its own mode...
     275  USE_GRID = FALSE;
     276  if ((N = get_argument (argc, argv, "-grid"))) {
     277    remove_argument (N, &argc, argv);
     278    USE_GRID = TRUE;
     279  }
     280
     281  KEEP_UBERCAL = TRUE;
     282  if ((N = get_argument (argc, argv, "-reset-ubercal"))) {
     283    remove_argument (N, &argc, argv);
     284    KEEP_UBERCAL = FALSE;
     285  }
     286
     287  MIN_ERROR = 0.001;
     288  if ((N = get_argument (argc, argv, "-minerror"))) {
     289    remove_argument (N, &argc, argv);
     290    MIN_ERROR = atof (argv[N]);
     291    remove_argument (N, &argc, argv);
     292    /* require MIN_ERROR > 0 */
     293  } 
     294
     295  AreaSelect = FALSE;
     296  if ((N = get_argument (argc, argv, "-area"))) {
     297    remove_argument (N, &argc, argv);
     298    AreaXmin = atof (argv[N]);
     299    remove_argument (N, &argc, argv);
     300    AreaXmax = atof (argv[N]);
     301    remove_argument (N, &argc, argv);
     302    AreaYmin = atof (argv[N]);
     303    remove_argument (N, &argc, argv);
     304    AreaYmax = atof (argv[N]);
     305    remove_argument (N, &argc, argv);
     306    AreaSelect = TRUE;
     307  }
     308
     309  ImagSelect = FALSE;
     310  if ((N = get_argument (argc, argv, "-instmag"))) {
     311    remove_argument (N, &argc, argv);
     312    ImagMin = atof (argv[N]);
     313    remove_argument (N, &argc, argv);
     314    ImagMax = atof (argv[N]);
     315    remove_argument (N, &argc, argv);
     316    ImagSelect = TRUE;
     317  }
     318
     319  DophotSelect = FALSE;
     320  if ((N = get_argument (argc, argv, "-dophot"))) {
     321    remove_argument (N, &argc, argv);
     322    DophotValue = atof (argv[N]);
     323    remove_argument (N, &argc, argv);
     324    DophotSelect = TRUE;
     325  }
     326
     327  SyntheticPhotometry = FALSE;
     328  if ((N = get_argument (argc, argv, "-synthphot"))) {
     329    remove_argument (N, &argc, argv);
     330    SyntheticPhotometry = TRUE;
     331    init_synthetic_mags();
     332  }
     333
     334  refPhotcode = NULL;
     335  if ((N = get_argument (argc, argv, "-refcode"))) {
     336    remove_argument (N, &argc, argv);
     337    refPhotcode = GetPhotcodebyName (argv[N]);
     338    if (!refPhotcode) {
     339      fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", argv[N]);
     340      exit (1);
     341    }
     342    remove_argument (N, &argc, argv);
     343  }
     344
     345  REGION_FILE = NULL;
     346  if ((N = get_argument (argc, argv, "-region-hosts"))) {
     347    remove_argument (N, &argc, argv);
     348    REGION_FILE = strcreate (argv[N]);
     349    remove_argument (N, &argc, argv);
     350  }
     351
     352  REGION_HOST_ID = 0;
     353  if ((N = get_argument (argc, argv, "-region-hostID"))) {
     354    remove_argument (N, &argc, argv);
     355    REGION_HOST_ID = atoi (argv[N]);
     356    remove_argument (N, &argc, argv);
     357  }
     358
     359  RelphotMode mode = MODE_ERROR;
     360  if ((N = get_argument (argc, argv, "-images"))) {
     361    remove_argument (N, &argc, argv);
     362    mode = UPDATE_IMAGES;
     363  }
     364  if ((N = get_argument (argc, argv, "-averages"))) {
     365    remove_argument (N, &argc, argv);
     366    mode = UPDATE_AVERAGES;
     367  }
     368  if ((N = get_argument (argc, argv, "-apply-offsets"))) {
     369    remove_argument (N, &argc, argv);
     370    mode = APPLY_OFFSETS;
     371  }
     372  IMAGE_TABLE = NULL;
     373  if ((N = get_argument (argc, argv, "-parallel-images"))) {
     374    remove_argument (N, &argc, argv);
     375    mode = PARALLEL_IMAGES;
     376    if (N >= argc) relphot_usage();
     377    IMAGE_TABLE = strcreate (argv[N]);
     378    remove_argument (N, &argc, argv);
     379    if (!REGION_FILE) relphot_usage();
     380  }
     381
     382  PARALLEL_REGIONS_MANUAL = FALSE;
     383  if ((N = get_argument (argc, argv, "-parallel-regions"))) {
     384    remove_argument (N, &argc, argv);
     385    mode = PARALLEL_REGIONS;
     386    if (!REGION_FILE) relphot_usage();
     387    if ((N = get_argument (argc, argv, "-parallel-regions-manual"))) {
     388      remove_argument (N, &argc, argv);
     389      PARALLEL_REGIONS_MANUAL = TRUE;
     390    }
     391  }
     392
     393  switch (mode) {
     394    case UPDATE_AVERAGES:
     395      if (argc != 1) relphot_usage();
     396      break;
     397     
     398    case UPDATE_IMAGES:
     399    case PARALLEL_IMAGES:
     400    case PARALLEL_REGIONS:
     401      PhotcodeList = strcreate (argv[1]);
     402      photcodes = ParsePhotcodeList (PhotcodeList, &Nphotcodes, TRUE); // require SEC photcodes
     403      remove_argument (1, &argc, argv);
     404      break;
     405
     406    default:
     407      fprintf (stderr, "no valid mode selected\n");
     408      relphot_usage();
     409      break;
     410  }
     411  if (argc != 1) relphot_usage ();
     412
     413  return mode;
     414}
     415
     416int args_client (int argc, char **argv) {
     417
     418  int N;
     419  double trange;
     420
     421  // by definition, the client is not parallel
     422  PARALLEL = FALSE;
     423  PARALLEL_MANUAL = FALSE;
     424  PARALLEL_SERIAL = FALSE;
     425
     426  HOST_ID = 0;
     427  if ((N = get_argument (argc, argv, "-hostID"))) {
     428    remove_argument (N, &argc, argv);
     429    HOST_ID = atoi (argv[N]);
     430    remove_argument (N, &argc, argv);
     431  }
     432  if (!HOST_ID) relphot_client_usage();
     433
     434  HOSTDIR = NULL;
     435  if ((N = get_argument (argc, argv, "-hostdir"))) {
     436    remove_argument (N, &argc, argv);
     437    HOSTDIR = strcreate (argv[N]);
     438    remove_argument (N, &argc, argv);
     439  }
     440  if (!HOSTDIR) relphot_client_usage();
     441
     442  IMAGES = NULL; // used in -update mode
     443  BCATALOG = NULL; // used in -load mode
     444  MODE = MODE_NONE;
     445  if ((N = get_argument (argc, argv, "-load"))) {
     446    MODE = MODE_LOAD;
     447    remove_argument (N, &argc, argv);
     448    BCATALOG = strcreate (argv[N]);
     449    remove_argument (N, &argc, argv);
     450  }
     451  if ((N = get_argument (argc, argv, "-update-catalogs"))) {
     452    if (MODE) {
     453      fprintf (stderr, "ERROR: cannot mix modes (-load, -update-catalogs, -update-objects)\n");
     454      relphot_client_usage();
     455    }
     456    MODE = MODE_UPDATE;
     457    remove_argument (N, &argc, argv);
     458    IMAGES = strcreate (argv[N]);
     459    remove_argument (N, &argc, argv);
     460  }
     461  if ((N = get_argument (argc, argv, "-update-objects"))) {
     462    if (MODE) {
     463      fprintf (stderr, "ERROR: cannot mix modes (-load, -update-catalogs, -update-objects)\n");
     464      relphot_client_usage();
     465    }
     466    MODE = MODE_UPDATE_OBJECTS;
     467    remove_argument (N, &argc, argv);
     468  }
     469  if (!MODE) relphot_client_usage();
     470
     471  strcpy (STATMODE, "WT_MEAN");
     472  if ((N = get_argument (argc, argv, "-statmode"))) {
     473    remove_argument (N, &argc, argv);
     474    strcpy (STATMODE, argv[N]);
     475    remove_argument (N, &argc, argv);
     476  }
     477
     478  BOUNDARY_TREE = NULL;
     479  if ((N = get_argument (argc, argv, "-boundary-tree"))) {
     480    remove_argument (N, &argc, argv);
     481    BOUNDARY_TREE = strcreate(argv[N]);
     482    load_tess (BOUNDARY_TREE);
     483    remove_argument (N, &argc, argv);
     484  }
     485
     486  /* specify portion of the sky */
     487  UserPatch.Rmin = 0;
     488  UserPatch.Rmax = 360;
     489  UserPatch.Dmin = -90;
     490  UserPatch.Dmax = +90;
     491  if ((N = get_argument (argc, argv, "-region"))) {
     492    remove_argument (N, &argc, argv);
     493    UserPatch.Rmin = atof (argv[N]);
     494    remove_argument (N, &argc, argv);
     495    UserPatch.Rmax = atof (argv[N]);
     496    remove_argument (N, &argc, argv);
     497    UserPatch.Dmin = atof (argv[N]);
     498    remove_argument (N, &argc, argv);
     499    UserPatch.Dmax = atof (argv[N]);
     500    remove_argument (N, &argc, argv);
     501  }
     502
     503  SET_MREL_VERSION = 1;
     504  if ((N = get_argument (argc, argv, "-set-mrel-version"))) {
     505    remove_argument (N, &argc, argv);
     506    SET_MREL_VERSION = atof(argv[N]);
     507    remove_argument (N, &argc, argv);
     508  }
     509
     510  VERBOSE = VERBOSE2 = FALSE;
     511  if ((N = get_argument (argc, argv, "-v"))) {
     512    VERBOSE = TRUE;
     513    remove_argument (N, &argc, argv);
     514  }
     515  if ((N = get_argument (argc, argv, "-vv"))) {
     516    VERBOSE2 = VERBOSE = TRUE;
     517    remove_argument (N, &argc, argv);
     518  }
     519
     520  RESET = FALSE;
     521  if ((N = get_argument (argc, argv, "-reset"))) {
     522    remove_argument (N, &argc, argv);
     523    RESET = TRUE;
     524  }
     525
     526  RESET_ZEROPTS = FALSE;
     527  if ((N = get_argument (argc, argv, "-reset-zpts"))) {
     528    remove_argument (N, &argc, argv);
     529    RESET_ZEROPTS = TRUE;
     530  }
     531
     532  KEEP_UBERCAL = TRUE;
     533  if ((N = get_argument (argc, argv, "-reset-ubercal"))) {
     534    remove_argument (N, &argc, argv);
     535    KEEP_UBERCAL = FALSE;
     536  }
    7537
    8538  /* define time */
     
    33563  }
    34564
    35   /* specify portion of the sky */
    36   UserPatch.Rmin = 0;
    37   UserPatch.Rmax = 360;
    38   UserPatch.Dmin = -90;
    39   UserPatch.Dmax = +90;
    40   if ((N = get_argument (argc, argv, "-region"))) {
    41     remove_argument (N, &argc, argv);
    42     UserPatch.Rmin = atof (argv[N]);
    43     remove_argument (N, &argc, argv);
    44     UserPatch.Rmax = atof (argv[N]);
    45     remove_argument (N, &argc, argv);
    46     UserPatch.Dmin = atof (argv[N]);
    47     remove_argument (N, &argc, argv);
    48     UserPatch.Dmax = atof (argv[N]);
    49     remove_argument (N, &argc, argv);
    50   }
    51 
    52   /* specify region file by name (eg n0000/0000.00) */
    53   UserCatalog = NULL;
    54   if ((N = get_argument (argc, argv, "-catalog"))) {
    55     remove_argument (N, &argc, argv);
    56     UserCatalog = strcreate (argv[N]);
    57     remove_argument (N, &argc, argv);
    58   }
    59 
    60   USE_BASIC_CHECK = FALSE;
    61   if ((N = get_argument (argc, argv, "-basic-image-search"))) {
    62     remove_argument (N, &argc, argv);
    63     USE_BASIC_CHECK = TRUE;
    64   }
    65 
    66   USE_FULL_OVERLAP = TRUE;
    67   if ((N = get_argument (argc, argv, "-sloppy-image-overlap"))) {
    68     remove_argument (N, &argc, argv);
    69     USE_FULL_OVERLAP = FALSE;
    70   }
    71 
    72   SET_MREL_VERSION = 1;
    73   if ((N = get_argument (argc, argv, "-set-mrel-version"))) {
    74     remove_argument (N, &argc, argv);
    75     SET_MREL_VERSION = atof(argv[N]);
    76     remove_argument (N, &argc, argv);
    77   }
    78 
    79   VERBOSE = VERBOSE2 = FALSE;
    80   if ((N = get_argument (argc, argv, "-v"))) {
    81     VERBOSE = TRUE;
    82     remove_argument (N, &argc, argv);
    83   }
    84   if ((N = get_argument (argc, argv, "-vv"))) {
    85     VERBOSE2 = VERBOSE = TRUE;
    86     remove_argument (N, &argc, argv);
    87   }
    88 
    89   NTHREADS = 0;
    90   if ((N = get_argument (argc, argv, "-threads"))) {
    91     remove_argument (N, &argc, argv);
    92     NTHREADS = atof (argv[N]);
    93     remove_argument (N, &argc, argv);
    94   }
    95 
    96   // XXX for the moment, make this selection manual.  it needs to be automatic
    97   // based on the state of the SkyTable
    98   HOST_ID = 0;
    99   PARALLEL = FALSE;
    100   if ((N = get_argument (argc, argv, "-parallel"))) {
    101     PARALLEL = TRUE;
    102     remove_argument (N, &argc, argv);
    103   }
    104   // this is a test mode : rather than launching the remote jobs and waiting for completion,
    105   // relphot will simply list the remote command and wait for the user to signal completion
    106   PARALLEL_MANUAL = FALSE;
    107   if ((N = get_argument (argc, argv, "-parallel-manual"))) {
    108     PARALLEL = TRUE; // -parallel-manual implies -parallel
    109     PARALLEL_MANUAL = TRUE;
    110     remove_argument (N, &argc, argv);
    111   }
    112   // this is a test mode : rather than launching the relphot_client jobs remotely, they are
    113   // run in serial via 'system'
    114   PARALLEL_SERIAL = FALSE;
    115   if ((N = get_argument (argc, argv, "-parallel-serial"))) {
    116     if (PARALLEL_MANUAL) {
    117       fprintf (stderr, "ERROR: cannot mix -parallel-manual and -parallel-serial\n");
    118       exit (1);
    119     }
    120     PARALLEL = TRUE; // -parallel-serial implies -parallel
    121     PARALLEL_SERIAL = TRUE;
    122     remove_argument (N, &argc, argv);
    123   }
    124 
    125   PLOTSTUFF = FALSE;
    126   if ((N = get_argument (argc, argv, "-plot"))) {
    127     PLOTSTUFF = TRUE;
    128     remove_argument (N, &argc, argv);
    129   }
    130 
    131   PLOTDELAY = 500000;
    132   if ((N = get_argument (argc, argv, "-plotdelay"))) {
    133     remove_argument (N, &argc, argv);
    134     PLOTDELAY = 1e6*atof(argv[N]);
    135     PLOTSTUFF = TRUE; // always turn on plotting if i request a plot delay
    136     remove_argument (N, &argc, argv);
    137   }
    138 
    139   if ((N = get_argument (argc, argv, "-outroot"))) {
    140     remove_argument (N, &argc, argv);
    141     OUTROOT = strcreate (argv[N]);
    142     remove_argument (N, &argc, argv);
    143   } else {
    144     OUTROOT = strcreate ("relphot");
    145   }     
    146 
    147   strcpy (STATMODE, "WT_MEAN");
    148   if ((N = get_argument (argc, argv, "-statmode"))) {
    149     remove_argument (N, &argc, argv);
    150     strcpy (STATMODE, argv[N]);
    151     remove_argument (N, &argc, argv);
    152   }
    153 
    154   NLOOP = 8;
    155   if ((N = get_argument (argc, argv, "-n"))) {
    156     remove_argument (N, &argc, argv);
    157     NLOOP = atof (argv[N]);
    158     remove_argument (N, &argc, argv);
    159   }
    160   if ((N = get_argument (argc, argv, "-nloop"))) {
    161     remove_argument (N, &argc, argv);
    162     NLOOP = atof (argv[N]);
    163     remove_argument (N, &argc, argv);
    164   }
    165 
    166   NGRID = 8;
    167   if ((N = get_argument (argc, argv, "-ngrid"))) {
    168     remove_argument (N, &argc, argv);
    169     NGRID = atof (argv[N]);
    170     remove_argument (N, &argc, argv);
    171   }
    172 
    173   RESET = FALSE;
    174   if ((N = get_argument (argc, argv, "-reset"))) {
    175     remove_argument (N, &argc, argv);
    176     RESET = TRUE;
    177   }
    178 
    179   RESET_ZEROPTS = FALSE;
    180   if ((N = get_argument (argc, argv, "-reset-zpts"))) {
    181     remove_argument (N, &argc, argv);
    182     RESET_ZEROPTS = TRUE;
    183   }
     565
     566  MIN_ERROR = 0.001;
     567  if ((N = get_argument (argc, argv, "-minerror"))) {
     568    remove_argument (N, &argc, argv);
     569    MIN_ERROR = atof (argv[N]);
     570    remove_argument (N, &argc, argv);
     571    /* require MIN_ERROR > 0 */
     572  } 
    184573
    185574  UPDATE = FALSE;
     
    196585  }
    197586
    198   SAVE_IMAGE_UPDATES = TRUE;
    199   if ((N = get_argument (argc, argv, "-skip-image-updates"))) {
    200     remove_argument (N, &argc, argv);
    201     SAVE_IMAGE_UPDATES = FALSE;
     587  AreaSelect = FALSE;
     588  if ((N = get_argument (argc, argv, "-area"))) {
     589    remove_argument (N, &argc, argv);
     590    AreaXmin = atof (argv[N]);
     591    remove_argument (N, &argc, argv);
     592    AreaXmax = atof (argv[N]);
     593    remove_argument (N, &argc, argv);
     594    AreaYmin = atof (argv[N]);
     595    remove_argument (N, &argc, argv);
     596    AreaYmax = atof (argv[N]);
     597    remove_argument (N, &argc, argv);
     598    AreaSelect = TRUE;
     599  }
     600
     601  SyntheticPhotometry = FALSE;
     602  if ((N = get_argument (argc, argv, "-synthphot"))) {
     603    remove_argument (N, &argc, argv);
     604    SyntheticPhotometry = FALSE;
     605    init_synthetic_mags();
     606  }
     607
     608  ImagSelect = FALSE;
     609  if ((N = get_argument (argc, argv, "-instmag"))) {
     610    remove_argument (N, &argc, argv);
     611    ImagMin = atof (argv[N]);
     612    remove_argument (N, &argc, argv);
     613    ImagMax = atof (argv[N]);
     614    remove_argument (N, &argc, argv);
     615    ImagSelect = TRUE;
     616  }
     617
     618  DophotSelect = FALSE;
     619  if ((N = get_argument (argc, argv, "-dophot"))) {
     620    remove_argument (N, &argc, argv);
     621    DophotValue = atof (argv[N]);
     622    remove_argument (N, &argc, argv);
     623    DophotSelect = TRUE;
    202624  }
    203625
     
    210632  }
    211633
    212   CLOUD_TOLERANCE = 0.02;
    213   if ((N = get_argument (argc, argv, "-cloud-limit"))) {
    214     remove_argument (N, &argc, argv);
    215     CLOUD_TOLERANCE = atof(argv[N]);
    216     remove_argument (N, &argc, argv);
    217   }
    218 
    219   BOUNDARY_TREE = NULL;
    220   if ((N = get_argument (argc, argv, "-boundary-tree"))) {
    221     remove_argument (N, &argc, argv);
    222     BOUNDARY_TREE = strcreate(argv[N]);
    223     load_tree (BOUNDARY_TREE);
    224     remove_argument (N, &argc, argv);
    225   }
    226 
    227   SHOW_PARAMS = FALSE;
    228   if ((N = get_argument (argc, argv, "-params"))) {
    229     remove_argument (N, &argc, argv);
    230     SHOW_PARAMS = TRUE;
    231   }
    232 
    233   PlotMmin = 10.0; PlotMmax = 20.0; PlotdMmin = -1.0; PlotdMmax = 1.0;
    234   if ((N = get_argument (argc, argv, "-plrange"))) {
    235     remove_argument (N, &argc, argv);
    236     PlotMmin = atof (argv[N]);
    237     remove_argument (N, &argc, argv);
    238     PlotMmax = atof (argv[N]);
    239     remove_argument (N, &argc, argv);
    240     PlotdMmin = atof (argv[N]);
    241     remove_argument (N, &argc, argv);
    242     PlotdMmax = atof (argv[N]);
    243     remove_argument (N, &argc, argv);
    244   }
    245 
    246   /* XXX this argument used to do two things: specify the camera name and tell the analysis to
    247      calculate a common zero point for a single mosaic.  I've moved the MOSAICNAME concept into the
    248      config system, but need to use this argument to specify that the mosaic zeropoints should be
    249      calculated. */
    250   MOSAIC_ZEROPT = FALSE;
    251   if ((N = get_argument (argc, argv, "-mosaic"))) {
    252     remove_argument (N, &argc, argv);
    253     MOSAIC_ZEROPT = TRUE;
    254     if (!strcasecmp (MOSAICNAME, "none")) {
    255       fprintf (stderr, "mosaic astrometry selected by MOSAICNAME not defined\n");
    256       exit (2);
    257     }
    258   }
    259 
    260   FREEZE_IMAGES = FALSE;
    261   if ((N = get_argument (argc, argv, "-imfreeze"))) {
    262     remove_argument (N, &argc, argv);
    263     FREEZE_IMAGES = TRUE;
    264   }
    265 
    266   FREEZE_MOSAICS = FALSE;
    267   if ((N = get_argument (argc, argv, "-mosfreeze"))) {
    268     remove_argument (N, &argc, argv);
    269     FREEZE_MOSAICS = TRUE;
    270   }
    271 
    272   USE_GRID = FALSE;
    273   if ((N = get_argument (argc, argv, "-grid"))) {
    274     remove_argument (N, &argc, argv);
    275     USE_GRID = TRUE;
    276   }
    277 
    278   KEEP_UBERCAL = TRUE;
    279   if ((N = get_argument (argc, argv, "-reset-ubercal"))) {
    280     remove_argument (N, &argc, argv);
    281     KEEP_UBERCAL = FALSE;
    282   }
    283 
    284   MIN_ERROR = 0.001;
    285   if ((N = get_argument (argc, argv, "-minerror"))) {
    286     remove_argument (N, &argc, argv);
    287     MIN_ERROR = atof (argv[N]);
    288     remove_argument (N, &argc, argv);
    289     /* require MIN_ERROR > 0 */
    290   } 
    291 
    292   AreaSelect = FALSE;
    293   if ((N = get_argument (argc, argv, "-area"))) {
    294     remove_argument (N, &argc, argv);
    295     AreaXmin = atof (argv[N]);
    296     remove_argument (N, &argc, argv);
    297     AreaXmax = atof (argv[N]);
    298     remove_argument (N, &argc, argv);
    299     AreaYmin = atof (argv[N]);
    300     remove_argument (N, &argc, argv);
    301     AreaYmax = atof (argv[N]);
    302     remove_argument (N, &argc, argv);
    303     AreaSelect = TRUE;
    304   }
    305 
    306   ImagSelect = FALSE;
    307   if ((N = get_argument (argc, argv, "-instmag"))) {
    308     remove_argument (N, &argc, argv);
    309     ImagMin = atof (argv[N]);
    310     remove_argument (N, &argc, argv);
    311     ImagMax = atof (argv[N]);
    312     remove_argument (N, &argc, argv);
    313     ImagSelect = TRUE;
    314   }
    315 
    316   DophotSelect = FALSE;
    317   if ((N = get_argument (argc, argv, "-dophot"))) {
    318     remove_argument (N, &argc, argv);
    319     DophotValue = atof (argv[N]);
    320     remove_argument (N, &argc, argv);
    321     DophotSelect = TRUE;
    322   }
    323 
    324   SyntheticPhotometry = FALSE;
    325   if ((N = get_argument (argc, argv, "-synthphot"))) {
    326     remove_argument (N, &argc, argv);
    327     SyntheticPhotometry = TRUE;
    328     init_synthetic_mags();
    329   }
    330 
    331   refPhotcode = NULL;
    332   if ((N = get_argument (argc, argv, "-refcode"))) {
    333     remove_argument (N, &argc, argv);
    334     refPhotcode = GetPhotcodebyName (argv[N]);
    335     if (!refPhotcode) {
    336       fprintf (stderr, "ERROR: photcode %s not found in photcode table\n", argv[N]);
    337       exit (1);
    338     }
    339     remove_argument (N, &argc, argv);
    340   }
    341 
    342   UpdateAverages = FALSE;
    343   if ((N = get_argument (argc, argv, "-averages"))) {
    344     remove_argument (N, &argc, argv);
    345     UpdateAverages = TRUE;
    346   }
    347 
    348   ApplyOffsets = FALSE;
    349   if ((N = get_argument (argc, argv, "-apply-offsets"))) {
    350     remove_argument (N, &argc, argv);
    351     ApplyOffsets = TRUE;
    352   }
    353 
    354   if (UpdateAverages && (argc == 1)) return TRUE;
    355   if (argc != 2) relphot_usage ();
     634  if ((MODE == MODE_UPDATE_OBJECTS)  && (argc == 1)) return TRUE;
     635  if (argc != 2) relphot_client_usage ();
    356636
    357637  return TRUE;
    358638}
    359639
    360 int args_client (int argc, char **argv) {
    361 
    362   int N;
    363   double trange;
    364 
    365   // by definition, the client is not parallel
    366   PARALLEL = FALSE;
    367   PARALLEL_MANUAL = FALSE;
    368   PARALLEL_SERIAL = FALSE;
    369 
    370   HOST_ID = 0;
    371   if ((N = get_argument (argc, argv, "-hostID"))) {
    372     remove_argument (N, &argc, argv);
    373     HOST_ID = atoi (argv[N]);
    374     remove_argument (N, &argc, argv);
    375   }
    376   if (!HOST_ID) relphot_client_usage();
    377 
    378   HOSTDIR = NULL;
    379   if ((N = get_argument (argc, argv, "-hostdir"))) {
    380     remove_argument (N, &argc, argv);
    381     HOSTDIR = strcreate (argv[N]);
    382     remove_argument (N, &argc, argv);
    383   }
    384   if (!HOSTDIR) relphot_client_usage();
    385 
    386   IMAGES = NULL; // used in -update mode
    387   BCATALOG = NULL; // used in -load mode
    388   MODE = MODE_NONE;
    389   if ((N = get_argument (argc, argv, "-load"))) {
    390     MODE = MODE_LOAD;
    391     remove_argument (N, &argc, argv);
    392     BCATALOG = strcreate (argv[N]);
    393     remove_argument (N, &argc, argv);
    394   }
    395   if ((N = get_argument (argc, argv, "-update-catalogs"))) {
    396     if (MODE) {
    397       fprintf (stderr, "ERROR: cannot mix modes (-load, -update-catalogs, -update-objects)\n");
    398       relphot_client_usage();
    399     }
    400     MODE = MODE_UPDATE;
    401     remove_argument (N, &argc, argv);
    402     IMAGES = strcreate (argv[N]);
    403     remove_argument (N, &argc, argv);
    404   }
    405   if ((N = get_argument (argc, argv, "-update-objects"))) {
    406     if (MODE) {
    407       fprintf (stderr, "ERROR: cannot mix modes (-load, -update-catalogs, -update-objects)\n");
    408       relphot_client_usage();
    409     }
    410     MODE = MODE_UPDATE_OBJECTS;
    411     remove_argument (N, &argc, argv);
    412   }
    413   if (!MODE) relphot_client_usage();
    414 
    415   strcpy (STATMODE, "WT_MEAN");
    416   if ((N = get_argument (argc, argv, "-statmode"))) {
    417     remove_argument (N, &argc, argv);
    418     strcpy (STATMODE, argv[N]);
    419     remove_argument (N, &argc, argv);
    420   }
    421 
    422   BOUNDARY_TREE = NULL;
    423   if ((N = get_argument (argc, argv, "-boundary-tree"))) {
    424     remove_argument (N, &argc, argv);
    425     BOUNDARY_TREE = strcreate(argv[N]);
    426     load_tree (BOUNDARY_TREE);
    427     remove_argument (N, &argc, argv);
    428   }
    429 
    430   /* specify portion of the sky */
    431   UserPatch.Rmin = 0;
    432   UserPatch.Rmax = 360;
    433   UserPatch.Dmin = -90;
    434   UserPatch.Dmax = +90;
    435   if ((N = get_argument (argc, argv, "-region"))) {
    436     remove_argument (N, &argc, argv);
    437     UserPatch.Rmin = atof (argv[N]);
    438     remove_argument (N, &argc, argv);
    439     UserPatch.Rmax = atof (argv[N]);
    440     remove_argument (N, &argc, argv);
    441     UserPatch.Dmin = atof (argv[N]);
    442     remove_argument (N, &argc, argv);
    443     UserPatch.Dmax = atof (argv[N]);
    444     remove_argument (N, &argc, argv);
    445   }
    446 
    447   SET_MREL_VERSION = 1;
    448   if ((N = get_argument (argc, argv, "-set-mrel-version"))) {
    449     remove_argument (N, &argc, argv);
    450     SET_MREL_VERSION = atof(argv[N]);
    451     remove_argument (N, &argc, argv);
    452   }
    453 
    454   VERBOSE = VERBOSE2 = FALSE;
    455   if ((N = get_argument (argc, argv, "-v"))) {
    456     VERBOSE = TRUE;
    457     remove_argument (N, &argc, argv);
    458   }
    459   if ((N = get_argument (argc, argv, "-vv"))) {
    460     VERBOSE2 = VERBOSE = TRUE;
    461     remove_argument (N, &argc, argv);
    462   }
    463 
    464   RESET = FALSE;
    465   if ((N = get_argument (argc, argv, "-reset"))) {
    466     remove_argument (N, &argc, argv);
    467     RESET = TRUE;
    468   }
    469 
    470   RESET_ZEROPTS = FALSE;
    471   if ((N = get_argument (argc, argv, "-reset-zpts"))) {
    472     remove_argument (N, &argc, argv);
    473     RESET_ZEROPTS = TRUE;
    474   }
    475 
    476   KEEP_UBERCAL = TRUE;
    477   if ((N = get_argument (argc, argv, "-reset-ubercal"))) {
    478     remove_argument (N, &argc, argv);
    479     KEEP_UBERCAL = FALSE;
    480   }
    481 
    482   /* define time */
    483   TimeSelect = FALSE;
    484   if ((N = get_argument (argc, argv, "-time"))) {
    485     remove_argument (N, &argc, argv);
    486     if (!ohana_str_to_time (argv[N], &TSTART)) {
    487       fprintf (stderr, "ERROR: syntax error\n");
    488       return (FALSE);
    489     }
    490     remove_argument (N, &argc, argv);
    491     if (!ohana_str_to_dtime (argv[N], &trange)) {
    492       if (!ohana_str_to_time (argv[N], &TSTOP)) {
    493         fprintf (stderr, "ERROR: syntax error\n");
    494         return (FALSE);
    495       }
    496     } else {
    497       if (trange < 0) {
    498         trange = fabs (trange);
    499         TSTOP = TSTART;
    500         TSTART -= trange;
    501       } else {
    502         TSTOP = TSTART + trange;
    503       }
    504     }
    505     remove_argument (N, &argc, argv);
    506     TimeSelect = TRUE;
    507   }
    508 
    509 
    510   MIN_ERROR = 0.001;
    511   if ((N = get_argument (argc, argv, "-minerror"))) {
    512     remove_argument (N, &argc, argv);
    513     MIN_ERROR = atof (argv[N]);
    514     remove_argument (N, &argc, argv);
    515     /* require MIN_ERROR > 0 */
    516   } 
    517 
    518   UPDATE = FALSE;
    519   if ((N = get_argument (argc, argv, "-update"))) {
    520     remove_argument (N, &argc, argv);
    521     UPDATE = TRUE;
    522   }
    523 
    524   UPDATE_CATFORMAT = NULL;
    525   if ((N = get_argument (argc, argv, "-update-catformat"))) {
    526     remove_argument (N, &argc, argv);
    527     UPDATE_CATFORMAT = strcreate (argv[N]);
    528     remove_argument (N, &argc, argv);
    529   }
    530 
    531   AreaSelect = FALSE;
    532   if ((N = get_argument (argc, argv, "-area"))) {
    533     remove_argument (N, &argc, argv);
    534     AreaXmin = atof (argv[N]);
    535     remove_argument (N, &argc, argv);
    536     AreaXmax = atof (argv[N]);
    537     remove_argument (N, &argc, argv);
    538     AreaYmin = atof (argv[N]);
    539     remove_argument (N, &argc, argv);
    540     AreaYmax = atof (argv[N]);
    541     remove_argument (N, &argc, argv);
    542     AreaSelect = TRUE;
    543   }
    544 
    545   SyntheticPhotometry = FALSE;
    546   if ((N = get_argument (argc, argv, "-synthphot"))) {
    547     remove_argument (N, &argc, argv);
    548     SyntheticPhotometry = FALSE;
    549     init_synthetic_mags();
    550   }
    551 
    552   ImagSelect = FALSE;
    553   if ((N = get_argument (argc, argv, "-instmag"))) {
    554     remove_argument (N, &argc, argv);
    555     ImagMin = atof (argv[N]);
    556     remove_argument (N, &argc, argv);
    557     ImagMax = atof (argv[N]);
    558     remove_argument (N, &argc, argv);
    559     ImagSelect = TRUE;
    560   }
    561 
    562   DophotSelect = FALSE;
    563   if ((N = get_argument (argc, argv, "-dophot"))) {
    564     remove_argument (N, &argc, argv);
    565     DophotValue = atof (argv[N]);
    566     remove_argument (N, &argc, argv);
    567     DophotSelect = TRUE;
    568   }
    569 
    570   MaxDensityUse = FALSE;
    571   if ((N = get_argument (argc, argv, "-max-density"))) {
    572     remove_argument (N, &argc, argv);
    573     MaxDensityValue = atof(argv[N]);
    574     remove_argument (N, &argc, argv);
    575     MaxDensityUse = TRUE;
    576   }
    577 
    578   if ((MODE == MODE_UPDATE_OBJECTS)  && (argc == 1)) return TRUE;
    579   if (argc != 2) relphot_client_usage ();
    580 
    581   return TRUE;
    582 }
    583 
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/client_logger.c

    r33963 r36680  
    55
    66static FILE *logfile = NULL;
    7 int client_logger_init () {
     7int client_logger_init (char *dirname) {
    88
    99  char filename[DVO_MAX_PATH];
    1010
    11   snprintf (filename, DVO_MAX_PATH, "%s/log.rlpc.XXXXXX", HOSTDIR);
     11  snprintf (filename, DVO_MAX_PATH, "%s/log.rlpc.XXXXXX", dirname);
    1212   
    1313  int fd = mkstemp (filename);
    1414  if (fd == -1) {
    15     fprintf (stderr, "failed to open client logger, exiting\n");
     15    fprintf (stderr, "failed to open client logger %s, exiting\n", filename);
    1616    exit (50);
    1717  }
     
    3232  vfprintf (logfile, format, argp);
    3333  va_end (argp);
     34
     35  fflush (logfile);
    3436  return TRUE;
    3537}
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/help.c

    r33651 r36680  
    22
    33void relphot_usage (void) {
    4   fprintf (stderr, "ERROR: USAGE: relphot (photcodes) -region RA RA DEC DEC\n");
    5   fprintf (stderr, "       or:    relphot (photcodes) -catalog (name)\n");
    6   fprintf (stderr, "       or:    relphot -averages -region RA RA DEC DEC\n");
     4  fprintf (stderr, "ERROR: USAGE: relphot (photcodes) -images\n");
     5  fprintf (stderr, "       or:    relphot -averages\n");
     6  fprintf (stderr, "       or:    relphot -apply-offsets\n");
     7  fprintf (stderr, "       or:    relphot (photcodes) -parallel-regions -region-hosts (RegionFile)\n");
     8  fprintf (stderr, "       or:    relphot (photcodes) -parallel-images (ImageTable) -region-hosts (RegionFile)\n\n");
     9  fprintf (stderr, "  regions:    -region RA RA DEC DEC)\n");
     10  fprintf (stderr, "       or:    -catalog (name)\n");
    711  fprintf (stderr, "  use -h for more usage information\n");
    812  exit (2);
     
    1822
    1923show_help:
    20   fprintf (stderr, "ERROR: USAGE: relphot (photcode) -region RA RA DEC DEC\n");
    21   fprintf (stderr, "       or:    relphot (photcode) -catalog (name)\n");
    22   fprintf (stderr, "       or:    relphot -averages -region RA RA DEC DEC\n");
     24  fprintf (stderr, "ERROR: USAGE: relphot (photcodes) -images\n");
     25  fprintf (stderr, "       or:    relphot -averages\n");
     26  fprintf (stderr, "       or:    relphot -apply-offsets\n");
     27  fprintf (stderr, "       or:    relphot (photcodes) -parallel-regions -region-hosts (RegionFile)\n");
     28  fprintf (stderr, "       or:    relphot (photcodes) -parallel-images (ImageTable) -region-hosts (RegionFile)\n\n");
     29  fprintf (stderr, "  regions:    -region RA RA DEC DEC)\n");
     30  fprintf (stderr, "       or:    -catalog (name)\n");
    2331  fprintf (stderr, "  options: \n");
    2432  fprintf (stderr, "  -time (start) (stop)\n");
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/initialize.c

    r34429 r36680  
    11# include "relphot.h"
    22
    3 void initialize (int argc, char **argv) {
     3RelphotMode initialize (int argc, char **argv) {
    44
    55  relphot_help (argc, argv);
    66  ConfigInit (&argc, argv);
    7   args (argc, argv);
     7  RelphotMode mode = args (argc, argv);
     8  if (!mode) exit (2);
    89
    9   if (!UpdateAverages) {
    10     // load the list of photcodes into the globals (photcodes, Nphotcodes)
    11     // only a single remaining argument in this mode (the list of photcodes, eg g,r,i)
    12     PhotcodeList = strcreate (argv[1]);
    13     photcodes = ParsePhotcodeList (PhotcodeList, &Nphotcodes, TRUE); // require SEC photcodes
    14   } else {
     10  // UPDATE_AVERAGES always operates on all photcodes?
     11  if (mode == UPDATE_AVERAGES) {
    1512    char tmpline1[256];
    1613    int Ns;
     
    6764  for (B = 0; A == time(NULL); B++);
    6865  srand48(B);
     66
     67  return mode;
    6968}
    7069
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/load_catalogs.c

    r35416 r36680  
    8989
    9090  fprintf (stderr, "using "OFF_T_FMT" of "OFF_T_FMT" stars ("OFF_T_FMT" of "OFF_T_FMT" measurements)\n", Nstar, Nstar_total, Nmeas, Nmeas_total);
    91   if (!hostID && (Nstar < 1)) Shutdown ("%s", "ERROR: no stars match the minimum requirements; exiting \n");
     91  if (!hostID && !REGION_HOST_ID && (Nstar < 1)) Shutdown ("%s", "ERROR: no stars match the minimum requirements; exiting \n");
    9292  // in regular relphot, we shutdown here; in relphot_client, we generate and return an empty table (for consistency)
    93    
    9493
    9594  // XXX consider only returning the populated catalogs
     
    107106# define DEBUG 1
    108107Catalog *load_catalogs_parallel (SkyList *sky, int *Ncatalog) {
     108
     109  char uniquer[12];
     110  int TIME = time(NULL);
     111  int PID = getpid();
     112  snprintf (uniquer, 12, "%05d.%05d", PID, TIME % 100000);
    109113
    110114  int Nsecfilt  = GetPhotcodeNsecfilt ();               // set the desired number in case we need to create the catalog
     
    128132
    129133    ALLOCATE (table->hosts[i].results, char, 1024);
    130     snprintf (table->hosts[i].results, 1024, "%s/relphot.catalog.subset.dat", table->hosts[i].pathname);
     134    snprintf (table->hosts[i].results, 1024, "%s/relphot.catalog.%s.dat", table->hosts[i].pathname, uniquer);
    131135
    132136    // options / arguments that can affect relphot_client -load:
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/reload_catalogs.c

    r35806 r36680  
    156156  // load the list of hosts
    157157  HostTable *table = HostTableLoad (CATDIR, sky->hosts);
     158  if (!table) {
     159    fprintf (stderr, "ERROR: problem with parallel host table\n");
     160    exit (2);
     161  }
    158162
    159163  if (BOUNDARY_TREE) {
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/relphot.c

    r35416 r36680  
    33int main (int argc, char **argv) {
    44
    5   /* get configuration info, args */
    6   initialize (argc, argv);
     5  // get configuration info, args
     6  RelphotMode mode = initialize (argc, argv);
     7  if (!mode) exit (2);
    78
    8   /* the object analysis is a separate process iterating over catalogs */
    9   if (UpdateAverages) {
    10     relphot_objects (0, NULL);
    11     exit (0);
     9  switch (mode) {
     10    case UPDATE_IMAGES:
     11      relphot_images ();
     12      exit (0);
     13
     14    case UPDATE_AVERAGES:
     15      // take the current set of detections and set the mean magnitudes
     16      relphot_objects (0, NULL);
     17      exit (0);
     18
     19    case PARALLEL_REGIONS:
     20      // run image updates in parallel across multiple remote machines
     21      relphot_parallel_regions ();
     22      exit (0);
     23
     24    case PARALLEL_IMAGES:
     25      // operation on the remote machines in the PARALLEL_REGION mode
     26      relphot_parallel_images ();
     27      exit (0);
     28
     29    case APPLY_OFFSETS:
     30      // re-run this step from a previous attempt (assumes an existing Images.subset.dat file)
     31      if (!PARALLEL) {
     32        fprintf (stderr, "-apply-offsets only makes sense in an parallel context\n");
     33        exit (2);
     34      }
     35      reload_catalogs (NULL, NULL, 0, NULL);
     36      exit (0);
     37
     38    default:
     39      fprintf (stderr, "ERROR: no valid relphot mode chosen\n");
     40      exit (2);
    1241  }
    13 
    14   if (ApplyOffsets) {
    15     // re-run this step from a previous attempt (assumes an existing Images.subset.dat file)
    16     if (!PARALLEL) {
    17       fprintf (stderr, "-apply-offsets only makes sense in an parallel context\n");
    18       exit (2);
    19     }
    20     reload_catalogs (NULL, NULL, 0, NULL);
    21     exit (0);
    22   }
    23 
    24   relphot_images ();
    25 
    26   exit (0);
     42  fprintf (stderr, "IMPOSSIBLE: skipped out of switch?\n");
     43  exit (1);
    2744}
    28 
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/relphot_client.c

    r33963 r36680  
    1919  // get configuration info, args, lockfile (set CATDIR, HOST_ID, HOSTDIR, etc)
    2020  initialize_client (argc, argv);
    21   client_logger_init ();
     21  client_logger_init (HOSTDIR);
    2222
    2323  // load the current sky table (layout of all SkyRegions)
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/relphot_images.c

    r35806 r36680  
    244244  if (!UPDATE) exit (0);
    245245 
    246   /* load catalog data from region files, update Mrel include all data */
     246  /* Load catalog data from region files, update Mrel include all data.  In a parallel
     247     context, this function writes the image parameters as a subset table for the remote
     248     clients */
    247249  reload_catalogs (skylist, flatcorr, 0, NULL);
    248250  MARKTIME("-- updated all catalogs: %f sec\n", dtime);
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/select_images.c

    r35806 r36680  
    4040  tcoords.pc1_1  = tcoords.pc2_2 = 1.0;
    4141  tcoords.pc1_2  = tcoords.pc2_1 = 0.0;
    42   strcpy (tcoords.ctype, "RA---TAN");
     42  strcpy (tcoords.ctype, "DEC--TAN");
    4343
    4444  double RminSkyRegion = region[0].Rmin;
     
    412412  tcoords.Npolyterms = 0;
    413413  memset (tcoords.polyterms, 0, 14*sizeof(float));
    414   strcpy (tcoords.ctype, "RA---TAN");
     414  strcpy (tcoords.ctype, "DEC--TAN");
    415415
    416416  /* compare with each region file */
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/relphot/src/setMrelCatalog.c

    r35759 r36680  
    3434  off_t j;
    3535
    36   liststats_setmode (&results->stats, STATMODE);
     36  liststats_setmode (&results->psfstats, STATMODE);
    3737  liststats_setmode (&results->apstats, STATMODE);
    3838  liststats_setmode (&results->kronstats, STATMODE);
     
    6767
    6868  off_t k;
    69   int N;
    7069  float Msys = 0, Mcal= 0, Mmos = 0, Mgrid = 0;
    7170
    72   double *list      = results->list;
    73   double *dlist     = results->dlist;
    74   double *wlist     = results->wlist;
    75   double *aplist    = results->aplist;
    76   double *kronlist  = results->kronlist;
     71  // we are measuring means for 3 types of mags: psf, ap, kron.  I am using the psf mag
     72  // error for the ap mags, but krons have their own errors.  it is an open question if I
     73  // should be doing weighted or unweighted fits (this is a user option)
     74  double *Mpsflist  = results->Mpsflist;
     75  double *dpsflist  = results->dpsflist;
     76  double *wpsflist  = results->wpsflist;
     77
     78  double *Maplist   = results->Maplist;
     79  double *daplist   = results->daplist;
     80  double *waplist   = results->waplist;
     81
     82  double *Mkronlist = results->Mkronlist;
    7783  double *dkronlist = results->dkronlist;
    78 
    79   StatType *stats = &results->stats;
    80   StatType *apstats = &results->apstats;
     84  double *wkronlist = results->wkronlist;
     85
     86  StatType *psfstats  = &results->psfstats;
     87  StatType *apstats   = &results->apstats;
    8188  StatType *kronstats = &results->kronstats;
    8289
     
    125132    off_t meas = measureOffset;
    126133
    127     N = 0;
     134    int Nap = 0;
     135    int Npsf = 0;
     136    int Nkron = 0;
    128137    for (k = 0; k < averageT[0].Nmeasure; k++, meas++) {
    129138
     
    135144
    136145      // are we a PS1 exposure photcode?
    137       if ((measure[k].photcode >= 10000) && (measure[k].photcode <= 10500)) {
     146      if ((measureT[k].photcode >= 10000) && (measureT[k].photcode <= 10500)) {
    138147        NexpPS1 ++;
    139148      }
     
    164173      int myUbercalDist = getUbercalDist(meas, cat);
    165174      minUbercalDist = MIN(minUbercalDist, myUbercalDist);
     175
     176      int isUbercal = (measureT[k].dbFlags & ID_MEAS_PHOTOM_UBERCAL);
     177      float dMpsf = MAX (hypot(measureT[k].dM, code->photomErrSys), MIN_ERROR);
     178
     179      if (isUbercal) haveUbercal = TRUE; // haveUbercal is set per secfilt, isUbercal is per measure
    166180
    167181      if (isSetMrelFinal) {
     
    231245          if (measureT[k].M < MaxMagForceSynth) {
    232246            forceSynth = TRUE;
    233             forceSynthEntry = N;
     247            forceSynthEntry = Npsf;
    234248          } else {
    235249            if (pass < 4) {
     
    240254        }
    241255
    242         // Map (aplist) and Mkron (kronlist,dkronlist) are used to calculate mean mags per filter
    243         float Map = PhotAper (&measure[k]);
    244         aplist[N] = Map - Mcal - Mmos - Mgrid;
    245 
    246         float Mkron = PhotKron (&measure[k]);
    247         kronlist[N] = Mkron - Mcal - Mmos - Mgrid;
    248         dkronlist[N] = measure[k].dMkron;
    249       }
     256        // Map (Maplist) and Mkron (Mkronlist,dkronlist) are used to calculate mean mags per filter
     257        float Map = PhotAperCat (&measure[k]);
     258        if (!isnan(Map)) {
     259            Maplist[Nap] = Map - Mcal - Mmos - Mgrid;
     260            daplist[Nap] = dMpsf;
     261            waplist[Nap] = isUbercal ? 10.0 : 1.0;
     262            Nap ++;
     263        }
     264
     265        float Mkron = PhotKronCat (&measure[k]);
     266        if (!isnan(Mkron)) {
     267          Mkronlist[Nkron] = Mkron - Mcal - Mmos - Mgrid;
     268          dkronlist[Nkron] = measure[k].dMkron;
     269          wkronlist[Nkron] = isUbercal ? 10.0 : 1.0;
     270          Nkron ++;
     271        }
     272      } // if (isSetMrelFinal)
    250273
    251274      // dlist gives the error per measurement, wlist gives the weight
     
    255278      // 3) UBERCAL measurements can have their weight increased by a big factor to help tie down the averages
    256279      // 4) some reference photcode of some kind can be specified as fixed and have a high weight
    257       dlist[N] = MAX (hypot(measureT[k].dM, code->photomErrSys), MIN_ERROR);
    258       wlist[N] = 1.0;
    259       list[N]  = Msys - Mcal - Mmos - Mgrid;
    260 
    261       // up-weight the ubercal values (or convergence can take a long time...)
    262       if (measureT[k].dbFlags & ID_MEAS_PHOTOM_UBERCAL) {
    263         haveUbercal = TRUE;
    264         wlist[N] = 10.0;
    265       }
     280      Mpsflist[Npsf] = Msys - Mcal - Mmos - Mgrid;
     281      dpsflist[Npsf] = dMpsf;
     282      wpsflist[Npsf] = isUbercal ? 10.0 : 1.0;
     283
     284      // NOTE:
     285      // Msys is measure[i].M + zp corrections
     286      // Mcal is image[j].Mcal
     287      // Mmos and Mgrid are offsets for mosaic and grid
    266288
    267289      // tie down reference photometry if the -refcode (code) option is selected
    268290      // eg, -refcode g_SDSS
    269291      // this probably makes no sense in the context of multifilter analysis
     292      // XXX probably need to use the photocde table to assign reference mag weights.
    270293      if (refPhotcode) {
    271294        if (code->code == refPhotcode->code) {
    272           wlist[N] = 100.0;
    273         }
    274       }
    275       N++;
     295          wpsflist[Npsf] = 100.0;
     296        }
     297      }
     298      Npsf ++;
    276299    }
    277300
     
    288311
    289312    // when performing the grid analysis, STAR_TOOFEW should be set to 1;
    290     if (N < Nminmeas) { /* too few measurements */
    291       // fprintf (f, "%10.6f %10.6f %d %d %d\n", averageT[0].R, averageT[0].D, measureT[0].imageID, N, STAR_TOOFEW);
     313    if (Npsf < Nminmeas) { /* too few measurements */
     314      // fprintf (f, "%10.6f %10.6f %d %d %d\n", averageT[0].R, averageT[0].D, measureT[0].imageID, Npsf, STAR_TOOFEW);
    292315      secfilt[Nsec].flags |= ID_STAR_FEW;
    293316      if (Ncode == 0) {
     
    303326    if (forceSynth) {
    304327      // use the single SYNTH value instead of the other mags here
    305       myAssert ((forceSynthEntry < N) && (forceSynthEntry >= 0), "programming error");
    306       list[0]  = list[forceSynthEntry];
    307       dlist[0] = dlist[forceSynthEntry];
    308       wlist[0] = wlist[forceSynthEntry];
    309       N = 1;
    310     }
    311     liststats (list, dlist, wlist, N, stats);
    312 
    313     secfilt[Nsec].M  = stats->mean;
    314     secfilt[Nsec].dM = stats->error;
    315     secfilt[Nsec].Xm = (stats->Nmeas > 1) ? 100.0*log10(stats->chisq + 1e-4) : NAN_S_SHORT;
     328      myAssert ((forceSynthEntry < Npsf) && (forceSynthEntry >= 0), "programming error");
     329      Mpsflist[0] = Mpsflist[forceSynthEntry];
     330      dpsflist[0] = dpsflist[forceSynthEntry];
     331      wpsflist[0] = wpsflist[forceSynthEntry];
     332      Npsf = 1;
     333    }
     334    liststats (Mpsflist, dpsflist, wpsflist, Npsf, psfstats);
     335
     336    secfilt[Nsec].M  = psfstats->mean;
     337    secfilt[Nsec].dM = psfstats->error;
     338    secfilt[Nsec].Xm = (psfstats->Nmeas > 1) ? 100.0*log10(psfstats->chisq + 1e-4) : NAN_S_SHORT;
    316339
    317340    // when running -averages, we have no information about the images, so we cannot set this
     
    323346      found[Nsec] = TRUE;
    324347
    325       secfilt[Nsec].Mstdev = 1000.0*stats->sigma; // Mstdev is in millimags (not enough space for more precision)
     348      secfilt[Nsec].Mstdev = 1000.0*psfstats->sigma; // Mstdev is in millimags (not enough space for more precision)
    326349      // secfilt[Nsec].Ncode = Ncode;
    327       secfilt[Nsec].Nused = stats->Nmeas;
    328 
    329       secfilt[Nsec].M_80 = 1000 * stats->Upper80;
    330       secfilt[Nsec].M_20 = 1000 * stats->Lower20;
     350      secfilt[Nsec].Nused = psfstats->Nmeas;
     351
     352      secfilt[Nsec].M_80 = 1000 * psfstats->Upper80;
     353      secfilt[Nsec].M_20 = 1000 * psfstats->Lower20;
    331354
    332355      // NOTE : use the modified weight for apmags as well as psf mags
    333       liststats (aplist, dlist, wlist, N, apstats);
    334       secfilt[Nsec].Map  = apstats->mean;
    335 
    336       liststats (kronlist, dkronlist, wlist, N, kronstats);
    337       secfilt[Nsec].Mkron  = kronstats->mean;
    338       secfilt[Nsec].dMkron = kronstats->error;
     356      liststats (Maplist, daplist, waplist, Nap, apstats);
     357      secfilt[Nsec].Map  = Nap > 0 ? apstats->mean : NAN;
     358
     359      liststats (Mkronlist, dkronlist, wkronlist, Nkron, kronstats);
     360      secfilt[Nsec].Mkron  = Nkron > 0 ? kronstats->mean  : NAN;
     361      secfilt[Nsec].dMkron = Nkron > 0 ? kronstats->error : NAN;
    339362
    340363      // NOTE: for 2MASS measurements, Next should be 1, as should N
    341       if ((Next > 0) && (Next > 0.5*N)) {
     364      if ((Next > 0) && (Next > 0.5*Npsf)) {
    342365        secfilt[Nsec].flags |= ID_SECF_OBJ_EXT;
    343366      }
     
    405428  float Msys = 0, Mcal= 0, Mmos = 0, Mgrid = 0;
    406429
    407   // set the name of the primary skycell (this is used in a strcmp to match the skycells in stack detections)
    408   // XXX drop BoundaryTreePrimaryCell(primaryCell, average[0].R, average[0].D);
     430  // set the primary projection cell and skycell for this coordinate
     431  int tessID    = -1;
    409432  int projectID = -1;
    410433  int skycellID = -1;
    411   BoundaryTreePrimaryCellIDs(&projectID, &skycellID, average[0].R, average[0].D);
     434  get_tess_ids(&tessID, &projectID, &skycellID, average[0].R, average[0].D);
    412435
    413436  int NstackGood = 0;
     
    477500      // which stack image should we use for the mean value?
    478501      // if we request the primary (USE_TREE_FOR_PRIMARY), then find the min distances for data from the primary cell
    479       if (MatchImageSkycellID (meas, cat, projectID, skycellID)) {
     502      if (MatchImageSkycellID (meas, cat, tessID, projectID, skycellID)) {
    480503        float stackPrimaryOffset = getCenterOffset (meas, cat, &measure[k], &stackImageID);
    481504        if (stackPrimaryOffset < stackPrimaryOffsetMin) {
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/tools/src/medianfilter.c

    r20652 r36680  
    9696    for (j = 0; j < Npixrd; j++, O++) {
    9797      Nvalid = 0;
     98      int debug = FALSE && (n == 5) && (j >= 1776779) && (j <= 1776789);
    9899      for (k = 0; k < Nfiles; k++) {
    99100        v = (float *)tmpmatr[k].buffer;
     101        if (debug) {
     102            fprintf (stderr, "%8.2f ", v[j]);
     103        }
    100104        if (v[j] < MinValid) continue;
    101         if (isnan(v[j])) continue;
    102         if (isinf(v[j])) continue;
    103         list[k] = v[j];
     105        if (isnan(v[j])) {
     106            continue;
     107        }
     108        if (isinf(v[j])) {
     109            continue;
     110        }
     111        list[Nvalid] = v[j];
    104112        Nvalid ++;
    105113      }
     114      if (debug) fprintf (stderr, "\n");
    106115      if (Nvalid == 0) {
    107         *O = 0.0;
     116        *O = NAN;
     117        if (debug) {
     118            fprintf (stderr, "Nvalid is 0\n");
     119        }
    108120        continue;
    109121      }
     
    111123      sum = 0;
    112124      Nval = 0;
     125      if (debug) fprintf (stderr, "list : ");
    113126      for (k = fmin*Nvalid; k < fmax*Nvalid; k++) {
     127        if (debug) {
     128            fprintf (stderr, "%8.2f ", list[k]);
     129        }
    114130        sum += list[k];
    115131        Nval ++;
    116132      }
    117133      *O = (sum / Nval);
     134      if (debug) {
     135          fprintf (stderr, " = %f / %f = %f\n", sum, Nval, *O);
     136          fprintf (stderr, "\n");
     137      }
    118138    }
    119139
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/uniphot/src/find_image_sgroups.c

    r31160 r36680  
    2222  coords.pc1_1 = coords.pc2_2 = 1.0;
    2323  coords.pc1_2 = coords.pc2_1 = 0.0;
    24   strcpy (coords.ctype, "RA---TAN");
     24  strcpy (coords.ctype, "DEC--TAN");
    2525 
    2626  Ngroup = 0;
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/uniphot/src/update_dvo_setphot.c

    r35103 r36680  
    22int update_dvo_setphot_parallel (SkyTable *sky, Image *image, off_t Nimage);
    33
     4// XXX convert this to use the ImageSubset to save space
    45int update_dvo_setphot (Image *image, off_t Nimage, FlatCorrectionTable *flatcorr) {
    56
  • branches/eam_branches/ps2-tc3-20130727/Ohana/src/uniphot/src/update_dvo_uniphot.c

    r34088 r36680  
    6161  coords.pc1_1 = coords.pc2_2 = 1.0;
    6262  coords.pc1_2 = coords.pc2_1 = 0.0;
    63   strcpy (coords.ctype, "RA---TAN");
     63  strcpy (coords.ctype, "DEC--TAN");
    6464 
    6565  for (i = 0; i < pglob.gl_pathc; i++) {
Note: See TracChangeset for help on using the changeset viewer.