IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39926 for trunk/Ohana


Ignore:
Timestamp:
Jan 6, 2017, 11:30:10 AM (10 years ago)
Author:
eugene
Message:

merging changes from czw dev branch (compare with r39924)

Location:
trunk
Files:
3 deleted
104 edited
14 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/Ohana

  • trunk/Ohana/Makefile.in

    r38473 r39926  
    138138
    139139rebuild:
     140        @date
    140141        $(MAKE) clean
    141142        $(MAKE) install
     143        @date
    142144
    143145# standard rules: targets are foo, foo.clean, foo.install, foo.dist
  • trunk/Ohana/src/addstar/Makefile

    r39496 r39926  
    2525load2mass    : $(BIN)/load2mass.$(ARCH)
    2626loadgalphot  : $(BIN)/loadgalphot.$(ARCH)
     27loadgaia     : $(BIN)/loadgaia.$(ARCH)
    2728loadstarpar  : $(BIN)/loadstarpar.$(ARCH)
    2829loadstarpar_client : $(BIN)/loadstarpar_client.$(ARCH)
     
    4243# programs in 'SERVER' use the client-server concept and are out of date
    4344
    44 INSTALL = addstar addstar_client sedstar loadgalphot loadstarpar loadstarpar_client setobjflags setobjflags_client loadICRF loadICRF_client skycells mkcmf dumpskycells findskycell load2mass loadwise loadtycho loadbsc loadsupercos
     45INSTALL = addstar addstar_client sedstar loadgalphot loadgaia loadstarpar loadstarpar_client setobjflags setobjflags_client loadICRF loadICRF_client skycells mkcmf dumpskycells findskycell load2mass loadwise loadtycho loadbsc loadsupercos
    4546SERVER  = addstarc addstard addstart
    4647
     
    267268$(SRC)/psps_ids.$(ARCH).o
    268269
    269 # $(SRC)/SkyRegionUtils.$(ARCH).o
    270 # $(SRC)/loadstarpar_io.$(ARCH).o
    271 # $(SRC)/loadgalphot_remote_hosts.$(ARCH).o
    272 # $(SRC)/loadgalphot_save_remote.$(ARCH).o
     270LOAD-GAIA = \
     271$(SRC)/loadgaia.$(ARCH).o \
     272$(SRC)/ConfigInit.$(ARCH).o \
     273$(SRC)/SetSignals.$(ARCH).o \
     274$(SRC)/Shutdown.$(ARCH).o \
     275$(SRC)/args_loadgaia.$(ARCH).o \
     276$(SRC)/find_matches_gaia.$(ARCH).o \
     277$(SRC)/loadgaia_catalog.$(ARCH).o \
     278$(SRC)/loadgaia_make_subset.$(ARCH).o \
     279$(SRC)/loadgaia_readstars.$(ARCH).o \
     280$(SRC)/loadgaia_table.$(ARCH).o \
     281$(SRC)/resort_catalog.$(ARCH).o \
     282$(SRC)/build_links.$(ARCH).o \
     283$(SRC)/strhash.$(ARCH).o \
     284$(SRC)/sortIDs.$(ARCH).o \
     285$(SRC)/psps_ids.$(ARCH).o
    273286
    274287LOAD-STARPAR = \
     
    493506$(LOAD-2MASS)          : $(INC)/addstar.h $(INC)/2mass.h
    494507$(LOAD-GALPHOT)        : $(INC)/addstar.h $(INC)/loadgalphot.h
     508$(LOAD-GAIA)           : $(INC)/addstar.h $(INC)/gaia.h
    495509$(LOAD-STARPAR)        : $(INC)/addstar.h $(INC)/loadstarpar.h
    496510$(LOAD-STARPAR-CLIENT) : $(INC)/addstar.h $(INC)/loadstarpar.h
     
    514528$(BIN)/loadbsc.$(ARCH)        : $(LOAD-BSC)
    515529$(BIN)/loadgalphot.$(ARCH)    : $(LOAD-GALPHOT)
     530$(BIN)/loadgaia.$(ARCH)       : $(LOAD-GAIA)
    516531$(BIN)/loadstarpar.$(ARCH)    : $(LOAD-STARPAR)
    517532$(BIN)/loadstarpar_client.$(ARCH) : $(LOAD-STARPAR-CLIENT)
  • trunk/Ohana/src/addstar/src/psps_ids.c

    r34701 r39926  
    4242
    4343    uint64_t part1, part2, part3;
    44     part1 = (uint64_t)( izone  * 10000000000000LL) ;
     44    part1 = (uint64_t)( izone  * 10000000000000LL) ; // 10,000,000,000,000
    4545    part2 = ((uint64_t)(ra * 1000000.)) * 10000 ; // 0 - 360*1e6 = 3.6e8 (< 29 bits)
    4646    part3 = (int) (zresid * 10000.0) ; // 0 - 10000 (1 bit == 30/10000 arcsec) (< 14 bits)
     
    4848    return part1 + part2 + part3;
    4949}
     50
     51// 10 000 000 000 000
  • trunk/Ohana/src/delstar/include/delstar.h

    r39692 r39926  
    9595int   SAVE_DELETES;
    9696int   SKIP_IMAGES;
     97char *BACKUP_EXTNAME;
    9798
    9899time_t    START;
     
    111112
    112113// for DELETE_MEASURES_BY_MATCH, these are the ranges to delete:
     114int DELETE_MIN_DET_ID;
     115int DELETE_MAX_DET_ID;
     116int DELETE_MIN_CAT_ID;
     117int DELETE_MAX_CAT_ID;
     118
    113119int DELETE_MIN_IMAGE_ID;
    114120int DELETE_MAX_IMAGE_ID;
     
    118124int DELETE_MIN_TIME;
    119125int DELETE_MAX_TIME;
    120 
    121126
    122127/*** delstar prototypes ***/
  • trunk/Ohana/src/delstar/src/args.c

    r39692 r39926  
    202202  }
    203203
     204  DELETE_MIN_DET_ID = 0;
     205  DELETE_MAX_DET_ID = 0;
     206  DELETE_MIN_CAT_ID = 0;
     207  DELETE_MAX_CAT_ID = 0;
    204208  DELETE_MIN_IMAGE_ID = 0;
    205209  DELETE_MAX_IMAGE_ID = 0;
     
    209213  DELETE_MAX_TIME = 0;
    210214
     215  if ((N = get_argument (argc, argv, "-delete-min-detID")))  { remove_argument (N, &argc, argv); DELETE_MIN_DET_ID = atoi(argv[N]); remove_argument (N, &argc, argv); }
     216  if ((N = get_argument (argc, argv, "-delete-max-detID")))  { remove_argument (N, &argc, argv); DELETE_MAX_DET_ID = atoi(argv[N]); remove_argument (N, &argc, argv); }
     217  if ((N = get_argument (argc, argv, "-delete-min-catID")))  { remove_argument (N, &argc, argv); DELETE_MIN_CAT_ID = atoi(argv[N]); remove_argument (N, &argc, argv); }
     218  if ((N = get_argument (argc, argv, "-delete-max-catID")))  { remove_argument (N, &argc, argv); DELETE_MAX_CAT_ID = atoi(argv[N]); remove_argument (N, &argc, argv); }
    211219  if ((N = get_argument (argc, argv, "-delete-min-imageID")))  { remove_argument (N, &argc, argv); DELETE_MIN_IMAGE_ID = atoi(argv[N]); remove_argument (N, &argc, argv); }
    212220  if ((N = get_argument (argc, argv, "-delete-max-imageID")))  { remove_argument (N, &argc, argv); DELETE_MAX_IMAGE_ID = atoi(argv[N]); remove_argument (N, &argc, argv); }
     
    221229    remove_argument (N, &argc, argv);
    222230  }
     231
     232  BACKUP_EXTNAME = NULL;
     233  if ((N = get_argument (argc, argv, "-backup-extname"))) {
     234    remove_argument (N, &argc, argv);
     235    BACKUP_EXTNAME = strcreate (argv[N]);
     236    remove_argument (N, &argc, argv);
     237  }
     238  if (!BACKUP_EXTNAME) BACKUP_EXTNAME = strcreate (".bck");
     239
    223240  SAVE_DELETES = FALSE;
    224241  if ((N = get_argument (argc, argv, "-save-deletes"))) {
     
    471488    remove_argument (N, &argc, argv);
    472489  }
     490
    473491  if ((N = get_argument (argc, argv, "-delete-measures-by-match"))) {
    474492    if (MODE != MODE_NONE) usage();
     
    477495    SKIP_IMAGES = TRUE; // we do not need to load the images for -dup-measures
    478496  }
     497
     498  DELETE_MIN_DET_ID = 0;
     499  DELETE_MAX_DET_ID = 0;
     500  DELETE_MIN_CAT_ID = 0;
     501  DELETE_MAX_CAT_ID = 0;
    479502  DELETE_MIN_IMAGE_ID = 0;
    480503  DELETE_MAX_IMAGE_ID = 0;
     
    484507  DELETE_MAX_TIME = 0;
    485508
     509  if ((N = get_argument (argc, argv, "-delete-min-detID")))  { remove_argument (N, &argc, argv); DELETE_MIN_DET_ID = atoi(argv[N]); remove_argument (N, &argc, argv); }
     510  if ((N = get_argument (argc, argv, "-delete-max-detID")))  { remove_argument (N, &argc, argv); DELETE_MAX_DET_ID = atoi(argv[N]); remove_argument (N, &argc, argv); }
     511  if ((N = get_argument (argc, argv, "-delete-min-catID")))  { remove_argument (N, &argc, argv); DELETE_MIN_CAT_ID = atoi(argv[N]); remove_argument (N, &argc, argv); }
     512  if ((N = get_argument (argc, argv, "-delete-max-catID")))  { remove_argument (N, &argc, argv); DELETE_MAX_CAT_ID = atoi(argv[N]); remove_argument (N, &argc, argv); }
    486513  if ((N = get_argument (argc, argv, "-delete-min-imageID")))  { remove_argument (N, &argc, argv); DELETE_MIN_IMAGE_ID = atoi(argv[N]); remove_argument (N, &argc, argv); }
    487514  if ((N = get_argument (argc, argv, "-delete-max-imageID")))  { remove_argument (N, &argc, argv); DELETE_MAX_IMAGE_ID = atoi(argv[N]); remove_argument (N, &argc, argv); }
     
    496523    remove_argument (N, &argc, argv);
    497524  }
     525  BACKUP_EXTNAME = NULL;
     526  if ((N = get_argument (argc, argv, "-backup-extname"))) {
     527    remove_argument (N, &argc, argv);
     528    BACKUP_EXTNAME = strcreate (argv[N]);
     529    remove_argument (N, &argc, argv);
     530  }
     531  if (!BACKUP_EXTNAME) BACKUP_EXTNAME = strcreate (".bck");
    498532
    499533  if ((N = get_argument (argc, argv, "-fix-LAP"))) {
  • trunk/Ohana/src/delstar/src/delete_duplicate_measures.c

    r39692 r39926  
    111111
    112112    // save backup of original cpm file
    113     if (!dvo_catalog_subset_backup (&catalog, ".dlx")) {
     113    if (!dvo_catalog_subset_backup (&catalog, ".dlz")) {
    114114      fprintf (stderr, "ERROR: failed to make backup cpt table for catalog %s\n", catalog.filename);
    115115      exit (1);
    116116    }
    117     if (!dvo_catalog_subset_backup (catalog.measure_catalog, ".d1x")) {
     117    if (!dvo_catalog_subset_backup (catalog.measure_catalog, ".d1z")) {
    118118      fprintf (stderr, "ERROR: failed to make backup cpm table for catalog %s\n", catalog.filename);
    119119      exit (1);
    120120    }
    121     if (!dvo_catalog_subset_backup (catalog.secfilt_catalog, ".dlx")) {
     121    if (!dvo_catalog_subset_backup (catalog.secfilt_catalog, ".dlz")) {
    122122      fprintf (stderr, "ERROR: failed to make backup cps table for catalog %s\n", catalog.filename);
    123123      exit (1);
     
    377377  if (SAVE_DUPLICATES) {
    378378    char savename[DVO_MAX_PATH];
    379     snprintf (savename, DVO_MAX_PATH, "%s.save.0912", catalog->filename);
     379    snprintf (savename, DVO_MAX_PATH, "%s.save.0914", catalog->filename);
    380380    struct stat filestat;
    381381    int myStatus = stat (savename, &filestat);
  • trunk/Ohana/src/delstar/src/delete_measures_by_match.c

    r39692 r39926  
    1313
    1414  int validOptions = FALSE;
     15  validOptions |= DELETE_MAX_CAT_ID;
     16  validOptions |= DELETE_MIN_CAT_ID;
     17  validOptions |= DELETE_MAX_DET_ID;
     18  validOptions |= DELETE_MIN_DET_ID;
    1519  validOptions |= DELETE_MAX_IMAGE_ID;
    1620  validOptions |= DELETE_MIN_IMAGE_ID;
     
    2630  fprintf (stderr, "deleting measurements matching the following\n");
    2731  fprintf (stderr, "image ID range : %d to %d\n", DELETE_MIN_IMAGE_ID, DELETE_MAX_IMAGE_ID);
     32  fprintf (stderr, "det ID range : %d to %d\n", DELETE_MIN_DET_ID, DELETE_MAX_DET_ID);
     33  fprintf (stderr, "cat ID range : %d to %d\n", DELETE_MIN_CAT_ID, DELETE_MAX_CAT_ID);
    2834  fprintf (stderr, "photcode range : %d to %d\n", DELETE_MIN_PHOTCODE, DELETE_MAX_PHOTCODE);
    2935  fprintf (stderr, "time range (UNIX) : %d to %d\n", DELETE_MIN_TIME, DELETE_MAX_TIME);
     
    133139
    134140    // save backup of original cpm file
    135     if (!dvo_catalog_subset_backup (&catalog, ".dlz")) {
     141    if (!dvo_catalog_subset_backup (&catalog, BACKUP_EXTNAME)) {
    136142      fprintf (stderr, "ERROR: failed to make backup cpt table for catalog %s\n", catalog.filename);
    137143      exit (1);
    138144    }
    139     if (!dvo_catalog_subset_backup (catalog.measure_catalog, ".d1z")) {
     145    if (!dvo_catalog_subset_backup (catalog.measure_catalog, BACKUP_EXTNAME)) {
    140146      fprintf (stderr, "ERROR: failed to make backup cpm table for catalog %s\n", catalog.filename);
    141147      exit (1);
    142148    }
    143     if (!dvo_catalog_subset_backup (catalog.secfilt_catalog, ".dlz")) {
     149    if (!dvo_catalog_subset_backup (catalog.secfilt_catalog, BACKUP_EXTNAME)) {
    144150      fprintf (stderr, "ERROR: failed to make backup cps table for catalog %s\n", catalog.filename);
    145151      exit (1);
     
    214220              UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    215221
     222    if (DELETE_MIN_DET_ID) strextend (&command, "-delete-min-detID %d", DELETE_MIN_DET_ID);
     223    if (DELETE_MAX_DET_ID) strextend (&command, "-delete-max-detID %d", DELETE_MAX_DET_ID);
     224    if (DELETE_MIN_CAT_ID) strextend (&command, "-delete-min-catID %d", DELETE_MIN_CAT_ID);
     225    if (DELETE_MAX_CAT_ID) strextend (&command, "-delete-max-catID %d", DELETE_MAX_CAT_ID);
     226
    216227    if (DELETE_MIN_IMAGE_ID) strextend (&command, "-delete-min-imageID %d", DELETE_MIN_IMAGE_ID);
    217228    if (DELETE_MAX_IMAGE_ID) strextend (&command, "-delete-max-imageID %d", DELETE_MAX_IMAGE_ID);
     
    234245    if (UPDATE)          { strextend (&command, "-update");             }
    235246    if (SAVE_DELETES)    { strextend (&command, "-save-deletes");    }
     247
     248    if (BACKUP_EXTNAME)  { strextend (&command, "-backup-extname %s", BACKUP_EXTNAME);    }
    236249
    237250    fprintf (stderr, "command: %s\n", command);
     
    356369
    357370    // does this measure match our selection criteria?
     371    if (measure[i].detID > DELETE_MAX_DET_ID) continue;
     372    if (measure[i].detID < DELETE_MIN_DET_ID) continue;
     373
     374    if (measure[i].catID > DELETE_MAX_CAT_ID) continue;
     375    if (measure[i].catID < DELETE_MIN_CAT_ID) continue;
     376
    358377    if (measure[i].imageID > DELETE_MAX_IMAGE_ID) continue;
    359378    if (measure[i].imageID < DELETE_MIN_IMAGE_ID) continue;
     
    367386    measureDrop[i] = TRUE;
    368387    off_t N = measure[i].averef;
    369     if (VERBOSE) fprintf (stderr, "0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[i].imageID, measure[i].detID, average[N].R, average[N].D, measure[i].photcode);
     388    if (VERBOSE) fprintf (stderr, "0x%08x 0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[i].imageID, measure[i].detID, measure[i].catID, average[N].R, average[N].D, measure[i].photcode);
    370389    if (fsave) {
    371       fprintf (fsave, "0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[i].imageID, measure[i].detID, average[N].R, average[N].D, measure[i].photcode);
     390      fprintf (fsave, "0x%08x 0x%08x 0x%08x %8.4f %8.4f %5d\n", measure[i].imageID, measure[i].detID, measure[i].catID, average[N].R, average[N].D, measure[i].photcode);
    372391    }
    373392    if (isGPC1chip(measure[i].photcode)) {
  • trunk/Ohana/src/dvomerge/include/dvomerge.h

    r39536 r39926  
    6161int    SKIP_MEASURE;
    6262int    SKIP_LENSING;
     63int    SKIP_LENSOBJ;
    6364int    SKIP_STARPAR;
    6465int    SKIP_GALPHOT;
     
    171172off_t     *build_measure_links    PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
    172173off_t     *init_measure_links     PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure));
    173 int        add_meas_link          PROTO((Average *average, off_t *next, off_t Nmeasure, off_t NMEASURE));
     174int        add_measure_link       PROTO((Average *average, off_t *next, off_t Nmeasure, off_t NMEASURE));
    174175Measure   *sort_measure           PROTO((Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next));
    175176
    176177off_t     *build_lensing_links    PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing));
    177178off_t     *init_lensing_links     PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing));
    178 int        add_lens_link          PROTO((Average *average, off_t *next, off_t Nlensing, off_t NLENSING));
     179int        add_lensing_link       PROTO((Average *average, off_t *next, off_t Nlensing, off_t NLENSING));
    179180Lensing   *sort_lensing           PROTO((Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next));
     181
     182off_t     *build_lensobj_links    PROTO((Average *average, off_t Naverage, Lensobj *lensobj, off_t Nlensobj));
     183off_t     *init_lensobj_links     PROTO((Average *average, off_t Naverage, Lensobj *lensobj, off_t Nlensobj));
     184int        add_lensobj_link       PROTO((Average *average, off_t *next, off_t Nlensobj, off_t NLENSOBJ));
     185Lensobj   *sort_lensobj           PROTO((Average *average, off_t Naverage, Lensobj *lensobj, off_t Nlensobj, off_t *next));
    180186
    181187off_t     *build_starpar_links    PROTO((Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar));
    182188off_t     *init_starpar_links     PROTO((Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar));
    183 int        add_star_link          PROTO((Average *average, off_t *next, off_t Nstarpar, off_t NSTARPAR));
     189int        add_starpar_link               PROTO((Average *average, off_t *next, off_t Nstarpar, off_t NSTARPAR));
    184190StarPar   *sort_starpar           PROTO((Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar, off_t *next));
    185191
    186192off_t     *build_galphot_links    PROTO((Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot));
    187193off_t     *init_galphot_links     PROTO((Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot));
    188 int        add_galp_link          PROTO((Average *average, off_t *next, off_t Ngalphot, off_t NGALPHOT));
     194int        add_galphot_link               PROTO((Average *average, off_t *next, off_t Ngalphot, off_t NGALPHOT));
    189195GalPhot   *sort_galphot           PROTO((Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot, off_t *next));
    190196
    191197off_t     *init_missing_links     PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing));
    192 int        add_miss_link          PROTO((Average *average, off_t *next, off_t Nmissing));
     198int        add_missing_link               PROTO((Average *average, off_t *next, off_t Nmissing));
    193199Missing   *sort_missing           PROTO((Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_miss));
    194200
  • trunk/Ohana/src/dvomerge/src/LoadCatalog.c

    r39536 r39926  
    99
    1010  // always load all of the data (if any exists)
    11   // XXXX TEMP HACK : skip GALPHOT
    1211
    13   catalog[0].catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT | DVO_LOAD_LENSOBJ;
     12  catalog[0].catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
    1413
    1514  if (SKIP_MEASURE) {
     
    2322  } else {
    2423    catalog[0].catflags = catalog[0].catflags | DVO_LOAD_LENSING;
     24  }
     25
     26  if (SKIP_LENSOBJ)  {
     27    catalog[0].catflags = catalog[0].catflags | DVO_SKIP_LENSOBJ;
     28  } else {
     29    catalog[0].catflags = catalog[0].catflags | DVO_LOAD_LENSOBJ;
    2530  }
    2631
  • trunk/Ohana/src/dvomerge/src/args.c

    r39536 r39926  
    5656  if ((N = get_argument (*argc, argv, "-skip-lensing"))) {
    5757    SKIP_LENSING = TRUE;
     58    remove_argument (N, argc, argv);
     59  }
     60  SKIP_LENSOBJ = FALSE;
     61  if ((N = get_argument (*argc, argv, "-skip-lensobj"))) {
     62    SKIP_LENSOBJ = TRUE;
    5863    remove_argument (N, argc, argv);
    5964  }
     
    340345    remove_argument (N, argc, argv);
    341346  }
     347  SKIP_LENSOBJ = FALSE;
     348  if ((N = get_argument (*argc, argv, "-skip-lensobj"))) {
     349    SKIP_LENSOBJ = TRUE;
     350    remove_argument (N, argc, argv);
     351  }
    342352  SKIP_STARPAR = FALSE;
    343353  if ((N = get_argument (*argc, argv, "-skip-starpar"))) {
  • trunk/Ohana/src/dvomerge/src/build_links.c

    r39536 r39926  
    1515data: they refer to the sequence number in the data blocks.
    1616
    17 next_meas is a list of the equivalent sequence of the measure block as if it were sorted.
     17next_measure is a list of the equivalent sequence of the measure block as if it were sorted.
    1818
    1919to find the sequence of measurements for a given average:
    2020n_0 = average->measureOffset
    21 n_1 = next_meas[n_0]
    22 n_i = next_meas[n_i-1]
     21n_1 = next_measure[n_0]
     22n_i = next_measure[n_i-1]
    2323
    2424*/
     
    3131
    3232  off_t i, j, N;
    33   off_t *next_meas;
     33  off_t *next_measure;
    3434
    3535  if (!measure) return NULL;
     
    3838  N = 0;
    3939
    40   ALLOCATE (next_meas, off_t, Nmeasure);
     40  ALLOCATE (next_measure, off_t, Nmeasure);
    4141  for (i = 0; i < Naverage; i++) {
    4242    if (!average[i].Nmeasure) continue;
     
    4545    for (j = 0; j < average[i].Nmeasure - 1; j++, N++) {
    4646      myAssert (measure[m+j+1].averef == i, "not sorted");
    47       next_meas[N] = N + 1;
     47      next_measure[N] = N + 1;
    4848      if (N >= Nmeasure) {
    4949        fprintf (stderr, "WARNING: N out of bounds (1)\n");
    5050      }
    5151    }
    52     next_meas[N] = -1;
     52    next_measure[N] = -1;
    5353    if (N >= Nmeasure) {
    5454      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     
    6161    N++;
    6262  }
    63   return (next_meas);
     63  return (next_measure);
    6464}
    6565
     
    7474
    7575  off_t i, m, k, Nm, averef;
    76   off_t *next_meas;
    77 
    78   ALLOCATE (next_meas, off_t, Nmeasure);
     76  off_t *next_measure;
     77
     78  ALLOCATE (next_measure, off_t, Nmeasure);
    7979
    8080  /* reset the Nm, offset values for average */
     
    8787    averef = measure[Nm].averef;
    8888    m = average[averef].measureOffset; 
    89     next_meas[Nm] = -1;
     89    next_measure[Nm] = -1;
    9090
    9191    if (m == -1) { /* no links yet for source */
     
    9595    }
    9696
    97     for (k = 0; next_meas[m] != -1; k++) {
    98       m = next_meas[m];
     97    for (k = 0; next_measure[m] != -1; k++) {
     98      m = next_measure[m];
    9999      if (m >= Nmeasure) {
    100100        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     
    103103
    104104    average[averef].Nmeasure = k + 2;
    105     next_meas[m] = Nm;
     105    next_measure[m] = Nm;
    106106    if (m >= Nmeasure) {
    107107      fprintf (stderr, "WARNING: m out of bounds (2)\n");
    108108    }
    109109  }
    110   return (next_meas);
     110  return (next_measure);
    111111}
    112112
    113113/* average[].measureOffset, average[].Nmeasure are valid within an addstar run */
    114 int add_meas_link (Average *average, off_t *next_meas, off_t Nmeasure, off_t NMEASURE) {
     114int add_measure_link (Average *average, off_t *next_measure, off_t Nmeasure, off_t NMEASURE) {
    115115
    116116  off_t k, m;
    117117
    118   /* if we have trouble, check validity of next_meas[m] : m < Nmeasure */
     118  /* if we have trouble, check validity of next_measure[m] : m < Nmeasure */
    119119  m = average[0].measureOffset; 
    120120
    121121  for (k = 0; k < average[0].Nmeasure - 1; k++)  {
    122     m = next_meas[m];
     122    m = next_measure[m];
    123123    if (m >= NMEASURE) {
    124124      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     
    127127
    128128  /* set up references */
    129   next_meas[Nmeasure] = -1;
     129  next_measure[Nmeasure] = -1;
    130130  if (Nmeasure >= NMEASURE) {
    131131    fprintf (stderr, "WARNING: Nmeasure out of bounds (1)\n");
     
    136136    average[0].measureOffset = Nmeasure;
    137137  } else {
    138     next_meas[m] = Nmeasure;
     138    next_measure[m] = Nmeasure;
    139139    if (m >= NMEASURE) {
    140140      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     
    145145}
    146146
    147 Measure *sort_measure (Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next_meas) {
     147Measure *sort_measure (Average *average, off_t Naverage, Measure *measure, off_t Nmeasure, off_t *next_measure) {
    148148
    149149  off_t i, k, n, np, N;
     
    169169      tmpmeasure[N].averef = i;
    170170      np = n;
    171       n = next_meas[n];
     171      n = next_measure[n];
    172172    }
    173173  }
     
    183183
    184184  off_t i, j, N;
    185   off_t *next_miss;
     185  off_t *next_missing;
    186186
    187187  N = 0;
    188188
    189   ALLOCATE (next_miss, off_t, Nmissing);
     189  ALLOCATE (next_missing, off_t, Nmissing);
    190190  for (i = 0; i < Naverage; i++) {
    191191    for (j = 0; j < average[i].Nmissing - 1; j++, N++) {
    192       next_miss[N] = N + 1;
     192      next_missing[N] = N + 1;
    193193    }
    194194    if (average[i].Nmissing > 0) {
    195       next_miss[N] = -1;
     195      next_missing[N] = -1;
    196196      if (N >= Nmissing) {
    197197        fprintf (stderr, "overflow in init_missing_links");
     
    202202
    203203  }
    204   return (next_miss);
    205 }
    206 
    207 int add_miss_link (Average *average, off_t *next_miss, off_t Nmissing) {
     204  return (next_missing);
     205}
     206
     207int add_missing_link (Average *average, off_t *next_missing, off_t Nmissing) {
    208208
    209209  off_t k, m;
     
    212212  if (average[0].Nmissing < 1) {
    213213    average[0].missingOffset = Nmissing;
    214     next_miss[Nmissing] = -1;
     214    next_missing[Nmissing] = -1;
    215215    return (TRUE);
    216216  }
    217217
    218218  m = average[0].missingOffset; 
    219   for (k = 0; k < average[0].Nmissing - 1; k++) m = next_miss[m];
     219  for (k = 0; k < average[0].Nmissing - 1; k++) m = next_missing[m];
    220220  /* set up references */
    221   next_miss[Nmissing] = -1;
    222   next_miss[m] = Nmissing;
     221  next_missing[Nmissing] = -1;
     222  next_missing[m] = Nmissing;
    223223  return (TRUE);
    224224}
     
    227227   we must always save the missing table, if it exists */
    228228
    229 Missing *sort_missing (Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_miss) {
     229Missing *sort_missing (Average *average, off_t Naverage, Missing *missing, off_t Nmissing, off_t *next_missing) {
    230230
    231231  off_t i, k, n, N;
     
    240240    for (k = 0; k < average[i].Nmissing; k++, N++) {
    241241      tmpmissing[N] = missing[n];
    242       n = next_miss[n];
     242      n = next_missing[n];
    243243    }
    244244  }
     
    254254
    255255  off_t i, j, N;
    256   off_t *next_lens;
     256  off_t *next_lensing;
    257257
    258258  if (!lensing) return NULL;
     
    261261  N = 0;
    262262
    263   ALLOCATE (next_lens, off_t, Nlensing);
     263  ALLOCATE (next_lensing, off_t, Nlensing);
    264264  for (i = 0; i < Naverage; i++) {
    265265    if (!average[i].Nlensing) continue;
     
    268268    for (j = 0; j < average[i].Nlensing - 1; j++, N++) {
    269269      myAssert (lensing[m+j+1].averef == i, "not sorted");
    270       next_lens[N] = N + 1;
     270      next_lensing[N] = N + 1;
    271271      if (N >= Nlensing) {
    272272        fprintf (stderr, "WARNING: N out of bounds (1)\n");
    273273      }
    274274    }
    275     next_lens[N] = -1;
     275    next_lensing[N] = -1;
    276276    if (N >= Nlensing) {
    277277      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     
    284284    N++;
    285285  }
    286   return (next_lens);
     286  return (next_lensing);
    287287}
    288288
     
    297297
    298298  off_t i, m, k, Nm, averef;
    299   off_t *next_lens;
    300 
    301   ALLOCATE (next_lens, off_t, Nlensing);
     299  off_t *next_lensing;
     300
     301  ALLOCATE (next_lensing, off_t, Nlensing);
    302302
    303303  /* reset the Nm, offset values for average */
     
    310310    averef = lensing[Nm].averef;
    311311    m = average[averef].lensingOffset; 
    312     next_lens[Nm] = -1;
     312    next_lensing[Nm] = -1;
    313313
    314314    if (m == -1) { /* no links yet for source */
     
    318318    }
    319319
    320     for (k = 0; next_lens[m] != -1; k++) {
    321       m = next_lens[m];
     320    for (k = 0; next_lensing[m] != -1; k++) {
     321      m = next_lensing[m];
    322322      if (m >= Nlensing) {
    323323        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     
    326326
    327327    average[averef].Nlensing = k + 2;
    328     next_lens[m] = Nm;
     328    next_lensing[m] = Nm;
    329329    if (m >= Nlensing) {
    330330      fprintf (stderr, "WARNING: m out of bounds (2)\n");
    331331    }
    332332  }
    333   return (next_lens);
     333  return (next_lensing);
    334334}
    335335
    336336/* average[].lensingOffset, average[].Nlensing are valid within an addstar run */
    337 int add_lens_link (Average *average, off_t *next_lens, off_t Nlensing, off_t NLENSING) {
     337int add_lensing_link (Average *average, off_t *next_lensing, off_t Nlensing, off_t NLENSING) {
    338338
    339339  off_t k, m;
    340340
    341   /* if we have trouble, check validity of next_lens[m] : m < Nlensing */
     341  /* if we have trouble, check validity of next_lensing[m] : m < Nlensing */
    342342  m = average[0].lensingOffset; 
    343343
    344344  for (k = 0; k < average[0].Nlensing - 1; k++)  {
    345     m = next_lens[m];
     345    m = next_lensing[m];
    346346    if (m >= NLENSING) {
    347347      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     
    350350
    351351  /* set up references */
    352   next_lens[Nlensing] = -1;
     352  next_lensing[Nlensing] = -1;
    353353  if (Nlensing >= NLENSING) {
    354354    fprintf (stderr, "WARNING: Nlensing out of bounds (1)\n");
     
    359359    average[0].lensingOffset = Nlensing;
    360360  } else {
    361     next_lens[m] = Nlensing;
     361    next_lensing[m] = Nlensing;
    362362    if (m >= NLENSING) {
    363363      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     
    368368}
    369369
    370 Lensing *sort_lensing (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next_lens) {
     370Lensing *sort_lensing (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next_lensing) {
    371371
    372372  off_t i, k, n, np, N;
     
    392392      tmplensing[N].averef = i;
    393393      np = n;
    394       n = next_lens[n];
     394      n = next_lensing[n];
    395395    }
    396396  }
    397397  free (lensing);
    398398  return (tmplensing);
     399}
     400
     401/*** Lensobj ****************************************************************************************/
     402
     403/* build the initial links assuming the table is sorted,
     404   not partial, and has a correct set of average[].lensobjOffset,Nlensobj values */
     405off_t *init_lensobj_links (Average *average, off_t Naverage, Lensobj *lensobj, off_t Nlensobj) {
     406
     407  off_t i, j, N;
     408  off_t *next_lensobj;
     409
     410  if (!lensobj) return NULL;
     411  if (SKIP_LENSOBJ) return NULL;
     412
     413  N = 0;
     414
     415  ALLOCATE (next_lensobj, off_t, Nlensobj);
     416  for (i = 0; i < Naverage; i++) {
     417    if (!average[i].Nlensobj) continue;
     418    // off_t m = average[i].lensobjOffset;
     419    // myAssert (lensobj[m].averef == i, "not sorted");
     420    for (j = 0; j < average[i].Nlensobj - 1; j++, N++) {
     421      // myAssert (lensobj[m+j+1].averef == i, "not sorted");
     422      next_lensobj[N] = N + 1;
     423      if (N >= Nlensobj) {
     424        fprintf (stderr, "WARNING: N out of bounds (1)\n");
     425      }
     426    }
     427    next_lensobj[N] = -1;
     428    if (N >= Nlensobj) {
     429      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     430    }
     431
     432    if (N >= Nlensobj) {
     433      fprintf (stderr, "overflow in init_lensobj_links\n");
     434      abort ();
     435    }
     436    N++;
     437  }
     438  return (next_lensobj);
     439}
     440
     441/* construct lensobj links which are valid FOR THIS LOAD
     442 * - if we have a full load, we will get links which can
     443 *   be used by other programs (eg, relphot, etc)
     444 * - if we have a partial load, the links are only valid
     445 *   for that partial load
     446 */
     447
     448off_t *build_lensobj_links (Average *average, off_t Naverage, Lensobj *lensobj, off_t Nlensobj) {
     449
     450  fprintf (stderr, "input is not sorted but contains lensobj -- trouble\n");
     451  exit (2);
     452
     453# if (0)
     454
     455  off_t i, m, k, Nm, averef;
     456  off_t *next_lensobj;
     457
     458  ALLOCATE (next_lensobj, off_t, Nlensobj);
     459
     460  /* reset the Nm, offset values for average */
     461  for (i = 0; i < Naverage; i++) {
     462    average[i].lensobjOffset = -1;
     463    average[i].Nlensobj     =  0;
     464  }
     465
     466  for (Nm = 0; Nm < Nlensobj; Nm++) {
     467    averef = lensobj[Nm].averef;
     468    m = average[averef].lensobjOffset; 
     469    next_lensobj[Nm] = -1;
     470
     471    if (m == -1) { /* no links yet for source */
     472      average[averef].lensobjOffset = Nm;
     473      average[averef].Nlensobj     = 1;
     474      continue;
     475    }
     476
     477    for (k = 0; next_lensobj[m] != -1; k++) {
     478      m = next_lensobj[m];
     479      if (m >= Nlensobj) {
     480        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     481      }
     482    }
     483
     484    average[averef].Nlensobj = k + 2;
     485    next_lensobj[m] = Nm;
     486    if (m >= Nlensobj) {
     487      fprintf (stderr, "WARNING: m out of bounds (2)\n");
     488    }
     489  }
     490  return (next_lensobj);
     491# endif
     492}
     493
     494/* average[].lensobjOffset, average[].Nlensobj are valid within an addstar run */
     495int add_lensobj_link (Average *average, off_t *next_lensobj, off_t Nlensobj, off_t NLENSOBJ) {
     496
     497  off_t k, m;
     498
     499  /* if we have trouble, check validity of next_lensobj[m] : m < Nlensobj */
     500  m = average[0].lensobjOffset; 
     501
     502  for (k = 0; k < average[0].Nlensobj - 1; k++)  {
     503    m = next_lensobj[m];
     504    if (m >= NLENSOBJ) {
     505      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     506    }
     507  }
     508
     509  /* set up references */
     510  next_lensobj[Nlensobj] = -1;
     511  if (Nlensobj >= NLENSOBJ) {
     512    fprintf (stderr, "WARNING: Nlensobj out of bounds (1)\n");
     513  }
     514
     515  // if Nlensobj is 0, m may have been mis-set; add to the end
     516  if ((average[0].Nlensobj == 0) || (m == -1)) {
     517    average[0].lensobjOffset = Nlensobj;
     518  } else {
     519    next_lensobj[m] = Nlensobj;
     520    if (m >= NLENSOBJ) {
     521      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     522    }
     523  }
     524
     525  return (TRUE);
     526}
     527
     528Lensobj *sort_lensobj (Average *average, off_t Naverage, Lensobj *lensobj, off_t Nlensobj, off_t *next_lensobj) {
     529
     530  off_t i, k, n, np, N;
     531  Lensobj *tmplensobj;
     532
     533  /* fix order of Lensobj (memory intensive, but fast) */
     534  np = -1;
     535  N = 0;
     536  ALLOCATE (tmplensobj, Lensobj, Nlensobj);
     537  for (i = 0; i < Naverage; i++) {
     538    if (!average[i].Nlensobj) continue;
     539    n = average[i].lensobjOffset;
     540    average[i].lensobjOffset = N;
     541    int myObjID = average[i].objID;
     542    for (k = 0; k < average[i].Nlensobj; k++, N++) {
     543      if (n == -1) {
     544        fprintf (stderr, "entry after %d has a problem\n", (int) np);
     545        abort();
     546      }
     547      tmplensobj[N] = lensobj[n];
     548      // myAssert (lensobj[n].averef == i, "error in averef");
     549      myAssert ((lensobj[n].objID == myObjID) || (lensobj[n].objID == -1), "error in objID?");
     550      // tmplensobj[N].averef = i;
     551      np = n;
     552      n = next_lensobj[n];
     553    }
     554  }
     555  free (lensobj);
     556  return (tmplensobj);
    399557}
    400558
     
    406564
    407565  off_t i, j, N;
    408   off_t *next_star;
     566  off_t *next_starpar;
    409567
    410568  if (!starpar) return NULL;
     
    415573  // NOTE that is we choose DVO_SKIP_STARPAR, catalog.starpar is NULL.
    416574  // this code will let merge_catalogs_old.c do nothing for starpar
    417   ALLOCATE (next_star, off_t, Nstarpar);
    418   if (!starpar) return next_star;
     575  ALLOCATE (next_starpar, off_t, Nstarpar);
     576  if (!starpar) return next_starpar;
    419577
    420578  for (i = 0; i < Naverage; i++) {
     
    424582    for (j = 0; j < average[i].Nstarpar - 1; j++, N++) {
    425583      myAssert (starpar[m+j+1].averef == i, "not sorted");
    426       next_star[N] = N + 1;
     584      next_starpar[N] = N + 1;
    427585      if (N >= Nstarpar) {
    428586        fprintf (stderr, "WARNING: N out of bounds (1)\n");
    429587      }
    430588    }
    431     next_star[N] = -1;
     589    next_starpar[N] = -1;
    432590    if (N >= Nstarpar) {
    433591      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     
    440598    N++;
    441599  }
    442   return (next_star);
     600  return (next_starpar);
    443601}
    444602
     
    453611
    454612  off_t i, m, k, Nm, averef;
    455   off_t *next_star;
    456 
    457   ALLOCATE (next_star, off_t, Nstarpar);
    458   if (!starpar) return next_star;
     613  off_t *next_starpar;
     614
     615  ALLOCATE (next_starpar, off_t, Nstarpar);
     616  if (!starpar) return next_starpar;
    459617
    460618  /* reset the Nm, offset values for average */
     
    467625    averef = starpar[Nm].averef;
    468626    m = average[averef].starparOffset; 
    469     next_star[Nm] = -1;
     627    next_starpar[Nm] = -1;
    470628
    471629    if (m == -1) { /* no links yet for source */
     
    475633    }
    476634
    477     for (k = 0; next_star[m] != -1; k++) {
    478       m = next_star[m];
     635    for (k = 0; next_starpar[m] != -1; k++) {
     636      m = next_starpar[m];
    479637      if (m >= Nstarpar) {
    480638        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     
    483641
    484642    average[averef].Nstarpar = k + 2;
    485     next_star[m] = Nm;
     643    next_starpar[m] = Nm;
    486644    if (m >= Nstarpar) {
    487645      fprintf (stderr, "WARNING: m out of bounds (2)\n");
    488646    }
    489647  }
    490   return (next_star);
     648  return (next_starpar);
    491649}
    492650
    493651/* average[].starparOffset, average[].Nstarpar are valid within an addstar run */
    494 int add_star_link (Average *average, off_t *next_star, off_t Nstarpar, off_t NSTARPAR) {
     652int add_starpar_link (Average *average, off_t *next_starpar, off_t Nstarpar, off_t NSTARPAR) {
    495653
    496654  off_t k, m;
    497655
    498   /* if we have trouble, check validity of next_star[m] : m < Nstarpar */
     656  /* if we have trouble, check validity of next_starpar[m] : m < Nstarpar */
    499657  m = average[0].starparOffset; 
    500658
    501659  for (k = 0; k < average[0].Nstarpar - 1; k++)  {
    502     m = next_star[m];
     660    m = next_starpar[m];
    503661    if (m >= NSTARPAR) {
    504662      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     
    507665
    508666  /* set up references */
    509   next_star[Nstarpar] = -1;
     667  next_starpar[Nstarpar] = -1;
    510668  if (Nstarpar >= NSTARPAR) {
    511669    fprintf (stderr, "WARNING: Nstarpar out of bounds (1)\n");
     
    516674    average[0].starparOffset = Nstarpar;
    517675  } else {
    518     next_star[m] = Nstarpar;
     676    next_starpar[m] = Nstarpar;
    519677    if (m >= NSTARPAR) {
    520678      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     
    525683}
    526684
    527 StarPar *sort_starpar (Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar, off_t *next_star) {
     685StarPar *sort_starpar (Average *average, off_t Naverage, StarPar *starpar, off_t Nstarpar, off_t *next_starpar) {
    528686
    529687  off_t i, k, n, np, N;
     
    552710      tmpstarpar[N].averef = i;
    553711      np = n;
    554       n = next_star[n];
     712      n = next_starpar[n];
    555713    }
    556714  }
     
    566724
    567725  off_t i, j, N;
    568   off_t *next_galp;
     726  off_t *next_galphot;
    569727
    570728  if (galphot) return NULL;
     
    573731  N = 0;
    574732
    575   ALLOCATE (next_galp, off_t, Ngalphot);
     733  ALLOCATE (next_galphot, off_t, Ngalphot);
    576734  for (i = 0; i < Naverage; i++) {
    577735    if (!average[i].Ngalphot) continue;
     
    580738    for (j = 0; j < average[i].Ngalphot - 1; j++, N++) {
    581739      myAssert (galphot[m+j+1].averef == i, "not sorted");
    582       next_galp[N] = N + 1;
     740      next_galphot[N] = N + 1;
    583741      if (N >= Ngalphot) {
    584742        fprintf (stderr, "WARNING: N out of bounds (1)\n");
    585743      }
    586744    }
    587     next_galp[N] = -1;
     745    next_galphot[N] = -1;
    588746    if (N >= Ngalphot) {
    589747      fprintf (stderr, "WARNING: N out of bounds (2)\n");
     
    596754    N++;
    597755  }
    598   return (next_galp);
     756  return (next_galphot);
    599757}
    600758
     
    609767
    610768  off_t i, m, k, Nm, averef;
    611   off_t *next_galp;
    612 
    613   ALLOCATE (next_galp, off_t, Ngalphot);
     769  off_t *next_galphot;
     770
     771  ALLOCATE (next_galphot, off_t, Ngalphot);
    614772
    615773  /* reset the Nm, offset values for average */
     
    622780    averef = galphot[Nm].averef;
    623781    m = average[averef].galphotOffset; 
    624     next_galp[Nm] = -1;
     782    next_galphot[Nm] = -1;
    625783
    626784    if (m == -1) { /* no links yet for source */
     
    630788    }
    631789
    632     for (k = 0; next_galp[m] != -1; k++) {
    633       m = next_galp[m];
     790    for (k = 0; next_galphot[m] != -1; k++) {
     791      m = next_galphot[m];
    634792      if (m >= Ngalphot) {
    635793        fprintf (stderr, "WARNING: m out of bounds (1)\n");
     
    638796
    639797    average[averef].Ngalphot = k + 2;
    640     next_galp[m] = Nm;
     798    next_galphot[m] = Nm;
    641799    if (m >= Ngalphot) {
    642800      fprintf (stderr, "WARNING: m out of bounds (2)\n");
    643801    }
    644802  }
    645   return (next_galp);
     803  return (next_galphot);
    646804}
    647805
    648806/* average[].galphotOffset, average[].Ngalphot are valid within an addstar run */
    649 int add_galp_link (Average *average, off_t *next_galp, off_t Ngalphot, off_t NGALPHOT) {
     807int add_galphot_link (Average *average, off_t *next_galphot, off_t Ngalphot, off_t NGALPHOT) {
    650808
    651809  off_t k, m;
    652810
    653   /* if we have trouble, check validity of next_galp[m] : m < Ngalphot */
     811  /* if we have trouble, check validity of next_galphot[m] : m < Ngalphot */
    654812  m = average[0].galphotOffset; 
    655813
    656814  for (k = 0; k < average[0].Ngalphot - 1; k++)  {
    657     m = next_galp[m];
     815    m = next_galphot[m];
    658816    if (m >= NGALPHOT) {
    659817      fprintf (stderr, "WARNING: m out of bounds (3)\n");
     
    662820
    663821  /* set up references */
    664   next_galp[Ngalphot] = -1;
     822  next_galphot[Ngalphot] = -1;
    665823  if (Ngalphot >= NGALPHOT) {
    666824    fprintf (stderr, "WARNING: Ngalphot out of bounds (1)\n");
     
    671829    average[0].galphotOffset = Ngalphot;
    672830  } else {
    673     next_galp[m] = Ngalphot;
     831    next_galphot[m] = Ngalphot;
    674832    if (m >= NGALPHOT) {
    675833      fprintf (stderr, "WARNING: m out of bounds (4)\n");
     
    680838}
    681839
    682 GalPhot *sort_galphot (Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot, off_t *next_galp) {
     840GalPhot *sort_galphot (Average *average, off_t Naverage, GalPhot *galphot, off_t Ngalphot, off_t *next_galphot) {
    683841
    684842  off_t i, k, n, np, N;
     
    704862      tmpgalphot[N].averef = i;
    705863      np = n;
    706       n = next_galp[n];
     864      n = next_galphot[n];
    707865    }
    708866  }
  • trunk/Ohana/src/dvomerge/src/dvomergeUpdate_catalogs.c

    r39536 r39926  
    336336    if (SKIP_MEASURE)               { strextend (&command, "-skip-measure"); }
    337337    if (SKIP_LENSING)               { strextend (&command, "-skip-lensing"); }
     338    if (SKIP_LENSOBJ)               { strextend (&command, "-skip-lensobj"); }
    338339    if (SKIP_GALPHOT)               { strextend (&command, "-skip-galphot"); }
    339340    if (SKIP_STARPAR)               { strextend (&command, "-skip-starpar"); }
  • trunk/Ohana/src/dvomerge/src/merge_catalogs_old.c

    r39342 r39926  
    1414  double *X1, *Y1, *X2, *Y2;
    1515  double dX, dY, dR;
    16   off_t *N1, *N2, *next_meas, *next_lens, *next_star, *next_galp;
    17   off_t Nave, NAVE, Nmeas, NMEAS, Nmatch, Nlens, NLENS, Nstar, NSTAR, Ngalp, NGALP;
     16  off_t *N1, *N2, *next_measure, *next_lensing, *next_lensobj, *next_starpar, *next_galphot;
     17  off_t Nave, NAVE, Nmeasure, NMEASURE, Nmatch, Nlensing, NLENSING, Nlensobj, NLENSOBJ, Nstarpar, NSTARPAR, Ngalphot, NGALPHOT;
    1818  int NsecfiltIn;
    1919  int NsecfiltOut;
     
    5151  /* internal counters */
    5252  Nmatch = 0;
    53   NMEAS = Nmeas = output[0].Nmeasure;
    54   NLENS = Nlens = output[0].Nlensing;
    55   NSTAR = Nstar = output[0].Nstarpar;
    56   NGALP = Ngalp = output[0].Ngalphot;
     53  NMEASURE = Nmeasure = output[0].Nmeasure;
     54  NLENSING = Nlensing = output[0].Nlensing;
     55  NLENSOBJ = Nlensobj = output[0].Nlensobj;
     56  NSTARPAR = Nstarpar = output[0].Nstarpar;
     57  NGALPHOT = Ngalphot = output[0].Ngalphot;
    5758
    5859  // current max obj ID for this catalog
     
    116117    // this version is only valid if we have done a full catalog load, and if the catalog
    117118    // is sorted while processed
    118     next_meas = init_measure_links (output[0].average, Nave, output[0].measure, Nmeas);
    119     next_lens = init_lensing_links (output[0].average, Nave, output[0].lensing, Nlens);
    120     next_star = init_starpar_links (output[0].average, Nave, output[0].starpar, Nstar);
    121     next_galp = init_galphot_links (output[0].average, Nave, output[0].galphot, Ngalp);
     119    next_measure = init_measure_links (output[0].average, Nave, output[0].measure, Nmeasure);
     120    next_lensing = init_lensing_links (output[0].average, Nave, output[0].lensing, Nlensing);
     121    next_lensobj = init_lensobj_links (output[0].average, Nave, output[0].lensobj, Nlensobj);
     122    next_starpar = init_starpar_links (output[0].average, Nave, output[0].starpar, Nstarpar);
     123    next_galphot = init_galphot_links (output[0].average, Nave, output[0].galphot, Ngalphot);
    122124  } else {
    123     next_meas = build_measure_links (output[0].average, Nave, output[0].measure, Nmeas);
    124     next_lens = build_lensing_links (output[0].average, Nave, output[0].lensing, Nlens);
    125     next_star = build_starpar_links (output[0].average, Nave, output[0].starpar, Nstar);
    126     next_galp = build_galphot_links (output[0].average, Nave, output[0].galphot, Ngalp);
     125    next_measure = build_measure_links (output[0].average, Nave, output[0].measure, Nmeasure);
     126    next_lensing = build_lensing_links (output[0].average, Nave, output[0].lensing, Nlensing);
     127    next_lensobj = build_lensobj_links (output[0].average, Nave, output[0].lensobj, Nlensobj);
     128    next_starpar = build_starpar_links (output[0].average, Nave, output[0].starpar, Nstarpar);
     129    next_galphot = build_galphot_links (output[0].average, Nave, output[0].galphot, Ngalphot);
    127130  }   
    128131
     
    183186
    184187    /* make sure there is space for next Nmeasure entries */
    185     if (Nmeas + input[0].average[N].Nmeasure >= NMEAS) {
    186       NMEAS = Nmeas + input[0].average[N].Nmeasure + 1000;
    187       REALLOCATE (next_meas, off_t, NMEAS);
    188       REALLOCATE (output[0].measure, Measure, NMEAS);
    189     }
    190     if (Nlens + input[0].average[N].Nlensing >= NLENS) {
    191       NLENS = Nlens + input[0].average[N].Nlensing + 1000;
    192       REALLOCATE (next_lens, off_t, NLENS);
    193       REALLOCATE (output[0].lensing, Lensing, NLENS);
    194     }
    195     if (Nstar + input[0].average[N].Nstarpar >= NSTAR) {
    196       NSTAR = Nstar + input[0].average[N].Nstarpar + 1000;
    197       REALLOCATE (next_star, off_t, NSTAR);
    198       REALLOCATE (output[0].starpar, StarPar, NSTAR);
    199     }
    200     if (Ngalp + input[0].average[N].Ngalphot >= NGALP) {
    201       NGALP = Ngalp + input[0].average[N].Ngalphot + 1000;
    202       REALLOCATE (next_galp, off_t, NGALP);
    203       REALLOCATE (output[0].galphot, GalPhot, NGALP);
     188    if (Nmeasure + input[0].average[N].Nmeasure >= NMEASURE) {
     189      NMEASURE = Nmeasure + input[0].average[N].Nmeasure + 1000;
     190      REALLOCATE (next_measure, off_t, NMEASURE);
     191      REALLOCATE (output[0].measure, Measure, NMEASURE);
     192    }
     193    if (Nlensing + input[0].average[N].Nlensing >= NLENSING) {
     194      NLENSING = Nlensing + input[0].average[N].Nlensing + 1000;
     195      REALLOCATE (next_lensing, off_t, NLENSING);
     196      REALLOCATE (output[0].lensing, Lensing, NLENSING);
     197    }
     198    if (Nlensobj + input[0].average[N].Nlensobj >= NLENSOBJ) {
     199      NLENSOBJ = Nlensobj + input[0].average[N].Nlensobj + 1000;
     200      REALLOCATE (next_lensobj, off_t, NLENSOBJ);
     201      REALLOCATE (output[0].lensobj, Lensobj, NLENSOBJ);
     202    }
     203    if (Nstarpar + input[0].average[N].Nstarpar >= NSTARPAR) {
     204      NSTARPAR = Nstarpar + input[0].average[N].Nstarpar + 1000;
     205      REALLOCATE (next_starpar, off_t, NSTARPAR);
     206      REALLOCATE (output[0].starpar, StarPar, NSTARPAR);
     207    }
     208    if (Ngalphot + input[0].average[N].Ngalphot >= NGALPHOT) {
     209      NGALPHOT = Ngalphot + input[0].average[N].Ngalphot + 1000;
     210      REALLOCATE (next_galphot, off_t, NGALPHOT);
     211      REALLOCATE (output[0].galphot, GalPhot, NGALPHOT);
    204212    }
    205213
     
    212220      if (REPLACE_TYCHO) {
    213221        int Minp =  input[0].average[N].measureOffset;
    214         Nreplace = replace_tycho (&output[0].average[n], output[0].measure, next_meas, &input[0].average[N], &input[0].measure[Minp]);
     222        Nreplace = replace_tycho (&output[0].average[n], output[0].measure, next_measure, &input[0].average[N], &input[0].measure[Minp]);
    215223        if (Nreplace == 6) {
    216           output[0].found_t[n] = Nmeas;
     224          output[0].found_t[n] = Nmeasure;
    217225          i++;
    218226          continue;
     
    227235          // index to first measure for this object
    228236          // XXX this does not support lensing, starpar, or galphot measurements
    229           if (replace_match (&output[0].average[n], output[0].measure, next_meas, &input[0].average[N], &input[0].measure[offset])) {
     237          if (replace_match (&output[0].average[n], output[0].measure, next_measure, &input[0].average[N], &input[0].measure[offset])) {
    230238            continue;
    231239          }
    232240        }
    233241        /* add to end of measurement list */
    234         add_meas_link (&output[0].average[n], next_meas, Nmeas, NMEAS);
     242        add_measure_link (&output[0].average[n], next_measure, Nmeasure, NMEASURE);
    235243       
    236244        // set the new measurements
    237         output[0].measure[Nmeas] = input[0].measure[offset];
     245        output[0].measure[Nmeasure] = input[0].measure[offset];
    238246
    239247        // old code: find R,D using average_in[0], the get offset relative to average_out[0].  no longer
     
    241249        // Rin = input[0].average[N].R - input[0].measure[offset].dR / 3600.0;
    242250        // Din = input[0].average[N].D - input[0].measure[offset].dD / 3600.0;
    243         // output[0].measure[Nmeas].dR = 3600.0*(output[0].average[n].R - Rin);
    244         // output[0].measure[Nmeas].dD = 3600.0*(output[0].average[n].D - Din);
    245 
    246         output[0].measure[Nmeas].dbFlags  = 0;  // XXX why reset these?
    247         output[0].measure[Nmeas].averef   = n;
    248         output[0].measure[Nmeas].objID    = output[0].average[n].objID;
    249         output[0].measure[Nmeas].catID    = output[0].catID;
    250 
    251         assert (output[0].measure[Nmeas].averef < Nave);
    252 
    253         // fprintf (stderr, "Nave : "OFF_T_FMT", Nmeas : "OFF_T_FMT", dR: %f, dD: %f, catID: %d\n",  n,  Nmeas, output[0].measure[Nmeas].dR, output[0].measure[Nmeas].dD, output[0].measure[i].catID);
    254 
    255         float dRoff = dvoOffsetR(&output[0].measure[Nmeas], &output[0].average[n]);
     251        // output[0].measure[Nmeasure].dR = 3600.0*(output[0].average[n].R - Rin);
     252        // output[0].measure[Nmeasure].dD = 3600.0*(output[0].average[n].D - Din);
     253
     254        output[0].measure[Nmeasure].dbFlags  = 0;  // XXX why reset these?
     255        output[0].measure[Nmeasure].averef   = n;
     256        output[0].measure[Nmeasure].objID    = output[0].average[n].objID;
     257        output[0].measure[Nmeasure].catID    = output[0].catID;
     258
     259        assert (output[0].measure[Nmeasure].averef < Nave);
     260
     261        // fprintf (stderr, "Nave : "OFF_T_FMT", Nmeasure : "OFF_T_FMT", dR: %f, dD: %f, catID: %d\n",  n,  Nmeasure, output[0].measure[Nmeasure].dR, output[0].measure[Nmeasure].dD, output[0].measure[i].catID);
     262
     263        float dRoff = dvoOffsetR(&output[0].measure[Nmeasure], &output[0].average[n]);
    256264
    257265        // rationalize R
    258266        if (dRoff > +180.0*3600.0) {
    259267          // average on high end of boundary, move star up
    260           output[0].measure[Nmeas].R += 360.0;
     268          output[0].measure[Nmeasure].R += 360.0;
    261269          dRoff -= 360.0*3600.0;
    262270        }
    263271        if (dRoff < -180.0*3600.0) {
    264272          // average on low end of boundary, move star down
    265           output[0].measure[Nmeas].R -= 360.0;
     273          output[0].measure[Nmeasure].R -= 360.0;
    266274          dRoff += 360.0*3600.0;
    267275        }
     
    272280            fprintf (stderr, "error: %10.6f,%10.6f vs %10.6f,%10.6f (%f,%f vs %f,%f)\n",
    273281                     output[0].average[n].R, output[0].average[n].D,
    274                      output[0].measure[Nmeas].R, output[0].measure[Nmeas].D,
     282                     output[0].measure[Nmeasure].R, output[0].measure[Nmeasure].D,
    275283                     X1[i], X2[Jmin], Y1[i], Y2[Jmin]);
    276284            // XXX abort on this? -- this is a bad failure...
     
    278286        }
    279287        output[0].average[n].Nmeasure ++;
    280         Nmeas ++;
     288        Nmeasure ++;
    281289      }
    282290    }
     
    286294      for (Nin = 0; Nin < input[0].average[N].Nlensing; Nin++) {
    287295        /* add to end of lensing list */
    288         add_lens_link (&output[0].average[n], next_lens, Nlens, NLENS);
     296        add_lensing_link (&output[0].average[n], next_lensing, Nlensing, NLENSING);
    289297       
    290298        // set the new lensing
    291299        off_t lensoff = input[0].average[N].lensingOffset + Nin;
    292         output[0].lensing[Nlens] = input[0].lensing[lensoff];
    293 
    294         output[0].lensing[Nlens].averef   = n;
    295         output[0].lensing[Nlens].objID    = output[0].average[n].objID;
    296         output[0].lensing[Nlens].catID    = output[0].catID;
     300        output[0].lensing[Nlensing] = input[0].lensing[lensoff];
     301
     302        output[0].lensing[Nlensing].averef   = n;
     303        output[0].lensing[Nlensing].objID    = output[0].average[n].objID;
     304        output[0].lensing[Nlensing].catID    = output[0].catID;
    297305        output[0].average[n].Nlensing ++;
    298         Nlens ++;
     306        Nlensing ++;
     307      }
     308    }
     309
     310    // if lensobj measurements exist, add them too
     311    if (output[0].lensobj && !SKIP_LENSOBJ) {
     312      for (Nin = 0; Nin < input[0].average[N].Nlensobj; Nin++) {
     313        /* add to end of lensobj list */
     314        add_lensobj_link (&output[0].average[n], next_lensobj, Nlensobj, NLENSOBJ);
     315       
     316        // set the new lensobj
     317        off_t lensoff = input[0].average[N].lensobjOffset + Nin;
     318        output[0].lensobj[Nlensobj] = input[0].lensobj[lensoff];
     319
     320        // output[0].lensobj[Nlensobj].averef   = n;
     321        output[0].lensobj[Nlensobj].objID    = output[0].average[n].objID;
     322        output[0].lensobj[Nlensobj].catID    = output[0].catID;
     323        output[0].average[n].Nlensobj ++;
     324        Nlensobj ++;
    299325      }
    300326    }
     
    304330      for (Nin = 0; Nin < input[0].average[N].Nstarpar; Nin++) {
    305331        /* add to end of lensing list */
    306         add_star_link (&output[0].average[n], next_star, Nstar, NSTAR);
     332        add_starpar_link (&output[0].average[n], next_starpar, Nstarpar, NSTARPAR);
    307333       
    308334        // set the new starpar
    309335        off_t staroff = input[0].average[N].starparOffset + Nin;
    310         output[0].starpar[Nstar] = input[0].starpar[staroff];
    311 
    312         output[0].starpar[Nstar].averef   = n;
    313         output[0].starpar[Nstar].objID    = output[0].average[n].objID;
    314         output[0].starpar[Nstar].catID    = output[0].catID;
     336        output[0].starpar[Nstarpar] = input[0].starpar[staroff];
     337
     338        output[0].starpar[Nstarpar].averef   = n;
     339        output[0].starpar[Nstarpar].objID    = output[0].average[n].objID;
     340        output[0].starpar[Nstarpar].catID    = output[0].catID;
    315341        output[0].average[n].Nstarpar ++;
    316         Nstar ++;
     342        Nstarpar ++;
    317343      }
    318344    }
     
    322348      for (Nin = 0; Nin < input[0].average[N].Ngalphot; Nin++) {
    323349        /* add to end of galphot list */
    324         add_galp_link (&output[0].average[n], next_galp, Ngalp, NGALP);
     350        add_galphot_link (&output[0].average[n], next_galphot, Ngalphot, NGALPHOT);
    325351       
    326352        // set the new galphot
    327353        off_t galpoff = input[0].average[N].galphotOffset + Nin;
    328         output[0].galphot[Ngalp] = input[0].galphot[galpoff];
    329 
    330         output[0].galphot[Ngalp].averef   = n;
    331         output[0].galphot[Ngalp].objID    = output[0].average[n].objID;
    332         output[0].galphot[Ngalp].catID    = output[0].catID;
     354        output[0].galphot[Ngalphot] = input[0].galphot[galpoff];
     355
     356        output[0].galphot[Ngalphot].averef   = n;
     357        output[0].galphot[Ngalphot].objID    = output[0].average[n].objID;
     358        output[0].galphot[Ngalphot].catID    = output[0].catID;
    333359        output[0].average[n].Ngalphot ++;
    334         Ngalp ++;
     360        Ngalphot ++;
    335361      }
    336362    }
     
    373399    /* Nm is updated, but not written out in -update mode (for existing entries)
    374400       Nm is recalculated in build_meas_links if loaded table is not sorted */
    375     output[0].found_t[n] = Nmeas;
     401    output[0].found_t[n] = Nmeasure;
    376402    i++;
    377403  }
    378   // MARKTIME("find matched stars: %f sec for "OFF_T_FMT","OFF_T_FMT" stars ("OFF_T_FMT" meas)\n", dtime, Nstars, Nave, Nmeas);
     404  // MARKTIME("find matched stars: %f sec for "OFF_T_FMT","OFF_T_FMT" stars ("OFF_T_FMT" meas)\n", dtime, Nstars, Nave, Nmeasure);
    379405
    380406  /** incorporate unmatched image stars, if this star is in field of this catalog **/
     
    384410
    385411    /* make sure there is space for next entry */
    386     if (Nmeas + input[0].average[N].Nmeasure >= NMEAS) {
    387       NMEAS = Nmeas + input[0].average[N].Nmeasure + 1000;
    388       REALLOCATE (next_meas, off_t, NMEAS);
    389       REALLOCATE (output[0].measure, Measure, NMEAS);
    390     }
    391     if (Nlens + input[0].average[N].Nlensing >= NLENS) {
    392       NLENS = Nlens + input[0].average[N].Nlensing + 1000;
    393       REALLOCATE (next_lens, off_t, NLENS);
    394       REALLOCATE (output[0].lensing, Lensing, NLENS);
    395     }
    396     if (Nstar + input[0].average[N].Nstarpar >= NSTAR) {
    397       NSTAR = Nstar + input[0].average[N].Nstarpar + 1000;
    398       REALLOCATE (next_star, off_t, NSTAR);
    399       REALLOCATE (output[0].starpar, StarPar, NSTAR);
    400     }
    401     if (Ngalp + input[0].average[N].Ngalphot >= NGALP) {
    402       NGALP = Ngalp + input[0].average[N].Ngalphot + 1000;
    403       REALLOCATE (next_galp, off_t, NGALP);
    404       REALLOCATE (output[0].galphot, GalPhot, NGALP);
     412    if (Nmeasure + input[0].average[N].Nmeasure >= NMEASURE) {
     413      NMEASURE = Nmeasure + input[0].average[N].Nmeasure + 1000;
     414      REALLOCATE (next_measure, off_t, NMEASURE);
     415      REALLOCATE (output[0].measure, Measure, NMEASURE);
     416    }
     417    if (Nlensing + input[0].average[N].Nlensing >= NLENSING) {
     418      NLENSING = Nlensing + input[0].average[N].Nlensing + 1000;
     419      REALLOCATE (next_lensing, off_t, NLENSING);
     420      REALLOCATE (output[0].lensing, Lensing, NLENSING);
     421    }
     422    if (Nlensobj + input[0].average[N].Nlensobj >= NLENSOBJ) {
     423      NLENSOBJ = Nlensobj + input[0].average[N].Nlensobj + 1000;
     424      REALLOCATE (next_lensobj, off_t, NLENSOBJ);
     425      REALLOCATE (output[0].lensobj, Lensobj, NLENSOBJ);
     426    }
     427    if (Nstarpar + input[0].average[N].Nstarpar >= NSTARPAR) {
     428      NSTARPAR = Nstarpar + input[0].average[N].Nstarpar + 1000;
     429      REALLOCATE (next_starpar, off_t, NSTARPAR);
     430      REALLOCATE (output[0].starpar, StarPar, NSTARPAR);
     431    }
     432    if (Ngalphot + input[0].average[N].Ngalphot >= NGALPHOT) {
     433      NGALPHOT = Ngalphot + input[0].average[N].Ngalphot + 1000;
     434      REALLOCATE (next_galphot, off_t, NGALPHOT);
     435      REALLOCATE (output[0].galphot, GalPhot, NGALPHOT);
    405436    }
    406437    if (Nave >= NAVE) {
     
    465496    /** add measurements for this input average object **/
    466497    if (output[0].measure && !SKIP_MEASURE && input[0].average[N].Nmeasure) {
    467       output[0].average[Nave].measureOffset  = Nmeas;
     498      output[0].average[Nave].measureOffset  = Nmeasure;
    468499      for (Nin = 0; Nin < input[0].average[N].Nmeasure; Nin ++) {
    469500        offset = input[0].average[N].measureOffset + Nin;
    470501       
    471502        // supply the measurments from this detection
    472         output[0].measure[Nmeas]           = input[0].measure[offset];
     503        output[0].measure[Nmeasure]           = input[0].measure[offset];
    473504       
    474505        // the following measure elements cannot be set until here:
    475         output[0].measure[Nmeas].dbFlags  = 0;
    476         output[0].measure[Nmeas].averef   = Nave;
    477         output[0].measure[Nmeas].objID    = output[0].average[Nave].objID;
    478         output[0].measure[Nmeas].catID    = output[0].catID;
     506        output[0].measure[Nmeasure].dbFlags  = 0;
     507        output[0].measure[Nmeasure].averef   = Nave;
     508        output[0].measure[Nmeasure].objID    = output[0].average[Nave].objID;
     509        output[0].measure[Nmeasure].catID    = output[0].catID;
    479510       
    480511        // as we add measurements, update Nmeasure to match
    481512        output[0].average[Nave].Nmeasure ++;
    482513
    483         /* we set next[Nmeas] to -1 here, and update correctly below */
    484         next_meas[Nmeas] = -1;
    485         Nmeas ++;
     514        /* we set next[Nmeasure] to -1 here, and update correctly below */
     515        next_measure[Nmeasure] = -1;
     516        Nmeasure ++;
    486517      }
    487518      int Ngroup = input[0].average[N].Nmeasure;
    488519      for (j = 0; j < Ngroup - 1; j++) {
    489         next_meas[Nmeas - Ngroup + j] = Nmeas - Ngroup + j + 1;
     520        next_measure[Nmeasure - Ngroup + j] = Nmeasure - Ngroup + j + 1;
    490521      }
    491522    }
     
    493524    /** add lensing for this input average object **/
    494525    if (output[0].lensing && !SKIP_LENSING && input[0].average[N].Nlensing) {
    495       output[0].average[Nave].lensingOffset  = Nlens;
     526      output[0].average[Nave].lensingOffset  = Nlensing;
    496527      for (Nin = 0; Nin < input[0].average[N].Nlensing; Nin ++) {
    497528        // supply the lensing values from this detection
    498529        off_t lensoff = input[0].average[N].lensingOffset + Nin;
    499         output[0].lensing[Nlens]           = input[0].lensing[lensoff];
     530        output[0].lensing[Nlensing]           = input[0].lensing[lensoff];
    500531
    501532        // the following lensing elements cannot be set until here:
    502         output[0].lensing[Nlens].averef   = Nave;
    503         output[0].lensing[Nlens].objID    = output[0].average[Nave].objID;
    504         output[0].lensing[Nlens].catID    = output[0].catID;
     533        output[0].lensing[Nlensing].averef   = Nave;
     534        output[0].lensing[Nlensing].objID    = output[0].average[Nave].objID;
     535        output[0].lensing[Nlensing].catID    = output[0].catID;
    505536
    506537        // as we add lensing, update Nlensing to match
    507538        output[0].average[Nave].Nlensing ++;
    508539
    509         /* we set next[Nlens] to -1 here, and update correctly below */
    510         next_lens[Nlens] = -1;
    511         Nlens ++;
     540        /* we set next[Nlensing] to -1 here, and update correctly below */
     541        next_lensing[Nlensing] = -1;
     542        Nlensing ++;
    512543      }
    513544      int Ngroup = input[0].average[N].Nlensing;
    514545      for (j = 0; j < Ngroup - 1; j++) {
    515         next_lens[Nlens - Ngroup + j] = Nlens - Ngroup + j + 1;
     546        next_lensing[Nlensing - Ngroup + j] = Nlensing - Ngroup + j + 1;
     547      }
     548    }
     549
     550    /** add lensobj for this input average object **/
     551    if (output[0].lensobj && !SKIP_LENSOBJ && input[0].average[N].Nlensobj) {
     552      output[0].average[Nave].lensobjOffset  = Nlensobj;
     553      for (Nin = 0; Nin < input[0].average[N].Nlensobj; Nin ++) {
     554        // supply the lensobj values from this detection
     555        off_t lensoff = input[0].average[N].lensobjOffset + Nin;
     556        output[0].lensobj[Nlensobj]           = input[0].lensobj[lensoff];
     557
     558        // the following lensobj elements cannot be set until here:
     559        // output[0].lensobj[Nlensobj].averef   = Nave;
     560        output[0].lensobj[Nlensobj].objID    = output[0].average[Nave].objID;
     561        output[0].lensobj[Nlensobj].catID    = output[0].catID;
     562
     563        // as we add lensobj, update Nlensobj to match
     564        output[0].average[Nave].Nlensobj ++;
     565
     566        /* we set next[Nlensobj] to -1 here, and update correctly below */
     567        next_lensobj[Nlensobj] = -1;
     568        Nlensobj ++;
     569      }
     570      int Ngroup = input[0].average[N].Nlensobj;
     571      for (j = 0; j < Ngroup - 1; j++) {
     572        next_lensobj[Nlensobj - Ngroup + j] = Nlensobj - Ngroup + j + 1;
    516573      }
    517574    }
     
    519576    /** add starpar for this input average object **/
    520577    if (output[0].starpar && !SKIP_STARPAR && input[0].average[N].Nstarpar) {
    521       output[0].average[Nave].starparOffset  = Nstar;
     578      output[0].average[Nave].starparOffset  = Nstarpar;
    522579      for (Nin = 0; Nin < input[0].average[N].Nstarpar; Nin ++) {
    523580        // supply the starpar values from this detection
    524581        off_t staroff = input[0].average[N].starparOffset + Nin;
    525         output[0].starpar[Nstar]           = input[0].starpar[staroff];
     582        output[0].starpar[Nstarpar]           = input[0].starpar[staroff];
    526583
    527584        // the following starpar elements cannot be set until here:
    528         output[0].starpar[Nstar].averef   = Nave;
    529         output[0].starpar[Nstar].objID    = output[0].average[Nave].objID;
    530         output[0].starpar[Nstar].catID    = output[0].catID;
     585        output[0].starpar[Nstarpar].averef   = Nave;
     586        output[0].starpar[Nstarpar].objID    = output[0].average[Nave].objID;
     587        output[0].starpar[Nstarpar].catID    = output[0].catID;
    531588
    532589        // as we add starpar, update Nstarpar to match
    533590        output[0].average[Nave].Nstarpar ++;
    534591
    535         /* we set next[Nstar] to -1 here, and update correctly below */
    536         next_star[Nstar] = -1;
    537         Nstar ++;
     592        /* we set next[Nstarpar] to -1 here, and update correctly below */
     593        next_starpar[Nstarpar] = -1;
     594        Nstarpar ++;
    538595      }
    539596      int Ngroup = input[0].average[N].Nstarpar;
    540597      for (j = 0; j < Ngroup - 1; j++) {
    541         next_star[Nstar - Ngroup + j] = Nstar - Ngroup + j + 1;
     598        next_starpar[Nstarpar - Ngroup + j] = Nstarpar - Ngroup + j + 1;
    542599      }
    543600    }
     
    545602    /** add galphot for this input average object **/
    546603    if (output[0].galphot && !SKIP_GALPHOT && input[0].average[N].Ngalphot) {
    547       output[0].average[Nave].galphotOffset  = Ngalp;
     604      output[0].average[Nave].galphotOffset  = Ngalphot;
    548605      for (Nin = 0; Nin < input[0].average[N].Ngalphot; Nin ++) {
    549606        // supply the galphot values from this detection
    550607        off_t galpoff = input[0].average[N].galphotOffset + Nin;
    551         output[0].galphot[Ngalp]           = input[0].galphot[galpoff];
     608        output[0].galphot[Ngalphot]           = input[0].galphot[galpoff];
    552609
    553610        // the following galphot elements cannot be set until here:
    554         output[0].galphot[Ngalp].averef   = Nave;
    555         output[0].galphot[Ngalp].objID    = output[0].average[Nave].objID;
    556         output[0].galphot[Ngalp].catID    = output[0].catID;
     611        output[0].galphot[Ngalphot].averef   = Nave;
     612        output[0].galphot[Ngalphot].objID    = output[0].average[Nave].objID;
     613        output[0].galphot[Ngalphot].catID    = output[0].catID;
    557614
    558615        // as we add galphot, update Ngalphot to match
    559616        output[0].average[Nave].Ngalphot ++;
    560617
    561         /* we set next[Ngalp] to -1 here, and update correctly below */
    562         next_galp[Ngalp] = -1;
    563         Ngalp ++;
     618        /* we set next[Ngalphot] to -1 here, and update correctly below */
     619        next_galphot[Ngalphot] = -1;
     620        Ngalphot ++;
    564621      }
    565622      int Ngroup = input[0].average[N].Ngalphot;
    566623      for (j = 0; j < Ngroup - 1; j++) {
    567         next_galp[Ngalp - Ngroup + j] = Ngalp - Ngroup + j + 1;
     624        next_galphot[Ngalphot - Ngroup + j] = Ngalphot - Ngroup + j + 1;
    568625      }
    569626    }
     
    575632
    576633  REALLOCATE (output[0].average, Average, Nave);
    577   if (!SKIP_MEASURE) { REALLOCATE (output[0].measure, Measure, Nmeas); }
    578   if (!SKIP_LENSING) { REALLOCATE (output[0].lensing, Lensing, Nlens); }
    579   if (!SKIP_STARPAR) { REALLOCATE (output[0].starpar, StarPar, Nstar); }
    580   if (!SKIP_GALPHOT) { REALLOCATE (output[0].galphot, GalPhot, Ngalp); }
     634  if (!SKIP_MEASURE) { REALLOCATE (output[0].measure, Measure, Nmeasure); }
     635  if (!SKIP_LENSING) { REALLOCATE (output[0].lensing, Lensing, Nlensing); }
     636  if (!SKIP_LENSOBJ) { REALLOCATE (output[0].lensobj, Lensobj, Nlensobj); }
     637  if (!SKIP_STARPAR) { REALLOCATE (output[0].starpar, StarPar, Nstarpar); }
     638  if (!SKIP_GALPHOT) { REALLOCATE (output[0].galphot, GalPhot, Ngalphot); }
    581639 
    582640# define NOSORT 0
     
    585643  } else {
    586644    output[0].sorted = TRUE;
    587     if (!SKIP_MEASURE) { output[0].measure = sort_measure (output[0].average, Nave, output[0].measure, Nmeas, next_meas); }
    588     if (!SKIP_LENSING) { output[0].lensing = sort_lensing (output[0].average, Nave, output[0].lensing, Nlens, next_lens); }
    589     if (!SKIP_STARPAR) { output[0].starpar = sort_starpar (output[0].average, Nave, output[0].starpar, Nstar, next_star); }
    590     if (!SKIP_GALPHOT) { output[0].galphot = sort_galphot (output[0].average, Nave, output[0].galphot, Ngalp, next_galp); }
     645    if (!SKIP_MEASURE) { output[0].measure = sort_measure (output[0].average, Nave, output[0].measure, Nmeasure, next_measure); }
     646    if (!SKIP_LENSING) { output[0].lensing = sort_lensing (output[0].average, Nave, output[0].lensing, Nlensing, next_lensing); }
     647    if (!SKIP_LENSOBJ) { output[0].lensobj = sort_lensobj (output[0].average, Nave, output[0].lensobj, Nlensobj, next_lensobj); }
     648    if (!SKIP_STARPAR) { output[0].starpar = sort_starpar (output[0].average, Nave, output[0].starpar, Nstarpar, next_starpar); }
     649    if (!SKIP_GALPHOT) { output[0].galphot = sort_galphot (output[0].average, Nave, output[0].galphot, Ngalphot, next_galphot); }
    591650  }
    592651
     
    594653  output[0].objID    = objID; // new max value, save on catalog close
    595654  output[0].Naverage = Nave;
    596   if (!SKIP_MEASURE) { output[0].Nmeasure = Nmeas; }
    597   if (!SKIP_LENSING) { output[0].Nlensing = Nlens; }
    598   if (!SKIP_STARPAR) { output[0].Nstarpar = Nstar; }
    599   if (!SKIP_GALPHOT) { output[0].Ngalphot = Ngalp; }
     655  if (!SKIP_MEASURE) { output[0].Nmeasure = Nmeasure; }
     656  if (!SKIP_LENSING) { output[0].Nlensing = Nlensing; }
     657  if (!SKIP_LENSOBJ) { output[0].Nlensobj = Nlensobj; }
     658  if (!SKIP_STARPAR) { output[0].Nstarpar = Nstarpar; }
     659  if (!SKIP_GALPHOT) { output[0].Ngalphot = Ngalphot; }
    600660  output[0].Nsecfilt_mem = Nave*NsecfiltOut;
    601   if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeas, Nlens, Ngalp: "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT", ("OFF_T_FMT" matches)\n",  Nstars,  Nave,  Nmeas,  Nlens, Ngalp, Nmatch);
    602 
    603   free (next_meas);
    604   free (next_lens);
    605   free (next_star);
    606   free (next_galp);
     661  if (VERBOSE) fprintf (stderr, "Nstars, Nave, Nmeasure, Nlensing, Ngalphot: "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT" "OFF_T_FMT", ("OFF_T_FMT" matches)\n",  Nstars,  Nave,  Nmeasure,  Nlensing, Ngalphot, Nmatch);
     662
     663  free (next_measure);
     664  free (next_lensing);
     665  free (next_lensobj);
     666  free (next_starpar);
     667  free (next_galphot);
    607668
    608669  free (X2);
     
    625686   images have boundaries which are lines in pixels coords, but curve in RA and DEC
    626687   
    627    output[0].found_t[Ncat] but stars[Nstar].found
     688   output[0].found_t[Ncat] but stars[Nstars].found
    628689   
    629690*/
  • trunk/Ohana/src/fakeastro/Makefile

    r39242 r39926  
    5353$(SRC)/match_fake_stars.$(ARCH).o \
    5454$(SRC)/fakeastro_2mass.$(ARCH).o \
     55$(SRC)/fakeastro_gaia.$(ARCH).o \
    5556$(SRC)/make_2mass_measures.$(ARCH).o \
     57$(SRC)/make_gaia_measures.$(ARCH).o \
    5658$(SRC)/remote_hosts.$(ARCH).o
    5759
  • trunk/Ohana/src/fakeastro/include/fakeastro.h

    r38986 r39926  
    88# define RESETTIME { gettimeofday (&startTimer, (void *) NULL); }
    99
    10 typedef enum {OP_NONE, OP_GALAXY, OP_IMAGES, OP_2MASS} FakeastroOp;
     10typedef enum {OP_NONE, OP_GALAXY, OP_IMAGES, OP_2MASS, OP_GAIA} FakeastroOp;
    1111
    1212typedef struct {
     
    8787int    VERBOSE;
    8888int    VERBOSE2;
    89 int    TESTING;
    9089int    ONE_BIG_CHIP;
     90
     91float  TEST_SCALE;
     92char  *GALAXY_MODEL;
    9193
    9294int    FORCE;
     
    101103char   FAKEASTRO_REF_EPOCH[80];
    102104char   FAKEASTRO_2MASS_EPOCH[80];
     105char   FAKEASTRO_GAIA_EPOCH[80];
    103106
    104107float  RADIUS;
    105108float  MAX_MAG_2MASS;
     109float  MAX_MAG_GAIA;
    106110
    107111SkyRegion UserPatch;
     
    198202int fakeastro_2mass ();
    199203int make_2mass_measures (Catalog *catalog);
     204
     205int fakeastro_gaia ();
     206int make_gaia_measures (Catalog *catalog);
  • trunk/Ohana/src/fakeastro/src/ConfigInit.c

    r37807 r39926  
    1919  // if (!ScanConfig (config, "ADDSTAR_RADIUS",         "%lf", 0, &ADDSTAR_RADIUS))   ADDSTAR_RADIUS = 1.0;
    2020
    21   if ((FAKEASTRO_OP == OP_GALAXY) || (FAKEASTRO_OP == OP_2MASS)) {
     21  if ((FAKEASTRO_OP == OP_GALAXY) || (FAKEASTRO_OP == OP_2MASS) || (FAKEASTRO_OP == OP_GAIA)) {
    2222    // force CATDIR to be absolute (so parallel mode will work)
    2323    GetConfig (config, "CATDIR",                 "%s",  0, CATDIR);
     
    6060    strcpy (FAKEASTRO_2MASS_EPOCH, "2000/01/01,00:00:00"); // epoch of 2MASS astrometry
    6161  }
     62  if (!ScanConfig (config, "FAKEASTRO_GAIA_EPOCH", "%s", 0, FAKEASTRO_GAIA_EPOCH)) {
     63    strcpy (FAKEASTRO_GAIA_EPOCH, "2015/01/01,00:00:00"); // epoch of GAIA astrometry
     64  }
    6265
    6366  /* set the default search radius */
     
    7679
    7780  // OP_2MASS is adding detections to an existing db, the others require and empty db
    78   if (FAKEASTRO_OP != OP_2MASS) {
     81  if ((FAKEASTRO_OP != OP_2MASS) && (FAKEASTRO_OP != OP_GAIA)) {
    7982    // check for existence of CATDIR
    8083    struct stat filestat;
  • trunk/Ohana/src/fakeastro/src/args.c

    r38986 r39926  
    2626  }
    2727
    28   TESTING = FALSE;
     28  if ((N = get_argument (*argc, argv, "-gaia"))) {
     29    remove_argument (N, argc, argv);
     30    FAKEASTRO_OP = OP_GAIA;
     31  }
     32
     33  GALAXY_MODEL = NULL;
     34  if ((N = get_argument (*argc, argv, "-galaxy-model"))) {
     35    remove_argument (N, argc, argv);
     36    GALAXY_MODEL = strcreate(argv[N]);
     37    remove_argument (N, argc, argv);
     38  }
     39  if (!GALAXY_MODEL) GALAXY_MODEL = strcreate ("ROESER");
     40
     41  TEST_SCALE = 1.0;
    2942  if ((N = get_argument (*argc, argv, "-testing"))) {
    3043    remove_argument (N, argc, argv);
    31     TESTING = TRUE;
     44    TEST_SCALE = atof(argv[N]);
     45    remove_argument (N, argc, argv);
    3246  }
    3347  ONE_BIG_CHIP = FALSE;
     
    114128  }
    115129
     130  MAX_MAG_GAIA = 21.0;
     131  if ((N = get_argument (*argc, argv, "-gaia-limit"))) {
     132    remove_argument (N, argc, argv);
     133    MAX_MAG_GAIA = atof(argv[N]);
     134    remove_argument (N, argc, argv);
     135  }
     136
    116137  FORCE = FALSE;
    117138  if ((N = get_argument (*argc, argv, "-force"))) {
     
    250271  // }
    251272
     273  GALAXY_MODEL = NULL;
     274  if ((N = get_argument (*argc, argv, "-galaxy-model"))) {
     275    remove_argument (N, argc, argv);
     276    GALAXY_MODEL = strcreate(argv[N]);
     277    remove_argument (N, argc, argv);
     278  }
     279  if (!GALAXY_MODEL) GALAXY_MODEL = strcreate ("FEAST-HIPPARCOS");
     280
    252281  VERBOSE = VERBOSE2 = FALSE;
    253282  if ((N = get_argument (*argc, argv, "-v"))) {
     
    273302  fprintf (stderr, " additional options: \n");
    274303  fprintf (stderr, "  -region RA RA DEC DEC\n");
    275   fprintf (stderr, "  -catalog (ra) (dec)\n\n");
     304  fprintf (stderr, "  -catalog (ra) (dec)\n");
     305  fprintf (stderr, "  -testing (scale)\n\n");
    276306  fprintf (stderr, "  -v\n");
    277307  fprintf (stderr, "  -vv\n");
  • trunk/Ohana/src/fakeastro/src/fakeastro.c

    r39248 r39926  
    4141      exit (0);
    4242
     43    case OP_GAIA:
     44      fakeastro_gaia ();
     45      /* make_gaia_measures()
     46       */
     47      exit (0);
     48
    4349    default:
    4450      fprintf (stderr, "impossible!\n");
  • trunk/Ohana/src/fakeastro/src/initialize.c

    r37807 r39926  
    1717
    1818  // XXX add to config?
    19   if (!InitGalaxyModel ("ROESER")) {
    20     fprintf (stderr, "failed to init galaxy model\n");
     19  if (!InitGalaxyModel (GALAXY_MODEL)) {
     20    fprintf (stderr, "failed to init galaxy model %s\n", GALAXY_MODEL);
    2121    exit (2);
    2222  }
     
    3030
    3131  // XXX add to config?
    32   if (!InitGalaxyModel ("ROESER")) {
    33     fprintf (stderr, "failed to init galaxy model\n");
     32  if (!InitGalaxyModel (GALAXY_MODEL)) {
     33    fprintf (stderr, "failed to init galaxy model %s\n", GALAXY_MODEL);
    3434    exit (2);
    3535  }
  • trunk/Ohana/src/fakeastro/src/make_fake_stars_catalog.c

    r39248 r39926  
    116116    double dDsee = ohana_gaussdev_rnd (0.0, 1.0 / SN);
    117117
     118    // XXX TEST
     119    // dDsee = dRsee = 0.0;
     120
    118121    double dRoff = (dRpm + dRsee) / 3600.0;
    119122    double dDoff = (dDpm + dDsee) / 3600.0;
  • trunk/Ohana/src/fakeastro/src/make_fakestars.c

    r39589 r39926  
    3535      // we can generate a distribution which is uniform on the sky, in which case
    3636      // we can limit to the selected patch analyically
     37
     38      // note: r & z are generated in parsec
    3739      r = pow(drand48(), 0.33333) * FAKEASTRO_RGAL;
    3840      z = 0.0;
     
    4850      int inPatch = FALSE;
    4951      while (!inPatch) {
     52        // note: r & z are generated in parsec
    5053        z = ohana_gaussdev_rnd (0.0, FAKEASTRO_ZGAL);
    5154        r = sqrt(drand48()) * FAKEASTRO_RGAL;
     
    6871    // double y = r*sin(L);
    6972
     73    // distance here is in parsec
    7074    double distance = sqrt (SQ(r) + SQ(z));
    7175
     
    7478
    7579    double uL_sol, uB_sol;
    76     SolarMotionModel_radians(&uL_sol, &uB_sol, Lrad, Brad, distance);
     80    SolarMotionModel_radians(&uL_sol, &uB_sol, Lrad, Brad, distance / 1000.0);
     81    // note: SolarMotionModel wants distance in kpc
    7782
    7883    double uL = uL_gal + uL_sol;
     
    8085   
    8186    // XXX: amplify motion to make tests easier:
    82     if (TESTING) {
    83       uL *= 100.0;
    84       uB *= 100.0;
    85     }
     87    uL *= TEST_SCALE;
     88    uB *= TEST_SCALE;
    8689   
    8790    double uR, uD;
  • trunk/Ohana/src/kapa2/include/prototypes.h

    r39457 r39926  
    3232void          DrawLabelsRaw       PROTO((Graphic *graphic, KapaGraphWidget *graph, int color));
    3333void          DrawTextlines       PROTO((KapaGraphWidget *graph));
    34 void          DrawConnect         PROTO((KapaGraphWidget *graph, Gobjects *objects));
    35 void          DrawHistogram       PROTO((KapaGraphWidget *graph, Gobjects *objects));
    36 int           DrawObjectN         PROTO((KapaGraphWidget *graph, Gobjects *objects));
    37 void          DrawPoints          PROTO((KapaGraphWidget *graph, Gobjects *objects));
    38 void          ClipLine            PROTO((double x0, double y0, double x1, double y1, double X0, double Y0, double X1, double Y1));
    39 void          DrawXErrors         PROTO((KapaGraphWidget *graph, Gobjects *objects));
    40 void          DrawYErrors         PROTO((KapaGraphWidget *graph, Gobjects *objects));
     34void          DrawConnect         PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects));
     35void          DrawHistogram       PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects));
     36int           DrawObjectN         PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects));
     37void          DrawPoints          PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects));
     38void          ClipLine            PROTO((Graphic *graphic, double x0, double y0, double x1, double y1, double X0, double Y0, double X1, double Y1));
     39void          DrawXErrors         PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects));
     40void          DrawYErrors         PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects));
    4141void          DrawTick            PROTO((Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis));
    4242void          AxisTickScale       PROTO((Axis *axis, double *range, double *major, double *minor, int *nsignif));
     
    115115void          PSLabels            PROTO((KapaGraphWidget *graph, FILE *f));
    116116void          PSTextlines         PROTO((KapaGraphWidget *graph, FILE *f));
     117int           PSObjectsN          PROTO((KapaGraphWidget *graph, Gobjects *objects, FILE *f));
    117118void          PSConnect           PROTO((KapaGraphWidget *graph, Gobjects *objects, FILE *f));
    118119void          PSHistogram         PROTO((KapaGraphWidget *graph, Gobjects *objects, FILE *f));
     
    135136void          bDrawLabels         PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph));
    136137void          bDrawTextlines      PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph));
     138int           bDrawObjectsN       PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
    137139void          bDrawConnect        PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
    138140void          bDrawHistogram      PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
  • trunk/Ohana/src/kapa2/src/DrawFrame.c

    r39594 r39926  
    1212
    1313  graphic = GetGraphic();
     14
     15  P = 0.5 * (1 + 0.25*graph[0].axis[0].lweight) * (hypot (graph[0].axis[0].dfx, graph[0].axis[0].dfy) + hypot (graph[0].axis[0].dfx, graph[0].axis[0].dfy));
    1416
    1517  /* each axis is drawn independently, but ticks and labels are placed according to perpendicular distance. */
     
    3032    dfy = graph[0].axis[i].dfy + 2*dy;
    3133
    32     P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
    33     P *= (1 + 0.25*lweight);
     34    // P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
     35    // P *= (1 + 0.25*lweight);
    3436
    3537    XSetLineAttributes (graphic->display, graphic->gc, lweight, LineSolid, CapNotLast, JoinMiter);
  • trunk/Ohana/src/kapa2/src/DrawObjects.c

    r39594 r39926  
    88# define FillCircle(X,Y,R) (XFillArc (graphic->display, graphic->window, graphic->gc, (int)(X-R), (int)(Y-R), abs(2*R+1), abs(2*R+1), 0, 23040))
    99
    10 # define CONNECT 0
    11 # define HISTOGRAM 1
    12 # define POINTS 2
    13 
    1410# define XCENTER 0.0
    1511# define YCENTER 0.0
     
    1713# define JOINSTYLE JoinMiter
    1814
    19 static Graphic *graphic;
     15// XXX this is not thread safe, but that is OK
     16// static Graphic *graphic;
    2017
    2118/* draw all objects for this Graph */
     
    2421  int i;
    2522 
     23  // the functions below use this global value
     24  Graphic *graphic = GetGraphic();
     25 
     26  // this function calls all of the supporting Draw... functions below
    2627  for (i = 0; i < graph[0].Nobjects; i++) {
    2728    if (DEBUG) fprintf (stderr, "object: %d\n", i);
    2829    if (DEBUG) fprintf (stderr, "Npts: %d\n", graph[0].objects[i].Npts);
    29     DrawObjectN (graph, &graph[0].objects[i]);
     30    DrawObjectN (graphic, graph, &graph[0].objects[i]);
    3031  }   
     32  XSetLineAttributes (graphic->display, graphic->gc, 0, LineSolid, CAPSTYLE, JOINSTYLE);
     33  XSetForeground (graphic->display, graphic->gc, graphic->fore);
    3134  return (TRUE);
    3235}
    3336
    3437/* Draw a specific object in the graph */
    35 int DrawObjectN (KapaGraphWidget *graph, Gobjects *object) {
     38int DrawObjectN (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object) {
    3639 
    3740  static char dot[2] = {2,3};
     
    4144  int lweight;
    4245 
    43   // this function calls all of the supporting Draw... functions below
    44   graphic = GetGraphic();
    45  
    4646  lweight = MAX (1, MIN (10, object[0].lweight));
    4747
     
    5858  /* set line type */
    5959  switch (object[0].ltype) {
    60     case 0:
    61       XSetLineAttributes (graphic->display, graphic->gc, lweight, LineSolid, CAPSTYLE, JOINSTYLE);
    62       break;
    63     case 1:
     60    case KAPA_LINE_DOT:
    6461      XSetDashes (graphic->display, graphic->gc, 1, dot, 2);
    65       XSetLineAttributes (graphic->display, graphic->gc, lweight, LineOnOffDash, CAPSTYLE, JOINSTYLE);
    66       break;
    67     case 2:
     62      XSetLineAttributes (graphic->display, graphic->gc, lweight, LineDoubleDash, CAPSTYLE, JOINSTYLE);
     63      break;
     64    case KAPA_LINE_DASH_SHORT:
    6865      XSetDashes (graphic->display, graphic->gc, 1, short_dash, 2);
    69       XSetLineAttributes (graphic->display, graphic->gc, lweight, LineOnOffDash, CAPSTYLE, JOINSTYLE);
    70       break;
    71     case 3:
     66      XSetLineAttributes (graphic->display, graphic->gc, lweight, LineDoubleDash, CAPSTYLE, JOINSTYLE);
     67      break;
     68    case KAPA_LINE_DASH_LONG:
    7269      XSetDashes (graphic->display, graphic->gc, 1, long_dash, 2);
    73       XSetLineAttributes (graphic->display, graphic->gc, lweight, LineOnOffDash, CAPSTYLE, JOINSTYLE);
    74       break;
    75     case 4:
     70      XSetLineAttributes (graphic->display, graphic->gc, lweight, LineDoubleDash, CAPSTYLE, JOINSTYLE);
     71      break;
     72    case KAPA_LINE_DOT_DASH:
    7673      XSetDashes (graphic->display, graphic->gc, 1, dot_dash, 4);
    77       XSetLineAttributes (graphic->display, graphic->gc, lweight, LineOnOffDash, CAPSTYLE, JOINSTYLE);
    78       break;
     74      XSetLineAttributes (graphic->display, graphic->gc, lweight, LineDoubleDash, CAPSTYLE, JOINSTYLE);
     75      break;
     76    case KAPA_LINE_SOLID:
    7977    default:
    8078      XSetLineAttributes (graphic->display, graphic->gc, lweight, LineSolid, CAPSTYLE, JOINSTYLE);
     
    8886
    8987  switch (object[0].style) {
    90     case CONNECT:
    91       DrawConnect (graph, object);
    92       break;
    93     case HISTOGRAM:
    94       DrawHistogram (graph, object);
    95       break;
    96     case POINTS:
    97       DrawPoints (graph, object);
     88    case KAPA_PLOT_CONNECT:
     89      DrawConnect (graphic, graph, object);
     90      break;
     91    case KAPA_PLOT_HISTOGRAM:
     92      DrawHistogram (graphic, graph, object);
     93      break;
     94    case KAPA_PLOT_POINTS:
     95    default:
     96      DrawPoints (graphic, graph, object);
    9897      break;
    9998  }
    10099   
    101100  if (object[0].etype & 0x01) {
    102     DrawYErrors (graph, object);
     101    DrawYErrors (graphic, graph, object);
    103102  }
    104103  if (object[0].etype & 0x02) {
    105     DrawXErrors (graph, object);
    106   }
    107 
    108   XSetLineAttributes (graphic->display, graphic->gc, 0, LineSolid, CAPSTYLE, JOINSTYLE);
    109   XSetForeground (graphic->display, graphic->gc, graphic->fore);
     104    DrawXErrors (graphic, graph, object);
     105  }
    110106  return (TRUE);
    111107}
    112108
    113109/******/
    114 void DrawConnect (KapaGraphWidget *graph, Gobjects *object) {
     110void DrawConnect (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object) {
    115111 
    116112  int i;
     
    149145    sy1 = x[i]*myi + y[i]*myj + by + YCENTER;
    150146   
    151     ClipLine (sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
     147    ClipLine (graphic, sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
    152148    /* DrawLine (sx0, sy0, sx1, sy1); */
    153149    sx0 = sx1; sy0 = sy1;
     
    156152}
    157153
    158 void ClipLine (double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0) {
     154void ClipLine (Graphic *graphic, double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0) {
    159155
    160156  /* skip line segement if both points are beyond box */
     
    212208/* simplify the code abit by finding triplets, watch out for a histogram of 2 points */
    213209# if (1)
    214 void DrawHistogram (KapaGraphWidget *graph, Gobjects *object) {
     210void DrawHistogram (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object) {
    215211
    216212  int i;
     
    298294# else
    299295
    300 void DrawHistogram (KapaGraphWidget *graph, Gobjects *object) {
     296void DrawHistogram (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object) {
    301297
    302298  int i;
     
    407403
    408404/******/
    409 void DrawPoints (KapaGraphWidget *graph, Gobjects *object) {
     405void DrawPoints (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object) {
    410406
    411407  int i;
     
    427423  by = byi + byj;
    428424 
    429   Graphic *graphic = GetGraphic();
    430 
    431   /**** points are scaled by object.z ***/
     425  /**** point sizes are scaled by object.size, colors by object.color ***/
    432426  int scaleSize = (object[0].size < 0);
    433427  int scaleColor = (object[0].color < 0);
     
    437431  x = object[0].x; y = object[0].y; z = object[0].z;
    438432
    439   if (object[0].ptype == 0) {   /* filled box */
    440     for (i = 0; i < object[0].Npts; i++) {
    441       if (!(finite(x[i]) && finite(y[i]))) continue;
    442       sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    443       sy = x[i]*myi + y[i]*myj + by + YCENTER;
    444       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    445           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
    446         if (scaleColor) {
    447           if (!finite(z[i])) continue;
    448           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    449           XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
    450         }
    451         D = scaleSize ? dz*z[i] : ds;
    452         FillRectangle (sx - D, sy - D, 2*D + 1, 2*D + 1);
    453       }
     433  switch (object[0].ptype) {
     434    case KAPA_POINT_BOX_OPEN:   /* open box */
     435      for (i = 0; i < object[0].Npts; i++) {
     436        if (!(finite(x[i]) && finite(y[i]))) continue;
     437        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     438        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     439        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     440            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     441          if (scaleColor) {
     442            if (!finite(z[i])) continue;
     443            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     444            XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
     445          }
     446          D = scaleSize ? dz*z[i] : ds;
     447          DrawRectangle (sx - D, sy - D, 2*D, 2*D);
     448        }
     449      }
     450      break;
     451    case KAPA_POINT_CROSS: /* cross */
     452      for (i = 0; i < object[0].Npts; i++) {
     453        if (!(finite(x[i]) && finite(y[i]))) continue;
     454        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     455        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     456        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     457            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     458          if (scaleColor) {
     459            if (!finite(z[i])) continue;
     460            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     461            XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
     462          }
     463          D = scaleSize ? dz*z[i] : ds;
     464          DrawLine (sx - D, sy, sx + D + 1, sy);
     465          DrawLine (sx, sy - D, sx, sy + D + 1);
     466        }
     467      }
     468      break;
     469    case KAPA_POINT_X:  /* x */
     470      for (i = 0; i < object[0].Npts; i++) {
     471        if (!(finite(x[i]) && finite(y[i]))) continue;
     472        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     473        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     474        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     475            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     476          if (scaleColor) {
     477            if (!finite(z[i])) continue;
     478            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     479            XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
     480          }
     481          D = scaleSize ? dz*z[i] : ds;
     482          DrawLine (sx - D, sy + D, sx + D + 1, sy - D - 1);
     483          DrawLine (sx - D, sy - D, sx + D + 1, sy + D + 1);
     484        }
     485      }
     486      break;
     487    case KAPA_POINT_TRIANGLE_SOLID:     /* filled triangle */
     488      for (i = 0; i < object[0].Npts; i++) {
     489        if (!(finite(x[i]) && finite(y[i]))) continue;
     490        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     491        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     492        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     493            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     494          if (scaleColor) {
     495            if (!finite(z[i])) continue;
     496            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     497            XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
     498          }
     499          D = scaleSize ? dz*z[i] : ds;
     500
     501          XPoint points[4];
     502          points[0].x = sx - D;  points[0].y = sy + 0.58*D; 
     503          points[1].x = sx + D;  points[1].y = sy + 0.58*D; 
     504          points[2].x = sx;      points[2].y = sy - 1.15*D; 
     505          points[3].x = sx - D;  points[3].y = sy + 0.58*D; 
     506          XFillPolygon (graphic->display, graphic->window, graphic->gc, points, 4, Convex, CoordModeOrigin);
     507        }
     508      }
     509      break;
     510    case KAPA_POINT_TRIANGLE_SOLID_DOWN: /* filled triangle (down) */
     511      for (i = 0; i < object[0].Npts; i++) {
     512        if (!(finite(x[i]) && finite(y[i]))) continue;
     513        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     514        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     515        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     516            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     517          if (scaleColor) {
     518            if (!finite(z[i])) continue;
     519            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     520            XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
     521          }
     522          D = scaleSize ? dz*z[i] : ds;
     523
     524          XPoint points[4];
     525          points[0].x = sx - D;  points[0].y = sy - 0.58*D; 
     526          points[1].x = sx + D;  points[1].y = sy - 0.58*D; 
     527          points[2].x = sx;      points[2].y = sy + 1.15*D; 
     528          points[3].x = sx - D;  points[3].y = sy - 0.58*D; 
     529          XFillPolygon (graphic->display, graphic->window, graphic->gc, points, 4, Convex, CoordModeOrigin);
     530        }
     531      }
     532      break;
     533    case KAPA_POINT_TRIANGLE_OPEN:      /* open triangle */
     534      for (i = 0; i < object[0].Npts; i++) {
     535        if (!(finite(x[i]) && finite(y[i]))) continue;
     536        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     537        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     538        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     539            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     540          if (scaleColor) {
     541            if (!finite(z[i])) continue;
     542            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     543            XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
     544          }
     545          D = scaleSize ? dz*z[i] : ds;
     546          DrawLine (sx - D, sy + 0.58*D, sx + D, sy + 0.58*D);
     547          DrawLine (sx + D, sy + 0.58*D, sx,     sy - 1.15*D);
     548          DrawLine (sx,     sy - 1.15*D, sx - D, sy + 0.58*D);
     549        }
     550      }
     551      break;
     552    case KAPA_POINT_TRIANGLE_OPEN_DOWN: /* upside-down open triangle */
     553      for (i = 0; i < object[0].Npts; i++) {
     554        if (!(finite(x[i]) && finite(y[i]))) continue;
     555        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     556        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     557        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     558            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     559          if (scaleColor) {
     560            if (!finite(z[i])) continue;
     561            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     562            XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
     563          }
     564          D = scaleSize ? dz*z[i] : ds;
     565          DrawLine (sx - D, sy - 0.58*D, sx + D, sy - 0.58*D);
     566          DrawLine (sx + D, sy - 0.58*D, sx,     sy + 1.15*D);
     567          DrawLine (sx,     sy + 1.15*D, sx - D, sy - 0.58*D);
     568        }
     569      }
     570      break;
     571    case KAPA_POINT_Y:  /* Y */
     572      for (i = 0; i < object[0].Npts; i++) {
     573        if (!(finite(x[i]) && finite(y[i]))) continue;
     574        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     575        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     576        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     577            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     578          if (scaleColor) {
     579            if (!finite(z[i])) continue;
     580            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     581            XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
     582          }
     583          D = scaleSize ? dz*z[i] : ds;
     584          DrawLine (sx, sy, sx - D, sy - 0.58*D);
     585          DrawLine (sx, sy, sx + D, sy - 0.58*D);
     586          DrawLine (sx, sy, sx,     sy + 1.15*D);
     587        }
     588      }
     589      break;
     590    case KAPA_POINT_Y_DOWN:     /* upside-down Y */
     591      for (i = 0; i < object[0].Npts; i++) {
     592        if (!(finite(x[i]) && finite(y[i]))) continue;
     593        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     594        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     595        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     596            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     597          if (scaleColor) {
     598            if (!finite(z[i])) continue;
     599            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     600            XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
     601          }
     602          D = scaleSize ? dz*z[i] : ds;
     603          DrawLine (sx, sy, sx - D, sy + 0.58*D);
     604          DrawLine (sx, sy, sx + D, sy + 0.58*D);
     605          DrawLine (sx, sy, sx,     sy - 1.15*D);
     606        }
     607      }
     608      break;
     609    case KAPA_POINT_CIRCLE_OPEN: /* 0 */
     610      for (i = 0; i < object[0].Npts; i++) {
     611        if (!(finite(x[i]) && finite(y[i]))) continue;
     612        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     613        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     614        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     615            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     616          if (scaleColor) {
     617            if (!finite(z[i])) continue;
     618            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     619            XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
     620          }
     621          D = scaleSize ? dz*z[i] : ds;
     622          DrawCircle (sx, sy, D);
     623        }
     624      }
     625      break;
     626    case KAPA_POINT_CIRCLE_SOLID: /* filled 0 */
     627      for (i = 0; i < object[0].Npts; i++) {
     628        if (!(finite(x[i]) && finite(y[i]))) continue;
     629        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     630        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     631        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     632            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     633          if (scaleColor) {
     634            if (!finite(z[i])) continue;
     635            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     636            XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
     637          }
     638          D = scaleSize ? dz*z[i] : ds;
     639          FillCircle (sx, sy, D);
     640          DrawCircle (sx, sy, D);
     641        }
     642      }
     643      break;
     644    case KAPA_POINT_PENTAGON:   /* pentagon */
     645      for (i = 0; i < object[0].Npts; i++) {
     646        if (!(finite(x[i]) && finite(y[i]))) continue;
     647        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     648        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     649        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     650            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     651          if (scaleColor) {
     652            if (!finite(z[i])) continue;
     653            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     654            XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
     655          }
     656          D = scaleSize ? dz*z[i] : ds;
     657          DrawLine (sx + 0.00*D, sy - 1.00*D, sx + 0.95*D, sy - 0.31*D);
     658          DrawLine (sx + 0.95*D, sy - 0.31*D, sx + 0.58*D, sy + 0.81*D);
     659          DrawLine (sx + 0.58*D, sy + 0.81*D, sx - 0.58*D, sy + 0.81*D);
     660          DrawLine (sx - 0.58*D, sy + 0.81*D, sx - 0.95*D, sy - 0.31*D);
     661          DrawLine (sx - 0.95*D, sy - 0.31*D, sx + 0.00*D, sy - 1.00*D);
     662        }
     663      }
     664      break;
     665    case KAPA_POINT_HEXAGON:    /* hexagon */
     666      for (i = 0; i < object[0].Npts; i++) {
     667        if (!(finite(x[i]) && finite(y[i]))) continue;
     668        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     669        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     670        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     671            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     672          if (scaleColor) {
     673            if (!finite(z[i])) continue;
     674            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     675            XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
     676          }
     677          D = scaleSize ? dz*z[i] : ds;
     678          DrawLine (sx -      D, sy,          sx - 0.50*D, sy + 0.87*D);
     679          DrawLine (sx - 0.50*D, sy + 0.87*D, sx + 0.50*D, sy + 0.87*D);
     680          DrawLine (sx + 0.50*D, sy + 0.87*D, sx +      D, sy);
     681
     682          DrawLine (sx +      D, sy,          sx + 0.50*D, sy - 0.87*D);
     683          DrawLine (sx + 0.50*D, sy - 0.87*D, sx - 0.50*D, sy - 0.87*D);
     684          DrawLine (sx - 0.50*D, sy - 0.87*D, sx -      D, sy);
     685        }
     686      }
     687      break;
     688    case KAPA_POINT_PAIR_CONNECT: { /* connect pairs of points */
     689      double X0 = graph[0].axis[0].fx;
     690      double X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx;
     691      double Y0 = graph[0].axis[1].fy;
     692      double Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy;
     693
     694      for (i = 0; i + 1 < object[0].Npts; i+=2) {
     695        if (!(finite(x[i]) && finite(y[i]))) continue;
     696        sx1 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     697        sy1 = x[i]*myi + y[i]*myj + by + YCENTER;
     698        if (!(finite(x[i+1]) && finite(y[i+1]))) continue;
     699        sx2 = x[i+1]*mxi + y[i+1]*mxj + bx + XCENTER;
     700        sy2 = x[i+1]*myi + y[i+1]*myj + by + YCENTER;
     701        ClipLine (graphic, sx1, sy1, sx2, sy2, X0, Y0, X1, Y1);
     702      }
     703      break;
    454704    }
    455   }
    456   if (object[0].ptype == 1) {   /* open box */
    457     for (i = 0; i < object[0].Npts; i++) {
    458       if (!(finite(x[i]) && finite(y[i]))) continue;
    459       sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    460       sy = x[i]*myi + y[i]*myj + by + YCENTER;
    461       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    462           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
    463         if (scaleColor) {
    464           if (!finite(z[i])) continue;
    465           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    466           XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
    467         }
    468         D = scaleSize ? dz*z[i] : ds;
    469         DrawRectangle (sx - D, sy - D, 2*D, 2*D);
    470       }
    471     }
    472   }
    473   if (object[0].ptype == 2) { /* cross */
    474     for (i = 0; i < object[0].Npts; i++) {
    475       if (!(finite(x[i]) && finite(y[i]))) continue;
    476       sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    477       sy = x[i]*myi + y[i]*myj + by + YCENTER;
    478       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    479           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
    480         if (scaleColor) {
    481           if (!finite(z[i])) continue;
    482           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    483           XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
    484         }
    485         D = scaleSize ? dz*z[i] : ds;
    486         DrawLine (sx - D, sy, sx + D + 1, sy);
    487         DrawLine (sx, sy - D, sx, sy + D + 1);
    488       }
    489     }
    490   }
    491   if (object[0].ptype == 3) {   /* x */
    492     for (i = 0; i < object[0].Npts; i++) {
    493       if (!(finite(x[i]) && finite(y[i]))) continue;
    494       sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    495       sy = x[i]*myi + y[i]*myj + by + YCENTER;
    496       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    497           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
    498         if (scaleColor) {
    499           if (!finite(z[i])) continue;
    500           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    501           XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
    502         }
    503         D = scaleSize ? dz*z[i] : ds;
    504         DrawLine (sx - D, sy + D, sx + D + 1, sy - D - 1);
    505         DrawLine (sx - D, sy - D, sx + D + 1, sy + D + 1);
    506       }
    507     }
    508   }
    509   if (object[0].ptype == 4) {   /* filled triangle */
    510     XPoint points[4];
    511     for (i = 0; i < object[0].Npts; i++) {
    512       if (!(finite(x[i]) && finite(y[i]))) continue;
    513       sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    514       sy = x[i]*myi + y[i]*myj + by + YCENTER;
    515       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    516           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
    517         if (scaleColor) {
    518           if (!finite(z[i])) continue;
    519           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    520           XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
    521         }
    522         D = scaleSize ? dz*z[i] : ds;
    523         points[0].x = sx - D;  points[0].y = sy + 0.58*D; 
    524         points[1].x = sx + D;  points[1].y = sy + 0.58*D; 
    525         points[2].x = sx;      points[2].y = sy - 1.15*D; 
    526         points[3].x = sx - D;  points[3].y = sy + 0.58*D; 
    527         XFillPolygon (graphic->display, graphic->window, graphic->gc, points, 4, Convex, CoordModeOrigin);
    528       }
    529     }
    530   }
    531   if (object[0].ptype == 5) {   /* open triangle */
    532     for (i = 0; i < object[0].Npts; i++) {
    533       if (!(finite(x[i]) && finite(y[i]))) continue;
    534       sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    535       sy = x[i]*myi + y[i]*myj + by + YCENTER;
    536       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    537           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
    538         if (scaleColor) {
    539           if (!finite(z[i])) continue;
    540           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    541           XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
    542         }
    543         D = scaleSize ? dz*z[i] : ds;
    544         DrawLine (sx - D, sy + 0.58*D, sx + D, sy + 0.58*D);
    545         DrawLine (sx + D, sy + 0.58*D, sx,     sy - 1.15*D);
    546         DrawLine (sx,     sy - 1.15*D, sx - D, sy + 0.58*D);
    547       }
    548     }
    549   }
    550   if (object[0].ptype == 6) {   /* Y */
    551     for (i = 0; i < object[0].Npts; i++) {
    552       if (!(finite(x[i]) && finite(y[i]))) continue;
    553       sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    554       sy = x[i]*myi + y[i]*myj + by + YCENTER;
    555       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    556           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
    557         if (scaleColor) {
    558           if (!finite(z[i])) continue;
    559           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    560           XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
    561         }
    562         D = scaleSize ? dz*z[i] : ds;
    563         DrawLine (sx, sy, sx - D, sy - 0.58*D);
    564         DrawLine (sx, sy, sx + D, sy - 0.58*D);
    565         DrawLine (sx, sy, sx,     sy + 1.15*D);
    566       }
    567     }
    568   }
    569   if (object[0].ptype == 7) {   /* 0 */
    570     for (i = 0; i < object[0].Npts; i++) {
    571       if (!(finite(x[i]) && finite(y[i]))) continue;
    572       sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    573       sy = x[i]*myi + y[i]*myj + by + YCENTER;
    574       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    575           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
    576         if (scaleColor) {
    577           if (!finite(z[i])) continue;
    578           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    579           XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
    580         }
    581         D = scaleSize ? dz*z[i] : ds;
    582         DrawCircle (sx, sy, D);
    583       }
    584     }
    585   }
    586   if (object[0].ptype == 8) {   /* pentagon */
    587     for (i = 0; i < object[0].Npts; i++) {
    588       if (!(finite(x[i]) && finite(y[i]))) continue;
    589       sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    590       sy = x[i]*myi + y[i]*myj + by + YCENTER;
    591       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    592           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
    593         if (scaleColor) {
    594           if (!finite(z[i])) continue;
    595           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    596           XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
    597         }
    598         D = scaleSize ? dz*z[i] : ds;
    599         DrawLine (sx + 0.00*D, sy - 1.00*D, sx + 0.95*D, sy - 0.31*D);
    600         DrawLine (sx + 0.95*D, sy - 0.31*D, sx + 0.58*D, sy + 0.81*D);
    601         DrawLine (sx + 0.58*D, sy + 0.81*D, sx - 0.58*D, sy + 0.81*D);
    602         DrawLine (sx - 0.58*D, sy + 0.81*D, sx - 0.95*D, sy - 0.31*D);
    603         DrawLine (sx - 0.95*D, sy - 0.31*D, sx + 0.00*D, sy - 1.00*D);
    604       }
    605     }
    606   }
    607   if (object[0].ptype == 9) {   /* hexagon */
    608     for (i = 0; i < object[0].Npts; i++) {
    609       if (!(finite(x[i]) && finite(y[i]))) continue;
    610       sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    611       sy = x[i]*myi + y[i]*myj + by + YCENTER;
    612       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    613           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
    614         if (scaleColor) {
    615           if (!finite(z[i])) continue;
    616           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    617           XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
    618         }
    619         D = scaleSize ? dz*z[i] : ds;
    620         DrawLine (sx -      D, sy,          sx - 0.50*D, sy + 0.87*D);
    621         DrawLine (sx - 0.50*D, sy + 0.87*D, sx + 0.50*D, sy + 0.87*D);
    622         DrawLine (sx + 0.50*D, sy + 0.87*D, sx +      D, sy);
    623 
    624         DrawLine (sx +      D, sy,          sx + 0.50*D, sy - 0.87*D);
    625         DrawLine (sx + 0.50*D, sy - 0.87*D, sx - 0.50*D, sy - 0.87*D);
    626         DrawLine (sx - 0.50*D, sy - 0.87*D, sx -      D, sy);
    627       }
    628     }
    629   }
    630   if (object[0].ptype == 10) {  /* filled 0 */
    631     for (i = 0; i < object[0].Npts; i++) {
    632       if (!(finite(x[i]) && finite(y[i]))) continue;
    633       sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    634       sy = x[i]*myi + y[i]*myj + by + YCENTER;
    635       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    636           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
    637         if (scaleColor) {
    638           if (!finite(z[i])) continue;
    639           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    640           XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
    641         }
    642         D = scaleSize ? dz*z[i] : ds;
    643         FillCircle (sx, sy, D);
    644       }
    645     }
    646   }
    647   if (object[0].ptype == 12) {  /* filled triangle (down) */
    648     XPoint points[4];
    649     for (i = 0; i < object[0].Npts; i++) {
    650       if (!(finite(x[i]) && finite(y[i]))) continue;
    651       sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    652       sy = x[i]*myi + y[i]*myj + by + YCENTER;
    653       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    654           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
    655         if (scaleColor) {
    656           if (!finite(z[i])) continue;
    657           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    658           XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
    659         }
    660         D = scaleSize ? dz*z[i] : ds;
    661         points[0].x = sx - D;  points[0].y = sy - 0.58*D; 
    662         points[1].x = sx + D;  points[1].y = sy - 0.58*D; 
    663         points[2].x = sx;      points[2].y = sy + 1.15*D; 
    664         points[3].x = sx - D;  points[3].y = sy - 0.58*D; 
    665         XFillPolygon (graphic->display, graphic->window, graphic->gc, points, 4, Convex, CoordModeOrigin);
    666       }
    667     }
    668   }
    669   if (object[0].ptype == 14) {  /* upside-down filled triangle */
    670     XPoint points[4];
    671     for (i = 0; i < object[0].Npts; i++) {
    672       if (!(finite(x[i]) && finite(y[i]))) continue;
    673       sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    674       sy = x[i]*myi + y[i]*myj + by + YCENTER;
    675       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    676           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
    677         if (scaleColor) {
    678           if (!finite(z[i])) continue;
    679           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    680           XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
    681         }
    682         D = scaleSize ? dz*z[i] : ds;
    683         points[0].x = sx - D;  points[0].y = sy - 0.58*D; 
    684         points[1].x = sx + D;  points[1].y = sy - 0.58*D; 
    685         points[2].x = sx;      points[2].y = sy + 1.15*D; 
    686         points[3].x = sx - D;  points[3].y = sy - 0.58*D; 
    687         XFillPolygon (graphic->display, graphic->window, graphic->gc, points, 4, Convex, CoordModeOrigin);
    688       }
    689     }
    690   }
    691   if (object[0].ptype == 15) {  /* upside-down open triangle */
    692     for (i = 0; i < object[0].Npts; i++) {
    693       if (!(finite(x[i]) && finite(y[i]))) continue;
    694       sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    695       sy = x[i]*myi + y[i]*myj + by + YCENTER;
    696       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    697           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
    698         if (scaleColor) {
    699           if (!finite(z[i])) continue;
    700           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    701           XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
    702         }
    703         D = scaleSize ? dz*z[i] : ds;
    704         DrawLine (sx - D, sy - 0.58*D, sx + D, sy - 0.58*D);
    705         DrawLine (sx + D, sy - 0.58*D, sx,     sy + 1.15*D);
    706         DrawLine (sx,     sy + 1.15*D, sx - D, sy - 0.58*D);
    707       }
    708     }
    709   }
    710   if (object[0].ptype == 16) {  /* upside-down Y */
    711     for (i = 0; i < object[0].Npts; i++) {
    712       if (!(finite(x[i]) && finite(y[i]))) continue;
    713       sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    714       sy = x[i]*myi + y[i]*myj + by + YCENTER;
    715       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    716           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
    717         if (scaleColor) {
    718           if (!finite(z[i])) continue;
    719           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    720           XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
    721         }
    722         D = scaleSize ? dz*z[i] : ds;
    723         DrawLine (sx, sy, sx - D, sy + 0.58*D);
    724         DrawLine (sx, sy, sx + D, sy + 0.58*D);
    725         DrawLine (sx, sy, sx,     sy - 1.15*D);
    726       }
    727     }
    728   }
    729   if (object[0].ptype == 100) { /* connect a pair of points */
    730 
    731     double X0 = graph[0].axis[0].fx;
    732     double X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx;
    733     double Y0 = graph[0].axis[1].fy;
    734     double Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy;
    735 
    736     for (i = 0; i + 1 < object[0].Npts; i+=2) {
    737       if (!(finite(x[i]) && finite(y[i]))) continue;
    738       sx1 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
    739       sy1 = x[i]*myi + y[i]*myj + by + YCENTER;
    740       if (!(finite(x[i+1]) && finite(y[i+1]))) continue;
    741       sx2 = x[i+1]*mxi + y[i+1]*mxj + bx + XCENTER;
    742       sy2 = x[i+1]*myi + y[i+1]*myj + by + YCENTER;
    743       ClipLine (sx1, sy1, sx2, sy2, X0, Y0, X1, Y1);
    744     }
     705    case KAPA_POINT_BOX_SOLID:  /* filled box */
     706    default:
     707      for (i = 0; i < object[0].Npts; i++) {
     708        if (!(finite(x[i]) && finite(y[i]))) continue;
     709        sx = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     710        sy = x[i]*myi + y[i]*myj + by + YCENTER;
     711        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     712            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     713          if (scaleColor) {
     714            if (!finite(z[i])) continue;
     715            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     716            XSetForeground (graphic->display, graphic->gc, graphic->cmap[pixel].pixel);
     717          }
     718          D = scaleSize ? dz*z[i] : ds;
     719          FillRectangle (sx - D, sy - D, 2*D + 1, 2*D + 1);
     720        }
     721      }
     722      break;
    745723  }
    746724}
    747725   
    748726/******/
    749 void DrawXErrors (KapaGraphWidget *graph, Gobjects *object) {
     727void DrawXErrors (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object) {
    750728 
    751729  int i, bar, dz, ds, D;
     
    800778         (sy1 < graph[0].axis[1].fy) && (sy1 > graph[0].axis[1].fy + graph[0].axis[1].dfy)))
    801779    {
    802       ClipLine (sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
     780      ClipLine (graphic, sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
    803781      if (bar) {
    804782        sx10 = sy1 - sz;
    805783        sx11 = sy1 + sz;
    806         ClipLine (sx1, sx10, sx1, sx11, X0, Y0, X1, Y1);
     784        ClipLine (graphic, sx1, sx10, sx1, sx11, X0, Y0, X1, Y1);
    807785      }
    808786    }
     
    819797         (sy1 < graph[0].axis[1].fy) && (sy1 > graph[0].axis[1].fy + graph[0].axis[1].dfy)))
    820798    {
    821       ClipLine (sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
     799      ClipLine (graphic, sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
    822800      if (bar) {
    823801        sx10 = sy1 - sz;
    824802        sx11 = sy1 + sz;
    825         ClipLine (sx1, sx10, sx1, sx11, X0, Y0, X1, Y1);
     803        ClipLine (graphic, sx1, sx10, sx1, sx11, X0, Y0, X1, Y1);
    826804      }
    827805    }
     
    830808   
    831809/******/
    832 void DrawYErrors (KapaGraphWidget *graph, Gobjects *object) {
     810void DrawYErrors (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object) {
    833811
    834812  int i, bar, dz, ds, D;
     
    883861         (sy1 < graph[0].axis[1].fy) && (sy1 > graph[0].axis[1].fy + graph[0].axis[1].dfy)))
    884862    {
    885       ClipLine (sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
     863      ClipLine (graphic, sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
    886864      if (bar) {
    887865        sx10 = sx1 - sz;
    888866        sx11 = sx1 + sz;
    889         ClipLine (sx10, sy1, sx11, sy1, X0, Y0, X1, Y1);
     867        ClipLine (graphic, sx10, sy1, sx11, sy1, X0, Y0, X1, Y1);
    890868      }
    891869    }
     
    904882         (sy1 < graph[0].axis[1].fy) && (sy1 > graph[0].axis[1].fy + graph[0].axis[1].dfy)))
    905883    {
    906       ClipLine (sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
     884      ClipLine (graphic, sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
    907885      if (bar) {
    908886        sx10 = sx1 - sz;
    909887        sx11 = sx1 + sz;
    910         ClipLine (sx10, sy1, sx11, sy1, X0, Y0, X1, Y1);
     888        ClipLine (graphic, sx10, sy1, sx11, sy1, X0, Y0, X1, Y1);
    911889      }
    912890    }
  • trunk/Ohana/src/kapa2/src/LoadObject.c

    r31665 r39926  
    102102  if (DEBUG) fprintf (stderr, "loaded %d objects, using object %d\n", graph[0].objects[N].Npts, N);
    103103
    104   if (USE_XWINDOW) DrawObjectN (graph, &graph[0].objects[graph[0].Nobjects-1]);
     104  if (USE_XWINDOW) {
     105    Graphic *graphic = GetGraphic();
     106    DrawObjectN (graphic, graph, &graph[0].objects[graph[0].Nobjects-1]);
     107  }
    105108  FlushDisplay ();
    106109
  • trunk/Ohana/src/kapa2/src/PSFrame.c

    r38986 r39926  
    1111
    1212  graphic = GetGraphic();
     13
     14  P = 0.5 * (1 + 0.25*graph[0].axis[0].lweight) * (hypot (graph[0].axis[0].dfx, graph[0].axis[0].dfy) + hypot (graph[0].axis[0].dfx, graph[0].axis[0].dfy));
    1315
    1416  /* each axis is drawn independently */
     
    3032    dfy = -graph[0].axis[i].dfy + 2*dy;
    3133
    32     P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
    33     P *= (1 + 0.25*lweight);
     34    // P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
     35    // P *= (1 + 0.25*lweight);
    3436
    3537    fprintf (f, "%.1f setlinewidth\n", lweight);
  • trunk/Ohana/src/kapa2/src/PSObjects.c

    r38153 r39926  
    77# define FillCircle(X1,Y1,R) (fprintf (f, " %6.2f %6.2f %6.2f FC\n", (X1), (graphic->dy - Y1), (R)))
    88# define FillTriangle(X1,Y1,X2,Y2, X3, Y3) (fprintf (f, " %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f TF\n", (X1), (graphic->dy-Y1), (X2), (graphic->dy-Y2), (X3), (graphic->dy-Y3)))
    9 # define CONNECT 0
    10 # define HISTOGRAM 1
    11 # define POINTS 2
    12 
     9
     10# define CAPSTYLE 1 /* CapButt */
     11# define JOINSTYLE 0 /* JoinMiter */
     12
     13// XXX this is not thread safe, but that is OK
    1314static Graphic *graphic;
    1415
     
    1617 
    1718  int i;
    18   double lweight;
    19   static char dash[] = "5";
    20   static char dot[] = "3";
    21  
     19 
     20  // the functions below use this global value
    2221  graphic = GetGraphic();
    2322
     23  // this function calls all of the supporting Draw... functions below
    2424  for (i = 0; i < graph[0].Nobjects; i++) {
    25     switch (graph[0].objects[i].ltype) {
    26     case 0:
    27       break;
    28     case 1:
    29       fprintf (f, "[%s] 0 setdash\n", dash);
    30       break;
    31     case 2:
     25    PSObjectsN (graph, &graph[0].objects[i], f);
     26  }
     27  // reset to default color and style
     28  fprintf (f, "[] 0 setdash\n");
     29  fprintf (f, "0.00 0.00 0.00 setrgbcolor\n");
     30
     31  return (TRUE);
     32}
     33
     34int PSObjectsN (KapaGraphWidget *graph, Gobjects *object, FILE *f) {
     35 
     36  static char short_dash[] = "4 4";
     37  static char long_dash[] = "8 8";
     38  static char dot_dash[] = "2 4 4 4";
     39  static char dot[] = "2 3";
     40 
     41  double lweight = MAX (0, MIN (10, object->lweight));
     42  fprintf (f, "%.1f setlinewidth\n", lweight);
     43  fprintf (f, "%d setlinecap %d setlinejoin\n", CAPSTYLE, JOINSTYLE);
     44
     45  switch (object->ltype) {
     46    case KAPA_LINE_DOT:
    3247      fprintf (f, "[%s] 0 setdash\n", dot);
    3348      break;
     49    case KAPA_LINE_DASH_SHORT:
     50      fprintf (f, "[%s] 0 setdash\n", short_dash);
     51      break;
     52    case KAPA_LINE_DASH_LONG:
     53      fprintf (f, "[%s] 0 setdash\n", long_dash);
     54      break;
     55    case KAPA_LINE_DOT_DASH:
     56      fprintf (f, "[%s] 0 setdash\n", dot_dash);
     57      break;
     58    case KAPA_LINE_SOLID: // no need to call 'setdash' as solid is the default
    3459    default:
    3560      break;
    36     }
     61  }
    3762   
    38     lweight = MAX (0, MIN (10, graph[0].objects[i].lweight));
    39     fprintf (f, "%.1f setlinewidth\n", lweight);
    40 
    41     if (graph[0].objects[i].color >= 0) {
    42         fprintf (f, "%s setrgbcolor\n", KapaColorRGBString(graph[0].objects[i].color));
    43     }
    44 
    45     switch (graph[0].objects[i].style) {
    46     case CONNECT:
    47       PSConnect (graph, &graph[0].objects[i], f);
    48       break;
    49     case HISTOGRAM:
    50       PSHistogram (graph, &graph[0].objects[i], f);
    51       break;
    52     case POINTS:
    53       PSPoints (graph, &graph[0].objects[i], f);
    54       break;
    55     }
    56 
    57     if (graph[0].objects[i].etype & 0x01) {
    58       PSYErrors (graph, &graph[0].objects[i], f);
    59     }
    60     if (graph[0].objects[i].etype & 0x02) {
    61       PSXErrors (graph, &graph[0].objects[i], f);
    62     }
    63     fprintf (f, "[] 0 setdash\n");
    64     fprintf (f, "0.00 0.00 0.00 setrgbcolor\n");
     63  if (object->color >= 0) {
     64    fprintf (f, "%s setrgbcolor\n", KapaColorRGBString(object->color));
     65  }
     66
     67  switch (object->style) {
     68    case KAPA_PLOT_CONNECT:
     69      PSConnect (graph, object, f);
     70      break;
     71    case KAPA_PLOT_HISTOGRAM:
     72      PSHistogram (graph, object, f);
     73      break;
     74    case KAPA_PLOT_POINTS:
     75    default:
     76      PSPoints (graph, object, f);
     77      break;
     78  }
     79
     80  if (object->etype & 0x01) {
     81    PSYErrors (graph, object, f);
     82  }
     83  if (object->etype & 0x02) {
     84    PSXErrors (graph, object, f);
    6585  }
    6686  return (TRUE);
     
    303323  }
    304324
    305   // black, I think
    306325  // fprintf (f, "0.00 0.00 0.00 setrgbcolor\n");
    307326
    308   /**** points are scaled by object.z ***/
     327  /**** point sizes are scaled by object.size, colors by object.color ***/
    309328  int scaleSize = (object[0].size < 0);
    310329  int scaleColor = (object[0].color < 0);
     
    314333  x = object[0].x; y = object[0].y; z = object[0].z;
    315334
    316   if (object[0].ptype == 0) {   /* filled box */
    317     for (i = 0; i < object[0].Npts; i++) {
    318       if (!(finite(x[i]) && finite(y[i]))) continue;
    319       sx = x[i]*mxi + y[i]*mxj + bx;
    320       sy = x[i]*myi + y[i]*myj + by;
    321       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    322           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    323       {
    324         if (scaleColor) {
    325           if (!finite(z[i])) continue;
    326           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    327           fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
    328         }
    329         D = scaleSize ? dz*z[i] : ds;
    330         FillRectangle (sx, sy, 2*D, 2*D);
    331       }
     335  switch (object[0].ptype) {
     336    case KAPA_POINT_BOX_OPEN:   /* open box */
     337      for (i = 0; i < object[0].Npts; i++) {
     338        if (!(finite(x[i]) && finite(y[i]))) continue;
     339        sx = x[i]*mxi + y[i]*mxj + bx;
     340        sy = x[i]*myi + y[i]*myj + by;
     341        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     342            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     343          if (scaleColor) {
     344            if (!finite(z[i])) continue;
     345            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     346            fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
     347          }
     348          D = scaleSize ? dz*z[i] : ds;
     349          DrawRectangle (sx, sy, 2*D, 2*D);
     350        }
     351      }
     352      break;
     353    case KAPA_POINT_CROSS: /* cross */
     354      for (i = 0; i < object[0].Npts; i++) {
     355        if (!(finite(x[i]) && finite(y[i]))) continue;
     356        sx = x[i]*mxi + y[i]*mxj + bx;
     357        sy = x[i]*myi + y[i]*myj + by;
     358        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     359            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     360          if (scaleColor) {
     361            if (!finite(z[i])) continue;
     362            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     363            fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
     364          }
     365          D = scaleSize ? dz*z[i] : ds;
     366          DrawLine (sx - D, sy, sx + D, sy);
     367          DrawLine (sx, sy - D, sx, sy + D);
     368        }
     369      }
     370      break;
     371    case KAPA_POINT_X:  /* x */
     372      for (i = 0; i < object[0].Npts; i++) {
     373        if (!(finite(x[i]) && finite(y[i]))) continue;
     374        sx = x[i]*mxi + y[i]*mxj + bx;
     375        sy = x[i]*myi + y[i]*myj + by;
     376        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     377            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     378          if (scaleColor) {
     379            if (!finite(z[i])) continue;
     380            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     381            fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
     382          }
     383          D = scaleSize ? dz*z[i] : ds;
     384          DrawLine (sx + D, sy - D, sx - D, sy + D);
     385          DrawLine (sx - D, sy - D, sx + D, sy + D);
     386        }
     387      }
     388      break;
     389    case KAPA_POINT_TRIANGLE_SOLID:     /* filled triangle */
     390      for (i = 0; i < object[0].Npts; i++) {
     391        if (!(finite(x[i]) && finite(y[i]))) continue;
     392        sx = x[i]*mxi + y[i]*mxj + bx;
     393        sy = x[i]*myi + y[i]*myj + by;
     394        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     395            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     396          if (scaleColor) {
     397            if (!finite(z[i])) continue;
     398            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     399            fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
     400          }
     401          D = scaleSize ? dz*z[i] : ds;
     402          FillTriangle (sx - D, sy - 0.58*D, sx + D, sy - 0.58*D, sx, sy + 1.15*D);
     403        }
     404      }
     405      break;
     406    case KAPA_POINT_TRIANGLE_SOLID_DOWN:        /* open triangle */
     407      for (i = 0; i < object[0].Npts; i++) {
     408        if (!(finite(x[i]) && finite(y[i]))) continue;
     409        sx = x[i]*mxi + y[i]*mxj + bx;
     410        sy = x[i]*myi + y[i]*myj + by;
     411        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     412            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     413          if (scaleColor) {
     414            if (!finite(z[i])) continue;
     415            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     416            fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
     417          }
     418          D = scaleSize ? dz*z[i] : ds;
     419          FillTriangle (sx - D, sy + 0.58*D, sx + D, sy + 0.58*D, sx, sy - 1.15*D);
     420        }
     421      }
     422      break;
     423    case KAPA_POINT_TRIANGLE_OPEN:      /* open triangle */
     424      for (i = 0; i < object[0].Npts; i++) {
     425        if (!(finite(x[i]) && finite(y[i]))) continue;
     426        sx = x[i]*mxi + y[i]*mxj + bx;
     427        sy = x[i]*myi + y[i]*myj + by;
     428        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     429            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     430          if (scaleColor) {
     431            if (!finite(z[i])) continue;
     432            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     433            fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
     434          }
     435          D = scaleSize ? dz*z[i] : ds;
     436          DrawLine (sx - D, sy - 0.58*D, sx + D, sy - 0.58*D);
     437          DrawLine (sx + D, sy - 0.58*D, sx,     sy + 1.15*D);
     438          DrawLine (sx,     sy + 1.15*D, sx - D, sy - 0.58*D);
     439        }
     440      }
     441      break;
     442    case KAPA_POINT_TRIANGLE_OPEN_DOWN: /* upside-down open triangle */
     443      for (i = 0; i < object[0].Npts; i++) {
     444        if (!(finite(x[i]) && finite(y[i]))) continue;
     445        sx = x[i]*mxi + y[i]*mxj + bx;
     446        sy = x[i]*myi + y[i]*myj + by;
     447        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     448            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     449          if (scaleColor) {
     450            if (!finite(z[i])) continue;
     451            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     452            fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
     453          }
     454          D = scaleSize ? dz*z[i] : ds;
     455          DrawLine (sx - D, sy + 0.58*D, sx + D, sy + 0.58*D);
     456          DrawLine (sx + D, sy + 0.58*D, sx,     sy - 1.15*D);
     457          DrawLine (sx,     sy - 1.15*D, sx - D, sy + 0.58*D);
     458        }
     459      }
     460      break;
     461    case KAPA_POINT_Y:  /* Y */
     462      for (i = 0; i < object[0].Npts; i++) {
     463        if (!(finite(x[i]) && finite(y[i]))) continue;
     464        sx = x[i]*mxi + y[i]*mxj + bx;
     465        sy = x[i]*myi + y[i]*myj + by;
     466        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     467            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     468          if (scaleColor) {
     469            if (!finite(z[i])) continue;
     470            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     471            fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
     472          }
     473          D = scaleSize ? dz*z[i] : ds;
     474          DrawLine (sx, sy, sx - D, sy + 0.58*D);
     475          DrawLine (sx, sy, sx + D, sy + 0.58*D);
     476          DrawLine (sx, sy, sx,          sy - 1.15*D);
     477        }
     478      }
     479      break;
     480    case KAPA_POINT_Y_DOWN:     /* upside-down Y */
     481      for (i = 0; i < object[0].Npts; i++) {
     482        if (!(finite(x[i]) && finite(y[i]))) continue;
     483        sx = x[i]*mxi + y[i]*mxj + bx;
     484        sy = x[i]*myi + y[i]*myj + by;
     485        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     486            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     487          if (scaleColor) {
     488            if (!finite(z[i])) continue;
     489            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     490            fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
     491          }
     492          D = scaleSize ? dz*z[i] : ds;
     493          DrawLine (sx, sy, sx - D, sy - 0.58*D);
     494          DrawLine (sx, sy, sx + D, sy - 0.58*D);
     495          DrawLine (sx, sy, sx,     sy + 1.15*D);
     496        }
     497      }
     498      break;
     499    case KAPA_POINT_CIRCLE_OPEN: /* 0 */
     500      for (i = 0; i < object[0].Npts; i++) {
     501        if (!(finite(x[i]) && finite(y[i]))) continue;
     502        sx = x[i]*mxi + y[i]*mxj + bx;
     503        sy = x[i]*myi + y[i]*myj + by;
     504        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     505            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     506          if (scaleColor) {
     507            if (!finite(z[i])) continue;
     508            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     509            fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
     510          }
     511          D = scaleSize ? dz*z[i] : ds;
     512          DrawCircle (sx, sy, D);
     513        }
     514      }
     515      break;
     516    case KAPA_POINT_CIRCLE_SOLID: /* filled 0 */
     517      for (i = 0; i < object[0].Npts; i++) {
     518        if (!(finite(x[i]) && finite(y[i]))) continue;
     519        sx = x[i]*mxi + y[i]*mxj + bx;
     520        sy = x[i]*myi + y[i]*myj + by;
     521        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     522            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     523          if (scaleColor) {
     524            if (!finite(z[i])) continue;
     525            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     526            fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
     527          }
     528          D = scaleSize ? dz*z[i] : ds;
     529          FillCircle (sx, sy, D);
     530        }
     531      }
     532      break;
     533    case KAPA_POINT_PENTAGON:   /* pentagon */
     534      for (i = 0; i < object[0].Npts; i++) {
     535        if (!(finite(x[i]) && finite(y[i]))) continue;
     536        sx = x[i]*mxi + y[i]*mxj + bx;
     537        sy = x[i]*myi + y[i]*myj + by;
     538        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     539            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     540          if (scaleColor) {
     541            if (!finite(z[i])) continue;
     542            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     543            fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
     544          }
     545          D = scaleSize ? dz*z[i] : ds;
     546          DrawLine (sx + 0.00*D, sy + 1.00*D, sx + 0.95*D, sy + 0.31*D);
     547          DrawLine (sx + 0.95*D, sy + 0.31*D, sx + 0.58*D, sy - 0.81*D);
     548          DrawLine (sx + 0.58*D, sy - 0.81*D, sx - 0.58*D, sy - 0.81*D);
     549          DrawLine (sx - 0.58*D, sy - 0.81*D, sx - 0.95*D, sy + 0.31*D);
     550          DrawLine (sx - 0.95*D, sy + 0.31*D, sx + 0.00*D, sy + 1.00*D);
     551        }
     552      }
     553      break;
     554    case KAPA_POINT_HEXAGON:    /* hexagon */
     555      for (i = 0; i < object[0].Npts; i++) {
     556        if (!(finite(x[i]) && finite(y[i]))) continue;
     557        sx = x[i]*mxi + y[i]*mxj + bx;
     558        sy = x[i]*myi + y[i]*myj + by;
     559        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     560            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     561          if (scaleColor) {
     562            if (!finite(z[i])) continue;
     563            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     564            fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
     565          }
     566          D = scaleSize ? dz*z[i] : ds;
     567          DrawLine (sx -      D, sy,               sx - 0.50*D, sy + 0.87*D);
     568          DrawLine (sx - 0.50*D, sy + 0.87*D, sx + 0.50*D, sy + 0.87*D);
     569          DrawLine (sx + 0.50*D, sy + 0.87*D, sx +      D, sy);
     570
     571          DrawLine (sx +      D, sy,               sx + 0.50*D, sy - 0.87*D);
     572          DrawLine (sx + 0.50*D, sy - 0.87*D, sx - 0.50*D, sy - 0.87*D);
     573          DrawLine (sx - 0.50*D, sy - 0.87*D, sx -      D, sy);
     574        }
     575      }
     576      break;
     577    case KAPA_POINT_PAIR_CONNECT: { /* connect pairs of points */
     578      double X0 = graph[0].axis[0].fx;
     579      double X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx;
     580      double Y0 = graph[0].axis[1].fy;
     581      double Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy;
     582
     583      for (i = 0; i + 1 < object[0].Npts; i+=2) {
     584        if (!(finite(x[i]) && finite(y[i]))) continue;
     585        sx1 = x[i]*mxi + y[i]*mxj + bx;
     586        sy1 = x[i]*myi + y[i]*myj + by;
     587        sx2 = x[i+1]*mxi + y[i+1]*mxj + bx;
     588        sy2 = x[i+1]*myi + y[i+1]*myj + by;
     589        ClipLinePS (sx1, sy1, sx2, sy2, X0, Y0, X1, Y1, f);
     590      }
     591      break;
    332592    }
    333   }
    334   if (object[0].ptype == 1) {   /* open box */
    335     for (i = 0; i < object[0].Npts; i++) {
    336       if (!(finite(x[i]) && finite(y[i]))) continue;
    337       sx = x[i]*mxi + y[i]*mxj + bx;
    338       sy = x[i]*myi + y[i]*myj + by;
    339       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    340           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    341       {
    342         if (scaleColor) {
    343           if (!finite(z[i])) continue;
    344           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    345           fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
    346         }
    347         D = scaleSize ? dz*z[i] : ds;
    348         DrawRectangle (sx, sy, 2*D, 2*D);
    349       }
    350     }
    351   }
    352   if (object[0].ptype == 2) { /* cross */
    353     for (i = 0; i < object[0].Npts; i++) {
    354       if (!(finite(x[i]) && finite(y[i]))) continue;
    355       sx = x[i]*mxi + y[i]*mxj + bx;
    356       sy = x[i]*myi + y[i]*myj + by;
    357       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    358           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    359       {
    360         if (scaleColor) {
    361           if (!finite(z[i])) continue;
    362           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    363           fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
    364         }
    365         D = scaleSize ? dz*z[i] : ds;
    366         DrawLine (sx - D, sy, sx + D, sy);
    367         DrawLine (sx, sy - D, sx, sy + D);
    368       }
    369     }
    370   }
    371   if (object[0].ptype == 3) {   /* x */
    372     for (i = 0; i < object[0].Npts; i++) {
    373       if (!(finite(x[i]) && finite(y[i]))) continue;
    374       sx = x[i]*mxi + y[i]*mxj + bx;
    375       sy = x[i]*myi + y[i]*myj + by;
    376       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    377           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    378       {
    379         if (scaleColor) {
    380           if (!finite(z[i])) continue;
    381           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    382           fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
    383         }
    384         D = scaleSize ? dz*z[i] : ds;
    385         DrawLine (sx + D, sy - D, sx - D, sy + D);
    386         DrawLine (sx - D, sy - D, sx + D, sy + D);
    387       }
    388     }
    389   }
    390   if (object[0].ptype == 4) {   /* filled triangle */
    391     for (i = 0; i < object[0].Npts; i++) {
    392       if (!(finite(x[i]) && finite(y[i]))) continue;
    393       sx = x[i]*mxi + y[i]*mxj + bx;
    394       sy = x[i]*myi + y[i]*myj + by;
    395       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    396           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    397       {
    398         if (scaleColor) {
    399           if (!finite(z[i])) continue;
    400           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    401           fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
    402         }
    403         D = scaleSize ? dz*z[i] : ds;
    404         FillTriangle (sx - D, sy - 0.58*D, sx + D, sy - 0.58*D, sx, sy + 1.15*D);
    405       }
    406     }
    407   }
    408   if (object[0].ptype == 14) {  /* filled triangle */
    409     for (i = 0; i < object[0].Npts; i++) {
    410       if (!(finite(x[i]) && finite(y[i]))) continue;
    411       sx = x[i]*mxi + y[i]*mxj + bx;
    412       sy = x[i]*myi + y[i]*myj + by;
    413       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    414           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    415       {
    416         if (scaleColor) {
    417           if (!finite(z[i])) continue;
    418           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    419           fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
    420         }
    421         D = scaleSize ? dz*z[i] : ds;
    422         FillTriangle (sx - D, sy + 0.58*D, sx + D, sy + 0.58*D, sx, sy - 1.15*D);
    423       }
    424     }
    425   }
    426   if (object[0].ptype == 5) {   /* open triangle */
    427     for (i = 0; i < object[0].Npts; i++) {
    428       if (!(finite(x[i]) && finite(y[i]))) continue;
    429       sx = x[i]*mxi + y[i]*mxj + bx;
    430       sy = x[i]*myi + y[i]*myj + by;
    431       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    432           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    433       {
    434         if (scaleColor) {
    435           if (!finite(z[i])) continue;
    436           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    437           fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
    438         }
    439         D = scaleSize ? dz*z[i] : ds;
    440         DrawLine (sx - D, sy - 0.58*D, sx + D, sy - 0.58*D);
    441         DrawLine (sx + D, sy - 0.58*D, sx,     sy + 1.15*D);
    442         DrawLine (sx,     sy + 1.15*D, sx - D, sy - 0.58*D);
    443       }
    444     }
    445   }
    446   if (object[0].ptype == 15) {  /* upside-down open triangle */
    447     for (i = 0; i < object[0].Npts; i++) {
    448       if (!(finite(x[i]) && finite(y[i]))) continue;
    449       sx = x[i]*mxi + y[i]*mxj + bx;
    450       sy = x[i]*myi + y[i]*myj + by;
    451       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    452           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    453       {
    454         if (scaleColor) {
    455           if (!finite(z[i])) continue;
    456           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    457           fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
    458         }
    459         D = scaleSize ? dz*z[i] : ds;
    460         DrawLine (sx - D, sy + 0.58*D, sx + D, sy + 0.58*D);
    461         DrawLine (sx + D, sy + 0.58*D, sx,     sy - 1.15*D);
    462         DrawLine (sx,     sy - 1.15*D, sx - D, sy + 0.58*D);
    463       }
    464     }
    465   }
    466   if (object[0].ptype == 6) {   /* Y */
    467     for (i = 0; i < object[0].Npts; i++) {
    468       if (!(finite(x[i]) && finite(y[i]))) continue;
    469       sx = x[i]*mxi + y[i]*mxj + bx;
    470       sy = x[i]*myi + y[i]*myj + by;
    471       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    472           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    473       {
    474         if (scaleColor) {
    475           if (!finite(z[i])) continue;
    476           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    477           fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
    478         }
    479         D = scaleSize ? dz*z[i] : ds;
    480         DrawLine (sx, sy, sx - D, sy + 0.58*D);
    481         DrawLine (sx, sy, sx + D, sy + 0.58*D);
    482         DrawLine (sx, sy, sx,          sy - 1.15*D);
    483       }
    484     }
    485   }
    486   if (object[0].ptype == 16) {  /* Y */
    487     for (i = 0; i < object[0].Npts; i++) {
    488       if (!(finite(x[i]) && finite(y[i]))) continue;
    489       sx = x[i]*mxi + y[i]*mxj + bx;
    490       sy = x[i]*myi + y[i]*myj + by;
    491       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    492           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    493       {
    494         if (scaleColor) {
    495           if (!finite(z[i])) continue;
    496           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    497           fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
    498         }
    499         D = scaleSize ? dz*z[i] : ds;
    500         DrawLine (sx, sy, sx - D, sy - 0.58*D);
    501         DrawLine (sx, sy, sx + D, sy - 0.58*D);
    502         DrawLine (sx, sy, sx,     sy + 1.15*D);
    503       }
    504     }
    505   }
    506   if (object[0].ptype == 7) {   /* 0 */
    507     for (i = 0; i < object[0].Npts; i++) {
    508       if (!(finite(x[i]) && finite(y[i]))) continue;
    509       sx = x[i]*mxi + y[i]*mxj + bx;
    510       sy = x[i]*myi + y[i]*myj + by;
    511       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    512           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    513       {
    514         if (scaleColor) {
    515           if (!finite(z[i])) continue;
    516           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    517           fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
    518         }
    519         D = scaleSize ? dz*z[i] : ds;
    520         DrawCircle (sx, sy, D);
    521       }
    522     }
    523   }
    524   if (object[0].ptype == 8) {   /* pentagon */
    525     for (i = 0; i < object[0].Npts; i++) {
    526       if (!(finite(x[i]) && finite(y[i]))) continue;
    527       sx = x[i]*mxi + y[i]*mxj + bx;
    528       sy = x[i]*myi + y[i]*myj + by;
    529       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    530           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    531       {
    532         if (scaleColor) {
    533           if (!finite(z[i])) continue;
    534           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    535           fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
    536         }
    537         D = scaleSize ? dz*z[i] : ds;
    538         DrawLine (sx + 0.00*D, sy + 1.00*D, sx + 0.95*D, sy + 0.31*D);
    539         DrawLine (sx + 0.95*D, sy + 0.31*D, sx + 0.58*D, sy - 0.81*D);
    540         DrawLine (sx + 0.58*D, sy - 0.81*D, sx - 0.58*D, sy - 0.81*D);
    541         DrawLine (sx - 0.58*D, sy - 0.81*D, sx - 0.95*D, sy + 0.31*D);
    542         DrawLine (sx - 0.95*D, sy + 0.31*D, sx + 0.00*D, sy + 1.00*D);
    543       }
    544     }
    545   }
    546   if (object[0].ptype == 9) {   /* hexagon */
    547     for (i = 0; i < object[0].Npts; i++) {
    548       if (!(finite(x[i]) && finite(y[i]))) continue;
    549       sx = x[i]*mxi + y[i]*mxj + bx;
    550       sy = x[i]*myi + y[i]*myj + by;
    551       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    552           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    553       {
    554         if (scaleColor) {
    555           if (!finite(z[i])) continue;
    556           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    557           fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
    558         }
    559         D = scaleSize ? dz*z[i] : ds;
    560         DrawLine (sx -      D, sy,               sx - 0.50*D, sy + 0.87*D);
    561         DrawLine (sx - 0.50*D, sy + 0.87*D, sx + 0.50*D, sy + 0.87*D);
    562         DrawLine (sx + 0.50*D, sy + 0.87*D, sx +      D, sy);
    563 
    564         DrawLine (sx +      D, sy,               sx + 0.50*D, sy - 0.87*D);
    565         DrawLine (sx + 0.50*D, sy - 0.87*D, sx - 0.50*D, sy - 0.87*D);
    566         DrawLine (sx - 0.50*D, sy - 0.87*D, sx -      D, sy);
    567       }
    568     }
    569   }
    570   if (object[0].ptype == 10) {  /* 0 */
    571     for (i = 0; i < object[0].Npts; i++) {
    572       if (!(finite(x[i]) && finite(y[i]))) continue;
    573       sx = x[i]*mxi + y[i]*mxj + bx;
    574       sy = x[i]*myi + y[i]*myj + by;
    575       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    576           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    577       {
    578         if (scaleColor) {
    579           if (!finite(z[i])) continue;
    580           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    581           fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
    582         }
    583         D = scaleSize ? dz*z[i] : ds;
    584         FillCircle (sx, sy, D);
    585       }
    586     }
    587   }
    588   if (object[0].ptype == 100) { /* connect a pair of points */
    589     double X0 = graph[0].axis[0].fx;
    590     double X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx;
    591     double Y0 = graph[0].axis[1].fy;
    592     double Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy;
    593 
    594     for (i = 0; i + 1 < object[0].Npts; i+=2) {
    595       if (!(finite(x[i]) && finite(y[i]))) continue;
    596       sx1 = x[i]*mxi + y[i]*mxj + bx;
    597       sy1 = x[i]*myi + y[i]*myj + by;
    598       sx2 = x[i+1]*mxi + y[i+1]*mxj + bx;
    599       sy2 = x[i+1]*myi + y[i+1]*myj + by;
    600       ClipLinePS (sx1, sy1, sx2, sy2, X0, Y0, X1, Y1, f);
    601     }
    602   }
    603 
     593    case KAPA_POINT_BOX_SOLID:  /* filled box */
     594    default:
     595      for (i = 0; i < object[0].Npts; i++) {
     596        if (!(finite(x[i]) && finite(y[i]))) continue;
     597        sx = x[i]*mxi + y[i]*mxj + bx;
     598        sy = x[i]*myi + y[i]*myj + by;
     599        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     600            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     601          if (scaleColor) {
     602            if (!finite(z[i])) continue;
     603            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     604            fprintf (f, "%4.2f %4.2f %4.2f setrgbcolor\n", pixel1[pixel], pixel2[pixel], pixel3[pixel]);
     605          }
     606          D = scaleSize ? dz*z[i] : ds;
     607          FillRectangle (sx, sy, 2*D, 2*D);
     608        }
     609      }
     610      break;
     611  }
    604612  free (pixel1);
    605613  free (pixel2);
  • trunk/Ohana/src/kapa2/src/bDrawFrame.c

    r38986 r39926  
    1111
    1212  // don't need graphic, unlink DrawFrame
     13
     14  P = 0.5 * (1 + 0.25*graph[0].axis[0].lweight) * (hypot (graph[0].axis[0].dfx, graph[0].axis[0].dfy) + hypot (graph[0].axis[0].dfx, graph[0].axis[0].dfy));
    1315
    1416  /* each axis is drawn independently */
     
    2830    dfx = graph[0].axis[i].dfx + 2*dx;
    2931    dfy = graph[0].axis[i].dfy + 2*dy;
    30     P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
    31     P *= (1 + 0.25*lweight);
     32
     33    // P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
     34    // P *= (1 + 0.25*lweight);
    3235
    3336    bDrawSetStyle (buffer, color, lweight, 0);
  • trunk/Ohana/src/kapa2/src/bDrawObjects.c

    r38153 r39926  
    1818 
    1919  int i;
    20   int type;
    21   int weight;
    22   bDrawColor color;
    23   bDrawColor black;
    24  
     20 
     21  // the functions below use this global value
    2522  graphic = GetGraphic();
    2623
    27   black = KapaColorByName ("black");
     24  // this function calls all of the supporting bDraw... functions below
    2825  for (i = 0; i < graph[0].Nobjects; i++) {
    29 
    30     weight = MAX (0, MIN (10, graph[0].objects[i].lweight));
    31     type = graph[0].objects[i].ltype;   
    32     color = graph[0].objects[i].color;
    33     bDrawSetStyle (buffer, color, weight, type);
    34 
    35     switch (graph[0].objects[i].style) {
    36       case CONNECT:
    37         bDrawConnect (buffer, graph, &graph[0].objects[i]);
    38         break;
    39       case HISTOGRAM:
    40         bDrawHistogram (buffer, graph, &graph[0].objects[i]);
    41         break;
    42       case POINTS:
    43         bDrawPoints (buffer, graph, &graph[0].objects[i]);
    44         break;
    45     }
    46 
    47     if (graph[0].objects[i].etype & 0x01) {
    48       bDrawYErrors (buffer, graph, &graph[0].objects[i]);
    49     }
    50     if (graph[0].objects[i].etype & 0x02) {
    51       bDrawXErrors (buffer, graph, &graph[0].objects[i]);
    52     }
    53   }
     26    bDrawObjectsN (buffer, graph, &graph[0].objects[i]);
     27  }
     28  bDrawColor black = KapaColorByName ("black");
    5429  bDrawSetStyle (buffer, black, 0, 0);
     30  return (TRUE);
     31}
     32
     33int bDrawObjectsN (bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object) {
     34 
     35  int weight = MAX (0, MIN (10, object->lweight));
     36  bDrawSetStyle (buffer, object->color, weight, object->ltype);
     37 
     38  switch (object->style) {
     39    case KAPA_PLOT_CONNECT:
     40      bDrawConnect (buffer, graph, object);
     41      break;
     42    case KAPA_PLOT_HISTOGRAM:
     43      bDrawHistogram (buffer, graph, object);
     44      break;
     45    case KAPA_PLOT_POINTS:
     46    default:
     47      bDrawPoints (buffer, graph, object);
     48      break;
     49  }
     50
     51  if (object->etype & 0x01) {
     52    bDrawYErrors (buffer, graph, object);
     53  }
     54  if (object->etype & 0x02) {
     55    bDrawXErrors (buffer, graph, object);
     56  }
     57
    5558  return (TRUE);
    5659}
     
    298301  x = object[0].x; y = object[0].y; z = object[0].z;
    299302
    300   if (object[0].ptype == 0) {   /* filled box */
    301     for (i = 0; i < object[0].Npts; i++) {
    302       if (!(finite(x[i]) && finite(y[i]))) continue;
    303       sx = x[i]*mxi + y[i]*mxj + bx;
    304       sy = x[i]*myi + y[i]*myj + by;
    305       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    306           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    307       {
    308         if (scaleColor) {
    309           if (!finite(z[i])) continue;
    310           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    311           buffer->bColor_R = pixel1[pixel];
    312           buffer->bColor_G = pixel2[pixel];
    313           buffer->bColor_B = pixel3[pixel];
    314         }
    315         D = scaleSize ? dz*z[i] : ds;
    316         FillRectangle (buffer, sx, sy, 2*D, 2*D);
    317         // plot range saturated by bDrawRectFill
    318       }
     303  switch (object[0].ptype) {
     304    case KAPA_POINT_BOX_OPEN:   /* open box */
     305      for (i = 0; i < object[0].Npts; i++) {
     306        if (!(finite(x[i]) && finite(y[i]))) continue;
     307        sx = x[i]*mxi + y[i]*mxj + bx;
     308        sy = x[i]*myi + y[i]*myj + by;
     309        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     310            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     311          if (scaleColor) {
     312            if (!finite(z[i])) continue;
     313            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     314            buffer->bColor_R = pixel1[pixel];
     315            buffer->bColor_G = pixel2[pixel];
     316            buffer->bColor_B = pixel3[pixel];
     317          }
     318          D = scaleSize ? dz*z[i] : ds;
     319          DrawRectangle (buffer, sx, sy, 2*D, 2*D);
     320          // plot range saturated by bDrawRectOpen
     321        }
     322      }
     323      break;
     324    case KAPA_POINT_CROSS: /* cross */
     325      for (i = 0; i < object[0].Npts; i++) {
     326        if (!(finite(x[i]) && finite(y[i]))) continue;
     327        sx = x[i]*mxi + y[i]*mxj + bx;
     328        sy = x[i]*myi + y[i]*myj + by;
     329        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     330            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     331          if (scaleColor) {
     332            if (!finite(z[i])) continue;
     333            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     334            buffer->bColor_R = pixel1[pixel];
     335            buffer->bColor_G = pixel2[pixel];
     336            buffer->bColor_B = pixel3[pixel];
     337          }
     338          D = scaleSize ? dz*z[i] : ds;
     339          DrawLine (buffer, sx - D, sy, sx + D, sy);
     340          DrawLine (buffer, sx, sy - D, sx, sy + D);
     341          // out-of-range points skipped by bDrawPoint
     342        }
     343      }
     344      break;
     345    case KAPA_POINT_X:  /* x */
     346      for (i = 0; i < object[0].Npts; i++) {
     347        if (!(finite(x[i]) && finite(y[i]))) continue;
     348        sx = x[i]*mxi + y[i]*mxj + bx;
     349        sy = x[i]*myi + y[i]*myj + by;
     350        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     351            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     352          if (scaleColor) {
     353            if (!finite(z[i])) continue;
     354            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     355            buffer->bColor_R = pixel1[pixel];
     356            buffer->bColor_G = pixel2[pixel];
     357            buffer->bColor_B = pixel3[pixel];
     358          }
     359          D = scaleSize ? dz*z[i] : ds;
     360          DrawLine (buffer, sx + D, sy - D, sx - D, sy + D);
     361          DrawLine (buffer, sx - D, sy - D, sx + D, sy + D);
     362          // out-of-range points skipped by bDrawPoint
     363        }
     364      }
     365      break;
     366    case KAPA_POINT_TRIANGLE_SOLID:     /* filled triangle */
     367      for (i = 0; i < object[0].Npts; i++) {
     368        if (!(finite(x[i]) && finite(y[i]))) continue;
     369        sx = x[i]*mxi + y[i]*mxj + bx;
     370        sy = x[i]*myi + y[i]*myj + by;
     371        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     372            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     373          if (scaleColor) {
     374            if (!finite(z[i])) continue;
     375            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     376            buffer->bColor_R = pixel1[pixel];
     377            buffer->bColor_G = pixel2[pixel];
     378            buffer->bColor_B = pixel3[pixel];
     379          }
     380          D = scaleSize ? dz*z[i] : ds;
     381          // FillTriangle (buffer, sx - D, sy - 0.58*D, sx + D, sy - 0.58*D, sx, sy + 1.15*D);
     382          FillTriangle (buffer, sx, sy + 0.58*D, D, -1.73*D);
     383          // out-of-range points skipped by bDrawPoint
     384        }
     385      }
     386      break;
     387    case KAPA_POINT_TRIANGLE_SOLID_DOWN:        /* open triangle */
     388      for (i = 0; i < object[0].Npts; i++) {
     389        if (!(finite(x[i]) && finite(y[i]))) continue;
     390        sx = x[i]*mxi + y[i]*mxj + bx;
     391        sy = x[i]*myi + y[i]*myj + by;
     392        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     393            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     394          if (scaleColor) {
     395            if (!finite(z[i])) continue;
     396            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     397            buffer->bColor_R = pixel1[pixel];
     398            buffer->bColor_G = pixel2[pixel];
     399            buffer->bColor_B = pixel3[pixel];
     400          }
     401          D = scaleSize ? dz*z[i] : ds;
     402          // FillTriangle (buffer, sx - D, sy - 0.58*D, sx + D, sy - 0.58*D, sx, sy + 1.15*D);
     403          FillTriangle (buffer, sx, sy - 0.58*D, D, +1.73*D);
     404          // out-of-range points skipped by bDrawPoint
     405        }
     406      }
     407      break;
     408    case KAPA_POINT_TRIANGLE_OPEN:      /* open triangle */
     409      for (i = 0; i < object[0].Npts; i++) {
     410        if (!(finite(x[i]) && finite(y[i]))) continue;
     411        sx = x[i]*mxi + y[i]*mxj + bx;
     412        sy = x[i]*myi + y[i]*myj + by;
     413        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     414            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     415          if (scaleColor) {
     416            if (!finite(z[i])) continue;
     417            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     418            buffer->bColor_R = pixel1[pixel];
     419            buffer->bColor_G = pixel2[pixel];
     420            buffer->bColor_B = pixel3[pixel];
     421          }
     422          D = scaleSize ? dz*z[i] : ds;
     423          OpenTriangle (buffer, sx - D, sy + 0.58*D, sx + D, sy + 0.58*D, sx, sy - 1.15*D);
     424          // out-of-range points skipped by bDrawPoint
     425        }
     426      }
     427      break;
     428    case KAPA_POINT_TRIANGLE_OPEN_DOWN: /* upside-down open triangle */
     429      for (i = 0; i < object[0].Npts; i++) {
     430        if (!(finite(x[i]) && finite(y[i]))) continue;
     431        sx = x[i]*mxi + y[i]*mxj + bx;
     432        sy = x[i]*myi + y[i]*myj + by;
     433        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     434            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     435          if (scaleColor) {
     436            if (!finite(z[i])) continue;
     437            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     438            buffer->bColor_R = pixel1[pixel];
     439            buffer->bColor_G = pixel2[pixel];
     440            buffer->bColor_B = pixel3[pixel];
     441          }
     442          D = scaleSize ? dz*z[i] : ds;
     443          OpenTriangle (buffer, sx - D, sy - 0.58*D, sx + D, sy - 0.58*D, sx, sy + 1.15*D);
     444          // out-of-range points skipped by bDrawPoint
     445        }
     446      }
     447      break;
     448    case KAPA_POINT_Y:  /* Y */
     449      for (i = 0; i < object[0].Npts; i++) {
     450        if (!(finite(x[i]) && finite(y[i]))) continue;
     451        sx = x[i]*mxi + y[i]*mxj + bx;
     452        sy = x[i]*myi + y[i]*myj + by;
     453        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     454            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     455          if (scaleColor) {
     456            if (!finite(z[i])) continue;
     457            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     458            buffer->bColor_R = pixel1[pixel];
     459            buffer->bColor_G = pixel2[pixel];
     460            buffer->bColor_B = pixel3[pixel];
     461          }
     462          D = scaleSize ? dz*z[i] : ds;
     463          DrawLine (buffer, sx, sy, sx - D, sy - 0.58*D);
     464          DrawLine (buffer, sx, sy, sx + D, sy - 0.58*D);
     465          DrawLine (buffer, sx, sy, sx,     sy + 1.15*D);
     466          // out-of-range points skipped by bDrawPoint
     467        }
     468      }
     469      break;
     470    case KAPA_POINT_Y_DOWN:     /* upside-down Y */
     471      for (i = 0; i < object[0].Npts; i++) {
     472        if (!(finite(x[i]) && finite(y[i]))) continue;
     473        sx = x[i]*mxi + y[i]*mxj + bx;
     474        sy = x[i]*myi + y[i]*myj + by;
     475        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     476            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     477          if (scaleColor) {
     478            if (!finite(z[i])) continue;
     479            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     480            buffer->bColor_R = pixel1[pixel];
     481            buffer->bColor_G = pixel2[pixel];
     482            buffer->bColor_B = pixel3[pixel];
     483          }
     484          D = scaleSize ? dz*z[i] : ds;
     485          DrawLine (buffer, sx, sy, sx - D, sy + 0.58*D);
     486          DrawLine (buffer, sx, sy, sx + D, sy + 0.58*D);
     487          DrawLine (buffer, sx, sy, sx,     sy - 1.15*D);
     488          // out-of-range points skipped by bDrawPoint
     489        }
     490      }
     491      break;
     492    case KAPA_POINT_CIRCLE_OPEN: /* 0 */
     493      for (i = 0; i < object[0].Npts; i++) {
     494        if (!(finite(x[i]) && finite(y[i]))) continue;
     495        sx = x[i]*mxi + y[i]*mxj + bx;
     496        sy = x[i]*myi + y[i]*myj + by;
     497        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     498            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     499          if (scaleColor) {
     500            if (!finite(z[i])) continue;
     501            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     502            buffer->bColor_R = pixel1[pixel];
     503            buffer->bColor_G = pixel2[pixel];
     504            buffer->bColor_B = pixel3[pixel];
     505          }
     506          D = scaleSize ? dz*z[i] : ds;
     507          DrawCircle (buffer, sx, sy, D);
     508          // out-of-range points skipped by bDrawPoint
     509        }
     510      }
     511      break;
     512    case KAPA_POINT_CIRCLE_SOLID: /* filled 0 */
     513      for (i = 0; i < object[0].Npts; i++) {
     514        if (!(finite(x[i]) && finite(y[i]))) continue;
     515        sx = x[i]*mxi + y[i]*mxj + bx;
     516        sy = x[i]*myi + y[i]*myj + by;
     517        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     518            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     519          if (scaleColor) {
     520            if (!finite(z[i])) continue;
     521            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     522            buffer->bColor_R = pixel1[pixel];
     523            buffer->bColor_G = pixel2[pixel];
     524            buffer->bColor_B = pixel3[pixel];
     525          }
     526          D = scaleSize ? dz*z[i] : ds;
     527          FillCircle (buffer, sx, sy, D);
     528          // out-of-range points skipped by bDrawLineHorizontal
     529        }
     530      }
     531      break;
     532    case KAPA_POINT_PENTAGON:   /* pentagon */
     533      for (i = 0; i < object[0].Npts; i++) {
     534        if (!(finite(x[i]) && finite(y[i]))) continue;
     535        sx = x[i]*mxi + y[i]*mxj + bx;
     536        sy = x[i]*myi + y[i]*myj + by;
     537        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     538            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     539          if (scaleColor) {
     540            if (!finite(z[i])) continue;
     541            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     542            buffer->bColor_R = pixel1[pixel];
     543            buffer->bColor_G = pixel2[pixel];
     544            buffer->bColor_B = pixel3[pixel];
     545          }
     546          D = scaleSize ? dz*z[i] : ds;
     547          DrawLine (buffer, sx + 0.00*D, sy - 1.00*D, sx + 0.95*D, sy - 0.31*D);
     548          DrawLine (buffer, sx + 0.95*D, sy - 0.31*D, sx + 0.58*D, sy + 0.81*D);
     549          DrawLine (buffer, sx + 0.58*D, sy + 0.81*D, sx - 0.58*D, sy + 0.81*D);
     550          DrawLine (buffer, sx - 0.58*D, sy + 0.81*D, sx - 0.95*D, sy - 0.31*D);
     551          DrawLine (buffer, sx - 0.95*D, sy - 0.31*D, sx + 0.00*D, sy - 1.00*D);
     552          // out-of-range points skipped by bDrawPoint
     553        }
     554      }
     555      break;
     556    case KAPA_POINT_HEXAGON:    /* hexagon */
     557      for (i = 0; i < object[0].Npts; i++) {
     558        if (!(finite(x[i]) && finite(y[i]))) continue;
     559        sx = x[i]*mxi + y[i]*mxj + bx;
     560        sy = x[i]*myi + y[i]*myj + by;
     561        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     562            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     563          if (scaleColor) {
     564            if (!finite(z[i])) continue;
     565            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     566            buffer->bColor_R = pixel1[pixel];
     567            buffer->bColor_G = pixel2[pixel];
     568            buffer->bColor_B = pixel3[pixel];
     569          }
     570          D = scaleSize ? dz*z[i] : ds;
     571          DrawLine (buffer, sx -      D, sy,          sx - 0.50*D, sy + 0.87*D);
     572          DrawLine (buffer, sx - 0.50*D, sy + 0.87*D, sx + 0.50*D, sy + 0.87*D);
     573          DrawLine (buffer, sx + 0.50*D, sy + 0.87*D, sx +      D, sy);
     574          DrawLine (buffer, sx +      D, sy,          sx + 0.50*D, sy - 0.87*D);
     575          DrawLine (buffer, sx + 0.50*D, sy - 0.87*D, sx - 0.50*D, sy - 0.87*D);
     576          DrawLine (buffer, sx - 0.50*D, sy - 0.87*D, sx -      D, sy);
     577          // out-of-range points skipped by bDrawPoint
     578        }
     579      }
     580      break;
     581    case KAPA_POINT_PAIR_CONNECT: { /* connect pairs of points */
     582
     583      double X0 = graph[0].axis[0].fx;
     584      double X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx;
     585      double Y0 = graph[0].axis[1].fy;
     586      double Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy;
     587
     588      for (i = 0; i + 1 < object[0].Npts; i+=2) {
     589        if (!(finite(x[i]) && finite(y[i]))) continue;
     590        sx1 = x[i]*mxi + y[i]*mxj + bx;
     591        sy1 = x[i]*myi + y[i]*myj + by;
     592        sx2 = x[i+1]*mxi + y[i+1]*mxj + bx;
     593        sy2 = x[i+1]*myi + y[i+1]*myj + by;
     594        bDrawClipLine (buffer, sx1, sy1, sx2, sy2, X0, Y0, X1, Y1);
     595      }
     596      break;
    319597    }
    320   }
    321   if (object[0].ptype == 1) {   /* open box */
    322     for (i = 0; i < object[0].Npts; i++) {
    323       if (!(finite(x[i]) && finite(y[i]))) continue;
    324       sx = x[i]*mxi + y[i]*mxj + bx;
    325       sy = x[i]*myi + y[i]*myj + by;
    326       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    327           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    328       {
    329         if (scaleColor) {
    330           if (!finite(z[i])) continue;
    331           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    332           buffer->bColor_R = pixel1[pixel];
    333           buffer->bColor_G = pixel2[pixel];
    334           buffer->bColor_B = pixel3[pixel];
    335         }
    336         D = scaleSize ? dz*z[i] : ds;
    337         DrawRectangle (buffer, sx, sy, 2*D, 2*D);
    338         // plot range saturated by bDrawRectOpen
    339       }
    340     }
    341   }
    342   if (object[0].ptype == 2) { /* cross */
    343     for (i = 0; i < object[0].Npts; i++) {
    344       if (!(finite(x[i]) && finite(y[i]))) continue;
    345       sx = x[i]*mxi + y[i]*mxj + bx;
    346       sy = x[i]*myi + y[i]*myj + by;
    347       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    348           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    349       {
    350         if (scaleColor) {
    351           if (!finite(z[i])) continue;
    352           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    353           buffer->bColor_R = pixel1[pixel];
    354           buffer->bColor_G = pixel2[pixel];
    355           buffer->bColor_B = pixel3[pixel];
    356         }
    357         D = scaleSize ? dz*z[i] : ds;
    358         DrawLine (buffer, sx - D, sy, sx + D, sy);
    359         DrawLine (buffer, sx, sy - D, sx, sy + D);
    360         // out-of-range points skipped by bDrawPoint
    361       }
    362     }
    363   }
    364   if (object[0].ptype == 3) {   /* x */
    365     for (i = 0; i < object[0].Npts; i++) {
    366       if (!(finite(x[i]) && finite(y[i]))) continue;
    367       sx = x[i]*mxi + y[i]*mxj + bx;
    368       sy = x[i]*myi + y[i]*myj + by;
    369       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    370           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    371       {
    372         if (scaleColor) {
    373           if (!finite(z[i])) continue;
    374           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    375           buffer->bColor_R = pixel1[pixel];
    376           buffer->bColor_G = pixel2[pixel];
    377           buffer->bColor_B = pixel3[pixel];
    378         }
    379         D = scaleSize ? dz*z[i] : ds;
    380         DrawLine (buffer, sx + D, sy - D, sx - D, sy + D);
    381         DrawLine (buffer, sx - D, sy - D, sx + D, sy + D);
    382         // out-of-range points skipped by bDrawPoint
    383       }
    384     }
    385   }
    386   if (object[0].ptype == 4) {   /* filled triangle */
    387     for (i = 0; i < object[0].Npts; i++) {
    388       if (!(finite(x[i]) && finite(y[i]))) continue;
    389       sx = x[i]*mxi + y[i]*mxj + bx;
    390       sy = x[i]*myi + y[i]*myj + by;
    391       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    392           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    393       {
    394         if (scaleColor) {
    395           if (!finite(z[i])) continue;
    396           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    397           buffer->bColor_R = pixel1[pixel];
    398           buffer->bColor_G = pixel2[pixel];
    399           buffer->bColor_B = pixel3[pixel];
    400         }
    401         D = scaleSize ? dz*z[i] : ds;
    402         // FillTriangle (buffer, sx - D, sy - 0.58*D, sx + D, sy - 0.58*D, sx, sy + 1.15*D);
    403         FillTriangle (buffer, sx, sy + 0.58*D, D, -1.73*D);
    404         // out-of-range points skipped by bDrawPoint
    405       }
    406     }
    407   }
    408   if (object[0].ptype == 14) {  /* filled triangle */
    409     for (i = 0; i < object[0].Npts; i++) {
    410       if (!(finite(x[i]) && finite(y[i]))) continue;
    411       sx = x[i]*mxi + y[i]*mxj + bx;
    412       sy = x[i]*myi + y[i]*myj + by;
    413       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    414           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    415       {
    416         if (scaleColor) {
    417           if (!finite(z[i])) continue;
    418           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    419           buffer->bColor_R = pixel1[pixel];
    420           buffer->bColor_G = pixel2[pixel];
    421           buffer->bColor_B = pixel3[pixel];
    422         }
    423         D = scaleSize ? dz*z[i] : ds;
    424         // FillTriangle (buffer, sx - D, sy - 0.58*D, sx + D, sy - 0.58*D, sx, sy + 1.15*D);
    425         FillTriangle (buffer, sx, sy - 0.58*D, D, +1.73*D);
    426         // out-of-range points skipped by bDrawPoint
    427       }
    428     }
    429   }
    430   if (object[0].ptype == 5) {   /* open triangle */
    431     for (i = 0; i < object[0].Npts; i++) {
    432       if (!(finite(x[i]) && finite(y[i]))) continue;
    433       sx = x[i]*mxi + y[i]*mxj + bx;
    434       sy = x[i]*myi + y[i]*myj + by;
    435       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    436           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    437       {
    438         if (scaleColor) {
    439           if (!finite(z[i])) continue;
    440           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    441           buffer->bColor_R = pixel1[pixel];
    442           buffer->bColor_G = pixel2[pixel];
    443           buffer->bColor_B = pixel3[pixel];
    444         }
    445         D = scaleSize ? dz*z[i] : ds;
    446         OpenTriangle (buffer, sx - D, sy + 0.58*D, sx + D, sy + 0.58*D, sx, sy - 1.15*D);
    447         // out-of-range points skipped by bDrawPoint
    448       }
    449     }
    450   }
    451   if (object[0].ptype == 15) {  /* open triangle */
    452     for (i = 0; i < object[0].Npts; i++) {
    453       if (!(finite(x[i]) && finite(y[i]))) continue;
    454       sx = x[i]*mxi + y[i]*mxj + bx;
    455       sy = x[i]*myi + y[i]*myj + by;
    456       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    457           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    458       {
    459         if (scaleColor) {
    460           if (!finite(z[i])) continue;
    461           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    462           buffer->bColor_R = pixel1[pixel];
    463           buffer->bColor_G = pixel2[pixel];
    464           buffer->bColor_B = pixel3[pixel];
    465         }
    466         D = scaleSize ? dz*z[i] : ds;
    467         OpenTriangle (buffer, sx - D, sy - 0.58*D, sx + D, sy - 0.58*D, sx, sy + 1.15*D);
    468         // out-of-range points skipped by bDrawPoint
    469       }
    470     }
    471   }
    472   if (object[0].ptype == 6) {   /* Y */
    473     for (i = 0; i < object[0].Npts; i++) {
    474       if (!(finite(x[i]) && finite(y[i]))) continue;
    475       sx = x[i]*mxi + y[i]*mxj + bx;
    476       sy = x[i]*myi + y[i]*myj + by;
    477       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    478           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    479       {
    480         if (scaleColor) {
    481           if (!finite(z[i])) continue;
    482           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    483           buffer->bColor_R = pixel1[pixel];
    484           buffer->bColor_G = pixel2[pixel];
    485           buffer->bColor_B = pixel3[pixel];
    486         }
    487         D = scaleSize ? dz*z[i] : ds;
    488         DrawLine (buffer, sx, sy, sx - D, sy - 0.58*D);
    489         DrawLine (buffer, sx, sy, sx + D, sy - 0.58*D);
    490         DrawLine (buffer, sx, sy, sx,     sy + 1.15*D);
    491         // out-of-range points skipped by bDrawPoint
    492       }
    493     }
    494   }
    495   if (object[0].ptype == 16) {  /* Y */
    496     for (i = 0; i < object[0].Npts; i++) {
    497       if (!(finite(x[i]) && finite(y[i]))) continue;
    498       sx = x[i]*mxi + y[i]*mxj + bx;
    499       sy = x[i]*myi + y[i]*myj + by;
    500       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    501           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    502       {
    503         if (scaleColor) {
    504           if (!finite(z[i])) continue;
    505           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    506           buffer->bColor_R = pixel1[pixel];
    507           buffer->bColor_G = pixel2[pixel];
    508           buffer->bColor_B = pixel3[pixel];
    509         }
    510         D = scaleSize ? dz*z[i] : ds;
    511         DrawLine (buffer, sx, sy, sx - D, sy + 0.58*D);
    512         DrawLine (buffer, sx, sy, sx + D, sy + 0.58*D);
    513         DrawLine (buffer, sx, sy, sx,     sy - 1.15*D);
    514         // out-of-range points skipped by bDrawPoint
    515       }
    516     }
    517   }
    518   if (object[0].ptype == 7) {   /* 0 */
    519     for (i = 0; i < object[0].Npts; i++) {
    520       if (!(finite(x[i]) && finite(y[i]))) continue;
    521       sx = x[i]*mxi + y[i]*mxj + bx;
    522       sy = x[i]*myi + y[i]*myj + by;
    523       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    524           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    525       {
    526         if (scaleColor) {
    527           if (!finite(z[i])) continue;
    528           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    529           buffer->bColor_R = pixel1[pixel];
    530           buffer->bColor_G = pixel2[pixel];
    531           buffer->bColor_B = pixel3[pixel];
    532         }
    533         D = scaleSize ? dz*z[i] : ds;
    534         DrawCircle (buffer, sx, sy, D);
    535         // out-of-range points skipped by bDrawPoint
    536       }
    537     }
    538   }
    539   if (object[0].ptype == 8) {   /* pentagon */
    540     for (i = 0; i < object[0].Npts; i++) {
    541       if (!(finite(x[i]) && finite(y[i]))) continue;
    542       sx = x[i]*mxi + y[i]*mxj + bx;
    543       sy = x[i]*myi + y[i]*myj + by;
    544       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    545           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    546       {
    547         if (scaleColor) {
    548           if (!finite(z[i])) continue;
    549           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    550           buffer->bColor_R = pixel1[pixel];
    551           buffer->bColor_G = pixel2[pixel];
    552           buffer->bColor_B = pixel3[pixel];
    553         }
    554         D = scaleSize ? dz*z[i] : ds;
    555         DrawLine (buffer, sx + 0.00*D, sy - 1.00*D, sx + 0.95*D, sy - 0.31*D);
    556         DrawLine (buffer, sx + 0.95*D, sy - 0.31*D, sx + 0.58*D, sy + 0.81*D);
    557         DrawLine (buffer, sx + 0.58*D, sy + 0.81*D, sx - 0.58*D, sy + 0.81*D);
    558         DrawLine (buffer, sx - 0.58*D, sy + 0.81*D, sx - 0.95*D, sy - 0.31*D);
    559         DrawLine (buffer, sx - 0.95*D, sy - 0.31*D, sx + 0.00*D, sy - 1.00*D);
    560         // out-of-range points skipped by bDrawPoint
    561       }
    562     }
    563   }
    564   if (object[0].ptype == 9) {   /* hexagon */
    565     for (i = 0; i < object[0].Npts; i++) {
    566       if (!(finite(x[i]) && finite(y[i]))) continue;
    567       sx = x[i]*mxi + y[i]*mxj + bx;
    568       sy = x[i]*myi + y[i]*myj + by;
    569       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    570           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    571       {
    572         if (scaleColor) {
    573           if (!finite(z[i])) continue;
    574           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    575           buffer->bColor_R = pixel1[pixel];
    576           buffer->bColor_G = pixel2[pixel];
    577           buffer->bColor_B = pixel3[pixel];
    578         }
    579         D = scaleSize ? dz*z[i] : ds;
    580         DrawLine (buffer, sx -      D, sy,          sx - 0.50*D, sy + 0.87*D);
    581         DrawLine (buffer, sx - 0.50*D, sy + 0.87*D, sx + 0.50*D, sy + 0.87*D);
    582         DrawLine (buffer, sx + 0.50*D, sy + 0.87*D, sx +      D, sy);
    583         DrawLine (buffer, sx +      D, sy,          sx + 0.50*D, sy - 0.87*D);
    584         DrawLine (buffer, sx + 0.50*D, sy - 0.87*D, sx - 0.50*D, sy - 0.87*D);
    585         DrawLine (buffer, sx - 0.50*D, sy - 0.87*D, sx -      D, sy);
    586         // out-of-range points skipped by bDrawPoint
    587       }
    588     }
    589   }
    590   if (object[0].ptype == 10) {  /* filled circle */
    591     for (i = 0; i < object[0].Npts; i++) {
    592       if (!(finite(x[i]) && finite(y[i]))) continue;
    593       sx = x[i]*mxi + y[i]*mxj + bx;
    594       sy = x[i]*myi + y[i]*myj + by;
    595       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    596           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    597       {
    598         if (scaleColor) {
    599           if (!finite(z[i])) continue;
    600           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    601           buffer->bColor_R = pixel1[pixel];
    602           buffer->bColor_G = pixel2[pixel];
    603           buffer->bColor_B = pixel3[pixel];
    604         }
    605         D = scaleSize ? dz*z[i] : ds;
    606         FillCircle (buffer, sx, sy, D);
    607         // out-of-range points skipped by bDrawLineHorizontal
    608       }
    609     }
    610   }
    611   if (object[0].ptype == 12) {  /* filled triangle (down) */
    612     for (i = 0; i < object[0].Npts; i++) {
    613       if (!(finite(x[i]) && finite(y[i]))) continue;
    614       sx = x[i]*mxi + y[i]*mxj + bx;
    615       sy = x[i]*myi + y[i]*myj + by;
    616       if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
    617           (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy))
    618       {
    619         if (scaleColor) {
    620           if (!finite(z[i])) continue;
    621           int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
    622           buffer->bColor_R = pixel1[pixel];
    623           buffer->bColor_G = pixel2[pixel];
    624           buffer->bColor_B = pixel3[pixel];
    625         }
    626         D = scaleSize ? dz*z[i] : ds;
    627         // FillTriangle (buffer, sx - D, sy - 0.58*D, sx + D, sy - 0.58*D, sx, sy + 1.15*D);
    628         FillTriangle (buffer, sx, sy + 0.58*D, D, 1.73*D);
    629         // out-of-range points skipped by bDrawPoint
    630       }
    631     }
    632   }
    633   if (object[0].ptype == 100) { /* connect a pair of points */
    634 
    635     double X0 = graph[0].axis[0].fx;
    636     double X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx;
    637     double Y0 = graph[0].axis[1].fy;
    638     double Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy;
    639 
    640     for (i = 0; i + 1 < object[0].Npts; i+=2) {
    641       if (!(finite(x[i]) && finite(y[i]))) continue;
    642       sx1 = x[i]*mxi + y[i]*mxj + bx;
    643       sy1 = x[i]*myi + y[i]*myj + by;
    644       sx2 = x[i+1]*mxi + y[i+1]*mxj + bx;
    645       sy2 = x[i+1]*myi + y[i+1]*myj + by;
    646       bDrawClipLine (buffer, sx1, sy1, sx2, sy2, X0, Y0, X1, Y1);
    647     }
    648   }
    649 
     598    case KAPA_POINT_BOX_SOLID:  /* filled box */
     599      for (i = 0; i < object[0].Npts; i++) {
     600        if (!(finite(x[i]) && finite(y[i]))) continue;
     601        sx = x[i]*mxi + y[i]*mxj + bx;
     602        sy = x[i]*myi + y[i]*myj + by;
     603        if ((sx > graph[0].axis[0].fx) && (sx < graph[0].axis[0].fx + graph[0].axis[0].dfx) &&
     604            (sy < graph[0].axis[1].fy) && (sy > graph[0].axis[1].fy + graph[0].axis[1].dfy)) {
     605          if (scaleColor) {
     606            if (!finite(z[i])) continue;
     607            int pixel = MIN (graphic->Npixels - 2, MAX (0, z[i]*(graphic->Npixels - 1)));
     608            buffer->bColor_R = pixel1[pixel];
     609            buffer->bColor_G = pixel2[pixel];
     610            buffer->bColor_B = pixel3[pixel];
     611          }
     612          D = scaleSize ? dz*z[i] : ds;
     613          FillRectangle (buffer, sx, sy, 2*D, 2*D);
     614          // plot range saturated by bDrawRectFill
     615        }
     616      }
     617      break;
     618  }
    650619  free (pixel1);
    651620  free (pixel2);
  • trunk/Ohana/src/libdvo/include/dvo.h

    r39670 r39926  
    114114/* Measure.flags values -- these values are 32 bit (as of PS1_V1) */
    115115typedef enum {
    116   ID_MEAS_NOCAL          = 0x00000001,  // detection ignored for this analysis (photcode, time range) -- internal only
    117   ID_MEAS_POOR_PHOTOM    = 0x00000002,  // detection is photometry outlier                                               
    118   ID_MEAS_SKIP_PHOTOM    = 0x00000004,  // detection was ignored for photometry measurement                               
    119   ID_MEAS_AREA           = 0x00000008,  // detection near image edge                                                 
    120   ID_MEAS_POOR_ASTROM    = 0x00000010,  // detection is astrometry outlier                                               
    121   ID_MEAS_SKIP_ASTROM    = 0x00000020,  // detection was ignored for astrometry measurement                               
    122   ID_MEAS_USED_OBJ       = 0x00000040,  // detection was used during update objects 
    123   ID_MEAS_USED_CHIP      = 0x00000080,  // detection was used during update chips (XXX this probably does not make it into the db)
    124   ID_MEAS_BLEND_MEAS     = 0x00000100,  // detection is within radius of multiple objects
    125   ID_MEAS_BLEND_OBJ      = 0x00000200,  // multiple detections within radius of object
    126   ID_MEAS_WARP_USED      = 0x00000400,  // measurement used to find mean warp photometry
    127   ID_MEAS_UNMASKED_ASTRO = 0x00000800,  // measurement was not masked in final astrometry fit
    128   ID_MEAS_BLEND_MEAS_X   = 0x00001000,  // detection is within radius of multiple objects across catalogs                   
    129   ID_MEAS_ARTIFACT       = 0x00002000,  // detection is thought to be non-astronomical                               
    130   ID_MEAS_SYNTH_MAG      = 0x00004000,  // magnitude is synthetic
    131   ID_MEAS_PHOTOM_UBERCAL = 0x00008000,  // externally-supplied zero point from ubercal analysis
    132   ID_MEAS_STACK_PRIMARY  = 0x00010000,  // this stack measurement is in the primary skycell
    133   ID_MEAS_STACK_PHOT_SRC = 0x00020000,  // this measurement supplied the stack photometry
    134   ID_MEAS_ICRF_QSO       = 0x00040000,  // this measurement is an ICRF reference position
    135   ID_MEAS_IMAGE_EPOCH    = 0x00080000,  // this measurement is registered to the image epoch (not tied to ref catalog epoch)
    136   ID_MEAS_PHOTOM_PSF     = 0x00100000,  // this measurement is used for the mean psf mag
    137   ID_MEAS_PHOTOM_APER    = 0x00200000,  // this measurement is used for the mean ap mag
    138   ID_MEAS_PHOTOM_KRON    = 0x00400000,  // this measurement is used for the mean kron mag
    139   ID_MEAS_MASKED_PSF     = 0x01000000,  // this measurement is masked based on IRLS weights for mean psf mag
    140   ID_MEAS_MASKED_APER    = 0x02000000,  // this measurement is masked based on IRLS weights for mean ap mag
    141   ID_MEAS_MASKED_KRON    = 0x04000000,  // this measurement is masked based on IRLS weights for mean kron mag
     116  ID_MEAS_NOCAL            = 0x00000001,  // detection ignored for this analysis (photcode, time range) -- internal only
     117  ID_MEAS_POOR_PHOTOM      = 0x00000002,  // detection is photometry outlier                                             
     118  ID_MEAS_SKIP_PHOTOM      = 0x00000004,  // detection was ignored for photometry measurement                             
     119  ID_MEAS_AREA             = 0x00000008,  // detection near image edge                                               
     120  ID_MEAS_POOR_ASTROM      = 0x00000010,  // detection is astrometry outlier                                             
     121  ID_MEAS_SKIP_ASTROM      = 0x00000020,  // detection was ignored for astrometry measurement                             
     122  ID_MEAS_USED_OBJ         = 0x00000040,  // detection was used during update objects 
     123  ID_MEAS_USED_CHIP        = 0x00000080,  // detection was used during update chips (XXX this probably does not make it into the db)
     124  ID_MEAS_BLEND_MEAS       = 0x00000100,  // detection is within radius of multiple objects
     125  ID_MEAS_BLEND_OBJ        = 0x00000200,  // multiple detections within radius of object
     126  ID_MEAS_WARP_USED        = 0x00000400,  // measurement used to find mean warp photometry
     127  ID_MEAS_UNMASKED_ASTRO   = 0x00000800,  // measurement was not masked in final astrometry fit
     128  ID_MEAS_BLEND_MEAS_X     = 0x00001000,  // detection is within radius of multiple objects across catalogs                 
     129  ID_MEAS_ARTIFACT         = 0x00002000,  // detection is thought to be non-astronomical                                     
     130  ID_MEAS_SYNTH_MAG        = 0x00004000,  // magnitude is synthetic
     131  ID_MEAS_PHOTOM_UBERCAL   = 0x00008000,  // externally-supplied zero point from ubercal analysis
     132  ID_MEAS_STACK_PRIMARY    = 0x00010000,  // this stack measurement is in the primary skycell
     133  ID_MEAS_STACK_PHOT_SRC   = 0x00020000,  // this measurement supplied the stack photometry
     134  ID_MEAS_ICRF_QSO         = 0x00040000,  // this measurement is an ICRF reference position
     135  ID_MEAS_IMAGE_EPOCH      = 0x00080000,  // this measurement is registered to the image epoch (not tied to ref catalog epoch)
     136  ID_MEAS_PHOTOM_PSF       = 0x00100000,  // this measurement is used for the mean psf mag
     137  ID_MEAS_PHOTOM_APER      = 0x00200000,  // this measurement is used for the mean ap mag
     138  ID_MEAS_PHOTOM_KRON      = 0x00400000,  // this measurement is used for the mean kron mag
     139  ID_MEAS_MASKED_PSF       = 0x01000000,  // this measurement is masked based on IRLS weights for mean psf mag
     140  ID_MEAS_MASKED_APER      = 0x02000000,  // this measurement is masked based on IRLS weights for mean ap mag
     141  ID_MEAS_MASKED_KRON      = 0x04000000,  // this measurement is masked based on IRLS weights for mean kron mag
     142  ID_MEAS_OBJECT_HAS_2MASS = 0x10000000,  // measurement comes from an object with 2mass data
     143  ID_MEAS_OBJECT_HAS_GAIA  = 0x20000000,  // measurement comes from an object with gaia data
     144  ID_MEAS_OBJECT_HAS_TYCHO = 0x40000000,  // measurement comes from an object with tycho data
    142145} DVOMeasureFlags;
    143146
     
    233236  ID_SECF_STACK_BESTDET = 0x00008000, // PS1 stack best measurement is a detection (not forced)
    234237  ID_SECF_STACK_PRIMDET = 0x00010000, // PS1 stack primary measurement is a detection (not forced)
     238
     239  ID_SECF_HAS_SDSS      = 0x00100000, // this photcode has SDSS photometry
     240  ID_SECF_HAS_HSC       = 0x00200000, // this photcode has HSC  photometry
     241  ID_SECF_HAS_CFH       = 0x00400000, // this photcode has CFH  photometry (mostly Megacam)
     242  ID_SECF_HAS_DES       = 0x00800000, // this photcode has DES  photometry
     243
    235244  ID_SECF_OBJ_EXT       = 0x01000000, // extended in this band
    236245
  • trunk/Ohana/src/libdvo/src/ImageMetadataSelection.c

    r37807 r39926  
    5959}
    6060
     61// note that this function is called by the dvo clients and uses the 'metadata' table
     62// generated by the dvo shell for the mosaic images only.
    6163Coords *MatchMosaicMetadata (unsigned int imageID) {
    6264
     
    7375  mosaic.crval2 = image[m].crval2;
    7476
     77  // note that image->theta is calculated based on pc1_1, pc1_2 when the metadata file is
     78  // generated
    7579  mosaic.pc1_1 =  cos(RAD_DEG*image[m].theta);
    7680  mosaic.pc1_2 =  sin(RAD_DEG*image[m].theta);
  • trunk/Ohana/src/libdvo/src/coordops.c

    r39608 r39926  
    8484
    8585  /** extra polynomial terms **/
     86  // for ZPN, these are used to modify the radial distance and not the X,Y coords
    8687  if ((coords[0].Npolyterms > 1) && (proj != PROJ_ZPN)) {
    8788    X2 = X*X;
     
    126127    if (proj == PROJ_WRP) {
    127128      if (!coords->mosaic) {
    128         myAbort ("missing mosaic element");
     129        // myAbort ("missing mosaic element");
     130        *ra  = L;
     131        *dec = M;
    129132        return (FALSE);
    130133      }
     
    157160          ctht = 0.0;
    158161        } else {
    159           T = DEG_RAD / R;
    160           stht =   T / sqrt ( 1.0 + T*T);
    161           ctht = 1.0 / sqrt ( 1.0 + T*T);
     162          // T = DEG_RAD / R; // T in 1/radians
     163          // stht =   T / sqrt ( 1.0 + T*T);
     164          // ctht = 1.0 / sqrt ( 1.0 + T*T);
     165
     166          T = RAD_DEG * R;
     167          stht = 1.0 / sqrt ( 1.0 + T*T);
     168          ctht =   T / sqrt ( 1.0 + T*T);
    162169        }
     170        break;
     171      case PROJ_SIN:
     172        // R = (180/pi) cos (theta)
     173        ctht = RAD_DEG * R;
     174        stht = sqrt (1 - ctht*ctht);
    163175        break;
    164176      case PROJ_STG:
     
    167179        ctht = sqrt (1 - stht*stht);
    168180        break;
    169       case PROJ_SIN:
    170         // R = (180/pi) cos (theta)
    171         ctht = RAD_DEG * R;
    172         stht = sqrt (1 - ctht*ctht);
    173         break;
    174181      case PROJ_ARC:
    175182        // R = 90 - theta (degrees)
     
    177184        stht = cos (RAD_DEG * R);
    178185        break;
    179 
    180       case PROJ_ZPN:
    181         // R = 90 - theta (degrees)
    182         // this is wrong because we are ignoring the distortion
    183         // XXX For now, just solve for terms up to n = 3
    184 
    185         // Ro = (pi/180)(90 - theta)
    186         // R = (180/pi)sum (P_i R^i)
    187 
    188         if (UKIRT_ONLY) {
    189           double Ro = RAD_DEG * R;
    190           double P1 = coords[0].polyterms[0][1];
    191           double P3 = coords[0].polyterms[0][3];
    192 
    193           // find the roots of f(gamma) = P1 gamma + P3 gamma^3 - Ro
    194           // starting guess for gamma is Ro / P1
    195           double gamma = Ro / P1;
    196 
    197           int i;
    198           for (i = 0; i < 5; i++) {
    199             double F = P1*gamma + P3*gamma*gamma*gamma - Ro;
    200             double dFdgamma = P1 + 3.0*P3*gamma*gamma;
    201 
    202             double gamma_new = gamma - F / dFdgamma;
    203             gamma = gamma_new;
    204           }
    205          
    206           double theta = 90.0 - gamma * DEG_RAD ;
    207           ctht = cos (RAD_DEG * theta);
    208           stht = sin (RAD_DEG * theta);
    209           break;
    210         }
    211186
    212187      case PROJ_ZEA:
     
    220195        ctht = sqrt (1 - stht*stht);
    221196        break;
     197
     198      case PROJ_ZPN:
     199
     200        // the forward projection is:
     201        // theta = atan2(stht, ctht)
     202        // gamma = (pi/2 - theta) : theta in radians
     203        // Ro = sum (P_i gamma^i)
     204        // R  = (180/pi) Ro
     205
     206        // given R, we need to find theta:
     207        // Ro = R * (pi / 180) = sum (P_i gamma^i)
     208        // solve sum (P_i gamma^i) - Ro = 0 using Newton-Raphson
     209
     210        // use Ro to get a guess for gamma and iterate
     211
     212        {
     213          double Ro = RAD_DEG * R;
     214         
     215          // find the roots of f(gamma) - Ro = 0
     216          // starting guess for gamma is (Ro - P0) / P1
     217          double gamma = (Ro - coords[0].polyterms[0][0]) / coords[0].polyterms[1][0];
     218         
     219          int iter;
     220          for (iter = 0; iter < 5; iter++) {
     221           
     222            double Rc = 0.0; // this will hold the ander
     223            double dR = 0.0;
     224            for (int i = coords[0].Npolyterms - 1; i > 1; i--) {
     225              double Pi = (i < 7) ? coords[0].polyterms[i][0] : coords[0].polyterms[i-7][1];
     226              Rc = (Rc + Pi)*gamma;
     227              dR = (dR + i*Pi)*gamma;
     228            }
     229            double P0 = coords[0].polyterms[0][0];
     230            double P1 = coords[0].polyterms[1][0];
     231            Rc = (Rc + P1)*gamma + P0;
     232            dR = (dR + P1);
     233
     234            double gamma_new = gamma - (Rc - Ro) / dR;
     235            gamma = gamma_new;
     236          }
     237         
     238          double theta = 90.0 - gamma * DEG_RAD ;
     239          ctht = cos (RAD_DEG * theta);
     240          stht = sin (RAD_DEG * theta);
     241          break;
     242        }
     243
    222244      default:
    223245        return (FALSE);
     
    354376
    355377      case PROJ_ZPN:
     378        // the forward projection is:
     379        // theta = atan2(stht, ctht)
     380        // gamma = (pi/2 - theta) : theta in radians
     381        // Ro = sum (P_i gamma^i)
     382        // R  = (180/pi) Ro
     383
    356384        // Ro = (pi/180)(90 - theta)
    357385        // R = (180/pi)sum (P_i R^i)
     386
     387        // is ZPN defined for Npolyterms = 0 or 1?
     388
    358389        ctht = hypot(sphi, cphi);
    359390        theta = atan2 (stht, ctht);
    360391
    361         double Rc;
    362         if (UKIRT_ONLY) {
    363           double P1 = coords[0].polyterms[0][1];
    364           double P3 = coords[0].polyterms[0][3];
    365           double gamma = RAD_DEG * (90 - DEG_RAD * theta);
    366           Rc = P1*gamma + P3*gamma*gamma*gamma;
    367         } else {
    368           double Ro = RAD_DEG * (90 - DEG_RAD * theta);
    369 
    370           // i = 0 .. Npolyterms - 1 (1 <= Npolyterms <= 21)
    371           i = coords[0].Npolyterms - 1;
    372           Rc = 0.0;
    373           while (i > 0) {
    374             if (i < 7) {
    375               Rc = (Rc + coords[0].polyterms[0][i])*Ro;
    376             } else {
    377               Rc = (Rc + coords[0].polyterms[1][i-7])*Ro;
    378             }
    379             i --;
    380           }
    381           Rc += coords[0].polyterms[0][i];
     392        double Ro;
     393        double gamma = M_PI_2 - theta;
     394
     395        // i = 0 .. Npolyterms - 1 (1 <= Npolyterms <= 21)
     396        Ro = 0.0;
     397        for (i = coords[0].Npolyterms - 1; i > 0; i --) {
     398          double Pi = (i < 7) ? coords[0].polyterms[i][0] : coords[0].polyterms[i-7][1];
     399          Ro = (Ro + Pi)*gamma;
    382400        }
    383         Rc = DEG_RAD * Rc;
     401        Ro += coords[0].polyterms[0][0];
     402
     403        Rc = DEG_RAD * Ro;
    384404
    385405        *L = (ctht == 0.0) ? 0.0 : +Rc * sphi / ctht ;
     
    609629enum {COORD_TYPE_NONE, COORD_TYPE_PC, COORD_TYPE_ROT, COORD_TYPE_CD, COORD_TYPE_LIN};
    610630
     631int GetRadialZPN (Coords *coords, Header *header);
     632
    611633int GetCoords (Coords *coords, Header *header) {
    612634 
    613   int i, status, status1, status2, itmp, Polynomial, Polyterm;
     635  int status, status1, status2, itmp, Polynomial, Polyterm;
    614636  double Lambda, rotate, rotate1, rotate2, scale;
    615637  double equinox;
     
    666688      status &= gfits_scan (header, "PC002002", "%f",  1, &coords[0].pc2_2);
    667689
     690      ctype = &coords[0].ctype[4];
     691
     692      // read the ZPN coeffients PV2_i (i = 0 < 14)
     693      // ZPN is inconsistent with the other Polynomial types
     694      if (!strcmp (ctype, "-ZPN")) {
     695        GetRadialZPN (coords, header);
     696        break;
     697      }
     698
    668699      /* set NPLYTERM based on header.  if NPLYTERM is missing, it should have a
    669700         value of 0, unless the projection type is one of PLY, DIS, WRP, in which
    670701         case it should be set to 3 */
    671       ctype = &coords[0].ctype[4];
    672702      Polynomial = !strcmp (ctype, "-PLY") || !strcmp (ctype, "-DIS") || !strcmp (ctype, "-WRP");
    673703      Polyterm = gfits_scan (header, "NPLYTERM", "%d", 1, &itmp);
     
    723753      coords[0].pc2_1 =  sin(rotate*RAD_DEG) / Lambda;
    724754      coords[0].pc2_2 =  cos(rotate*RAD_DEG);
     755
     756      // read the ZPN coeffients PV2_i (i = 0 < 14)
     757      if (!strcmp (&coords[0].ctype[4], "-ZPN")) GetRadialZPN (coords, header);
    725758      break;
    726759
     
    744777      coords[0].pc2_2 /= scale;
    745778
    746       if (!strcmp (&coords[0].ctype[4], "-ZPN")) {
    747         int found;
    748         for (i = 0; i < 14; i++) {
    749           char name[64];
    750           snprintf (name, 64, "PV2_%d", i);
    751           if (i < 7) {
    752             found = gfits_scan (header, name, "%f", 1, &coords[0].polyterms[0][i]);
    753           } else {
    754             found = gfits_scan (header, name, "%f", 1, &coords[0].polyterms[1][i-7]);
    755           }
    756           if ((i == 0) && !found) {
    757             coords[0].polyterms[0][0] = 0.0;
    758             continue;
    759           }
    760           if ((i == 1) && !found) {
    761             coords[0].polyterms[0][1] = 1.0;
    762             continue;
    763           }
    764           if (!found) {
    765             coords[0].Npolyterms = i;
    766             break;
    767           }
    768         }
    769       }
     779      // read the ZPN coeffients PV2_i (i = 0 < 14)
     780      if (!strcmp (&coords[0].ctype[4], "-ZPN")) GetRadialZPN (coords, header);
    770781      break;
    771782
     
    819830  }
    820831  return (status);
     832}
     833
     834int GetRadialZPN (Coords *coords, Header *header) {
     835
     836  // RA---ZPN can have up to 14 radial polynomial terms.  these are stored in
     837  // polyterms[0][0] - [6][0] for the first 7 and [0][1] - [6][1] for the rest
     838  // these terms are coeffients of a polynomial of the radial distances
     839
     840  // read the ZPN coeffients PV2_i (i = 0 < 14)
     841  int found;
     842  int Nmax = 0;
     843  for (int i = 0; i < 14; i++) {
     844    char name[64];
     845    snprintf (name, 64, "PV2_%d", i);
     846    if (i < 7) {
     847      coords[0].polyterms[i][0] = 0.0;
     848      found = gfits_scan (header, name, "%f", 1, &coords[0].polyterms[i][0]);
     849    } else {
     850      coords[0].polyterms[i-7][1] = 0.0;
     851      found = gfits_scan (header, name, "%f", 1, &coords[0].polyterms[i-7][1]);
     852    }
     853    // PV2_1 is implicit if not present
     854    if ((i == 1) && !found) {
     855      coords[0].polyterms[1][0] = 1.0;
     856      continue;
     857    }
     858    // set Npolyterms based on the largest coefficient found
     859    if (found) {
     860      Nmax = i;
     861    }
     862  }
     863  coords[0].Npolyterms = Nmax + 1;
     864  return TRUE;
    821865}
    822866
  • trunk/Ohana/src/libdvo/src/dbExtractMeasures.c

    r39670 r39926  
    427427      break;
    428428    case MEAS_TMEAN: /* OK */
     429      value.Flt = TimeValue (average[0].Tmean, TimeReference, TimeFormat);
     430      break;
     431    case MEAS_TRANGE: /* OK */
    429432      value.Flt = GetTimeRange (average[0].Trange, TimeFormat);
    430       break;
    431     case MEAS_TRANGE: /* OK */
    432       value.Flt = TimeValue (average[0].Trange, 0, TimeFormat);
    433433      break;
    434434    case MEAS_NMEAS: /* OK */
     
    461461      break;
    462462    case MEAS_RA_FIT_OFFSET: /* OK */
     463      // RA_epoch_fit = RA_mean + uR*(t - Tmean)/cos(dec) + plx*parR
     464      // note that this extraction ignores parallax
    463465      dT = (measure[0].t - average[0].Tmean) / (86400*365.25);
    464       dR = dvoOffsetR (measure, average);
    465       value.Flt = average[0].uR * dT + dR;
     466      dR = dvoOffsetR (measure, average); // RA_epoch - RA_mean (** NOT local linear distance **)
     467      value.Flt = dR*cos(RAD_DEG*measure[0].D) - average[0].uR * dT;
     468      // this is the local linear distance of the measurement from the fit
    466469      break;
    467470    case MEAS_DEC_FIT_OFFSET: /* OK */
    468471      dT = (measure[0].t - average[0].Tmean) / (86400*365.25);
    469472      dD = dvoOffsetD (measure, average);
    470       value.Flt = average[0].uD * dT + dD;
     473      value.Flt = dD - average[0].uD * dT;
    471474      break;
    472475    case MEAS_RA_OFFSET_ERR: /* OK */
  • trunk/Ohana/src/libdvo/src/galaxy_model.c

    r39588 r39926  
    2828    V_sol  =  11.18; // km/sec
    2929    W_sol  =   7.61; // km/sec
     30    return TRUE;
     31  }
     32  if (!strcmp(version, "TEST-CONSTANT")) {
     33    // use for testing
     34    A_oort = +47.40; // km/sec/kpc
     35    B_oort = -47.40; // km/sec/kpc
     36    U_sol  =   0.00; // km/sec
     37    V_sol  =   0.00; // km/sec
     38    W_sol  =   0.00; // km/sec
     39    return TRUE;
     40  }
     41  if (!strcmp(version, "TEST-ZERO")) {
     42    // use for testing
     43    A_oort =   0.00; // km/sec/kpc
     44    B_oort =   0.00; // km/sec/kpc
     45    U_sol  =   0.00; // km/sec
     46    V_sol  =   0.00; // km/sec
     47    W_sol  =   0.00; // km/sec
    3048    return TRUE;
    3149  }
  • trunk/Ohana/src/libfits/header/F_H_field.c

    r38986 r39926  
    9090      ptr = buf + 9; // start of following keyword
    9191      if (strncmp (field, ptr, Nfield)) continue;
     92      if (ptr[Nfield + 1] != '=') continue; // the strncmp above will match a longer string which matches the subset of field (e.g., FOO will match FOOBAR and FOO).  test for the following '=' sign
    9293      Nfound ++;
    9394      if (Nfound == N) return (ptr);
  • trunk/Ohana/src/libkapa/Makefile

    r39590 r39926  
    3434$(SRC)/KapaWindow.$(ARCH).o \
    3535$(SRC)/KapaColors.$(ARCH).o \
     36$(SRC)/KapaStyles.$(ARCH).o \
    3637$(SRC)/KapaOpen.$(ARCH).o
    3738
  • trunk/Ohana/src/libkapa/include/kapa.h

    r38986 r39926  
    2525typedef struct sockaddr_in KapaSockAddress;
    2626
    27 typedef struct {
    28   float *data1d;
    29   float **data2d;
    30   int Nx;
    31   int Ny;
    32 } KiiImage;
    33 
    34 typedef struct {
    35   float x;
    36   float y;
    37   float dx;
    38   float dy;
    39   float angle;
    40   int type;
    41 } KiiOverlayBase;
    42 
    43 typedef struct {
    44   float x;
    45   float y;
    46   float dx;
    47   float dy;
    48   float angle;
    49   int type;
    50   char *text;
    51 } KiiOverlay;
     27// retain historical numerical definitions:
     28typedef enum {
     29  KAPA_LINE_INVALID_MIN = -1,
     30  KAPA_LINE_SOLID       = 0,
     31  KAPA_LINE_DOT         = 1,
     32  KAPA_LINE_DASH_SHORT  = 2,
     33  KAPA_LINE_DASH_LONG   = 3,
     34  KAPA_LINE_DOT_DASH    = 4,
     35  KAPA_LINE_INVALID_MAX = 5,
     36} KapaLineType;
     37
     38// retain historical numerical definitions:
     39typedef enum {
     40  KAPA_PLOT_INVALID_MIN = -1,
     41  KAPA_PLOT_CONNECT     =  0,
     42  KAPA_PLOT_HISTOGRAM   =  1,
     43  KAPA_PLOT_POINTS      =  2,
     44  KAPA_PLOT_INVALID_MAX =  3,
     45} KapaPlotStyle;
     46
     47typedef enum {
     48  KAPA_POINT_INVALID_MIN         = -1,
     49  KAPA_POINT_BOX_SOLID           =  0,
     50  KAPA_POINT_BOX_OPEN            =  1,
     51  KAPA_POINT_CROSS               =  2, // OR PLUS
     52  KAPA_POINT_X                   =  3,
     53  KAPA_POINT_Y                   =  4,
     54  KAPA_POINT_TRIANGLE_SOLID      =  5,
     55  KAPA_POINT_TRIANGLE_OPEN       =  6,
     56  KAPA_POINT_CIRCLE_OPEN         =  7,
     57  KAPA_POINT_PENTAGON            =  8,
     58  KAPA_POINT_HEXAGON             =  9,
     59  KAPA_POINT_CIRCLE_SOLID        = 10,
     60  KAPA_POINT_TRIANGLE_SOLID_DOWN = 11,
     61  KAPA_POINT_TRIANGLE_OPEN_DOWN  = 12,
     62  KAPA_POINT_Y_DOWN              = 13,
     63  KAPA_POINT_INVALID_MAX         = 14,
     64  KAPA_POINT_PAIR_CONNECT        = 100, // change to a plot style?
     65} KapaPointStyle;
     66// note that PAIR_CONNECT was historically 100
     67
    5268
    5369typedef enum {
     
    7591  KAPA_PS_RAWPAGE
    7692} KapaPSmode;
     93
     94typedef struct {
     95  float *data1d;
     96  float **data2d;
     97  int Nx;
     98  int Ny;
     99} KiiImage;
     100
     101typedef struct {
     102  float x;
     103  float y;
     104  float dx;
     105  float dy;
     106  float angle;
     107  int type;
     108} KiiOverlayBase;
     109
     110typedef struct {
     111  float x;
     112  float y;
     113  float dx;
     114  float dy;
     115  float angle;
     116  int type;
     117  char *text;
     118} KiiOverlay;
    77119
    78120typedef struct {
     
    219261unsigned long *KapaX11colors (Display *display, Colormap colormap, unsigned long default_color, int *Ncolors);
    220262
     263/* KapaStyles.c */
     264KapaLineType KapaLineTypeFromString (char *string);
     265KapaPlotStyle KapaPlotStyleFromString (char *string);
     266KapaPointStyle KapaPointStyleFromString (char *string);
     267
    221268/* RotFont.c */
    222269void InitRotFonts PROTO((void));
  • trunk/Ohana/src/libkapa/src/KapaOpen.c

    r39457 r39926  
    66# define MY_PORT 2500
    77# define MY_PORT_MAX 2520
    8 # define MY_WAIT 100000
     8# define MY_WAIT 1000000
    99# define DEBUG 0
    1010
  • trunk/Ohana/src/libkapa/src/KapaWindow.c

    r39652 r39926  
    449449  return (TRUE);
    450450}
     451
  • trunk/Ohana/src/libkapa/src/bDrawFuncs.c

    r36488 r39926  
    222222  e = 0;
    223223  for (X = X1, N = 0; X <= X2; X++, N++) {
    224     if (buffer->bType == 1) { DashOn = (N % 10) < 5; }
    225     if (buffer->bType == 2) { DashOn = (N % 6) < 3; }
     224    if (buffer->bType == KAPA_LINE_DOT) {
     225      DashOn = (N % 5) == 0 || (N % 5) == 1;
     226    }
     227    if (buffer->bType == KAPA_LINE_DASH_SHORT) {
     228      DashOn = (N % 8) < 4;
     229    }
     230    if (buffer->bType == KAPA_LINE_DASH_LONG) {
     231      DashOn = (N % 16) < 8;
     232    }
     233    if (buffer->bType == KAPA_LINE_DOT_DASH) {
     234      DashOn = ((N % 12) < 2) || ((N % 12 >= 6) && (N % 12 < 10)) ;
     235    }
    226236    if (swapcoords) {
    227237      if (DashOn) bDrawPoint (buffer, Y,X);
  • trunk/Ohana/src/opihi/cmd.astro/csystem.c

    r39591 r39926  
    125125  opihi_flt *yptr = yvec[0].elements.Flt;
    126126
    127   opihi_flt *uxptr = uxvec ? xvec[0].elements.Flt : NULL;
    128   opihi_flt *uyptr = uyvec ? yvec[0].elements.Flt : NULL;
     127  opihi_flt *uxptr = uxvec ? uxvec[0].elements.Flt : NULL;
     128  opihi_flt *uyptr = uyvec ? uyvec[0].elements.Flt : NULL;
    129129
    130130  for (i = 0; i < xvec[0].Nelements; i++, xptr++, yptr++) {
  • trunk/Ohana/src/opihi/cmd.astro/fitplx_irls.c

    r39610 r39926  
    158158    // now that the mask has been updated, we need to recalculate mean epoch and positions
    159159    // XXX make this conditional on actually masking unmasked points above
    160     PlxSetMeanEpoch (R, D, T, &Rmean, &Dmean, &Tmean, mask, Ntotal);
    161     PlxSetEpochPosition (&fitdata, R, D, dR, dD, T, mask, Ntotal, &coords, Tmean);
     160    // PlxSetMeanEpoch (R, D, T, &Rmean, &Dmean, &Tmean, mask, Ntotal);
     161    // PlxSetEpochPosition (&fitdata, R, D, dR, dD, T, mask, Ntotal, &coords, Tmean);
    162162
    163163    PlxFitData sample;
     
    218218  // fprintf (stderr, "%f +/- %f | %f %f\n", fit.p, fit.dp, fit.uR, fit.uD);
    219219
    220 /*
    221   FILE *f = fopen ("test.pf.dat", "w");
     220  Vector *dRresPMP, *dDresPMP, *dRresPLX, *dDresPLX;
     221
     222  // save fit residuals (with only pm removed, and pm and plx removed)
     223  if ((dRresPMP = SelectVector ("dRresPMP", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dRresPMP");
     224  if ((dDresPMP = SelectVector ("dDresPMP", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dDresPMP");
     225  if ((dRresPLX = SelectVector ("dRresPLX", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dRresPLX");
     226  if ((dDresPLX = SelectVector ("dDresPLX", ANYVECTOR, TRUE)) == NULL) ESCAPE ("cannot generate vector %s\n", "dDresPLX");
     227   
     228  ResetVector (dRresPMP, OPIHI_FLT, Ntotal);
     229  ResetVector (dDresPMP, OPIHI_FLT, Ntotal);
     230  ResetVector (dRresPLX, OPIHI_FLT, Ntotal);
     231  ResetVector (dDresPLX, OPIHI_FLT, Ntotal);
     232 
    222233  for (i = 0; i < Ntotal; i++) {
    223     double Xf = fit.Ro + fit.uR*fitdata.t[i] + fit.p*fitdata.pX[i];
    224     double Yf = fit.Do + fit.uD*fitdata.t[i] + fit.p*fitdata.pY[i];
    225     fprintf (f, "%f : %f %f : %f %f : %f : %f %f : %f %f\n", T[i], R[i], D[i], Xf, Yf, fitdata.t[i], fitdata.X[i], fitdata.Y[i], fitdata.pX[i], fitdata.pY[i]);
    226   }
    227   fclose (f);
    228 */
     234   
     235    double x0, y0;
     236    RD_to_XY (&x0, &y0, R[i], D[i], &coords);
     237
     238    double pX0, pY0;
     239    ParFactor (&pX0, &pY0, R[i], D[i], T[i]);
     240
     241    double t0 = (T[i] - Tmean)/365.25;
     242
     243    double Xpmp = fit.Ro + fit.uR*t0 + fit.p*pX0;
     244    double Ypmp = fit.Do + fit.uD*t0 + fit.p*pY0;
     245    double Xplx = fit.Ro + fit.uR*t0;
     246    double Yplx = fit.Do + fit.uD*t0;
     247
     248    dRresPMP->elements.Flt[i] = x0 - Xpmp;
     249    dDresPMP->elements.Flt[i] = y0 - Ypmp;
     250    dRresPLX->elements.Flt[i] = x0 - Xplx;
     251    dDresPLX->elements.Flt[i] = y0 - Yplx;
     252  }
    229253
    230254  // fprintf (stderr, "Roff, Doff: %f, %f; dRo, dDo: %f, %f\n", fit.Ro, fit.Do, fit.dRo, fit.dDo);
  • trunk/Ohana/src/opihi/cmd.astro/spex1dgas.c

    r33662 r39926  
    108108  IDList = NULL;
    109109  XoList = NULL;
    110   {
    111     // init random numbers
    112     long A, B;
    113     A = time(NULL);
    114     for (B = 0; A == time(NULL); B++);
    115     srand48(B);
    116   }
    117110 
     111  // srand48() is called by startup.c
     112
    118113  if (argc != 11) goto usage;
    119114
  • trunk/Ohana/src/opihi/cmd.astro/spex2dgas.c

    r33662 r39926  
    120120  float XoMax, YoMax;
    121121
    122   {
    123     // init random numbers
    124     long A, B;
    125     A = time(NULL);
    126     for (B = 0; A == time(NULL); B++);
    127     srand48(B);
    128   }
    129  
     122  // srand48() is called by startup.c
     123
    130124  if (argc != 9) goto usage;
    131125
  • trunk/Ohana/src/opihi/cmd.astro/spexseq.c

    r39457 r39926  
    9090  int Nobject = 0;
    9191
    92   {
    93     // init random numbers
    94     long A, B;
    95     A = time(NULL);
    96     for (B = 0; A == time(NULL); B++);
    97     srand48(B);
    98   }
    99  
    10092  if (argc != 6) goto usage;
     93
     94  // srand48() is called by startup.c
    10195
    10296  // XXX enforce matching lengths on the three vectors
  • trunk/Ohana/src/opihi/cmd.data/Makefile

    r39638 r39926  
    124124$(SRC)/resize.$(ARCH).o         \
    125125$(SRC)/relocate.$(ARCH).o       \
     126$(SRC)/rndseed.$(ARCH).o                \
    126127$(SRC)/roll.$(ARCH).o           \
    127128$(SRC)/rotate.$(ARCH).o \
  • trunk/Ohana/src/opihi/cmd.data/init.c

    r39638 r39926  
    113113int reindex          PROTO((int, char **));
    114114int relocate         PROTO((int, char **));
     115int rndseed          PROTO((int, char **));
    115116int roll             PROTO((int, char **));
    116117int rotate           PROTO((int, char **));
     
    293294  {1, "relocate",     relocate,         "set graphics/image window position"},
    294295  {1, "roll",         roll,             "roll image to new start point"},
     296  {1, "rndseed",      rndseed,          "set the pseudo-random seed"},
    295297  {1, "rotate",       rotate,           "rotate image"},
    296298  {1, "save",         save,             "save an SAOimage style image overlay"},
  • trunk/Ohana/src/opihi/cmd.data/match2d.c

    r36084 r39926  
    11# include "data.h"
    22
    3 int find_matches2d (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index1, Vector *index2);
     3int find_matches2d (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index1, Vector *index2, Vector *radiusMatch);
    44int find_matches2d_closest (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index);
     5
     6int find_matches2d_sphere (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index1, Vector *index2, Vector *radiusMatch);
     7int find_matches2d_sphere_closest (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index);
    58
    69// match2d (X1) (Y1) (X2) (Y2) (Radius) [-index1 (index1)] [-index2 (index2)] [-nomatch1 nomatch1] [-nomatch2 nomatch2]
     
    2326  }
    2427
     28  int SPHERE_DISTANCE = FALSE;
     29  if ((N = get_argument (argc, argv, "-sphere"))) {
     30    remove_argument (N, &argc, argv);
     31    SPHERE_DISTANCE = TRUE;
     32  }
     33  if ((N = get_argument (argc, argv, "-sky"))) {
     34    remove_argument (N, &argc, argv);
     35    SPHERE_DISTANCE = TRUE;
     36  }
     37
    2538  if ((N = get_argument (argc, argv, "-index1"))) {
    2639    remove_argument (N, &argc, argv);
     
    3750  } else {
    3851    if ((index2 = SelectVector ("index2", ANYVECTOR, TRUE)) == NULL) return (FALSE);   
     52  }
     53
     54 
     55  Vector *radiusMatch = NULL;
     56  if ((N = get_argument (argc, argv, "-radius"))) {
     57    if (CLOSEST) {
     58      gprint (GP_ERR, "error: -radius and -closest are currently incompatible\n");
     59      return (FALSE);
     60    }
     61    remove_argument (N, &argc, argv);
     62    if ((radiusMatch = SelectVector (argv[N], ANYVECTOR, TRUE)) == NULL) return (FALSE);   
     63    remove_argument (N, &argc, argv);
    3964  }
    4065
     
    84109  }
    85110
    86   if (CLOSEST) {
     111  if (SPHERE_DISTANCE) {
     112    if (CLOSEST) {
     113      find_matches2d_sphere_closest (X1vec, Y1vec, X2vec, Y2vec, Radius, index1);
     114      find_matches2d_sphere_closest (X2vec, Y2vec, X1vec, Y1vec, Radius, index2);
     115    } else {
     116      find_matches2d_sphere (X1vec, Y1vec, X2vec, Y2vec, Radius, index1, index2, radiusMatch);
     117    }
     118  } else {
     119    if (CLOSEST) {
    87120      find_matches2d_closest (X1vec, Y1vec, X2vec, Y2vec, Radius, index1);
    88121      find_matches2d_closest (X2vec, Y2vec, X1vec, Y1vec, Radius, index2);
    89   } else {
    90       find_matches2d (X1vec, Y1vec, X2vec, Y2vec, Radius, index1, index2);
    91   }
    92 
     122    } else {
     123      find_matches2d (X1vec, Y1vec, X2vec, Y2vec, Radius, index1, index2, radiusMatch);
     124    }
     125  }
    93126  return (TRUE);
    94127
     
    108141  gprint (GP_ERR, "use 'reindex' to generate new vectors based on these index vectors\n");
    109142
     143  gprint (GP_ERR, "if -sphere or -sky is supplied, (x1,y1) and (x2,y2) are treaded as (ra,dec) or (long,lat) pairs in degrees\n");
     144
     145  gprint (GP_ERR, "if -radius (vector) is supplied, the vector will be filled with the distance between the matched pairs\n");
     146  gprint (GP_ERR, "  not valid with -closest\n");
    110147  return FALSE;
    111148}
    112149
    113150// we are not defining a relative offset DX,DY for now
    114 int find_matches2d (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index1, Vector *index2) {
     151int find_matches2d (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index1, Vector *index2, Vector *radiusMatch) {
    115152 
    116153  off_t i, j, first_j, I, J, *N1, *N2, Nmatch, NMATCH, DMATCH;
     
    122159  ResetVector (index1, OPIHI_INT, NMATCH);
    123160  ResetVector (index2, OPIHI_INT, NMATCH);
     161  if (radiusMatch) ResetVector (radiusMatch, OPIHI_FLT, NMATCH);
    124162
    125163  ALLOCATE (N1, off_t, X1->Nelements);
     
    154192        index1->elements.Int[Nmatch] = I;
    155193        index2->elements.Int[Nmatch] = J;
     194        if (radiusMatch) radiusMatch->elements.Flt[Nmatch] = dR;
    156195
    157196        // XXX track matches 1 and 2 with internal vector, save new nomatch index vectors
     
    163202          REALLOCATE (index1->elements.Int, opihi_int, NMATCH);
    164203          REALLOCATE (index2->elements.Int, opihi_int, NMATCH);
     204          if (radiusMatch) { REALLOCATE (radiusMatch->elements.Flt, opihi_flt, NMATCH); }
    165205        }
    166206      }
     
    171211  index1->Nelements = Nmatch;
    172212  index2->Nelements = Nmatch;
     213  if (radiusMatch) radiusMatch->Nelements = Nmatch;
    173214
    174215  free (N1);
     
    246287  return (TRUE);
    247288}
     289
     290double gcdist (double r1, double d1, double r2, double d2) {
     291  double num,den;
     292  r1 *= RAD_DEG;
     293  d1 *= RAD_DEG;
     294  r2 *= RAD_DEG;
     295  d2 *= RAD_DEG;
     296
     297  num = sqrt(pow((cos(d2) * sin(r2 - r1)),2) +
     298             pow((cos(d1) * sin(d2) -
     299                  sin(d1) * cos(d2) * cos(r2 - r1)),2));
     300  den = (sin(d1) * sin(d2) + cos(d1) * cos(d2) * cos(r2 - r1));
     301  return(atan2(num,den) * (180 / M_PI));
     302}
     303
     304typedef struct {
     305  double sD;
     306  double cD;
     307  double sR;
     308  double cR;
     309} Match2D_PreCalc;
     310
     311double gcdist_PreCalc_v0 (Match2D_PreCalc *p1, Match2D_PreCalc *p2) {
     312  double num,den;
     313
     314  num = sqrt(pow((p2->cD * (p2->sR*p1->cR - p1->sR*p2->cR)),2) +
     315             pow((p1->cD * p2->sD -
     316                  p1->sD * p2->cD * (p2->cR*p1->cR + p2->sR*p1->sR)),2));
     317  den = (p1->sD * p2->sD + p1->cD * p2->cD * (p2->cR*p1->cR + p2->sR*p1->sR));
     318  return(atan2(num,den) * (180 / M_PI));
     319}
     320
     321// we are not defining a relative offset DX,DY for now
     322double gcdist_PreCalc (Match2D_PreCalc *p1, Match2D_PreCalc *p2) {
     323  double num,den;
     324
     325  // double Qd = p1->sD * p1->cD * p2->sD * p2->cD;
     326  // double Qr = p1->sR * p1->cR * p2->sR * p2->cR;
     327
     328  //  double Xa
     329  //    = SQ(p2->cD * p1->cR * p2->sR)
     330  //    + SQ(p2->cD * p1->sR * p2->cR) -
     331  //    - 2 * SQ(p2->cD) * Qr;
     332
     333  double cdR = (p2->cR*p1->cR + p2->sR*p1->sR);
     334
     335  double Xa = SQ(p2->cD * p2->sR * p1->cR - p2->cD * p1->sR * p2->cR);
     336  double Xb = SQ(p1->cD * p2->sD - p1->sD * p2->cD * cdR);
     337
     338  num = sqrt(Xa + Xb);
     339  den = (p1->sD * p2->sD + p1->cD * p2->cD * cdR);
     340  return(atan2(num,den) * (180 / M_PI));
     341}
     342
     343// we are not defining a relative offset DX,DY for now
     344int find_matches2d_sphere (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index1, Vector *index2, Vector *radiusMatch) {
     345 
     346  off_t i, j, first_j, I, J, *N1, *N2, Nmatch, NMATCH, DMATCH;
     347  double dY, dR;
     348
     349  NMATCH = MAX(MAX(0.05*X1->Nelements, 0.05*X2->Nelements), 1000);
     350  DMATCH = NMATCH;
     351
     352  ResetVector (index1, OPIHI_INT, NMATCH);
     353  ResetVector (index2, OPIHI_INT, NMATCH);
     354  if (radiusMatch) ResetVector (radiusMatch, OPIHI_FLT, NMATCH);
     355
     356  ALLOCATE (N1, off_t, X1->Nelements);
     357  ALLOCATE (N2, off_t, X2->Nelements);
     358
     359  ALLOCATE_PTR (A1, Match2D_PreCalc, X1->Nelements);
     360  ALLOCATE_PTR (A2, Match2D_PreCalc, X2->Nelements);
     361
     362  for (i = 0; i < X1->Nelements; i++) {
     363    A1[i].sR = sin(RAD_DEG*X1->elements.Flt[i]);
     364    A1[i].cR = cos(RAD_DEG*X1->elements.Flt[i]);
     365    A1[i].sD = sin(RAD_DEG*Y1->elements.Flt[i]);
     366    A1[i].cD = cos(RAD_DEG*Y1->elements.Flt[i]);
     367    N1[i] = i;
     368  }
     369  for (i = 0; i < X2->Nelements; i++) {
     370    A2[i].sR = sin(RAD_DEG*X2->elements.Flt[i]);
     371    A2[i].cR = cos(RAD_DEG*X2->elements.Flt[i]);
     372    A2[i].sD = sin(RAD_DEG*Y2->elements.Flt[i]);
     373    A2[i].cD = cos(RAD_DEG*Y2->elements.Flt[i]);
     374    N2[i] = i;
     375  }
     376
     377  // sort from one pole to the other
     378  sort_coords_indexonly (Y1->elements.Flt, X1->elements.Flt, N1, X1->Nelements);
     379  sort_coords_indexonly (Y2->elements.Flt, X2->elements.Flt, N2, X2->Nelements);
     380
     381  Nmatch = 0;
     382  for (i = j = 0; (i < X1->Nelements) && (j < X2->Nelements);) {
     383    I = N1[i];
     384    J = N2[j];
     385
     386    // we can use dY as minimal requirement: if dY > Radius, we are too far apart
     387    dY = Y1->elements.Flt[I] - Y2->elements.Flt[J];
     388
     389    if (dY <= -1.02*Radius) { i++; continue; }
     390    if (dY >= +1.02*Radius) { j++; continue; }
     391
     392    // look for all matches of list2() to list1(i)
     393    first_j = j;
     394    for (j = first_j; (dY > -1.02*Radius) && (j < X2->Nelements); j++) {
     395      J = N2[j];
     396
     397      dR = gcdist_PreCalc (&A1[I], &A2[J]);
     398      // dR = gcdist (X1->elements.Flt[I], Y1->elements.Flt[I], X2->elements.Flt[J], Y2->elements.Flt[J]);
     399
     400      if (dR < Radius) {
     401        index1->elements.Int[Nmatch] = I;
     402        index2->elements.Int[Nmatch] = J;
     403        if (radiusMatch) radiusMatch->elements.Flt[Nmatch] = dR;
     404
     405        // XXX track matches 1 and 2 with internal vector, save new nomatch index vectors
     406        // after this loop
     407
     408        Nmatch ++;
     409        if (Nmatch >= NMATCH) {
     410          NMATCH += DMATCH;
     411          REALLOCATE (index1->elements.Int, opihi_int, NMATCH);
     412          REALLOCATE (index2->elements.Int, opihi_int, NMATCH);
     413          if (radiusMatch) { REALLOCATE (radiusMatch->elements.Flt, opihi_flt, NMATCH); }
     414        }
     415      }
     416    }
     417    j = first_j;
     418    i++;
     419  }
     420  index1->Nelements = Nmatch;
     421  index2->Nelements = Nmatch;
     422  if (radiusMatch) radiusMatch->Nelements = Nmatch;
     423
     424  free (A1);
     425  free (A2);
     426
     427  free (N1);
     428  free (N2);
     429
     430  return (TRUE);
     431}
     432
     433// we are not defining a relative offset DX,DY for now
     434int find_matches2d_sphere_closest (Vector *X1, Vector *Y1, Vector *X2, Vector *Y2, double Radius, Vector *index) {
     435 
     436  off_t i, j, Jmin, Ji, I, J, *N1, *N2;
     437  double dY, dR, Rmin;
     438
     439  ResetVector (index, OPIHI_INT, X1->Nelements);
     440  for (i = 0; i < index->Nelements; i++) { index->elements.Int[i] = -1; }
     441
     442  ALLOCATE (N1, off_t, X1->Nelements);
     443  ALLOCATE (N2, off_t, X2->Nelements);
     444
     445  ALLOCATE_PTR (A1, Match2D_PreCalc, X1->Nelements);
     446  ALLOCATE_PTR (A2, Match2D_PreCalc, X2->Nelements);
     447
     448  for (i = 0; i < X1->Nelements; i++) {
     449    A1[i].sR = sin(RAD_DEG*X1->elements.Flt[i]);
     450    A1[i].cR = cos(RAD_DEG*X1->elements.Flt[i]);
     451    A1[i].sD = sin(RAD_DEG*Y1->elements.Flt[i]);
     452    A1[i].cD = cos(RAD_DEG*Y1->elements.Flt[i]);
     453    N1[i] = i;
     454  }
     455  for (i = 0; i < X2->Nelements; i++) {
     456    A2[i].sR = sin(RAD_DEG*X2->elements.Flt[i]);
     457    A2[i].cR = cos(RAD_DEG*X2->elements.Flt[i]);
     458    A2[i].sD = sin(RAD_DEG*Y2->elements.Flt[i]);
     459    A2[i].cD = cos(RAD_DEG*Y2->elements.Flt[i]);
     460    N2[i] = i;
     461  }
     462
     463  // sort from one pole to the other
     464  sort_coords_indexonly (Y1->elements.Flt, X1->elements.Flt, N1, X1->Nelements);
     465  sort_coords_indexonly (Y2->elements.Flt, X2->elements.Flt, N2, X2->Nelements);
     466
     467  for (i = j = 0; (i < X1->Nelements) && (j < X2->Nelements);) {
     468    I = N1[i];
     469    J = N2[j];
     470
     471    // we can use dY as minimal requirement: if dY > Radius, we are too far apart
     472    dY = Y1->elements.Flt[I] - Y2->elements.Flt[J];
     473
     474    if (dY <= -1.02*Radius) {
     475      // no match in list 2 to this entry
     476      index->elements.Int[I] = -1; // (probably not needed --- index is init'ed above)o
     477      i++;
     478      continue;
     479    }
     480    if (dY >= +1.02*Radius) { j++; continue; }
     481
     482    // look for all matches of list2() to list1(i)
     483    Jmin = -1;
     484    Rmin = Radius;
     485    for (Ji = j; (dY > -1.02*Radius) && (Ji < X2->Nelements); Ji++) {
     486      J = N2[Ji];
     487
     488      dR = gcdist_PreCalc (&A1[I], &A2[J]);
     489      // dR = gcdist (X1->elements.Flt[I], Y1->elements.Flt[I], X2->elements.Flt[J], Y2->elements.Flt[J]);
     490
     491      if (dR < Rmin) {
     492        Rmin = dR;
     493        Jmin = J;
     494      }
     495    }
     496   
     497
     498    // no match in list 2 to this entry
     499    if (Jmin == -1) {
     500      index->elements.Int[I] = -1;
     501      i++;
     502      continue;
     503    }
     504    index->elements.Int[I] = Jmin;
     505    i++;
     506  }
     507
     508  free (A1);
     509  free (A2);
     510
     511  free (N1);
     512  free (N2);
     513
     514  return (TRUE);
     515}
     516
     517
  • trunk/Ohana/src/opihi/cmd.data/stats-new.c

    r15274 r39926  
    129129  ALLOCATE (values, float, Nsample);
    130130   
    131   A = time(NULL);
    132   for (B = 0; A == time(NULL); B++);
    133   srand48(B);
     131  // srand48() is called by startup.c
    134132 
    135133  *buffer = (float *) matrix[0].buffer;
  • trunk/Ohana/src/opihi/dvo/imbox.c

    r37807 r39926  
    1515
    1616  if (!style_args (&graphmode, &argc, argv, &kapa)) return FALSE;
     17
     18  char *xaxis = NULL;
     19  if ((N = get_argument (argc, argv, "-xaxis"))) {
     20    remove_argument (N, &argc, argv);
     21    xaxis = strcreate (argv[N]);
     22    remove_argument (N, &argc, argv);
     23  }
     24  char *yaxis = NULL;
     25  if ((N = get_argument (argc, argv, "-yaxis"))) {
     26    remove_argument (N, &argc, argv);
     27    yaxis = strcreate (argv[N]);
     28    remove_argument (N, &argc, argv);
     29  }
    1730
    1831  SOLO_PHU = FALSE;
     
    6174    // XXX currently, image uses an unsigned short for NX,XY. this is rather restrictive
    6275    // and needs to be at least checked.
    63     haveNx = gfits_scan (&header, "IMNAXIS1",   "%d", 1, &Nx);
    64     haveNy = gfits_scan (&header, "IMNAXIS2",   "%d", 1, &Ny);
     76    haveNx = FALSE;
     77    if (xaxis) {
     78      haveNx = gfits_scan (&header, xaxis, "%d", 1, &Nx);
     79    }
     80    if (!haveNx) {
     81      haveNx = gfits_scan (&header, "IMNAXIS1",   "%d", 1, &Nx);
     82    }
     83    if (!haveNx) {
     84        haveNx = gfits_scan (&header, "ZNAXIS1",   "%d", 1, &Nx);
     85    }
     86    if (!haveNx) {
     87        haveNx = gfits_scan (&header, "NAXIS1",   "%d", 1, &Nx);
     88    }
    6589
    66     if (!haveNx && !haveNy) {
    67         haveNx = gfits_scan (&header, "ZNAXIS1",   "%d", 1, &Nx);
     90    haveNy = FALSE;
     91    if (yaxis) {
     92      haveNy = gfits_scan (&header, yaxis, "%d", 1, &Ny);
     93    }
     94    if (!haveNy) {
     95      haveNy = gfits_scan (&header, "IMNAXIS2",   "%d", 1, &Ny);
     96    }
     97    if (!haveNy) {
    6898        haveNy = gfits_scan (&header, "ZNAXIS2",   "%d", 1, &Ny);
    6999    }
    70 
    71     if (!haveNx && !haveNy) {
    72         haveNx = gfits_scan (&header, "NAXIS1",   "%d", 1, &Nx);
     100    if (!haveNy) {
    73101        haveNy = gfits_scan (&header, "NAXIS2",   "%d", 1, &Ny);
    74102    }
     
    137165  free (Xvec.elements.Flt);
    138166  free (Yvec.elements.Flt);
     167  if (xaxis) free (xaxis);
     168  if (yaxis) free (yaxis);
    139169  return (TRUE);
    140170
  • trunk/Ohana/src/opihi/dvo/imdense.c

    r37807 r39926  
    44int imdense (int argc, char **argv) {
    55 
    6   long A, B;
    76  off_t i, Nimage;
    87  int kapa, N, status, NPTS;
     
    2726  Rmax = graphmode.coords.crval1 + 182.0;
    2827 
    29   A = time(NULL);
    30   for (B = 0; A == time(NULL); B++);
    31   srand48(B);
     28  // srand48() is called by startup.c
    3229
    3330  N = 0;
  • trunk/Ohana/src/opihi/dvo/skycat.c

    r39457 r39926  
    7878      if (table) {
    7979        int hostID = (regions[i][0].hostFlags & DATA_USE_BCK) ? regions[i][0].backupID : regions[i][0].hostID;
    80         int index = table->index[hostID];
    81         snprintf (hostfile, 1024, "%s/%s.cpt", table->hosts[index].pathname, regions[i][0].name);
     80        if (hostID) {
     81          int index = table->index[hostID];
     82          snprintf (hostfile, 1024, "%s/%s.cpt", table->hosts[index].pathname, regions[i][0].name);
     83        } else {
     84          strcpy (hostfile, skylist[0].filename[i]);
     85        }
    8286      } else {
    8387        strcpy (hostfile, skylist[0].filename[i]);
  • trunk/Ohana/src/opihi/lib.data/style_args.c

    r13479 r39926  
    2929  if ((N = get_argument (*argc, argv, "-lt"))) {
    3030    remove_argument (N, argc, argv);
    31     graphmode[0].ltype = atof(argv[N]);
     31    graphmode[0].ltype = KapaLineTypeFromString(argv[N]);
    3232    remove_argument (N, argc, argv);
    3333  }
     
    3939  if ((N = get_argument (*argc, argv, "-pt"))) {
    4040    remove_argument (N, argc, argv);
    41     graphmode[0].ptype = atof(argv[N]);
     41    graphmode[0].ptype = KapaPointStyleFromString(argv[N]);
    4242    remove_argument (N, argc, argv);
    4343  }
     
    6363  if ((N = get_argument (*argc, argv, "-x"))) {
    6464    remove_argument (N, argc, argv);
    65     graphmode[0].style = atof(argv[N]);
     65    graphmode[0].style = KapaPlotStyleFromString(argv[N]);
    6666    remove_argument (N, argc, argv);
    6767  }
  • trunk/Ohana/src/opihi/lib.shell/startup.c

    r33963 r39926  
    5151    gfits_set_unsign_mode (FALSE);
    5252   
     53    set_variable ("M_PI", M_PI);
     54    set_variable ("M_E",  M_E);
     55    set_variable ("M_c",  299792459.0); // meter / second
     56    set_variable ("M_c_cgs", 29979245900.0); // cm / second
     57
     58    set_variable ("M_h",  6.62607004e-34); // meter^2 kg / second (J s)
     59    set_variable ("M_h_cgs",  6.62607004e-27); // erg s
     60
     61    set_variable ("M_kB",  1.38064853e-23); // J / K
     62    set_variable ("M_kB_cgs",  1.38064853e-16); // erg / K
     63
    5364  /* check history file permission */
    5465  {
  • trunk/Ohana/src/photdbc/src/make_subcatalog.c

    r38441 r39926  
    77  int found;
    88  off_t i, j, k, offset;
    9   off_t NAVERAGE, NMEASURE, Naverage, Nmeasure, Nm, Nsecfilt;
     9  off_t Nm, Nsecfilt;
    1010  double mag, minMag, minSigma;
    1111  int keep, *secKeep;
     
    2727
    2828  /* we are moving only the subset of measurements from catalog[0] to subcatalog[0] */
    29   NAVERAGE = 50;
    30   NMEASURE = 1000;
    31   Nmeasure = Naverage = 0;
     29  off_t NAVERAGE = 50;   off_t Naverage = 0;
     30  off_t NMEASURE = 1000; off_t Nmeasure = 0;
     31  off_t NLENSING = 1000; off_t Nlensing = 0;
     32  off_t NLENSOBJ = 1000; off_t Nlensobj = 0;
     33  off_t NSTARPAR = 1000; off_t Nstarpar = 0;
     34  off_t NGALPHOT = 1000; off_t Ngalphot = 0;
     35
    3236  REALLOCATE (subcatalog[0].average, Average, NAVERAGE);
    3337  REALLOCATE (subcatalog[0].secfilt, SecFilt, NAVERAGE*Nsecfilt);
    3438  REALLOCATE (subcatalog[0].measure, Measure, NMEASURE);
     39  REALLOCATE (subcatalog[0].lensing, Lensing, NLENSING);
     40  REALLOCATE (subcatalog[0].lensobj, Lensobj, NLENSOBJ);
     41  REALLOCATE (subcatalog[0].starpar, StarPar, NSTARPAR);
     42  REALLOCATE (subcatalog[0].galphot, GalPhot, NGALPHOT);
    3543
    3644  for (i = 0; i < catalog[0].Naverage; i++) {
     
    3947    // XXX: temporary check make sure that this object belongs in this region
    4048    // used to fix the pole area in the reference catalog
    41     {
     49    if (0) {
    4250        double R = catalog[0].average[i].R;
    4351        double D = catalog[0].average[i].D;
     
    177185    subcatalog[0].average[Naverage].Nmissing = 0;
    178186    subcatalog[0].average[Naverage].Nmeasure = Nm;
     187
     188    // **** lensing
     189    Nm = 0;
     190    subcatalog[0].average[Naverage].lensingOffset = Nlensing;
     191    for (j = 0; j < catalog[0].average[i].Nlensing; j++) {
     192
     193      offset = catalog[0].average[i].lensingOffset + j;
     194
     195      subcatalog[0].lensing[Nlensing]        = catalog[0].lensing[offset];
     196      subcatalog[0].lensing[Nlensing].averef = Naverage;
     197
     198      Nlensing ++;
     199      Nm ++;
     200      if (Nlensing == NLENSING) {
     201        NLENSING += 1000;
     202        REALLOCATE (subcatalog[0].lensing, Lensing, NLENSING);
     203      }
     204    }
     205    subcatalog[0].average[Naverage].Nlensing = Nm;
     206
     207    // **** lensobj
     208    Nm = 0;
     209    subcatalog[0].average[Naverage].lensobjOffset = Nlensobj;
     210    for (j = 0; j < catalog[0].average[i].Nlensobj; j++) {
     211
     212      offset = catalog[0].average[i].lensobjOffset + j;
     213
     214      subcatalog[0].lensobj[Nlensobj]        = catalog[0].lensobj[offset];
     215
     216      Nlensobj ++;
     217      Nm ++;
     218      if (Nlensobj == NLENSOBJ) {
     219        NLENSOBJ += 1000;
     220        REALLOCATE (subcatalog[0].lensobj, Lensobj, NLENSOBJ);
     221      }
     222    }
     223    subcatalog[0].average[Naverage].Nlensobj = Nm;
     224
     225    // **** starpar
     226    Nm = 0;
     227    subcatalog[0].average[Naverage].starparOffset = Nstarpar;
     228    for (j = 0; j < catalog[0].average[i].Nstarpar; j++) {
     229
     230      offset = catalog[0].average[i].starparOffset + j;
     231
     232      subcatalog[0].starpar[Nstarpar]        = catalog[0].starpar[offset];
     233      subcatalog[0].starpar[Nstarpar].averef = Naverage;
     234
     235      Nstarpar ++;
     236      Nm ++;
     237      if (Nstarpar == NSTARPAR) {
     238        NSTARPAR += 1000;
     239        REALLOCATE (subcatalog[0].starpar, StarPar, NSTARPAR);
     240      }
     241    }
     242    subcatalog[0].average[Naverage].Nstarpar = Nm;
     243
     244    // **** galphot
     245    Nm = 0;
     246    subcatalog[0].average[Naverage].galphotOffset = Ngalphot;
     247    for (j = 0; j < catalog[0].average[i].Ngalphot; j++) {
     248
     249      offset = catalog[0].average[i].galphotOffset + j;
     250
     251      subcatalog[0].galphot[Ngalphot]        = catalog[0].galphot[offset];
     252      subcatalog[0].galphot[Ngalphot].averef = Naverage;
     253
     254      Ngalphot ++;
     255      Nm ++;
     256      if (Ngalphot == NGALPHOT) {
     257        NGALPHOT += 1000;
     258        REALLOCATE (subcatalog[0].galphot, GalPhot, NGALPHOT);
     259      }
     260    }
     261    subcatalog[0].average[Naverage].Ngalphot = Nm;
     262
    179263    Naverage ++;
    180264    if (Naverage == NAVERAGE) {
     
    187271  REALLOCATE (subcatalog[0].measure, Measure, MAX (Nmeasure, 1));
    188272  REALLOCATE (subcatalog[0].secfilt, SecFilt, Nsecfilt*MAX (Naverage, 1));
     273  REALLOCATE (subcatalog[0].lensing, Lensing, MAX (Nlensing, 1));
     274  REALLOCATE (subcatalog[0].lensobj, Lensobj, MAX (Nlensobj, 1));
     275  REALLOCATE (subcatalog[0].starpar, StarPar, MAX (Nstarpar, 1));
     276  REALLOCATE (subcatalog[0].galphot, GalPhot, MAX (Ngalphot, 1));
     277
    189278  subcatalog[0].Naverage = Naverage;
    190279  subcatalog[0].Nmeasure = Nmeasure;
    191280  subcatalog[0].Nsecfilt = Nsecfilt;
     281  subcatalog[0].Nlensing = Nlensing;
     282  subcatalog[0].Nlensobj = Nlensobj;
     283  subcatalog[0].Nstarpar = Nstarpar;
     284  subcatalog[0].Ngalphot = Ngalphot;
     285
    192286  subcatalog[0].Nsecfilt_mem = Naverage * Nsecfilt;
    193287
  • trunk/Ohana/src/photdbc/src/photdbc_catalogs.c

    r38986 r39926  
    2626    incatalog.filename  = hostID ? hostfile : skylist[0].filename[i];
    2727    incatalog.Nsecfilt = GetPhotcodeNsecfilt ();
    28     incatalog.catflags = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_SECFILT;
     28
     29    incatalog.catflags    = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
     30    incatalog.catflags   |= DVO_LOAD_MEASURE | DVO_LOAD_MISSING;
     31    incatalog.catflags   |= DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ;
     32    incatalog.catflags   |= DVO_LOAD_STARPAR | DVO_LOAD_GALPHOT;
    2933
    3034    // an error exit status here is a significant error
     
    5761    outcatalog.catcompress = CATCOMPRESS ? dvo_catalog_catcompress (CATCOMPRESS) : incatalog.catcompress; // set the default catcompress from config data
    5862    outcatalog.Nsecfilt    = incatalog.Nsecfilt;                 // inherit from the incatalog
    59     outcatalog.catflags    = DVO_LOAD_AVERAGE | DVO_LOAD_MEASURE | DVO_LOAD_MISSING | DVO_LOAD_SECFILT;
     63
     64    outcatalog.catflags    = DVO_LOAD_AVERAGE | DVO_LOAD_SECFILT;
     65    outcatalog.catflags   |= DVO_LOAD_MEASURE | DVO_LOAD_MISSING;
     66    outcatalog.catflags   |= DVO_LOAD_LENSING | DVO_LOAD_LENSOBJ;
     67    outcatalog.catflags   |= DVO_LOAD_STARPAR | DVO_LOAD_GALPHOT;
    6068
    6169    // output catalogs always represent the same skyregions as the input catalogs
  • trunk/Ohana/src/relastro/include/relastro.h

    r39693 r39926  
    3333typedef 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, OP_REPAIR_STACKS, OP_REPAIR_WARPS, OP_REPAIR_OBJECT_ID} RelastroOp;
    3434
    35 typedef enum {TARGET_NONE, TARGET_SIMPLE, TARGET_CHIPS, TARGET_MOSAICS} FitTarget;
     35typedef enum {TARGET_NONE, TARGET_SIMPLE, TARGET_CHIPS, SET_CHIPS, TARGET_MOSAICS} FitTarget;
    3636
    3737typedef enum {
     
    144144  int Nfit;
    145145  int converged;
     146  int useWeight;
     147
    146148} FitAstromResult;
    147149
     
    296298} CheckMeasureResult;
    297299
    298 # define ID_MEAS_OBJECT_HAS_2MASS ID_MEAS_POOR_PHOTOM
     300// # define ID_MEAS_OBJECT_HAS_2MASS ID_MEAS_POOR_PHOTOM
    299301
    300302/* global variables set in parameter file */
     
    315317int    PARALLEL_REGIONS_MANUAL;
    316318char  *MANUAL_UNIQUER;
     319int    CATCH_UP;
    317320
    318321int          HOST_ID;
     
    352355int    VERBOSE2;
    353356
     357float  TEST_SCALE;
     358char  *GALAXY_MODEL;
     359
    354360int    USE_FIXED_PIXCOORDS;
    355361int    USE_GALAXY_MODEL;
     
    363369int    USE_IMAGE_COORDS_FOR_REPAIR;
    364370int    USE_ALL_IMAGES;
     371int    KEEP_ALL_IMAGES_RA;
    365372int    CHECK_MEASURE_TO_IMAGE;
     373
     374int    SKIP_PS1_CHIP;
     375int    SKIP_PS1_STACK;
     376int    SKIP_HSC;
     377int    SKIP_CFH;
     378
     379int    UPDATE_PS1_STACK_MEASURE;
     380int    UPDATE_PS1_CHIP_MEASURE;
     381int    UPDATE_HSC_MEASURE;
     382int    UPDATE_CFH_MEASURE;
     383
     384int    APPLY_PROPER_MOTION;
    366385
    367386int    RESET;
     
    383402int    CHIPMAP;
    384403
     404int    *ChipMapLoop;
     405int    *ChipOrderLoop;
     406char   *ChipMapLoopStr;
     407char   *ChipOrderLoopStr;
     408
    385409int    N_BOOTSTRAP_SAMPLES;
    386410
     
    407431
    408432float *LoopWeight2MASS;
     433char *LoopWeight2MASSstr;
     434
    409435float *LoopWeightTycho;
    410 char *LoopWeight2MASSstr;
    411436char *LoopWeightTychostr;
     437
     438float *LoopWeightGAIA;
     439char *LoopWeightGAIAstr;
    412440
    413441int ImagSelect;
     
    433461
    434462FitMode FIT_MODE;
     463int USE_IRLS;
     464int ALLOW_IRLS;
    435465
    436466RelastroOp RELASTRO_OP;
     
    498528void          initGridBins        PROTO((Catalog *catalog, int Ncatalog));
    499529void          initImageBins       PROTO((Catalog *catalog, int Ncatalog, int FULLINIT));
    500 void          initImages          PROTO((Image *input, off_t *line_number, off_t N));
     530void          initImages          PROTO((Image *input, off_t *line_number, off_t N, int isSubset));
    501531void          freeImages          PROTO((char *dbImagePtr));
    502532void          initMosaicBins      PROTO((Catalog *catalog, int Ncatalog));
     
    744774int isGPC1stack (int photcode);
    745775int isGPC1warp (int photcode);
     776int isHSCchip (int photcode);
     777int isCFHchip (int photcode);
    746778
    747779int save_astrom_table ();
  • trunk/Ohana/src/relastro/src

  • trunk/Ohana/src/relastro/src/BootstrapOps.c

    r39457 r39926  
    7777    case FIT_RESULT_RA:
    7878      // result->Ro = median;
    79       result->dRo = sigma;
     79      result->dRo = MAX(sigma, result->dRo);
    8080      break;
    8181    case FIT_RESULT_DEC:
    8282      // result->Do = median;
    83       result->dDo = sigma;
     83      result->dDo = MAX(sigma, result->dDo);
    8484      break;
    8585    case FIT_RESULT_uR:
    8686      // result->uR = median;
    87       result->duR = sigma;
     87      result->duR = MAX(sigma, result->duR);
    8888      break;
    8989    case FIT_RESULT_uD:
    9090      // result->uD = median;
    91       result->duD = sigma;
     91      result->duD = MAX(sigma, result->duD);
    9292      break;
    9393    case FIT_RESULT_PLX:
    9494      // result->p = median;
    95       result->dp = sigma;
     95      result->dp = MAX(sigma, result->dp);
    9696      break;
    9797    default:
  • trunk/Ohana/src/relastro/src/BrightCatalog.c

    r39457 r39926  
    353353  /*** MeasureTiny ***/
    354354  {
    355     ohana_memcheck (1);
     355    // ohana_memcheck (1);
    356356    gfits_create_table_header (&theader, "BINTABLE", "MEASURE_TINY");
    357357
    358     ohana_memcheck (1);
     358    // ohana_memcheck (1);
    359359
    360360    gfits_define_bintable_column (&theader, "D", "RA",       "ra",                         "degrees", 1.0, 0.0);
     
    429429    gfits_set_bintable_column (&theader, &ftable, "RA",         R,         catalog->Nmeasure);
    430430
    431     fprintf (stderr, "--------------- after set_bintable RA --------------");
    432     ohana_memdump_file (stderr, TRUE);
     431    // fprintf (stderr, "--------------- after set_bintable RA --------------");
     432    // ohana_memdump_file (stderr, TRUE);
    433433   
    434434    gfits_set_bintable_column (&theader, &ftable, "DEC",        D,         catalog->Nmeasure);
  • trunk/Ohana/src/relastro/src/ConfigInit.c

    r39396 r39926  
    8484  SetZeroPoint (25.0);
    8585
    86   if (USE_GALAXY_MODEL) {
    87     if (!InitGalaxyModel ("FEAST-HIPPARCOS")) {
    88       fprintf (stderr, "failed to init galaxy model\n");
    89       exit (2);
    90     }
    91   }
    92 
    9386  FreeConfigFile();
    9487  free (config);
  • trunk/Ohana/src/relastro/src/FitAstromOps.c

    r39610 r39926  
    257257  fit->converged = FALSE;
    258258 
     259  // this is an input value
     260  // if true, use the IRLS modified weight
     261  fit->useWeight = FALSE;
     262
    259263  return;
    260264}
  • trunk/Ohana/src/relastro/src/FitChip.c

    r39457 r39926  
    7878      order_use = MIN(MIN(order_use, CHIPMAP), 6); // can only go up to 6th order map (can be user limited)
    7979    } else {
    80       order_use = MIN(order_use, 3); // can only go up to 3rd order for polynomials
     80      order_use = MIN(MIN(order_use, CHIPORDER), 3); // can only go up to 3rd order for polynomials
    8181    }
    8282
     
    206206  if (VERBOSE2) fprintf (stderr, "fit sigma: %f (%f, %f) : full: %f (%f, %f), scatter limit: %f (%d full, %d bright, %d fit, %d all) (%d %d %d %d %d)\n", dRsig, dLsig, dMsig, dRsigFull, dLsigFull, dMsigFull, dRmax, NstatFull, Nstat, fit[0].Npts, Nmatch, nMask1, nMask2, nMask3, nMask4, nMask5);
    207207
    208   image[0].dXpixSys = dLsig;
    209   image[0].dYpixSys = dMsig;
     208  // need to convert dLsig, dMsig back to pixel scale (or up to arcsec)
     209
     210  float plateScale;
     211  if (image[0].coords.mosaic) {
     212    // NOTE: for the full pixel to sky plate scale, use this:
     213    // float plateScaleX = 3600.0*image[0].coords.mosaic->cdelt1*image[0].coords.cdelt1;
     214    // float plateScaleY = 3600.0*image[0].coords.mosaic->cdelt2*image[0].coords.cdelt2;
     215
     216    // since we are compare L,M values, just need to compensate for focal plate to sky:
     217    float plateScaleX = 3600.0*fabs(image[0].coords.mosaic->cdelt1);
     218    float plateScaleY = 3600.0*fabs(image[0].coords.mosaic->cdelt2);
     219    plateScale = 0.5*(plateScaleX + plateScaleY);
     220  } else {
     221    // since we are compare L,M values, just need to compensate for arcsec vs degrees:
     222    plateScale = 3600.0;
     223  }
     224
     225  image[0].dXpixSys = plateScale*dLsig;
     226  image[0].dYpixSys = plateScale*dMsig;
    210227  image[0].nFitAstrom = fit[0].Npts;
    211228
    212   // fprintf (stderr, "%s %6.3f %4d %4d\n", image[0].name, image[0].refColor, Ncolor, image[0].nFitAstrom);
     229  if (VERBOSE2) fprintf (stderr, "%s | %6.3f %6.3f | %4d %4d | %6.3f %6.3f\n", image[0].name, image[0].refColorRed, image[0].refColorBlue, Ncolor, image[0].nFitAstrom, image[0].dXpixSys, image[0].dYpixSys);
    213230
    214231  if (fit) fit_free (fit);
  • trunk/Ohana/src/relastro/src/FitPM.c

    r39612 r39926  
    2525  }
    2626
     27  fit->useWeight = FALSE; // Ordinary Least Squares
    2728  if (!FitPM_MinChisq (fit, data, points, Npoints)) return FALSE;
    2829  if (!FitPM_SetChisq (fit, data, points, Npoints)) return FALSE;
     
    4748 
    4849  // Solve OLS equation 
     50  fit->useWeight = FALSE; // Ordinary Least Squares
    4951  if (!FitPM_MinChisq(fit, data, points, Npoints)) {
    5052    return(FALSE);
     
    6971
    7072  // Iteratively reweight and solve
    71   double sigma_hat = 0.0; // save for the error model
     73  // double sigma_hat = 0.0; // save for the error model
    7274  int converged = FALSE;
    7375  int iterations = 0;
     
    9092
    9193    // Solve with the new weights
     94    fit->useWeight = TRUE; // Reweighted Least Squares
    9295    if (!FitPM_MinChisq(fit, data, points, Npoints)) {
    9396
     
    104107        points[i].u = sqrt(SQ(points[i].rx / points[i].dX) + SQ(points[i].ry / points[i].dY));
    105108      }
    106       sigma_hat = MedianAbsDeviation(points, Npoints) / 0.6745;
     109      // sigma_hat = MedianAbsDeviation(points, Npoints) / 0.6745;
    107110      break;
    108111    }
     
    119122      points[i].u = sqrt(SQ(points[i].rx / points[i].dX) + SQ(points[i].ry / points[i].dY));
    120123    }
    121     sigma_hat = MedianAbsDeviation(points, Npoints) / 0.6745;
     124    // sigma_hat = MedianAbsDeviation(points, Npoints) / 0.6745;
    122125   
    123126    // Check convergence
     
    159162  // NOTE EAM: in tests (fitpm.c), they seem to be too large by a factor of ~5.37
    160163  if (data->getError) {
    161     double ax = 0.0, ay = 0.0;
    162     double bx = 0.0, by = 0.0;
    163 
    164     for (i = 0; i < Npoints; i++) {
    165       ax += dpsi_cauchy(points[i].rx / points[i].dX);
    166       ay += dpsi_cauchy(points[i].ry / points[i].dY);
    167 
    168       bx += SQ(points[i].Wx);
    169       by += SQ(points[i].Wy);
    170     }
    171     ax /= 1.0 * Npoints;  // mean(psi_dot(r))
    172     ay /= 1.0 * Npoints;
    173     bx /= 1.0 * (Npoints - data->Nterms); // mean(psi^2(r)) * (N / (N-p))
    174     by /= 1.0 * (Npoints - data->Nterms);
    175  
    176     double lambda_x = 1.0 + (data->Nterms / Npoints) * (1 - ax) / ax;
    177     double lambda_y = 1.0 + (data->Nterms / Npoints) * (1 - ay) / ay;
    178  
    179     double sigma_robust_x = lambda_x * sqrt(bx) * sigma_hat * 2.385 / ax;
    180     double sigma_robust_y = lambda_y * sqrt(by) * sigma_hat * 2.385 / ay;
    181 
    182     // This is actually sigma^2, as that's the factor in the covariance (dumouchel 4.1)
    183     double sigma_final_x  = MAX(SQ(sigma_robust_x), (2 * Npoints * SQ(sigma_robust_x) + SQ(data->Nterms * sigma_ols)) / (2 * Npoints + SQ(data->Nterms)));
    184     double sigma_final_y  = MAX(SQ(sigma_robust_y), (2 * Npoints * SQ(sigma_robust_y) + SQ(data->Nterms * sigma_ols)) / (2 * Npoints + SQ(data->Nterms)));
    185 
    186     fit[0].dRo = sqrt(data->Cov[0][0]);
    187     fit[0].duR = sqrt(data->Cov[1][1]);
    188     fit[0].dDo = sqrt(data->Cov[2][2]);
    189     fit[0].duD = sqrt(data->Cov[3][3]);
    190 
    191     fit[0].dRo *= sigma_final_x;
    192     fit[0].duR *= sigma_final_x;
    193     fit[0].dDo *= sigma_final_y;
    194     fit[0].duD *= sigma_final_y;
     164    FitAstromResult fitErrors;
     165    FitAstromResultInit (&fitErrors);
     166    fitErrors.useWeight = FALSE;
     167
     168    FitPM_MinChisq(&fitErrors, data, points, Npoints);
     169
     170    // we use the errors from a simple OLS, ignoring masked points
     171    fit[0].dRo = fitErrors.dRo;
     172    fit[0].duR = fitErrors.duR;
     173    fit[0].dDo = fitErrors.dDo;
     174    fit[0].duD = fitErrors.duD;
    195175  }
    196176
     
    212192    Nfit ++;
    213193
    214     wx = points[i].qx;
    215     wy = points[i].qy;
     194    if (fit->useWeight) {
     195      wx = points[i].qx;
     196      wy = points[i].qy;
     197    } else {
     198      wx = points[i].Qx;
     199      wy = points[i].Qy;
     200    }
    216201
    217202    Wx += wx;
  • trunk/Ohana/src/relastro/src/FitPMandPar.c

    r39612 r39926  
    2525  }
    2626
     27  fit->useWeight = FALSE; // Ordinary Least Squares
    2728  if (!FitPMandPar_MinChisq (fit, data, points, Npoints)) return FALSE;
    2829  if (!FitPMandPar_SetChisq (fit, data, points, Npoints)) return FALSE;
     
    4748 
    4849  // Solve OLS equation: failure here means the chisq matrix is degenerate, give up entirely
     50  fit->useWeight = FALSE; // Ordinary Least Squares
    4951  if (!FitPMandPar_MinChisq(fit, data, points, Npoints)) {
    5052    return(FALSE);
     
    6971
    7072  // Iteratively reweight and solve
    71   double sigma_hat = 0.0; // save for the error model
     73  // double sigma_hat = 0.0; // save for the error model
    7274  int converged = FALSE;
    7375  int iterations = 0;
     
    9092
    9193    // Solve with the new weights
     94    fit->useWeight = TRUE; // Reweighted Least Squares
    9295    if (!FitPMandPar_MinChisq(fit, data, points, Npoints)) {
    9396
     
    105108        points[i].u = sqrt(SQ(points[i].rx / points[i].dX) + SQ(points[i].ry / points[i].dY));
    106109      }
    107       sigma_hat = MedianAbsDeviation(points, Npoints) / 0.6745;
     110      // sigma_hat = MedianAbsDeviation(points, Npoints) / 0.6745;
    108111      break;
    109112    }
     
    120123      points[i].u = sqrt(SQ(points[i].rx / points[i].dX) + SQ(points[i].ry / points[i].dY));
    121124    }
    122     sigma_hat = MedianAbsDeviation(points, Npoints) / 0.6745;
     125    // sigma_hat = MedianAbsDeviation(points, Npoints) / 0.6745;
    123126
    124127    // Check convergence
     
    157160  }
    158161
    159   // this section calculates the formal error on the weighted fit using the covariance values
    160   // NOTE EAM: in tests (fitpm.c), they seem to be too large by a factor of ~5.37
     162  // this section calculates the formal error on the regular (unweighted) fit using the covariance values
     163  // NOTE 20160929 : use only the unmasked points to calculate the error
    161164  if (data->getError) {
    162     double ax = 0.0, ay = 0.0;
    163     double bx = 0.0, by = 0.0;
    164 
    165     for (i = 0; i < Npoints; i++) {
    166       ax += dpsi_cauchy(points[i].rx / points[i].dX);
    167       ay += dpsi_cauchy(points[i].ry / points[i].dY);
    168 
    169       bx += SQ(points[i].Wx);
    170       by += SQ(points[i].Wy);
    171     }
    172     ax /= 1.0 * Npoints;  // mean(psi_dot(r))
    173     ay /= 1.0 * Npoints;
    174     bx /= 1.0 * (Npoints - data->Nterms); // mean(psi^2(r)) * (N / (N-p))
    175     by /= 1.0 * (Npoints - data->Nterms);
    176  
    177     double lambda_x = 1.0 + (data->Nterms / Npoints) * (1 - ax) / ax;
    178     double lambda_y = 1.0 + (data->Nterms / Npoints) * (1 - ay) / ay;
    179  
    180     double sigma_robust_x = lambda_x * sqrt(bx) * sigma_hat * 2.385 / ax;
    181     double sigma_robust_y = lambda_y * sqrt(by) * sigma_hat * 2.385 / ay;
    182 
    183     // This is actually sigma^2, as that's the factor in the covariance (dumouchel 4.1)
    184     double sigma_final_x  = MAX(SQ(sigma_robust_x), (2 * Npoints * SQ(sigma_robust_x) + SQ(data->Nterms * sigma_ols)) / (2 * Npoints + SQ(data->Nterms)));
    185     double sigma_final_y  = MAX(SQ(sigma_robust_y), (2 * Npoints * SQ(sigma_robust_y) + SQ(data->Nterms * sigma_ols)) / (2 * Npoints + SQ(data->Nterms)));
    186 
    187     fit[0].dRo = sqrt(data->Cov[0][0]);
    188     fit[0].duR = sqrt(data->Cov[1][1]);
    189     fit[0].dDo = sqrt(data->Cov[2][2]);
    190     fit[0].duD = sqrt(data->Cov[3][3]);
    191     fit[0].dp  = sqrt(data->Cov[4][4]);
    192 
    193     fit[0].dRo *= sigma_final_x;
    194     fit[0].duR *= sigma_final_x;
    195     fit[0].dDo *= sigma_final_y;
    196     fit[0].duD *= sigma_final_y;
    197     fit[0].dp  *= sqrt(sigma_final_x * sigma_final_y);
     165    FitAstromResult fitErrors;
     166    FitAstromResultInit (&fitErrors);
     167    fitErrors.useWeight = FALSE;
     168
     169    FitPMandPar_MinChisq(&fitErrors, data, points, Npoints);
     170
     171    // we use the errors from a simple OLS, ignoring masked points
     172    fit[0].dRo = fitErrors.dRo;
     173    fit[0].duR = fitErrors.duR;
     174    fit[0].dDo = fitErrors.dDo;
     175    fit[0].duD = fitErrors.duD;
     176    fit[0].dp  = fitErrors.dp;
    198177  }
    199178
     
    219198    Nfit ++;
    220199
    221     wx = points[i].qx;
    222     wy = points[i].qy;
     200    if (fit->useWeight) {
     201      wx = points[i].qx;
     202      wy = points[i].qy;
     203    } else {
     204      wx = points[i].Qx;
     205      wy = points[i].Qy;
     206    }
    223207
    224208    Wx += wx;
  • trunk/Ohana/src/relastro/src/FitPosPMfixed.c

    r39612 r39926  
    5454  }
    5555
     56  fit->useWeight = FALSE; // Ordinary Least Squares
    5657  if (!FitPosPMfixed_MinChisq (fit, data, points, Npoints)) {
    5758    if (!FitPosPMfixed_Single (fit, points, Npoints)) return FALSE;
     
    8384 
    8485  // Solve OLS equation 
     86  fit->useWeight = FALSE; // Ordinary Least Squares
    8587  if (!FitPosPMfixed_MinChisq(fit, data, points, Npoints)) {
    8688    return(FALSE);
     
    105107
    106108  // Iteratively reweight and solve
    107   double sigma_hat = 0.0; // save for the error model
     109  // double sigma_hat = 0.0; // save for the error model
    108110  int converged = FALSE;
    109111  int iterations = 0;
     
    126128
    127129    // Solve with the new weights
     130    fit->useWeight = TRUE; // Reweighted Least Squares
    128131    if (!FitPosPMfixed_MinChisq(fit, data, points, Npoints)) {
    129132
     
    138141        points[i].u = sqrt(SQ(points[i].rx / points[i].dX) + SQ(points[i].ry / points[i].dY));
    139142      }
    140       sigma_hat = MedianAbsDeviation(points, Npoints) / 0.6745;
     143      // sigma_hat = MedianAbsDeviation(points, Npoints) / 0.6745;
    141144      break;
    142145    }
     
    153156      points[i].u = sqrt(SQ(points[i].rx / points[i].dX) + SQ(points[i].ry / points[i].dY));
    154157    }
    155     sigma_hat = MedianAbsDeviation(points, Npoints) / 0.6745;
     158    // sigma_hat = MedianAbsDeviation(points, Npoints) / 0.6745;
    156159   
    157160    // Check convergence
     
    193196  // NOTE EAM: in tests (fitpm.c), they seem to be too large by a factor of ~5.37
    194197  if (data->getError) {
    195     double ax = 0.0, ay = 0.0;
    196     double bx = 0.0, by = 0.0;
    197 
    198     for (i = 0; i < Npoints; i++) {
    199       ax += dpsi_cauchy(points[i].rx / points[i].dX);
    200       ay += dpsi_cauchy(points[i].ry / points[i].dY);
    201 
    202       bx += SQ(points[i].Wx);
    203       by += SQ(points[i].Wy);
    204     }
    205     ax /= 1.0 * Npoints;  // mean(psi_dot(r))
    206     ay /= 1.0 * Npoints;
    207     bx /= 1.0 * (Npoints - data->Nterms); // mean(psi^2(r)) * (N / (N-p))
    208     by /= 1.0 * (Npoints - data->Nterms);
    209  
    210     double lambda_x = 1.0 + (data->Nterms / Npoints) * (1 - ax) / ax;
    211     double lambda_y = 1.0 + (data->Nterms / Npoints) * (1 - ay) / ay;
    212  
    213     double sigma_robust_x = lambda_x * sqrt(bx) * sigma_hat * 2.385 / ax;
    214     double sigma_robust_y = lambda_y * sqrt(by) * sigma_hat * 2.385 / ay;
    215 
    216     // This is actually sigma^2, as that's the factor in the covariance (dumouchel 4.1)
    217     double sigma_final_x  = MAX(SQ(sigma_robust_x), (2 * Npoints * SQ(sigma_robust_x) + SQ(data->Nterms * sigma_ols)) / (2 * Npoints + SQ(data->Nterms)));
    218     double sigma_final_y  = MAX(SQ(sigma_robust_y), (2 * Npoints * SQ(sigma_robust_y) + SQ(data->Nterms * sigma_ols)) / (2 * Npoints + SQ(data->Nterms)));
    219 
    220     fit[0].dRo = sqrt(data->Cov[0][0]);
    221     fit[0].dDo = sqrt(data->Cov[1][1]);
    222 
    223     fit[0].dRo *= sigma_final_x;
    224     fit[0].dDo *= sigma_final_y;
     198    FitAstromResult fitErrors;
     199    FitAstromResultInit (&fitErrors);
     200    fitErrors.useWeight = FALSE;
     201
     202    FitPosPMfixed_MinChisq(&fitErrors, data, points, Npoints);
     203
     204    // we use the errors from a simple OLS, ignoring masked points
     205    fit[0].dRo = fitErrors.dRo;
     206    fit[0].duR = fitErrors.duR;
     207    fit[0].dDo = fitErrors.dDo;
     208    fit[0].duD = fitErrors.duD;
     209    fit[0].dp  = fitErrors.dp;
    225210  }
    226211
     
    242227    Nfit ++;
    243228
    244     wx = points[i].qx;
    245     wy = points[i].qy;
     229    if (fit->useWeight) {
     230      wx = points[i].qx;
     231      wy = points[i].qy;
     232    } else {
     233      wx = points[i].Qx;
     234      wy = points[i].Qy;
     235    }
    246236
    247237    Wx += wx;
  • trunk/Ohana/src/relastro/src/GetAstromError.c

    r39457 r39926  
    4848  if (isnan(code[0].astromErrSys)) return NAN;
    4949
     50  if (measure[0].photcode == 1030) {
     51    if (mode == ERROR_MODE_RA) {
     52      dPobs = pow(10.0, (6.0 * measure[0].dXccd - 3.0));  // dXccd is a value in pixels
     53    }
     54    if (mode == ERROR_MODE_DEC) {
     55      dPobs = pow(10.0, (6.0 * measure[0].dYccd - 3.0));  // dXccd is a value in pixels
     56    }
     57  }
     58
    5059  AS    = code[0].astromErrScale;
    5160  MS    = code[0].astromErrMagScale;
     
    6978  // to match the 2MASS / Tycho / ICRS reference frame.  As Nloop gets higher, the weight
    7079  // needs to drop to allow the ps1 measurements to drive the solution
     80  int isGAIA   = USE_GALAXY_MODEL && !isImage && (measure[0].photcode == 1030);
    7181  int is2MASS  = USE_GALAXY_MODEL && !isImage && (measure[0].photcode >= 2011) && (measure[0].photcode <= 2013);
    7282  int isTycho  = USE_GALAXY_MODEL && !isImage && (measure[0].photcode >= 2020) && (measure[0].photcode <= 2021);
     83
     84  int hasGAIA  = USE_GALAXY_MODEL &&  isImage && (measure[0].dbFlags & ID_MEAS_OBJECT_HAS_GAIA);
    7385  int has2MASS = USE_GALAXY_MODEL &&  isImage && (measure[0].dbFlags & ID_MEAS_OBJECT_HAS_2MASS);
     86  int hasTycho = USE_GALAXY_MODEL &&  isImage && (measure[0].dbFlags & ID_MEAS_OBJECT_HAS_TYCHO);
    7487
    7588  // modest hack: if the object has 2MASS or Tycho, we set this internal bit and adjust the
     
    7992    dPtotal = dPtotal / LoopWeight2MASS[Nloop];
    8093  }
     94  if (hasGAIA && LoopWeightGAIA && (Nloop >= 0)) {
     95    dPtotal = dPtotal / LoopWeightGAIA[Nloop];
     96  }
     97  if (hasTycho && LoopWeightTycho && (Nloop >= 0)) {
     98    dPtotal = dPtotal / LoopWeightTycho[Nloop];
     99  }
     100
    81101  if (is2MASS && LoopWeight2MASS && (Nloop >= 0)) {
    82102    dPtotal = dPtotal / LoopWeight2MASS[Nloop];
     103  }
     104  if (isGAIA && LoopWeightGAIA && (Nloop >= 0)) {
     105    dPtotal = dPtotal / LoopWeightGAIA[Nloop];
    83106  }
    84107  if (isTycho && LoopWeightTycho && (Nloop >= 0)) {
     
    120143  // do not raise an exception, just send back the result
    121144  if (isnan(code[0].astromErrSys)) return NAN;
     145
     146  if (measure[0].photcode == 1030) {
     147    if (mode == ERROR_MODE_RA) {
     148      dPobs = pow(10.0, (6.0 * measure[0].dXccd - 3.0));  // dXccd is a value in pixels
     149    }
     150    if (mode == ERROR_MODE_DEC) {
     151      dPobs = pow(10.0, (6.0 * measure[0].dYccd - 3.0));  // dXccd is a value in pixels
     152    }
     153  }
    122154
    123155  AS    = code[0].astromErrScale;
     
    143175  // to match the 2MASS / Tycho / ICRS reference frame.  As Nloop gets higher, the weight
    144176  // needs to drop to allow the ps1 measurements to drive the solution
     177  int isGAIA   = USE_GALAXY_MODEL && !isImage && (measure[0].photcode == 1030);
    145178  int is2MASS  = USE_GALAXY_MODEL && !isImage && (measure[0].photcode >= 2011) && (measure[0].photcode <= 2013);
    146179  int isTycho  = USE_GALAXY_MODEL && !isImage && (measure[0].photcode >= 2020) && (measure[0].photcode <= 2021);
     180
     181  int hasGAIA  = USE_GALAXY_MODEL &&  isImage && (measure[0].dbFlags & ID_MEAS_OBJECT_HAS_GAIA);
    147182  int has2MASS = USE_GALAXY_MODEL &&  isImage && (measure[0].dbFlags & ID_MEAS_OBJECT_HAS_2MASS);
     183  int hasTycho = USE_GALAXY_MODEL &&  isImage && (measure[0].dbFlags & ID_MEAS_OBJECT_HAS_TYCHO);
    148184
    149185  // modest hack: if the object has 2MASS or Tycho, we set this internal bit and adjust the
     
    153189    dPtotal = dPtotal / LoopWeight2MASS[Nloop];
    154190  }
     191  if (hasGAIA && LoopWeightGAIA && (Nloop >= 0)) {
     192    dPtotal = dPtotal / LoopWeightGAIA[Nloop];
     193  }
     194  if (hasTycho && LoopWeightTycho && (Nloop >= 0)) {
     195    dPtotal = dPtotal / LoopWeightTycho[Nloop];
     196  }
     197
    155198  if (is2MASS && LoopWeight2MASS) {
    156199    dPtotal = dPtotal / LoopWeight2MASS[Nloop];
     200  }
     201  if (isGAIA && LoopWeightGAIA && (Nloop >= 0)) {
     202    dPtotal = dPtotal / LoopWeightGAIA[Nloop];
    157203  }
    158204  if (isTycho && LoopWeightTycho) {
  • trunk/Ohana/src/relastro/src/ImageOps.c

    r39580 r39926  
    66static Image        *image;   // list of available images
    77static off_t        Nimage;   // number of available images
     8static int         isImageSubset;
    89
    910// if we read only a subset of the rows from the Image FITS, LineNumber tells us to which row
     
    7879}
    7980
    80 void initImages (Image *input, off_t *line_number, off_t N) {
     81void initImages (Image *input, off_t *line_number, off_t N, int isSubset) {
    8182
    8283  off_t i;
    8384
     85  isImageSubset = isSubset;
    8486  image = input;
    8587  LineNumber = line_number;
     
    136138  // we call gfits_db_free as well as this function.  sometimes those point at the same
    137139  // memory location, in which case we should only do the free once.
    138   if ((void *) dbImagePtr != (void *) image) free (image);
     140  if (((void *) dbImagePtr != (void *) image) && isImageSubset) free (image);
    139141  free_astrom_table();
    140142}
     
    793795    ref[i].D = catalog[c].average[n].D;
    794796   
     797    int XVERB = FALSE;
     798    XVERB |= (catalog[c].average[n].objID == OBJ_ID_SRC) && (catalog[c].average[n].catID == CAT_ID_SRC);
     799    XVERB |= (catalog[c].average[n].objID == OBJ_ID_DST) && (catalog[c].average[n].catID == CAT_ID_DST);
     800    if (XVERB) {
     801      fprintf (stderr, "found test object\n");
     802    }
     803
    795804    // if we are applying the galaxy model, move the reference position...
    796     if (USE_GALAXY_MODEL) {
     805    if (APPLY_PROPER_MOTION) {
    797806      // apply proper-motion from average position to measure epoch:
    798807      float dTime = (measure[0].t - catalog[c].average[n].Tmean) / (86400*365.25) ; // time relative to Tmean in years
     
    934943}
    935944
    936 # if (0)
    937 /** lifted from relphot/StarOps.clean_measures */
    938 void FlagOutliers2D(Catalog *catalog);
    939 
    940 // operates on Full values (not tiny)
    941 void FlagOutliers (Catalog *catalog) {
    942 
    943   // XXX FlagOutliers is now just using FlagOutliers2D
    944   FlagOutliers2D(catalog);
    945   return;
    946 
    947   int Ndel, Nave;
    948   off_t i, j, k, m, N, Nmax, TOOFEW, Nsecfilt;
    949   double Ns, theta, x, y;
    950   double *R, *D, *dR, *dD;
    951   StatType statsR, statsD;
    952 
    953   Nsecfilt = GetPhotcodeNsecfilt();
    954   assert(catalog[0].Nsecfilt == Nsecfilt);
    955 
    956   if (VERBOSE2) fprintf (stderr, "marking poor measures\n");
    957   Nmax = 0;
    958   for (i = 0; i < catalog[0].Naverage; i++) {
    959     Nmax = MAX (Nmax, catalog[0].average[i].Nmeasure);
    960   }
    961 
    962   ALLOCATE (R, double, Nmax);
    963   ALLOCATE (D, double, Nmax);
    964   ALLOCATE (dR, double, Nmax);
    965   ALLOCATE (dD, double, Nmax);
    966 
    967   /* it makes no sense to mark 3-sigma outliers with <5 measurements */
    968   TOOFEW = MAX (5, SRC_MEAS_TOOFEW);
    969 
    970   Ns = CLIP_THRESH;
    971   Ndel = Nave = 0;
    972      
    973   /* loop over each object in the catalog */
    974   for (j = 0; j < catalog[0].Naverage; j++) {
    975    
    976     // pointer to this set of measurements
    977     m = catalog[0].average[j].measureOffset;
    978     Measure *measure = &catalog[0].measure[m];
    979 
    980     /* accumulate list of valid measurements */
    981     N = 0;
    982     for (k = 0; k < catalog[0].average[j].Nmeasure; k++) {
    983       // skip measurements based on user selected criteria
    984       if (!MeasFilterTest(&measure[k], FALSE)) continue;
    985       R[N] = measure[k].R;
    986       D[N] = measure[k].D;
    987       dR[N] = GetAstromError (&measure[k], ERROR_MODE_RA);
    988       dD[N] = GetAstromError (&measure[k], ERROR_MODE_DEC);
    989       if (isnan(R[N]) || isnan(D[N])) continue;
    990       N++;
    991     }
    992     if (N <= TOOFEW) continue;
    993    
    994     /* 3-sigma clip based on stats of inner 50% */
    995     initstats ("MEAN");
    996     liststats (R, dR, N, &statsR);
    997     liststats (D, dD, N, &statsD);
    998    
    999     statsR.sigma = MAX (MIN_ERROR, statsR.sigma);
    1000     statsD.sigma = MAX (MIN_ERROR, statsD.sigma);
    1001    
    1002     /* compare per-object distance to this standard deviation, and flag outliers*/
    1003     N = 0;
    1004     for (k = 0; k < catalog[0].average[j].Nmeasure; k++) {
    1005       // reset flag on each invocation
    1006       measure[k].dbFlags &= ~ID_MEAS_POOR_ASTROM;
    1007 
    1008       // skip measurements based on user selected criteria
    1009       if (!MeasFilterTest(&measure[k], FALSE)) continue;
    1010      
    1011       x = measure[k].R - statsR.median;
    1012       y = measure[k].D - statsD.median;
    1013       theta = atan2(y,x);
    1014       if ((x*x + y*y) > (SQR(statsR.sigma * Ns * cos(theta)) +
    1015                          SQR(statsD.sigma * Ns * sin(theta)))) {   
    1016         measure[k].dbFlags |= ID_MEAS_POOR_ASTROM;
    1017         Ndel++;
    1018       }
    1019       N++;
    1020       Nave ++;
    1021     }
    1022 
    1023     // examine results
    1024     // relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset, catalog[0].average[j].Nmeasure, statsR, statsD, Ns);
    1025   }
    1026  
    1027   if (VERBOSE) fprintf (stderr, "%d measures marked poor, %d total\n", Ndel, Nave);
    1028   free (R);
    1029   free (dR);
    1030   free (D);
    1031   free (dD);
    1032 }
    1033 
    1034 
    1035 /** an alternative outlier rejection scheme */
    1036 void FlagOutliers2D (Catalog *catalog) {
    1037 
    1038   int Ndel, Nave;
    1039   off_t i, j, k, m, N, Nmax, TOOFEW, Nsecfilt;
    1040   double *index;
    1041   double Ns, theta, x, y;
    1042   double *R, *D, *dR, *dD, *d2;
    1043   StatType statsR, statsD;
    1044 
    1045   // XXX we are not going to use this for now
    1046   return;
    1047 
    1048   Nsecfilt = GetPhotcodeNsecfilt();
    1049   assert(catalog[0].Nsecfilt == Nsecfilt);
    1050 
    1051   if (VERBOSE2) fprintf (stderr, "marking poor measures\n");
    1052   Nmax = 0;
    1053   for (i = 0; i < catalog[0].Naverage; i++) {
    1054     Nmax = MAX (Nmax, catalog[0].average[i].Nmeasure);
    1055   }
    1056 
    1057   ALLOCATE (R, double, Nmax);
    1058   ALLOCATE (D, double, Nmax);
    1059   ALLOCATE (dR, double, Nmax);
    1060   ALLOCATE (dD, double, Nmax);
    1061   ALLOCATE (d2, double, Nmax);
    1062   ALLOCATE (index, double, Nmax);
    1063 
    1064   /* it makes no sense to mark 3-sigma outliers with <5 measurements */
    1065   TOOFEW = MAX (5, SRC_MEAS_TOOFEW);
    1066 
    1067   Ns = CLIP_THRESH;
    1068   Ndel = Nave = 0;
    1069      
    1070   /* loop over each object in the catalog */
    1071   for (j = 0; j < catalog[0].Naverage; j++) {
    1072    
    1073     // pointer to this set of measurements
    1074     m = catalog[0].average[j].measureOffset;
    1075     Measure *measure = &catalog[0].measure[m];
    1076 
    1077     /* accumulate list of valid measurements */
    1078     N = 0;
    1079     for (k = 0; k < catalog[0].average[j].Nmeasure; k++) {
    1080 
    1081       // reset flag on each invocation
    1082       measure[k].dbFlags &= ~ID_MEAS_POOR_ASTROM;
    1083      
    1084       // skip measurements based on user selected criteria
    1085       if (!MeasFilterTest(&measure[k], FALSE)) continue;
    1086       R[N] = measure[k].R;
    1087       D[N] = measure[k].D;
    1088       dR[N] = GetAstromError(&measure[k], ERROR_MODE_RA);
    1089       dD[N] = GetAstromError(&measure[k], ERROR_MODE_DEC);
    1090       if (isnan(R[N]) || isnan(D[N])) continue;
    1091       N++;
    1092     }
    1093     if (N <= TOOFEW) continue;
    1094    
    1095     /* calculate mean of all points*/
    1096     initstats ("MEAN");
    1097     liststats (R, dR, N, &statsR);
    1098     liststats (D, dD, N, &statsD);
    1099     statsR.sigma = MAX (MIN_ERROR, statsR.sigma);
    1100     statsD.sigma = MAX (MIN_ERROR, statsD.sigma);
    1101    
    1102     /* calculate deviations of all points*/
    1103     N = 0;
    1104     for (k = 0; k < catalog[0].average[j].Nmeasure; k++) {
    1105       // skip bad measurements
    1106       if (!MeasFilterTest(&measure[k], FALSE)) continue; 
    1107       x = measure[k].R - statsR.median;
    1108       y = measure[k].D - statsD.median;
    1109       theta = atan2(y,x);
    1110       d2[N] = (x*x + y*y) / (SQR(statsR.sigma * Ns * cos(theta)) +
    1111                              SQR(statsD.sigma * Ns * sin(theta)));     
    1112       index[N] = k;
    1113       N++;
    1114     }
    1115    
    1116     // sort d2
    1117     dsortpair(d2, index, N);
    1118     N = (N/2 > (N-1)) ? N/2 : N-1;
    1119 
    1120     // recalculate image center, sigma based on closest 50% of points
    1121     for (k = 0;  k < N; k++) {
    1122       off_t ind = (off_t) index[k];
    1123       R[k] = measure[ind].R;
    1124       D[k] = measure[ind].D;
    1125       dR[k] = GetAstromError(&measure[ind], ERROR_MODE_RA);
    1126       dD[k] = GetAstromError(&measure[ind], ERROR_MODE_DEC);
    1127     }
    1128     liststats (R, dR, N, &statsR);
    1129     liststats (D, dD, N, &statsD);
    1130     statsR.sigma = MAX (MIN_ERROR, statsR.sigma);
    1131     statsD.sigma = MAX (MIN_ERROR, statsD.sigma);
    1132    
    1133     // use these new statistics to flag outliers
    1134     N = 0;
    1135     for (k = 0; k < catalog[0].average[j].Nmeasure; k++) {
    1136       //skip bad measurements
    1137       if (!MeasFilterTest(&measure[k], FALSE)) continue; 
    1138       x = measure[k].R - statsR.median;
    1139       y = measure[k].D - statsD.median;
    1140       theta = atan2(y,x);
    1141       d2[N] = (x*x + y*y) / (SQR(statsR.sigma * Ns * cos(theta)) +
    1142                              SQR(statsD.sigma * Ns * sin(theta)));     
    1143       if ((d2[N]) > 1) {
    1144         measure[k].dbFlags |= ID_MEAS_POOR_ASTROM;
    1145         Ndel ++;
    1146       }
    1147       N++;
    1148       Nave++;
    1149     }  // done rejecting outliers
    1150 
    1151     // examine results
    1152     // relastroVisualPlotOutliers(catalog, catalog[0].average[j].measureOffset, catalog[0].average[j].Nmeasure, statsR, statsD, Ns);
    1153    
    1154   } // done looping over objects
    1155  
    1156   if (VERBOSE) fprintf (stderr, "%d measures marked poor, %d total\n", Ndel, Nave);
    1157   free (R);
    1158   free (dR);
    1159   free (D);
    1160   free (dD);
    1161   free (d2);
    1162   free (index);
    1163 }
    1164 
    1165 /** Determine whether a measurement should be included in the analysis, based on supplied filter criteria */
    1166 // we only optionally apply the sigma limit: for object averages, this should not be used
    1167 int MeasFilterTestTiny(MeasureTiny *measure, int applySigmaLim) {
    1168   int found, k;
    1169   long mask;
    1170   PhotCode *code;
    1171   float mag;
    1172 
    1173   if (!finite(measure[0].R) || !finite(measure[0].D)) return FALSE;
    1174   if (!finite(measure[0].M)) return FALSE; //XXX is this necessary for all relastro tasks?
    1175   if (!finite(measure[0].dM)) return FALSE; //XXX is this necessary for all relastro tasks?
    1176  
    1177   if ((MinBadQF > 0.0) && (isGPC1chip(measure[0].photcode) || isGPC1stack(measure[0].photcode))) {
    1178     if (!isfinite(measure[0].psfQF)) { return FALSE; };
    1179     if (measure[0].psfQF < MinBadQF) { return FALSE; };
    1180   }
    1181 
    1182   /* select measurements by photcode, or equiv photcode, if specified */
    1183   if (NphotcodesKeep > 0) {
    1184     found = FALSE;
    1185     for (k = 0; (k < NphotcodesKeep) && !found; k++) {
    1186       if (photcodesKeep[k][0].code == measure[0].photcode) found = TRUE;
    1187       if (photcodesKeep[k][0].code == GetPhotcodeEquivCodebyCode(measure[0].photcode)) found = TRUE;
    1188     }
    1189     if (!found) return FALSE;
    1190   }
    1191  
    1192   if (NphotcodesSkip > 0) {
    1193     found = FALSE;
    1194     for (k = 0; (k < NphotcodesSkip) && !found; k++) {
    1195       if (photcodesSkip[k][0].code == measure[0].photcode) found = TRUE;
    1196       if (photcodesSkip[k][0].code == GetPhotcodeEquivCodebyCode(measure[0].photcode)) found = TRUE;
    1197     }
    1198     if (found) return FALSE;
    1199   } 
    1200  
    1201   /* select measurements by time */
    1202   if (TimeSelect) {
    1203     if (measure[0].t < TSTART) return FALSE;
    1204     if (measure[0].t > TSTOP) return FALSE;
    1205   }
    1206  
    1207   /* select measurements by quality */
    1208   if (PhotFlagSelect) {
    1209     if (PhotFlagBad) {
    1210       mask = PhotFlagBad;
    1211     } else {
    1212       code = GetPhotcodebyCode (measure[0].photcode);
    1213       if (!code) return FALSE;
    1214       mask = code[0].astromBadMask;
    1215     }
    1216     if (mask & measure[0].photFlags) return FALSE;
    1217   }
    1218 
    1219   /* select measurements by measurement error */
    1220   // this is a bit convoluted: applySigmaLim is only TRUE when this function is
    1221   // called by bcatalog.  for UpdateObjects, it is FALSE
    1222   if (applySigmaLim && (SIGMA_LIM > 0) && (measure[0].dM > SIGMA_LIM)) {
    1223     return FALSE;
    1224   }
    1225  
    1226   /* select measurements by mag limit */
    1227   if (ImagSelect) {
    1228     mag = PhotInstTiny (measure, MAG_CLASS_PSF);
    1229     if (mag < ImagMin || mag > ImagMax) return FALSE;
    1230   }
    1231  
    1232   return TRUE;
    1233 }
    1234 
    1235 # define SUPER_VERBOSE 0
    1236 
    1237 /** Determine whether a measurement should be included in the analysis, based on supplied filter criteria */
    1238 // we only optionally apply the sigma limit: for object averages, this should not be used (should it?)
    1239 int MeasFilterTest(Measure *measure, int applySigmaLim) {
    1240   int found, k;
    1241   long mask;
    1242   PhotCode *code;
    1243   float mag;
    1244 
    1245   if (!finite(measure[0].R) || !finite(measure[0].D)) { if (SUPER_VERBOSE) fprintf (stderr, "filter 1\n"); return FALSE; };
    1246   if (!finite(measure[0].M)) { if (SUPER_VERBOSE) fprintf (stderr, "filter 2\n"); return FALSE; }; //XXX is this necessary for all relastro tasks?
    1247   if (!finite(measure[0].dM)) { if (SUPER_VERBOSE) fprintf (stderr, "filter 3\n"); return FALSE; }; //XXX is this necessary for all relastro tasks?
    1248  
    1249   /* select measurements by photcode, or equiv photcode, if specified */
    1250   if (NphotcodesKeep > 0) {
    1251     found = FALSE;
    1252     for (k = 0; (k < NphotcodesKeep) && !found; k++) {
    1253       if (photcodesKeep[k][0].code == measure[0].photcode) found = TRUE;
    1254       if (photcodesKeep[k][0].code == GetPhotcodeEquivCodebyCode(measure[0].photcode)) found = TRUE;
    1255     }
    1256     if (!found) { if (SUPER_VERBOSE) fprintf (stderr, "filter 4\n"); return FALSE; };
    1257   }
    1258  
    1259   if (NphotcodesSkip > 0) {
    1260     found = FALSE;
    1261     for (k = 0; (k < NphotcodesSkip) && !found; k++) {
    1262       if (photcodesSkip[k][0].code == measure[0].photcode) found = TRUE;
    1263       if (photcodesSkip[k][0].code == GetPhotcodeEquivCodebyCode(measure[0].photcode)) found = TRUE;
    1264     }
    1265     if (found) { if (SUPER_VERBOSE) fprintf (stderr, "filter 5\n"); return FALSE; };
    1266   } 
    1267  
    1268   if ((MinBadQF > 0.0) && isGPC1chip(measure[0].photcode)) {
    1269     if (!isfinite(measure[0].psfQF)) { if (SUPER_VERBOSE) fprintf (stderr, "filter 6\n"); return FALSE; };
    1270     if (measure[0].psfQF < MinBadQF) { if (SUPER_VERBOSE) fprintf (stderr, "filter 7\n"); return FALSE; };
    1271   }
    1272 
    1273   /* select measurements by time */
    1274   if (TimeSelect) {
    1275     if (measure[0].t < TSTART) { if (SUPER_VERBOSE) fprintf (stderr, "filter 8\n"); return FALSE; };
    1276     if (measure[0].t > TSTOP) { if (SUPER_VERBOSE) fprintf (stderr, "filter 9\n"); return FALSE; };
    1277   }
    1278  
    1279   /* select measurements by quality */
    1280   if (PhotFlagSelect) {
    1281     if (PhotFlagBad) {
    1282       mask = PhotFlagBad;
    1283     } else {
    1284       code = GetPhotcodebyCode (measure[0].photcode);
    1285       if (!code) { if (SUPER_VERBOSE) fprintf (stderr, "filter 10\n"); return FALSE; };
    1286       mask = code[0].astromBadMask;
    1287     }
    1288     if (mask & measure[0].photFlags) { if (SUPER_VERBOSE) fprintf (stderr, "filter 11\n"); return FALSE; };
    1289   }
    1290 
    1291   /* select measurements by measurement error */
    1292   if (applySigmaLim && (SIGMA_LIM > 0) && (measure[0].dM > SIGMA_LIM)) {
    1293     { if (SUPER_VERBOSE) fprintf (stderr, "filter 12\n"); return FALSE; };
    1294   }
    1295  
    1296   /* select measurements by mag limit */
    1297   if (ImagSelect) {
    1298     mag = PhotInst (measure, MAG_CLASS_PSF);
    1299     if (mag < ImagMin || mag > ImagMax) { if (SUPER_VERBOSE) fprintf (stderr, "filter 13\n"); return FALSE; };
    1300   }
    1301  
    1302   return TRUE;
    1303 }
    1304 # endif
  • trunk/Ohana/src/relastro/src/StarMaps.c

    r39457 r39926  
    166166  dLmax = dMmax = 0.0;
    167167
     168  float plateScale;
     169  if (images[N].coords.mosaic) {
     170    // NOTE: for the full pixel to sky plate scale, use this:
     171    // float plateScaleX = 3600.0*images[N].coords.mosaic->cdelt1*images[N].coords.cdelt1;
     172    // float plateScaleY = 3600.0*images[N].coords.mosaic->cdelt2*images[N].coords.cdelt2;
     173
     174    // since we are compare L,M values, just need to compensate for focal plate to sky:
     175    float plateScaleX = 3600.0*fabs(images[N].coords.mosaic->cdelt1);
     176    float plateScaleY = 3600.0*fabs(images[N].coords.mosaic->cdelt2);
     177    plateScale = 0.5*(plateScaleX + plateScaleY);
     178  } else {
     179    // since we are compare L,M values, just need to compensate for arcsec vs degrees:
     180    plateScale = 3600.0;
     181  }
     182
    168183  for (i = 0; i < starmap[N].Npoints; i++) {
    169184
     
    171186    XY_to_LM (&L, &M, starmap[N].points[i].X, starmap[N].points[i].Y, &images[N].coords);
    172187
    173     starmap[N].points[i].dL = starmap[N].points[i].L - L;
    174     starmap[N].points[i].dM = starmap[N].points[i].M - M;
     188    starmap[N].points[i].dL = plateScale*(starmap[N].points[i].L - L);
     189    starmap[N].points[i].dM = plateScale*(starmap[N].points[i].M - M);
    175190
    176191    dLmax = MAX(fabs(starmap[N].points[i].dL), dLmax);
  • trunk/Ohana/src/relastro/src/UpdateChips.c

    r39457 r39926  
    4242  AstromErrorSetLoop (Nloop, TRUE);
    4343
     44  // if ChipMapLoop or ChipOrderLoop is set use that to define the value of CHIPMAP and/or CHIPORDER this loop
     45  if (ChipMapLoop) { CHIPMAP = ChipMapLoop[Nloop]; }
     46  if (ChipOrderLoop) { CHIPORDER = ChipOrderLoop[Nloop]; }
     47 
    4448  if (NTHREADS) {
    4549    UpdateChips_threaded (catalog, Ncatalog);
     
    6064  for (i = 0; i < Nimage; i++) {
    6165
    62     VERBOSE_IMAGE = !strcmp(image[i].name, "o5745g0516o.356887.cm.982631.smf[XY54]");
     66    VERBOSE = FALSE;
     67    VERBOSE_IMAGE |= !strcmp(image[i].name, "o5745g0516o.356887.cm.982631.smf[XY45]");
     68    VERBOSE_IMAGE |= !strcmp(image[i].name, "o5745g0526o.356899.cm.982643.smf[XY45]");
     69    VERBOSE_IMAGE |= !strcmp(image[i].name, "o5748g0436o.358811.cm.982690.smf[XY34]");
    6370
    6471    // XXX looks like everything below is thread safe : we can unroll this into a set of
    6572    // helper functions that grab the next available chip....
    6673
     74    // allow certain cameras to stay static
     75    if (SKIP_PS1_CHIP  && isGPC1chip (image[i].photcode)) { Nskip ++;  mode[i] = 0; continue; }
     76    if (SKIP_PS1_STACK && isGPC1stack(image[i].photcode)) { Nskip ++;  mode[i] = 0; continue; }
     77    if (SKIP_HSC       && isHSCchip  (image[i].photcode)) { Nskip ++;  mode[i] = 0; continue; }
     78    if (SKIP_CFH       && isCFHchip  (image[i].photcode)) { Nskip ++;  mode[i] = 0; continue; }
     79   
    6780    /* skip all except WRP images */
    6881    if (strcmp(&image[i].coords.ctype[4], "-WRP")) {
     
    160173    setImageRaw (catalog, Ncatalog, i, raw, Nraw, MODE_MOSAIC);
    161174    if (USE_GALAXY_MODEL) {
    162       // XXX DEPRECATE?
     175      // the image calibration was calculated using a galaxy motion model
    163176      image[i].flags |= ID_IMAGE_ASTROM_GMM;
    164177    }
     
    281294    }
    282295
     296    // allow certain cameras to stay static
     297    if (SKIP_PS1_CHIP  && isGPC1chip (image[i].photcode)) { threadinfo->Nskip ++;  threadinfo->mode[i] = 0; continue; }
     298    if (SKIP_PS1_STACK && isGPC1stack(image[i].photcode)) { threadinfo->Nskip ++;  threadinfo->mode[i] = 0; continue; }
     299    if (SKIP_HSC       && isHSCchip  (image[i].photcode)) { threadinfo->Nskip ++;  threadinfo->mode[i] = 0; continue; }
     300    if (SKIP_CFH       && isCFHchip  (image[i].photcode)) { threadinfo->Nskip ++;  threadinfo->mode[i] = 0; continue; }
     301   
    283302    /* skip all except WRP images */
    284303    if (strcmp(&image[i].coords.ctype[4], "-WRP")) {
  • trunk/Ohana/src/relastro/src/UpdateMeasures.c

    r39624 r39926  
    115115
    116116      // only modify the chip coordinates
    117       if (isGPC1chip (measureT->photcode)) {
     117      if (UPDATE_PS1_STACK_MEASURE && isGPC1stack (measureT->photcode)) {
     118        measureT->R = R;
     119        measureT->D = D;
     120        if (measureB) {
     121          measureB->R = R;
     122          measureB->D = D;
     123        }
     124      }
     125      // only modify the chip coordinates
     126      if (UPDATE_PS1_CHIP_MEASURE && isGPC1chip (measureT->photcode)) {
     127        measureT->R = R;
     128        measureT->D = D;
     129        if (measureB) {
     130          measureB->R = R;
     131          measureB->D = D;
     132        }
     133      }
     134      // only modify the chip coordinates
     135      if (UPDATE_HSC_MEASURE && isGPC1chip (measureT->photcode)) {
     136        measureT->R = R;
     137        measureT->D = D;
     138        if (measureB) {
     139          measureB->R = R;
     140          measureB->D = D;
     141        }
     142      }
     143      // only modify the chip coordinates
     144      if (UPDATE_CFH_MEASURE && isGPC1chip (measureT->photcode)) {
    118145        measureT->R = R;
    119146        measureT->D = D;
  • trunk/Ohana/src/relastro/src/UpdateObjectOffsets.c

    r39693 r39926  
    167167    strextend (&command, "relastro_client -update-offsets");
    168168    strextend (&command, "-hostID %d", group->hosts[i][0].hostID);
     169    strextend (&command, "-hostdir %s", group->hosts[i][0].pathname);
     170
    169171    strextend (&command, "-D CATDIR %s", CATDIR);
    170     strextend (&command, "-hostdir %s", group->hosts[i][0].pathname);
    171172    strextend (&command, "-region %f %f %f %f", UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    172173    strextend (&command, "-statmode %s", STATMODE);
    173174    strextend (&command, "-minerror %f", MIN_ERROR);
    174175
     176    strextend (&command, "-D RELASTRO_SIGMA_LIM %f", SIGMA_LIM);
     177    strextend (&command, "-D RELASTRO_SRC_MEAS_TOOFEW %d", SRC_MEAS_TOOFEW);
     178
    175179    if (FIT_MODE == FIT_PM_ONLY)         strextend (&command, "-pm");
    176180    if (FIT_MODE == FIT_PAR_ONLY)        strextend (&command, "-par");
     
    180184    if (VERBOSE2)      strextend (&command, "-vv");
    181185    if (RESET)         strextend (&command, "-reset");
    182     if (UPDATE)        strextend (&command, "-update");
    183 
    184     if (RESET_BAD_IMAGES) strextend (&command, "-reset-bad-images");
    185186
    186187    if (ImagSelect)    strextend (&command, "-instmag %f %f", ImagMin, ImagMax);
    187188    if (MaxDensityUse) strextend (&command, "-max-density %f", MaxDensityValue);
    188    
    189     if (USE_BASIC_CHECK) strextend (&command, "-basic-image-search");
    190189    if (FlagOutlier)     strextend (&command, "-clip %d", CLIP_THRESH);
    191190    if (ExcludeBogus)    strextend (&command, "-exclude-bogus %f", ExcludeBogusRadius);
    192191   
    193     if (USE_ALL_IMAGES)      strextend (&command, "-use-all-images");
    194192    if (USE_FIXED_PIXCOORDS) strextend (&command, "-D USE_FIXED_PIXCOORDS 1");
    195 
    196     if (REPAIR_STACKS)          strextend (&command, "-repair-stacks-on-update");
    197     if (CHECK_MEASURE_TO_IMAGE) strextend (&command, "-check-measures");
    198 
    199193    if (PHOTCODE_KEEP_LIST) strextend (&command, "+photcode %s", PHOTCODE_KEEP_LIST);
    200194    if (PHOTCODE_SKIP_LIST) strextend (&command, "-photcode %s", PHOTCODE_SKIP_LIST);
     
    204198    // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
    205199
    206     if (N_BOOTSTRAP_SAMPLES > 1) strextend (&command, "-bootstrap-samples %d", N_BOOTSTRAP_SAMPLES);
    207 
    208200    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
    209201      strextend (&command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     
    213205    }
    214206
     207    if (REPAIR_STACKS)          strextend (&command, "-repair-stacks-on-update");
     208    if (CHECK_MEASURE_TO_IMAGE) strextend (&command, "-check-measures");
     209
     210    if (UPDATE_PS1_STACK_MEASURE) strextend (&command, "-update-ps1-stack");
     211    if (UPDATE_PS1_CHIP_MEASURE) strextend (&command, "-update-ps1-chip");
     212    if (UPDATE_HSC_MEASURE)      strextend (&command, "-update-hsc");
     213    if (UPDATE_CFH_MEASURE)      strextend (&command, "-update-cfh");
     214
     215    if (UPDATE)        strextend (&command, "-update");
     216    if (RESET_BAD_IMAGES) strextend (&command, "-reset-bad-images");
     217    if (USE_BASIC_CHECK) strextend (&command, "-basic-image-search");
     218    if (USE_ALL_IMAGES)      strextend (&command, "-use-all-images");
     219
    215220    if (MinBadQF > 0.0)        strextend (&command, "-min-bad-psfqf %f", MinBadQF);
    216221    if (MaxMeanOffset != 10.0) strextend (&command, "-max-mean-offset  %f", MaxMeanOffset);
     222    if (N_BOOTSTRAP_SAMPLES > 1) strextend (&command, "-bootstrap-samples %d", N_BOOTSTRAP_SAMPLES);
    217223
    218224    if (TimeSelect) {
     
    300306    strextend (&command, "relastro_client -update-offsets");
    301307    strextend (&command, "-hostID %d", table->hosts[i].hostID);
     308    strextend (&command, "-hostdir %s", table->hosts[i].pathname);
     309
    302310    strextend (&command, "-D CATDIR %s", CATDIR);
    303     strextend (&command, "-hostdir %s", table->hosts[i].pathname);
    304311    strextend (&command, "-region %f %f %f %f", UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    305312    strextend (&command, "-statmode %s", STATMODE);
    306313    strextend (&command, "-minerror %f", MIN_ERROR);
    307314
     315    strextend (&command, "-D RELASTRO_SIGMA_LIM %f", SIGMA_LIM);
     316    strextend (&command, "-D RELASTRO_SRC_MEAS_TOOFEW %d", SRC_MEAS_TOOFEW);
     317
    308318    if (FIT_MODE == FIT_PM_ONLY)         strextend (&command, "-pm");
    309319    if (FIT_MODE == FIT_PAR_ONLY)        strextend (&command, "-par");
     
    313323    if (VERBOSE2)      strextend (&command, "-vv");
    314324    if (RESET)         strextend (&command, "-reset");
    315     if (UPDATE)        strextend (&command, "-update");
    316 
    317     if (RESET_BAD_IMAGES) strextend (&command, "-reset-bad-images");
    318325
    319326    if (ImagSelect)    strextend (&command, "-instmag %f %f", ImagMin, ImagMax);
    320327    if (MaxDensityUse) strextend (&command, "-max-density %f", MaxDensityValue);
    321    
    322     if (USE_BASIC_CHECK) strextend (&command, "-basic-image-search");
    323328    if (FlagOutlier)     strextend (&command, "-clip %d", CLIP_THRESH);
    324329    if (ExcludeBogus)    strextend (&command, "-exclude-bogus %f", ExcludeBogusRadius);
    325330   
    326     if (USE_ALL_IMAGES)      strextend (&command, "-use-all-images");
    327331    if (USE_FIXED_PIXCOORDS) strextend (&command, "-D USE_FIXED_PIXCOORDS 1");
    328 
    329     if (REPAIR_STACKS)          strextend (&command, "-repair-stacks-on-update");
    330     if (CHECK_MEASURE_TO_IMAGE) strextend (&command, "-check-measures");
    331 
    332332    if (PHOTCODE_KEEP_LIST) strextend (&command, "+photcode %s", PHOTCODE_KEEP_LIST);
    333333    if (PHOTCODE_SKIP_LIST) strextend (&command, "-photcode %s", PHOTCODE_SKIP_LIST);
     
    337337    // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
    338338
    339     if (N_BOOTSTRAP_SAMPLES > 1) strextend (&command, "-bootstrap-samples %d", N_BOOTSTRAP_SAMPLES);
    340 
    341339    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
    342340      strextend (&command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     
    345343      strextend (&command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
    346344    }
     345
     346    if (REPAIR_STACKS)          strextend (&command, "-repair-stacks-on-update");
     347    if (CHECK_MEASURE_TO_IMAGE) strextend (&command, "-check-measures");
     348
     349    if (UPDATE_PS1_STACK_MEASURE) strextend (&command, "-update-ps1-stack");
     350    if (UPDATE_PS1_CHIP_MEASURE) strextend (&command, "-update-ps1-chip");
     351    if (UPDATE_HSC_MEASURE)      strextend (&command, "-update-hsc");
     352    if (UPDATE_CFH_MEASURE)      strextend (&command, "-update-cfh");
     353
     354    if (UPDATE)        strextend (&command, "-update");
     355    if (RESET_BAD_IMAGES) strextend (&command, "-reset-bad-images");
     356    if (USE_BASIC_CHECK) strextend (&command, "-basic-image-search");
     357    if (USE_ALL_IMAGES)      strextend (&command, "-use-all-images");
     358
     359    if (N_BOOTSTRAP_SAMPLES > 1) strextend (&command, "-bootstrap-samples %d", N_BOOTSTRAP_SAMPLES);
    347360
    348361    if (MinBadQF > 0.0)        strextend (&command, "-min-bad-psfqf %f", MinBadQF);
  • trunk/Ohana/src/relastro/src/UpdateObjects.c

    r39617 r39926  
    55# define PAR_MIN_NPTS 7
    66# define PAR_MIN_NPTS_BOOT 6
    7 # define PM_MIN_NPTS 4
    8 # define PM_MIN_NPTS_BOOT 3
    9 # define POS_MIN_NPTS 3
    10 # define POS_MIN_NPTS_BOOT 2
     7# define PM_MIN_NPTS 5
     8# define PM_MIN_NPTS_BOOT 4
     9# define POS_MIN_NPTS 4
     10# define POS_MIN_NPTS_BOOT 4
    1111
    1212typedef enum {
    13   SELECT_MEAS_HAS_DATA  = 1,
    14   SELECT_MEAS_HAS_STACK = 2,
    15   SELECT_MEAS_HAS_2MASS = 4,
     13  SELECT_MEAS_HAS_DATA  = 0x01,
     14  SELECT_MEAS_HAS_STACK = 0x02,
     15  SELECT_MEAS_HAS_2MASS = 0x04,
     16  SELECT_MEAS_HAS_GAIA  = 0x08,
     17  SELECT_MEAS_HAS_TYCHO = 0x10,
    1618} SelectMeasureStatus;
    1719
     
    181183    if (Trange < PM_DT_MIN) {
    182184      // not enough baseline for proper motion, only set mean position
    183       mode = FIT_AVERAGE;
    184185      goto justPosition;
    185186    }
    186187    if (parRange < PAR_FACTOR_MIN) {
    187188      // not enough parallax factor range, skip parallax
    188       mode = FIT_PM_ONLY;
    189189      goto skipParallax;
    190190    }
    191191    if (fitStats->Npoints < PAR_MIN_NPTS) {
    192192      // not enough data, skip parallax
    193       mode = FIT_PM_ONLY;
    194193      goto skipParallax;
    195194    }
    196195
    197196    // we are going to use the IRLS analysis to calculate the mean solution and the masking
    198     // then run N_BOOTSTRAP_SAMPLES to measure the errors
    199     fitStats->fitdataPar->getError = !N_BOOTSTRAP_SAMPLES;
    200     if (!FitPMandPar_IRLS (&fitPar, fitStats->fitdataPar, fitStats->points, fitStats->Npoints)) {
    201       mode = FIT_PM_ONLY;
    202       goto skipParallax;
    203     }
    204 
    205     if (N_BOOTSTRAP_SAMPLES) {
     197    // then run N_BOOTSTRAP_SAMPLES to measure the errors.  We first measure the OLS error,
     198    // and choose the max of the OLS and bootstrap errors
     199    fitStats->fitdataPar->getError = TRUE;
     200    if (USE_IRLS) {
     201      if (!FitPMandPar_IRLS (&fitPar, fitStats->fitdataPar, fitStats->points, fitStats->Npoints)) {
     202        goto skipParallax;
     203      }
     204    } else {
     205      if (!FitPMandPar_Basic (&fitPar, fitStats->fitdataPar, fitStats->points, fitStats->Npoints)) {
     206        goto skipParallax;
     207      }
     208    }
     209
     210    // in the fits above, we have saved the formal error for the unmasked points. 
     211    // if we do not have enough points for bootstrap, we will keep those errors
     212    if (N_BOOTSTRAP_SAMPLES && (fitPar.Nfit >= PAR_MIN_NPTS_BOOT)) {
    206213      fitStats->Nfit = 0;
    207214      int Nnomask = BootstrapSaveUnmasked (fitStats->nomask, fitStats->points, fitStats->Npoints);
    208       if (Nnomask < PAR_MIN_NPTS_BOOT) {
    209         // if we do not have enough points to assess parallax error, we cannot do the bootstrap analysis.
    210         mode = FIT_PM_ONLY;
    211         goto skipParallax;
    212       }
     215
     216      // if we do not have enough points to assess parallax error, skip the bootstrap analysis.
     217      // (I think the test above means we never do this skip)
     218      if (Nnomask < PAR_MIN_NPTS_BOOT) goto skipParallaxBootstrap;
     219
    213220      for (k = 0; k < fitStats->NfitAlloc; k++) {
    214221        BootstrapResample (fitStats->sample, fitStats->nomask, Nnomask);
     
    216223        fitStats->Nfit ++;
    217224      }
    218       // these calls set the ERRORS on the fit parameters, not the fit values (set in IRLS above)
     225
     226      // These calls set the ERRORS on the fit parameters, not the fit values (set in IRLS above)
     227      // this call expects the fitted parameters to have the formal error set: it will apply the
     228      // max of the formal and bootstrap errors
    219229      BootstrapRobustStats (&fitPar, fitStats->fit, fitStats->Nfit, FIT_RESULT_RA);
    220230      BootstrapRobustStats (&fitPar, fitStats->fit, fitStats->Nfit, FIT_RESULT_DEC);
     
    224234    }
    225235
     236  skipParallaxBootstrap:
    226237    // project Ro, Do back to RA,DEC
    227238    XY_to_RD (&fitPar.Ro, &fitPar.Do, fitPar.Ro, fitPar.Do, &fitStats->coords);
     
    242253    valid = valid && (fabs(fitPar.uD) < 4.0);
    243254    valid = valid && (fabs(fitPar.p) < 2.0);
    244     if (!valid) {
    245       mode = FIT_PM_ONLY;
    246     } else {
     255    if (valid) {
    247256      average[0].flags |= ID_OBJ_USE_PAR;
    248257    }
     
    254263  if ((mode == FIT_PM_ONLY) || (mode == FIT_PM_AND_PAR)) {
    255264    if (Trange < PM_DT_MIN) {
    256       mode = FIT_AVERAGE;
    257265      goto justPosition;
    258266    }
    259267    if (fitStats->Npoints < PM_MIN_NPTS) {
    260       mode = FIT_AVERAGE;
    261268      goto justPosition;
    262269    }
    263270
    264271    // if we have fitted (and accepted) a parallax model, get the best pm fit and chisq
    265     // given the set of points (mask is respected)
    266     if (average[0].flags & ID_OBJ_USE_PAR) {
     272    // given the set of points (mask is respected).  Alternatively, if we do not request
     273    // IRLS fitting, the just use OLS fitting (skip bootstrap)
     274    if ((average[0].flags & ID_OBJ_USE_PAR) || !USE_IRLS) {
    267275      if (!FitPM_Basic (&fitPM, fitStats->fitdataPM, fitStats->points, fitStats->Npoints)) {
    268276        average[0].flags |= ID_OBJ_BAD_PM;
    269277        goto justPosition;
    270278      }
    271     } else {
    272       fitStats->fitdataPM->getError = !N_BOOTSTRAP_SAMPLES;
    273       if (!FitPM_IRLS (&fitPM, fitStats->fitdataPM, fitStats->points, fitStats->Npoints)) {
    274         mode = FIT_AVERAGE;
    275         goto justPosition;
    276       }
    277       if (N_BOOTSTRAP_SAMPLES) {
    278         fitStats->Nfit = 0;
    279         int Nnomask = BootstrapSaveUnmasked (fitStats->nomask, fitStats->points, fitStats->Npoints);
    280         if (Nnomask < PM_MIN_NPTS_BOOT) {
    281           mode = FIT_AVERAGE;
    282           goto justPosition;
    283         }
    284         for (k = 0; k < fitStats->NfitAlloc; k++) {
    285           BootstrapResample (fitStats->sample, fitStats->nomask, Nnomask);
    286           if (!FitPM_Basic (&fitStats->fit[k], fitStats->fitdataPM, fitStats->sample, Nnomask)) continue;
    287           fitStats->Nfit ++;
    288         }
    289         BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_RA);
    290         BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_DEC);
    291         BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_uR);
    292         BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_uD);
    293       }
    294     }
    295 
     279      goto skipProperMotionBootstrap;
     280    }
     281
     282    // we are going to use the IRLS analysis to calculate the mean solution and the masking
     283    // then run N_BOOTSTRAP_SAMPLES to measure the errors.  We first measure the OLS error,
     284    // and choose the max of the OLS and bootstrap errors
     285    fitStats->fitdataPM->getError = TRUE;
     286    if (!FitPM_IRLS (&fitPM, fitStats->fitdataPM, fitStats->points, fitStats->Npoints)) {
     287      goto justPosition;
     288    }
     289
     290    // in the fits above, we have saved the formal error for the unmasked points. 
     291    // if we do not have enough points for bootstrap, we will keep those errors
     292    if (N_BOOTSTRAP_SAMPLES && (fitPM.Nfit >= PM_MIN_NPTS_BOOT)) {
     293      fitStats->Nfit = 0;
     294      int Nnomask = BootstrapSaveUnmasked (fitStats->nomask, fitStats->points, fitStats->Npoints);
     295       
     296      // if we do not have enough points to assess p.m. error, skip the bootstrap analysis.
     297      // (I think the test above means we never do this skip)
     298      if (Nnomask < PM_MIN_NPTS_BOOT) goto skipProperMotionBootstrap;
     299
     300      for (k = 0; k < fitStats->NfitAlloc; k++) {
     301        BootstrapResample (fitStats->sample, fitStats->nomask, Nnomask);
     302        if (!FitPM_Basic (&fitStats->fit[k], fitStats->fitdataPM, fitStats->sample, Nnomask)) continue;
     303        fitStats->Nfit ++;
     304      }
     305
     306      // These calls set the ERRORS on the fit parameters, not the fit values (set in IRLS above)
     307      // this call expects the fitted parameters to have the formal error set: it will apply the
     308      // max of the formal and bootstrap errors
     309      BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_RA);
     310      BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_DEC);
     311      BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_uR);
     312      BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_uD);
     313    }
     314
     315skipProperMotionBootstrap:
    296316    // project Ro, Do back to RA,DEC
    297317    XY_to_RD (&fitPM.Ro, &fitPM.Do, fitPM.Ro, fitPM.Do, &fitStats->coords);
     
    300320    fitStats->Npm ++;
    301321
     322    // XXX a hard-wired hack...
    302323    // unless there is a clear problems (below) with the proper-motion fit or we have a parallax fit, we will use pm fit
    303324    int valid = TRUE;
     
    309330    valid = valid && (fabs(fitPM.uD) < 4.0);
    310331    if (!valid) {
    311       mode = FIT_AVERAGE;
    312332      average[0].flags |= ID_OBJ_BAD_PM;
    313333    } else {
     
    323343    // if we only have one point, this is silly...
    324344
     345    // set the proper motion (to the galaxy model or average value, if desired; else to 0,0)
    325346    FitAstromResultSetPM (&fitPos, 1, average);
    326     // fprintf (stderr, "fit 1: %f %f : %f %f\n", fitPos.Ro, fitPos.Do, fitPos.uR, fitPos.uD);
    327     if (average[0].flags & (ID_OBJ_USE_PAR | ID_OBJ_USE_PM)) {
     347
     348    // if we already have a valid fit (pm or par), use OLS to fit the position
     349    // alternatively, if we do not request IRLS, use OLS
     350    // alternatively, if we do not have enough points, use OLS
     351    if ((average[0].flags & (ID_OBJ_USE_PAR | ID_OBJ_USE_PM)) || (fitStats->Npoints < POS_MIN_NPTS) || !USE_IRLS) {
    328352      if (!FitPosPMfixed_Basic (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) {
    329         // if this fails, stick with the PM and/or PAR fit from above
     353        // if this fails, stick with the PM and/or PAR fit from above, or use a single value
    330354        goto doneWithFit;
    331355      }
    332     } else {
    333       if (fitStats->Npoints < POS_MIN_NPTS) {
    334         // I will not try to outlier-reject, just calculate the weighted average
    335         if (!FitPosPMfixed_Basic (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) {
    336           // if we have tried this, we have not masked any points; we will find a single unmasked point below
    337           goto doneWithFit;
    338         }
     356      // if we have not already gotten a good fit, use this fit
     357      if (!(average[0].flags & (ID_OBJ_USE_PAR | ID_OBJ_USE_PM))) {
    339358        average[0].flags |= ID_OBJ_USE_AVE;
    340359        average[0].flags |= ID_OBJ_RAW_AVE;
    341         goto useBasic;
    342       }
    343       if (!FitPosPMfixed_IRLS (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) {
    344         // if the above fails, we need to clear the masks and try again below
    345         FitPointsClearMasks (fitStats->points, fitStats->Npoints);
    346         // just calculate the weighted average
    347         if (!FitPosPMfixed_Basic (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) {
    348           // if this fails, find a single unmasked point below
    349           goto doneWithFit;
    350         }
    351         average[0].flags |= ID_OBJ_USE_AVE;
    352         average[0].flags |= ID_OBJ_RAW_AVE;
    353         goto useBasic;
    354       }
    355       // fprintf (stderr, "fit 2: %f %f : %f %f\n", fitPos.Ro, fitPos.Do, fitPos.uR, fitPos.uD);
    356       if (N_BOOTSTRAP_SAMPLES) {
    357         fitStats->Nfit = 0;
    358         int Nnomask = BootstrapSaveUnmasked (fitStats->nomask, fitStats->points, fitStats->Npoints);
    359         if (Nnomask < POS_MIN_NPTS_BOOT) {
    360           // if the above fails, we need to clear the masks and try again below
    361           FitPointsClearMasks (fitStats->points, fitStats->Npoints);
    362           if (!FitPosPMfixed_Basic (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) {
    363             // if this fails, find a single unmasked point below
    364             goto doneWithFit;
    365           }
    366           average[0].flags |= ID_OBJ_USE_AVE;
    367           average[0].flags |= ID_OBJ_RAW_AVE;
    368           goto useBasic;
    369         }
    370         FitAstromResultSetPM (fitStats->fit, fitStats->NfitAlloc, average);
    371         for (k = 0; k < fitStats->NfitAlloc; k++) {
    372           BootstrapResample (fitStats->sample, fitStats->nomask, Nnomask);
    373           if (!FitPosPMfixed_Basic (&fitStats->fit[k], fitStats->fitdataPos, fitStats->sample, Nnomask)) continue;
    374           fitStats->Nfit ++;
    375         }
    376         BootstrapRobustStats (&fitPos, fitStats->fit, fitStats->Nfit, FIT_RESULT_RA);
    377         BootstrapRobustStats (&fitPos, fitStats->fit, fitStats->Nfit, FIT_RESULT_DEC);
     360      }
     361      goto useBasic;
     362    }
     363   
     364    // try the IRLS fitting, otherwise give up and use OLS
     365    if (!FitPosPMfixed_IRLS (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) {
     366      // if the above fails, we need to clear the masks and try again below
     367      FitPointsClearMasks (fitStats->points, fitStats->Npoints);
     368      // just calculate the weighted average
     369      if (!FitPosPMfixed_Basic (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) {
     370        // if this fails, find a single unmasked point below
     371        goto doneWithFit;
    378372      }
    379373      average[0].flags |= ID_OBJ_USE_AVE;
     374      average[0].flags |= ID_OBJ_RAW_AVE;
     375      goto useBasic;
     376    }
     377    average[0].flags |= ID_OBJ_USE_AVE;
     378
     379    if (N_BOOTSTRAP_SAMPLES && (fitPos.Nfit >= POS_MIN_NPTS_BOOT)) {
     380      fitStats->Nfit = 0;
     381      int Nnomask = BootstrapSaveUnmasked (fitStats->nomask, fitStats->points, fitStats->Npoints);
     382     
     383      if (Nnomask < POS_MIN_NPTS_BOOT) goto useBasic;
     384     
     385      FitAstromResultSetPM (fitStats->fit, fitStats->NfitAlloc, average);
     386      for (k = 0; k < fitStats->NfitAlloc; k++) {
     387        BootstrapResample (fitStats->sample, fitStats->nomask, Nnomask);
     388        if (!FitPosPMfixed_Basic (&fitStats->fit[k], fitStats->fitdataPos, fitStats->sample, Nnomask)) continue;
     389        fitStats->Nfit ++;
     390      }
     391     
     392      // These calls set the ERRORS on the fit parameters, not the fit values (set in IRLS above)
     393      // this call expects the fitted parameters to have the formal error set: it will apply the
     394      // max of the formal and bootstrap errors
     395      BootstrapRobustStats (&fitPos, fitStats->fit, fitStats->Nfit, FIT_RESULT_RA);
     396      BootstrapRobustStats (&fitPos, fitStats->fit, fitStats->Nfit, FIT_RESULT_DEC);
    380397    }
    381398
     
    544561  average[0].dP         = fit.dp; // parallax error in arcsec
    545562
     563
    546564  average[0].ChiSqAve   = fitPos.chisq;
    547565  average[0].ChiSqPM    = fitPM.chisq;
     
    666684
    667685  int has2MASS = FALSE;
     686  int hasGAIA  = FALSE;
     687  int hasTycho = FALSE;
    668688  int hasStack = FALSE;
    669689  if (stackEntry) *stackEntry = -1;
     
    774794    Npoints++;
    775795
    776     if ((measure[k].photcode >= 2011) && (measure[k].photcode <= 2013)) {
    777       has2MASS = TRUE;
    778     }
     796    hasGAIA  =  (measure[k].photcode == 1030);
     797    has2MASS = ((measure[k].photcode >= 2011) && (measure[k].photcode <= 2013));
     798    hasTycho = ((measure[k].photcode >= 2020) && (measure[k].photcode <= 2021));
    779799
    780800    myAssert (Npoints <= fit->NpointsAlloc, "oops");
     
    796816      measure[k].dbFlags &= ~ID_MEAS_OBJECT_HAS_2MASS;
    797817    }
     818    if (hasGAIA) {
     819      measure[k].dbFlags |=  ID_MEAS_OBJECT_HAS_GAIA;
     820    } else {
     821      measure[k].dbFlags &= ~ID_MEAS_OBJECT_HAS_GAIA;
     822    }
     823    if (hasTycho) {
     824      measure[k].dbFlags |=  ID_MEAS_OBJECT_HAS_TYCHO;
     825    } else {
     826      measure[k].dbFlags &= ~ID_MEAS_OBJECT_HAS_TYCHO;
     827    }
    798828  }
    799829
     
    803833  if (hasStack) status |= SELECT_MEAS_HAS_STACK;
    804834  if (has2MASS) status |= SELECT_MEAS_HAS_2MASS;
     835  if (hasGAIA)  status |= SELECT_MEAS_HAS_GAIA;
     836  if (hasTycho) status |= SELECT_MEAS_HAS_TYCHO;
    805837  return status;
    806838}
     
    822854
    823855  int i;
     856
     857  myAbort ("this should not be called anymore");
    824858
    825859  // add up the chi square for the fit
     
    852886  int i;
    853887
    854   if (USE_GALAXY_MODEL) {
     888  if (APPLY_PROPER_MOTION) {
    855889    for (i = 0; i < Nfit; i++) {
    856       fit[i].uR = average->uRgal;
    857       fit[i].uD = average->uDgal;
     890      if (USE_GALAXY_MODEL) {
     891        fit[i].uR = average->uRgal;
     892        fit[i].uD = average->uDgal;
     893      } else {
     894        fit[i].uR = average->uR;
     895        fit[i].uD = average->uD;
     896      }
    858897    }
    859898  } else {
  • trunk/Ohana/src/relastro/src/UpdateStacks.c

    r39457 r39926  
    33// NOTE: we only measure the systematic floor of the astrometric scatter per stack, no change to the calibration
    44int UpdateStacks (Catalog *catalog, int Ncatalog) {
     5
     6  if (SKIP_PS1_STACK) return TRUE;
    57
    68  off_t Nimage;
     
    4648
    4749    // XXX: I need to convert dLsig, dMsig from degrees to pixels
    48     dLsig *= 3600.0 / 0.25;
    49     dMsig *= 3600.0 / 0.25;
     50    dLsig *= 3600.0;
     51    dMsig *= 3600.0;
    5052
    5153    image[i].dXpixSys = dLsig;
  • trunk/Ohana/src/relastro/src/args.c

    r39693 r39926  
    11# include "relastro.h"
    2 void usage (void);
    3 void usage_client (void);
     2void usage (int argc, char **argv);
     3void usage_client (int argc, char **argv);
    44void usage_merge_source (void);
    55void usage_merge_source_id (char *name);
    66float *ParseLoopWeights (char *rawlist);
     7int *ParseLoopOrder (char *rawlist, int minValue);
    78
    89int args (int argc, char **argv) {
     
    3940    remove_argument (N, &argc, argv);
    4041
    41     if (argc != 1) usage ();
     42    if (argc != 1) usage (argc, argv);
    4243    return TRUE;
    4344  }
     
    7677    remove_argument (N, &argc, argv);
    7778    CHECK_MEASURE_TO_IMAGE = TRUE;
     79  }
     80
     81  // catch-up mode : for a re-run, allow the sync file to be ahead of the desired location:
     82  CATCH_UP = FALSE;
     83  if ((N = get_argument (argc, argv, "-catch-up"))) {
     84    remove_argument (N, &argc, argv);
     85    CATCH_UP = TRUE;
    7886  }
    7987
     
    105113    remove_argument (N, &argc, argv);
    106114    RELASTRO_OP = OP_PARALLEL_IMAGES;
    107     if (N >= argc) usage();
     115    if (N >= argc) usage (argc, argv);
    108116    IMAGE_TABLE = strcreate (argv[N]);
    109117    remove_argument (N, &argc, argv);
    110     if (!REGION_FILE) usage();
     118    if (!REGION_FILE) usage (argc, argv);
    111119  }
    112120
     
    114122    remove_argument (N, &argc, argv);
    115123    RELASTRO_OP = OP_IMAGES;
     124  }
     125
     126  // used to decide if changes to the image parameters get applied to the measures
     127  APPLY_OFFSETS = FALSE;
     128  if ((N = get_argument (argc, argv, "-apply-offsets"))) {
     129    remove_argument (N, &argc, argv);
     130    APPLY_OFFSETS = TRUE;
     131  }
     132
     133  APPLY_PROPER_MOTION = FALSE;
     134  if ((N = get_argument (argc, argv, "-apply-proper-motion"))) {
     135    remove_argument (N, &argc, argv);
     136    APPLY_PROPER_MOTION = TRUE;
     137  }
     138
     139  SKIP_PS1_CHIP = FALSE;
     140  if ((N = get_argument (argc, argv, "-skip-ps1-chip"))) {
     141    remove_argument (N, &argc, argv);
     142    SKIP_PS1_CHIP = TRUE;
     143  }
     144  SKIP_PS1_STACK = FALSE;
     145  if ((N = get_argument (argc, argv, "-skip-ps1-stack"))) {
     146    remove_argument (N, &argc, argv);
     147    SKIP_PS1_STACK = TRUE;
     148  }
     149  SKIP_HSC = FALSE;
     150  if ((N = get_argument (argc, argv, "-skip-hsc"))) {
     151    remove_argument (N, &argc, argv);
     152    SKIP_HSC = TRUE;
     153  }
     154  SKIP_CFH = FALSE;
     155  if ((N = get_argument (argc, argv, "-skip-cfh"))) {
     156    remove_argument (N, &argc, argv);
     157    SKIP_CFH = TRUE;
     158  }
     159
     160  UPDATE_PS1_STACK_MEASURE = FALSE;
     161  if ((N = get_argument (argc, argv, "-update-ps1-stack"))) {
     162    remove_argument (N, &argc, argv);
     163    UPDATE_PS1_STACK_MEASURE = TRUE;
     164  }
     165  UPDATE_PS1_CHIP_MEASURE = FALSE;
     166  if ((N = get_argument (argc, argv, "-update-ps1-chip"))) {
     167    remove_argument (N, &argc, argv);
     168    UPDATE_PS1_CHIP_MEASURE = TRUE;
     169  }
     170  UPDATE_HSC_MEASURE = FALSE;
     171  if ((N = get_argument (argc, argv, "-update-hsc"))) {
     172    remove_argument (N, &argc, argv);
     173    UPDATE_HSC_MEASURE = TRUE;
     174  }
     175  UPDATE_CFH_MEASURE = FALSE;
     176  if ((N = get_argument (argc, argv, "-update-cfh"))) {
     177    remove_argument (N, &argc, argv);
     178    UPDATE_CFH_MEASURE = TRUE;
     179  }
     180  if (RELASTRO_OP == OP_UPDATE_OFFSETS) {
     181    if (!UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
     182      fprintf (stderr, "for -update-offsets, need to select at least one of -update-ps1-stack, -update-ps1-chip, -update-hsc, -update-cfh\n");
     183      exit (2);
     184    }
     185  }
     186  if ((RELASTRO_OP == OP_PARALLEL_IMAGES) || (RELASTRO_OP == OP_IMAGES)) {
     187    if (APPLY_OFFSETS && !UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
     188      fprintf (stderr, "for [-images or -parallel-images] with -apply-offsets, need to select at least one of -update-ps1-stack, -update-ps1-chip, -update-hsc, -update-cfh\n");
     189      exit (2);
     190    }
     191  }
     192
     193  // for fitting objects, this is always the same as 'ALLOW_IRLS' below, but for fitting
     194  // images, this is set to FALSE while doing the fit for the image parameters
     195  USE_IRLS = TRUE; 
     196  ALLOW_IRLS = TRUE;
     197  if ((N = get_argument (argc, argv, "-no-irls"))) {
     198    remove_argument (N, &argc, argv);
     199    USE_IRLS = FALSE;
     200    ALLOW_IRLS = FALSE;
    116201  }
    117202
     
    120205    remove_argument (N, &argc, argv);
    121206    RELASTRO_OP = OP_PARALLEL_REGIONS;
    122     if (!REGION_FILE) usage();
     207    if (!REGION_FILE) usage (argc, argv);
    123208    if ((N = get_argument (argc, argv, "-parallel-regions-manual"))) {
    124209      remove_argument (N, &argc, argv);
     
    128213
    129214  if ((N = get_argument (argc, argv, "-testobj1"))) {
    130     if (N > argc - 3) usage ();
     215    if (N > argc - 3) usage (argc, argv);
    131216    remove_argument (N, &argc, argv);
    132217    OBJ_ID_SRC = strtol(argv[N], &endptr, 0);
    133     if (*endptr) usage ();
     218    if (*endptr) usage (argc, argv);
    134219    remove_argument (N, &argc, argv);
    135220    CAT_ID_SRC = strtol(argv[N], &endptr, 0);
    136     if (*endptr) usage ();
     221    if (*endptr) usage (argc, argv);
    137222    remove_argument (N, &argc, argv);
    138223  }
    139224
    140225  if ((N = get_argument (argc, argv, "-testobj2"))) {
    141     if (N > argc - 3) usage ();
     226    if (N > argc - 3) usage (argc, argv);
    142227    remove_argument (N, &argc, argv);
    143228    OBJ_ID_DST = strtol(argv[N], &endptr, 0);
    144     if (*endptr) usage ();
     229    if (*endptr) usage (argc, argv);
    145230    remove_argument (N, &argc, argv);
    146231    CAT_ID_DST = strtol(argv[N], &endptr, 0);
    147     if (*endptr) usage ();
     232    if (*endptr) usage (argc, argv);
    148233    remove_argument (N, &argc, argv);
    149234  }
     
    167252  if ((N = get_argument (argc, argv, "-high-speed"))) {
    168253    // XXX include a parallax / no-parallax option
    169     if (N >= argc - 4) usage();
     254    if (N >= argc - 4) usage (argc, argv);
    170255    RELASTRO_OP = OP_HIGH_SPEED;
    171256    remove_argument (N, &argc, argv);
     
    181266
    182267  if ((N = get_argument (argc, argv, "-hpm"))) {
    183     if (N >= argc - 2) usage();
     268    if (N >= argc - 2) usage (argc, argv);
    184269    RELASTRO_OP = OP_HPM;
    185270    remove_argument (N, &argc, argv);
     
    212297    FIT_TARGET = TARGET_MOSAICS;
    213298  }
     299  if ((N = get_argument (argc, argv, "-set-chips"))) {
     300    remove_argument (N, &argc, argv);
     301    FIT_TARGET = SET_CHIPS;
     302  }
    214303
    215304  FlagOutlier = FALSE;
     
    231320  }
    232321
    233   if (RELASTRO_OP == OP_NONE) usage();
    234 
    235   if (((RELASTRO_OP == OP_IMAGES) || (RELASTRO_OP == OP_PARALLEL_REGIONS) || (RELASTRO_OP == OP_PARALLEL_IMAGES)) && (FIT_TARGET == TARGET_NONE)) usage();
     322  if (RELASTRO_OP == OP_NONE) usage (argc, argv);
     323
     324  if (((RELASTRO_OP == OP_IMAGES) || (RELASTRO_OP == OP_PARALLEL_REGIONS) || (RELASTRO_OP == OP_PARALLEL_IMAGES)) && (FIT_TARGET == TARGET_NONE)) usage (argc, argv);
    236325
    237326  /* specify portion of the sky : allow default of all sky? */
     
    303392  }
    304393
     394  KEEP_ALL_IMAGES_RA = FALSE;
     395  if ((N = get_argument (argc, argv, "-keep-all-images-ra"))) {
     396    remove_argument (N, &argc, argv);
     397    KEEP_ALL_IMAGES_RA = TRUE;
     398  }
     399
    305400  USE_BASIC_CHECK = FALSE;
    306401  if ((N = get_argument (argc, argv, "-basic-image-search"))) {
     
    315410    remove_argument (N, &argc, argv);
    316411    MaxDensityUse = TRUE;
    317   }
    318 
    319   APPLY_OFFSETS = FALSE;
    320   if ((N = get_argument (argc, argv, "-apply-offsets"))) {
    321     remove_argument (N, &argc, argv);
    322     APPLY_OFFSETS = TRUE;
    323412  }
    324413
     
    439528  }
    440529
    441   CHIPORDER = 0;
    442   if ((N = get_argument (argc, argv, "-chiporder"))) {
    443     remove_argument (N, &argc, argv);
    444     CHIPORDER = atoi(argv[N]);
    445     remove_argument (N, &argc, argv);
    446   }
    447 
    448   CHIPMAP = 0;
    449   if ((N = get_argument (argc, argv, "-chipmap"))) {
    450     remove_argument (N, &argc, argv);
    451     CHIPMAP = atoi(argv[N]);
    452     remove_argument (N, &argc, argv);
    453 
    454   }
    455 
    456530  SAVEPLOT = FALSE;
    457531  PLOTSTUFF = FALSE;
     
    580654  }
    581655
     656  // e.g., -chiporderloop 3,4,5
     657  // NOTE: this must come after -nloop above
     658  ChipOrderLoop = NULL;
     659  ChipOrderLoopStr = NULL;
     660  CHIPORDER = 1;
     661  if ((N = get_argument (argc, argv, "-chiporder"))) {
     662    remove_argument (N, &argc, argv);
     663    CHIPORDER = atoi(argv[N]);
     664    remove_argument (N, &argc, argv);
     665  }
     666  if ((N = get_argument (argc, argv, "-chiporderloop"))) {
     667    remove_argument (N, &argc, argv);
     668    ChipOrderLoopStr = strcreate(argv[N]);
     669    ChipOrderLoop = ParseLoopOrder (argv[N], 1);
     670    remove_argument (N, &argc, argv);
     671  }
     672
     673  ChipMapLoop = NULL;
     674  ChipMapLoopStr = NULL;
     675  CHIPMAP = 0;
     676  if ((N = get_argument (argc, argv, "-chipmap"))) {
     677    remove_argument (N, &argc, argv);
     678    CHIPMAP = atoi(argv[N]);
     679    remove_argument (N, &argc, argv);
     680
     681  }
     682  if ((N = get_argument (argc, argv, "-chipmaploop"))) {
     683    remove_argument (N, &argc, argv);
     684    ChipMapLoopStr = strcreate(argv[N]);
     685    ChipMapLoop = ParseLoopOrder (argv[N], 0);
     686    remove_argument (N, &argc, argv);
     687  }
     688 
     689
    582690  // e.g., -loop-weights-2mass 1000,300,300,200,200,100
    583691  // NOTE: this must come after -nloop above
     
    591699  }
    592700  LoopWeightTycho = NULL;
     701  LoopWeightTychostr = NULL;
    593702  if ((N = get_argument (argc, argv, "-loop-weights-tycho"))) {
    594703    remove_argument (N, &argc, argv);
     
    597706    remove_argument (N, &argc, argv);
    598707  }
     708  LoopWeightGAIA = NULL;
     709  LoopWeightGAIAstr = NULL;
     710  if ((N = get_argument (argc, argv, "-loop-weights-gaia"))) {
     711    remove_argument (N, &argc, argv);
     712    LoopWeightGAIAstr = strcreate(argv[N]);
     713    LoopWeightGAIA = ParseLoopWeights (argv[N]);
     714    remove_argument (N, &argc, argv);
     715  }
     716
     717  GALAXY_MODEL = NULL;
     718  if ((N = get_argument (argc, argv, "-galaxy-model"))) {
     719    remove_argument (N, &argc, argv);
     720    GALAXY_MODEL = strcreate(argv[N]);
     721    remove_argument (N, &argc, argv);
     722  }
     723  if (!GALAXY_MODEL) GALAXY_MODEL = strcreate ("FEAST-HIPPARCOS");
     724
     725  // for testing, allow the galaxy model scale to be non-unity
     726  TEST_SCALE = 1.0;
     727  if ((N = get_argument (argc, argv, "-testing"))) {
     728    remove_argument (N, &argc, argv);
     729    TEST_SCALE = atof(argv[N]);
     730    remove_argument (N, &argc, argv);
     731  }
    599732
    600733  NTHREADS = 0;
     
    605738  }
    606739
    607   if (argc != 1) usage ();
     740  if (argc != 1) usage (argc, argv);
    608741  return TRUE;
    609742}
     
    614747  FREE (LoopWeight2MASSstr);
    615748  FREE (LoopWeightTychostr);
     749  FREE (LoopWeightGAIAstr);
     750  FREE (LoopWeight2MASS);
     751  FREE (LoopWeightTycho);
     752  FREE (LoopWeightGAIA);
     753
     754  FREE (ChipMapLoop);
     755  FREE (ChipMapLoopStr);
     756  FREE (ChipOrderLoop);
     757  FREE (ChipOrderLoopStr);
    616758
    617759  FREE (PHOTCODE_SKIP_LIST);
     
    628770  FREE (BCATALOG);
    629771  FREE (HOSTDIR);
     772  FREE (GALAXY_MODEL);
    630773
    631774  // these are set in initialize
     
    673816    remove_argument (N, &argc, argv);
    674817  }
    675   if (!HOST_ID) usage_client();
     818  if (!HOST_ID) usage_client (argc, argv);
    676819
    677820  HOSTDIR = NULL;
     
    681824    remove_argument (N, &argc, argv);
    682825  }
    683   if (!HOSTDIR) usage_client();
     826  if (!HOSTDIR) usage_client (argc, argv);
    684827
    685828  if ((N = get_argument (argc, argv, "-load-objects"))) {
     
    726869  }
    727870
     871  SKIP_PS1_CHIP = FALSE;
     872  if ((N = get_argument (argc, argv, "-skip-ps1-chip"))) {
     873    remove_argument (N, &argc, argv);
     874    SKIP_PS1_CHIP = TRUE;
     875  }
     876  SKIP_PS1_STACK = FALSE;
     877  if ((N = get_argument (argc, argv, "-skip-ps1-stack"))) {
     878    remove_argument (N, &argc, argv);
     879    SKIP_PS1_STACK = TRUE;
     880  }
     881  SKIP_HSC = FALSE;
     882  if ((N = get_argument (argc, argv, "-skip-hsc"))) {
     883    remove_argument (N, &argc, argv);
     884    SKIP_HSC = TRUE;
     885  }
     886  SKIP_CFH = FALSE;
     887  if ((N = get_argument (argc, argv, "-skip-cfh"))) {
     888    remove_argument (N, &argc, argv);
     889    SKIP_CFH = TRUE;
     890  }
     891
     892  UPDATE_PS1_STACK_MEASURE = FALSE;
     893  if ((N = get_argument (argc, argv, "-update-ps1-stack"))) {
     894    remove_argument (N, &argc, argv);
     895    UPDATE_PS1_STACK_MEASURE = TRUE;
     896  }
     897  UPDATE_PS1_CHIP_MEASURE = FALSE;
     898  if ((N = get_argument (argc, argv, "-update-ps1-chip"))) {
     899    remove_argument (N, &argc, argv);
     900    UPDATE_PS1_CHIP_MEASURE = TRUE;
     901  }
     902  UPDATE_HSC_MEASURE = FALSE;
     903  if ((N = get_argument (argc, argv, "-update-hsc"))) {
     904    remove_argument (N, &argc, argv);
     905    UPDATE_HSC_MEASURE = TRUE;
     906  }
     907  UPDATE_CFH_MEASURE = FALSE;
     908  if ((N = get_argument (argc, argv, "-update-cfh"))) {
     909    remove_argument (N, &argc, argv);
     910    UPDATE_CFH_MEASURE = TRUE;
     911  }
     912  if (RELASTRO_OP == OP_UPDATE_OFFSETS) {
     913    if (!UPDATE_PS1_STACK_MEASURE && !UPDATE_PS1_CHIP_MEASURE && !UPDATE_HSC_MEASURE && !UPDATE_CFH_MEASURE) {
     914      fprintf (stderr, "for -update-offsets, need to select at least one of -update-ps1-stack, -update-ps1-chip, -update-hsc, -update-cfh\n");
     915      exit (2);
     916    }
     917  }
     918
    728919  // check for object fitting modes
    729920  if ((N = get_argument (argc, argv, "-pm"))) {
     
    742933  if ((N = get_argument (argc, argv, "-high-speed"))) {
    743934    // XXX include a parallax / no-parallax option
    744     if (N >= argc - 5) usage_client();
     935    if (N >= argc - 5) usage_client (argc, argv);
    745936    RELASTRO_OP = OP_HIGH_SPEED;
    746937    remove_argument (N, &argc, argv);
     
    756947
    757948  if ((N = get_argument (argc, argv, "-hpm"))) {
    758     if (N >= argc - 3) usage();
     949    if (N >= argc - 3) usage_client (argc, argv);
    759950    RELASTRO_OP = OP_HPM;
    760951    remove_argument (N, &argc, argv);
     
    766957
    767958  if ((N = get_argument (argc, argv, "-testobj1"))) {
    768     if (N > argc - 3) usage ();
     959    if (N > argc - 3) usage_client (argc, argv);
    769960    remove_argument (N, &argc, argv);
    770961    OBJ_ID_SRC = strtol(argv[N], &endptr, 0);
    771     if (*endptr) usage ();
     962    if (*endptr) usage_client (argc, argv);
    772963    remove_argument (N, &argc, argv);
    773964    CAT_ID_SRC = strtol(argv[N], &endptr, 0);
    774     if (*endptr) usage ();
     965    if (*endptr) usage_client (argc, argv);
    775966    remove_argument (N, &argc, argv);
    776967  }
    777968
    778969  if ((N = get_argument (argc, argv, "-testobj2"))) {
    779     if (N > argc - 3) usage ();
     970    if (N > argc - 3) usage_client (argc, argv);
    780971    remove_argument (N, &argc, argv);
    781972    OBJ_ID_DST = strtol(argv[N], &endptr, 0);
    782     if (*endptr) usage ();
     973    if (*endptr) usage_client (argc, argv);
    783974    remove_argument (N, &argc, argv);
    784975    CAT_ID_DST = strtol(argv[N], &endptr, 0);
    785     if (*endptr) usage ();
     976    if (*endptr) usage_client (argc, argv);
    786977    remove_argument (N, &argc, argv);
    787978  }
     
    805996  }
    806997
    807   if (RELASTRO_OP == OP_NONE) usage_client();
     998  GALAXY_MODEL = NULL;
     999  if ((N = get_argument (argc, argv, "-galaxy-model"))) {
     1000    remove_argument (N, &argc, argv);
     1001    GALAXY_MODEL = strcreate(argv[N]);
     1002    remove_argument (N, &argc, argv);
     1003  }
     1004  if (!GALAXY_MODEL) GALAXY_MODEL = strcreate ("FEAST-HIPPARCOS");
     1005
     1006  // for testing, allow the galaxy model scale to be non-unity
     1007  TEST_SCALE = 1.0;
     1008  if ((N = get_argument (argc, argv, "-testing"))) {
     1009    remove_argument (N, &argc, argv);
     1010    TEST_SCALE = atof(argv[N]);
     1011    remove_argument (N, &argc, argv);
     1012  }
     1013
     1014  if (RELASTRO_OP == OP_NONE) usage_client (argc, argv);
    8081015
    8091016  /* specify portion of the sky : allow default of all sky? */
     
    10321239  }
    10331240
    1034   if (argc != 1) usage_client ();
     1241  if (argc != 1) usage_client (argc, argv);
    10351242  return TRUE;
    10361243}
     
    10491256  FREE(HIGH_SPEED_DIR);
    10501257  FREE(BCATALOG);
    1051   FREE (HOSTDIR);
     1258  FREE(HOSTDIR);
     1259  FREE(GALAXY_MODEL);
    10521260
    10531261  // these are set in initialize
     
    10661274}
    10671275
    1068 void usage () {
     1276void usage (int argc, char **argv) {
    10691277  fprintf (stderr, "ERROR: USAGE: relastro -images -update-simple [options]\n");
    10701278  fprintf (stderr, "       OR:    relastro -images -update-chips [options]\n");
     
    11161324  fprintf (stderr, "  -v\n");
    11171325  fprintf (stderr, "  \n");
     1326
     1327  fprintf (stderr, "remaining args: ");
     1328  for (int i = 0; i < argc; i++) {
     1329    fprintf (stderr, "%s ", argv[i]);
     1330  }
     1331  fprintf (stderr, "\n");
     1332
    11181333  exit (2);
    11191334}
    11201335
    1121 void usage_client () {
     1336void usage_client (int argc, char **argv) {
    11221337  fprintf (stderr, "ERROR: USAGE: relastro_client -load\n");
    11231338  fprintf (stderr, "       OR:    relastro_client -update-offsets\n");
     
    11501365  fprintf (stderr, "  -v\n");
    11511366  fprintf (stderr, "  \n");
     1367
     1368  fprintf (stderr, "remaining args: ");
     1369  for (int i = 0; i < argc; i++) {
     1370    fprintf (stderr, "%s ", argv[i]);
     1371  }
     1372  fprintf (stderr, "\n");
     1373
    11521374  exit (2);
    11531375}
     
    11891411  }
    11901412
     1413  // this sets the last loops to match the last value...
    11911414  while (Nloop < NLOOP) {
    11921415    weights[Nloop] = weights[Nloop - 1];
    11931416    Nloop ++;
    11941417  }
     1418
    11951419  return weights;
    11961420}
     1421
     1422int *ParseLoopOrder (char *rawlist, int minValue) {
     1423
     1424  int *orders = NULL;
     1425  ALLOCATE (orders, int, NLOOP);
     1426
     1427  int Nloop = 0;
     1428
     1429  /* parse the comma-separated list of photcodes */
     1430  char *myList = strcreate(rawlist);
     1431  char *list = myList;
     1432  char *entry = NULL;
     1433  char *ptr = NULL;
     1434  while ((Nloop < NLOOP) && ((entry = strtok_r (list, ",", &ptr)) != NULL)) {
     1435    list = NULL; // pass NULL on successive strtok_r calls
     1436
     1437    orders[Nloop] = atoi(entry);
     1438    if (orders[Nloop] < minValue) {
     1439      fprintf (stderr, "order cannot be < %d: %s\n", minValue, rawlist);
     1440      exit (3);
     1441    }
     1442
     1443    Nloop ++;
     1444  }
     1445  free (myList);
     1446
     1447  if (Nloop == 0) {
     1448    fprintf (stderr, "syntax error parsing orders: %s\n", rawlist);
     1449    exit (3);
     1450  }
     1451
     1452  // this sets the last loops to match the last value...
     1453  while (Nloop < NLOOP) {
     1454    orders[Nloop] = orders[Nloop - 1];
     1455    Nloop ++;
     1456  }
     1457
     1458  return orders;
     1459}
  • trunk/Ohana/src/relastro/src/assign_images.c

    r39457 r39926  
    4040
    4141  // register the image array with ImageOps.c for later getimageByID calls
    42   initImages (image, NULL, Nimage);
     42  initImages (image, NULL, Nimage, FALSE);
    4343
    4444  if (VERBOSE) fprintf (stderr, "finding images\n");
     
    7272
    7373  for (j = 0; j < Nimage; j++) {
     74   
     75    // allow certain cameras to stay static
     76    if (SKIP_PS1_CHIP  && isGPC1chip (image[j].photcode)) continue;
     77    if (SKIP_PS1_STACK && isGPC1stack(image[j].photcode)) continue;
     78    if (SKIP_HSC       && isHSCchip  (image[j].photcode)) continue;
     79    if (SKIP_CFH       && isCFHchip  (image[j].photcode)) continue;
    7480   
    7581    /* select images by photcode, or equiv photcode, if specified */
  • trunk/Ohana/src/relastro/src/bcatalog.c

    r39587 r39926  
    7272
    7373  int myNskip1 = 0, myNskip2 = 0, myNskip3 = 0, myNskip4 = 0, myNskip5 = 0, myNskip6 = 0;
     74
     75  int NgaiaObject = 0;
    7476
    7577  /* exclude stars not in range or with too few measurements */
     
    187189      if (isGPC1warp(catalog[0].measure[offset].photcode)) continue;
    188190
     191      // allow certain cameras to stay static
     192      if (SKIP_PS1_CHIP  && isGPC1chip(catalog[0].measure[offset].photcode)) continue;
     193      if (SKIP_PS1_STACK && isGPC1stack(catalog[0].measure[offset].photcode)) continue;
     194      if (SKIP_HSC       && isHSCchip(catalog[0].measure[offset].photcode)) continue;
     195      if (SKIP_CFH       && isCFHchip(catalog[0].measure[offset].photcode)) continue;
     196
    189197      // filter objects based on user supplied criteria, including SIGMA_LIM
    190198      if (!MeasFilterTest(&catalog[0].measure[offset], TRUE)) {
     
    250258      }
    251259
     260      if (catalog[0].measure[offset].photcode == 1030) { NgaiaObject ++; }
     261
    252262      CopyMeasureToTiny (&subcatalog[0].measureT[Nmeasure], &catalog[0].measure[offset]);
    253263      // subcatalog[0].measure[Nmeasure] = catalog[0].measure[offset];
     
    281291    }
    282292  }
    283   fprintf (stderr, "skips: %d %d %d %d %d %d\n", myNskip1, myNskip2, myNskip3, myNskip4, myNskip5, myNskip6);
     293  fprintf (stderr, "skips: %d %d %d %d %d %d, Ngaia: %d\n", myNskip1, myNskip2, myNskip3, myNskip4, myNskip5, myNskip6, NgaiaObject);
    284294  REALLOCATE (subcatalog[0].average,  Average,     MAX (Naverage, 1));
    285295  REALLOCATE (subcatalog[0].measureT, MeasureTiny, MAX (Nmeasure, 1));
  • trunk/Ohana/src/relastro/src/extra.c

    r37261 r39926  
    3939  return FALSE;
    4040}
     41
     42// for now (20160925) I need to identify HSC chips explicitly.  generalize in the future
     43int isHSCchip (int photcode) {
     44
     45  if ((photcode >= 20000) && (photcode <= 20111)) return TRUE; // g-band
     46  if ((photcode >= 21000) && (photcode <= 21111)) return TRUE; // r-band
     47  if ((photcode >= 22000) && (photcode <= 22111)) return TRUE; // i-band
     48  if ((photcode >= 23000) && (photcode <= 23111)) return TRUE; // z-band
     49  if ((photcode >= 24000) && (photcode <= 24111)) return TRUE; // y-band
     50
     51  return FALSE;
     52}
     53
     54// for now (20160925) I need to identify CFH chips explicitly.  generalize in the future
     55int isCFHchip (int photcode) {
     56
     57  if ((photcode >= 100) && (photcode <= 152)) return TRUE; // g-band
     58  if ((photcode >= 200) && (photcode <= 252)) return TRUE; // r-band
     59  if ((photcode >= 300) && (photcode <= 352)) return TRUE; // i-band
     60  if ((photcode >= 400) && (photcode <= 452)) return TRUE; // z-band
     61  if ((photcode >= 500) && (photcode <= 552)) return TRUE; // y-band
     62
     63  return FALSE;
     64}
  • trunk/Ohana/src/relastro/src/initialize.c

    r39457 r39926  
    1111  ConfigInit (&argc, argv);
    1212  args (argc, argv);
     13
     14  if (USE_GALAXY_MODEL) {
     15    if (!InitGalaxyModel (GALAXY_MODEL)) {
     16      fprintf (stderr, "failed to init galaxy model %s\n", GALAXY_MODEL);
     17      exit (2);
     18    }
     19  }
    1320
    1421  if (RELASTRO_OP == OP_MERGE_SOURCE) return;
  • trunk/Ohana/src/relastro/src/launch_region_hosts.c

    r39457 r39926  
    8181    strextend (&command, "-region-hosts %s", REGION_FILE);
    8282    strextend (&command, "-region-hostID %d", host->hostID);
     83
    8384    strextend (&command, "-D CATDIR %s", CATDIR);
    8485    strextend (&command, "-region %f %f %f %f", host->RminCat, host->RmaxCat, host->DminCat, host->DmaxCat);
    8586    strextend (&command, "-statmode %s", STATMODE);
    8687    strextend (&command, "-minerror %f", MIN_ERROR);
    87     strextend (&command, "-nloop %d", NLOOP);
    88     strextend (&command, "-threads %d", NTHREADS);
     88
     89    strextend (&command, "-D RELASTRO_SIGMA_LIM %f", SIGMA_LIM);
     90    strextend (&command, "-D RELASTRO_SRC_MEAS_TOOFEW %d", SRC_MEAS_TOOFEW);
     91
     92    strextend (&command, " -D RELASTRO_MIN_DISTANCE_MOD %f",     MIN_DISTANCE_MOD);
     93    strextend (&command, " -D RELASTRO_MAX_DISTANCE_MOD %f",     MAX_DISTANCE_MOD);
     94    strextend (&command, " -D RELASTRO_MAX_DISTANCE_MOD_ERR %f", MAX_DISTANCE_MOD_ERR);
     95
     96    strextend (&command, "-D USE_GALAXY_MODEL %d", USE_GALAXY_MODEL);
     97    strextend (&command, "-D USE_ICRF_CORRECT %d", USE_ICRF_CORRECT);
     98
     99    strextend (&command, "-D RELASTRO_DPOS_MAX %f", DPOS_MAX);
     100    strextend (&command, "-D ADDSTAR_RADIUS %f", ADDSTAR_RADIUS);
     101
     102    strextend (&command, "-D USE_ICRF_LOCAL %d",   USE_ICRF_LOCAL);
     103    strextend (&command, "-D USE_ICRF_SHFIT %d",   USE_ICRF_SHFIT);
     104    strextend (&command, "-D USE_ICRF_POLE %d",    USE_ICRF_POLE);
    89105
    90106    switch (FIT_TARGET) {
     
    98114        strextend (&command, "-update-mosaics");
    99115        break;
     116      case SET_CHIPS:
     117        strextend (&command, "-set-chips");
     118        break;
    100119      case TARGET_NONE:
    101120        abort();
     
    105124    if (VERBOSE2)           strextend (&command, "-vv");
    106125    if (RESET)              strextend (&command, "-reset");
     126
     127    if (ImagSelect)         strextend (&command, "-instmag %f %f", ImagMin, ImagMax);
     128    if (MaxDensityUse)      strextend (&command, "-max-density %f", MaxDensityValue);
     129    if (FlagOutlier)        strextend (&command, "-clip %d", CLIP_THRESH);
     130    if (ExcludeBogus)       strextend (&command, "-exclude-bogus %f", ExcludeBogusRadius);
     131
     132    if (USE_FIXED_PIXCOORDS) strextend (&command, "-D USE_FIXED_PIXCOORDS 1");
     133    if (PHOTCODE_KEEP_LIST) strextend (&command, "+photcode %s", PHOTCODE_KEEP_LIST);
     134    if (PHOTCODE_SKIP_LIST) strextend (&command, "-photcode %s", PHOTCODE_SKIP_LIST);
     135    if (PhotFlagSelect)     strextend (&command, "+photflags");
     136    if (PhotFlagBad)        strextend (&command, "+photflagbad %d", PhotFlagBad);
     137    if (PhotFlagPoor)       strextend (&command, "+photflagpoor %d", PhotFlagPoor);
     138
     139    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
     140      strextend (&command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     141    }
     142    if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
     143      strextend (&command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
     144    }
     145
     146    if (TEST_SCALE != 1.0)   strextend (&command, "-testing %f", TEST_SCALE);
     147
     148    if (SKIP_PS1_CHIP)       strextend (&command, "-skip-ps1-chip");
     149    if (SKIP_PS1_STACK)      strextend (&command, "-skip-ps1-stack");
     150    if (SKIP_HSC)            strextend (&command, "-skip-hsc");
     151    if (SKIP_CFH)            strextend (&command, "-skip-cfh");
     152
     153    strextend (&command, "-nloop %d", NLOOP);
     154    strextend (&command, "-threads %d", NTHREADS);
     155   
     156    if (PHOTCODE_RESET_LIST) strextend (&command, "-reset-to-photcode %s", PHOTCODE_RESET_LIST);
     157
    107158    if (UPDATE)             strextend (&command, "-update");
    108159    if (PARALLEL)           strextend (&command, "-parallel");
    109160    if (PARALLEL_MANUAL)    strextend (&command, "-parallel-manual");
    110161    if (PARALLEL_SERIAL)    strextend (&command, "-parallel-serial");
    111     if (PHOTCODE_KEEP_LIST) strextend (&command, "+photcode %s", PHOTCODE_KEEP_LIST);
    112     if (PHOTCODE_SKIP_LIST) strextend (&command, "-photcode %s", PHOTCODE_SKIP_LIST);
    113     if (PHOTCODE_RESET_LIST) strextend (&command, "-reset-to-photcode %s", PHOTCODE_RESET_LIST);
    114 
    115     if (MaxDensityUse)      strextend (&command, "-max-density %f", MaxDensityValue);
    116     if (ImagSelect)         strextend (&command, "-instmag %f %f", ImagMin, ImagMax);
    117     if (ExcludeBogus)       strextend (&command, "-exclude-bogus %f", ExcludeBogusRadius);
    118 
    119     if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
    120       strextend (&command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
    121     }
    122     if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
    123       strextend (&command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
    124     }
    125 
    126     if (PhotFlagSelect)     strextend (&command, "+photflags");
    127     if (PhotFlagBad)        strextend (&command, "+photflagbad %d", PhotFlagBad);
    128     if (PhotFlagPoor)       strextend (&command, "+photflagpoor %d", PhotFlagPoor);
    129 
     162
     163    strextend (&command, "-chiporder %d", CHIPORDER);
    130164    if (CHIPMAP)            strextend (&command, "-chipmap %d", CHIPMAP);
     165    if (ChipMapLoop)        strextend (&command, "-chipmaploop %s", ChipMapLoopStr);
     166    if (ChipOrderLoop)      strextend (&command, "-chiporderloop %s", ChipOrderLoopStr);
     167
    131168    if (RESET_IMAGES)       strextend (&command, "-reset-images");
    132169
     
    136173    if (LoopWeight2MASS) {  strextend (&command, "-loop-weights-2mass %s", LoopWeight2MASSstr); }
    137174    if (LoopWeightTycho) {  strextend (&command, "-loop-weights-tycho %s", LoopWeightTychostr); }
    138 
    139     strextend (&command, "-D RELASTRO_SRC_MEAS_TOOFEW %d", SRC_MEAS_TOOFEW);
    140     strextend (&command, "-D RELASTRO_SIGMA_LIM %f", SIGMA_LIM);
    141     strextend (&command, "-D RELASTRO_DPOS_MAX %f", DPOS_MAX);
    142     strextend (&command, "-D ADDSTAR_RADIUS %f", ADDSTAR_RADIUS);
    143 
    144     strextend (&command, "-D USE_GALAXY_MODEL %d", USE_GALAXY_MODEL);
    145 
    146     strextend (&command, "-D USE_ICRF_CORRECT %d", USE_ICRF_CORRECT);
    147     strextend (&command, "-D USE_ICRF_LOCAL %d",   USE_ICRF_LOCAL);
    148     strextend (&command, "-D USE_ICRF_SHFIT %d",   USE_ICRF_SHFIT);
    149     strextend (&command, "-D USE_ICRF_POLE %d",    USE_ICRF_POLE);
    150 
    151     if (USE_FIXED_PIXCOORDS) strextend (&command, "-D USE_FIXED_PIXCOORDS 1");
     175    if (LoopWeightGAIA)  {  strextend (&command, "-loop-weights-gaia %s", LoopWeightGAIAstr); }
     176    if (APPLY_PROPER_MOTION) strextend (&command, "-apply-proper-motion");
    152177
    153178    if (TimeSelect) {
  • trunk/Ohana/src/relastro/src/load_catalogs.c

    r39466 r39926  
    178178    strextend (&command, "relastro_client -load-objects %s", table->hosts[i].results);
    179179    strextend (&command, " -hostID %d", table->hosts[i].hostID);
     180    strextend (&command, " -hostdir %s", table->hosts[i].pathname);
     181
    180182    strextend (&command, " -D CATDIR %s", CATDIR);
    181     strextend (&command, " -hostdir %s", table->hosts[i].pathname);
    182183    strextend (&command, " -region %f %f %f %f", UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    183184    strextend (&command, " -statmode %s", STATMODE);
    184185    strextend (&command, " -minerror %f", MIN_ERROR);
     186
    185187    strextend (&command, " -D RELASTRO_SIGMA_LIM %f", SIGMA_LIM);
     188    strextend (&command, " -D RELASTRO_SRC_MEAS_TOOFEW %d", SRC_MEAS_TOOFEW);
     189
    186190    strextend (&command, " -D RELASTRO_MIN_DISTANCE_MOD %f",     MIN_DISTANCE_MOD);
    187191    strextend (&command, " -D RELASTRO_MAX_DISTANCE_MOD %f",     MAX_DISTANCE_MOD);
    188192    strextend (&command, " -D RELASTRO_MAX_DISTANCE_MOD_ERR %f", MAX_DISTANCE_MOD_ERR);
    189193
     194    strextend (&command, "-D USE_GALAXY_MODEL %d", USE_GALAXY_MODEL);
     195    strextend (&command, "-D USE_ICRF_CORRECT %d", USE_ICRF_CORRECT);
     196
    190197    if (FIT_MODE == FIT_PM_ONLY)         strextend (&command, "-pm");
    191198    if (FIT_MODE == FIT_PAR_ONLY)        strextend (&command, "-par");
    192199    if (FIT_MODE == FIT_PM_AND_PAR)      strextend (&command, "-pmpar");
    193200
    194     if (VERBOSE)       strextend (&command, "-v");
    195     if (VERBOSE2)      strextend (&command, "-vv");
    196     if (RESET)         strextend (&command, "-reset");
    197     if (ImagSelect)    strextend (&command, "-instmag %f %f", ImagMin, ImagMax);
    198     if (MaxDensityUse) strextend (&command, "-max-density %f", MaxDensityValue);
    199     if (FlagOutlier)   strextend (&command, "-clip %d", CLIP_THRESH);
    200     if (ExcludeBogus)  strextend (&command, "-exclude-bogus %f", ExcludeBogusRadius);
    201 
    202     if (USE_ICRF_CORRECT) strextend (&command, "-D USE_ICRF_CORRECT %d", USE_ICRF_CORRECT);
    203     if (USE_GALAXY_MODEL) strextend (&command, "-D USE_GALAXY_MODEL %d", USE_GALAXY_MODEL);
    204    
    205     if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
    206       strextend (&command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
    207     }
    208     if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
    209       strextend (&command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
    210     }
    211 
    212     if (USE_ALL_IMAGES)      strextend (&command, "-use-all-images");
     201    if (VERBOSE)             strextend (&command, "-v");
     202    if (VERBOSE2)            strextend (&command, "-vv");
     203    if (RESET)               strextend (&command, "-reset");
     204                             
     205    if (ImagSelect)          strextend (&command, "-instmag %f %f", ImagMin, ImagMax);
     206    if (MaxDensityUse)       strextend (&command, "-max-density %f", MaxDensityValue);
     207    if (FlagOutlier)         strextend (&command, "-clip %d", CLIP_THRESH);
     208    if (ExcludeBogus)        strextend (&command, "-exclude-bogus %f", ExcludeBogusRadius);
     209
    213210    if (USE_FIXED_PIXCOORDS) strextend (&command, "-D USE_FIXED_PIXCOORDS 1");
    214211    if (PHOTCODE_KEEP_LIST)  strextend (&command, "+photcode %s", PHOTCODE_KEEP_LIST);
     
    217214    if (PhotFlagBad)         strextend (&command, "+photflagbad %d", PhotFlagBad);
    218215    if (PhotFlagPoor)        strextend (&command, "+photflagpoor %d", PhotFlagPoor);
     216
     217    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
     218      strextend (&command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     219    }
     220    if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
     221      strextend (&command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
     222    }
     223
     224    if (SKIP_PS1_CHIP)       strextend (&command, "-skip-ps1-chip");
     225    if (SKIP_PS1_STACK)      strextend (&command, "-skip-ps1-stack");
     226    if (SKIP_HSC)            strextend (&command, "-skip-hsc");
     227    if (SKIP_CFH)            strextend (&command, "-skip-cfh");
     228
     229    if (USE_ALL_IMAGES)      strextend (&command, "-use-all-images");
     230
    219231    // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
    220232
     
    282294  CatalogSplitter *catalogs = BrightCatalogSplitInit (Nsecfilt);
    283295
     296  ohana_memstats (TRUE);
     297
    284298  for (i = 0; i < table->Nhosts; i++) {
    285299
     
    296310    free (bcatalog->secfilt);
    297311    free (bcatalog);
     312
     313    ohana_memstats (TRUE);
    298314  }
    299315
     
    320336
    321337  BrightCatalogSplitFree (catalogs);
     338  ohana_memstats (TRUE);
    322339
    323340  return (catalog);
  • trunk/Ohana/src/relastro/src/load_images.c

    r39474 r39926  
    6666  }
    6767
    68   initImages (subset, LineNumber, Nsubset);
     68  initImages (subset, LineNumber, Nsubset, !USE_ALL_IMAGES);
    6969  MARKTIME("  init images: %f sec\n", dtime);
    7070 
  • trunk/Ohana/src/relastro/src/relastro_images.c

    r39580 r39926  
    1616  int finalPassMode = FIT_MODE; // start with the globally-defined fit mode
    1717  FIT_MODE = FIT_AVERAGE;
     18
     19  int RESET_ON_UPDATE = RESET; 
     20  RESET = TRUE; // we need to reset when we load the bright catalog subset
    1821
    1922  /* lock and load the image db table */
     
    6568  // XXX NOTE : for 2mass reset, photcodesKeep should now limit to 2MASS measurements
    6669
     70  USE_IRLS = FALSE;  // do not use IRLS yet -- leads to excessive outlier rejections in the loops
     71
    6772  /* major modes */
    6873  switch (FIT_TARGET) {
     
    9095      break;
    9196
     97    case SET_CHIPS:
     98      // we just want to fit the selected chips to the mean positions
     99      UpdateChips (catalog, Ncatalog, 0);   // measure.X,Y -> R,D, fit image.coords
     100      MARKTIME("update chips: %f sec\n", dtime);
     101
     102      break;
     103
    92104    case TARGET_MOSAICS:
    93105      for (i = 0; i < NLOOP; i++) {
     
    102114  }
    103115
    104   if (!UPDATE) {
    105     freeStarMaps();
    106     gfits_db_free (&db);
    107     ohana_memcheck (VERBOSE);
    108     ohana_memdump (VERBOSE);
    109     exit (0);
    110   }
    111 
    112116  // free the image / measurement pointers
    113117  freeImageBins (Ncatalog);
     
    117121  free (catalog);
    118122  freeMosaics ();
     123
     124  if (!UPDATE) {
     125    freeStarMaps();
     126    dvo_image_unlock (&db);
     127    freeImages (db.ftable.buffer);
     128    gfits_db_free (&db);
     129    return TRUE;
     130  }
    119131
    120132  // If we did NOT use all images, then we applied the measured corrections to a subset of
     
    154166  // iterate over catalogs to make detection coordinates consistant
    155167  if (APPLY_OFFSETS) {
     168    USE_IRLS = ALLOW_IRLS;  // now that we have fitted the images, choose the user's option
     169    RESET = RESET_ON_UPDATE;
    156170    UpdateObjectOffsets (skylist, 0, NULL);
    157171  }
  • trunk/Ohana/src/relastro/src/relastro_objects.c

    r39457 r39926  
    159159    strextend (&command, "relastro_client -update-objects");
    160160    strextend (&command, "-hostID %d", table->hosts[i].hostID);
     161    strextend (&command, "-hostdir %s", table->hosts[i].pathname);
     162
    161163    strextend (&command, "-D CATDIR %s", CATDIR);
    162     strextend (&command, "-hostdir %s", table->hosts[i].pathname);
    163164    strextend (&command, "-region %f %f %f %f", UserPatch.Rmin, UserPatch.Rmax, UserPatch.Dmin, UserPatch.Dmax);
    164165    strextend (&command, "-statmode %s", STATMODE);
     166    strextend (&command, "-minerror %f", MIN_ERROR);
     167
     168    strextend (&command, "-D RELASTRO_SIGMA_LIM %f", SIGMA_LIM);
     169    strextend (&command, "-D RELASTRO_SRC_MEAS_TOOFEW %d", SRC_MEAS_TOOFEW);
    165170
    166171    if (FIT_MODE == FIT_PM_ONLY)         { strextend (&command, "-pm"); }
     
    171176    if (VERBOSE2)      { strextend (&command, "-vv"); }
    172177    if (RESET)         { strextend (&command, "-reset"); }
    173     if (UPDATE)        { strextend (&command, "-update"); }
     178
    174179    if (ImagSelect)    { strextend (&command, "-instmag %f %f", ImagMin, ImagMax); }
    175180    if (MaxDensityUse) { strextend (&command, "-max-density %f", MaxDensityValue); }
    176181    if (FlagOutlier)   { strextend (&command, "-clip %d", CLIP_THRESH); }
    177 
    178     if (USE_ALL_IMAGES)      { strextend (&command, "-use-all-images"); }
     182    if (ExcludeBogus)    strextend (&command, "-exclude-bogus %f", ExcludeBogusRadius);
     183
    179184    if (USE_FIXED_PIXCOORDS) { strextend (&command, "-D USE_FIXED_PIXCOORDS 1"); }
    180185    if (PHOTCODE_KEEP_LIST)  { strextend (&command, "+photcode %s", PHOTCODE_KEEP_LIST); }
     
    185190    // XXX note that the above pass in the flag as decimal -- also note that args.c cannot handle 0xHEX values
    186191
     192    if (DCR_BLUE_COLOR_POS && DCR_BLUE_COLOR_NEG) {
     193      strextend (&command, "-dcr-blue-color %s %s", DCR_BLUE_COLOR_POS, DCR_BLUE_COLOR_NEG);
     194    }
     195    if (DCR_RED_COLOR_POS && DCR_RED_COLOR_NEG) {
     196      strextend (&command, "-dcr-red-color %s %s", DCR_RED_COLOR_POS, DCR_RED_COLOR_NEG);
     197    }
     198
     199    if (UPDATE)        { strextend (&command, "-update"); }
     200    if (USE_ALL_IMAGES)      { strextend (&command, "-use-all-images"); }
     201
    187202    if (MinBadQF > 0.0)          strextend (&command, "-min-bad-psfqf %f", MinBadQF);
    188203    if (MaxMeanOffset != 10.0)   strextend (&command, "-max-mean-offset  %f", MaxMeanOffset);
  • trunk/Ohana/src/relastro/src/relastro_parallel_images.c

    r39580 r39926  
    6161  initMosaics (image, Nimage);
    6262
    63   initImages (image, NULL, Nimage);
     63  initImages (image, NULL, Nimage, FALSE);
    6464
    6565  SkyTable *sky = SkyTableLoadOptimal (CATDIR, SKY_TABLE, GSCFILE, TRUE, SKY_DEPTH, VERBOSE);
     
    103103
    104104  client_logger_message ("starting the loops: %s\n", myHostName);
     105
     106  RESET = TRUE; // we need to reset when we load the bright catalog subset
     107  FIT_MODE = FIT_AVERAGE; // we need to only fit the average
     108  USE_IRLS = FALSE;  // do not use IRLS yet -- leads to excessive outlier rejections in the loops
    105109
    106110  /* major modes */
  • trunk/Ohana/src/relastro/src/select_images.c

    r39474 r39926  
    121121    }
    122122
     123    // allow certain cameras to stay static
     124    if (SKIP_PS1_CHIP  && isGPC1chip (timage[i].photcode)) continue;
     125    if (SKIP_PS1_STACK && isGPC1stack(timage[i].photcode)) continue;
     126    if (SKIP_HSC       && isHSCchip  (timage[i].photcode)) continue;
     127    if (SKIP_CFH       && isCFHchip  (timage[i].photcode)) continue;
     128   
    123129    /* select images by photcode, or equiv photcode, if specified */
    124130    if (NphotcodesKeep > 0) {
     
    187193    if (DmaxImage < DminSkyRegion) continue;
    188194   
     195    if (KEEP_ALL_IMAGES_RA) goto found_it;
     196
    189197    // the sky region RA is defined to be 0 - 360.0
    190198    if (RminImage > RmaxSkyRegion) continue;
  • trunk/Ohana/src/relastro/src/syncfile.c

    r36871 r39926  
    3939    int loop;
    4040    sscanf (message, "%*s %d", &loop);
     41    if (CATCH_UP && (nloop < loop)) return TRUE; // if I am behind this machine, I need to catch up!
    4142    if (loop != nloop) {
    4243      usleep (2000000);
  • trunk/Ohana/src/relphot/include/relphot.h

    r39648 r39926  
    309309int    RESET_ZEROPTS;
    310310int    REPAIR_WARPS;
     311int    PRESERVE_PS1;
    311312int    UPDATE;
    312313int    SAVE_IMAGE_UPDATES;
     
    616617int isTYCHO (int photcode);
    617618
     619int isHSCchip  (int photcode);
     620int isCFHchip  (int photcode);
     621
    618622int magStatsByRanking (StatDataSet *dataset, StatType *stats);
    619623
  • trunk/Ohana/src/relphot/src/args.c

    r39642 r39926  
    226226    remove_argument (N, &argc, argv);
    227227    REPAIR_WARPS = TRUE;
     228  }
     229
     230  PRESERVE_PS1 = FALSE;
     231  if ((N = get_argument (argc, argv, "-preserve-ps1"))) {
     232    remove_argument (N, &argc, argv);
     233    PRESERVE_PS1 = TRUE;
    228234  }
    229235
     
    672678  }
    673679
     680  PRESERVE_PS1 = FALSE;
     681  if ((N = get_argument (argc, argv, "-preserve-ps1"))) {
     682    remove_argument (N, &argc, argv);
     683    PRESERVE_PS1 = TRUE;
     684  }
     685
    674686  REPAIR_WARPS = FALSE;
    675687  if ((N = get_argument (argc, argv, "-repair-warps"))) {
  • trunk/Ohana/src/relphot/src/extra.c

    r38993 r39926  
    22
    33// for now (20140710) I need to identify gpc1 chips explicitly.  generalize in the future
     4// note that the 4000, 14000, 15000 sets are SIMTEST (*not* synthetic)
    45int whichGPC1filter (int photcode) {
    56
    6   if (((photcode > 10000) && (photcode < 10077)) || (photcode == 4100)) return PS1_g; // g-band
     7  if (((photcode > 10000) && (photcode < 10077)) || (photcode == 4100)) return PS1_g; // g-band 
    78  if (((photcode > 10100) && (photcode < 10177)) || (photcode == 4200)) return PS1_r; // r-band
    89  if (((photcode > 10200) && (photcode < 10277)) || (photcode == 4300)) return PS1_i; // i-band
     
    8384}
    8485
     86// for now (20160925) I need to identify HSC chips explicitly.  generalize in the future
     87int isHSCchip (int photcode) {
     88
     89  if ((photcode >= 20000) && (photcode <= 20111)) return TRUE; // g-band
     90  if ((photcode >= 21000) && (photcode <= 21111)) return TRUE; // r-band
     91  if ((photcode >= 22000) && (photcode <= 22111)) return TRUE; // i-band
     92  if ((photcode >= 23000) && (photcode <= 23111)) return TRUE; // z-band
     93  if ((photcode >= 24000) && (photcode <= 24111)) return TRUE; // y-band
     94
     95  return FALSE;
     96}
     97
     98// for now (20160925) I need to identify CFH chips explicitly.  generalize in the future
     99int isCFHchip (int photcode) {
     100
     101  if ((photcode >= 100) && (photcode <= 152)) return TRUE; // g-band
     102  if ((photcode >= 200) && (photcode <= 252)) return TRUE; // r-band
     103  if ((photcode >= 300) && (photcode <= 352)) return TRUE; // i-band
     104  if ((photcode >= 400) && (photcode <= 452)) return TRUE; // z-band
     105  if ((photcode >= 500) && (photcode <= 552)) return TRUE; // y-band
     106
     107  return FALSE;
     108}
     109
  • trunk/Ohana/src/relphot/src/reload_catalogs.c

    r39511 r39926  
    239239    if (RESET)             { strextend (&command, "-reset"); }
    240240    if (RESET_ZEROPTS)     { strextend (&command, "-reset-zpts"); }
     241    if (PRESERVE_PS1)      { strextend (&command, "-preserve-ps1"); }
    241242    if (UPDATE)            { strextend (&command, "-update"); }
    242243    if (IS_DIFF_DB)        { strextend (&command, "-is-diff-db"); }
  • trunk/Ohana/src/relphot/src/relphot_objects.c

    r39643 r39926  
    243243    if (RESET_ZEROPTS)     { strextend (&command, "-reset-zpts"); }
    244244    if (REPAIR_WARPS)      { strextend (&command, "-repair-warps"); }
     245    if (PRESERVE_PS1)      { strextend (&command, "-preserve-ps1"); }
    245246    if (IS_DIFF_DB)        { strextend (&command, "-is-diff-db"); }
    246247    if (UPDATE)            { strextend (&command, "-update"); }
  • trunk/Ohana/src/relphot/src/setMrelCatalog.c

    r39636 r39926  
    142142  int Galaxy2MASS = FALSE;
    143143  int haveTYCHO = FALSE;
     144  int haveHSC = FALSE;
     145  int haveCFH = FALSE;
    144146
    145147  float stargalmax = 0.0;
     
    163165   
    164166    if (isTYCHO(measureT[k].photcode)) { haveTYCHO = TRUE; }
     167    if (isHSCchip(measureT[k].photcode)) { haveHSC = TRUE; }
     168    if (isCFHchip(measureT[k].photcode)) { haveCFH = TRUE; }
    165169
    166170    if (is2MASS(measureT[k].photcode)) {
     
    317321  // now calculate the mean stats for the Nsec bands.
    318322  for (Nsec = 0; Nsec < Nsecfilt; Nsec++) {
    319     dvo_secfilt_init (&secfilt[Nsec], SECFILT_RESET_CHIP); // this does not reset astrometry or STACK bits
     323
     324    // if we detected this object in PS1, or do not request -preserve-ps1, keep the mean photometry values
     325    if (!PRESERVE_PS1 || !(secfilt[Nsec].flags & ID_SECF_HAS_PS1)) {
     326      dvo_secfilt_init (&secfilt[Nsec], SECFILT_RESET_CHIP); // this does not reset astrometry or STACK bits
     327    }
     328
     329    if (haveTYCHO) {
     330      secfilt[Nsec].flags |= ID_SECF_HAS_TYCHO;
     331    }
     332    if (haveHSC) {
     333      secfilt[Nsec].flags |= ID_SECF_HAS_HSC;
     334    }
     335    if (haveCFH) {
     336      secfilt[Nsec].flags |= ID_SECF_HAS_CFH;
     337    }
     338
     339    if (PRESERVE_PS1 && (secfilt[Nsec].flags & ID_SECF_HAS_PS1)) continue;
     340    // if -preserve-ps1 is set and this object has PS1 data, skip the rest of the steps:
    320341
    321342    // XXX hardwired grizy = (01234) JHK = (567) w = (8)
     
    324345    } else {
    325346      secfilt[Nsec].Ncode = results->Nmeas[Nsec]; // 2MASS data if it exists
    326     }
    327 
    328     if (haveTYCHO) {
    329       secfilt[Nsec].flags |= ID_SECF_HAS_TYCHO;
    330347    }
    331348
  • trunk/Ohana/src/uniphot/include/setgalmodel.h

    r38986 r39926  
    1010char        *HOSTDIR;
    1111int          VERBOSE;
    12 int          TESTING;
    1312int          UPDATE;
    1413int          PARALLEL;
     
    1817char        *SINGLE_CPT;
    1918
     19float        TEST_SCALE;
     20char        *GALAXY_MODEL;
    2021SkyRegion    UserPatch;
    2122
  • trunk/Ohana/src/uniphot/include/setphot.h

    r39356 r39926  
    6767int          VERBOSE;
    6868int          RESET;
     69int          PHOTCODE_MIN;
     70int          PHOTCODE_MAX;
    6971int          UBERCAL; // load the supplied ubercal zero point fits table (with flat-field corrections)
    7072int          NO_METADATA; // the supplied ubercal data has no descriptive metadata
  • trunk/Ohana/src/uniphot/src/initialize_setgalmodel.c

    r39225 r39926  
    4545
    4646  // XXX add to config?
    47   if (!InitGalaxyModel ("FEAST-HIPPARCOS")) {
    48     fprintf (stderr, "failed to init galaxy model\n");
     47  if (!InitGalaxyModel (GALAXY_MODEL)) {
     48    fprintf (stderr, "failed to init galaxy model %s\n", GALAXY_MODEL);
    4949    exit (2);
    5050  }
     
    9292  }
    9393
    94   TESTING = FALSE;
     94  GALAXY_MODEL = NULL;
     95  if ((N = get_argument (argc, argv, "-galaxy-model"))) {
     96    remove_argument (N, &argc, argv);
     97    GALAXY_MODEL = strcreate(argv[N]);
     98    remove_argument (N, &argc, argv);
     99  }
     100  if (!GALAXY_MODEL) GALAXY_MODEL = strcreate ("FEAST-HIPPARCOS");
     101
     102  TEST_SCALE = 1.0;
    95103  if ((N = get_argument (argc, argv, "-testing"))) {
    96     TESTING = TRUE;
     104    remove_argument (N, &argc, argv);
     105    TEST_SCALE = atof(argv[N]);
    97106    remove_argument (N, &argc, argv);
    98107  }
     
    171180  }
    172181
    173   // XXX add to config?
    174   if (!InitGalaxyModel ("ROESER")) {
     182  // from args
     183  if (!InitGalaxyModel (GALAXY_MODEL)) {
    175184    fprintf (stderr, "failed to init galaxy model\n");
    176185    exit (2);
     
    212221  }
    213222
    214   TESTING = FALSE;
     223  GALAXY_MODEL = NULL;
     224  if ((N = get_argument (argc, argv, "-galaxy-model"))) {
     225    remove_argument (N, &argc, argv);
     226    GALAXY_MODEL = strcreate(argv[N]);
     227    remove_argument (N, &argc, argv);
     228  }
     229  if (!GALAXY_MODEL) GALAXY_MODEL = strcreate ("FEAST-HIPPARCOS");
     230
     231  TEST_SCALE = 1.0;
    215232  if ((N = get_argument (argc, argv, "-testing"))) {
    216     TESTING = TRUE;
     233    remove_argument (N, &argc, argv);
     234    TEST_SCALE = atof(argv[N]);
    217235    remove_argument (N, &argc, argv);
    218236  }
  • trunk/Ohana/src/uniphot/src/initialize_setphot.c

    r39356 r39926  
    109109  if ((N = get_argument (argc, argv, "-reset"))) {
    110110    RESET = TRUE;
     111    remove_argument (N, &argc, argv);
     112  }
     113
     114  PHOTCODE_MIN = 0;
     115  PHOTCODE_MAX = 0;
     116  if ((N = get_argument (argc, argv, "-photcode-range"))) {
     117    remove_argument (N, &argc, argv);
     118    PHOTCODE_MIN = atoi (argv[N]);   
     119    remove_argument (N, &argc, argv);
     120    PHOTCODE_MAX = atoi (argv[N]);   
    111121    remove_argument (N, &argc, argv);
    112122  }
  • trunk/Ohana/src/uniphot/src/initialize_setphot_client.c

    r39356 r39926  
    9696  }
    9797
     98  PHOTCODE_MIN = 0;
     99  PHOTCODE_MAX = 0;
     100  if ((N = get_argument (argc, argv, "-photcode-range"))) {
     101    remove_argument (N, &argc, argv);
     102    PHOTCODE_MIN = atoi (argv[N]);   
     103    remove_argument (N, &argc, argv);
     104    PHOTCODE_MAX = atoi (argv[N]);   
     105    remove_argument (N, &argc, argv);
     106  }
     107
    98108  // region of interest
    99109  UserPatch.Rmin = 0;
  • trunk/Ohana/src/uniphot/src/update_catalog_setgalmodel.c

    r39586 r39926  
    3333
    3434    // fake or real QSOs are marked with FeH = +/- 100.0
    35     if (fabs(starpar->FeH) > 99.0) continue;
     35    if (fabs(starpar->FeH) > 99.0) {
     36      starpar->uRA  = 0.0;
     37      starpar->uDEC = 0.0;
     38      average[i].uRgal = 0.0;
     39      average[i].uDgal = 0.0;
     40      continue;
     41    }
    3642
    37     // NOTE: distance is in kiloparsec
     43    // NOTE: DistMag is standard (10pc reference).  SolarMotionModel wants distance in kiloparsec:
    3844    double distance = pow(10.0, 0.2*(starpar->DistMag + 5.0)) / 1000.0;
    3945
     
    5157
    5258    // XXX: amplify motion to make tests easier:
    53     if (TESTING) {
    54       uL *= 100.0;
    55       uB *= 100.0;
    56     }
     59    uL *= TEST_SCALE;
     60    uB *= TEST_SCALE;
    5761   
    5862    double uR, uD;
  • trunk/Ohana/src/uniphot/src/update_catalog_setphot.c

    r39457 r39926  
    11# include "setphot.h"
     2
     3// XXX I need to add a few things for HSC + MC + GPC1:
     4// * I can generate a zpt table for the MC exposures using the nominal zero points
     5// * for the HSC data, I need to add a function to define Mflat as a function of Xmos, Ymos
    26
    37void update_catalog_setphot (Catalog *catalog, Image *image, off_t *index, off_t Nimage, CamPhotomCorrection *camcorr) {
     
    1418    Measure *measure = &catalog[0].measure[i];
    1519
    16     // only do GPC1 data for now
    17     if (measure[0].photcode < 10000) continue;
    18     if (measure[0].photcode > 10600) continue;
     20    // XXX deprecated 2016.09.22 : only do GPC1 data for now
     21    // if (measure[0].photcode < 10000) continue;
     22    // if (measure[0].photcode > 10600) continue;
    1923     
     24    // only do DEP photcodes (skip REF, etc)
     25    PhotCode *code = GetPhotcodebyCode (measure[0].photcode);
     26    if (!code) continue; // invalid photcode
     27    if (code->type != PHOT_DEP) continue;
     28
     29    // allow a restriction on the modified zpts:
     30    if (PHOTCODE_MAX) {
     31      if (measure[0].photcode < PHOTCODE_MIN) continue;
     32      if (measure[0].photcode > PHOTCODE_MAX) continue;
     33    }
     34
    2035    off_t idx = measure[0].imageID;
    2136    if (idx <= 0) continue; // detections with imageID == 0 do not have a valid image (eg, ref photcode)
     
    3348      Mflat = CamPhotomCorrectionValue (camcorr, flat_id, measure[0].Xccd, measure[0].Yccd);
    3449    }
     50
     51# if (0)
     52    // the mosaic lookup is broken : fix it then redo this block
     53    if (radialZP) {
     54      mosaic = MatchMosaicMetadata (measure[0].imageID);
     55      if (mosaic == NULL) break;
     56      double Rm = measure[0].R;
     57      double Dm = measure[0].D;
     58      RD_to_XY (&XMOS_MEAS, &YMOS_MEAS, Rm, Dm, mosaic);
     59      Mflat = RadialZPtrend (XMOS_MEAS, XMOS_MEAS);
     60    }
     61# endif
    3562
    3663    measure[0].Mcal = Mcal;
  • trunk/Ohana/src/uniphot/src/update_dvo_setgalmodel.c

    r39225 r39926  
    9898
    9999    if (VERBOSE)          { strextend (&command, "-v"); }
    100     if (TESTING)          { strextend (&command, "-testing"); }
     100    if (TEST_SCALE != 1.0){ strextend (&command, "-testing %f", TEST_SCALE); }
    101101    if (UPDATE)           { strextend (&command, "-update"); }
    102102    if (UPDATE_CATFORMAT) { strextend (&command, "-update-catformat %s", UPDATE_CATFORMAT); }
  • trunk/Ohana/src/uniphot/src/update_dvo_setphot.c

    r39356 r39926  
    179179    if (DCR_RESET)        { strextend (&command, "-DCR-reset"); }
    180180    if (CAM_RESET)        { strextend (&command, "-CAM-reset"); }
     181
     182    if (PHOTCODE_MAX)     { strextend (&command, "-photcode-range %d %d", PHOTCODE_MIN, PHOTCODE_MAX); }
    181183
    182184    fprintf (stderr, "command: %s\n", command);
Note: See TracChangeset for help on using the changeset viewer.